Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/mbien/jocl
Browse files Browse the repository at this point in the history
  • Loading branch information
sgothel committed May 13, 2010
2 parents 4bbfd2d + 6f0a2ff commit 17a620f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 20 deletions.
9 changes: 7 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

<target name="-post-compile" depends="c.compile.default" />

<target name="-post-jar">
<target name="-post-jar" depends="jar.natives">

<!-- TODO temporary codebase -->
<property name="jnlp.codebase" value="http://people.fh-landshut.de/~mbien/jogamp/jocl/"/>
Expand All @@ -99,15 +99,20 @@
</filterchain>
</copy>

</target>

<target name="jar.natives" unless="c.dont.compile">

<jar basedir="${natives.jocl.dir}/${namespace}" excludes="*.xml"
destfile="${dist.jar.dir}/jocl-natives-${os.and.arch}.jar"
manifest="${basedir}/manifest.mf" />

</target>


<target name="c.compile.default" depends="gluegen.cpptasks.detect.os, gluegen.cpptasks.detect.compiler, jocl.c.compile, c.rename.lib.mingw" />

<target name="jocl.c.compile" depends="c.setup.build">
<target name="jocl.c.compile" depends="c.setup.build" unless="c.dont.compile">

<echo message=" - - - compiling JOCL natives - - - "/>
<echo message="${compiler.cfg.id}"/>
Expand Down
5 changes: 4 additions & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@ static.binding=true
#overwrite lib path for static linking
#use only if static.binding is true
#opencl.lib.dir=C:/Program Files (x86)/ATI Stream/lib/x86
#opencl.lib.dir=C:/NVIDIAComputingSDK/OpenCL/common/lib/Win32
#opencl.lib.dir=C:/NVIDIAComputingSDK/OpenCL/common/lib/Win32

#disable the build build the native part of the bindings
#c.dont.compile=true
42 changes: 28 additions & 14 deletions resources/clImplCustomCode.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void buildProgramCallback(cl_program id, void * object) {

(*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);

(*env)->CallVoidMethod(env, obj, bcb_mid, (jlong)id);
(*env)->CallVoidMethod(env, obj, bcb_mid, (jlong)(intptr_t)id);
(*env)->DeleteGlobalRef(env, obj);

(*jvm)->DetachCurrentThread(jvm);
Expand Down Expand Up @@ -83,12 +83,12 @@ 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 global, jobject errcode, jint errcode_byte_offset) {
jobject props, jint props_byte_offset, jlong device_type, jobject cb, jobject global, jobject errcode, jint errcode_byte_offset) {

cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
cl_int * _errcode_ptr = NULL;
cl_context _ctx = NULL;
void (*pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data) = NULL;
void (*_pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data) = NULL;
jobject globalCB = NULL;

if (props != NULL) {
Expand All @@ -99,13 +99,16 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject
_errcode_ptr = (void *) (((char*) (*env)->GetDirectBufferAddress(env, errcode)) + errcode_byte_offset);
}

/*
if (cb != NULL) {
pfn_notify = &createContextCallback;
globalCB = (*env)->NewGlobalRef(env, cb);
}
*/

_ctx = clCreateContextFromType(_props_ptr, (uint64_t) device_type, pfn_notify, globalCB, (int32_t *) _errcode_ptr);
_ctx = clCreateContextFromType(_props_ptr, (uint64_t) device_type, _pfn_notify, globalCB, _errcode_ptr);

/*
if(globalCB != NULL) {
jlong *g = (*env)->GetPrimitiveArrayCritical(env, global, NULL);
// if something went wrong
Expand All @@ -117,6 +120,7 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject
}
(*env)->ReleasePrimitiveArrayCritical(env, global, g, 0);
}
*/

return (jlong) (intptr_t)_ctx;
}
Expand All @@ -136,10 +140,10 @@ 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 global, jobject errcode, jint errcode_byte_offset) {

cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
size_t * _deviceListPtr = NULL;
cl_int * _errcode_ptr = NULL;
cl_device_id * _deviceListPtr = NULL;
cl_context _ctx = NULL;
void (*pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data) = NULL;
void (*_pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data) = NULL;
jobject globalCB = NULL;

if (props != NULL) {
Expand All @@ -152,13 +156,16 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContext0(JNIEnv *env, jobject _unused
_errcode_ptr = (void *) (((char*) (*env)->GetDirectBufferAddress(env, errcode)) + errcode_byte_offset);
}

/*
if (cb != NULL) {
pfn_notify = &createContextCallback;
_pfn_notify = &createContextCallback;
globalCB = (*env)->NewGlobalRef(env, cb);
}
*/

_ctx = clCreateContext(_props_ptr, numDevices, (cl_device_id *)_deviceListPtr, pfn_notify, globalCB, (int32_t *) _errcode_ptr);
_ctx = clCreateContext(_props_ptr, numDevices, _deviceListPtr, _pfn_notify, globalCB, _errcode_ptr);

/*
if(globalCB != NULL) {
jlong *g = (*env)->GetPrimitiveArrayCritical(env, global, NULL);
// if something went wrong
Expand All @@ -170,6 +177,7 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContext0(JNIEnv *env, jobject _unused
}
(*env)->ReleasePrimitiveArrayCritical(env, global, g, 0);
}
*/

return (jlong) (intptr_t)_ctx;
}
Expand All @@ -183,10 +191,12 @@ 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;
}

Expand All @@ -207,8 +217,8 @@ Java_com_jogamp_opencl_impl_CLImpl_clBuildProgram0(JNIEnv *env, jobject _unused,

const char* _strchars_options = NULL;
cl_int _res;
size_t * _deviceListPtr = NULL;
void (*pfn_notify)(cl_program, void *user_data) = NULL;
cl_device_id * _deviceListPtr = NULL;
void (*_pfn_notify)(cl_program, void *) = NULL;
jobject globalCB = NULL;

if (options != NULL) {
Expand All @@ -224,17 +234,21 @@ Java_com_jogamp_opencl_impl_CLImpl_clBuildProgram0(JNIEnv *env, jobject _unused,
_deviceListPtr = (void *) (((char*) (*env)->GetDirectBufferAddress(env, deviceList)) + device_type_offset);
}

/*
if (cb != NULL) {
pfn_notify = &buildProgramCallback;
_pfn_notify = &buildProgramCallback;
globalCB = (*env)->NewGlobalRef(env, cb);
}
*/

_res = clBuildProgram((cl_program)program, (cl_uint)deviceCount, (cl_device_id *)_deviceListPtr, _strchars_options, pfn_notify, globalCB);
_res = clBuildProgram((cl_program)(intptr_t)program, (cl_uint)deviceCount, (cl_device_id *)_deviceListPtr, _strchars_options, _pfn_notify, globalCB);

/*
// if something went wrong
if(_res != CL_SUCCESS && globalCB != NULL) {
(*env)->DeleteGlobalRef(env, globalCB);
}
*/

if (options != NULL) {
(*env)->ReleaseStringUTFChars(env, options, _strchars_options);
Expand Down
10 changes: 8 additions & 2 deletions resources/clImplCustomCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CLE
if(properties!=null && !properties.isDirect())
throw new RuntimeException("Argument \"properties\" was not a direct buffer");

if(errcode_ret!=null && !errcode_ret.isDirect())
throw new RuntimeException("Argument \"errcode_ret\" was not a direct buffer");

long[] global = new long[1];
long ctx = this.clCreateContext0(
properties!=null?properties.getBuffer():null, Buffers.getDirectBufferByteOffset(properties),
Expand All @@ -28,14 +31,17 @@ public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CLE
}
return ctx;
}
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);
private native long clCreateContext0(Object cl_context_properties, int props_offset, int numDevices, Object devices, int devices_offset, Object pfn_notify, long[] global, Object errcode_ret, int err_offset);


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");

if(errcode_ret!=null && !errcode_ret.isDirect())
throw new RuntimeException("Argument \"errcode_ret\" was not a direct buffer");

long[] global = new long[1];
long ctx = this.clCreateContextFromType0(
properties!=null?properties.getBuffer():null, Buffers.getDirectBufferByteOffset(properties),
Expand All @@ -48,7 +54,7 @@ public long clCreateContextFromType(PointerBuffer properties, long device_type,
}
return ctx;
}
private native long clCreateContextFromType0(Object properties, int props_offset, long device_type, CLErrorHandler pfn_notify, long[] global, Object errcode_ret, int err_offset);
private native long clCreateContextFromType0(Object properties, int props_offset, long device_type, Object pfn_notify, long[] global, Object errcode_ret, int err_offset);


public int clReleaseContext(long context) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/jogamp/opencl/CLContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static CLContext create(CLPlatform platform, CLDevice... devices) {

protected static long createContextFromType(CLErrorHandler handler, PointerBuffer properties, long deviceType) {

IntBuffer status = IntBuffer.allocate(1);
IntBuffer status = newDirectIntBuffer(1);
long context = CLPlatform.getLowLevelCLInterface().clCreateContextFromType(properties, deviceType, handler, status);

checkForError(status.get(), "can not create CL context");
Expand Down
1 change: 1 addition & 0 deletions test/com/jogamp/opencl/CLProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public void buildFinished(CLProgram program) {
};

builder.setProgram(program).build(buildCallback);
countdown.countDown(); // TODO remove if callbacks are enabled again
countdown.await();
}

Expand Down
1 change: 1 addition & 0 deletions test/com/jogamp/opencl/LowLevelBindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public void buildFinished(long cl_program) {

// Build the program
ret = cl.clBuildProgram(program, 0, null, null, callback);
latch.countDown(); // TODO remove if callbacks are enabled again
checkError("on clBuildProgram", ret);

out.println("waiting for program to build...");
Expand Down
2 changes: 2 additions & 0 deletions test/com/jogamp/opencl/gl/CLGLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public void createContextTest() {
if(device == null) {
out.println("Aborting test: no GLCL capable devices found.");
return;
}else{
out.println("isGLMemorySharingSupported==true on: \n "+device);
}

CLContext context = CLGLContext.create(glcontext, device);
Expand Down

0 comments on commit 17a620f

Please sign in to comment.