aboutsummaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
Diffstat (limited to 'resources')
-rw-r--r--resources/cl-if.cfg4
-rw-r--r--resources/cl-impl.cfg1
-rw-r--r--resources/clImplCustomCode.c66
-rw-r--r--resources/clImplCustomCode.java49
4 files changed, 94 insertions, 26 deletions
diff --git a/resources/cl-if.cfg b/resources/cl-if.cfg
index d0413d97..6f19e64f 100644
--- a/resources/cl-if.cfg
+++ b/resources/cl-if.cfg
@@ -21,12 +21,12 @@ Ignore CL_GL_.*|cl.*GL.*
Ignore clCreateContext
CustomJavaCode CL
CustomJavaCode CL /** Interface to C language function: <br> <code> cl_context {@native clCreateContext}(intptr_t * , uint32_t, cl_device_id * , void (*pfn_notify)(const char *, const void *, size_t, void *), void *, int32_t * ); </code> */
-CustomJavaCode CL public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CreateContextCallback pfn_notify, IntBuffer errcode_ret);
+CustomJavaCode CL public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CLErrorHandler pfn_notify, IntBuffer errcode_ret);
Ignore clCreateContextFromType
CustomJavaCode CL
CustomJavaCode CL /** Interface to C language function: <br> <code> cl_context {@native clCreateContextFromType}(cl_context_properties *properties, cl_device_type device_type, void (*pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data), void *user_data, cl_int *errcode_ret) ; </code> */
-CustomJavaCode CL public long clCreateContextFromType(PointerBuffer properties, long device_type, CreateContextCallback pfn_notify, IntBuffer errcode_ret);
+CustomJavaCode CL public long clCreateContextFromType(PointerBuffer properties, long device_type, CLErrorHandler pfn_notify, IntBuffer errcode_ret);
Ignore clBuildProgram
CustomJavaCode CL
diff --git a/resources/cl-impl.cfg b/resources/cl-impl.cfg
index 34753eb7..fc04d2b0 100644
--- a/resources/cl-impl.cfg
+++ b/resources/cl-impl.cfg
@@ -46,6 +46,7 @@ Ignore clCreateContext
Ignore clCreateContextFromType
Ignore clBuildProgram
Ignore clEnqueueNativeKernel
+Ignore clReleaseContext
#take buffer capacity from input param 5
ReturnValueCapacity clEnqueueMapBuffer {5}
diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c
index b491eb7f..1314e7b8 100644
--- a/resources/clImplCustomCode.c
+++ b/resources/clImplCustomCode.c
@@ -25,7 +25,7 @@ JNI_OnLoad(JavaVM * _jvm, void *reserved) {
// throws ClassNotFoundException (or other reflection stuff)
jclass buildCBClassID = (*env)->FindClass(env, "com/jogamp/opencl/impl/BuildProgramCallback");
- jclass errorHandlerClassID = (*env)->FindClass(env, "com/jogamp/opencl/CreateContextCallback");
+ jclass errorHandlerClassID = (*env)->FindClass(env, "com/jogamp/opencl/CLErrorHandler");
// throws even more reflection Exceptions
// IDs are unique and do not change
@@ -35,7 +35,7 @@ JNI_OnLoad(JavaVM * _jvm, void *reserved) {
if (errorHandlerClassID != NULL) {
cccb_mid = (*env)->GetMethodID(env, errorHandlerClassID, "onError", "(Ljava/lang/String;Ljava/nio/ByteBuffer;J)V");
}
-
+
return JNI_VERSION_1_2;
}
@@ -47,8 +47,10 @@ void buildProgramCallback(cl_program id, void * object) {
(*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
- (*env)->CallVoidMethod(env, obj, bcb_mid, (jlong)id);
- (*env)->DeleteGlobalRef(env, obj);
+ (*env)->CallVoidMethod(env, obj, bcb_mid, (jlong)id);
+ (*env)->DeleteGlobalRef(env, obj);
+
+ (*jvm)->DetachCurrentThread(jvm);
}
@@ -59,11 +61,12 @@ void createContextCallback(const char * errinfo, const void * private_info, size
(*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
- jstring errorString = (*env)->NewStringUTF(env, errinfo);
+ jstring errorString = (*env)->NewStringUTF(env, errinfo);
- //TODO private_info
- (*env)->CallVoidMethod(env, obj, cccb_mid, errorString, NULL, 0);
- //(*env)->DeleteGlobalRef(env, obj);
+ //TODO private_info
+ (*env)->CallVoidMethod(env, obj, cccb_mid, errorString, NULL, 0);
+
+ (*jvm)->DetachCurrentThread(jvm);
}
@@ -80,7 +83,7 @@ void createContextCallback(const char * errinfo, const void * private_info, size
*/
JNIEXPORT jlong JNICALL
Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject _unused,
- jobject props, jint props_byte_offset, jobject device_type, jobject cb, jobject errcode, jint errcode_byte_offset) {
+ jobject props, jint props_byte_offset, jobject device_type, jobject cb, jobject global, jobject errcode, jint errcode_byte_offset) {
cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
@@ -103,9 +106,16 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject
_ctx = clCreateContextFromType(_props_ptr, (uint64_t) device_type, pfn_notify, globalCB, (int32_t *) _errcode_ptr);
- // if something went wrong
- if (_ctx == NULL && globalCB != NULL) {
- (*env)->DeleteGlobalRef(env, globalCB);
+ if(globalCB != NULL) {
+ jlong *g = (*env)->GetPrimitiveArrayCritical(env, global, NULL);
+ // if something went wrong
+ if(_ctx == NULL) {
+ g[0] = 0;
+ (*env)->DeleteGlobalRef(env, globalCB);
+ }else{
+ g[0] = (jlong)globalCB;
+ }
+ (*env)->ReleasePrimitiveArrayCritical(env, global, g, 0);
}
return (jlong) (intptr_t)_ctx;
@@ -123,7 +133,7 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject
*/
JNIEXPORT jlong JNICALL
Java_com_jogamp_opencl_impl_CLImpl_clCreateContext0(JNIEnv *env, jobject _unused,
- jobject props, jint props_byte_offset, jint numDevices, jobject deviceList, jint device_type_offset, jobject cb, jobject errcode, jint errcode_byte_offset) {
+ jobject props, jint props_byte_offset, jint numDevices, jobject deviceList, jint device_type_offset, jobject cb, jobject global, jobject errcode, jint errcode_byte_offset) {
cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
@@ -149,14 +159,38 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContext0(JNIEnv *env, jobject _unused
_ctx = clCreateContext(_props_ptr, numDevices, (cl_device_id *)_deviceListPtr, pfn_notify, globalCB, (int32_t *) _errcode_ptr);
- // if something went wrong
- if (_ctx == NULL && globalCB != NULL) {
- (*env)->DeleteGlobalRef(env, globalCB);
+ if(globalCB != NULL) {
+ jlong *g = (*env)->GetPrimitiveArrayCritical(env, global, NULL);
+ // if something went wrong
+ if(_ctx == NULL) {
+ g[0] = 0;
+ (*env)->DeleteGlobalRef(env, globalCB);
+ }else{
+ g[0] = (jlong)globalCB;
+ }
+ (*env)->ReleasePrimitiveArrayCritical(env, global, g, 0);
}
return (jlong) (intptr_t)_ctx;
}
+/* Java->C glue code:
+ * Java package: com.jogamp.opencl.impl.CLImpl
+ * Java method: int clReleaseContextImpl(long context)
+ * C function: int32_t clReleaseContextImpl(cl_context context);
+ */
+JNIEXPORT jint JNICALL
+Java_com_jogamp_opencl_impl_CLImpl_clReleaseContextImpl(JNIEnv *env, jobject _unused, jlong context, jlong global) {
+ int32_t _res;
+ _res = clReleaseContext((cl_context) (intptr_t) context);
+ // TODO deal with retains
+ if (global != 0) {
+ (*env)->DeleteGlobalRef(env, (jobject) global);
+ }
+ return _res;
+}
+
+
/**
* Entry point to C language function:
* extern CL_API_ENTRY cl_int CL_API_CALL
diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java
index f3daddf0..d2993f96 100644
--- a/resources/clImplCustomCode.java
+++ b/resources/clImplCustomCode.java
@@ -1,33 +1,66 @@
private final CLProcAddressTable addressTable;
+ //maps the context id to its error handler's global object pointer
+ private final com.jogamp.common.util.LongLongHashMap contextCallbackMap;
+
public CLImpl(CLProcAddressTable addressTable) {
this.addressTable = addressTable;
+ this.contextCallbackMap = new com.jogamp.common.util.LongLongHashMap();
+ this.contextCallbackMap.setKeyNotFoundValue(0);
}
- public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CreateContextCallback pfn_notify, IntBuffer errcode_ret) {
+ public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CLErrorHandler pfn_notify, IntBuffer errcode_ret) {
if(properties!=null && !properties.isDirect())
throw new RuntimeException("Argument \"properties\" was not a direct buffer");
- return this.clCreateContext0(
+ long[] global = new long[1];
+ long ctx = this.clCreateContext0(
properties!=null?properties.getBuffer():null, Buffers.getDirectBufferByteOffset(properties),
devices!=null?devices.remaining():0, devices!=null?devices.getBuffer():null, Buffers.getDirectBufferByteOffset(devices),
- null, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) );
+ pfn_notify, global, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) );
+
+ if(pfn_notify != null && global[0] != 0) {
+ synchronized(contextCallbackMap) {
+ contextCallbackMap.put(ctx, global[0]);
+ }
+ }
+ return ctx;
}
- private native long clCreateContext0(Object cl_context_properties, int props_offset, int numDevices, Object devices, int devices_offset, CreateContextCallback pfn_notify, Object errcode_ret, int err_offset);
+ private native long clCreateContext0(Object cl_context_properties, int props_offset, int numDevices, Object devices, int devices_offset, CLErrorHandler pfn_notify, long[] global, Object errcode_ret, int err_offset);
- public long clCreateContextFromType(PointerBuffer properties, long device_type, CreateContextCallback pfn_notify, IntBuffer errcode_ret) {
+ public long clCreateContextFromType(PointerBuffer properties, long device_type, CLErrorHandler pfn_notify, IntBuffer errcode_ret) {
if(properties!=null && !properties.isDirect())
throw new RuntimeException("Argument \"properties\" was not a direct buffer");
- return this.clCreateContextFromType0(
+ long[] global = new long[1];
+ long ctx = this.clCreateContextFromType0(
properties!=null?properties.getBuffer():null, Buffers.getDirectBufferByteOffset(properties),
- device_type, pfn_notify, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) );
+ device_type, pfn_notify, global, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) );
+
+ if(pfn_notify != null && global[0] != 0) {
+ synchronized(contextCallbackMap) {
+ contextCallbackMap.put(ctx, global[0]);
+ }
+ }
+ return ctx;
}
- private native long clCreateContextFromType0(Object properties, int props_offset, long device_type, CreateContextCallback pfn_notify, Object errcode_ret, int err_offset);
+ private native long clCreateContextFromType0(Object properties, int props_offset, long device_type, CLErrorHandler pfn_notify, long[] global, Object errcode_ret, int err_offset);
+
+
+ public int clReleaseContext(long context) {
+ long global = 0;
+ synchronized(contextCallbackMap) {
+ global = contextCallbackMap.remove(context);
+ }
+ return clReleaseContextImpl(context, global);
+ }
+
+ /** Interface to C language function: <br> <code> int32_t {@native clReleaseContext}(cl_context context); </code> */
+ public native int clReleaseContextImpl(long context, long global);
/** Interface to C language function: <br> <code> int32_t clBuildProgram(cl_program, uint32_t, cl_device_id * , const char * , void * ); </code> */