summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2011-09-18 02:52:35 +0200
committerMichael Bien <[email protected]>2011-09-18 02:52:35 +0200
commit953c64c02c61ec6fe2756105cd1a06967cb3d765 (patch)
treef8f365e10c37a47086f3eb0cd72373337a60c3ad
parent58eca7ee6b1743f471576ff77c6508dd2a886595 (diff)
introduced CLResourceQueueContext CLQueueContext implementation.
-rw-r--r--src/com/jogamp/opencl/util/concurrent/CLQueueContext.java40
-rw-r--r--src/com/jogamp/opencl/util/pp/Reduction.java48
2 files changed, 42 insertions, 46 deletions
diff --git a/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java b/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java
index 6dd5aa19..9624b286 100644
--- a/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java
+++ b/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java
@@ -66,14 +66,12 @@ public abstract class CLQueueContext implements CLResource {
* A simple queue context holding a precompiled program and its kernels.
* @author Michael Bien
*/
- public static class CLSingleProgramQueueContext extends CLQueueContext {
+ public static class CLSingleProgramQueueContext extends CLResourceQueueContext<CLProgram> {
- public final CLProgram program;
public final Map<String, CLKernel> kernels;
public CLSingleProgramQueueContext(CLCommandQueue queue, CLProgram program) {
- super(queue);
- this.program = program;
+ super(queue, program);
this.kernels = program.createCLKernels();
}
@@ -90,23 +88,47 @@ public abstract class CLQueueContext implements CLResource {
}
public CLProgram getProgram() {
- return program;
+ return getResource();
}
+ }
+
+ /**
+ * {@link CLQueueContext} serving a single {@link CLResource}.
+ */
+ public static class CLResourceQueueContext<R extends CLResource> extends CLQueueContext {
+
+ public final R resource;
+
+ public CLResourceQueueContext(CLCommandQueue queue, R resource) {
+ super(queue);
+ this.resource = resource;
+ }
+
@Override
public void release() {
- synchronized(program) {
- if(!program.isReleased()) {
- program.release();
+ synchronized(resource) {
+ if(!resource.isReleased()) {
+ resource.release();
}
}
}
@Override
public boolean isReleased() {
- return program.isReleased();
+ return resource.isReleased();
}
+ public R getResource() {
+ return resource;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName()+"["+resource+"]";
+ }
+
}
+
}
diff --git a/src/com/jogamp/opencl/util/pp/Reduction.java b/src/com/jogamp/opencl/util/pp/Reduction.java
index 1e75819f..e5e13ef7 100644
--- a/src/com/jogamp/opencl/util/pp/Reduction.java
+++ b/src/com/jogamp/opencl/util/pp/Reduction.java
@@ -29,7 +29,6 @@
*/
package com.jogamp.opencl.util.pp;
-import com.jogamp.opencl.util.CLProgramConfiguration;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.LongBuffer;
@@ -43,6 +42,8 @@ import com.jogamp.opencl.CLWork.CLWork1D;
import com.jogamp.opencl.util.CLUtil;
import com.jogamp.opencl.util.concurrent.CLQueueContext;
import com.jogamp.opencl.util.concurrent.CLTask;
+import com.jogamp.opencl.util.concurrent.CLQueueContext.CLResourceQueueContext;
+import com.jogamp.opencl.util.CLProgramConfiguration;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
@@ -104,7 +105,7 @@ public class Reduction<B extends Buffer> implements CLResource {
return create(queue.getContext(), op, elementType);
}
- public static <B extends Buffer> CLTask<CLReductionQueueContext<B>, B> createTask(B input, B output, OP op, Class<B> elementType) {
+ public static <B extends Buffer> CLTask<CLResourceQueueContext<Reduction<B>>, B> createTask(B input, B output, OP op, Class<B> elementType) {
return new CLReductionTask<B>(input, output, op, elementType);
}
@@ -384,7 +385,9 @@ public class Reduction<B extends Buffer> implements CLResource {
}
}
- private static class CLReductionTask<B extends Buffer> extends CLTask<CLReductionQueueContext<B>, B> {
+ private static class CLReductionTask<B extends Buffer> extends CLTask<CLResourceQueueContext<Reduction<B>>, B> {
+
+ private final static int TYPE_ID = 1;
private final B input;
private final B output;
@@ -397,18 +400,18 @@ public class Reduction<B extends Buffer> implements CLResource {
this.output = output;
this.op = op;
this.elementType = elementType;
- this.KEY = op.ordinal() + 100*TYPE.valueOf(elementType).ordinal();
+ this.KEY = TYPE_ID + op.ordinal()*10 + 1000*TYPE.valueOf(elementType).ordinal();
}
@Override
- public CLReductionQueueContext<B> createQueueContext(CLCommandQueue queue) {
+ public CLResourceQueueContext<Reduction<B>> createQueueContext(CLCommandQueue queue) {
Reduction<B> reduction = Reduction.create(queue, op, elementType);
- return new CLReductionQueueContext<B>(queue, reduction);
+ return new CLQueueContext.CLResourceQueueContext<Reduction<B>>(queue, reduction);
}
@Override
- public B execute(CLReductionQueueContext<B> context) {
- return context.reduction.reduce(context.queue, input, output);
+ public B execute(CLResourceQueueContext<Reduction<B>> context) {
+ return context.resource.reduce(context.queue, input, output);
}
@Override
@@ -422,33 +425,4 @@ public class Reduction<B extends Buffer> implements CLResource {
}
}
- /**
- * Context required for executing {@link Reduction} {@link CLTask}s.
- * @author Michael Bien
- */
- public static class CLReductionQueueContext<B extends Buffer> extends CLQueueContext {
-
- private final Reduction<B> reduction;
-
- private CLReductionQueueContext(CLCommandQueue queue, Reduction<B> reduction) {
- super(queue);
- this.reduction = reduction;
- }
-
- @Override
- public void release() {
- reduction.release();
- }
-
- @Override
- public boolean isReleased() {
- return reduction.isReleased();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName()+"["+reduction+"]";
- }
- }
-
}