summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-10-25 18:35:46 +0100
committerMichael Bien <[email protected]>2009-10-25 18:35:46 +0100
commit30cd68083930688693ebdfefdeda609d857a2c8a (patch)
tree96f7a2625bb393510ded578566f2378bc25c856a /src
parent054e5005d1429ba6ea4f9283eee2988ff54d1abb (diff)
implemented clCreateContext(...) and updated Tests and high level binding.
Diffstat (limited to 'src')
-rw-r--r--src/com/mbien/opencl/CLContext.java61
-rw-r--r--src/com/mbien/opencl/CLDevice.java22
2 files changed, 70 insertions, 13 deletions
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java
index 81ac58f0..68ff131c 100644
--- a/src/com/mbien/opencl/CLContext.java
+++ b/src/com/mbien/opencl/CLContext.java
@@ -66,29 +66,44 @@ public final class CLContext {
}
/**
- * Creates a default context on all available devices (CL_DEVICE_TYPE_ALL).
+ * Creates a context on all available devices (CL_DEVICE_TYPE_ALL).
* The platform to be used is implementation dependent.
*/
public static final CLContext create() {
- return createContext(null, CL.CL_DEVICE_TYPE_ALL);
+ return createContextFromType(null, CL.CL_DEVICE_TYPE_ALL);
}
/**
- * Creates a default context on the specified device types.
+ * Creates a context on the specified device types.
* The platform to be used is implementation dependent.
*/
public static final CLContext create(CLDevice.Type... deviceTypes) {
return create(null, deviceTypes);
}
+ /**
+ * Creates a context on the specified devices.
+ * The platform to be used is implementation dependent.
+ */
+ public static final CLContext create(CLDevice... devices) {
+ return create(null, devices);
+ }
+
+ /**
+ * Creates a context on the specified platform on all available devices (CL_DEVICE_TYPE_ALL).
+ */
+ public static final CLContext create(CLPlatform platform) {
+ 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 default context on the specified platform and with the specified
+ * Creates a context on the specified platform and with the specified
* device types.
*/
private static final CLContext create(CLPlatform platform, CLDevice.Type... deviceTypes) {
- int type = 0;
+ long type = 0;
if(deviceTypes != null) {
for (int i = 0; i < deviceTypes.length; i++) {
type |= deviceTypes[i].CL_TYPE;
@@ -102,10 +117,32 @@ public final class CLContext {
properties.rewind();
}
- return createContext(properties, type);
+ return createContextFromType(properties, type);
+ }
+
+ /**
+ * Creates a context on the specified platform and with the specified
+ * devices.
+ */
+ private static final CLContext create(CLPlatform platform, CLDevice... devices) {
+
+ long[] deviceIDs = new long[devices.length];
+
+ for (int i = 0; i < devices.length; i++) {
+ deviceIDs[i] = devices[i].ID;
+ }
+
+ IntBuffer properties = null;
+ if(platform != null) {
+ properties = IntBuffer.allocate(3);
+ properties.put(CL.CL_CONTEXT_PLATFORM).put((int)platform.ID).put(0); // TODO check if this has to be int or long
+ properties.rewind();
+ }
+
+ return createContext(properties, deviceIDs);
}
- private static final CLContext createContext(IntBuffer properties, long deviceType) {
+ private static final CLContext createContextFromType(IntBuffer properties, long deviceType) {
IntBuffer status = IntBuffer.allocate(1);
long context = CLPlatform.getLowLevelBinding().clCreateContextFromType(properties, deviceType, null, null, status);
@@ -115,6 +152,16 @@ public final class CLContext {
return new CLContext(context);
}
+ private static final CLContext createContext(IntBuffer properties, long[] devices) {
+
+ IntBuffer status = IntBuffer.allocate(1);
+ long context = CLPlatform.getLowLevelBinding().clCreateContext(properties, devices, null, null, status);
+
+ checkForError(status.get(), "can not create CL context");
+
+ return new CLContext(context);
+ }
+
/**
* Creates a program from the given sources, the program is not build yet.
*/
diff --git a/src/com/mbien/opencl/CLDevice.java b/src/com/mbien/opencl/CLDevice.java
index 0ad8f0e9..de49aafa 100644
--- a/src/com/mbien/opencl/CLDevice.java
+++ b/src/com/mbien/opencl/CLDevice.java
@@ -255,21 +255,31 @@ public final class CLDevice {
*/
ACCELERATOR(CL.CL_DEVICE_TYPE_ACCELERATOR),
/**
- * CL_DEVICE_TYPE_DEFAULT
+ * CL_DEVICE_TYPE_DEFAULT. This type can be used for creating a context on
+ * the default device, a single device can never have this type.
*/
- DEFAULT(CL.CL_DEVICE_TYPE_DEFAULT);
+ DEFAULT(CL.CL_DEVICE_TYPE_DEFAULT),
+ /**
+ * CL_DEVICE_TYPE_ALL. This type can be used for creating a context on
+ * all devices, a single device can never have this type.
+ */
+ ALL(CL.CL_DEVICE_TYPE_ALL);
/**
* Value of wrapped OpenCL device type.
*/
- public final int CL_TYPE;
+ public final long CL_TYPE;
- private Type(int CL_TYPE) {
+ private Type(long CL_TYPE) {
this.CL_TYPE = CL_TYPE;
}
- public static Type valueOf(int clDeviceType) {
- switch(clDeviceType) {
+ public static Type valueOf(long clDeviceType) {
+
+ if(clDeviceType == CL.CL_DEVICE_TYPE_ALL)
+ return ALL;
+
+ switch((int)clDeviceType) {
case(CL.CL_DEVICE_TYPE_DEFAULT):
return DEFAULT;
case(CL.CL_DEVICE_TYPE_CPU):