summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLCommandQueue.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-10-19 23:02:09 +0200
committerMichael Bien <[email protected]>2009-10-19 23:02:09 +0200
commit224985638b2a1486e4b7da1642a4f2cc22fc8644 (patch)
tree2540189dc43f6d6b67001cab1e7d1332ffa14dc3 /src/com/mbien/opencl/CLCommandQueue.java
parentcb7fa23952a10795215eda50848530828b92895e (diff)
initial import of CLCommandQueue.
updated JUnit test to test CLCommandQueue. cleand up project dependencies.
Diffstat (limited to 'src/com/mbien/opencl/CLCommandQueue.java')
-rw-r--r--src/com/mbien/opencl/CLCommandQueue.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLCommandQueue.java b/src/com/mbien/opencl/CLCommandQueue.java
new file mode 100644
index 00000000..ff91131b
--- /dev/null
+++ b/src/com/mbien/opencl/CLCommandQueue.java
@@ -0,0 +1,77 @@
+package com.mbien.opencl;
+
+import static com.mbien.opencl.CLException.*;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class CLCommandQueue {
+
+ public final long ID;
+ private final CLContext context;
+ private final CL cl;
+
+ CLCommandQueue(CLContext context, CLDevice device, long properties) {
+ this.context = context;
+ this.cl = context.cl;
+
+ int[] status = new int[1];
+ this.ID = cl.clCreateCommandQueue(context.ID, device.ID, properties, status, 0);
+
+ if(status[0] != CL.CL_SUCCESS)
+ throw new CLException(status[0], "can not create command queue on "+device);
+ }
+
+ public CLCommandQueue putWriteBuffer(CLBuffer writeBuffer, boolean blockingWrite) {
+
+ int ret = cl.clEnqueueWriteBuffer(
+ ID, writeBuffer.ID, blockingWrite ? CL.CL_TRUE : CL.CL_FALSE,
+ 0, writeBuffer.buffer.capacity(), writeBuffer.buffer,
+ 0, null, 0,
+ null, 0 );
+
+ if(ret != CL.CL_SUCCESS)
+ throw new CLException(ret, "can not enqueue WriteBuffer: " + writeBuffer);
+
+ return this;
+ }
+
+ public CLCommandQueue putReadBuffer(CLBuffer readBuffer, boolean blockingRead) {
+
+ int ret = cl.clEnqueueReadBuffer(
+ ID, readBuffer.ID, blockingRead ? CL.CL_TRUE : CL.CL_FALSE,
+ 0, readBuffer.buffer.capacity(), readBuffer.buffer,
+ 0, null, 0,
+ null, 0 );
+
+ if(ret != CL.CL_SUCCESS)
+ throw new CLException(ret, "can not enqueue ReadBuffer: " + readBuffer);
+
+ return this;
+ }
+
+ public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, long[] globalWorkOffset, long[] globalWorkSize, long[] localWorkSize) {
+
+ int ret = cl.clEnqueueNDRangeKernel(
+ ID, kernel.ID, 1,
+ null, 0,
+ globalWorkSize, 0,
+ localWorkSize, 0,
+ 0,
+ null, 0,
+ null, 0 );
+
+ if(ret != CL.CL_SUCCESS)
+ throw new CLException(ret, "can not enqueue NDRangeKernel: " + kernel);
+
+ return this;
+ }
+
+ public void release() {
+ int ret = cl.clReleaseCommandQueue(ID);
+ checkForError(ret, "can not release command queue");
+ }
+
+
+}