you are wrong. in specification to CL_USE_HOST_PTR
OpenCL implementations are allowed to cache the buffer
contents pointed to by host_ptr in device memory. This
cached copy can be used when kernels are executed on a
CL_ALLOC_HOST_PTR just say OpenCL should provide pointer to a data.
and mapping buffer.
If the buffer object is created with CL_MEM_USE_HOST_PTR set in mem_flags, the following
will be true:
The host_ptr specified in clCreateBuffer is guaranteed to contain the latest bits in the
region being mapped when the clEnqueueMapBuffer command has completed.
The pointer value returned by clEnqueueMapBuffer will be derived from the host_ptr
specified when the buffer object is created.
and AFAIK using mapped buffer will lead to undefined behaviour. so even program crash.
I was asking a while back how can I allocate memory on device without having to allocate the same amount on the host? USE_HOST_PTR and COPY_HOST_PTR both initialize data with the given host_ptr when creating the buffer.
If I'd wish to create a 1GB buffer, I do not wish to allocate the same amount in host just to ensure that the pointer I give can be read by the application and the OS will not seg_fault the program.
Someone told me the way to do this is to use the ALLOC_HOST_PTR and pass a NULL pointer to clCreateBuffer. Is this not true?
Also I am unsure about what you meant by "guaranteed to contain the latest bits in the region being mapped". Does this mean that it contains the most up-to-date information? If so, why doesn't a buffer created with COPY_HOST_PTR do the same when mapped to host memory?
you don't need pass any HOST_PTR flag. just READ/WRITE flag. then you create buffer on device without allocation memory on host side.
and with guaranteed to contain the latest bits in the region being mapped is meant that you execute some kernel which write into buffer with USE_HOST_PTR. that kernel write into device memory. and with mapping you synchronize content of device and host memory.
The answer to that question might be implementation dependent. AFAIK OpenCL spec does not specify when a copy is necessary.
It just states the behaviour expected by using various flags. One technique which I tried was to track the system memory in use and note the changes in it when I create buffers using different FLAGS. It was very simple to do so using Task MAnager in windows. I hope there is something similar in Linux also.