If a variable is passed to kernel with CL_MEM_USE_HOST_PTR, does it mean any change to the variable in the device would be also shown in host memory?
I am in a scenario where I am using CPU as the device instead of GPU, so everything passed to kernel will be marked with CL_MEM_USE_HOST_PTR.
If this is true, then I no longer need to read everything back to host, which is very convenient.
Your understanding is correct, except one possible pitfall: documentation states that
This means that changes to data performed by kernel might not be immediately reflected in
host_ptr. In fact, there is no guarantee thathost_ptrcontains valid data while it is used for buffer.In order to have valid and up-to-date data you must force synchronization. The offcial documentation is a little vague about this moment, but buffer mapping/unmapping definetly works:
Here is an example adapted from Khronos group forum post: