diff options
author | Michael Bien <[email protected]> | 2010-01-25 21:14:26 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-25 21:14:26 +0100 |
commit | 22a5f55a5d0e4215eacda6dbf01b34cec47a5bf0 (patch) | |
tree | b838b8121715fb99e42231264ab050d059ecb317 /resources | |
parent | 3ff3ea603ce0e3b0ac8fed74ce57edc2314a3dba (diff) |
more direct NIO.
Diffstat (limited to 'resources')
-rw-r--r-- | resources/cl-if.cfg | 6 | ||||
-rw-r--r-- | resources/clImplCustomCode.c | 46 | ||||
-rw-r--r-- | resources/clImplCustomCode.java | 100 |
3 files changed, 69 insertions, 83 deletions
diff --git a/resources/cl-if.cfg b/resources/cl-if.cfg index 9b37973f..4b60e8a6 100644 --- a/resources/cl-if.cfg +++ b/resources/cl-if.cfg @@ -19,17 +19,17 @@ 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(java.nio.Buffer properties, long[] devices, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret); +CustomJavaCode CL public long clCreateContext(com.sun.gluegen.runtime.PointerBuffer properties, com.sun.gluegen.runtime.PointerBuffer devices, CreateContextCallback pfn_notify, Object userData, 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(java.nio.Buffer properties, long device_type, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret); +CustomJavaCode CL public long clCreateContextFromType(com.sun.gluegen.runtime.PointerBuffer properties, long device_type, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret); Ignore clBuildProgram CustomJavaCode CL CustomJavaCode CL /** Interface to C language function: <br> <code> int32_t {@native clBuildProgram}(cl_program, uint32_t, cl_device_id * , const char * , void (*pfn_notify)(cl_program, void *user_data), void * ); </code> */ -CustomJavaCode CL public int clBuildProgram(long program, long[] devices, String options, BuildProgramCallback cb, Object userData); +CustomJavaCode CL public int clBuildProgram(long program, int deviceCount, com.sun.gluegen.runtime.PointerBuffer devices, String options, BuildProgramCallback cb, Object userData); Ignore clEnqueueNativeKernel #TODO.. diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c index a0b91f35..6829e8b6 100644 --- a/resources/clImplCustomCode.c +++ b/resources/clImplCustomCode.c @@ -25,30 +25,24 @@ void createContextCallback(const char * c, const void * v, size_t s, void * o) { * cl_int * errcode_ret ); */ 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) { +Java_com_mbien_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject _unused, + jobject props, jint props_byte_offset, jobject device_type, jobject cb, jobject data, jobject errcode, jint errcode_byte_offset) { cl_context_properties* _props_ptr = NULL; int32_t * _errcode_ptr = NULL; cl_context _ctx; if (props != NULL) { - _props_ptr = (cl_context_properties*) (((char*) (*env)->GetPrimitiveArrayCritical(env, props, NULL)) + props_byte_offset); + _props_ptr = (cl_context_properties*) (((char*) (*env)->GetDirectBufferAddress(env, props)) + props_byte_offset); } + if (errcode != NULL) { - _errcode_ptr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, errcode, NULL)) + errcode_byte_offset); + _errcode_ptr = (void *) (((char*) (*env)->GetDirectBufferAddress(env, errcode)) + errcode_byte_offset); } //TODO callback; payload _ctx = clCreateContextFromType(_props_ptr, (uint64_t) device_type, NULL, NULL, (int32_t *) _errcode_ptr); - if (errcode != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, errcode, _errcode_ptr, 0); - } - if (props != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, props, _props_ptr, 0); - } - return (jlong) (intptr_t)_ctx; } @@ -63,8 +57,8 @@ Java_com_mbien_opencl_impl_CLImpl_clCreateContextFromType1(JNIEnv *env, jobject * cl_int * errcode_ret ) CL_API_SUFFIX__VERSION_1_0; */ 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) { +Java_com_mbien_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 data, jobject errcode, jint errcode_byte_offset) { cl_context_properties* _props_ptr = NULL; int32_t * _errcode_ptr = NULL; @@ -73,28 +67,18 @@ Java_com_mbien_opencl_impl_CLImpl_clCreateContext1(JNIEnv *env, jobject _unused, cl_context _ctx; if (props != NULL) { - _props_ptr = (cl_context_properties*) (((char*) (*env)->GetPrimitiveArrayCritical(env, props, NULL)) + props_byte_offset); + _props_ptr = (cl_context_properties*) (((char*) (*env)->GetDirectBufferAddress(env, props)) + props_byte_offset); } if (deviceList != NULL) { - _deviceListPtr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, deviceList, NULL)) /*+ device_byte_offset*/); + _deviceListPtr = (void *) (((char*) (*env)->GetDirectBufferAddress(env, deviceList)) + device_type_offset); } if (errcode != NULL) { - _errcode_ptr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, errcode, NULL)) + errcode_byte_offset); + _errcode_ptr = (void *) (((char*) (*env)->GetDirectBufferAddress(env, errcode)) + errcode_byte_offset); } // TODO payload, callback... _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); - } - if (deviceList != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, deviceList, _deviceListPtr, 0); - } - if (props != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, props, _props_ptr, 0); - } - return (jlong) (intptr_t)_ctx; } @@ -109,8 +93,8 @@ Java_com_mbien_opencl_impl_CLImpl_clCreateContext1(JNIEnv *env, jobject _unused, * void * user_data ) CL_API_SUFFIX__VERSION_1_0; */ JNIEXPORT jint JNICALL -Java_com_mbien_opencl_impl_CLImpl_clBuildProgram1(JNIEnv *env, jobject _unused, - jlong program, jint deviceCount, jobject deviceList, jstring options, jobject cb, jobject data) { +Java_com_mbien_opencl_impl_CLImpl_clBuildProgram0(JNIEnv *env, jobject _unused, + jlong program, jint deviceCount, jobject deviceList, jint device_type_offset, jstring options, jobject cb, jobject data) { const char* _strchars_options = NULL; cl_int _res; @@ -126,16 +110,12 @@ Java_com_mbien_opencl_impl_CLImpl_clBuildProgram1(JNIEnv *env, jobject _unused, } if (deviceList != NULL) { - _deviceListPtr = (void *) (((char*) (*env)->GetPrimitiveArrayCritical(env, deviceList, NULL))); + _deviceListPtr = (void *) (((char*) (*env)->GetDirectBufferAddress(env, deviceList)) + device_type_offset); } // TODO payload, callback... _res = clBuildProgram((cl_program)program, (cl_uint)deviceCount, (cl_device_id *)_deviceListPtr, _strchars_options, NULL, NULL); - if (deviceList != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, deviceList, _deviceListPtr, 0); - } - if (options != NULL) { (*env)->ReleaseStringUTFChars(env, options, _strchars_options); } diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java index 0a42cc12..6ee9193b 100644 --- a/resources/clImplCustomCode.java +++ b/resources/clImplCustomCode.java @@ -1,66 +1,72 @@ - CLProcAddressTable addressTable = new CLProcAddressTable(); + CLProcAddressTable addressTable = new CLProcAddressTable(); - public long clCreateContext(java.nio.Buffer properties, long[] devices, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret) { + public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret) { - if(pfn_notify != null) - throw new RuntimeException("asynchronous execution with callback is not yet implemented, pass null through this method to block until complete."); + if(properties!=null && !properties.isDirect()) + throw new RuntimeException("Argument \"properties\" was not a direct buffer"); - if(userData != null) - System.err.println("WARNING: userData not yet implemented... ignoring"); + if(pfn_notify != null) + throw new RuntimeException("asynchronous execution with callback is not yet implemented, pass null through this method to block until complete."); - int listLength = 0; - if(devices != null) - listLength = devices.length; + if(userData != null) + System.err.println("WARNING: userData not yet implemented... ignoring"); - return this.clCreateContext1( - BufferFactory.getArray(properties), BufferFactory.getIndirectBufferByteOffset(properties), listLength, devices, null, null, - BufferFactory.getArray(errcode_ret), BufferFactory.getIndirectBufferByteOffset(errcode_ret) ); - } - private native long clCreateContext1(Object cl_context_properties, int props_offset, int deviceCount, long[] devices, CreateContextCallback pfn_notify, Object userData, Object errcode_ret, int err_offset); + return this.clCreateContext0( + properties!=null?properties.getBuffer():null, BufferFactory.getDirectBufferByteOffset(properties), + devices!=null?devices.getBuffer():null, BufferFactory.getDirectBufferByteOffset(devices), + null, null, + errcode_ret, BufferFactory.getDirectBufferByteOffset(errcode_ret) ); + } + private native long clCreateContext0(Object cl_context_properties, int props_offset, Object devices, int devices_offset, CreateContextCallback pfn_notify, Object userData, Object errcode_ret, int err_offset); - public long clCreateContextFromType(java.nio.Buffer properties, long device_type, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret) { + public long clCreateContextFromType(PointerBuffer properties, long device_type, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret) { - if(pfn_notify != null) - throw new RuntimeException("asynchronous execution with callback is not yet implemented, pass null through this method to block until complete."); + if(properties!=null && !properties.isDirect()) + throw new RuntimeException("Argument \"properties\" was not a direct buffer"); - if(userData != null) - System.err.println("WARNING: userData not yet implemented... ignoring"); + if(pfn_notify != null) + throw new RuntimeException("asynchronous execution with callback is not yet implemented, pass null through this method to block until complete."); - return this.clCreateContextFromType1( - BufferFactory.getArray(properties), BufferFactory.getIndirectBufferByteOffset(properties), device_type, pfn_notify, null, - BufferFactory.getArray(errcode_ret), BufferFactory.getIndirectBufferByteOffset(errcode_ret) ); - } - private native long clCreateContextFromType1(Object properties, int props_offset, long device_type, CreateContextCallback pfn_notify, Object userData, Object errcode_ret, int err_offset); + if(userData != null) + System.err.println("WARNING: userData not yet implemented... ignoring"); + + return this.clCreateContextFromType0( + properties!=null?properties.getBuffer():null, BufferFactory.getDirectBufferByteOffset(properties), + device_type, pfn_notify, null, + errcode_ret, BufferFactory.getDirectBufferByteOffset(errcode_ret) ); + } + private native long clCreateContextFromType0(Object properties, int props_offset, long device_type, CreateContextCallback pfn_notify, Object userData, Object errcode_ret, int err_offset); + + + /** Interface to C language function: <br> <code> int32_t clBuildProgram(cl_program, uint32_t, cl_device_id * , const char * , void * ); </code> */ + public int clBuildProgram(long program, int deviceCount, PointerBuffer deviceList, String options, BuildProgramCallback cb, Object userData) { + if(deviceList!=null && !deviceList.isDirect()) + throw new RuntimeException("Argument \"properties\" was not a direct buffer"); - /** Interface to C language function: <br> <code> int32_t clBuildProgram(cl_program, uint32_t, cl_device_id * , const char * , void * ); </code> */ - public int clBuildProgram(long program, long[] deviceList, String options, BuildProgramCallback cb, Object userData) { + if(cb != null) + throw new RuntimeException("asynchronous execution with callback is not yet implemented, pass null through this method to block until complete."); - if(cb != null) - throw new RuntimeException("asynchronous execution with callback is not yet implemented, pass null through this method to block until complete."); + if(userData != null) + System.err.println("WARNING: userData not yet implemented... ignoring"); - if(userData != null) - System.err.println("WARNING: userData not yet implemented... ignoring"); + return clBuildProgram0(program, deviceCount, + deviceList!=null?deviceList.getBuffer():null, BufferFactory.getDirectBufferByteOffset(deviceList), + options, cb, userData); + } + /** Entry point to C language function: <code> int32_t clBuildProgram(cl_program, uint32_t, cl_device_id * , const char * , void * ); </code> */ + private native int clBuildProgram0(long program, int deviceCount, Object deviceList, int deviceListOffset, String options, BuildProgramCallback cb, Object userData); - int listLength = 0; - if(deviceList != null) - listLength = deviceList.length; - return clBuildProgram1(program, listLength, deviceList, options, cb, userData); + private final static void convert32To64(long[] values) { + if(values.length%2 == 1) { + values[values.length-1] = values[values.length/2]>>>32; } - /** 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; - } - for (int i = values.length - 1 - values.length%2; i >= 0; i-=2) { - long temp = values[i/2]; - values[i-1] = temp>>>32; - values[i ] = temp & 0x00000000FFFFFFFFL; - } + for (int i = values.length - 1 - values.length%2; i >= 0; i-=2) { + long temp = values[i/2]; + values[i-1] = temp>>>32; + values[i ] = temp & 0x00000000FFFFFFFFL; } + } |