javaopencljocl

Java OpenCL with JOCL: What is a direct buffer?


When I was experimenting on clEnqueueReadBuffer, I got an exception:

Exception in thread "main" java.lang.IllegalArgumentException: Non-blocking read operations may only be performed using pointers to direct buffers

On this line:

    ec.add(clEnqueueReadBuffer(commandQueue, zCacheMem, false, 0, Sizeof.cl_int*numWords, zCachePtr, 0 , null, readEvents[0]));

Where zCacheMem is cl_mem, zCachePtr is pointing to a int[]

I cannot find any documentation which explains this error. Can someone help?


Solution

  • Yes, you need to allocate your buffers using ByteBuffer.allocateDirect(), or use the JOCL's allocator functions.

    If you wrap a java-allocated array such as byte[] or int[] to a Buffer, it will not work.

    The direct buffers might be mapped directly to the device's address space. These are somehow 'outside' the JVM.

    Non-direct buffers are allocated in java heap and are managed by the JVM (and subject to garbage collector etc)