From c33ac63fb62d3d27979ca56bb577c18f745f70d4 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 6 Nov 2009 03:11:14 +0100 Subject: added more buffer creation factory methods. --- src/com/mbien/opencl/CLContext.java | 63 +++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 13 deletions(-) (limited to 'src/com') diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index 2a4bd7d0..757e0498 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -1,7 +1,6 @@ package com.mbien.opencl; import com.mbien.opencl.CLBuffer.Mem; -import com.sun.gluegen.runtime.BufferFactory; import com.sun.gluegen.runtime.CPU; import java.io.BufferedReader; import java.io.IOException; @@ -10,8 +9,11 @@ import java.io.InputStreamReader; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.DoubleBuffer; +import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.LongBuffer; +import java.nio.ShortBuffer; import java.util.ArrayList; import java.util.Collections; @@ -19,6 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import static com.mbien.opencl.CLException.*; +import static com.sun.gluegen.runtime.BufferFactory.*; /** * CLContext is responsible for managing objects such as command-queues, memory, @@ -98,7 +101,6 @@ public final class CLContext { return create(platform, CLDevice.Type.ALL); } - // TODO check if driver bug, otherwise find the reason why this is not working (INVALID_VALUE with NV driver) /** * Creates a context on the specified platform and with the specified * device types. @@ -194,40 +196,75 @@ public final class CLContext { } /** - * Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer. + * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. */ - public CLBuffer createBuffer(B directBuffer, Mem... flags) { - return createBuffer(directBuffer, Mem.flagsToInt(flags)); + public final CLBuffer createShortBuffer(int size, Mem... flags) { + return createBuffer(newDirectByteBuffer(size*SIZEOF_SHORT).asShortBuffer(), flags); } - + + /** + * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. + */ + public final CLBuffer createIntBuffer(int size, Mem... flags) { + return createBuffer(newDirectByteBuffer(size*SIZEOF_INT).asIntBuffer(), flags); + } + + /** + * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. + */ + public final CLBuffer createLongBuffer(int size, Mem... flags) { + return createBuffer(newDirectByteBuffer(size*SIZEOF_LONG).asLongBuffer(), flags); + } + + /** + * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. + */ + public final CLBuffer createFloatBuffer(int size, Mem... flags) { + return createBuffer(newDirectByteBuffer(size*SIZEOF_FLOAT).asFloatBuffer(), flags); + } + + /** + * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. + */ + public final CLBuffer createDoubleBuffer(int size, Mem... flags) { + return createBuffer(newDirectByteBuffer(size*SIZEOF_DOUBLE).asDoubleBuffer(), flags); + } + /** * Creates a CLBuffer with the specified flags and buffer size in bytes. No flags creates a MEM.READ_WRITE buffer. */ - public CLBuffer createBuffer(int size, Mem... flags) { - return createBuffer(size, Mem.flagsToInt(flags)); + public final CLBuffer createByteBuffer(int size, Mem... flags) { + return createByteBuffer(size, Mem.flagsToInt(flags)); } /** * Creates a CLBuffer with the specified flags and buffer size in bytes. */ - public CLBuffer createBuffer(int size, int flags) { - return createBuffer(BufferFactory.newDirectByteBuffer(size), flags); + public final CLBuffer createByteBuffer(int size, int flags) { + return createBuffer(newDirectByteBuffer(size), flags); + } + + /** + * Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer. + */ + public final CLBuffer createBuffer(B directBuffer, Mem... flags) { + return createBuffer(directBuffer, Mem.flagsToInt(flags)); } /** * Creates a CLBuffer with the specified flags. */ - public CLBuffer createBuffer(B directBuffer, int flags) { + public final CLBuffer createBuffer(B directBuffer, int flags) { CLBuffer buffer = new CLBuffer(this, directBuffer, flags); buffers.add(buffer); return buffer; } - public CLBuffer createFromGLBuffer(B directBuffer, int glBuffer, Mem... flags) { + public final CLBuffer createFromGLBuffer(B directBuffer, int glBuffer, Mem... flags) { return createFromGLBuffer(directBuffer, glBuffer, Mem.flagsToInt(flags)); } - public CLBuffer createFromGLBuffer(B directBuffer, int glBuffer, int flags) { + public final CLBuffer createFromGLBuffer(B directBuffer, int glBuffer, int flags) { CLBuffer buffer = new CLBuffer(this, directBuffer, glBuffer, flags); buffers.add(buffer); return buffer; -- cgit v1.2.3