cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

drstrip
Journeyman III

CL_MEM_USE_HOST_PTR vs CL_MEM_COPY_HOST_PTR

In clCreateBuffer, if I set mem_flags to CL_MEM_USE_HOST_PTR, the spec says that the contents of the host memory may be copied to device memory. However, if I use CL_MEM_COPY_HOST_PTR, it says that the implementation will "allocate memory ... and copy ..." What is not clear to me is whether this means the allocated memory must be on the device (which is what I want).

 

Also, I'm unclear on how one uses CL_MEM_ALLOC_HOST_PTR. If I use this, obviously memory is allocated on the host but are the contents copied to the device? If the answer to the first question above is that CL_MEM_COPY_HOST_PTR requires copy, then if these two are combined, is the newly allocated memory always copied to the device? And how do I get my hands on the allocated memory? The spec is not clear that this is provided in host_ptr on output.

 

Thanks.

0 Likes
4 Replies
nou
Exemplar

you do not need use any CL_MEM_*_PTR flag.

you can get pointer to memory when you use CL_MEM_ALLOC_HOST_PTR with clGetMemObjectInfo(..., CL_MEM_HOST_PTR, ...)

0 Likes

In clCreateBuffer, if I set mem_flags to CL_MEM_USE_HOST_PTR, the spec says that the contents of the host memory may be copied to device memory. However, if I use CL_MEM_COPY_HOST_PTR, it says that the implementation will "allocate memory ... and copy ..." What is not clear to me is whether this means the allocated memory must be on the device (which is what I want).

 

 

 

Also, I'm unclear on how one uses CL_MEM_ALLOC_HOST_PTR. If I use this, obviously memory is allocated on the host but are the contents copied to the device? If the answer to the first question above is that CL_MEM_COPY_HOST_PTR requires copy, then if these two are combined, is the newly allocated memory always copied to the device?



1. It is not necessary that allocated memory will be on device. If you combine CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR, memory is allocated on host and it gets initialized with the host pointer data.

2. Contents of host allocated memory (CL_MEM_ALLOC_HOST_PTR) are not copied to device, they remain on host.

0 Likes

2. Contents of host allocated memory (CL_MEM_ALLOC_HOST_PTR) are not copied to device, they remain on host.


If so, why mapping/umpapping takes more (much more sometimes!) time then copy of this region of memory to GPU itself?
Please, look these threads for further info:
http://forums.amd.com/devforum...=129713&enterthread=y
and
http://forums.amd.com/devforum...=129722&enterthread=y
0 Likes

If so, why mapping/umpapping takes more (much more sometimes!) time then copy of this region of memory to GPU itself


I think you are right, current OpenCL implementation does create a copy of the host buffer on GPU.

I was answering from my CAL understanding (guessing CL_MEM_ALLOC_HOST_PTR is similar to cal remote resource). Time to do some benchmarking on OpenCL .

0 Likes