summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.xml2
-rw-r--r--resources/cl-common.cfg3
-rw-r--r--resources/cl-impl.cfg6
-rw-r--r--resources/clImplCustomCode.c18
-rw-r--r--resources/clImplCustomCode.java4
-rw-r--r--src/com/mbien/opencl/CLProgram.java41
-rw-r--r--test/com/mbien/opencl/CLProgramTest.java48
7 files changed, 104 insertions, 18 deletions
diff --git a/build.xml b/build.xml
index 5d69536f..dcae6d78 100644
--- a/build.xml
+++ b/build.xml
@@ -55,7 +55,7 @@
<gluegen src="resources/opencl.h"
config="resources/cl-impl.cfg"
includeRefid="jocl.include.path"
- emitter="com.sun.gluegen.JavaEmitter">
+ emitter="com.sun.gluegen.procaddress.ProcAddressEmitter">
<classpath refid="gluegen.classpath" />
</gluegen>
<echo message=" - - - JOCL binding files generated - - - "/>
diff --git a/resources/cl-common.cfg b/resources/cl-common.cfg
index e7d761ca..46ee61e5 100644
--- a/resources/cl-common.cfg
+++ b/resources/cl-common.cfg
@@ -72,10 +72,11 @@ NioDirectOnly clGetProgramInfo
NioDirectOnly clGetSamplerInfo
NioDirectOnly clSetCommandQueueProperty
NioDirectOnly clWaitForEvents
-
#NioDirectOnly clCreateContext
#NioDirectOnly clBuildProgram
+#extensions
+NioDirectOnly clGetGLContextInfoKHR
#common rename emitted struct accessors
#struct cl_image_format
diff --git a/resources/cl-impl.cfg b/resources/cl-impl.cfg
index c2af12cf..ec2718df 100644
--- a/resources/cl-impl.cfg
+++ b/resources/cl-impl.cfg
@@ -16,6 +16,12 @@ ClassJavadoc CLImpl */
ImplJavaClass CLImpl
Implements CLImpl CLGLI
+EmitProcAddressTable true
+ProcAddressTableClassName CLProcAddressTable
+GetProcAddressTableExpr addressTable
+ProcAddressNameExpr $UpperCase(arg)
+ForceProcAddressGen clGetGLContextInfoKHR
+
#append to generated c files
CustomCCode #include <CL/cl.h>
CustomCCode #include <GL3/gl3.h>
diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c
index 864edc6b..a0b91f35 100644
--- a/resources/clImplCustomCode.c
+++ b/resources/clImplCustomCode.c
@@ -28,19 +28,19 @@ JNIEXPORT jlong JNICALL
Java_com_mbien_opencl_impl_CLImpl_clCreateContextFromType1(JNIEnv *env, jobject _unused,
jobject props, jint props_byte_offset, jlong device_type, jobject cb, jobject data, jobject errcode, jint errcode_byte_offset) {
- intptr_t * _props_ptr = NULL;
+ cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
cl_context _ctx;
if (props != NULL) {
- _props_ptr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, props, NULL)) + props_byte_offset);
+ _props_ptr = (cl_context_properties*) (((char*) (*env)->GetPrimitiveArrayCritical(env, props, NULL)) + props_byte_offset);
}
if (errcode != NULL) {
_errcode_ptr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, errcode, NULL)) + errcode_byte_offset);
}
//TODO callback; payload
- _ctx = clCreateContextFromType((cl_context_properties *) _props_ptr, (uint64_t) device_type, NULL, NULL, (int32_t *) _errcode_ptr);
+ _ctx = clCreateContextFromType(_props_ptr, (uint64_t) device_type, NULL, NULL, (int32_t *) _errcode_ptr);
if (errcode != NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, errcode, _errcode_ptr, 0);
@@ -49,7 +49,7 @@ Java_com_mbien_opencl_impl_CLImpl_clCreateContextFromType1(JNIEnv *env, jobject
(*env)->ReleasePrimitiveArrayCritical(env, props, _props_ptr, 0);
}
- return (jlong)_ctx;
+ return (jlong) (intptr_t)_ctx;
}
/*
@@ -66,14 +66,14 @@ JNIEXPORT jlong JNICALL
Java_com_mbien_opencl_impl_CLImpl_clCreateContext1(JNIEnv *env, jobject _unused,
jobject props, jint props_byte_offset, jint numDevices, jobject deviceList, jobject cb, jobject data, jobject errcode, jint errcode_byte_offset) {
- intptr_t * _props_ptr = NULL;
+ cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
size_t * _deviceListPtr = NULL;
cl_context _ctx;
if (props != NULL) {
- _props_ptr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, props, NULL)) + props_byte_offset);
+ _props_ptr = (cl_context_properties*) (((char*) (*env)->GetPrimitiveArrayCritical(env, props, NULL)) + props_byte_offset);
}
if (deviceList != NULL) {
_deviceListPtr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, deviceList, NULL)) /*+ device_byte_offset*/);
@@ -83,7 +83,7 @@ Java_com_mbien_opencl_impl_CLImpl_clCreateContext1(JNIEnv *env, jobject _unused,
}
// TODO payload, callback...
- _ctx = clCreateContext((cl_context_properties *) _props_ptr, numDevices, (cl_device_id *)_deviceListPtr, NULL, NULL, (int32_t *) _errcode_ptr);
+ _ctx = clCreateContext(_props_ptr, numDevices, (cl_device_id *)_deviceListPtr, NULL, NULL, (int32_t *) _errcode_ptr);
if (errcode != NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, errcode, _errcode_ptr, 0);
@@ -95,7 +95,7 @@ Java_com_mbien_opencl_impl_CLImpl_clCreateContext1(JNIEnv *env, jobject _unused,
(*env)->ReleasePrimitiveArrayCritical(env, props, _props_ptr, 0);
}
- return (jlong) _ctx;
+ return (jlong) (intptr_t)_ctx;
}
/**
@@ -140,5 +140,5 @@ Java_com_mbien_opencl_impl_CLImpl_clBuildProgram1(JNIEnv *env, jobject _unused,
(*env)->ReleaseStringUTFChars(env, options, _strchars_options);
}
- return _res;
+ return (jint)_res;
}
diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java
index c0c8365b..0a42cc12 100644
--- a/resources/clImplCustomCode.java
+++ b/resources/clImplCustomCode.java
@@ -1,4 +1,6 @@
+ CLProcAddressTable addressTable = new CLProcAddressTable();
+
public long clCreateContext(java.nio.Buffer properties, long[] devices, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret) {
if(pfn_notify != null)
@@ -51,7 +53,7 @@
/** Entry point to C language function: <code> int32_t clBuildProgram(cl_program, uint32_t, cl_device_id * , const char * , void * ); </code> */
private native int clBuildProgram1(long program, int devices, Object deviceList, String options, BuildProgramCallback cb, Object userData);
-
+
private final static void convert32To64(long[] values) {
if(values.length%2 == 1) {
values[values.length-1] = values[values.length/2]>>>32;
diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java
index 306a5b66..39663e54 100644
--- a/src/com/mbien/opencl/CLProgram.java
+++ b/src/com/mbien/opencl/CLProgram.java
@@ -29,6 +29,7 @@ public class CLProgram implements CLResource {
private Map<CLDevice, Status> buildStatusMap;
private boolean executable;
+ private boolean released;
CLProgram(CLContext context, String src) {
@@ -127,10 +128,12 @@ public class CLProgram implements CLResource {
}
}
- // TODO serialization, program build options
-
private final String getBuildInfoString(long device, int flag) {
+ if(released) {
+ return "";
+ }
+
PointerBuffer pb = PointerBuffer.allocateDirect(1);
int ret = cl.clGetProgramBuildInfo(ID, device, flag, 0, null, pb);
@@ -146,6 +149,10 @@ public class CLProgram implements CLResource {
private final String getProgramInfoString(int flag) {
+ if(released) {
+ return "";
+ }
+
PointerBuffer pb = PointerBuffer.allocateDirect(1);
int ret = cl.clGetProgramInfo(ID, flag, 0, null, pb);
@@ -254,6 +261,10 @@ public class CLProgram implements CLResource {
releaseKernels();
+ executable = false;
+ released = true;
+ buildStatusMap = null;
+
int ret = cl.clReleaseProgram(ID);
context.onProgramReleased(this);
checkForError(ret, "can not release program");
@@ -274,6 +285,9 @@ public class CLProgram implements CLResource {
* @throws IllegalArgumentException when no kernel with the specified name exists in this program.
*/
public CLKernel getCLKernel(String kernelName) {
+ if(released) {
+ return null;
+ }
initKernels();
final CLKernel kernel = kernels.get(kernelName);
if(kernel == null) {
@@ -289,6 +303,9 @@ public class CLProgram implements CLResource {
* with the kernel function names as keys.
*/
public Map<String, CLKernel> getCLKernels() {
+ if(released) {
+ return Collections.emptyMap();
+ }
initKernels();
return Collections.unmodifiableMap(kernels);
}
@@ -297,7 +314,9 @@ public class CLProgram implements CLResource {
* Returns all devices associated with this program.
*/
public CLDevice[] getCLDevices() {
-
+ if(released) {
+ return new CLDevice[0];
+ }
PointerBuffer pb = PointerBuffer.allocateDirect(1);
int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, 0, null, pb);
checkForError(ret, "on clGetProgramInfo");
@@ -321,6 +340,9 @@ public class CLProgram implements CLResource {
* implementation dependent.
*/
public String getBuildLog() {
+ if(released) {
+ return "";
+ }
StringBuilder sb = new StringBuilder();
CLDevice[] devices = getCLDevices();
for (int i = 0; i < devices.length; i++) {
@@ -338,6 +360,9 @@ public class CLProgram implements CLResource {
* Returns the build status enum of this program for each device as Map.
*/
public Map<CLDevice,Status> getBuildStatus() {
+ if(released) {
+ return Collections.emptyMap();
+ }
initBuildStatus();
return buildStatusMap;
}
@@ -347,6 +372,9 @@ public class CLProgram implements CLResource {
* of this program exists.
*/
public boolean isExecutable() {
+ if(released) {
+ return false;
+ }
initBuildStatus();
return executable;
}
@@ -363,6 +391,9 @@ public class CLProgram implements CLResource {
* Returns the build status enum for this program on the specified device.
*/
public Status getBuildStatus(CLDevice device) {
+ if(released) {
+ return Status.BUILD_NONE;
+ }
int clStatus = getBuildInfoInt(device.ID, CL_PROGRAM_BUILD_STATUS);
return Status.valueOf(clStatus);
}
@@ -381,6 +412,10 @@ public class CLProgram implements CLResource {
*/
public Map<CLDevice, byte[]> getBinaries() {
+ if(!isExecutable()) {
+ return Collections.emptyMap();
+ }
+
CLDevice[] devices = getCLDevices();
ByteBuffer sizes = ByteBuffer.allocateDirect(8*devices.length).order(ByteOrder.nativeOrder());
diff --git a/test/com/mbien/opencl/CLProgramTest.java b/test/com/mbien/opencl/CLProgramTest.java
index 0ca0fa9e..bc095a9a 100644
--- a/test/com/mbien/opencl/CLProgramTest.java
+++ b/test/com/mbien/opencl/CLProgramTest.java
@@ -6,7 +6,6 @@ import org.junit.Test;
import static org.junit.Assert.*;
import static java.lang.System.*;
-import static com.mbien.opencl.TestUtils.*;
import static com.sun.gluegen.runtime.BufferFactory.*;
/**
@@ -31,10 +30,12 @@ public class CLProgramTest {
assertEquals(ex.errorcode, CL.CL_INVALID_PROGRAM_EXECUTABLE);
}
+ out.println(program.getBuildStatus());
program.build();
- assertTrue(program.isExecutable());
out.println(program.getBuildStatus());
+ assertTrue(program.isExecutable());
+
Map<String, CLKernel> kernels = program.getCLKernels();
assertNotNull(kernels);
assertTrue("kernel map is empty", kernels.size() > 0);
@@ -76,11 +77,52 @@ public class CLProgramTest {
// 2. re-create program with old binaries
program.release();
+ assertFalse(program.isExecutable());
+
+ assertNotNull(program.getBinaries());
+ assertEquals(program.getBinaries().size(), 0);
+
+ assertNotNull(program.getBuildLog());
+ assertEquals(program.getBuildLog().length(), 0);
+
+ assertNotNull(program.getSource());
+ assertEquals(program.getSource().length(), 0);
+
+ assertNotNull(program.getCLDevices());
+ assertEquals(program.getCLDevices().length, 0);
+
+ assertNotNull(program.getCLKernels());
+ assertEquals(program.getCLKernels().size(), 0);
+
+ assertNull(program.getCLKernel("foo"));
+
program = context.createProgram(binaries);
- out.println(program.getBuildStatus());
+ assertFalse(program.isExecutable());
+ assertNotNull(program.getCLDevices());
+ assertTrue(program.getCLDevices().length != 0);
+
+ assertNotNull(program.getBinaries());
+ assertEquals(program.getBinaries().size(), 0);
+
+ assertNotNull(program.getBuildLog());
+ assertTrue(program.getBuildLog().length() != 0);
+
+ assertNotNull(program.getSource());
+ assertEquals(program.getSource().length(), 0);
+
+ try{
+ program.getCLKernels();
+ }catch(CLException ex) {
+ // expected, not build yet
+ }
+
+ out.println(program.getBuildStatus());
program.build();
+ out.println(program.getBuildStatus());
+
+ assertNotNull(program.getCLKernel("Test"));
assertTrue(program.isExecutable());