0

I am using a kernel that has an image as a parameter with java and JOCL

input ="12.jpg";
image = createBufferedImage(input);
image = createBufferedImage(input);
DataBufferInt dataBufferSrc = (DataBufferInt)image.getRaster().getDataBuffer();
int dataSrc[] = dataBufferSrc.getData();
inputImageMem = clCreateBuffer(context, CL_MEM_READ_ONLY| CL_MEM_USE_HOST_PTR,
            dataSrc.length * Sizeof.cl_uint, Pointer.to(dataSrc), null);
clSetKernelArg(kernel, 0, Sizeof.cl_mem, Pointer.to(inputImageMem));

When I compile, I get the error:

Pointer may not point to null objects

It is in the line:

clSetKernelArg(kernel, 0, Sizeof.cl_mem, Pointer.to(inputImageMem));

What is the probable problem? How can I fix it?

PS: createBufferedImage is a function taken from JOCL samples http://jocl.org/

jonhopkins
  • 3,844
  • 3
  • 27
  • 39

1 Answers1

1

From the openCL clCreateBuffer documentation:

Returns a valid non-zero buffer object and errcode_ret is set to CL_SUCCESS if the buffer object is created successfully. Otherwise, it returns a NULL value with one of the following error values returned in errcode_ret...

The last parameter of clCreateBuffer function is an int pointer (where you want the error code to be returned). You currently have it set to null. My guess is that something failed in clCreateBuffer. I'd recommend checking the value of errcode_ret, it will contain an error code that will help you fix the issue.

Kilves
  • 1,028
  • 10
  • 13
  • In the documentation, they said that when the the value of the buffer is null it returns to NULL with one of the following error values returned in errcode_ret: **CL_INVALID_CONTEXT** or **CL_INVALID_VALUE** or **CL_INVALID_BUFFER_SIZE** or **CL_INVALID_HOST_PTR** or .....but in my code There is just : 'Pointer may not point to null objects' Is there any way to see the errors? – Nasima Info Jun 22 '16 at 17:25
  • @NasimaInfo You need to do it yourself: pass a pointer to contain the error value as the last argument of `clCreateBuffer`. I'm not entirely sure how it works in java. Pointers are C/C++ thing and java should not even use them. JOCL Pointer class seems to be some sort of a weird hack around it. Maybe create a pointer object to an integer, pass it as a last argument of `clCreateBuffer` and check if it equals any error codes somehow...? I'm not really a java expert or a pointer expert. – Kilves Jun 22 '16 at 22:45
  • 'Pointer may not point to null objects' logical, since you are calling to Pointer.to(). And Pointer is what gives you the error. But the source is in clCreateBuffer() – DarkZeros Jun 23 '16 at 01:50
  • @Kilves Yes, the pointer class is an attempt to emulate a C `void*` pointer. It's not uncommon for JNI bindings of libraries like CL,GL and others, which *heavily* make use of `void*` pointers. – Marco13 Jun 26 '16 at 02:04
  • Regarding the error: The message "Pointer may not point to null objects" is part of an `IllegalArgumentException` that is thrown when the argument to `Pointer.to(...)` is `null`. In this case, the `inputImageMem` is `null`. Usually, the `clCreatebuffer` call should not return `null`, unless there was an error. And if you have set `CL.setExceptionsEnabled(true)`, for example, at the beginning of your `main` method, then it should print messages when errors occur, even if you do *not* manually check the error code. An *compilable* example that shows what exacty you are doing would be helpful. – Marco13 Jun 26 '16 at 02:10