Skip to content

sycl::buffer write back #10091

@sommerlukas

Description

@sommerlukas

Describe the bug
If a sycl::buffer is constructed with a const T* as host data, no write back should happen upon destruction of the buffer.

The description of the relevant buffer constructor says:

Since, the hostData is const, this buffer is only initialized with this memory and there is no write back after its destruction, unless the buffer has another valid non-null final data address specified via the member function set_final_data() after construction of the buffer.

However, with DPC++, the write back still happens in the example given below.

To Reproduce

Code example:

#include <iostream>

#include <sycl/sycl.hpp>

using namespace sycl;

#define N 32

int main() {
  std::vector<int> vec(N, 1);
  std::cout << "Vec first element: " << vec[0] << "\n";
  {
    buffer<int, 1> buf(static_cast<const int*>(vec.data()), range<1>{N});

    queue q;

    q.submit([&](handler& cgh) {
      auto acc = buf.get_access<access_mode::read_write>(cgh);

      cgh.parallel_for<class Kernel>({N}, [=](id<1> i) { acc[i] += 5; });
    });
  }
  std::cout << "Vec first element: " << vec[0] << "\n";

  return 0;
}

If no write back happens, the elements of vec should all still contain 1 after the buffer is destructed. However, the following output is produced:

Vec first element: 1
Vec first element: 6

The application can simply be compiled with clang++ -fsycl to create this behavior.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Target device and vendor: Intel CPU OpenCL
  • DPC++ version: 92dbe1f89b3554e6d4836cbbbca447f892af756f

Additional context

The elements of vec are even overwritten before the buffer is destructed, if host access (get_host_access) is requested after executing the kernel.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions