According SYCL reference
Buffers can be initialized by a host data pointer. While the buffer exists, it owns the host data and direct access of the host data pointer during that time is undefined.
Which is understandable for output buffers. But what about read only buffer? In the following code fragment is it undefined behavior to access read only buffer before kernel completes?
range<1> bufer_size{ 100 };
buffer<int> in_buf(input_buffer, bufer_size);
buffer<int> out_buf(output_buffer, bufer_size);
auto my_device = default_selector{};
queue q{ my_device };
q.submit([&](handler& h) {
auto x = in_buf.get_access<access::mode::read>(h);
auto y = out_buf.get_access<access::mode::write>(h);
h.parallel_for(bufer_size,
[=](id<1> idx) {
y[idx] = 100 * x[idx] + 1;
});
});
// Is it OK to read input_buffer without waiting for queue to complete?
for (int i = 0; i < size; ++i) {
std::cout << input_buffer[i] << ' ';
}