Allocate memory object on device only ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Allocate memory object on device only ?

fqhuy
From what I know about JOCL, the context.create****Buffer function always allocate 2 version of buffers, one in host, and one in device. However, in some cases, I need to create the device one only; to use it as a temporary buffer, for instance. Is it possible to do so ?
Reply | Threaded
Open this post in threaded view
|

Re: Allocate memory object on device only ?

Michael Bien
  Hello fqhuy,

a CLBuffer usually holds a direct allocated buffer (can be any type of
java.nio.Buffer). This buffer is used when you enqueue synchronous or
asynchronous write/read commands in a CLCommandQueue.

example (junit test):
         CLBuffer<ByteBuffer> clBufferA = context.createByteBuffer(elements*SIZEOF_INT, mem.READ_ONLY);
         CLBuffer<ByteBuffer> clBufferB = context.createByteBuffer(elements*SIZEOF_INT, mem.READ_ONLY);

         // asynchronous write of data to GPU device, blocking read later to get the computed results back.
         queue.putWriteBuffer(clBufferA, false)                                 // write A
              .putCopyBuffer(clBufferA, clBufferB, clBufferA.buffer.capacity()) // copy A -> B
              .putReadBuffer(clBufferB, true)                                   // read B
              .finish();


If you don't need this nio buffer but only the on-device counterpart use
one of the create methods with the question mark in it:

CLBuffer<?> createBuffer(int size, CLMemory.Mem... flags)
http://jogamp.org/deployment/webstart-next/javadoc/jocl/javadoc/com/jogamp/opencl/CLContext.html#createBuffer%28int,%20com.jogamp.opencl.CLMemory.Mem...%29

this will give you a CLBuffer<?> without a NIO buffer (that was
basically your question).

you can change this later at runtime if you want:
just use buffer.cloneWith(niobuffer) to get a new instance of a CLBuffer
pointing to the same device buffer but using a different NIO buffer.

(everything above applies for CLImages, CLGLBuffers and CLGLTextures also)

hope that helps,
michael


On 02/10/2011 11:16 AM, fqhuy [via jogamp] wrote:
>
> > From what I know about JOCL, the context.create****Buffer function always
> allocate 2 version of buffers, one in host, and one in device. However, in
> some cases, I need to create the device one only; to use it as a temporary
> buffer, for instance. Is it possible to do so ?
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://jogamp.762907.n3.nabble.com/Allocate-memory-object-on-device-only-tp2465039p2465039.html
> To start a new topic under jogamp, email ml-node+762907-380265080-8131@n3.nabble.com
> To unsubscribe from jogamp, visit http://jogamp.762907.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=762907&code=YmllbmF0b3JAYXJjb3IuZGV8NzYyOTA3fDQxNTEwMDY0OA==

--
http://michael-bien.com/