diff options
35 files changed, 529 insertions, 333 deletions
diff --git a/make/build.xml b/make/build.xml index 0c50129f..0f796e3a 100644 --- a/make/build.xml +++ b/make/build.xml @@ -45,6 +45,7 @@ <!-- This is the version of JOCL you are building --> <mkdir dir="${build}" /> + <exec dir="." executable="git" logError="true" failonerror="false" failifexecutionfails="false" output="${build}/localbranch.raw"> <arg line="branch --no-color"/> @@ -127,7 +128,7 @@ <property name="rootrel.src.c" value="resources" /> <property name="rootrel.src.generated" value="${rootrel.build}/gensrc" /> <property name="rootrel.generated.java" value="${rootrel.src.generated}/classes" /> - <property name="rootrel.generated.c.jocl" value="${rootrel.src.generated}/native" /> + <property name="rootrel.generated.c.jocl" value="${rootrel.src.generated}/native/jocl" /> <property name="rootrel.obj" value="${rootrel.build}/obj" /> <property name="rootrel.obj.jocl" value="${rootrel.obj}/jocl" /> @@ -287,7 +288,7 @@ <!-- Now check for the presence of one well-known file --> <uptodate property="java.generate.skip" - targetfile="${src.generated.java}/com/jogamp/opencl/llb/CL.java"> + targetfile="${src.generated.c}/CLAbstractImpl_JNI.c"> <srcfiles refid="stub.includes.dependencies.fileset.1" /> <srcfiles refid="stub.includes.dependencies.fileset.2" /> <srcfiles refid="stub.includes.dependencies.fileset.3" /> @@ -298,7 +299,7 @@ <target name="java.generate.copy2temp"> <copy todir="${tempdir}"> <fileset dir="${build}" - includes="gensrc/classes/**" /> + includes="gensrc/java/**" /> </copy> </target> @@ -370,7 +371,12 @@ - from the C OpenCL headers. This involves setting the taskdef and creating - the classpath reference id then running the task on each header. --> - <target name="java.generate" depends="build.gluegen, generate.jdk6.autocloseable, generate.jdk7.autocloseable, java.generate.check, preprocess-opencl-headers" unless="java.generate.skip"> + <target name="java.generate" depends="build.gluegen, java.generate.check" unless="java.generate.skip"> + <antcall target="java.generate.impl" inheritRefs="true" /> + </target> + + <target name="java.generate.impl" depends="generate.jdk6.autocloseable, generate.jdk7.autocloseable, preprocess-opencl-headers"> + <!-- Add the GlueGen task to ANT --> <taskdef name="gluegen" classname="com.jogamp.gluegen.ant.GlueGenTask" classpathref="gluegen.classpath" /> @@ -500,6 +506,7 @@ </gluegen> <echo message="CL..."/> + <antcall target="java.generate.copy2temp" inheritRefs="true" /> <gluegen src="${stub.includes}/opencl.h" outputRootDir="${build}" config="${config}/cl-if.cfg" diff --git a/make/config/cl-common.cfg b/make/config/cl-common.cfg index d89643b9..8e1adf16 100644 --- a/make/config/cl-common.cfg +++ b/make/config/cl-common.cfg @@ -1,5 +1,5 @@ JavaOutputDir gensrc/java -NativeOutputDir gensrc/native +NativeOutputDir gensrc/native/jocl Package com.jogamp.opencl.llb diff --git a/make/config/cl-if.cfg b/make/config/cl-if.cfg index 2078123a..8b5322f7 100644 --- a/make/config/cl-if.cfg +++ b/make/config/cl-if.cfg @@ -19,17 +19,17 @@ Extends CL CLSamplerBinding Extends CL CLEventBinding Extends CL CLPlatformBinding -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLContextBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLProgramBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLKernelBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLCommandQueueBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLDeviceBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLMemObjBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLImageBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLBufferBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLSamplerBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLEventBinding.java -ExtendedInterfaceSymbolsIgnore ../build/gensrc/java/com/jogamp/opencl/llb/CLPlatformBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLContextBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLProgramBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLKernelBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLCommandQueueBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLDeviceBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLMemObjBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLImageBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLBufferBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLSamplerBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLEventBinding.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/java/com/jogamp/opencl/llb/CLPlatformBinding.java #ignore cl-gl interoperability functions. Interface 'CL' is pure OpenCL. Ignore CL_GL_.*|cl.*GL.*|.*_GL_.* diff --git a/make/config/cl-impl.cfg b/make/config/cl-impl.cfg index 4beb22b3..a7b53950 100644 --- a/make/config/cl-impl.cfg +++ b/make/config/cl-impl.cfg @@ -16,10 +16,13 @@ ImplJavaClass CLAbstractImpl AccessControl CLAbstractImpl PUBLIC_ABSTRACT Implements CLAbstractImpl CLGL +LocalProcAddressCallingConvention __ALL__ CL_API_CALL + EmitProcAddressTable true ProcAddressTableClassName CLProcAddressTable GetProcAddressTableExpr addressTable ProcAddressNameExpr $UpperCase(arg) +ForceProcAddressGen __ALL__ #dynamic binding for OpenGL specific functions... #ForceProcAddressGen clGetGLContextInfoKHR diff --git a/make/config/clImplCustomCode.c b/make/config/clImplCustomCode.c index 751f819b..6a5da4f0 100644 --- a/make/config/clImplCustomCode.c +++ b/make/config/clImplCustomCode.c @@ -116,7 +116,7 @@ CL_CALLBACK void memObjDestructorCallback(cl_mem mem, void * object) { 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); + typedef void* (CL_API_CALL * _local_LPCLGETPROCADDRESS)(const char * fname); _local_LPCLGETPROCADDRESS ptr_clGetExtensionFunctionAddress; const char* _strchars_fname = NULL; void* _res; @@ -130,7 +130,7 @@ Java_com_jogamp_opencl_llb_impl_CLAbstractImpl_dispatch_1clGetExtensionFunctionA } ptr_clGetExtensionFunctionAddress = (_local_LPCLGETPROCADDRESS) (intptr_t) procAddress; assert(ptr_clGetExtensionFunctionAddress != NULL); - _res = (* ptr_clGetExtensionFunctionAddress) ((char *) _strchars_fname); + _res = (* ptr_clGetExtensionFunctionAddress) (_strchars_fname); if ( NULL != fname ) { (*env)->ReleaseStringUTFChars(env, fname, _strchars_fname); } @@ -210,7 +210,7 @@ Java_com_jogamp_opencl_llb_impl_CLImpl_clCreateContext0(JNIEnv *env, jobject _un cccallback _pfn_notify = NULL; jobject globalCB = NULL; - typedef cl_context (*function)(cl_context_properties *, cl_uint, const cl_device_id *, void (*pfn_notify)(const char *, const void *, size_t, void *), void *, cl_int *); + typedef cl_context (CL_API_CALL * function)(cl_context_properties *, cl_uint, const cl_device_id *, void (*pfn_notify)(const char *, const void *, size_t, void *), void *, cl_int *); function clCreateContext = (function)(intptr_t) procAddress; if (props != NULL) { @@ -286,7 +286,7 @@ Java_com_jogamp_opencl_llb_impl_CLImpl_clBuildProgram0(JNIEnv *env, jobject _unu bpcallback _pfn_notify = NULL; jobject globalCB = NULL; - typedef cl_int (*function)(cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *); + typedef cl_int (CL_API_CALL * function)(cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *); function clBuildProgram = (function)(intptr_t)procAddress; if (options != NULL) { diff --git a/make/scripts/check-junit.sh b/make/scripts/check-junit.sh new file mode 100755 index 00000000..232b3c6a --- /dev/null +++ b/make/scripts/check-junit.sh @@ -0,0 +1,39 @@ +#! /bin/bash + +builddir=$1 +shift + +function checkresult() { + resdir=$1 + shift + if [ -e $builddir/test/$resdir ] ; then + echo + echo Results of $builddir/test/$resdir + echo + echo number of junit classes + grep failures $builddir/test/$resdir/* | wc + echo + echo number of passed junit classes - failures + grep failures $builddir/test/$resdir/* | grep "failures=\"0\"" | wc + echo + echo number of passed junit classes - errors + grep failures $builddir/test/$resdir/* | grep "errors=\"0\"" | wc + echo + echo number of failed junit classes - failures + grep failures $builddir/test/$resdir/* | grep -v "failures=\"0\"" | wc + echo + echo number of failed junit classes - errors + grep failures $builddir/test/$resdir/* | grep -v "errors=\"0\"" | wc + echo + echo failed junit classes - failures + grep failures $builddir/test/$resdir/* | grep -v "failures=\"0\"" + echo + echo failed junit classes - errors + grep failures $builddir/test/$resdir/* | grep -v "errors=\"0\"" + echo + fi +} + +checkresult results +checkresult results-java7 +checkresult results-x32 diff --git a/make/scripts/install-ati-stream.sh b/make/scripts/install-ati-stream.sh index 94d3eca6..94d3eca6 100644..100755 --- a/make/scripts/install-ati-stream.sh +++ b/make/scripts/install-ati-stream.sh diff --git a/make/scripts/make.jocl.all.linux-armv6-cross.sh b/make/scripts/make.jocl.all.linux-armv6-cross.sh index 97f3c1f9..d13d51b0 100755 --- a/make/scripts/make.jocl.all.linux-armv6-cross.sh +++ b/make/scripts/make.jocl.all.linux-armv6-cross.sh @@ -1,12 +1,12 @@ #! /bin/sh -SDIR=`dirname $0` +SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh fi -PATH=`pwd`/../gluegen/make/lib/toolchain/armsf-linux-gnueabi/bin:$PATH +PATH=`pwd`/../../gluegen/make/lib/toolchain/armsf-linux-gnueabi/bin:$PATH export PATH # -Dc.compiler.debug=true @@ -31,7 +31,7 @@ export TARGET_ANT_HOME=/usr/share/ant export TARGET_PLATFORM_LIBS=/opt-linux-armv6-eabi/lib export TARGET_JAVA_LIBS=/opt-linux-armv6-eabi/jre/lib/arm -export GLUEGEN_CPPTASKS_FILE="../gluegen/make/lib/gluegen-cpptasks-linux-armv6.xml" +export GLUEGEN_CPPTASKS_FILE="../../gluegen/make/lib/gluegen-cpptasks-linux-armv6.xml" #export JUNIT_DISABLED="true" #export JUNIT_RUN_ARG0="-Dnewt.test.Screen.disableScreenMode" diff --git a/make/scripts/make.jocl.all.linux-armv6hf-cross.sh b/make/scripts/make.jocl.all.linux-armv6hf-cross.sh index 36343d27..fe375c12 100755 --- a/make/scripts/make.jocl.all.linux-armv6hf-cross.sh +++ b/make/scripts/make.jocl.all.linux-armv6hf-cross.sh @@ -1,12 +1,12 @@ #! /bin/sh -SDIR=`dirname $0` +SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh fi -PATH=`pwd`/../gluegen/make/lib/toolchain/armhf-linux-gnueabi/bin:$PATH +PATH=`pwd`/../../gluegen/make/lib/toolchain/armhf-linux-gnueabi/bin:$PATH export PATH # -Dc.compiler.debug=true @@ -31,7 +31,7 @@ export TARGET_ANT_HOME=/usr/share/ant export TARGET_PLATFORM_LIBS=/opt-linux-armv6-armhf/lib export TARGET_JAVA_LIBS=/opt-linux-armv6-armhf/jre/lib/arm -export GLUEGEN_CPPTASKS_FILE="../gluegen/make/lib/gluegen-cpptasks-linux-armv6hf.xml" +export GLUEGEN_CPPTASKS_FILE="../../gluegen/make/lib/gluegen-cpptasks-linux-armv6hf.xml" #export JUNIT_DISABLED="true" #export JUNIT_RUN_ARG0="-Dnewt.test.Screen.disableScreenMode" diff --git a/make/scripts/make.jocl.all.linux-x86-clang.sh b/make/scripts/make.jocl.all.linux-x86-clang.sh index ca9c8abc..be694d1a 100644..100755 --- a/make/scripts/make.jocl.all.linux-x86-clang.sh +++ b/make/scripts/make.jocl.all.linux-x86-clang.sh @@ -2,15 +2,15 @@ SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86.sh fi export SOURCE_LEVEL=1.6 export TARGET_LEVEL=1.6 export TARGET_RT_JAR=/opt-share/jre1.6.0_30/lib/rt.jar -export GLUEGEN_PROPERTIES_FILE="../gluegen/make/lib/gluegen-clang.properties" +export GLUEGEN_PROPERTIES_FILE="../../gluegen/make/lib/gluegen-clang.properties" # or -Dgcc.compat.compiler=clang #export JOGAMP_JAR_CODEBASE="Codebase: *.jogamp.org" diff --git a/make/scripts/make.jocl.all.linux-x86.sh b/make/scripts/make.jocl.all.linux-x86.sh index 04494b21..010a6041 100644..100755 --- a/make/scripts/make.jocl.all.linux-x86.sh +++ b/make/scripts/make.jocl.all.linux-x86.sh @@ -2,8 +2,8 @@ SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86.sh fi export SOURCE_LEVEL=1.6 diff --git a/make/scripts/make.jocl.all.linux-x86_64-clang.sh b/make/scripts/make.jocl.all.linux-x86_64-clang.sh index 1d2a2a05..a30eb3c2 100644..100755 --- a/make/scripts/make.jocl.all.linux-x86_64-clang.sh +++ b/make/scripts/make.jocl.all.linux-x86_64-clang.sh @@ -1,9 +1,9 @@ #! /bin/sh -SDIR=`dirname $0` +SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh fi # -Dbuild.archiveon=true \ @@ -12,7 +12,7 @@ export SOURCE_LEVEL=1.6 export TARGET_LEVEL=1.6 export TARGET_RT_JAR=/opt-share/jre1.6.0_30/lib/rt.jar -export GLUEGEN_PROPERTIES_FILE="../gluegen/make/lib/gluegen-clang.properties" +export GLUEGEN_PROPERTIES_FILE="../../gluegen/make/lib/gluegen-clang.properties" # or -Dgcc.compat.compiler=clang #export JOGAMP_JAR_CODEBASE="Codebase: *.jogamp.org" diff --git a/make/scripts/make.jocl.all.linux-x86_64.sh b/make/scripts/make.jocl.all.linux-x86_64.sh index 8e508684..460af803 100644..100755 --- a/make/scripts/make.jocl.all.linux-x86_64.sh +++ b/make/scripts/make.jocl.all.linux-x86_64.sh @@ -1,9 +1,9 @@ #! /bin/sh -SDIR=`dirname $0` +SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh fi # -Dbuild.archiveon=true \ diff --git a/make/scripts/make.jocl.all.macosx-clang.sh b/make/scripts/make.jocl.all.macosx-clang.sh index fc16ed15..6e5552d9 100755 --- a/make/scripts/make.jocl.all.macosx-clang.sh +++ b/make/scripts/make.jocl.all.macosx-clang.sh @@ -14,7 +14,7 @@ export SOURCE_LEVEL=1.6 export TARGET_LEVEL=1.6 export TARGET_RT_JAR=/opt-share/jre1.6.0_30/lib/rt.jar -export GLUEGEN_PROPERTIES_FILE="../gluegen/make/lib/gluegen-xcode_clang.properties" +export GLUEGEN_PROPERTIES_FILE="../../gluegen/make/lib/gluegen-xcode_clang.properties" # or -Dgcc.compat.compiler=xcode.clang #export JOGAMP_JAR_CODEBASE="Codebase: *.jogamp.org" diff --git a/make/scripts/make.jocl.all.macosx.sh b/make/scripts/make.jocl.all.macosx.sh index 20f65b92..20f65b92 100644..100755 --- a/make/scripts/make.jocl.all.macosx.sh +++ b/make/scripts/make.jocl.all.macosx.sh diff --git a/make/scripts/make.jocl.all.solaris-x86.sh b/make/scripts/make.jocl.all.solaris-x86.sh index a59f756b..6e643cb2 100644..100755 --- a/make/scripts/make.jocl.all.solaris-x86.sh +++ b/make/scripts/make.jocl.all.solaris-x86.sh @@ -2,8 +2,8 @@ SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86.sh fi export SOURCE_LEVEL=1.6 diff --git a/make/scripts/make.jocl.all.solaris-x86_64.sh b/make/scripts/make.jocl.all.solaris-x86_64.sh index 2a207ab5..abca7e2a 100644..100755 --- a/make/scripts/make.jocl.all.solaris-x86_64.sh +++ b/make/scripts/make.jocl.all.solaris-x86_64.sh @@ -2,8 +2,8 @@ SDIR=`dirname $0` -if [ -e $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then - . $SDIR/../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh +if [ -e $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh ] ; then + . $SDIR/../../../gluegen/make/scripts/setenv-build-jogl-x86_64.sh fi export SOURCE_LEVEL=1.6 diff --git a/make/scripts/make.jocl.all.win32.bat b/make/scripts/make.jocl.all.win32.bat index bb4418bd..d75d5e70 100644..100755 --- a/make/scripts/make.jocl.all.win32.bat +++ b/make/scripts/make.jocl.all.win32.bat @@ -2,7 +2,7 @@ set THISDIR="C:\JOGL" set J2RE_HOME=c:\jre1.7.0_45_x32
set JAVA_HOME=c:\jdk1.7.0_45_x32
-set ANT_PATH=C:\apache-ant-1.8.0
+set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/make.jocl.all.win64.bat b/make/scripts/make.jocl.all.win64.bat index a174e710..56e200a0 100644..100755 --- a/make/scripts/make.jocl.all.win64.bat +++ b/make/scripts/make.jocl.all.win64.bat @@ -2,7 +2,7 @@ set THISDIR="C:\JOGL" set J2RE_HOME=c:\jre1.7.0_45_x64
set JAVA_HOME=c:\jdk1.7.0_45_x64
-set ANT_PATH=C:\apache-ant-1.8.0
+set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw64\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/tests-win.bat b/make/scripts/tests-win.bat index 583b5cde..ad4daf9a 100755 --- a/make/scripts/tests-win.bat +++ b/make/scripts/tests-win.bat @@ -1 +1,13 @@ -scripts\java-win.bat com.jogamp.opencl.JoclVersion %* +REM scripts\java-win.bat com.jogamp.opencl.JoclVersion %* + +scripts\java-win.bat com.jogamp.opencl.CLBufferTest %* +REM scripts\java-win.bat com.jogamp.opencl.CLCommandQueueTest %* +REM scripts\java-win.bat com.jogamp.opencl.CLExceptionTest %* +REM scripts\java-win.bat com.jogamp.opencl.CLImageTest %* +REM scripts\java-win.bat com.jogamp.opencl.CLProgramTest %* +REM scripts\java-win.bat com.jogamp.opencl.HighLevelBindingTest %* +REM scripts\java-win.bat com.jogamp.opencl.LowLevelBindingTest %* +REM scripts\java-win.bat com.jogamp.opencl.TestJoclVersion %* +REM scripts\java-win.bat com.jogamp.opencl.TestUtils %* +REM scripts\java-win.bat com.jogamp.opencl.gl.CLGLTest %* +REM scripts\java-win.bat com.jogamp.opencl.util.concurrent.CLMultiContextTest %* diff --git a/make/scripts/tests-x32.bat b/make/scripts/tests-x32.bat index c8ead0ad..6aebd5a7 100755 --- a/make/scripts/tests-x32.bat +++ b/make/scripts/tests-x32.bat @@ -21,8 +21,14 @@ set BLD_DIR=..\%BLD_SUB% REM set LIB_DIR=..\..\gluegen\%BLD_SUB%\obj;%BLD_DIR%\lib
set LIB_DIR=
-set CP_ALL=.;%BLD_DIR%\jar\jogl-all.jar;%BLD_DIR%\jar\jogl-test.jar;..\..\gluegen\%BLD_SUB%\gluegen-rt.jar;..\..\gluegen\make\lib\junit.jar;%ANT_PATH%\lib\ant.jar;%ANT_PATH%\lib\ant-junit.jar;%BLD_DIR%\..\make\lib\swt\win32-win32-x86\swt-debug.jar
+set CP_ALL=.;%BLD_DIR%\jar\jocl.jar;%BLD_DIR%\jar\jocl-test.jar;..\..\jogl\%BLD_SUB%\jar\jogl-all.jar;..\..\joal\%BLD_SUB%\jar\joal.jar;..\..\gluegen\%BLD_SUB%\gluegen-rt.jar;..\..\gluegen\make\lib\junit.jar;%ANT_PATH%\lib\ant.jar;%ANT_PATH%\lib\ant-junit.jar;%BLD_DIR%\..\make\lib\swt\win32-win32-x86\swt-debug.jar
echo CP_ALL %CP_ALL%
+REM set D_ARGS="-Djogamp.debug=all" "-Djocl.debug=all"
+REM set D_ARGS="-Djogamp.debug.ProcAddressHelper" "-Djogamp.debug.NativeLibrary" "-Djogamp.debug.NativeLibrary.Lookup" "-Djogamp.debug.JNILibLoader" "-Djogamp.debug.TempJarCache" "-Djogamp.debug.JarUtil" "-Djocl.debug=all"
+set D_ARGS="-Djogamp.debug.ProcAddressHelper" "-Djogamp.debug.NativeLibrary" "-Djogamp.debug.NativeLibrary.Lookup" "-Djogamp.debug.JNILibLoader"
+
+REM set X_ARGS="-Dsun.java2d.noddraw=true" "-Dsun.awt.noerasebackground=true"
+
scripts\tests-win.bat %*
diff --git a/make/scripts/tests-x64.bat b/make/scripts/tests-x64.bat index ac74f4c9..2a480d9a 100755 --- a/make/scripts/tests-x64.bat +++ b/make/scripts/tests-x64.bat @@ -16,10 +16,15 @@ set BLD_DIR=..\%BLD_SUB% REM set LIB_DIR=%BLD_DIR%\lib;..\..\gluegen\%BLD_SUB%\obj
set LIB_DIR=
-set CP_ALL=.;%BLD_DIR%\jar\jogl-all.jar;%BLD_DIR%\jar\jogl-test.jar;..\..\joal\%BLD_SUB%\joal.jar;..\..\gluegen\%BLD_SUB%\gluegen-rt.jar;..\..\gluegen\make\lib\junit.jar;%ANT_PATH%\lib\ant.jar;%ANT_PATH%\lib\ant-junit.jar;%BLD_DIR%\..\make\lib\swt\win32-win32-x86_64\swt-debug.jar
+set CP_ALL=.;%BLD_DIR%\jar\jocl.jar;%BLD_DIR%\jar\jocl-test.jar;..\..\jogl\%BLD_SUB%\jar\jogl-all.jar;..\..\joal\%BLD_SUB%\jar\joal.jar;..\..\gluegen\%BLD_SUB%\gluegen-rt.jar;..\..\gluegen\make\lib\junit.jar;%ANT_PATH%\lib\ant.jar;%ANT_PATH%\lib\ant-junit.jar;%BLD_DIR%\..\make\lib\swt\win32-win32-x86_64\swt-debug.jar
+
echo CP_ALL %CP_ALL%
-set X_ARGS="-Dsun.java2d.noddraw=true" "-Dsun.awt.noerasebackground=true"
+REM set D_ARGS="-Djogamp.debug=all" "-Djocl.debug=all"
+REM set D_ARGS="-Djogamp.debug.ProcAddressHelper" "-Djogamp.debug.NativeLibrary" "-Djogamp.debug.NativeLibrary.Lookup" "-Djogamp.debug.JNILibLoader" "-Djogamp.debug.TempJarCache" "-Djogamp.debug.JarUtil" "-Djocl.debug=all"
+set D_ARGS="-Djogamp.debug.ProcAddressHelper" "-Djogamp.debug.NativeLibrary" "-Djogamp.debug.NativeLibrary.Lookup" "-Djogamp.debug.JNILibLoader"
+
+REM set X_ARGS="-Dsun.java2d.noddraw=true" "-Dsun.awt.noerasebackground=true"
scripts\tests-win.bat %*
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 6337b623..bc718c4f 100644..100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -60,8 +60,12 @@ function jrun() { #D_ARGS="-Dnativewindow.debug=all" #D_ARGS="-Djogl.debug=all" #D_ARGS="-Dnewt.debug=all" - #D_ARGS="-Djocl=all" + #D_ARGS="-Djocl.debug=all" + #D_ARGS="-Djogamp.debug=all -Djocl.debug=all" + #D_ARGS="-Djogamp.debug.ProcAddressHelper -Djogamp.debug.NativeLibrary -Djogamp.debug.NativeLibrary.Lookup -Djogamp.debug.JNILibLoader -Djogamp.debug.TempJarCache -Djogamp.debug.JarUtil -Djocl.debug=all" + D_ARGS="-Djogamp.debug.ProcAddressHelper -Djogamp.debug.NativeLibrary -Djogamp.debug.NativeLibrary.Lookup -Djogamp.debug.JNILibLoader" + #X_ARGS="-Dsun.java2d.noddraw=true -Dsun.awt.noerasebackground=true" #X_ARGS="-verbose:jni" #X_ARGS="-Xrs" @@ -111,7 +115,7 @@ function testawt() { # # -#testnoawt com.jogamp.opencl.CLBufferTest $* +testnoawt com.jogamp.opencl.CLBufferTest $* #testnoawt com.jogamp.opencl.CLCommandQueueTest $* #testnoawt com.jogamp.opencl.CLExceptionTest $* #testnoawt com.jogamp.opencl.CLImageTest $* @@ -120,7 +124,7 @@ function testawt() { #testnoawt com.jogamp.opencl.LowLevelBindingTest $* #testnoawt com.jogamp.opencl.TestJoclVersion $* #testnoawt com.jogamp.opencl.TestUtils $* -testnoawt com.jogamp.opencl.gl.CLGLTest $* +#testnoawt com.jogamp.opencl.gl.CLGLTest $* #testnoawt com.jogamp.opencl.util.concurrent.CLMultiContextTest $* diff --git a/src/com/jogamp/opencl/CLBuffer.java b/src/com/jogamp/opencl/CLBuffer.java index 873256e8..56cbccda 100644 --- a/src/com/jogamp/opencl/CLBuffer.java +++ b/src/com/jogamp/opencl/CLBuffer.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -29,17 +29,17 @@ package com.jogamp.opencl; import com.jogamp.common.nio.Buffers; + import java.util.List; + import com.jogamp.common.nio.PointerBuffer; -import com.jogamp.opencl.CLMemory.Mem; import com.jogamp.opencl.llb.CL; import com.jogamp.opencl.llb.CLBufferBinding; + import java.nio.Buffer; import java.util.ArrayList; import java.util.Collections; -import static com.jogamp.opencl.CLException.*; - /** * OpenCL buffer object wrapping an optional NIO buffer. * @author Michael Bien, et al. @@ -56,17 +56,17 @@ public class CLBuffer<B extends Buffer> extends CLMemory<B> { super(context, directBuffer, size, id, flags); } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") static CLBuffer<?> create(CLContext context, int size, int flags) { if(isHostPointerFlag(flags)) { throw new IllegalArgumentException("no host pointer defined"); } - CLBufferBinding binding = context.getPlatform().getBufferBinding(); - int[] result = new int[1]; - long id = binding.clCreateBuffer(context.ID, flags, size, null, result, 0); - checkForError(result[0], "can not create cl buffer"); + final CLBufferBinding binding = context.getPlatform().getBufferBinding(); + final int[] result = new int[1]; + final long id = binding.clCreateBuffer(context.ID, flags, size, null, result, 0); + CLException.checkForError(result[0], "can not create cl buffer"); return new CLBuffer(context, size, id, flags); } @@ -85,8 +85,8 @@ public class CLBuffer<B extends Buffer> extends CLMemory<B> { int[] result = new int[1]; int size = Buffers.sizeOfBufferElem(directBuffer) * directBuffer.capacity(); long id = binding.clCreateBuffer(context.ID, flags, size, host_ptr, result, 0); - checkForError(result[0], "can not create cl buffer"); - + CLException.checkForError(result[0], "can not create cl buffer"); + return new CLBuffer<B>(context, directBuffer, size, id, flags); } @@ -101,24 +101,27 @@ public class CLBuffer<B extends Buffer> extends CLMemory<B> { */ public CLSubBuffer<B> createSubBuffer(int offset, int size, Mem... flags) { - B slice = null; + final B slice; if(buffer != null) { slice = Buffers.slice(buffer, offset, size); int elemSize = Buffers.sizeOfBufferElem(buffer); offset *= elemSize; size *= elemSize; + } else { + slice = null; } - PointerBuffer info = PointerBuffer.allocateDirect(2); - info.put(offset).put(size).rewind(); - int bitset = Mem.flagsToInt(flags); - - CLBufferBinding binding = getPlatform().getBufferBinding(); - int[] err = new int[1]; - long subID = binding.clCreateSubBuffer(ID, bitset, CL.CL_BUFFER_CREATE_TYPE_REGION, info.getBuffer(), err, 0); - checkForError(err[0], "can not create sub buffer"); + final PointerBuffer info = PointerBuffer.allocateDirect(2); + info.put(0, offset); + info.put(1, size); + final int bitset = Mem.flagsToInt(flags); + + final CLBufferBinding binding = getPlatform().getBufferBinding(); + final int[] err = new int[1]; + final long subID = binding.clCreateSubBuffer(ID, bitset, CL.CL_BUFFER_CREATE_TYPE_REGION, info.getBuffer(), err, 0); + CLException.checkForError(err[0], "can not create sub buffer"); - CLSubBuffer<B> clSubBuffer = new CLSubBuffer<B>(this, offset, size, slice, subID, bitset); + final CLSubBuffer<B> clSubBuffer = new CLSubBuffer<B>(this, offset, size, slice, subID, bitset); if(childs == null) { childs = new ArrayList<CLSubBuffer<B>>(); } @@ -136,7 +139,7 @@ public class CLBuffer<B extends Buffer> extends CLMemory<B> { super.release(); } - void onReleaseSubBuffer(CLSubBuffer sub) { + void onReleaseSubBuffer(CLSubBuffer<?> sub) { childs.remove(sub); } @@ -158,7 +161,7 @@ public class CLBuffer<B extends Buffer> extends CLMemory<B> { public boolean isSubBuffer() { return false; } - + @Override public <T extends Buffer> CLBuffer<T> cloneWith(T directBuffer) { return new CLBuffer<T>(context, directBuffer, size, ID, FLAGS); diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java index c3bd0e3f..e801c686 100644 --- a/src/com/jogamp/opencl/CLContext.java +++ b/src/com/jogamp/opencl/CLContext.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -28,14 +28,6 @@ package com.jogamp.opencl; -import com.jogamp.opencl.llb.CL; -import com.jogamp.common.nio.Buffers; -import com.jogamp.opencl.CLDevice.Type; -import com.jogamp.opencl.CLSampler.AddressingMode; -import com.jogamp.opencl.CLSampler.FilteringMode; -import com.jogamp.common.nio.PointerBuffer; -import com.jogamp.opencl.llb.CLContextBinding; -import com.jogamp.opencl.llb.impl.CLImageFormatImpl; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -47,22 +39,25 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.LongBuffer; import java.nio.ShortBuffer; - import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import static java.lang.System.*; -import static com.jogamp.opencl.CLException.*; -import static com.jogamp.common.nio.Buffers.*; -import static com.jogamp.common.os.Platform.*; -import static com.jogamp.opencl.llb.CL.*; -import static com.jogamp.opencl.CLBuffer.*; -import static java.util.Collections.*; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.common.os.Platform; +import com.jogamp.opencl.CLDevice.Type; +import com.jogamp.opencl.CLMemory.Mem; +import com.jogamp.opencl.CLSampler.AddressingMode; +import com.jogamp.opencl.CLSampler.FilteringMode; +import com.jogamp.opencl.llb.CL; +import com.jogamp.opencl.llb.CLContextBinding; +import com.jogamp.opencl.llb.impl.CLImageFormatImpl; /** * CLContext is responsible for managing objects such as command-queues, memory, @@ -76,10 +71,10 @@ import static java.util.Collections.*; * <p> * For a code example see {@link CLPlatform}. * <p/> - * + * * concurrency:<br/> * CLContext is threadsafe. - * + * * @author Michael Bien, et al. */ public class CLContext extends CLObjectResource { @@ -89,23 +84,23 @@ public class CLContext extends CLObjectResource { protected final Set<CLProgram> programs; protected final Set<CLSampler> samplers; protected final Set<CLMemory<? extends Buffer>> memoryObjects; - + protected final Map<CLDevice, List<CLCommandQueue>> queuesMap; protected final CLPlatform platform; - + private final ErrorDispatcher errorHandler; protected CLContext(CLPlatform platform, long contextID, ErrorDispatcher dispatcher) { super(contextID); this.platform = platform; - - this.programs = synchronizedSet(new HashSet<CLProgram>()); - this.samplers = synchronizedSet(new HashSet<CLSampler>()); - this.memoryObjects = synchronizedSet(new HashSet<CLMemory<? extends Buffer>>()); - + + this.programs = Collections.synchronizedSet(new HashSet<CLProgram>()); + this.samplers = Collections.synchronizedSet(new HashSet<CLSampler>()); + this.memoryObjects = Collections.synchronizedSet(new HashSet<CLMemory<? extends Buffer>>()); + this.queuesMap = new HashMap<CLDevice, List<CLCommandQueue>>(); - + this.errorHandler = dispatcher; /* @@ -115,25 +110,25 @@ public class CLContext extends CLObjectResource { } }); */ - + } private synchronized void initDevices(CLContextBinding cl) { - + if (devices == null) { - PointerBuffer deviceCount = PointerBuffer.allocateDirect(1); + final PointerBuffer deviceCount = PointerBuffer.allocateDirect(1); - int ret = cl.clGetContextInfo(ID, CL_CONTEXT_DEVICES, 0, null, deviceCount); - checkForError(ret, "can not enumerate devices"); + int ret = cl.clGetContextInfo(ID, CL.CL_CONTEXT_DEVICES, 0, null, deviceCount); + CLException.checkForError(ret, "can not enumerate devices"); ByteBuffer deviceIDs = Buffers.newDirectByteBuffer((int)deviceCount.get()); - ret = cl.clGetContextInfo(ID, CL_CONTEXT_DEVICES, deviceIDs.capacity(), deviceIDs, null); - checkForError(ret, "can not enumerate devices"); + ret = cl.clGetContextInfo(ID, CL.CL_CONTEXT_DEVICES, deviceIDs.capacity(), deviceIDs, null); + CLException.checkForError(ret, "can not enumerate devices"); - devices = new CLDevice[deviceIDs.capacity() / (is32Bit() ? 4 : 8)]; + devices = new CLDevice[deviceIDs.capacity() / (Platform.is32Bit() ? 4 : 8)]; for (int i = 0; i < devices.length; i++) { - devices[i] = new CLDevice(this, is32Bit() ? deviceIDs.getInt() : deviceIDs.getLong()); + devices[i] = new CLDevice(this, Platform.is32Bit() ? deviceIDs.getInt() : deviceIDs.getLong()); } } } @@ -203,17 +198,17 @@ public class CLContext extends CLObjectResource { } protected static long createContextFromType(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, long deviceType) { - IntBuffer status = newDirectIntBuffer(1); + IntBuffer status = Buffers.newDirectIntBuffer(1); CLContextBinding cl = platform.getContextBinding(); long context = cl.clCreateContextFromType(properties, deviceType, handler, status); - checkForError(status.get(), "can not create CL context"); + CLException.checkForError(status.get(), "can not create CL context"); return context; } protected static long createContext(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, CLDevice... devices) { - IntBuffer status = newDirectIntBuffer(1); + IntBuffer status = Buffers.newDirectIntBuffer(1); PointerBuffer pb = null; if(devices != null && devices.length != 0) { pb = PointerBuffer.allocateDirect(devices.length); @@ -228,7 +223,7 @@ public class CLContext extends CLObjectResource { CLContextBinding cl = platform.getContextBinding(); long context = cl.clCreateContext(properties, pb, handler, status); - checkForError(status.get(), "can not create CL context"); + CLException.checkForError(status.get(), "can not create CL context"); return context; } @@ -238,7 +233,7 @@ public class CLContext extends CLObjectResource { throw new RuntimeException("no OpenCL installation found"); } - return PointerBuffer.allocateDirect(3).put(CL_CONTEXT_PLATFORM) + return PointerBuffer.allocateDirect(3).put(CL.CL_CONTEXT_PLATFORM) .put(platform.ID).put(0) // 0 terminated array .rewind(); } @@ -287,6 +282,7 @@ public class CLContext extends CLObjectResource { */ public CLProgram createProgram(Map<CLDevice, byte[]> binaries) { CLProgram program = CLProgram.create(this, binaries); + program.setNoSource(); programs.add(program); return program; } @@ -295,35 +291,35 @@ public class CLContext extends CLObjectResource { * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. */ public final CLBuffer<ShortBuffer> createShortBuffer(int size, Mem... flags) { - return createBuffer(newDirectShortBuffer(size), flags); + return createBuffer(Buffers.newDirectShortBuffer(size), flags); } /** * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. */ public final CLBuffer<IntBuffer> createIntBuffer(int size, Mem... flags) { - return createBuffer(newDirectIntBuffer(size), flags); + return createBuffer(Buffers.newDirectIntBuffer(size), flags); } /** * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. */ public final CLBuffer<LongBuffer> createLongBuffer(int size, Mem... flags) { - return createBuffer(newDirectLongBuffer(size), flags); + return createBuffer(Buffers.newDirectLongBuffer(size), flags); } /** * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. */ public final CLBuffer<FloatBuffer> createFloatBuffer(int size, Mem... flags) { - return createBuffer(newDirectFloatBuffer(size), flags); + return createBuffer(Buffers.newDirectFloatBuffer(size), flags); } /** * Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer. */ public final CLBuffer<DoubleBuffer> createDoubleBuffer(int size, Mem... flags) { - return createBuffer(newDirectDoubleBuffer(size), flags); + return createBuffer(Buffers.newDirectDoubleBuffer(size), flags); } /** @@ -337,7 +333,7 @@ public class CLContext extends CLObjectResource { * Creates a CLBuffer with the specified flags and buffer size in bytes. */ public final CLBuffer<ByteBuffer> createByteBuffer(int size, int flags) { - return createBuffer(newDirectByteBuffer(size), flags); + return createBuffer(Buffers.newDirectByteBuffer(size), flags); } /** @@ -483,14 +479,11 @@ public class CLContext extends CLObjectResource { public void removeCLErrorHandler(CLErrorHandler handler) { errorHandler.removeHandler(handler); } - + private void release(Collection<? extends CLResource> resources) { // resources remove themselves when released, see above - if(!resources.isEmpty()) { - CLResource[] array = resources.toArray(new CLResource[resources.size()]); - for (CLResource resource : array) { - resource.release(); - } + while(!resources.isEmpty()) { + resources.iterator().next().release(); } } @@ -509,14 +502,13 @@ public class CLContext extends CLObjectResource { synchronized(queuesMap) { final Collection<List<CLCommandQueue>> queuesList = queuesMap.values(); - for( Iterator<List<CLCommandQueue>> queuesI = queuesList.iterator(); queuesI.hasNext(); ) { - release(queuesI.next()); - } + while(!queuesList.isEmpty()) + release(queuesList.iterator().next()); } } finally { int ret = platform.getContextBinding().clReleaseContext(ID); - checkForError(ret, "error releasing context"); + CLException.checkForError(ret, "error releasing context"); } } @@ -531,8 +523,8 @@ public class CLContext extends CLObjectResource { int[] entries = new int[1]; int ret = binding.clGetSupportedImageFormats(ID, flags, type, 0, null, entries, 0); - if(ret != CL_SUCCESS) { - throw newException(ret, "error calling clGetSupportedImageFormats"); + if(ret != CL.CL_SUCCESS) { + throw CLException.newException(ret, "error calling clGetSupportedImageFormats"); } int count = entries[0]; @@ -541,10 +533,10 @@ public class CLContext extends CLObjectResource { } CLImageFormat[] formats = new CLImageFormat[count]; - CLImageFormatImpl impl = CLImageFormatImpl.create(newDirectByteBuffer(count * CLImageFormatImpl.size())); + CLImageFormatImpl impl = CLImageFormatImpl.create(Buffers.newDirectByteBuffer(count * CLImageFormatImpl.size())); ret = binding.clGetSupportedImageFormats(ID, flags, type, count, impl, null); - if(ret != CL_SUCCESS) { - throw newException(ret, "error calling clGetSupportedImageFormats"); + if(ret != CL.CL_SUCCESS) { + throw CLException.newException(ret, "error calling clGetSupportedImageFormats"); } ByteBuffer buffer = impl.getBuffer(); @@ -561,14 +553,14 @@ public class CLContext extends CLObjectResource { * Returns all supported 2d image formats with the (optional) memory allocation flags. */ public CLImageFormat[] getSupportedImage2dFormats(Mem... flags) { - return getSupportedImageFormats(flags==null?0:Mem.flagsToInt(flags), CL_MEM_OBJECT_IMAGE2D); + return getSupportedImageFormats(flags==null?0:Mem.flagsToInt(flags), CL.CL_MEM_OBJECT_IMAGE2D); } /** * Returns all supported 3d image formats with the (optional) memory allocation flags. */ public CLImageFormat[] getSupportedImage3dFormats(Mem... flags) { - return getSupportedImageFormats(flags==null?0:Mem.flagsToInt(flags), CL_MEM_OBJECT_IMAGE3D); + return getSupportedImageFormats(flags==null?0:Mem.flagsToInt(flags), CL.CL_MEM_OBJECT_IMAGE3D); } /** @@ -589,7 +581,7 @@ public class CLContext extends CLObjectResource { */ public List<CLProgram> getPrograms() { synchronized(programs) { - return unmodifiableList(new ArrayList<CLProgram>(programs)); + return Collections.unmodifiableList(new ArrayList<CLProgram>(programs)); } } @@ -598,7 +590,7 @@ public class CLContext extends CLObjectResource { */ public List<CLMemory<? extends Buffer>> getMemoryObjects() { synchronized(memoryObjects) { - return unmodifiableList(new ArrayList<CLMemory<? extends Buffer>>(memoryObjects)); + return Collections.unmodifiableList(new ArrayList<CLMemory<? extends Buffer>>(memoryObjects)); } } @@ -607,7 +599,7 @@ public class CLContext extends CLObjectResource { */ public List<CLSampler> getSamplers() { synchronized(samplers) { - return unmodifiableList(new ArrayList<CLSampler>(samplers)); + return Collections.unmodifiableList(new ArrayList<CLSampler>(samplers)); } } @@ -631,6 +623,17 @@ public class CLContext extends CLObjectResource { } /** + * Returns the maximum {@link CLDevice#getMemBaseAddrAlign()} of all devices. + */ + public long getMaxMemBaseAddrAlign() { + long maxAlignment = 0; + for (CLDevice device : getDevices()) { + maxAlignment = Math.max(maxAlignment, device.getMemBaseAddrAlign()); + } + return maxAlignment; + } + + /** * Returns all devices associated with this CLContext. */ public CLDevice[] getDevices() { @@ -722,13 +725,13 @@ public class CLContext extends CLObjectResource { } CLErrorHandler[] handlers = new CLErrorHandler[clientHandlers.length+1]; - arraycopy(clientHandlers, 0, handlers, 0, clientHandlers.length); + System.arraycopy(clientHandlers, 0, handlers, 0, clientHandlers.length); handlers[handlers.length-1] = handler; clientHandlers = handlers; } private synchronized void removeHandler(CLErrorHandler handler) { - + if(handler == null) { throw new IllegalArgumentException("handler was null."); } @@ -736,8 +739,8 @@ public class CLContext extends CLObjectResource { for (int i = 0; i < clientHandlers.length; i++) { if(handler.equals(clientHandlers[i])) { CLErrorHandler[] handlers = new CLErrorHandler[clientHandlers.length-1]; - arraycopy(clientHandlers, 0, handlers, 0, i); - arraycopy(clientHandlers, i, handlers, 0, handlers.length-i); + System.arraycopy(clientHandlers, 0, handlers, 0, i); + System.arraycopy(clientHandlers, i, handlers, 0, handlers.length-i); clientHandlers = handlers; return; } diff --git a/src/com/jogamp/opencl/CLDevice.java b/src/com/jogamp/opencl/CLDevice.java index b47deb2b..d8e90106 100644 --- a/src/com/jogamp/opencl/CLDevice.java +++ b/src/com/jogamp/opencl/CLDevice.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -28,8 +28,6 @@ package com.jogamp.opencl; -import com.jogamp.opencl.util.CLUtil; -import com.jogamp.opencl.spi.CLInfoAccessor; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collections; @@ -40,7 +38,9 @@ import java.util.Map; import java.util.Scanner; import java.util.Set; -import static com.jogamp.opencl.llb.CL.*; +import com.jogamp.opencl.llb.CL; +import com.jogamp.opencl.spi.CLInfoAccessor; +import com.jogamp.opencl.util.CLUtil; /** * This object represents an OpenCL device. @@ -48,7 +48,7 @@ import static com.jogamp.opencl.llb.CL.*; * @see CLPlatform#getMaxFlopsDevice(com.jogamp.opencl.CLDevice.Type...) * @see CLContext#getDevices() * @see CLContext#getMaxFlopsDevice(com.jogamp.opencl.CLDevice.Type) - * @author Michael Bien + * @author Michael Bien, et al. */ public class CLDevice extends CLObject { @@ -108,7 +108,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NAME") public String getName() { - return deviceInfo.getString(CL_DEVICE_NAME); + return deviceInfo.getString(CL.CL_DEVICE_NAME); } /** @@ -116,7 +116,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PROFILE") public String getProfile() { - return deviceInfo.getString(CL_DEVICE_PROFILE); + return deviceInfo.getString(CL.CL_DEVICE_PROFILE); } /** @@ -124,7 +124,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_VENDOR") public String getVendor() { - return deviceInfo.getString(CL_DEVICE_VENDOR); + return deviceInfo.getString(CL.CL_DEVICE_VENDOR); } /** @@ -132,7 +132,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_VENDOR_ID") public long getVendorID() { - return deviceInfo.getLong(CL_DEVICE_VENDOR_ID); + return deviceInfo.getLong(CL.CL_DEVICE_VENDOR_ID); } /** @@ -140,7 +140,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_VERSION") public CLVersion getVersion() { - return new CLVersion(deviceInfo.getString(CL_DEVICE_VERSION)); + return new CLVersion(deviceInfo.getString(CL.CL_DEVICE_VERSION)); } /** @@ -148,7 +148,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_OPENCL_C_VERSION") public CLVersion getCVersion() { - return new CLVersion(deviceInfo.getString(CL_DEVICE_OPENCL_C_VERSION)); + return new CLVersion(deviceInfo.getString(CL.CL_DEVICE_OPENCL_C_VERSION)); } /** @@ -156,7 +156,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DRIVER_VERSION") public String getDriverVersion() { - return deviceInfo.getString(CL_DRIVER_VERSION); + return deviceInfo.getString(CL.CL_DRIVER_VERSION); } /** @@ -164,7 +164,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_TYPE") public Type getType() { - return Type.valueOf((int)deviceInfo.getLong(CL_DEVICE_TYPE)); + return Type.valueOf((int)deviceInfo.getLong(CL.CL_DEVICE_TYPE)); } /** @@ -173,7 +173,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_ADDRESS_BITS") public int getAddressBits() { - return (int)deviceInfo.getLong(CL_DEVICE_ADDRESS_BITS); + return (int)deviceInfo.getLong(CL.CL_DEVICE_ADDRESS_BITS); } /** @@ -182,7 +182,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT") public int getPreferredShortVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT); } /** @@ -191,7 +191,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR") public int getPreferredCharVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR); + return (int)deviceInfo.getLong(CL.CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR); } /** @@ -200,7 +200,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT") public int getPreferredIntVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT); } /** @@ -209,7 +209,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG") public int getPreferredLongVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG); + return (int)deviceInfo.getLong(CL.CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG); } /** @@ -218,7 +218,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT") public int getPreferredFloatVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT); } /** @@ -227,7 +227,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE") public int getPreferredDoubleVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE); + return (int)deviceInfo.getLong(CL.CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE); } /** @@ -236,7 +236,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR") public int getNativeCharVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR); + return (int)deviceInfo.getLong(CL.CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR); } /** @@ -245,7 +245,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT") public int getNativeShortVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT); } /** @@ -254,7 +254,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_INT") public int getNativeIntVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_NATIVE_VECTOR_WIDTH_INT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_NATIVE_VECTOR_WIDTH_INT); } /** @@ -263,7 +263,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG") public int getNativeLongVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG); + return (int)deviceInfo.getLong(CL.CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG); } /** @@ -272,7 +272,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF") public int getNativeHalfVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF); + return (int)deviceInfo.getLong(CL.CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF); } /** @@ -281,7 +281,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT") public int getNativeFloatVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT); } /** @@ -290,7 +290,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE") public int getNativeDoubleVectorWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE); + return (int)deviceInfo.getLong(CL.CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE); } /** @@ -299,7 +299,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_COMPUTE_UNITS") public int getMaxComputeUnits() { - return (int) deviceInfo.getLong(CL_DEVICE_MAX_COMPUTE_UNITS); + return (int) deviceInfo.getLong(CL.CL_DEVICE_MAX_COMPUTE_UNITS); } /** @@ -309,7 +309,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_WORK_GROUP_SIZE") public int getMaxWorkGroupSize() { - return (int) deviceInfo.getLong(CL_DEVICE_MAX_WORK_GROUP_SIZE); + return (int) deviceInfo.getLong(CL.CL_DEVICE_MAX_WORK_GROUP_SIZE); } /** @@ -317,7 +317,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_CLOCK_FREQUENCY") public int getMaxClockFrequency() { - return (int) (deviceInfo.getLong(CL_DEVICE_MAX_CLOCK_FREQUENCY)); + return (int) (deviceInfo.getLong(CL.CL_DEVICE_MAX_CLOCK_FREQUENCY)); } /** @@ -327,7 +327,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS") public int getMaxWorkItemDimensions() { - return (int) deviceInfo.getLong(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS); + return (int) deviceInfo.getLong(CL.CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS); } /** @@ -338,7 +338,7 @@ public class CLDevice extends CLObject { @CLProperty("CL_DEVICE_MAX_WORK_ITEM_SIZES") public int[] getMaxWorkItemSizes() { int n = getMaxWorkItemDimensions(); - return deviceInfo.getInts(CL_DEVICE_MAX_WORK_ITEM_SIZES, n); + return deviceInfo.getInts(CL.CL_DEVICE_MAX_WORK_ITEM_SIZES, n); } /** @@ -348,7 +348,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_PARAMETER_SIZE") public long getMaxParameterSize() { - return deviceInfo.getLong(CL_DEVICE_MAX_PARAMETER_SIZE); + return deviceInfo.getLong(CL.CL_DEVICE_MAX_PARAMETER_SIZE); } /** @@ -356,7 +356,16 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_MEM_ALLOC_SIZE") public long getMaxMemAllocSize() { - return deviceInfo.getLong(CL_DEVICE_MAX_MEM_ALLOC_SIZE); + return deviceInfo.getLong(CL.CL_DEVICE_MAX_MEM_ALLOC_SIZE); + } + + /** + * Returns the <code>uint32_t</code> memory base address alignment + * value reinterpreted as a <code>long</code> value. + */ + @CLProperty("CL_DEVICE_MEM_BASE_ADDR_ALIGN") + public long getMemBaseAddrAlign() { + return deviceInfo.getUInt32Long(CL.CL_DEVICE_MEM_BASE_ADDR_ALIGN); } /** @@ -364,7 +373,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_GLOBAL_MEM_SIZE") public long getGlobalMemSize() { - return deviceInfo.getLong(CL_DEVICE_GLOBAL_MEM_SIZE); + return deviceInfo.getLong(CL.CL_DEVICE_GLOBAL_MEM_SIZE); } /** @@ -374,7 +383,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_LOCAL_MEM_SIZE") public long getLocalMemSize() { - return deviceInfo.getLong(CL_DEVICE_LOCAL_MEM_SIZE); + return deviceInfo.getLong(CL.CL_DEVICE_LOCAL_MEM_SIZE); } /** @@ -382,7 +391,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_HOST_UNIFIED_MEMORY") public boolean isMemoryUnified() { - return deviceInfo.getLong(CL_DEVICE_HOST_UNIFIED_MEMORY) == CL_TRUE; + return deviceInfo.getLong(CL.CL_DEVICE_HOST_UNIFIED_MEMORY) == CL.CL_TRUE; } /** @@ -391,7 +400,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE") public long getMaxConstantBufferSize() { - return deviceInfo.getLong(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE); + return deviceInfo.getLong(CL.CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE); } /** @@ -399,7 +408,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE") public long getGlobalMemCachelineSize() { - return deviceInfo.getLong(CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE); + return deviceInfo.getLong(CL.CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE); } /** @@ -407,7 +416,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_GLOBAL_MEM_CACHE_SIZE") public long getGlobalMemCacheSize() { - return deviceInfo.getLong(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE); + return deviceInfo.getLong(CL.CL_DEVICE_GLOBAL_MEM_CACHE_SIZE); } /** @@ -416,7 +425,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_CONSTANT_ARGS") public long getMaxConstantArgs() { - return deviceInfo.getLong(CL_DEVICE_MAX_CONSTANT_ARGS); + return deviceInfo.getLong(CL.CL_DEVICE_MAX_CONSTANT_ARGS); } /** @@ -424,7 +433,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_IMAGE_SUPPORT") public boolean isImageSupportAvailable() { - return deviceInfo.getLong(CL_DEVICE_IMAGE_SUPPORT) == CL_TRUE; + return deviceInfo.getLong(CL.CL_DEVICE_IMAGE_SUPPORT) == CL.CL_TRUE; } /** @@ -433,7 +442,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_READ_IMAGE_ARGS") public int getMaxReadImageArgs() { - return (int)deviceInfo.getLong(CL_DEVICE_MAX_READ_IMAGE_ARGS); + return (int)deviceInfo.getLong(CL.CL_DEVICE_MAX_READ_IMAGE_ARGS); } /** @@ -442,7 +451,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_WRITE_IMAGE_ARGS") public int getMaxWriteImageArgs() { - return (int)deviceInfo.getLong(CL_DEVICE_MAX_WRITE_IMAGE_ARGS); + return (int)deviceInfo.getLong(CL.CL_DEVICE_MAX_WRITE_IMAGE_ARGS); } /** @@ -451,7 +460,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_IMAGE2D_MAX_WIDTH") public int getMaxImage2dWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_IMAGE2D_MAX_WIDTH); + return (int)deviceInfo.getLong(CL.CL_DEVICE_IMAGE2D_MAX_WIDTH); } /** @@ -460,7 +469,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_IMAGE2D_MAX_HEIGHT") public int getMaxImage2dHeight() { - return (int)deviceInfo.getLong(CL_DEVICE_IMAGE2D_MAX_HEIGHT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_IMAGE2D_MAX_HEIGHT); } /** @@ -469,7 +478,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_IMAGE3D_MAX_WIDTH") public int getMaxImage3dWidth() { - return (int)deviceInfo.getLong(CL_DEVICE_IMAGE3D_MAX_WIDTH); + return (int)deviceInfo.getLong(CL.CL_DEVICE_IMAGE3D_MAX_WIDTH); } /** @@ -478,7 +487,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_IMAGE3D_MAX_HEIGHT") public int getMaxImage3dHeight() { - return (int)deviceInfo.getLong(CL_DEVICE_IMAGE3D_MAX_HEIGHT); + return (int)deviceInfo.getLong(CL.CL_DEVICE_IMAGE3D_MAX_HEIGHT); } /** @@ -487,7 +496,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_IMAGE3D_MAX_DEPTH") public int getMaxImage3dDepth() { - return (int)deviceInfo.getLong(CL_DEVICE_IMAGE3D_MAX_DEPTH); + return (int)deviceInfo.getLong(CL.CL_DEVICE_IMAGE3D_MAX_DEPTH); } /** @@ -496,7 +505,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_MAX_SAMPLERS") public int getMaxSamplers() { - return (int)deviceInfo.getLong(CL_DEVICE_MAX_SAMPLERS); + return (int)deviceInfo.getLong(CL.CL_DEVICE_MAX_SAMPLERS); } /** @@ -504,7 +513,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_PROFILING_TIMER_RESOLUTION") public long getProfilingTimerResolution() { - return deviceInfo.getLong(CL_DEVICE_PROFILING_TIMER_RESOLUTION); + return deviceInfo.getLong(CL.CL_DEVICE_PROFILING_TIMER_RESOLUTION); } /** @@ -512,7 +521,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_EXECUTION_CAPABILITIES") public EnumSet<Capabilities> getExecutionCapabilities() { - return Capabilities.valuesOf((int)deviceInfo.getLong(CL_DEVICE_EXECUTION_CAPABILITIES)); + return Capabilities.valuesOf((int)deviceInfo.getLong(CL.CL_DEVICE_EXECUTION_CAPABILITIES)); } /** @@ -525,7 +534,7 @@ public class CLDevice extends CLObject { @CLProperty("CL_DEVICE_HALF_FP_CONFIG") public EnumSet<FPConfig> getHalfFPConfig() { if(isHalfFPAvailable()) - return FPConfig.valuesOf((int)deviceInfo.getLong(CL_DEVICE_HALF_FP_CONFIG)); + return FPConfig.valuesOf((int)deviceInfo.getLong(CL.CL_DEVICE_HALF_FP_CONFIG)); else return EnumSet.noneOf(FPConfig.class); } @@ -538,7 +547,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_SINGLE_FP_CONFIG") public EnumSet<FPConfig> getSingleFPConfig() { - return FPConfig.valuesOf((int)deviceInfo.getLong(CL_DEVICE_SINGLE_FP_CONFIG)); + return FPConfig.valuesOf((int)deviceInfo.getLong(CL.CL_DEVICE_SINGLE_FP_CONFIG)); } /** @@ -551,7 +560,7 @@ public class CLDevice extends CLObject { @CLProperty("CL_DEVICE_DOUBLE_FP_CONFIG") public EnumSet<FPConfig> getDoubleFPConfig() { if(isDoubleFPAvailable()) - return FPConfig.valuesOf((int)deviceInfo.getLong(CL_DEVICE_DOUBLE_FP_CONFIG)); + return FPConfig.valuesOf((int)deviceInfo.getLong(CL.CL_DEVICE_DOUBLE_FP_CONFIG)); else return EnumSet.noneOf(FPConfig.class); } @@ -561,7 +570,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_LOCAL_MEM_TYPE") public LocalMemType getLocalMemType() { - return LocalMemType.valueOf((int)deviceInfo.getLong(CL_DEVICE_LOCAL_MEM_TYPE)); + return LocalMemType.valueOf((int)deviceInfo.getLong(CL.CL_DEVICE_LOCAL_MEM_TYPE)); } /** @@ -569,15 +578,16 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_GLOBAL_MEM_CACHE_TYPE") public GlobalMemCacheType getGlobalMemCacheType() { - return GlobalMemCacheType.valueOf((int)deviceInfo.getLong(CL_DEVICE_GLOBAL_MEM_CACHE_TYPE)); + return GlobalMemCacheType.valueOf((int)deviceInfo.getLong(CL.CL_DEVICE_GLOBAL_MEM_CACHE_TYPE)); } + /** * Returns the command-queue properties supported by the device. */ @CLProperty("CL_DEVICE_QUEUE_PROPERTIES") public EnumSet<CLCommandQueue.Mode> getQueueProperties() { - return CLCommandQueue.Mode.valuesOf((int)deviceInfo.getLong(CL_DEVICE_QUEUE_PROPERTIES)); + return CLCommandQueue.Mode.valuesOf((int)deviceInfo.getLong(CL.CL_DEVICE_QUEUE_PROPERTIES)); } /** @@ -585,7 +595,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_AVAILABLE") public boolean isAvailable() { - return deviceInfo.getLong(CL_DEVICE_AVAILABLE) == CL_TRUE; + return deviceInfo.getLong(CL.CL_DEVICE_AVAILABLE) == CL.CL_TRUE; } /** @@ -595,7 +605,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_COMPILER_AVAILABLE") public boolean isCompilerAvailable() { - return deviceInfo.getLong(CL_DEVICE_COMPILER_AVAILABLE) == CL_TRUE; + return deviceInfo.getLong(CL.CL_DEVICE_COMPILER_AVAILABLE) == CL.CL_TRUE; } /** @@ -603,7 +613,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_ENDIAN_LITTLE") public boolean isLittleEndian() { - return deviceInfo.getLong(CL_DEVICE_ENDIAN_LITTLE) == CL_TRUE; + return deviceInfo.getLong(CL.CL_DEVICE_ENDIAN_LITTLE) == CL.CL_TRUE; } /** @@ -613,7 +623,7 @@ public class CLDevice extends CLObject { */ @CLProperty("CL_DEVICE_ERROR_CORRECTION_SUPPORT") public boolean isErrorCorrectionSupported() { - return deviceInfo.getLong(CL_DEVICE_ERROR_CORRECTION_SUPPORT) == CL_TRUE; + return deviceInfo.getLong(CL.CL_DEVICE_ERROR_CORRECTION_SUPPORT) == CL.CL_TRUE; } /** @@ -635,6 +645,15 @@ public class CLDevice extends CLObject { } /** + * Returns {@link #isExtensionAvailable}("cl_khr_icd"). + * @see #getExtensions() + */ + @CLProperty("cl_khr_icd") + public boolean isICDAvailable() { + return isExtensionAvailable("cl_khr_icd"); + } + + /** * Returns {@link #isExtensionAvailable}("cl_khr_gl_sharing") || {@link #isExtensionAvailable}("cl_APPLE_gl_sharing"). * @see #getExtensions() */ @@ -650,7 +669,7 @@ public class CLDevice extends CLObject { public boolean isExtensionAvailable(String extension) { return getExtensions().contains(extension); } - + /** * Returns {@link ByteOrder#LITTLE_ENDIAN} or {@link ByteOrder#BIG_ENDIAN}. */ @@ -670,7 +689,7 @@ public class CLDevice extends CLObject { if(extensions == null) { extensions = new HashSet<String>(); - String ext = deviceInfo.getString(CL_DEVICE_EXTENSIONS); + String ext = deviceInfo.getString(CL.CL_DEVICE_EXTENSIONS); Scanner scanner = new Scanner(ext); while(scanner.hasNext()) @@ -732,12 +751,12 @@ public class CLDevice extends CLObject { /** * The OpenCL device can execute OpenCL kernels. */ - EXEC_KERNEL(CL_EXEC_KERNEL), + EXEC_KERNEL(CL.CL_EXEC_KERNEL), /** * The OpenCL device can execute native kernels. */ - EXEC_NATIVE_KERNEL(CL_EXEC_NATIVE_KERNEL); + EXEC_NATIVE_KERNEL(CL.CL_EXEC_NATIVE_KERNEL); /** * Value of wrapped OpenCL device type. @@ -750,9 +769,9 @@ public class CLDevice extends CLObject { public static Capabilities valueOf(int caps) { switch(caps) { - case(CL_EXEC_KERNEL): + case(CL.CL_EXEC_KERNEL): return EXEC_KERNEL; - case(CL_EXEC_NATIVE_KERNEL): + case(CL.CL_EXEC_NATIVE_KERNEL): return EXEC_NATIVE_KERNEL; } return null; @@ -780,25 +799,25 @@ public class CLDevice extends CLObject { /** * CL_DEVICE_TYPE_CPU */ - CPU(CL_DEVICE_TYPE_CPU), + CPU(CL.CL_DEVICE_TYPE_CPU), /** * CL_DEVICE_TYPE_GPU */ - GPU(CL_DEVICE_TYPE_GPU), + GPU(CL.CL_DEVICE_TYPE_GPU), /** * CL_DEVICE_TYPE_ACCELERATOR */ - ACCELERATOR(CL_DEVICE_TYPE_ACCELERATOR), + ACCELERATOR(CL.CL_DEVICE_TYPE_ACCELERATOR), /** * CL_DEVICE_TYPE_DEFAULT. This type can be used for creating a context on * the default device, a single device can never have this type. */ - DEFAULT(CL_DEVICE_TYPE_DEFAULT), + DEFAULT(CL.CL_DEVICE_TYPE_DEFAULT), /** * CL_DEVICE_TYPE_ALL. This type can be used for creating a context on * all devices, a single device can never have this type. */ - ALL(CL_DEVICE_TYPE_ALL); + ALL(CL.CL_DEVICE_TYPE_ALL); /** * Value of wrapped OpenCL device type. @@ -811,17 +830,17 @@ public class CLDevice extends CLObject { public static Type valueOf(long clDeviceType) { - if(clDeviceType == CL_DEVICE_TYPE_ALL) + if(clDeviceType == CL.CL_DEVICE_TYPE_ALL) return ALL; switch((int)clDeviceType) { - case(CL_DEVICE_TYPE_DEFAULT): + case(CL.CL_DEVICE_TYPE_DEFAULT): return DEFAULT; - case(CL_DEVICE_TYPE_CPU): + case(CL.CL_DEVICE_TYPE_CPU): return CPU; - case(CL_DEVICE_TYPE_GPU): + case(CL.CL_DEVICE_TYPE_GPU): return GPU; - case(CL_DEVICE_TYPE_ACCELERATOR): + case(CL.CL_DEVICE_TYPE_ACCELERATOR): return ACCELERATOR; } return null; @@ -837,32 +856,32 @@ public class CLDevice extends CLObject { /** * denorms are supported. */ - DENORM(CL_FP_DENORM), + DENORM(CL.CL_FP_DENORM), /** * INF and quiet NaNs are supported. */ - INF_NAN(CL_FP_INF_NAN), + INF_NAN(CL.CL_FP_INF_NAN), /** * round to nearest rounding mode supported. */ - ROUND_TO_NEAREST(CL_FP_ROUND_TO_NEAREST), + ROUND_TO_NEAREST(CL.CL_FP_ROUND_TO_NEAREST), /** - * round to +ve and –ve infinity rounding modes supported. + * round to positive and negative infinity rounding modes supported. */ - ROUND_TO_INF(CL_FP_ROUND_TO_INF), + ROUND_TO_INF(CL.CL_FP_ROUND_TO_INF), /** * round to zero rounding mode supported. */ - ROUND_TO_ZERO(CL_FP_ROUND_TO_ZERO), + ROUND_TO_ZERO(CL.CL_FP_ROUND_TO_ZERO), /** * IEEE754-2008 fused multiply-add is supported. */ - FMA(CL_FP_FMA); + FMA(CL.CL_FP_FMA); /** @@ -900,17 +919,17 @@ public class CLDevice extends CLObject { /** * Global memory cache not supported. */ - NONE(CL_NONE), + NONE(CL.CL_NONE), /** * Read only cache. */ - READ_ONLY(CL_READ_ONLY_CACHE), + READ_ONLY(CL.CL_READ_ONLY_CACHE), /** * Read-write cache. */ - READ_WRITE(CL_READ_WRITE_CACHE); + READ_WRITE(CL.CL_READ_WRITE_CACHE); /** @@ -943,12 +962,12 @@ public class CLDevice extends CLObject { /** * GLOBAL implies that no dedicated memory storage is available (global mem is used instead). */ - GLOBAL(CL_GLOBAL), + GLOBAL(CL.CL_GLOBAL), /** * LOCAL implies dedicated local memory storage such as SRAM. */ - LOCAL(CL_LOCAL); + LOCAL(CL.CL_LOCAL); /** * Value of wrapped OpenCL value. @@ -963,9 +982,9 @@ public class CLDevice extends CLObject { * Returns the matching LocalMemCacheType for the given cl type. */ public static LocalMemType valueOf(int clLocalCacheType) { - if(clLocalCacheType == CL_GLOBAL) + if(clLocalCacheType == CL.CL_GLOBAL) return GLOBAL; - else if(clLocalCacheType == CL_LOCAL) + else if(clLocalCacheType == CL.CL_LOCAL) return LOCAL; return null; } diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java index 3919d374..9dd3db82 100644 --- a/src/com/jogamp/opencl/CLProgram.java +++ b/src/com/jogamp/opencl/CLProgram.java @@ -70,6 +70,8 @@ public class CLProgram extends CLObjectResource { private boolean executable; private boolean released; + /** Set if program created from binary, or else getting source can crash the driver on Macs. */ + private boolean noSource; private CLProgram(CLContext context, long id) { super(context, id); @@ -592,10 +594,20 @@ public class CLProgram extends CLObjectResource { } /** + * Must set this if the program is created from binary so we know not to call getSource(), + * which can SIGSEGV on Macs if there is no source. + */ + public void setNoSource() { + noSource = true; + } + + /** * Returns the source code of this program. Note: sources are not cached, * each call of this method calls into Open */ public String getSource() { + if(noSource) + return ""; // some drivers return IVE codes if the program haven't been built from source. try{ return getProgramInfoString(CL_PROGRAM_SOURCE); @@ -810,7 +822,7 @@ public class CLProgram extends CLObjectResource { public final static String UNSAFE_MATH = "-cl-unsafe-math-optimizations"; /** - * Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or ±∞. + * Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or plus/minus infinity. * This option may violate the OpenCL numerical compliance requirements defined in in section 7.4 for * single-precision floating-point, section 9.3.9 for double-precision floating-point, and edge case behavior in section 7.5. */ diff --git a/src/com/jogamp/opencl/CLProgramBuilder.java b/src/com/jogamp/opencl/CLProgramBuilder.java index e80b9923..dd0c64f9 100644 --- a/src/com/jogamp/opencl/CLProgramBuilder.java +++ b/src/com/jogamp/opencl/CLProgramBuilder.java @@ -276,14 +276,16 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); - String suffix = null; + String suffix = ""; if(!binariesMap.isEmpty()) { - CLPlatform platform = binariesMap.keySet().iterator().next().getPlatform(); - suffix = platform.getICDSuffix(); + CLDevice device = binariesMap.keySet().iterator().next(); + if(device.isICDAvailable()) + suffix = device.getPlatform().getICDSuffix(); } - out.writeUTF(suffix); // null if we have no binaries or no devices specified + // empty string if we have no binaries or no devices specified, or if cl_khr_icd isn't supported + out.writeUTF(suffix); out.writeInt(binariesMap.size()); // may be 0 for (Map.Entry<CLDevice, byte[]> entry : binariesMap.entrySet()) { @@ -299,22 +301,22 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); - String suffix = in.readUTF(); + String suffix = in.readUTF(); // empty string means no suffix was written; just picks first platform CLPlatform platform = null; for (CLPlatform p : CLPlatform.listCLPlatforms()) { - if(p.getICDSuffix().equals(suffix)) { + if(suffix.isEmpty() || p.getICDSuffix().equals(suffix)) { platform = p; break; } } - + this.binariesMap = new LinkedHashMap<CLDevice, byte[]>(); List<CLDevice> devices; if(platform != null) { - devices = new ArrayList(Arrays.asList(platform.listCLDevices())); + devices = new ArrayList<CLDevice>(Arrays.asList(platform.listCLDevices())); }else{ - devices = Collections.EMPTY_LIST; + devices = Collections.emptyList(); } int mapSize = in.readInt(); diff --git a/src/com/jogamp/opencl/impl/CLTLInfoAccessor.java b/src/com/jogamp/opencl/impl/CLTLInfoAccessor.java index c31b22a6..f1419c7b 100644 --- a/src/com/jogamp/opencl/impl/CLTLInfoAccessor.java +++ b/src/com/jogamp/opencl/impl/CLTLInfoAccessor.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -28,20 +28,21 @@ package com.jogamp.opencl.impl; -import com.jogamp.opencl.spi.CLInfoAccessor; -import com.jogamp.common.nio.PointerBuffer; -import com.jogamp.common.os.Platform; -import com.jogamp.opencl.util.CLUtil; import java.nio.Buffer; import java.nio.ByteBuffer; -import static com.jogamp.common.nio.Buffers.*; -import static com.jogamp.opencl.CLException.*; +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.Bitstream; +import com.jogamp.opencl.CLException; +import com.jogamp.opencl.spi.CLInfoAccessor; +import com.jogamp.opencl.util.CLUtil; /** * Internal utility for common OpenCL clGetFooInfo calls. * Threadsafe, threadlocal implementation. - * @author Michael Bien + * @author Michael Bien, et al. */ public abstract class CLTLInfoAccessor implements CLInfoAccessor { @@ -51,7 +52,7 @@ public abstract class CLTLInfoAccessor implements CLInfoAccessor { @Override protected ByteBuffer initialValue() { - return newDirectByteBuffer(BB_SIZE); + return Buffers.newDirectByteBuffer(BB_SIZE); } }; @@ -65,27 +66,35 @@ public abstract class CLTLInfoAccessor implements CLInfoAccessor { }; @Override + public final long getUInt32Long(int key) { + final ByteBuffer buffer = getBB(4).putInt(0, 0); + final int ret = getInfo(key, 4, buffer, null); + CLException.checkForError(ret, "error while asking for info value"); + return Bitstream.toUInt32Long(buffer.getInt(0)); + } + + @Override public final long getLong(int key) { ByteBuffer buffer = getBB(8).putLong(0, 0); int ret = getInfo(key, 8, buffer, null); - checkForError(ret, "error while asking for info value"); + CLException.checkForError(ret, "error while asking for info value"); return buffer.getLong(0); } @Override public final String getString(int key) { - + PointerBuffer sizeBuffer = getNSB(); int ret = getInfo(key, 0, null, sizeBuffer); - checkForError(ret, "error while asking for info string"); + CLException.checkForError(ret, "error while asking for info string"); int clSize = (int)sizeBuffer.get(0); ByteBuffer buffer = getBB(clSize); ret = getInfo(key, buffer.capacity(), buffer, null); - checkForError(ret, "error while asking for info string"); + CLException.checkForError(ret, "error while asking for info string"); byte[] array = new byte[clSize]; buffer.get(array).rewind(); @@ -96,10 +105,10 @@ public abstract class CLTLInfoAccessor implements CLInfoAccessor { @Override public final int[] getInts(int key, int n) { - + // FIXME: Really 8 bytes per int on 64bit platforms ? ByteBuffer buffer = getBB(n * (Platform.is32Bit()?4:8)); int ret = getInfo(key, buffer.capacity(), buffer, null); - checkForError(ret, "error while asking for info value"); + CLException.checkForError(ret, "error while asking for info value"); int[] array = new int[n]; for(int i = 0; i < array.length; i++) { @@ -116,7 +125,7 @@ public abstract class CLTLInfoAccessor implements CLInfoAccessor { protected ByteBuffer getBB(int minCapacity) { if(minCapacity > BB_SIZE) { - return newDirectByteBuffer(minCapacity); + return Buffers.newDirectByteBuffer(minCapacity); }else{ return localBB.get(); } diff --git a/src/com/jogamp/opencl/llb/impl/CLDynamicLibraryBundleInfo.java b/src/com/jogamp/opencl/llb/impl/CLDynamicLibraryBundleInfo.java index 36bc26f9..19d89fc1 100644 --- a/src/com/jogamp/opencl/llb/impl/CLDynamicLibraryBundleInfo.java +++ b/src/com/jogamp/opencl/llb/impl/CLDynamicLibraryBundleInfo.java @@ -135,12 +135,12 @@ public final class CLDynamicLibraryBundleInfo implements DynamicLibraryBundleInf private static int Impl_len = Impl_str.length(); @Override - public final long toolGetProcAddress(long toolGetProcAddressHandle, String funcName) { + public final long toolGetProcAddress(final long toolGetProcAddressHandle, String funcName) { //FIXME workaround to fix a gluegen issue if( funcName.endsWith(Impl_str) ) { funcName = funcName.substring(0, funcName.length() - Impl_len); } - if(funcName.endsWith("KHR") || funcName.endsWith("EXT")) { + if( funcName.endsWith("KHR") || funcName.endsWith("EXT") ) { return CLImpl.clGetExtensionFunctionAddress(toolGetProcAddressHandle, funcName); } return 0; // on libs .. diff --git a/src/com/jogamp/opencl/spi/CLInfoAccessor.java b/src/com/jogamp/opencl/spi/CLInfoAccessor.java index 0ff0aeac..a02a38e8 100644 --- a/src/com/jogamp/opencl/spi/CLInfoAccessor.java +++ b/src/com/jogamp/opencl/spi/CLInfoAccessor.java @@ -6,13 +6,19 @@ package com.jogamp.opencl.spi; /** * Internal utility for common OpenCL clGetFooInfo calls. * Provides common accessors to CL objects. - * @author Michael Bien + * @author Michael Bien, et al. */ public interface CLInfoAccessor { int[] getInts(int key, int n); /** + * Returns the <code>uint32_t</code> value for the given key, + * reinterpreted as a <code>long</code> value. + */ + long getUInt32Long(int key); + + /** * Returns the long value for the given key. */ long getLong(int key); diff --git a/test/com/jogamp/opencl/CLBufferTest.java b/test/com/jogamp/opencl/CLBufferTest.java index 3ac1fffe..50820d4e 100644 --- a/test/com/jogamp/opencl/CLBufferTest.java +++ b/test/com/jogamp/opencl/CLBufferTest.java @@ -33,6 +33,7 @@ import com.jogamp.opencl.CLMemory.Map; import com.jogamp.opencl.test.util.MiscUtils; import com.jogamp.opencl.test.util.UITestCase; import com.jogamp.common.nio.Buffers; +import com.jogamp.common.util.Bitstream; import java.io.IOException; import java.nio.Buffer; @@ -256,7 +257,7 @@ public class CLBufferTest extends UITestCase { } @Test - public void subBufferTest() { + public void subBufferTest01ByteBuffer() { out.println(" - - - subBufferTest - - - "); if(MiscUtils.isOpenCLUnavailable()) @@ -271,48 +272,77 @@ public class CLBufferTest extends UITestCase { CLContext context = CLContext.create(platform); try{ final int subelements = 5; + final long lMaxAlignment = context.getMaxMemBaseAddrAlign(); + final int iMaxAlignment = Bitstream.uint32LongToInt(lMaxAlignment); + System.err.println("XXX: maxAlignment "+lMaxAlignment+", 0x"+Long.toHexString(lMaxAlignment)+", (int)"+iMaxAlignment+", (int)0x"+Integer.toHexString(iMaxAlignment)); + if( -1 == iMaxAlignment ) { + throw new RuntimeException("Cannot handle MaxMemBaseAddrAlign > MAX_INT, has 0x"+Long.toHexString(lMaxAlignment)); + } // device only - { - CLBuffer<?> buffer = context.createBuffer(64); + CLBuffer<?> buffer = context.createBuffer(iMaxAlignment+subelements); - assertFalse(buffer.isSubBuffer()); - assertNotNull(buffer.getSubBuffers()); - assertTrue(buffer.getSubBuffers().isEmpty()); + assertFalse(buffer.isSubBuffer()); + assertNotNull(buffer.getSubBuffers()); + assertTrue(buffer.getSubBuffers().isEmpty()); - CLSubBuffer<?> subBuffer = buffer.createSubBuffer(10, subelements); + CLSubBuffer<?> subBuffer = buffer.createSubBuffer(iMaxAlignment, subelements); - assertTrue(subBuffer.isSubBuffer()); - assertEquals(subelements, subBuffer.getCLSize()); - assertEquals(10, subBuffer.getOffset()); - assertEquals(10, subBuffer.getCLOffset()); - assertEquals(buffer, subBuffer.getParent()); - assertEquals(1, buffer.getSubBuffers().size()); + assertTrue(subBuffer.isSubBuffer()); + assertEquals(subelements, subBuffer.getCLSize()); + assertEquals(iMaxAlignment, subBuffer.getOffset()); + assertEquals(iMaxAlignment, subBuffer.getCLOffset()); + assertEquals(buffer, subBuffer.getParent()); + assertEquals(1, buffer.getSubBuffers().size()); - subBuffer.release(); - assertEquals(0, buffer.getSubBuffers().size()); - } + subBuffer.release(); + assertEquals(0, buffer.getSubBuffers().size()); + }finally{ + context.release(); + } - // device + direct buffer - { - CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(64); - assertFalse(buffer.isSubBuffer()); - assertNotNull(buffer.getSubBuffers()); - assertTrue(buffer.getSubBuffers().isEmpty()); + } - CLSubBuffer<FloatBuffer> subBuffer = buffer.createSubBuffer(10, subelements); + @Test + public void subBufferTest02FloatBuffer() { - assertTrue(subBuffer.isSubBuffer()); - assertEquals(subelements, subBuffer.getBuffer().capacity()); - assertEquals(10, subBuffer.getOffset()); - assertEquals(40, subBuffer.getCLOffset()); - assertEquals(buffer, subBuffer.getParent()); - assertEquals(1, buffer.getSubBuffers().size()); + out.println(" - - - subBufferTest - - - "); - assertEquals(subBuffer.getCLCapacity(), subBuffer.getBuffer().capacity()); + CLPlatform platform = CLPlatform.getDefault(version(CL_1_1)); + if(platform == null) { + out.println("aborting subBufferTest"); + return; + } - subBuffer.release(); - assertEquals(0, buffer.getSubBuffers().size()); + CLContext context = CLContext.create(platform); + try{ + final int subelements = 5; + final long lMaxAlignment = context.getMaxMemBaseAddrAlign(); + final int iMaxAlignment = Bitstream.uint32LongToInt(lMaxAlignment); + System.err.println("XXX: maxAlignment "+lMaxAlignment+", 0x"+Long.toHexString(lMaxAlignment)+", (int)"+iMaxAlignment+", (int)0x"+Integer.toHexString(iMaxAlignment)); + if( -1 == iMaxAlignment ) { + throw new RuntimeException("Cannot handle MaxMemBaseAddrAlign > MAX_INT, has 0x"+Long.toHexString(lMaxAlignment)); } + // FIXME: See Bug 979: Offset/Alignment via offset calculation per element-count is faulty! + final int floatsPerAlignment = iMaxAlignment / Buffers.SIZEOF_FLOAT; + // device + direct buffer + CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(floatsPerAlignment+subelements); + assertFalse(buffer.isSubBuffer()); + assertNotNull(buffer.getSubBuffers()); + assertTrue(buffer.getSubBuffers().isEmpty()); + + CLSubBuffer<FloatBuffer> subBuffer = buffer.createSubBuffer(floatsPerAlignment, subelements); + + assertTrue(subBuffer.isSubBuffer()); + assertEquals(subelements, subBuffer.getBuffer().capacity()); + assertEquals(floatsPerAlignment, subBuffer.getOffset()); + assertEquals(iMaxAlignment, subBuffer.getCLOffset()); + assertEquals(buffer, subBuffer.getParent()); + assertEquals(1, buffer.getSubBuffers().size()); + + assertEquals(subBuffer.getCLCapacity(), subBuffer.getBuffer().capacity()); + + subBuffer.release(); + assertEquals(0, buffer.getSubBuffers().size()); }finally{ context.release(); diff --git a/test/com/jogamp/opencl/CLCommandQueueTest.java b/test/com/jogamp/opencl/CLCommandQueueTest.java index 76260289..491eab53 100644 --- a/test/com/jogamp/opencl/CLCommandQueueTest.java +++ b/test/com/jogamp/opencl/CLCommandQueueTest.java @@ -487,7 +487,9 @@ public class CLCommandQueueTest extends UITestCase { @Override public void run() { - int groupSize = queue2.getDevice().getMaxWorkItemSizes()[0]; + int maxWorkItemSize = queue2.getDevice().getMaxWorkItemSizes()[0]; + int kernelWorkGroupSize = (int)vectorAddKernel2.getWorkGroupSize( queue2.getDevice() ); + int localWorkSize = Math.min( maxWorkItemSize, kernelWorkGroupSize ); fillBuffer(clBufferA2.buffer, 12345); fillBuffer(clBufferB2.buffer, 67890); @@ -501,7 +503,7 @@ public class CLCommandQueueTest extends UITestCase { // System.out.println("D kernels"); CLEventList events2 = new CLEventList(2); - queue2.put1DRangeKernel(vectorAddKernel2, 0, elements, groupSize, events2); + queue2.put1DRangeKernel(vectorAddKernel2, 0, elements, localWorkSize, events2); queue2.putReadBuffer(clBufferD, false, events2); barrier.waitFor(queue2, events2); diff --git a/test/com/jogamp/opencl/HighLevelBindingTest.java b/test/com/jogamp/opencl/HighLevelBindingTest.java index 6a003435..a0a67595 100644 --- a/test/com/jogamp/opencl/HighLevelBindingTest.java +++ b/test/com/jogamp/opencl/HighLevelBindingTest.java @@ -167,6 +167,7 @@ public class HighLevelBindingTest extends UITestCase { // out.println(" C version: "+device.getCVersion()); //CL 1.1 out.println(" driver version: "+device.getDriverVersion()); out.println(" type: "+device.getType()); + out.println(" mem base addr align: "+device.getMemBaseAddrAlign()); out.println(" global mem: "+device.getGlobalMemSize()/(1024*1024)+" MB"); out.println(" max alloc mem: "+device.getMaxMemAllocSize()/(1024*1024)+" MB"); out.println(" max param size: "+device.getMaxParameterSize()+" byte"); @@ -323,13 +324,29 @@ public class HighLevelBindingTest extends UITestCase { int elementCount = 11444777; // Length of float arrays to process (odd # for illustration) int localWorkSize = device.getMaxWorkItemSizes()[0]; // set and log Global and Local work size dimensions - int globalWorkSize = roundUp(localWorkSize, elementCount); // rounded up to the nearest multiple of the LocalWorkSize - - out.println("allocateing buffers of size: "+globalWorkSize); - - ByteBuffer srcA = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); - ByteBuffer srcB = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); - ByteBuffer dest = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + int globalWorkSize = 0; + + ByteBuffer srcA = null; + ByteBuffer srcB = null; + ByteBuffer dest = null; + boolean allocated = false; + int divisor = 1; + while( !allocated ) { + try { + // round up to the nearest multiple of the LocalWorkSize + globalWorkSize = roundUp(localWorkSize, elementCount); + out.println("allocating three buffers of size: "+globalWorkSize); + srcA = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + srcB = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + dest = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + allocated = true; + } + catch( OutOfMemoryError oome ) { + ++divisor; + elementCount /= divisor; + out.println("not enough direct buffer memory; retrying with smaller buffers"); + } + } fillBuffer(srcA, 23456); fillBuffer(srcB, 46987); diff --git a/test/com/jogamp/opencl/LowLevelBindingTest.java b/test/com/jogamp/opencl/LowLevelBindingTest.java index 5381cab0..90027e13 100644 --- a/test/com/jogamp/opencl/LowLevelBindingTest.java +++ b/test/com/jogamp/opencl/LowLevelBindingTest.java @@ -280,13 +280,30 @@ public class LowLevelBindingTest extends UITestCase { checkError("on clCreateCommandQueue", intBuffer.get(0)); int localWorkSize = Math.min(128, maxWGS); // set and log Global and Local work size dimensions - int globalWorkSize = roundUp(localWorkSize, ELEMENT_COUNT); // rounded up to the nearest multiple of the LocalWorkSize - - out.println("allocateing buffers of size: "+globalWorkSize); - - ByteBuffer srcA = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); - ByteBuffer srcB = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); - ByteBuffer dest = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + int elementCount = ELEMENT_COUNT; + int globalWorkSize = 0; + + ByteBuffer srcA = null; + ByteBuffer srcB = null; + ByteBuffer dest = null; + boolean allocated = false; + int divisor = 1; + while( !allocated ) { + try { + // round up to the nearest multiple of the LocalWorkSize + globalWorkSize = roundUp(localWorkSize, elementCount); + out.println("allocating three buffers of size: "+globalWorkSize); + srcA = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + srcB = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + dest = newDirectByteBuffer(globalWorkSize*SIZEOF_INT); + allocated = true; + } + catch( OutOfMemoryError oome ) { + ++divisor; + elementCount /= divisor; + out.println("not enough direct buffer memory; retrying with smaller buffers"); + } + } // Allocate the OpenCL buffer memory objects for source and result on the device GMEM long devSrcA = cl.clCreateBuffer(context, CL.CL_MEM_READ_ONLY, srcA.capacity(), null, intBuffer); @@ -374,7 +391,7 @@ public class LowLevelBindingTest extends UITestCase { ret = cl.clSetKernelArg(kernel, 0, is32Bit()?SIZEOF_INT:SIZEOF_LONG, wrap(devSrcA)); checkError("on clSetKernelArg0", ret); ret = cl.clSetKernelArg(kernel, 1, is32Bit()?SIZEOF_INT:SIZEOF_LONG, wrap(devSrcB)); checkError("on clSetKernelArg1", ret); ret = cl.clSetKernelArg(kernel, 2, is32Bit()?SIZEOF_INT:SIZEOF_LONG, wrap(devDst)); checkError("on clSetKernelArg2", ret); - ret = cl.clSetKernelArg(kernel, 3, SIZEOF_INT, wrap(ELEMENT_COUNT)); checkError("on clSetKernelArg3", ret); + ret = cl.clSetKernelArg(kernel, 3, SIZEOF_INT, wrap(elementCount)); checkError("on clSetKernelArg3", ret); out.println("used device memory: "+ (srcA.capacity()+srcB.capacity()+dest.capacity())/1000000 +"MB"); |