From c22e658c8da17ecf3b889683e02b6d367f4b8668 Mon Sep 17 00:00:00 2001 From: Gary Frost <frost.gary@gmail.com> Date: Thu, 13 Oct 2011 01:08:58 +0000 Subject: [PATCH] Applied (modified) patch aparapi-5-xx.patch submitted by Witold Bolt. Patch adds Mac OS support. --- CREDITS.txt | 4 +- build.xml | 7 +- com.amd.aparapi.jni/build.xml | 279 +++++++++++------- com.amd.aparapi.jni/src/cpp/aparapi.cpp | 24 +- .../src/java/com/amd/aparapi/Kernel.java | 2 +- 5 files changed, 206 insertions(+), 110 deletions(-) diff --git a/CREDITS.txt b/CREDITS.txt index c0ce9eaf..8187186f 100644 --- a/CREDITS.txt +++ b/CREDITS.txt @@ -2,7 +2,9 @@ We want to correctly attribute all contributions and will maintain this CREDITS. We discourage including attribution as comments in the code, instead we intend to let the history feature of SVN be the primary method for tracking attributions. -Aparapi Contributors. +Aparapi Contributors. Thanks to all. + +Witold Bolt provided patch for issue #5. Added and tested Mac OS support. Oct 12th 2011 diff --git a/build.xml b/build.xml index 0bf02980..85e365b5 100644 --- a/build.xml +++ b/build.xml @@ -4,9 +4,10 @@ <property environment="env" /> <condition property="x86_or_x86_64" value="x86" else="x86_64"> <or><os arch="x86" /><os arch="i386"/></or> </condition> - <condition property="linux_or_windows" value="linux" else="win"> <os family="unix" /> </condition> - <property name="dist" value="dist_${linux_or_windows}_${x86_or_x86_64}"/> - + <condition property="dist" value="dist_windows_${x86_or_x86_64}"><os family="windows" /></condition> + <condition property="dist" value="dist_linux_${x86_or_x86_64}"><and><not><os family="mac"/></not><os family="unix" /></and></condition> + <condition property="dist" value="dist_mac_${x86_or_x86_64}"><os family="mac" /></condition> + <target name="help"> <echo message="Available targets are:-"/> <echo message=" clean"/> diff --git a/com.amd.aparapi.jni/build.xml b/com.amd.aparapi.jni/build.xml index 525a9532..55c4a9db 100644 --- a/com.amd.aparapi.jni/build.xml +++ b/com.amd.aparapi.jni/build.xml @@ -1,21 +1,25 @@ <?xml version="1.0"?> - <!-- You should not have to edit this file. First consider editing the properties in build.properties. --> <project name="com.amd.aparapi.jni" default="build" basedir="."> - <property environment="env" /> <!-- we need env.PATH for msvc only --> - <property file="build.properties"/> + + <property environment="env" /> + <!-- we need env.PATH for msvc only --> + + <property file="build.properties" /> <target name="check"> <fail message="Error:"> <condition> <and> <os family="windows" /> - <isset property="msvc.dir"/> - <not><isset property="msvc.sdk.dir"/></not> + <isset property="msvc.dir" /> + <not> + <isset property="msvc.sdk.dir" /> + </not> </and> </condition> <![CDATA[ @@ -29,8 +33,10 @@ You should not have to edit this file. First consider editing the properties in <condition> <and> <os family="windows" /> - <not><isset property="msvc.dir"/></not> - <isset property="msvc.sdk.dir"/> + <not> + <isset property="msvc.dir" /> + </not> + <isset property="msvc.sdk.dir" /> </and> </condition> <![CDATA[ @@ -39,15 +45,17 @@ You should not have to edit this file. First consider editing the properties in At present msvc.sdk.dir seems to be configured but not msvc.dir ]]> </fail> - <available file="${msvc.dir}" type="dir" property="msvc.dir.exists"/> - <available file="${msvc.sdk.dir}" type="dir" property="msvc.sdk.dir.exists"/> + <available file="${msvc.dir}" type="dir" property="msvc.dir.exists" /> + <available file="${msvc.sdk.dir}" type="dir" property="msvc.sdk.dir.exists" /> <fail message="Error:"> <condition> <and> <os family="windows" /> - <isset property="msvc.dir"/> - <not><isset property="msvc.dir.exists"/></not> + <isset property="msvc.dir" /> + <not> + <isset property="msvc.dir.exists" /> + </not> </and> </condition> <![CDATA[ @@ -60,8 +68,10 @@ You should not have to edit this file. First consider editing the properties in <condition> <and> <os family="windows" /> - <isset property="msvc.sdk.dir"/> - <not><isset property="msvc.sdk.dir.exists"/></not> + <isset property="msvc.sdk.dir" /> + <not> + <isset property="msvc.sdk.dir.exists" /> + </not> </and> </condition> <![CDATA[ @@ -72,13 +82,15 @@ You should not have to edit this file. First consider editing the properties in </fail> - <available file="${mingw.dir}" type="dir" property="mingw.dir.exists"/> + <available file="${mingw.dir}" type="dir" property="mingw.dir.exists" /> <fail message="Error:"> <condition> <and> <os family="windows" /> - <isset property="mingw.dir"/> - <not><isset property="mingw.dir.exists"/></not> + <isset property="mingw.dir" /> + <not> + <isset property="mingw.dir.exists" /> + </not> </and> </condition> <![CDATA[ @@ -91,19 +103,19 @@ You should not have to edit this file. First consider editing the properties in <!--<echo message="msvc.dir.exists ${msvc.dir.exists}"/>--> <!--<echo message="msvc.sdk.dir.exists ${msvc.sdk.dir.exists}"/>--> <!--<echo message="mingw.dir.exists ${mingw.dir.exists}"/>--> - <condition property="use.msvc"> + <condition property="use.msvc"> <and> <os family="windows" /> - <isset property="msvc.dir.exists"/> - <isset property="msvc.sdk.dir.exists"/> + <isset property="msvc.dir.exists" /> + <isset property="msvc.sdk.dir.exists" /> </and> </condition> <!--<echo message="use.msvc ${use.msvc}"/>--> - <condition property="use.mingw"> + <condition property="use.mingw"> <and> <os family="windows" /> - <isset property="mingw.dir.exists"/> + <isset property="mingw.dir.exists" /> </and> </condition> <!--<echo message="use.mingw ${use.mingw}"/>--> @@ -111,8 +123,8 @@ You should not have to edit this file. First consider editing the properties in <fail message="Error:"> <condition> <and> - <isset property="use.mingw"/> - <isset property="use.msvc"/> + <isset property="use.mingw" /> + <isset property="use.msvc" /> </and> </condition> <![CDATA[ @@ -130,8 +142,8 @@ You should not have to edit this file. First consider editing the properties in <os family="windows" /> <not> <or> - <isset property="use.mingw"/> - <isset property="use.msvc"/> + <isset property="use.mingw" /> + <isset property="use.msvc" /> </or> </not> </and> @@ -146,23 +158,52 @@ You should not have to edit this file. First consider editing the properties in * mingw.dir if you prefer if you prefer to use MinGW ]]> </fail> - <condition property="use.gcc"> <os family="unix" /> </condition> - <condition property="x86_or_x86_64" value="x86" else="x86_64"> <or><os arch="x86"/><os arch="i386"/></or> </condition> + <condition property="use.gcc"> + <and> + <os family="unix" /> + <not> + <os family="mac" /> + </not> + </and> + </condition> - <condition property="optional.amd64.subdir" value="" else="amd64\"> <or><os arch="x86"/><os arch="i386"/></or> </condition> + <condition property="use.gcc_mac"> + <os family="mac" /> + </condition> - <condition property="optional.x64.subdir" value="" else="x64\"> <or><os arch="x86"/><os arch="i386"/></or></condition> + <condition property="x86_or_x86_64" value="x86" else="x86_64"> + <or> + <os arch="x86" /> + <os arch="i386" /> + </or> + </condition> + + <condition property="optional.amd64.subdir" value="" else="amd64\"> + <or> + <os arch="x86" /> + <os arch="i386" /> + </or> + </condition> + + <condition property="optional.x64.subdir" value="" else="x64\"> + <or> + <os arch="x86" /> + <os arch="i386" /> + </or> + </condition> - <property name="cl" value="${msvc.dir}\vc\bin\${optional.amd64.subdir}cl.exe"/> + <property name="cl" value="${msvc.dir}\vc\bin\${optional.amd64.subdir}cl.exe" /> - <available file="${msvc.dir}\vc\bin\${optional.amd64.subdir}cl.exe" type="file" property="cl.exists"/> + <available file="${msvc.dir}\vc\bin\${optional.amd64.subdir}cl.exe" type="file" property="cl.exists" /> <fail message="Error:"> <condition> <and> - <isset property="use.msvc"/> - <not><isset property="cl.exists"/></not> + <isset property="use.msvc" /> + <not> + <isset property="cl.exists" /> + </not> </and> </condition> <![CDATA[ @@ -175,7 +216,14 @@ You should not have to edit this file. First consider editing the properties in <fail message="Error:"> <condition> - <not><isset property="amd.app.sdk.dir"/></not> + <and> + <not> + <os family="mac" /> + </not> + <not> + <isset property="amd.app.sdk.dir" /> + </not> + </and> </condition> <![CDATA[ You will need to edit com.amd.aparapi.jni/build.properties to compile aparapi JNI code @@ -183,11 +231,18 @@ You should not have to edit this file. First consider editing the properties in You need to set amd.app.sdk.dir to point to the location where AMD APP SDK is installed ]]> </fail> - <available file="${amd.app.sdk.dir}" type="dir" property="amd.app.sdk.dir.exists"/> + <available file="${amd.app.sdk.dir}" type="dir" property="amd.app.sdk.dir.exists" /> <fail message="Error:"> <condition> - <not><isset property="amd.app.sdk.dir.exists"/></not> + <and> + <not> + <os family="mac" /> + </not> + <not> + <isset property="amd.app.sdk.dir.exists" /> + </not> + </and> </condition> <![CDATA[ You will need to edit com.amd.aparapi.jni/build.properties to compile aparapi JNI code @@ -201,94 +256,112 @@ You should not have to edit this file. First consider editing the properties in <target name="clean" depends="check"> - <delete dir="include"/> - <delete file="libaparapi_${x86_or_x86_64}.so"/> - <delete file="aparapi_${x86_or_x86_64}.dll"/> - <delete file="aparapi.dll"/> - <delete file="aparapi.obj"/> - <delete file="aparapi.o"/> - <delete file="aparapi.lib"/> - <delete file="aparapi.exp"/> + <delete dir="include" /> + <delete file="libaparapi_${x86_or_x86_64}.so" /> + <delete file="aparapi_${x86_or_x86_64}.dll" /> + <delete file="aparapi.dll" /> + <delete file="aparapi.obj" /> + <delete file="aparapi.o" /> + <delete file="aparapi.lib" /> + <delete file="aparapi.exp" /> </target> <target name="javah"> - <mkdir dir="include"/> + <mkdir dir="include" /> <javah classpath="..\com.amd.aparapi\aparapi.jar" destdir="include" force="true"> - <class name="com.amd.aparapi.KernelRunner"/> + <class name="com.amd.aparapi.KernelRunner" /> </javah> </target> <target name="gcc" if="use.gcc"> - <echo message="linuxcc ${os.arch}"/> - <exec executable="g++" > - <arg value="-O3"/> - <arg value="-g"/> - <arg value="-fPIC"/> - <arg value="-I${java.home}/../include"/> - <arg value="-I${java.home}/../include/linux"/> - <arg value="-Iinclude"/> - <arg value="-I${amd.app.sdk.dir}/include"/> - <arg value="-shared"/> - <arg value="-o"/> - <arg value="libaparapi_${x86_or_x86_64}.so"/> - <arg value="src/cpp/aparapi.cpp"/> - <arg value="-L${amd.app.sdk.dir}/lib/${x86_or_x86_64}"/> - <arg value="-lOpenCL"/> + <echo message="linuxcc ${os.arch}" /> + <exec executable="g++"> + <arg value="-O3" /> + <arg value="-g" /> + <arg value="-fPIC" /> + <arg value="-I${java.home}/../include" /> + <arg value="-I${java.home}/../include/linux" /> + <arg value="-Iinclude" /> + <arg value="-I${amd.app.sdk.dir}/include" /> + <arg value="-shared" /> + <arg value="-o" /> + <arg value="libaparapi_${x86_or_x86_64}.so" /> + <arg value="src/cpp/aparapi.cpp" /> + <arg value="-L${amd.app.sdk.dir}/lib/${x86_or_x86_64}" /> + <arg value="-lOpenCL" /> + </exec> + </target> + + <target name="gcc_mac" if="use.gcc_mac"> + <echo message="gcc ${os.arch}" /> + <exec executable="g++"> + <arg value="-O3" /> + <arg value="-g" /> + <arg value="-fPIC" /> + <arg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" /> + <arg value="-I/System/Library/Frameworks/OpenCL.framework/Headers" /> + <arg value="-Iinclude" /> + <arg value="-shared" /> + <arg value="-o" /> + <arg value="libaparapi_${x86_or_x86_64}.dylib" /> + <arg value="src/cpp/aparapi.cpp" /> + <arg value="-framework" /> + <arg value="OpenCL" /> </exec> </target> - <target name="msvc" if="use.msvc"> - <exec executable="${cl}" > - <env key="PATH" path="${env.PATH};${msvc.dir}\\Common7\\IDE"/> - <arg value="/nologo"/> - <arg value="/TP"/> - <arg value="/Ox"/> - <arg value="/I${msvc.dir}\vc\include"/> - <arg value="/I${msvc.sdk.dir}\include"/> - <arg value="/I${java.home}\..\include"/> - <arg value="/I${java.home}\..\include\win32"/> - <arg value="/Iinclude"/> - <arg value="/I${amd.app.sdk.dir}\include"/> - <arg value="/c"/> - <arg value="src\cpp\aparapi.cpp"/> + <target name="msvc" if="use.msvc"> + <exec executable="${cl}"> + <env key="PATH" path="${env.PATH};${msvc.dir}\\Common7\\IDE" /> + <arg value="/nologo" /> + <arg value="/TP" /> + <arg value="/Ox" /> + <arg value="/I${msvc.dir}\vc\include" /> + <arg value="/I${msvc.sdk.dir}\include" /> + <arg value="/I${java.home}\..\include" /> + <arg value="/I${java.home}\..\include\win32" /> + <arg value="/Iinclude" /> + <arg value="/I${amd.app.sdk.dir}\include" /> + <arg value="/c" /> + <arg value="src\cpp\aparapi.cpp" /> </exec> - <exec executable="${cl}" > - <env key="PATH" path="${env.PATH};${msvc.dir}\\Common7\\IDE"/> - <arg value="/nologo"/> - <arg value="/LD"/> - <arg value="aparapi.obj"/> - <arg value="/link"/> - <arg value="/libpath:${msvc.dir}\vc\lib\${optional.amd64.subdir}"/> - <arg value="/libpath:${msvc.sdk.dir}\lib\${optional.x64.subdir}"/> - <arg value="/libpath:${amd.app.sdk.dir}\lib\${x86_or_x86_64}"/> - <arg value="OpenCL.lib"/> - <arg value="/out:aparapi_${x86_or_x86_64}.dll"/> + <exec executable="${cl}"> + <env key="PATH" path="${env.PATH};${msvc.dir}\\Common7\\IDE" /> + <arg value="/nologo" /> + <arg value="/LD" /> + <arg value="aparapi.obj" /> + <arg value="/link" /> + <arg value="/libpath:${msvc.dir}\vc\lib\${optional.amd64.subdir}" /> + <arg value="/libpath:${msvc.sdk.dir}\lib\${optional.x64.subdir}" /> + <arg value="/libpath:${amd.app.sdk.dir}\lib\${x86_or_x86_64}" /> + <arg value="OpenCL.lib" /> + <arg value="/out:aparapi_${x86_or_x86_64}.dll" /> </exec> - </target> <target name="mingw" if="use.mingw"> - <exec executable="${mingw.dir}/bin/g++" > - <env key="PATH" path="${env.PATH};${mingw.dir}/bin"/> - <arg value="-Wall"/> - <arg value="-O3"/> - <arg value="-Wl,--kill-at"/> - <arg value="-I${java.home}\..\include"/> - <arg value="-I${java.home}\..\include\win32"/> - <arg value="-Iinclude"/> - <arg value="-I${amd.app.sdk.dir}\include"/> - <arg value="-shared"/> - <arg value="-o"/> - <arg value="aparapi_${x86_or_x86_64}.dll"/> - <arg value="src\cpp\aparapi.cpp"/> - <arg value="-L${amd.app.sdk.dir}\lib\${x86_or_x86_64}"/> - <arg value="-lOpenCL"/> + <exec executable="${mingw.dir}/bin/g++"> + <env key="PATH" path="${env.PATH};${mingw.dir}/bin" /> + <arg value="-Wall" /> + <arg value="-O3" /> + <arg value="-Wl,--kill-at" /> + <arg value="-I${java.home}\..\include" /> + <arg value="-I${java.home}\..\include\win32" /> + <arg value="-Iinclude" /> + <arg value="-I${amd.app.sdk.dir}\include" /> + <arg value="-shared" /> + <arg value="-o" /> + <arg value="aparapi_${x86_or_x86_64}.dll" /> + <arg value="src\cpp\aparapi.cpp" /> + <arg value="-L${amd.app.sdk.dir}\lib\${x86_or_x86_64}" /> + <arg value="-lOpenCL" /> </exec> </target> - <target name="build" depends="check, javah, msvc, mingw, gcc"/> + + <target name="build" depends="check, javah, msvc, mingw, gcc, gcc_mac" /> </project> diff --git a/com.amd.aparapi.jni/src/cpp/aparapi.cpp b/com.amd.aparapi.jni/src/cpp/aparapi.cpp index 6859fa8f..0d114279 100644 --- a/com.amd.aparapi.jni/src/cpp/aparapi.cpp +++ b/com.amd.aparapi.jni/src/cpp/aparapi.cpp @@ -40,12 +40,22 @@ under those regulations, please refer to the U.S. Bureau of Industry and Securit #include <stdlib.h> #include <string.h> #include <time.h> + +#ifndef __APPLE__ #include <malloc.h> +#endif + #include <sys/types.h> #ifndef _WIN32 #include <unistd.h> #endif + +#ifndef __APPLE__ #include <CL/cl.h> +#else +#include <cl.h> +#endif + #include <jni.h> #define JNIExceptionChecker(){\ @@ -424,8 +434,13 @@ class JNIContext{ } // platformVendorName = "Advanced Micro Devices, Inc."||"NVIDIA Corporation" // platformVersionName = "OpenCL 1.1 AMD-APP-SDK-v2.5 (684.213)"|"OpenCL 1.1 CUDA 4.0.1" - // we check if the platformVersionName starts with "OpenCL 1.1" (10 chars!) +#ifndef __APPLE__ + // Here we check if the platformVersionName starts with "OpenCL 1.1" (10 chars!) if (!strncmp(platformVersionName, "OpenCL 1.1", 10)) { +#else + // Here we check if the platformVersionName starts with "OpenCL 1.1" or "OpenCL 1.0" (10 chars!) + if (!strncmp(platformVersionName, "OpenCL 1.1", 10) || !strncmp(platformVersionName, "OpenCL 1.0", 10)) { +#endif // Get the # of devices status = clGetDeviceIDs(platforms[i], deviceType, 0, NULL, &deviceIdc); // now check if this platform supports the requested device type (GPU or CPU) @@ -434,7 +449,7 @@ class JNIContext{ if (isVerbose()){ fprintf(stderr, "platform %s supports requested device type\n", platformVendorName); } - + deviceIds = new cl_device_id[deviceIdc]; status = clGetDeviceIDs(platform, deviceType, deviceIdc, deviceIds, NULL); if (status == CL_SUCCESS){ @@ -482,7 +497,12 @@ class JNIContext{ }else{ if (isVerbose()){ +#ifndef __APPLE__ fprintf(stderr, "platform %s version %s is not OpenCL 1.1 skipping!\n", platformVendorName, platformVersionName); +#else + fprintf(stderr, "platform %s version %s is neither OpenCL 1.1 or OpenCL 1.0 skipping!\n", platformVendorName, platformVersionName); +#endif + } } } diff --git a/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java b/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java index 33b5cc4e..c6dd14a1 100644 --- a/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java +++ b/com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java @@ -232,7 +232,7 @@ public abstract class Kernel implements Cloneable{ String libName = null; try { - if (arch.equals("amd64")) { + if (arch.equals("amd64") || arch.equals("x86_64")) { libName = "aparapi_x86_64"; logger.fine("attempting to load shared lib " + libName); -- GitLab