cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

Hi,

I would like to know what is the difference between :

oclBuff = clCreateBuffer(gpu_context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, mem_size, dataSet, &err);

 

...and...

 

oclBuff = clCreateBuffer(gpu_context, CL_MEM_READ_ONLY, mem_size, NULL, &err);

err = clEnqueueWriteBuffer(cmd_queue, dataSet, CL_TRUE, 0, mem_size, a, 0, NULL, NULL);

Which one I should use in which case ? and why ? Or it is exactly the same ?

Thanks



0 Likes
8 Replies
genaganna
Journeyman III

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

viewon01,

       In both cases, you are creating buffer and initializing the buffer with your own data.  only thing is that you are using two functions to do that in the second case.

       One difference i can tell you.   Choose first case if you want create buffer and initialize only once in whole program.   Use clEnqueueWriteBuffer if you want to update the buffer values with new data set more than once.

0 Likes
spectral
Adept II

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

Thanks for the precision,

 

Regards

0 Likes
davibu
Journeyman III

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

Originally posted by: viewon01

oclBuff = clCreateBuffer(gpu_context, CL_MEM_READ_ONLY, mem_size, NULL, &err);

err = clEnqueueWriteBuffer(cmd_queue, dataSet, CL_TRUE, 0, mem_size, a, 0, NULL, NULL);

Does clCreateBuffer() include an implicit call to clEnqueueWriteBuffer() too ?

I mean, for a read only buffer, is it required to call clEnqueueWriteBuffer() after the creation of the buffer of it is implicitaly done buy clCreateBuffer() ?

 

Thanks,

David

 

0 Likes
genaganna
Journeyman III

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

Originally posted by: davibu
Originally posted by: viewon01

oclBuff = clCreateBuffer(gpu_context, CL_MEM_READ_ONLY, mem_size, NULL, &err);

err = clEnqueueWriteBuffer(cmd_queue, dataSet, CL_TRUE, 0, mem_size, a, 0, NULL, NULL);

Does clCreateBuffer() include an implicit call to clEnqueueWriteBuffer() too ?

        No

I mean, for a read only buffer, is it required to call clEnqueueWriteBuffer() after the creation of the buffer of it is implicitaly done buy clCreateBuffer() ?

 



You need to call clEnqueueWriteBuffer if CL_MEM_COPY_HOST_PTR is not used in clCreateBuffer.  Please read spec for more details.

0 Likes
davibu
Journeyman III

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

Originally posted by: genaganna

 

You need to call clEnqueueWriteBuffer if CL_MEM_COPY_HOST_PTR is not used in clCreateBuffer.  Please read spec for more details.

 

 

Thank you very much.

 

0 Likes
_Big_Mac_
Journeyman III

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

What if there are multiple devices within the context? clCreateBuffer only takes a context as a parameter, not a command queue associated with a specific device. I've been told on Nvidia forums that clCreateBuffer with CL_MEM_COPY_HOST_PTR will copy the data to ALL devices associated with that context. So if you're only using a single device, you might be better off manually enqueuing a write to this particular device because if a user's machine has several GPUs, he will pay for several memcopies over PCIE. Is this correct?
0 Likes
n_treutner
Journeyman III

Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

Originally posted by: genaganna viewon01,

 

       In both cases, you are creating buffer and initializing the buffer with your own data.  only thing is that you are using two functions to do that in the second case.

 

       One difference i can tell you.   Choose first case if you want create buffer and initialize only once in whole program.   Use clEnqueueWriteBuffer if you want to update the buffer values with new data set more than once.

 

Your hint, what the difference is, just fixed a memory leak, that i've been working on for 2 weeks now.

Thanks!

0 Likes
tal1974
Journeyman III

Re: Difference between : clCreateBuffer OR clCreateBuffer + clEnqueueWriteBuffer

Thank you. It's very important addition.

0 Likes