Hello, guys! I have a small problem while using Image buffer in OpenCL.
When I tried to use cl::CommandQueue::enqueueCopyImageToBuffer (C++ wrap) to copy one row of an image2d object to a global buffer, I always get a CL_INVALID_VALUE(-30) error.
src_origin = [0, k, 0];
region = [width, 1, 1];
dst_offset = 0;
I'm sure that width*1*1*element_size <= buffer_size. However, I'm not sure about "src_origin + region inside the image". How do these two varibles work together? src_origin is the start point and region is the size, right?
Thanks!
Why nobody replies this problem?
The problem could be related to 64-bit system. Apparently the same program runs fun on windows7-32bit. However, when I try it with windows7 64bit and linux 64bit, the problem remains.
Please post your code.Also mention the GPU,SDK,Driver.
I wrote a simple test program, and it returns the same error.
SDK2.2 + Driver 10.9, Ubuntu 9.10 x86-64
#include <iostream> #if defined(__APPLE__) || defined(__MACOSX) #include <OpenCL/cl.hpp> #else #include <CL/cl.hpp> #endif int main () { // initial OpenCL context, queue, device cl_int err; unsigned short device_id = 0; std::vector<cl::Platform> platforms; cl::Platform * pplatfrm = NULL; cl::Platform::get(&platforms); for (int i=0; i < platforms.size(); i++) { std::string str; pplatfrm = &platforms; pplatfrm->getInfo(CL_PLATFORM_VENDOR, &str); printf("Found platform from: %s\n", str.c_str()); if (str == "Advanced Micro Devices, Inc.") break; pplatfrm = NULL; } if (!pplatfrm) { printf("Can not find AMD platform\n"); return 1; } cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)((*pplatfrm)()), 0 }; cl::Context context(CL_DEVICE_TYPE_GPU, cps, NULL, NULL, &err); if (err != CL_SUCCESS) { printf("Context::Context() failed (%d)\n", (int) err); return EXIT_FAILURE; } std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>(); if (err != CL_SUCCESS) { printf("Context::getInfo() failed (%d)\n", (int) err); return 1; } if (devices.size() <= device_id) { printf("OCL device unavailable! \n"); return 1; } cl::Device device = devices[device_id]; cl::CommandQueue queue(context, device, 0, &err); if (err != CL_SUCCESS) { printf("CommandQueue::CommandQueue() failed (%d)\n", (int) err); return 1; } printf("OpenCL Runtime initialized.\n"); // OpenCL initialized int dim = 1024; // problem dimension int size = dim * dim; // matrix size float *host_src = new float[size]; // host data cl::ImageFormat cl_format( CL_RGBA, CL_FLOAT ); int img_width = dim / 4; // each pixel is a float4 int img_height = dim; cl::size_t<3> origin; cl::size_t<3> region; cl::size_t<3> origin_copy; cl::size_t<3> region_copy; origin[0] = 0; origin[1] = 0; origin[2] = 0; region[0] = img_width; region[1] = img_height; region[2] = 1; cl::Image2D img(context, CL_MEM_READ_WRITE, cl_format, img_width, img_height, 0, 0, &err); if (err != CL_SUCCESS) { printf("Create Image failed (%d)\n", (int) err); return 1; } cl::Buffer buf(context, CL_MEM_READ_WRITE, dim * sizeof(float), NULL, &err); if (err != CL_SUCCESS) { printf("Create Buffer failed (%d)\n", (int) err); return 1; } err = queue.enqueueWriteImage( img, CL_TRUE, origin, region, dim * sizeof(float), 0, (void*)host_src); if (err != CL_SUCCESS) { printf("Write Image failed (%d)\n", (int) err); return 0; } origin_copy[0] = 0; origin_copy[1] = 2; // any number from 0 to img_height-1 origin_copy[2] = 0; region_copy[0] = img_width/4; region_copy[1] = 1; region_copy[2] = 1; // *problem* err = queue.enqueueCopyImageToBuffer( img, buf, origin_copy, region_copy, 0); // always get a -30 error if (err != CL_SUCCESS) { printf("CopyImageToBuffer failed (%d)\n", (int) err); return 0; } // *end problem* err = queue.finish(); if (err != CL_SUCCESS) { printf("CommandQueue::finish() failed (%d)\n", (int) err); return 0; } return 0; }
wudee,
That error code means that some invalid value is present in the command.
This error normally occurs if any of the parameters in not initialized properly.
Do you pass appropriate number of parameters. The command requires 9 parameters.
Originally posted by: wudee I wrote a simple test program, and it returns the same error.
SDK2.2 + Driver 10.9, Ubuntu 9.10 x86-64
We are not able reproduce this issue with SDK2.3. Can you conform from your end.