KhronosGroup / KhronosGroup/SYCL-Docs

buffer::get_access<access::mode::read> should be marked const.

Open
#10 7 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
158
Forks
80
Avg merge
7d 6h
Merged PRs (30d)
5

Description

### The Problem

Calling `get_access` in read-only mode requires the `buffer` to be non-`const` since `get_access` itself is never marked as `const`. This is a problem for `const` data structures which encapsulate a SYCL `buffer`. It also contradicts `const`-correctness which is strongly advocated for by the C++ community. Finally it is counterintuitive for the programmer.

### Example

```c++
#include

int main()
{
auto queue = cl::sycl::queue{};

const auto in = cl::sycl::buffer{1024};
auto out = cl::sycl::buffer{1024};

queue.submit([&](cl::sycl::handler& cgh)
{
// candidate function not viable: method is not marked const
auto in_acc = in.get_access(cgh);
auto out_acc = out.get_access(cgh);

cgh.copy(in_acc, out_acc);
});

return 0;
}
```

### Use case

Any `const` data structure encapsulating a SYCL `buffer`.

### Possible solutions

1. Mark `get_access` `const` for `access::mode::read`. I'd be happy to open a pull-request for this if needed.
2. Add wording to `get_access`'s specification which explains why it cannot be marked `const`.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue concerns the SYCL buffer get_access specification and includes a const-correctness example. Start by reading the get_access specification and the seven-comment discussion, then determine which proposed resolution is accepted. Done means the specification clearly settles the behavior of read-only access for const buffers.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.