cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

shunyo
Journeyman III

clEnqueueWriteBuffer for part of array

Jump to solution

Hi,

I want to write a part of array into the buffer and run the kernel code in parallel  for that part of the array, To do that, is there any way to directly write the part of the array to the buffer using clEnqueueWriteBuffer or do we have to write to a temporary array and then write to the buffer?

Tags (1)
0 Likes
1 Solution

Accepted Solutions
himanshu_gautam
Grandmaster

Re: clEnqueueWriteBuffer for part of array

Jump to solution

As i understand it, you have a big array at host side, and you only want to do some computations on a part of it? Are you talking about a 2-D array here, where   doing a clEnqueueWriteBuffer using a simple pointer is not possible?  clEnqueueWriteBufferRect might be helpful in that case.

You can also look into creating a subBuffer from the original cl_buffer and populate this subbuffer instead of the actual buffer. In case subBuffer is considerably smaller as compared to original buffer, you can save time for transferring data to the GPU and back.

View solution in original post

0 Likes
5 Replies
himanshu_gautam
Grandmaster

Re: clEnqueueWriteBuffer for part of array

Jump to solution

As i understand it, you have a big array at host side, and you only want to do some computations on a part of it? Are you talking about a 2-D array here, where   doing a clEnqueueWriteBuffer using a simple pointer is not possible?  clEnqueueWriteBufferRect might be helpful in that case.

You can also look into creating a subBuffer from the original cl_buffer and populate this subbuffer instead of the actual buffer. In case subBuffer is considerably smaller as compared to original buffer, you can save time for transferring data to the GPU and back.

View solution in original post

0 Likes
Meteorhead
Challenger

Re: clEnqueueWriteBuffer for part of array

Jump to solution

I don't quite understand your question.

The first part makes no sense, saying that you wish to write from a host array to a device buffer, and use that very part in a kernel simultaneously? Is the kernel running on a CPU? It is wrong to use the buffer's contents before they arrive on device, because you have no control over in what order and when data will appear (without proper syncing).

The second part, clEnqueueWrite buffer has an input parameter of a host pointer to start reading from. Why would you want to create a temporary array?

0 Likes
shunyo
Journeyman III

Re: clEnqueueWriteBuffer for part of array

Jump to solution

Meteorhead sorry if I was ambiguous.

himanshu.gautam I have a 1-D array (vector) and you are correct in understanding the question. I am looking at subBuffer and think that it works perfectly for my application. Thanks.

0 Likes
shunyo
Journeyman III

Re: clEnqueueWriteBuffer for part of array

Jump to solution

himanshu.gautam There is one problem I am encountering while using subBuffer. There is an alignment problem. So the offset needs to be set accordingly or I am getting CL_MISALIGNED_SUB_BUFFER_OFFSET error. But, the offsets are not set to the alignment in my array. So is there something else that can be done?

0 Likes
himanshu_gautam
Grandmaster

Re: clEnqueueWriteBuffer for part of array

Jump to solution

From spec:

CL_MISALIGNED_SUB_BUFFER_OFFSET if buffer is a sub-buffer object and offset specified when the sub-buffer object is created is not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue

Can you show the code used to create the actual buffer and then the subBuffer from it?

0 Likes