summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLEvent.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-01-15 16:45:29 +0100
committerMichael Bien <[email protected]>2010-01-15 16:45:29 +0100
commit64f212c105fd0f23e8116307b64ee4b87928823d (patch)
tree02adbfa7a3ef1a9b0c5379ae86a9fe1187b7314c /src/com/mbien/opencl/CLEvent.java
parentd446e57f45811c23da651f7a5f481ddaed4c01c6 (diff)
CLInfoAccessor uses now threadlocal direct nio buffers for all operations.
javadoc improvements. added event based profiling functionality.
Diffstat (limited to 'src/com/mbien/opencl/CLEvent.java')
-rw-r--r--src/com/mbien/opencl/CLEvent.java83
1 files changed, 80 insertions, 3 deletions
diff --git a/src/com/mbien/opencl/CLEvent.java b/src/com/mbien/opencl/CLEvent.java
index 0855ec7e..1855fea9 100644
--- a/src/com/mbien/opencl/CLEvent.java
+++ b/src/com/mbien/opencl/CLEvent.java
@@ -1,12 +1,17 @@
package com.mbien.opencl;
+import com.sun.gluegen.runtime.PointerBuffer;
import java.nio.Buffer;
import static com.mbien.opencl.CL.*;
import static com.mbien.opencl.CLException.*;
/**
- *
+ * Event objects can be used for synchronizing command queues, e.g you can wait until a
+ * event accures or they can also be used to capture profiling information that
+ * measure execution time of a command.
+ * Profiling of OpenCL commands can be enabled by using a {@link com.mbien.opencl.CLCommandQueue} created with
+ * {@link com.mbien.opencl.CLCommandQueue.Mode#PROFILING_MODE}.
* @author Michael Bien
*/
public class CLEvent implements CLResource {
@@ -17,12 +22,14 @@ public class CLEvent implements CLResource {
private final CL cl;
private final CLEventInfoAccessor eventInfo;
+ private final CLEventProfilingInfoAccessor eventProfilingInfo;
CLEvent(CLContext context, long id) {
this.context = context;
this.cl = context.cl;
this.ID = id;
this.eventInfo = new CLEventInfoAccessor();
+ this.eventProfilingInfo = new CLEventProfilingInfoAccessor();
}
public void release() {
@@ -40,6 +47,11 @@ public class CLEvent implements CLResource {
return CommandType.valueOf(status);
}
+ public long getProfilingInfo(ProfilingCommand command) {
+ return eventProfilingInfo.getLong(command.COMMAND);
+ }
+
+
@Override
public String toString() {
return "CLEvent [id: " + ID
@@ -78,12 +90,77 @@ public class CLEvent implements CLResource {
private class CLEventInfoAccessor extends CLInfoAccessor {
@Override
- protected int getInfo(int name, long valueSize, Buffer value, long[] valueSizeRet, int valueSizeRetOffset) {
- return cl.clGetEventInfo(ID, name, valueSize, value, valueSizeRet, valueSizeRetOffset);
+ protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
+ return cl.clGetEventInfo(ID, name, valueSize, value, valueSizeRet);
+ }
+
+ }
+
+ private class CLEventProfilingInfoAccessor extends CLInfoAccessor {
+
+ @Override
+ protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
+ return cl.clGetEventProfilingInfo(ID, name, valueSize, value, valueSizeRet);
+ }
+
+ }
+
+ // TODO merge with ExecutionStatus?
+
+ public enum ProfilingCommand {
+
+ /**
+ * A 64-bit value that describes the current device time counter in nanoseconds
+ * when the command identified by event is enqueued in a command-queue by the host.
+ */
+ QUEUED(CL_PROFILING_COMMAND_QUEUED),
+
+ /**
+ * A 64-bit value that describes the current device time counter in nanoseconds when
+ * the command identified by event that has been enqueued is submitted by the host to
+ * the device associated with the commandqueue.
+ */
+ SUBMIT(CL_PROFILING_COMMAND_SUBMIT),
+
+ /**
+ * A 64-bit value that describes the current device time counter in nanoseconds when
+ * the command identified by event starts execution on the device.
+ */
+ START(CL_PROFILING_COMMAND_START),
+
+ /**
+ * A 64-bit value that describes the current device time counter in nanoseconds when
+ * the command identified by event has finished execution on the device.
+ */
+ END(CL_PROFILING_COMMAND_END);
+
+ /**
+ * Value of wrapped OpenCL profiling command.
+ */
+ public final int COMMAND;
+
+ private ProfilingCommand(int command) {
+ this.COMMAND = command;
+ }
+
+ public static ProfilingCommand valueOf(int status) {
+ switch(status) {
+ case(CL_PROFILING_COMMAND_QUEUED):
+ return QUEUED;
+ case(CL_PROFILING_COMMAND_SUBMIT):
+ return SUBMIT;
+ case(CL_PROFILING_COMMAND_START):
+ return START;
+ case(CL_PROFILING_COMMAND_END):
+ return END;
+ }
+ return null;
}
}
+
+
public enum ExecutionStatus {
/**