summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--resources/cl-if.cfg6
-rw-r--r--resources/clImplCustomCode.c46
-rw-r--r--resources/clImplCustomCode.java100
-rw-r--r--src/com/mbien/opencl/CLContext.java37
-rw-r--r--src/com/mbien/opencl/CLGLContext.java4
-rw-r--r--src/com/mbien/opencl/CLProgram.java13
6 files changed, 99 insertions, 107 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;
}
+ }
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java
index 30197f37..ebd5821d 100644
--- a/src/com/mbien/opencl/CLContext.java
+++ b/src/com/mbien/opencl/CLContext.java
@@ -3,6 +3,7 @@ package com.mbien.opencl;
import com.mbien.opencl.CLMemory.Mem;
import com.mbien.opencl.CLSampler.AddressingMode;
import com.mbien.opencl.CLSampler.FilteringMode;
+import com.sun.gluegen.runtime.BufferFactory;
import com.sun.gluegen.runtime.CPU;
import com.sun.gluegen.runtime.PointerBuffer;
import java.io.BufferedReader;
@@ -80,7 +81,7 @@ public class CLContext implements CLResource {
* The platform to be used is implementation dependent.
*/
public static final CLContext create() {
- Buffer properties = setupContextProperties(null);
+ PointerBuffer properties = setupContextProperties(null);
return new CLContext(createContextFromType(properties, CL.CL_DEVICE_TYPE_ALL));
}
@@ -120,7 +121,7 @@ public class CLContext implements CLResource {
}
}
- Buffer properties = setupContextProperties(platform);
+ PointerBuffer properties = setupContextProperties(platform);
return new CLContext(createContextFromType(properties, type));
}
@@ -136,11 +137,11 @@ public class CLContext implements CLResource {
deviceIDs[i] = devices[i].ID;
}
- Buffer properties = setupContextProperties(platform);
+ PointerBuffer properties = setupContextProperties(platform);
return new CLContext(createContext(properties, deviceIDs));
}
- protected static final long createContextFromType(Buffer properties, long deviceType) {
+ protected static final long createContextFromType(PointerBuffer properties, long deviceType) {
IntBuffer status = IntBuffer.allocate(1);
long context = CLPlatform.getLowLevelBinding().clCreateContextFromType(properties, deviceType, null, null, status);
@@ -150,17 +151,24 @@ public class CLContext implements CLResource {
return context;
}
- protected static final long createContext(Buffer properties, long[] devices) {
+ protected static final long createContext(PointerBuffer properties, long[] devices) {
- IntBuffer status = IntBuffer.allocate(1);
- long context = CLPlatform.getLowLevelBinding().clCreateContext(properties, devices, null, null, status);
+ IntBuffer status = BufferFactory.newDirectByteBuffer(4).asIntBuffer();
+ PointerBuffer pb = null;
+ if(devices != null && devices.length != 0) {
+ pb = PointerBuffer.allocateDirect(devices.length);
+ for (int i = 0; i < devices.length; i++) {
+ pb.put(i, devices[i]);
+ }
+ }
+ long context = CLPlatform.getLowLevelBinding().clCreateContext(properties, pb, null, null, status);
checkForError(status.get(), "can not create CL context");
return context;
}
- private static final Buffer setupContextProperties(CLPlatform platform) {
+ private static final PointerBuffer setupContextProperties(CLPlatform platform) {
if(platform == null) {
CLPlatform[] platforms = CLPlatform.listCLPlatforms();
@@ -168,16 +176,11 @@ public class CLContext implements CLResource {
platform = platforms[0];
}
- Buffer properties = null;
+ PointerBuffer properties = null;
if(platform != null) {
- if(CPU.is32Bit()){
- properties = ByteBuffer.allocate(4*3).order(ByteOrder.nativeOrder())
- .putInt(CL.CL_CONTEXT_PLATFORM).putInt((int)platform.ID).putInt(0); // 0 terminated array
- }else{
- properties = LongBuffer.allocate(3)
- .put(CL.CL_CONTEXT_PLATFORM).put(platform.ID).put(0); // 0 terminated array
- }
- properties.rewind();
+ properties = PointerBuffer.allocateDirect(3)
+ .put(CL.CL_CONTEXT_PLATFORM).put(platform.ID).put(0) // 0 terminated array
+ .rewind();
}
return properties;
}
diff --git a/src/com/mbien/opencl/CLGLContext.java b/src/com/mbien/opencl/CLGLContext.java
index 03367a35..a76c15ab 100644
--- a/src/com/mbien/opencl/CLGLContext.java
+++ b/src/com/mbien/opencl/CLGLContext.java
@@ -2,11 +2,11 @@ package com.mbien.opencl;
import java.nio.Buffer;
import com.mbien.opencl.CLMemory.Mem;
+import com.sun.gluegen.runtime.PointerBuffer;
import com.sun.opengl.impl.GLContextImpl;
import com.sun.opengl.impl.macosx.cgl.MacOSXCGLContext;
import com.sun.opengl.impl.windows.wgl.WindowsWGLContext;
import com.sun.opengl.impl.x11.glx.X11GLXContext;
-import java.nio.LongBuffer;
import javax.media.nativewindow.DefaultGraphicsConfiguration;
import javax.media.opengl.GLContext;
@@ -52,7 +52,7 @@ public final class CLGLContext extends CLContext {
DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration)ctxImpl.getDrawableImpl()
.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
- LongBuffer properties = LongBuffer.allocate(5);
+ PointerBuffer properties = PointerBuffer.allocateDirect(5);
if(glContext instanceof X11GLXContext) {
long handle = config.getScreen().getDevice().getHandle();
glID = ((X11GLXContext)glContext).getContext();
diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java
index 0c4325ee..6f1ed551 100644
--- a/src/com/mbien/opencl/CLProgram.java
+++ b/src/com/mbien/opencl/CLProgram.java
@@ -241,12 +241,15 @@ public class CLProgram implements CLResource {
releaseKernels();
}
- long[] deviceIDs = null;
+ PointerBuffer deviceIDs = null;
+ int count = 0;
if(devices != null) {
- deviceIDs = new long[devices.length];
- for (int i = 0; i < deviceIDs.length; i++) {
- deviceIDs[i] = devices[i].ID;
+ deviceIDs = PointerBuffer.allocateDirect(devices.length);
+ for (int i = 0; i < devices.length; i++) {
+ deviceIDs.put(i, devices[i].ID);
}
+ deviceIDs.rewind();
+ count = devices.length;
}
// invalidate build status
@@ -254,7 +257,7 @@ public class CLProgram implements CLResource {
executable = false;
// Build the program
- int ret = cl.clBuildProgram(ID, deviceIDs, options, null, null);
+ int ret = cl.clBuildProgram(ID, count, deviceIDs, options, null, null);
if(ret != CL_SUCCESS) {
throw new CLException(ret, "\n"+getBuildLog());