summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLBuffer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/mbien/opencl/CLBuffer.java')
-rw-r--r--src/com/mbien/opencl/CLBuffer.java84
1 files changed, 82 insertions, 2 deletions
diff --git a/src/com/mbien/opencl/CLBuffer.java b/src/com/mbien/opencl/CLBuffer.java
index f9f3a239..7dcd2928 100644
--- a/src/com/mbien/opencl/CLBuffer.java
+++ b/src/com/mbien/opencl/CLBuffer.java
@@ -9,13 +9,93 @@ import static com.mbien.opencl.CLException.*;
*/
public class CLBuffer {
+ public enum MEM {
+
+ /**
+ * This flag specifies that the memory object will be read and
+ * written by a kernel.
+ */
+ READ_WRITE(CL.CL_MEM_READ_WRITE),
+
+ /**
+ * This flags specifies that the memory object will be written
+ * but not read by a kernel.
+ * Reading from a buffer or image object created with WRITE_ONLY
+ * inside a kernel is undefined.
+ */
+ WRITE_ONLY(CL.CL_MEM_WRITE_ONLY),
+
+ /**
+ * This flag specifies that the memory object is a read-only memory
+ * object when used inside a kernel. Writing to a buffer or image object
+ * created withREAD_ONLY inside a kernel is undefined.
+ */
+ READ_ONLY(CL.CL_MEM_READ_ONLY);
+
+ /**
+ * If specified, it indicates that the application wants the OpenCL
+ * implementation to use memory referenced by host_ptr as the storage
+ * bits for the memory object. OpenCL implementations are allowed
+ * to cache the buffer contents pointed to by host_ptr in device memory.
+ * This cached copy can be used when kernels are executed on a device.
+ */
+// USE_HOST_PTR(CL.CL_MEM_USE_HOST_PTR),
+
+// ALLOC_HOST_PTR(CL.CL_MEM_ALLOC_HOST_PTR), // this is the default in java world anyway
+
+ /**
+ * If CL_MEM_COPY_HOST_PTR specified, it indicates that the application
+ * wants the OpenCL implementation to allocate memory for the memory object
+ * and copy the data from memory referenced by host_ptr.<br/>
+ * COPY_HOST_PTR and USE_HOST_PTR are mutually exclusive.
+ */
+// COPY_HOST_PTR(CL.CL_MEM_COPY_HOST_PTR);
+
+ /**
+ * Value of wrapped OpenCL flag.
+ */
+ public final int CL_FLAG;
+
+ private MEM(int CL_TYPE) {
+ this.CL_FLAG = CL_TYPE;
+ }
+
+ public static MEM valueOf(int bufferFlag) {
+ switch(bufferFlag) {
+ case(CL.CL_MEM_READ_WRITE):
+ return READ_WRITE;
+ case(CL.CL_MEM_READ_ONLY):
+ return READ_ONLY;
+// case(CL.CL_MEM_USE_HOST_PTR):
+// return USE_HOST_PTR;
+// case(CL.CL_MEM_ALLOC_HOST_PTR):
+// return ALLOC_HOST_PTR;
+// case(CL.CL_MEM_COPY_HOST_PTR):
+// return COPY_HOST_PTR;
+ }
+ return null;
+ }
+
+ static int flagsToInt(MEM[] flags) {
+ int clFlags = CL.CL_MEM_READ_WRITE;
+ if(flags != null) {
+ for (int i = 0; i < flags.length; i++) {
+ clFlags |= flags[i].CL_FLAG;
+ }
+ }
+ return clFlags;
+ }
+
+ }
+
+
public final ByteBuffer buffer;
public final long ID;
private final CLContext context;
private final CL cl;
- CLBuffer(CLContext context, int flags, ByteBuffer directBuffer) {
+ CLBuffer(CLContext context, ByteBuffer directBuffer, int flags) {
if(!directBuffer.isDirect())
throw new IllegalArgumentException("buffer is not a direct buffer");
@@ -34,7 +114,7 @@ public class CLBuffer {
public void release() {
int ret = cl.clReleaseMemObject(ID);
- context.bufferReleased(this);
+ context.onBufferReleased(this);
checkForError(ret, "can not release mem object");
}