diff options
Diffstat (limited to 'resources')
-rw-r--r-- | resources/cl-impl.cfg | 11 | ||||
-rw-r--r-- | resources/clImplCustomCode.c | 24 | ||||
-rw-r--r-- | resources/clImplCustomCode.java | 53 |
3 files changed, 81 insertions, 7 deletions
diff --git a/resources/cl-impl.cfg b/resources/cl-impl.cfg index 32a3099d..c2aff892 100644 --- a/resources/cl-impl.cfg +++ b/resources/cl-impl.cfg @@ -5,6 +5,8 @@ Style ImplOnly #imports for all generated java files Import com.jogamp.opencl.llb.* Import com.jogamp.opencl.llb.gl.CLGL +Import java.security.AccessController +Import java.security.PrivilegedAction ClassJavadoc CLAbstractImpl /** ClassJavadoc CLAbstractImpl * Java bindings to OpenCL, the Open Computing Language (generated). @@ -45,10 +47,11 @@ ProcAddressNameExpr $UpperCase(arg) #...or force all ForceProcAddressGen __ALL__ -Unignore clGetExtensionFunctionAddress -RenameJavaMethod clGetExtensionFunctionAddress clGetExtensionFunctionAddressImpl -AccessControl clGetExtensionFunctionAddressImpl PROTECTED -ArgumentIsString clGetExtensionFunctionAddressImpl 0 +# +# extern CL_API_ENTRY void * CL_API_CALL clGetExtensionFunctionAddress(const char * /* func_name */) CL_API_SUFFIX__VERSION_1_0; +# +Ignore clGetExtensionFunctionAddress +ForceProcAddressGen clGetExtensionFunctionAddress #append to generated c files CustomCCode #include <CL/cl.h> diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c index 4a43ae3b..751f819b 100644 --- a/resources/clImplCustomCode.c +++ b/resources/clImplCustomCode.c @@ -112,6 +112,30 @@ CL_CALLBACK void memObjDestructorCallback(cl_mem mem, void * object) { (*jvm)->DetachCurrentThread(jvm); } +// extern CL_API_ENTRY void * CL_API_CALL clGetExtensionFunctionAddress(const char * /* func_name */) CL_API_SUFFIX__VERSION_1_0; + +JNIEXPORT jlong JNICALL +Java_com_jogamp_opencl_llb_impl_CLAbstractImpl_dispatch_1clGetExtensionFunctionAddressStatic(JNIEnv *env, jclass _unused, jstring fname, jlong procAddress) { + typedef void* (CL_API_ENTRY*_local_LPCLGETPROCADDRESS)(const char * fname); + _local_LPCLGETPROCADDRESS ptr_clGetExtensionFunctionAddress; + const char* _strchars_fname = NULL; + void* _res; + if ( NULL != fname ) { + _strchars_fname = (*env)->GetStringUTFChars(env, fname, (jboolean*)NULL); + if ( NULL == _strchars_fname ) { + (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), + "Failed to get UTF-8 chars for argument \"fname\" in native dispatcher for \"dispatch_clGetExtensionFunctionAddress\""); + return 0; + } + } + ptr_clGetExtensionFunctionAddress = (_local_LPCLGETPROCADDRESS) (intptr_t) procAddress; + assert(ptr_clGetExtensionFunctionAddress != NULL); + _res = (* ptr_clGetExtensionFunctionAddress) ((char *) _strchars_fname); + if ( NULL != fname ) { + (*env)->ReleaseStringUTFChars(env, fname, _strchars_fname); + } + return (jlong) (intptr_t) _res; +} /* Java->C glue code: * Java package: com.jogamp.opencl.impl.CLImpl diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java index 1826da86..bee53425 100644 --- a/resources/clImplCustomCode.java +++ b/resources/clImplCustomCode.java @@ -1,6 +1,53 @@ - protected final CLProcAddressTable addressTable; + static final DynamicLibraryBundle dynamicLookupHelper; + protected static final CLProcAddressTable addressTable; - public CLAbstractImpl(CLProcAddressTable addressTable) { - this.addressTable = addressTable; + static { + addressTable = new CLProcAddressTable(); + if(null==addressTable) { + throw new RuntimeException("Couldn't instantiate ALProcAddressTable"); + } + + dynamicLookupHelper = AccessController.doPrivileged(new PrivilegedAction<DynamicLibraryBundle>() { + public DynamicLibraryBundle run() { + final DynamicLibraryBundle bundle = new DynamicLibraryBundle(new CLDynamicLibraryBundleInfo()); + if(null==bundle) { + throw new RuntimeException("Null CLDynamicLookupHelper"); + } + if(!bundle.isToolLibLoaded()) { + throw new RuntimeException("Couln't load native CL library"); + } + if(!bundle.isLibComplete()) { + throw new RuntimeException("Couln't load native CL/JNI glue library"); + } + addressTable.reset(bundle); + return bundle; + } } ); } + + public static CLProcAddressTable getCLProcAddressTable() { return addressTable; } + + static long clGetExtensionFunctionAddress(long clGetExtensionFunctionAddressHandle, java.lang.String procname) + { + if (clGetExtensionFunctionAddressHandle == 0) { + throw new RuntimeException("Passed null pointer for method \"clGetExtensionFunctionAddress\""); + } + return dispatch_clGetExtensionFunctionAddressStatic(procname, clGetExtensionFunctionAddressHandle); + } + + public CLAbstractImpl() { + } + + /** Entry point (through function pointer) to C language function: <br> <code> void* clGetExtensionFunctionAddress(const char * fname); </code> */ + long clGetExtensionFunctionAddress(String fname) { + + final long __addr_ = addressTable._addressof_clGetExtensionFunctionAddress; + if (__addr_ == 0) { + throw new UnsupportedOperationException("Method \"clGetExtensionFunctionAddress\" not available"); + } + return dispatch_clGetExtensionFunctionAddressStatic(fname, __addr_); + } + + /** Entry point (through function pointer) to C language function: <br> <code> void* clGetExtensionFunctionAddress(const char * fname); </code> */ + private static native long dispatch_clGetExtensionFunctionAddressStatic(String fname, long procAddress); + |