summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/CLContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/jogamp/opencl/CLContext.java')
-rw-r--r--src/com/jogamp/opencl/CLContext.java55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index 43755c37..7073e5d3 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -28,12 +28,14 @@
package com.jogamp.opencl;
+import com.jogamp.opencl.llb.CL;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opencl.CLDevice.Type;
import com.jogamp.opencl.CLSampler.AddressingMode;
import com.jogamp.opencl.CLSampler.FilteringMode;
import com.jogamp.common.nio.PointerBuffer;
-import com.jogamp.opencl.impl.CLImageFormatImpl;
+import com.jogamp.opencl.llb.CLContextBinding;
+import com.jogamp.opencl.llb.impl.CLImageFormatImpl;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -57,7 +59,7 @@ import static java.lang.System.*;
import static com.jogamp.opencl.CLException.*;
import static com.jogamp.common.nio.Buffers.*;
import static com.jogamp.common.os.Platform.*;
-import static com.jogamp.opencl.CL.*;
+import static com.jogamp.opencl.llb.CL.*;
import static com.jogamp.opencl.CLBuffer.*;
import static java.util.Collections.*;
@@ -79,7 +81,7 @@ import static java.util.Collections.*;
*
* @author Michael Bien
*/
-public class CLContext extends CLObject implements CLResource {
+public class CLContext extends CLObjectResource {
protected CLDevice[] devices;
@@ -94,7 +96,7 @@ public class CLContext extends CLObject implements CLResource {
private final ErrorDispatcher errorHandler;
protected CLContext(CLPlatform platform, long contextID, ErrorDispatcher dispatcher) {
- super(CLPlatform.getLowLevelCLInterface(), contextID);
+ super(contextID);
this.platform = platform;
this.programs = synchronizedSet(new HashSet<CLProgram>());
@@ -115,17 +117,17 @@ public class CLContext extends CLObject implements CLResource {
}
- private synchronized void initDevices() {
+ private synchronized void initDevices(CLContextBinding cl) {
if (devices == null) {
PointerBuffer deviceCount = PointerBuffer.allocateDirect(1);
- int ret = cl.clGetContextInfo(ID, CL.CL_CONTEXT_DEVICES, 0, null, deviceCount);
+ int ret = cl.clGetContextInfo(ID, CL_CONTEXT_DEVICES, 0, null, deviceCount);
checkForError(ret, "can not enumerate devices");
ByteBuffer deviceIDs = Buffers.newDirectByteBuffer((int)deviceCount.get());
- ret = cl.clGetContextInfo(ID, CL.CL_CONTEXT_DEVICES, deviceIDs.capacity(), deviceIDs, null);
+ ret = cl.clGetContextInfo(ID, CL_CONTEXT_DEVICES, deviceIDs.capacity(), deviceIDs, null);
checkForError(ret, "can not enumerate devices");
devices = new CLDevice[deviceIDs.capacity() / (is32Bit() ? 4 : 8)];
@@ -172,7 +174,7 @@ public class CLContext extends CLObject implements CLResource {
PointerBuffer properties = setupContextProperties(platform);
ErrorDispatcher dispatcher = new ErrorDispatcher();
- return new CLContext(platform, createContextFromType(dispatcher, properties, type), dispatcher);
+ return new CLContext(platform, createContextFromType(platform, dispatcher, properties, type), dispatcher);
}
/**
@@ -190,7 +192,7 @@ public class CLContext extends CLObject implements CLResource {
PointerBuffer properties = setupContextProperties(platform);
ErrorDispatcher dispatcher = new ErrorDispatcher();
- CLContext context = new CLContext(platform, createContext(dispatcher, properties, devices), dispatcher);
+ CLContext context = new CLContext(platform, createContext(platform, dispatcher, properties, devices), dispatcher);
if(devices != null) {
for (int i = 0; i < devices.length; i++) {
devices[i].setContext(context);
@@ -199,18 +201,17 @@ public class CLContext extends CLObject implements CLResource {
return context;
}
- protected static long createContextFromType(CLErrorHandler handler, PointerBuffer properties, long deviceType) {
-
+ protected static long createContextFromType(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, long deviceType) {
IntBuffer status = newDirectIntBuffer(1);
- long context = CLPlatform.getLowLevelCLInterface().clCreateContextFromType(properties, deviceType, handler, status);
+ CLContextBinding cl = platform.getContextBinding();
+ long context = cl.clCreateContextFromType(properties, deviceType, handler, status);
checkForError(status.get(), "can not create CL context");
return context;
}
- protected static long createContext(CLErrorHandler handler, PointerBuffer properties, CLDevice... devices) {
-
+ protected static long createContext(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, CLDevice... devices) {
IntBuffer status = newDirectIntBuffer(1);
PointerBuffer pb = null;
if(devices != null && devices.length != 0) {
@@ -223,7 +224,8 @@ public class CLContext extends CLObject implements CLResource {
pb.put(i, device.ID);
}
}
- long context = CLPlatform.getLowLevelCLInterface().clCreateContext(properties, pb, handler, status);
+ CLContextBinding cl = platform.getContextBinding();
+ long context = cl.clCreateContext(properties, pb, handler, status);
checkForError(status.get(), "can not create CL context");
@@ -231,12 +233,11 @@ public class CLContext extends CLObject implements CLResource {
}
private static PointerBuffer setupContextProperties(CLPlatform platform) {
-
if(platform == null) {
throw new RuntimeException("no OpenCL installation found");
}
- return PointerBuffer.allocateDirect(3).put(CL.CL_CONTEXT_PLATFORM)
+ return PointerBuffer.allocateDirect(3).put(CL_CONTEXT_PLATFORM)
.put(platform.ID).put(0) // 0 terminated array
.rewind();
}
@@ -497,6 +498,7 @@ public class CLContext extends CLObject implements CLResource {
*/
@Override
public synchronized void release() {
+ super.release();
try{
//release all resources
@@ -504,15 +506,12 @@ public class CLContext extends CLObject implements CLResource {
release(memoryObjects);
release(samplers);
- for (CLDevice device : getDevices()) {
- Collection<CLCommandQueue> queues = queuesMap.get(device);
- if(queues != null) {
- release(queues);
- }
+ for (List<CLCommandQueue> queues : queuesMap.values()) {
+ release(queues);
}
}finally{
- int ret = cl.clReleaseContext(ID);
+ int ret = platform.getContextBinding().clReleaseContext(ID);
checkForError(ret, "error releasing context");
}
@@ -524,8 +523,10 @@ public class CLContext extends CLObject implements CLResource {
private CLImageFormat[] getSupportedImageFormats(int flags, int type) {
+ CLContextBinding binding = platform.getContextBinding();
+
int[] entries = new int[1];
- int ret = cl.clGetSupportedImageFormats(ID, flags, type, 0, null, entries, 0);
+ int ret = binding.clGetSupportedImageFormats(ID, flags, type, 0, null, entries, 0);
if(ret != CL_SUCCESS) {
throw newException(ret, "error calling clGetSupportedImageFormats");
}
@@ -537,7 +538,7 @@ public class CLContext extends CLObject implements CLResource {
CLImageFormat[] formats = new CLImageFormat[count];
CLImageFormatImpl impl = CLImageFormatImpl.create(newDirectByteBuffer(count * CLImageFormatImpl.size()));
- ret = cl.clGetSupportedImageFormats(ID, flags, type, count, impl, null, 0);
+ ret = binding.clGetSupportedImageFormats(ID, flags, type, count, impl, null);
if(ret != CL_SUCCESS) {
throw newException(ret, "error calling clGetSupportedImageFormats");
}
@@ -629,7 +630,7 @@ public class CLContext extends CLObject implements CLResource {
* Returns all devices associated with this CLContext.
*/
public CLDevice[] getDevices() {
- initDevices();
+ initDevices(platform.getContextBinding());
return devices;
}
@@ -637,7 +638,7 @@ public class CLContext extends CLObject implements CLResource {
* Return the low level OpenCL interface.
*/
public CL getCL() {
- return cl;
+ return getPlatform().getCLBinding();
}
CLDevice getDevice(long dID) {