Using clCreateSubBuffer

2020-07-27 16:30发布

问题:

I am trying to use create a subBuffer to read in a chunk of the buffer created from a 1-D vector. This is the code I am using:

d_treeArray = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_uint)*total,NULL,&err);
cl_buffer_region region;
region.origin = 0; // This works
//region.origin = 4; // This doesnt work
region.size = 10*sizeof(cl_uint);
d_subtreeArray = clCreateSubBuffer(d_treeArray,CL_MEM_READ_WRITE,CL_BUFFER_CREATE_TYPE_REGION, &region, &err);
if(err != CL_SUCCESS) {
      std::cout << "Cannot set buffers" << std::endl;
      exit(1);
}

Now when I give the region.origin as anything other than 0, I am getting -13 error (CL_INVALID_VALUE) which according to the help, means the region origin and size is out of bounds of the buffer. What might be the reason for this?

回答1:

I believe the error code -13 is for CL_MISALIGNED_SUB_BUFFER_OFFSET. Make sure the offset is aligned to the device's' CL_DEVICE_MEM_BASE_ADDR_ALIGN. The value is usually between 1024 and 4096.



标签: opencl