Skip to content
Snippets Groups Projects
Commit df48e4d9 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Added extension sample.

parent c7522f9c
No related branches found
No related tags found
No related merge requests found
Showing
with 358 additions and 209 deletions
/classes/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>extension</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>
<?xml version="1.0"?>
<project name="extension" default="build" basedir=".">
<!-- Ideally this would be the latest version of Java but not everyone is going to have it installed -->
<!-- Additionally we want to avoid "Class not found: javac1.8" errors from old Ant versions (i.e. Eclipse) -->
<property name="build.compiler" value="javac1.7" />
<property name="ant.build.javac.source" value="1.7" />
<property name="ant.build.javac.target" value="1.7" />
<target name="build" depends="clean">
<mkdir dir="classes" />
<javac srcdir="src" destdir="classes" debug="on" includeantruntime="false">
<classpath>
<pathelement path="../../com.syncleus.aparapi/dist/aparapi.jar" />
</classpath>
</javac>
<copy todir="classes/com\amd\aparapi\sample\extension" file="src\com\amd\aparapi\sample\extension\fft.cl" />
<copy todir="classes/com\amd\aparapi\sample\extension" file="src\com\amd\aparapi\sample\extension\HistogramKernel.cl" />
<copy todir="classes/com\amd\aparapi\sample\extension" file="src\com\amd\aparapi\sample\extension\mandel.cl" />
<copy todir="classes/com\amd\aparapi\sample\extension" file="src\com\amd\aparapi\sample\extension\mandel2.cl" />
<copy todir="classes/com\amd\aparapi\sample\extension" file="src\com\amd\aparapi\sample\extension\squarer.cl" />
<jar jarfile="${ant.project.name}.jar" basedir="classes" />
</target>
<target name="clean">
<delete dir="classes" />
<delete file="${ant.project.name}.jar" />
</target>
<path id="compiler.class.path">
<pathelement path="../../com.syncleus.aparapi/dist/aparapi.jar" />
</path>
<path id="runtime.class.path" cache="true">
<path refid="compiler.class.path" />
<pathelement path="${ant.project.name}.jar" />
</path>
<!-- FFT -->
<target name="run-fft-gpu">
<java classname="com.syncleus.aparapi.sample.extension.FFTExample" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="GPU" />
</java>
</target>
<target name="run-fft-jtp">
<java classname="com.syncleus.aparapi.sample.extension.FFTExample" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="JTP" />
</java>
</target>
<!-- Histogram -->
<target name="run-histogram-gpu">
<java classname="com.syncleus.aparapi.sample.extension.Histogram" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="GPU" />
</java>
</target>
<target name="run-histogram-jtp">
<java classname="com.syncleus.aparapi.sample.extension.Histogram" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="JTP" />
</java>
</target>
<target name="run-histogram-ideal-gpu">
<java classname="com.syncleus.aparapi.sample.extension.HistogramIdeal" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="GPU" />
</java>
</target>
<target name="run-histogram-ideal-jtp">
<java classname="com.syncleus.aparapi.sample.extension.HistogramIdeal" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="JTP" />
</java>
</target>
<!-- Mandel -->
<target name="run-mandel-gpu">
<java classname="com.syncleus.aparapi.sample.extension.MandelExample" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="GPU" />
</java>
</target>
<target name="run-mandel-jtp">
<java classname="com.syncleus.aparapi.sample.extension.MandelExample" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="JTP" />
</java>
</target>
<!-- Square -->
<target name="run-square-gpu">
<java classname="com.syncleus.aparapi.sample.extension.SquareExample" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="GPU" />
</java>
</target>
<target name="run-square-jtp">
<java classname="com.syncleus.aparapi.sample.extension.SquareExample" fork="true">
<classpath refid="runtime.class.path" />
<sysproperty key="java.library.path" path="..\..\com.syncleus.aparapi.jni\dist" />
<sysproperty key="com.syncleus.aparapi.executionMode" value="JTP" />
</java>
</target>
</project>
java ^
-Djava.library.path=../../com.syncleus.aparapi.jni/dist ^
-Dcom.syncleus.aparapi.executionMode=%1 ^
-Dcom.syncleus.aparapi.enableProfiling=false ^
-Dcom.syncleus.aparapi.enableShowGeneratedOpenCL=true ^
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar;extension.jar ^
com.syncleus.aparapi.sample.extension.FFTExample
java \
-Djava.library.path=../../com.syncleus.aparapi.jni/dist \
-Dcom.syncleus.aparapi.executionMode=$1 \
-Dcom.syncleus.aparapi.enableProfiling=false \
-Dcom.syncleus.aparapi.enableShowGeneratedOpenCL=true \
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar:extension.jar \
com.syncleus.aparapi.sample.extension.FFTExample
java ^
-Xmx1024M^
-Djava.library.path=../../com.syncleus.aparapi.jni/dist ^
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar;extension.jar ^
com.syncleus.aparapi.sample.extension.Histogram
java\
-Djava.library.path=../../com.syncleus.aparapi.jni/dist\
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar:extension.jar\
com.syncleus.aparapi.sample.extension.Histogram
java ^
-Xmx1024M^
-Djava.library.path=../../com.syncleus.aparapi.jni/dist ^
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar;extension.jar ^
com.syncleus.aparapi.sample.extension.HistogramIdeal
java ^
-Djava.library.path=../../com.syncleus.aparapi.jni/dist ^
-Dcom.syncleus.aparapi.executionMode=%1 ^
-Dcom.syncleus.aparapi.enableProfiling=false ^
-Dcom.syncleus.aparapi.enableShowGeneratedOpenCL=true ^
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar;extension.jar ^
com.syncleus.aparapi.sample.extension.MandelExample
java\
-Djava.library.path=../../com.syncleus.aparapi.jni/dist\
-Dcom.syncleus.aparapi.executionMode=$1\
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar:extension.jar\
com.syncleus.aparapi.sample.extension.MandelExample
java ^
-Djava.library.path=../../com.syncleus.aparapi.jni/dist ^
-Dcom.syncleus.aparapi.executionMode=%1 ^
-Dcom.syncleus.aparapi.enableProfiling=false ^
-Dcom.syncleus.aparapi.enableShowGeneratedOpenCL=true ^
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar;extension.jar ^
com.syncleus.aparapi.sample.extension.SquareExample
java\
-Djava.library.path=../../com.syncleus.aparapi.jni/dist\
-Dcom.syncleus.aparapi.executionMode=$1\
-classpath ../../com.syncleus.aparapi/dist/aparapi.jar:extension.jar\
com.syncleus.aparapi.sample.extension.SquareExample
......@@ -29,6 +29,11 @@ public class All {
System.out.println(" 12) Medians");
System.out.println(" 13) MDArray");
System.out.println(" 14) Add");
System.out.println(" 15) Extension - FFT");
System.out.println(" 16) Extension - Histogram");
System.out.println(" 17) Extension - Histogram Ideal");
System.out.println(" 18) Extension - Mandel");
System.out.println(" 19) Extension - Square");
System.out.println();
Scanner in = new Scanner(System.in);
......@@ -101,6 +106,21 @@ public class All {
case "14":
com.syncleus.aparapi.examples.add.Main.main(args);
break;
case "15":
com.syncleus.aparapi.examples.extension.FFTExample.main(args);
break;
case "16":
com.syncleus.aparapi.examples.extension.Histogram.main(args);
break;
case "17":
com.syncleus.aparapi.examples.extension.HistogramIdeal.main(args);
break;
case "18":
com.syncleus.aparapi.examples.extension.MandelExample.main(args);
break;
case "19":
com.syncleus.aparapi.examples.extension.SquareExample.main(args);
break;
default:
System.out.println("Invalid selection.");
}
......
package com.syncleus.aparapi.sample.extension;
/**
* This product currently only contains code developed by authors
* of specific components, as identified by the source code files.
*
* Since product implements StAX API, it has dependencies to StAX API
* classes.
*
* For additional credits (generally to people who reported problems)
* see CREDITS file.
*/
package com.syncleus.aparapi.examples.extension;
import com.syncleus.aparapi.*;
import com.syncleus.aparapi.device.*;
......@@ -10,7 +20,7 @@ import java.util.*;
public class FFTExample{
@Resource("com/amd/aparapi/sample/extension/fft.cl") interface FFT extends OpenCL<FFT>{
@Resource("com/syncleus/aparapi/examples/extension/fft.cl") interface FFT extends OpenCL<FFT>{
public FFT forward(//
Range _range,//
......
package com.syncleus.aparapi.sample.extension;
/**
* This product currently only contains code developed by authors
* of specific components, as identified by the source code files.
*
* Since product implements StAX API, it has dependencies to StAX API
* classes.
*
* For additional credits (generally to people who reported problems)
* see CREDITS file.
*/
package com.syncleus.aparapi.examples.extension;
import com.syncleus.aparapi.Kernel;
import com.syncleus.aparapi.Range;
......@@ -9,7 +19,7 @@ import com.syncleus.aparapi.opencl.OpenCL.Resource;
public class Histogram{
@Resource("com/amd/aparapi/sample/extension/HistogramKernel.cl") interface HistogramKernel extends OpenCL<HistogramKernel>{
@Resource("com/syncleus/aparapi/examples/extension/HistogramKernel.cl") interface HistogramKernel extends OpenCL<HistogramKernel>{
public HistogramKernel histogram256(//
Range _range,//
......
package com.syncleus.aparapi.sample.extension;
/**
* This product currently only contains code developed by authors
* of specific components, as identified by the source code files.
*
* Since product implements StAX API, it has dependencies to StAX API
* classes.
*
* For additional credits (generally to people who reported problems)
* see CREDITS file.
*/
package com.syncleus.aparapi.examples.extension;
import com.syncleus.aparapi.Range;
import com.syncleus.aparapi.device.Device;
......
/**
* This product currently only contains code developed by authors
* of specific components, as identified by the source code files.
*
* Since product implements StAX API, it has dependencies to StAX API
* classes.
*
* For additional credits (generally to people who reported problems)
* see CREDITS file.
*/
package com.syncleus.aparapi.examples.extension;
import com.syncleus.aparapi.*;
import com.syncleus.aparapi.device.*;
import com.syncleus.aparapi.internal.kernel.*;
import com.syncleus.aparapi.opencl.*;
public class JavaMandelBrot extends OpenCLAdapter<MandelBrot> implements MandelBrot{
final int MAX_ITERATIONS = 64;
final int pallette[] = new int[] {
-65536,
-59392,
-53248,
-112640,
-106752,
-166144,
-160256,
-219904,
-279552,
-339200,
-399104,
-985344,
-2624000,
-4197376,
-5770496,
-7343872,
-8851712,
-10425088,
-11932928,
-13375232,
-14817792,
-16260096,
-16719602,
-16720349,
-16721097,
-16721846,
-16722595,
-16723345,
-16724351,
-16725102,
-16726110,
-16727119,
-16728129,
-16733509,
-16738889,
-16744269,
-16749138,
-16754006,
-16758619,
-16762976,
-16767077,
-16771178,
-16774767,
-16514932,
-15662970,
-14942079,
-14221189,
-13631371,
-13107088,
-12648342,
-12320669,
-11992995,
-11796393,
-11665328,
-11993019,
-12386248,
-12845011,
-13303773,
-13762534,
-14286830,
-14745588,
-15269881,
-15728637,
-16252927,
0
};
@Override public MandelBrot createMandleBrot(Range range, float scale, float offsetx, float offsety, int[] rgb) {
final int width = range.getGlobalSize(0);
final int height = range.getGlobalSize(1);
for (int gridy = 0; gridy < height; gridy++) {
for (int gridx = 0; gridx < width; gridx++) {
final float x = ((((gridx) * scale) - ((scale / 2.0f) * width)) / width) + offsetx;
final float y = ((((gridy) * scale) - ((scale / 2.0f) * height)) / height) + offsety;
int count = 0;
float zx = x;
float zy = y;
float new_zx = 0.0f;
for (; (count < MAX_ITERATIONS) && (((zx * zx) + (zy * zy)) < 8.0f); count++) {
new_zx = ((zx * zx) - (zy * zy)) + x;
zy = ((2.0f * zx) * zy) + y;
zx = new_zx;
}
rgb[gridx + (gridy * width)] = pallette[count];
}
}
return (this);
}
}
/**
* This product currently only contains code developed by authors
* of specific components, as identified by the source code files.
*
* Since product implements StAX API, it has dependencies to StAX API
* classes.
*
* For additional credits (generally to people who reported problems)
* see CREDITS file.
*/
package com.syncleus.aparapi.examples.extension;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import com.syncleus.aparapi.*;
import com.syncleus.aparapi.device.*;
import com.syncleus.aparapi.internal.kernel.*;
import com.syncleus.aparapi.opencl.*;
import com.syncleus.aparapi.Range;
public class JavaMandelBrotMultiThread extends OpenCLAdapter<MandelBrot> implements MandelBrot{
final int MAX_ITERATIONS = 64;
final int pallette[] = new int[] {
-65536,
-59392,
-53248,
-112640,
-106752,
-166144,
-160256,
-219904,
-279552,
-339200,
-399104,
-985344,
-2624000,
-4197376,
-5770496,
-7343872,
-8851712,
-10425088,
-11932928,
-13375232,
-14817792,
-16260096,
-16719602,
-16720349,
-16721097,
-16721846,
-16722595,
-16723345,
-16724351,
-16725102,
-16726110,
-16727119,
-16728129,
-16733509,
-16738889,
-16744269,
-16749138,
-16754006,
-16758619,
-16762976,
-16767077,
-16771178,
-16774767,
-16514932,
-15662970,
-14942079,
-14221189,
-13631371,
-13107088,
-12648342,
-12320669,
-11992995,
-11796393,
-11665328,
-11993019,
-12386248,
-12845011,
-13303773,
-13762534,
-14286830,
-14745588,
-15269881,
-15728637,
-16252927,
0
};
@Override public MandelBrot createMandleBrot(final Range range, final float scale, final float offsetx, final float offsety,
final int[] rgb) {
final int width = range.getGlobalSize(0);
final int height = range.getGlobalSize(1);
final int threadCount = 8;
final Thread[] threads = new Thread[threadCount];
final CyclicBarrier barrier = new CyclicBarrier(threadCount + 1);
for (int thread = 0; thread < threadCount; thread++) {
final int threadId = thread;
final int groupHeight = height / threadCount;
(threads[threadId] = new Thread(new Runnable(){
@Override public void run() {
for (int gridy = threadId * groupHeight; gridy < ((threadId + 1) * groupHeight); gridy++) {
for (int gridx = 0; gridx < width; gridx++) {
final float x = ((((gridx) * scale) - ((scale / 2.0f) * width)) / width) + offsetx;
final float y = ((((gridy) * scale) - ((scale / 2.0f) * height)) / height) + offsety;
int count = 0;
float zx = x;
float zy = y;
float new_zx = 0.0f;
for (; (count < MAX_ITERATIONS) && (((zx * zx) + (zy * zy)) < 8.0f); count++) {
new_zx = ((zx * zx) - (zy * zy)) + x;
zy = ((2.0f * zx) * zy) + y;
zx = new_zx;
}
rgb[gridx + (gridy * width)] = pallette[count];
}
}
try {
barrier.await();
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final BrokenBarrierException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
})).start();
}
try {
barrier.await();
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final BrokenBarrierException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (this);
}
}
/**
* This product currently only contains code developed by authors
* of specific components, as identified by the source code files.
*
* Since product implements StAX API, it has dependencies to StAX API
* classes.
*
* For additional credits (generally to people who reported problems)
* see CREDITS file.
*/
package com.syncleus.aparapi.examples.extension;
import com.syncleus.aparapi.*;
import com.syncleus.aparapi.device.*;
import com.syncleus.aparapi.internal.kernel.*;
import com.syncleus.aparapi.opencl.*;
import com.syncleus.aparapi.opencl.OpenCL.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.concurrent.*;
import com.syncleus.aparapi.opencl.OpenCL.Resource;
/**
* An example Aparapi application which displays a view of the Mandelbrot set and lets the user zoom in to a particular point.
*
* When the user clicks on the view, this example application will zoom in to the clicked point and zoom out there after.
* On GPU, additional computing units will offer a better viewing experience. On the other hand on CPU, this example
* application might suffer with sub-optimal frame refresh rate as compared to GPU.
*
* @author gfrost
*
*/
@Resource("com/syncleus/aparapi/examples/extension/mandel2.cl")
public interface Mandel extends OpenCL<com.syncleus.aparapi.examples.extension.Mandel>{
com.syncleus.aparapi.examples.extension.Mandel createMandleBrot(//
Range range,//
@Arg("scale") float scale, //
@Arg("offsetx") float offsetx, //
@Arg("offsety") float offsety, //
@GlobalWriteOnly("rgb") int[] rgb);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment