I realize that the spec has only been clarified recently regarding all the possible combinations of accessors/pointers when it comes to explicit memory operations - so maybe this has simply not been implemented yet. Anyhow, I believe according to SYCL 1.2.1 Rev 6 something like this should be possible:
#include <cassert>
#include <cstdio>
#include <vector>
#include <CL/sycl.hpp>
int main(int argc, char* argv[]) {
constexpr size_t range = 16;
cl::sycl::queue queue{cl::sycl::cpu_selector{}};
std::vector<size_t> host_data(range);
for(size_t i = 0; i < host_data.size(); ++i) {
host_data[i] = i;
}
cl::sycl::buffer<size_t, 1> host_buf(host_data.data(), range);
cl::sycl::buffer<size_t, 1> device_buf(range);
auto r_host = host_buf.get_access<cl::sycl::access::mode::read>();
queue.submit([&](cl::sycl::handler& cgh) {
auto dw_a = device_buf.get_access<cl::sycl::access::mode::discard_write>(cgh);
cgh.copy(r_host, dw_a);
});
auto r_a = device_buf.get_access<cl::sycl::access::mode::read>();
for(size_t i = 0; i < range; ++i) {
printf("%llu\n", r_a[i]);
assert(r_a[i] == i);
}
return 0;
}
In short, I’m trying to copy data from a host-initialized buffer into a device buffer using cl::sycl::handler::copy
. This means I’m passing a host-accessor for the source, and a device-accessor for the target. I would then expect the same data that host_buf
was initialized with would also be in device_buf
. What actually happens as of ComputeCpp 1.1.6 however is that apparently uninitialized memory is being copied to the device_buf
.