Showing results for 
Search instead for 
Did you mean: 

Archives Discussions


behaviour of CL_MEM_USE_HOST_PTR

if i create memory buffer with CL_MEM_USE_HOST_PTR i  was exceptet that after that i execute kernel which write into this buffer whis writes will be reflected into host memory. but appereantly it is not the case.

is my understanding of CL_MEM_USE_HOST_PTR or CL_MEM_ALLOC_HOST_PTR wrong? specification is unclearly about this.

i found that i should map/unmap this buffer but then use of CL_MEM_USE_HOST_PTR is meaningless

1 Reply
Journeyman III

No, it's not meaningless. You both save a copy operation when creating the buffer, and don't have to (temporarily)duplicate host-side data. The reason changes aren't reflected immediately is probably because you're using the GPU, and it is both allowed to cache the region of memory and possibly also keep variables in registers during computation.

If you had used a CPU device, with cache coherency, only the last of those issues would have been a potential problem, and it can be avoided by using the "volatile" keyword in your OpenCL code.

But yeah, mapping/unmapping is the way to force a copyback operation from the gpu.(I'm sure you noticed that mapping always returns the original host pointer in that case)