Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Journeyman III

error while trying to read buffer


I'm quite new with opencl, just started looking into it, so my problem might be a bit stupid. However, i've spent some time with it, before asking you .

My task is simple: upload three buffers to kernel and get one output buffer. All three are arrays of structures, Here how it looks code-wise:

output_struct* struct_ptr3 = new output_struct[CNT];
memset(struct_ptr3, 0, CNT *sizeof(output_struct));
//Creating memory buffers
cl::Buffer clmInputVector1 = cl::Buffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR , CNT  *sizeof(inp_struct) , (void*)(struct_ptr));
cl::Buffer clmInputVector2 = cl::Buffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR , CNT  *sizeof(inp_struct1) , (void*)(struct_ptr1);
cl::Buffer clmInputVector3 = cl::Buffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR , CNT1 *sizeof(inp_struct2) , (void*)(struct_ptr2);
cl::Buffer clmOutputVector = cl::Buffer(context, CL_MEM_WRITE_ONLY|CL_MEM_COPY_HOST_PTR , CNT  *sizeof(output_struct) , (void*)(struct_ptr3));
//Setting arguments to kernel
err = kernel.setArg(0, clmInputVector1);if(CL_SUCCESS != err)printf("setArg failed! %d\n\n", err);
err = kernel.setArg(1, clmInputVector2);if(CL_SUCCESS != err)printf("setArg failed! %d\n\n", err);
err = kernel.setArg(2, clmInputVector3);if(CL_SUCCESS != err)printf("setArg failed! %d\n\n", err);
err = kernel.setArg(3, clmOutputVector);if(CL_SUCCESS != err)printf("setArg failed! %d\n\n", err);
queue.enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(CNT), cl::NDRange(128));
err = queue.finish();
if(CL_SUCCESS != err)printf("cl program has failed to finish successfully!\n");
err = queue.enqueueReadBuffer(clmOutputVector, CL_TRUE, 0, CNT *sizeof(output_struct), struct_ptr3);
if(CL_SUCCESS != err)printf("enqueueReadBuffer failed! %d\n\n", err);

After successful kernel execution i get -38 error, which is CL_INVALID_MEM_OBJECT. But what is invalid about my buffer? I honestly have no idea.

Any help will be much appreciated!

1 Reply
Adept II


I could try to help. Could you please share the code so that I can try to re-create the same issue at my end? Also so that I can see the full definition of your structure.