Skip to content

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

@j-stephan

Description

@j-stephan

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

#include <CL/sycl.hpp>

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

    const auto in = cl::sycl::buffer<int, 1>{1024};
    auto out = cl::sycl::buffer<int, 1>{1024};

    queue.submit([&](cl::sycl::handler& cgh)
    {
        // candidate function not viable: method is not marked const
        auto in_acc = in.get_access<cl::sycl::access::mode::read>(cgh);
        auto out_acc = out.get_access<cl::sycl::access::mode::write>(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions