Marco13

Arguments for clEnqueueReadBufferRect

Discussion created by Marco13 on Aug 12, 2010
Latest reply on Aug 13, 2010 by Marco13
Setup for copying a region from a 2D int buffer

Hello,

I'm wondering about the right setup for the clEnqueueReadBufferRect function. I tried to boil it down to a minimum test case: In the attached example, a buffer of 4x4 ints is created. Then the clEnqueueReadBufferRect should be used to copy a region with origin (0,0) and a size of 3x3 ints. However, it keeps saying "CL_INVALID_VALUE". (With a region of size 2x2 it works, but I assume that it copies only garbage then)

Can anyone give me a hint or an example how this function may be used, or tell me what's wrong with the function arguments in the example?

 

 

 

#include <cstdio> #include <cstdlib> #include <iostream> #include <CL/cl.hpp> int main() { // --->--- Initialization stuff cl_platform_id platform; clGetPlatformIDs(1, &platform, NULL); cl_context_properties contextProperties[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 }; cl_context context = clCreateContextFromType( contextProperties, CL_DEVICE_TYPE_CPU, NULL, NULL, NULL); cl_device_id device; clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(cl_device_id), &device, NULL); cl_command_queue commandQueue = clCreateCommandQueue(context, device, 0, NULL); // ---<--- Initialization stuff // Create a buffer of 4*4 ints int sizeX = 4; int sizeY = 4; int n = sizeX * sizeY; cl_mem mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*n, NULL, NULL); size_t bufferOffset[] = { 0, 0, 0 }; size_t hostOffset[] = { 0, 0, 0 }; // Copy a region of 3x3 int values from the buffer int regionSizeX = 3; int regionSizeY = 3; // The region size must be given in bytes size_t region[] = { regionSizeX * sizeof(int), regionSizeY * sizeof(int), 1 }; // These values are computed automatically when they are 0 size_t bufferRowPitch = 0; size_t bufferSlicePitch = 0; size_t hostRowPitch = 0; size_t hostSlicePitch = 0; int *regionData = new int[regionSizeX*regionSizeY]; int result = clEnqueueReadBufferRect( commandQueue, mem, true, bufferOffset, hostOffset, region, bufferRowPitch, bufferSlicePitch, hostRowPitch, hostSlicePitch, regionData, 0, NULL, NULL); if (result == CL_SUCCESS) { printf("Passed\n"); } else { printf("Failed\n"); } return 0; }

Outcomes