Commit a55b6d2c authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥

Merge branch 'test' into next

parents f3914ba3 8a2cc996
......@@ -29,3 +29,7 @@ hs_err_pid*
**/include/
**/nbproject/
target/
# java files
*.class
*~
Change log can be found at:
https://gitlab.com/mora/aparapi-ucores/wikis/ReleaseNotes
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
......@@ -198,5 +198,4 @@ Apache License
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
\ No newline at end of file
......@@ -74,4 +74,4 @@ Kernel kernel = new Kernel() {
Range range = Range.create(result.length);
kernel.execute(range);
```
```
\ No newline at end of file
java \
-agentpath:../../com.amd.aparapi.jni/dist/libaparapi_x86_64.so\
-Dcom.amd.aparapi.useAgent=true\
-Djava.library.path=../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
---------------------------------------------------------
APARAPI Installation Notes for CentOS release 6.x (Tested on 6.3/4/5/6)
---------------------------------------------------------
* Note default CentOs repository versions of Java(1.6) and Ant(1.7) are not compatible with latest APARAPI svn src
need to download newr versions (see below)
- install Java JDK
sudo yum install java-1.7.0-openjdk-devel
- install ANT
Download latest ANT -> currently apache-ant-1.9.1-bin.tar.gz
sudo tar xvzf apache-ant-1.9.1-bin.tar.gz -C /opt
sudo ln -s /opt/apache-ant-1.9.1 /opt/ant
- install AMD APP SDK
- needed for build even if hardware not available
- install git
- install g++
sudo yum install gcc-c++
- get src from git repository
git clone ... [project folder]
- set environment vars
source [project folder]/env/aparapiBuildEnv
- build
cd [project folder]/src/aparapi
ant clean build dist
Aparapi Ucores Binary Flow
--------------------------
This is currently used only for FPGAs but we plan to expand it for general manual optimization/compilation of OpenCL source code.
A Binary flow is one where the Aparapi framework generates an OpenCL file while running and then tries to read and execute the binary compilation of that source file.
Sequence of events
------------------
1. Aparapi Application is executed. Aparapi automatically generates an OpencL source file describing the kernel(file name is the full java kernel class name.cl)
2. Aparapi Application automatically tries to load the binary compiled file (full java kernel class name.aocx)
3. If Aparapi Application finds the compiled file it executes the compiled kernel (runs the kernel on the accelerator) else it will revert to JTP mode in which case the application runs as specified without acceleration (JTP mode). A simulation mode if you will.
How this works for FPGAs
------------------------
1. We first run the Application CPU/GPU/ACC mode. Aparapi-Ucores will generate an OpenCL file (ClassXXXName.cl), but will not find the equivalent binary file (ClassXXXName.aocx). It will revert to another execution mode such as JTP. We can simulate if the kernel works logically correct using JTP.
2. We feed the OpenCL file (ClassXXXName.cl) to an FPGA OpenCL compiler.
Example:
a. aoc ClassXXXName.cl -O3 --board pcie385n_a7 -v --report
b. Wait until an optimized FPGA design is created...currently takes several hours
c. Output of the compiler will be: ClassXXXName.aocx
3. Copy the binary output file (ClassXXXName.aocx) to folder where the .cl file resides.
4. Run application again in ACC/GPU mode. This time Aparapi will detect the ClassXXXName.aocx and use the FPGA as the acclerator.
\ No newline at end of file
---------------------------------------------------------
How to build APARAPI from the cmd line after modifications to code
---------------------------------------------------------
* first read APARAPI Installation Notes (APARAPIInstallationNotes.txt) for general instructions on getting the project setup and initial build steps
- open new terminal window
- set environment variables
source [project folder]/env/AlteraV14Env
- to build the APARAPI src tree
cd [project folder]/src/aparapi
ant clean build dist
* this does not build the jni proxy with FPGA support automatically (see below for jni FPGA build)
- to build the APARAPI jni proxy library (should run after initial build and after any changes to CPP source files)
- goto jni dir
cd [project folder]/src/aparapi/com.amd.aparapi.jni/
- to use ant to build standard jni version *
ant
- to use ant to build FPGA jni version *
ant -f build_altera_ocl.xml
* The output of the com.amd.aparapi.jni build is a dll stored in dist folder:
[project folder]/src/aparapi/com.amd.aparapi.jni/dist/libaparapi_x86_64.so
If you have a system where you want to have both FPGA and standard versions available (i.e. with multi OpenCL hardware platforms)you can simply copy the dll's to diffrent locations after the build and link to them through the java vm command line parameters:
Example:
Copy the fpga and standard dll's to the following locations respectively:
/src/aparapi/com.amd.aparapi.jni/dist.fpga/libaparapi_x86_64.so
/src/aparapi/com.amd.aparapi.jni/dist.std/libaparapi_x86_64.so
To select one JNI version or the other at execution time run use the following paramaters to the java command:
java -Djava.library.path=../../com.amd.aparapi.jni/dist.std [rest of cmd line]
java -Djava.library.path=../../com.amd.aparapi.jni/dist.fpga [rest of cmd line]
---------------------------------------------------------
How to run APARAPI tests from the cmd line
---------------------------------------------------------
- open new terminal window
- set environment variables
source [project folder]/env/AlteraV14Env
- got to either samples/examples
- samples dir ->
cd [project folder]/src/aparapi/samples
- examples dir->
cd [project folder]/src/aparapi/examples/
- to run any sample or example:
- run the shell script file named after the sample/example name and specify type of run
Format is*:
sh [name].sh [ACC|CPU|JTP|GPU|SEQ]
Examples:
- run nbody simulation
cd [project folder]/src/aparapi/examples/nbody
sh nbody.sh JTP
sh nbody.sh CPU
sh nbody.sh GPU
sh nbody.sh ACC
- run mandel
cd [project folder]/src/aparapi/samples/mandel/
sh mandel.sh JTP
sh mandel.sh CPU
sh mandel.sh GPU
sh mandel.sh ACC
* For more sophisticated use cases with dual configs(fpga/std) you can use the following format:
sh [name].std.sh [ACC|CPU|JTP|GPU|SEQ]
sh [name].fpga.sh [ACC|CPU|JTP|GPU|SEQ]
You can read more about dual config in how to build aparapi.
Working with multiple platforms
-------------------------------
The original version of Aparapi does not support platform selection (it just chooses the first available one).
This means that in scenarios where you have multiple OpenCL platforms such as AMD, NVidia, Intel, Altera etc. you do not have control over what accelerator device will be used.
One of the changes we made is to allow selection for platforms that support the OpenCL ICD model.
(https://www.khronos.org/news/permalink/opencl-installable-client-driver-icd-loader)
In the spirit of other Aparapi configuration options for device selection this can be set using a configuration option.
The platform configuration option is called: com.amd.aparapi.platformHint
When this option is set it causes Aparapi to search for the string platformHint inside the available platform names and if it found it will select that platform over other available ones.
You can use it on the command line in the following way:
java -Dcom.amd.aparapi.platformHint=AMD ....
or
java -Dcom.amd.aparapi.platformHint=NVIDIA ....
Nbody simulation example with platform selection
---------------------------------------------------------------------
The script nbody.std.no-opengles-platform-select.sh contains the following java command line:
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dcom.amd.aparapi.platformHint=$3 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
To choose an AMD GPU for example we would invoke the script in the following way(the third parameter):
nbody.std.no-opengles-platform-select.sh GPU 1024 AMD
export QUARTUS_ROOTDIR=/home/sdev/altera/14.0/quartus
export PATH=$PATH:$QUARTUS_ROOTDIR/bin
export ALTERAOCLSDKROOT=/home/sdev/altera/14.0/hld
export LD_LIBRARY_PATH=$ALTERAOCLSDKROOT/host/linux64/lib:$ALTERAOCLSDKROOT/board/nalla_pcie/linux64/lib
export PATH=$PATH:$ALTERAOCLSDKROOT/bin
export AOCL_BOARD_PACKAGE_ROOT=/home/sdev/altera/14.0/hld/board/nalla_pcie
export LM_LICENSE_FILE=[your license file here]
# Ant build environment
export ANT_HOME=/opt/ant
export PATH=${PATH}:${ANT_HOME}/bin
# Generated file for hadoop/mahout env
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/
#export HADOOP_HOME=/usr/local/hadoop-1.2.0/
export HADOOP_DIR=/usr/local/hadoop-1.2.0
export HADOOP_PREFIX=$HADOOP_DIR/
export HADOOP_CONF_DIR=HADOOP_DIR/conf
export MAHOUT_HOME=/usr/local/mahout-0.9/
export MAHOUT_VERSION=0.9-SNAPSHOT
#export MAVEN_OPTS=-Xmx1024m
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>correlation-matrix</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@echo off
java ^
-Djava.library.path=..\..\com.amd.aparapi.jni\dist;..\third-party\jogamp ^
-Dcom.amd.aparapi.executionMode=%1 ^
-Dcom.amd.aparapi.enableShowGeneratedOpenCL=true ^
-Dcom.amd.aparapi.enableVerboseJNI=false ^
-Dcom.amd.aparapi.enableProfiling=true ^
-Dbodies=%2 ^
-Dheight=600 ^
-Dwidth=600 ^
-classpath ..\third-party\jogamp\gluegen-rt.jar;..\third-party\jogamp\jogl.all.jar;..\..\com.amd.aparapi\dist\aparapi.jar;nbody.jar ^
com.amd.aparapi.examples.nbody.Local
@echo off
java ^
-agentpath:../../com.amd.aparapi.jni/dist/aparapi_x86_64.dll ^
-Dcom.amd.aparapi.useAgent=true ^
-Djava.library.path=..\third-party\jogamp ^
-Dcom.amd.aparapi.executionMode=%1 ^
-Dcom.amd.aparapi.enableProfiling=false ^
-Dcom.amd.aparapi.enableShowGeneratedOpenCL=true ^
-Dbodies=%2 ^
-Dheight=600 ^
-Dwidth=600 ^
-classpath ..\third-party\jogamp\gluegen-rt.jar;..\third-party\jogamp\jogl-all.jar;..\..\com.amd.aparapi\dist\aparapi.jar;nbody.jar ^
com.amd.aparapi.examples.nbody.Main
@echo off
java ^
-Djava.library.path=..\..\com.amd.aparapi.jni\dist;..\third-party\jogamp ^
-Dcom.amd.aparapi.executionMode=%1 ^
-Dcom.amd.aparapi.enableProfiling=false ^
-Dcom.amd.aparapi.enableShowGeneratedOpenCL=true ^
-Dcom.amd.aparapi.logLevel=SEVERE ^
-Dbodies=%2 ^
-Dheight=600 ^
-Dwidth=600 ^
-classpath ..\third-party\jogamp\gluegen-rt.jar;..\third-party\jogamp\jogl-all.jar;..\..\com.amd.aparapi\dist\aparapi.jar;nbody.jar ^
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.fpga:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.fpga:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dcom.amd.aparapi.enableProfiling=true \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dcom.amd.aparapi.platformHint=$3 \
-Dcom.amd.aparapi.enableProfiling=true \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dcom.amd.aparapi.platformHint=$3 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dcom.amd.aparapi.enableShowGeneratedOpenCL=true \
-Dcom.amd.aparapi.enableVerboseJNI=false \
-Dcom.amd.aparapi.enableProfilingCSV=true \
-Dcom.amd.aparapi.enableProfiling=true \
-Dcom.amd.aparapi.profilingFileNameFormatStr=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dcom.amd.aparapi.enableProfiling=true \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-Djogl.disable.opengles \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dcom.amd.aparapi.enableProfiling=true \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
java \
-Djava.library.path=../../com.amd.aparapi.jni/dist.std:../third-party/jogamp \
-Dcom.amd.aparapi.executionMode=$1 \
-Dbodies=$2 \
-Dheight=600 \
-Dwidth=600 \
-classpath ../third-party/jogamp/jogl-all.jar:../third-party/jogamp/gluegen-rt.jar:../../com.amd.aparapi/dist/aparapi.jar:nbody.jar \
com.amd.aparapi.examples.nbody.Main
......@@ -10,7 +10,7 @@
<groupId>com.aparapi</groupId>
<artifactId>aparapi-examples</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
......@@ -81,7 +81,7 @@
<dependency>
<groupId>com.aparapi</groupId>
<artifactId>aparapi</artifactId>
<version>1.2.0</version>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
......
......@@ -48,6 +48,11 @@ under those regulations, please refer to the U.S. Bureau of Industry and Securit
package com.aparapi.examples.add;
import com.aparapi.Kernel;
import com.aparapi.Range;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import com.aparapi.Kernel;
import com.aparapi.Range;
......@@ -55,7 +60,7 @@ public class Main{
public static void main(String[] _args) {
final int size = 512;
final int size = 30*1000*1000;
final float[] a = new float[size];
final float[] b = new float[size];
......@@ -74,9 +79,39 @@ public class Main{
}
};
// !!! oren -> for JNI debug
// try {
// System.out.printf("Press any key...");
// System.in.read();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// !!! oren -> add time measurement
System.out.printf("Running kernel..");
long startTime = System.nanoTime();
kernel.execute(Range.create(size));
for (int i = 0; i < size; i++) {
long elapsedTimeNano = System.nanoTime() - startTime;
long elapsedTimeSec = TimeUnit.SECONDS.convert(elapsedTimeNano, TimeUnit.NANOSECONDS);
long elapsedTimeMilli = TimeUnit.MILLISECONDS.convert(elapsedTimeNano, TimeUnit.NANOSECONDS);
System.out.printf("****************\n");
System.out.printf("Elapsed time in milli: %d\n",elapsedTimeMilli);
System.out.printf("Elapsed time in sec : %d\n",elapsedTimeSec);
System.out.printf("****************\n");
// !!! oren change -> show first 10 only
//for (int i = 0; i < size; i++) {
int displayRange = (size > 20) ? 20 : size;
System.out.printf("**************** Showing first %d results ****************\n",displayRange);
for (int i = 0; i < displayRange; i++) {
System.out.printf("%6.2f + %6.2f = %8.2f\n", a[i], b[i], sum[i]);
}
......
/*
Copyright (c) 2010-2011, Advanced Micro Devices, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.