Hello @Heinzelnisse ,
I understand you want to explicitly manage your data transfers between devices.
Is it really necessary to run a queue submission like this every time I want a vector of data initialized on device memory in a
sycl::buffer
?
Not really, that was just one example. Better and cleaner, you can just enqueue dedicated copy commands to/from device for this behaviour via the explicit memory operation APIs in the command group handler - sycl::handler::copy
(see: 4.9.4.3. SYCL functions for explicit memory operations in the SYCL 2020 (Revision 7) specification.
Aren’t there any one-liners to pass
buf_data
directly into the ownership of the buffer ,without having to worry about device memory copying and explicit copying via queue submissions?
Yes, sycl::handler::copy
can be used in place of the separate copy_dev_mem_kernel_func
kernel, i.e.:
queue.submit([&](sycl::handler &cgh) {
auto dev_data_acc = ...
cgh.copy(host_data.data(), dev_data_acc);
}
Destination here is sycl::accessor
as you’d need to define the range of the memory to be written (see this example).
Buffer objects enqueue implicit data transfers to the device when the associated accessors with the buffer memory region are enqeued in the device commands and most likely this would be when that memory is actually required on the device. If you want to explicitly manage when data transfers to device should happen, the above approach via using the SYCL explicit memory copy functions should work.
Please let me know if there is more to your use-case that needs to be clarified. Thanks!
Kind regards,
Georgi