Hello friends,
I was working with some SYCL code and I tried the memory synchronization by using an host accessor on the host side, but it did not work. I don’t know why, because if I add a scope around the buffer creation and kernel function everything is fine.
This is the code:
cl::sycl::gpu_selector device;
cl::sycl::queue Q{device};
std::cout << "Running on "
<< Q.get_device().get_info<sycl::info::device::name>()
<< "\n";
constexpr int N = 10;
std::vector<float>vector(N);
for(int i=0; i<N; i++){
vector[i] = 100.0;
}
cl::sycl::buffer<float,1> buffVec(vector.data(),vector.size());
//WE DO NOT USE SCOPE
Q.submit([&](cl::sycl::handler &cgh){
//Create accesors to data
auto acc = buffVec.get_access<cl::sycl::access::mode::read_write>(cgh);
cgh.parallel_for<vec_mult>(cl::sycl::range<1>(N), [=](cl::sycl::id<1> index){
acc[index] *=2.0;
});
});
buffVec.get_access<cl::sycl::access::mode::read>(); //<--- Host accessor to Synchronize memory
for(int i=0; i<N; i++){
std::cout<<vector[i]<<std::endl;
}
Thanks for your support