summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/jogamp/opencl/CLContext.java21
-rw-r--r--src/com/jogamp/opencl/CLDevice.java10
-rw-r--r--src/com/jogamp/opencl/CLPlatform.java2
-rw-r--r--src/com/jogamp/opencl/CLProgramBuilder.java22
-rw-r--r--src/com/jogamp/opencl/gl/CLGLContext.java30
-rw-r--r--test/com/jogamp/opencl/HighLevelBindingTest.java25
6 files changed, 57 insertions, 53 deletions
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index 7db6e4e5..837b2ebd 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -106,14 +106,6 @@ public class CLContext extends CLObject implements CLResource {
}
/**
- * Creates a context on the specified devices.
- * The platform to be used is implementation dependent.
- */
- public static 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 CLContext create(CLPlatform platform) {
@@ -138,15 +130,18 @@ public class CLContext extends CLObject implements CLResource {
}
/**
- * Creates a context on the specified platform and with the specified
- * devices.
+ * Creates a context on the specified devices.
*/
- public static CLContext create(CLPlatform platform, CLDevice... devices) {
+ public static CLContext create(CLDevice... devices) {
- if(platform == null) {
- platform = CLPlatform.getDefault();
+ if(devices == null) {
+ throw new IllegalArgumentException("no devices specified");
+ }else if(devices[0] == null) {
+ throw new IllegalArgumentException("first device was null");
}
+ CLPlatform platform = devices[0].getPlatform();
+
PointerBuffer properties = setupContextProperties(platform);
ErrorDispatcher dispatcher = new ErrorDispatcher();
CLContext context = new CLContext(platform, createContext(dispatcher, properties, devices), dispatcher);
diff --git a/src/com/jogamp/opencl/CLDevice.java b/src/com/jogamp/opencl/CLDevice.java
index c60f63f5..d20aa30c 100644
--- a/src/com/jogamp/opencl/CLDevice.java
+++ b/src/com/jogamp/opencl/CLDevice.java
@@ -29,14 +29,17 @@ public final class CLDevice extends CLObject {
private Set<String> extensions;
private final CLDeviceInfoAccessor deviceInfo;
+ private final CLPlatform platform;
- CLDevice(CL cl, long id) {
+ CLDevice(CL cl, CLPlatform platform, long id) {
super(cl, id);
+ this.platform = platform;
this.deviceInfo = new CLDeviceInfoAccessor();
}
CLDevice(CLContext context, long id) {
super(context, id);
+ this.platform = context.getPlatform();
this.deviceInfo = new CLDeviceInfoAccessor();
}
@@ -69,6 +72,11 @@ public final class CLDevice extends CLObject {
this.context = context;
}
+ @Override
+ public CLPlatform getPlatform() {
+ return platform;
+ }
+
/**
* Returns the name of this device.
*/
diff --git a/src/com/jogamp/opencl/CLPlatform.java b/src/com/jogamp/opencl/CLPlatform.java
index 15d0639f..aef828d1 100644
--- a/src/com/jogamp/opencl/CLPlatform.java
+++ b/src/com/jogamp/opencl/CLPlatform.java
@@ -207,7 +207,7 @@ public final class CLPlatform {
//add device to list
for (int n = 0; n < deviceIDs.capacity(); n++)
- list.add(new CLDevice(cl, deviceIDs.get(n)));
+ list.add(new CLDevice(cl, this, deviceIDs.get(n)));
}
CLDevice[] devices = new CLDevice[list.size()];
diff --git a/src/com/jogamp/opencl/CLProgramBuilder.java b/src/com/jogamp/opencl/CLProgramBuilder.java
index e9440755..88543aac 100644
--- a/src/com/jogamp/opencl/CLProgramBuilder.java
+++ b/src/com/jogamp/opencl/CLProgramBuilder.java
@@ -83,7 +83,7 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa
/**
* Loads a CLProgramConfiguration containing a CLProgram.
* The CLProgram is initialized and ready to be build after this method call.
- * This method preferes program initialization from binaries if this fails or if
+ * This method prefers program initialization from binaries if this fails or if
* no binaries have been found, it will try to load the program from sources. If
* This also fails an appropriate exception will be thrown.
* @param ois The ObjectInputStream for reading the object.
@@ -231,11 +231,17 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa
return this;
}
+ // format: { platform_suffix, num_binaries, (device.ID, length, binaries)+ }
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
+
+ Set<CLDevice> devices = binariesMap.keySet();
+ String suffix = devices.iterator().next().getPlatform().getICDSuffix();
+ out.writeUTF(suffix);
+
out.writeInt(binariesMap.size());
- for (CLDevice device : binariesMap.keySet()) {
+ for (CLDevice device : devices) {
byte[] binaries = binariesMap.get(device);
out.writeLong(device.ID);
out.writeInt(binaries.length);
@@ -245,6 +251,16 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
+
+ String suffix = in.readUTF();
+ CLPlatform platform = null;
+ for (CLPlatform p : CLPlatform.listCLPlatforms()) {
+ if(p.getICDSuffix().equals(suffix)) {
+ platform = p;
+ break;
+ }
+ }
+
this.binariesMap = new LinkedHashMap<CLDevice, byte[]>();
int mapSize = in.readInt();
@@ -254,7 +270,7 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa
byte[] binaries = new byte[length];
in.readFully(binaries);
- CLDevice device = new CLDevice(CLPlatform.getLowLevelCLInterface(), deviceID);
+ CLDevice device = new CLDevice(CLPlatform.getLowLevelCLInterface(), platform, deviceID);
binariesMap.put(device, binaries);
}
}
diff --git a/src/com/jogamp/opencl/gl/CLGLContext.java b/src/com/jogamp/opencl/gl/CLGLContext.java
index f4eda602..7ce4c766 100644
--- a/src/com/jogamp/opencl/gl/CLGLContext.java
+++ b/src/com/jogamp/opencl/gl/CLGLContext.java
@@ -59,16 +59,6 @@ public final class CLGLContext extends CLContext {
}
/**
- * Creates a shared context on the specified devices.
- * The platform to be used is implementation dependent.
- * Note: This will make the GLContext current.
- * @see GLContext#makeCurrent()
- */
- public static CLGLContext create(GLContext glContext, CLDevice... devices) {
- return create(glContext, null, devices);
- }
-
- /**
* Creates a shared context on the specified platform and with the specified
* device types.
* Note: This will make the GLContext current.
@@ -95,12 +85,16 @@ public final class CLGLContext extends CLContext {
* Note: This will make the GLContext current.
* @see GLContext#makeCurrent()
*/
- public static CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice... devices) {
+ public static CLGLContext create(GLContext glContext, CLDevice... devices) {
- if(platform == null) {
- platform = CLPlatform.getDefault();
+ if(devices == null) {
+ throw new IllegalArgumentException("no devices specified");
+ }else if(devices[0] == null) {
+ throw new IllegalArgumentException("first device was null");
}
+ CLPlatform platform = devices[0].getPlatform();
+
long[] glID = new long[1];
PointerBuffer properties = setupContextProperties(platform, glContext, glID);
ErrorDispatcher dispatcher = createErrorHandler();
@@ -126,7 +120,7 @@ public final class CLGLContext extends CLContext {
}
// context must be current
- glContext.makeCurrent();
+// glContext.makeCurrent();
GLContextImpl ctxImpl = (GLContextImpl)glContext;
glID[0] = glContext.getHandle();
@@ -211,13 +205,13 @@ public final class CLGLContext extends CLContext {
public final <B extends Buffer> CLGLImage2d<B> createFromGLRenderbuffer(B directBuffer, int glBuffer, Mem... flags) {
return createFromGLRenderbuffer(directBuffer, glBuffer, Mem.flagsToInt(flags));
}
-
+
public final <B extends Buffer> CLGLImage2d<B> createFromGLRenderbuffer(B directBuffer, int glBuffer, int flags) {
CLGLImage2d<B> buffer = CLGLImage2d.createFromGLRenderbuffer(this, directBuffer, flags, glBuffer);
memoryObjects.add(buffer);
return buffer;
}
-
+
//2d Textures
public final CLGLTexture2d<?> createFromGLTexture2d(int target, int texture, int mipmap, Mem... flags) {
return createFromGLTexture2d(null, target, texture, mipmap, Mem.flagsToInt(flags));
@@ -230,13 +224,13 @@ public final class CLGLContext extends CLContext {
public final <B extends Buffer> CLGLTexture2d<B> createFromGLTexture2d(B directBuffer, int target, int texture, int mipmap, Mem... flags) {
return createFromGLTexture2d(directBuffer, target, texture, mipmap, Mem.flagsToInt(flags));
}
-
+
public final <B extends Buffer> CLGLTexture2d<B> createFromGLTexture2d(B directBuffer, int target, int texture, int mipmap, int flags) {
CLGLTexture2d<B> buffer = CLGLTexture2d.createFromGLTexture2d(this, directBuffer, target, texture, mipmap, flags);
memoryObjects.add(buffer);
return buffer;
}
-
+
//3d Textures
public final CLGLTexture3d<?> createFromGLTexture3d(int target, int texture, int mipmap, Mem... flags) {
return createFromGLTexture3d(null, target, texture, mipmap, Mem.flagsToInt(flags));
diff --git a/test/com/jogamp/opencl/HighLevelBindingTest.java b/test/com/jogamp/opencl/HighLevelBindingTest.java
index e927f1fa..3755221b 100644
--- a/test/com/jogamp/opencl/HighLevelBindingTest.java
+++ b/test/com/jogamp/opencl/HighLevelBindingTest.java
@@ -169,8 +169,8 @@ public class HighLevelBindingTest {
out.println(" - - - highLevelTest; create context - - - ");
CLPlatform platform = CLPlatform.getDefault();
- int deviceCount = platform.listCLDevices().length;
- CLDevice firstDevice = platform.listCLDevices()[0];
+ CLDevice[] devices = platform.listCLDevices();
+ int deviceCount = devices.length;
CLContext c = CLContext.create();
assertNotNull(c);
@@ -182,21 +182,18 @@ public class HighLevelBindingTest {
assertEquals(deviceCount, c.getDevices().length);
c.release();
- c = CLContext.create(firstDevice);
- assertNotNull(c);
- assertEquals(1, c.getDevices().length);
- c.release();
+ for (CLDevice device : devices) {
+ c = CLContext.create(device);
+ assertNotNull(c);
+ assertEquals(1, c.getDevices().length);
+ c.release();
+ }
c = CLContext.create(CLDevice.Type.ALL);
assertNotNull(c);
assertEquals(deviceCount, c.getDevices().length);
c.release();
- c = CLContext.create(platform, firstDevice);
- assertNotNull(c);
- assertEquals(1, c.getDevices().length);
- c.release();
-
c = CLContext.create(platform, CLDevice.Type.ALL);
assertNotNull(c);
assertEquals(deviceCount, c.getDevices().length);
@@ -217,12 +214,6 @@ public class HighLevelBindingTest {
// expected
}
try{
- CLContext.create((CLPlatform)null, (CLDevice)null);
- fail("create with null device");
- }catch(IllegalArgumentException ex) {
- // expected
- }
- try{
CLContext.create((CLPlatform)null, (CLDevice.Type)null);
fail("create with null CLDevice.Type");
}catch(IllegalArgumentException ex) {