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, ®ion, &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?
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.