diff --git a/samples/extension/.gitignore b/samples/extension/.gitignore deleted file mode 100644 index 840e7d3120ee3206168d49bf62df2c269c38e17e..0000000000000000000000000000000000000000 --- a/samples/extension/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/classes/ diff --git a/samples/extension/.project b/samples/extension/.project deleted file mode 100644 index 1e2c59dc69eca99384cd5999f987cdb332a70bdb..0000000000000000000000000000000000000000 --- a/samples/extension/.project +++ /dev/null @@ -1,17 +0,0 @@ -<?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> diff --git a/samples/extension/build.xml b/samples/extension/build.xml deleted file mode 100644 index bc98d2dbd142116477a97d4016ef89baadde5c38..0000000000000000000000000000000000000000 --- a/samples/extension/build.xml +++ /dev/null @@ -1,124 +0,0 @@ -<?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> diff --git a/samples/extension/fft.bat b/samples/extension/fft.bat deleted file mode 100644 index 9c705745036a4b9faea328f44348a15e3ad330e0..0000000000000000000000000000000000000000 --- a/samples/extension/fft.bat +++ /dev/null @@ -1,9 +0,0 @@ -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 - - diff --git a/samples/extension/fft.sh b/samples/extension/fft.sh deleted file mode 100644 index 66787111035717398542499dfa1c5e9806ce17b9..0000000000000000000000000000000000000000 --- a/samples/extension/fft.sh +++ /dev/null @@ -1,7 +0,0 @@ -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 diff --git a/samples/extension/histo.bat b/samples/extension/histo.bat deleted file mode 100644 index d165b7badc4d53af90415dd8077c0684f8ffe15d..0000000000000000000000000000000000000000 --- a/samples/extension/histo.bat +++ /dev/null @@ -1,7 +0,0 @@ -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 - - diff --git a/samples/extension/histo.sh b/samples/extension/histo.sh deleted file mode 100644 index 0b013340a647287504aa3663743e0c1a4254bc4d..0000000000000000000000000000000000000000 --- a/samples/extension/histo.sh +++ /dev/null @@ -1,4 +0,0 @@ -java\ - -Djava.library.path=../../com.syncleus.aparapi.jni/dist\ - -classpath ../../com.syncleus.aparapi/dist/aparapi.jar:extension.jar\ - com.syncleus.aparapi.sample.extension.Histogram diff --git a/samples/extension/histoideal.bat b/samples/extension/histoideal.bat deleted file mode 100644 index 254b9bb31814b608cbe194f3ab3293de66136786..0000000000000000000000000000000000000000 --- a/samples/extension/histoideal.bat +++ /dev/null @@ -1,7 +0,0 @@ -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 - - diff --git a/samples/extension/mandel.bat b/samples/extension/mandel.bat deleted file mode 100644 index fb4addb7563ffce0d7bed9a9467a205da393a824..0000000000000000000000000000000000000000 --- a/samples/extension/mandel.bat +++ /dev/null @@ -1,9 +0,0 @@ -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 - - diff --git a/samples/extension/mandel.sh b/samples/extension/mandel.sh deleted file mode 100644 index e48030ab273135c0dafa6249ea2d7f95a6477ed2..0000000000000000000000000000000000000000 --- a/samples/extension/mandel.sh +++ /dev/null @@ -1,5 +0,0 @@ -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 diff --git a/samples/extension/square.bat b/samples/extension/square.bat deleted file mode 100644 index e96166674108911e21d1faa6de05686164fa032e..0000000000000000000000000000000000000000 --- a/samples/extension/square.bat +++ /dev/null @@ -1,9 +0,0 @@ -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 - - diff --git a/samples/extension/square.sh b/samples/extension/square.sh deleted file mode 100644 index 89334ac379ff44ddd41d1b57afb190113600ea68..0000000000000000000000000000000000000000 --- a/samples/extension/square.sh +++ /dev/null @@ -1,5 +0,0 @@ -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 diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/StopWatch.java b/samples/extension/src/com/amd/aparapi/sample/extension/StopWatch.java deleted file mode 100644 index 1a535ef3533f7338a21aacf12b1cf078f4fbc929..0000000000000000000000000000000000000000 --- a/samples/extension/src/com/amd/aparapi/sample/extension/StopWatch.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.syncleus.aparapi.sample.extension; - -public class StopWatch{ - long start = 0L; - - public void start() { - start = System.nanoTime(); - } - - public void print(String _str) { - long end = (System.nanoTime() - start) / 1000000; - System.out.println(_str + " " + end); - } - -} diff --git a/src/main/java/com/syncleus/aparapi/examples/All.java b/src/main/java/com/syncleus/aparapi/examples/All.java index 5fc5fb7794a74767564112475085df9b1f1e7aaf..b15c81502fdf33e82b94d7b601836a41a6daa908 100644 --- a/src/main/java/com/syncleus/aparapi/examples/All.java +++ b/src/main/java/com/syncleus/aparapi/examples/All.java @@ -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."); } diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/FFTExample.java b/src/main/java/com/syncleus/aparapi/examples/extension/FFTExample.java similarity index 84% rename from samples/extension/src/com/amd/aparapi/sample/extension/FFTExample.java rename to src/main/java/com/syncleus/aparapi/examples/extension/FFTExample.java index 48e077d15074572665401d74db06f50164b72a87..de3975e4cbaced84fc5da3c93f4734227023e915 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/FFTExample.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/FFTExample.java @@ -1,4 +1,14 @@ -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,// diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/Histogram.java b/src/main/java/com/syncleus/aparapi/examples/extension/Histogram.java similarity index 84% rename from samples/extension/src/com/amd/aparapi/sample/extension/Histogram.java rename to src/main/java/com/syncleus/aparapi/examples/extension/Histogram.java index be6c111d1bee1aec7051084742addc8a7c268802..3a57f14ee4cae479cb4f558c268979bd4f3752b3 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/Histogram.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/Histogram.java @@ -1,4 +1,14 @@ -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,// diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/HistogramIdeal.java b/src/main/java/com/syncleus/aparapi/examples/extension/HistogramIdeal.java similarity index 87% rename from samples/extension/src/com/amd/aparapi/sample/extension/HistogramIdeal.java rename to src/main/java/com/syncleus/aparapi/examples/extension/HistogramIdeal.java index 27b39149c66e5bc27151a147222ef183e026806a..888c78f25dddec7a9a8af3868283da5fe323d902 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/HistogramIdeal.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/HistogramIdeal.java @@ -1,4 +1,14 @@ -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; diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/HistogramKernel.cl b/src/main/java/com/syncleus/aparapi/examples/extension/HistogramKernel.cl similarity index 100% rename from samples/extension/src/com/amd/aparapi/sample/extension/HistogramKernel.cl rename to src/main/java/com/syncleus/aparapi/examples/extension/HistogramKernel.cl diff --git a/src/main/java/com/syncleus/aparapi/examples/extension/JavaMandelBrot.java b/src/main/java/com/syncleus/aparapi/examples/extension/JavaMandelBrot.java new file mode 100644 index 0000000000000000000000000000000000000000..e595e2ec570f56d699e7ce13e1195c17f6cf09f1 --- /dev/null +++ b/src/main/java/com/syncleus/aparapi/examples/extension/JavaMandelBrot.java @@ -0,0 +1,113 @@ +/** + * 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); + } + +} diff --git a/src/main/java/com/syncleus/aparapi/examples/extension/JavaMandelBrotMultiThread.java b/src/main/java/com/syncleus/aparapi/examples/extension/JavaMandelBrotMultiThread.java new file mode 100644 index 0000000000000000000000000000000000000000..45a4fbb3993c366fdb51046fc156d073a59ee660 --- /dev/null +++ b/src/main/java/com/syncleus/aparapi/examples/extension/JavaMandelBrotMultiThread.java @@ -0,0 +1,145 @@ +/** + * 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); + } + +} diff --git a/src/main/java/com/syncleus/aparapi/examples/extension/Mandel.java b/src/main/java/com/syncleus/aparapi/examples/extension/Mandel.java new file mode 100644 index 0000000000000000000000000000000000000000..59c29dab6d74967b32a40861ebe1dcc6ce75431a --- /dev/null +++ b/src/main/java/com/syncleus/aparapi/examples/extension/Mandel.java @@ -0,0 +1,45 @@ +/** + * 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); +} diff --git a/src/main/java/com/syncleus/aparapi/examples/extension/MandelBrot.java b/src/main/java/com/syncleus/aparapi/examples/extension/MandelBrot.java new file mode 100644 index 0000000000000000000000000000000000000000..691727e51ed18d5e965162f078699756dbeea15f --- /dev/null +++ b/src/main/java/com/syncleus/aparapi/examples/extension/MandelBrot.java @@ -0,0 +1,38 @@ +/** + * 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.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 MandelBrot extends OpenCL<MandelBrot>{ + MandelBrot createMandleBrot(// + Range range,// + @Arg("scale") float scale, // + @Arg("offsetx") float offsetx, // + @Arg("offsety") float offsety, // + @GlobalWriteOnly("rgb") int[] rgb); +} diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/MandelExample.java b/src/main/java/com/syncleus/aparapi/examples/extension/MandelExample.java similarity index 56% rename from samples/extension/src/com/amd/aparapi/sample/extension/MandelExample.java rename to src/main/java/com/syncleus/aparapi/examples/extension/MandelExample.java index 1e91cd044fe6fa00d2c1a197edfb0d498877d40e..27394d96b684cfda0126513e2492f12b8f84a6ea 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/MandelExample.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/MandelExample.java @@ -1,3 +1,13 @@ +/** + * 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. + */ /* Copyright (c) 2010-2011, Advanced Micro Devices, Inc. All rights reserved. @@ -36,7 +46,7 @@ under those regulations, please refer to the U.S. Bureau of Industry and Securit */ -package com.syncleus.aparapi.sample.extension; +package com.syncleus.aparapi.examples.extension; import com.syncleus.aparapi.*; import com.syncleus.aparapi.device.*; @@ -50,249 +60,6 @@ import java.awt.event.*; import java.awt.image.*; import java.util.concurrent.*; -/** - * 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/amd/aparapi/sample/extension/mandel2.cl") interface MandelBrot extends OpenCL<MandelBrot>{ - MandelBrot createMandleBrot(// - Range range,// - @Arg("scale") float scale, // - @Arg("offsetx") float offsetx, // - @Arg("offsety") float offsety, // - @GlobalWriteOnly("rgb") int[] rgb); -} - -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); - } - -} - -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); - } - -} - public class MandelExample{ /** User selected zoom-in point on the Mandelbrot view. */ diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/MandelSimple.java b/src/main/java/com/syncleus/aparapi/examples/extension/MandelSimple.java similarity index 88% rename from samples/extension/src/com/amd/aparapi/sample/extension/MandelSimple.java rename to src/main/java/com/syncleus/aparapi/examples/extension/MandelSimple.java index bbe0f8bb55f83eb35037f0a84131fb7808c31cc9..b976e2d6c9e2c65ec2b0b0f30ff5873c50916ba4 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/MandelSimple.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/MandelSimple.java @@ -1,3 +1,13 @@ +/** + * 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. + */ /* Copyright (c) 2010-2011, Advanced Micro Devices, Inc. All rights reserved. @@ -36,39 +46,20 @@ under those regulations, please refer to the U.S. Bureau of Industry and Securit */ -package com.syncleus.aparapi.sample.extension; +package com.syncleus.aparapi.examples.extension; -import com.syncleus.aparapi.*; import com.syncleus.aparapi.device.*; +import com.syncleus.aparapi.examples.extension.Mandel; import com.syncleus.aparapi.internal.kernel.*; import com.syncleus.aparapi.opencl.*; import com.syncleus.aparapi.opencl.OpenCL.*; +import com.syncleus.aparapi.Range; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; -/** - * 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/amd/aparapi/sample/extension/mandel2.cl") interface Mandel extends OpenCL<Mandel>{ - Mandel createMandleBrot(// - Range range,// - @Arg("scale") float scale, // - @Arg("offsetx") float offsetx, // - @Arg("offsety") float offsety, // - @GlobalWriteOnly("rgb") int[] rgb); -} - public class MandelSimple{ /** User selected zoom-in point on the Mandelbrot view. */ diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/Pow4Example.java b/src/main/java/com/syncleus/aparapi/examples/extension/Pow4Example.java similarity index 70% rename from samples/extension/src/com/amd/aparapi/sample/extension/Pow4Example.java rename to src/main/java/com/syncleus/aparapi/examples/extension/Pow4Example.java index 34cbc70d3e9874ff36367c6e2297bc03bad43c72..67bad08a6defcffae0a32b1b732caeafc0d13831 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/Pow4Example.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/Pow4Example.java @@ -1,4 +1,14 @@ -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; @@ -9,7 +19,8 @@ import com.syncleus.aparapi.opencl.OpenCL.Resource; public class Pow4Example{ - @Resource("com/amd/aparapi/sample/extension/squarer.cl") interface Squarer extends OpenCL<Squarer>{ + @Resource("com/syncleus/aparapi/examples/extension/squarer.cl") + interface Squarer extends OpenCL<Squarer>{ public Squarer square(// Range _range,// diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/SquareExample.java b/src/main/java/com/syncleus/aparapi/examples/extension/SquareExample.java similarity index 83% rename from samples/extension/src/com/amd/aparapi/sample/extension/SquareExample.java rename to src/main/java/com/syncleus/aparapi/examples/extension/SquareExample.java index c234dee5b214cc6dd5517aa505da7fd24901bef7..cb9efe4144d1824afa4f91f3101607c604f5dfe2 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/SquareExample.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/SquareExample.java @@ -1,4 +1,14 @@ -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.ProfileInfo; import com.syncleus.aparapi.Range; @@ -23,7 +33,7 @@ public class SquareExample{ @GlobalReadWrite("out") float[] out); } - @Resource("com/amd/aparapi/sample/extension/squarer.cl") interface SquarerWithResource extends OpenCL<SquarerWithResource>{ + @Resource("com/syncleus/aparapi/examples/extension/squarer.cl") interface SquarerWithResource extends OpenCL<SquarerWithResource>{ public SquarerWithResource square(// Range _range,// @GlobalReadWrite("in") float[] in,// diff --git a/src/main/java/com/syncleus/aparapi/examples/extension/StopWatch.java b/src/main/java/com/syncleus/aparapi/examples/extension/StopWatch.java new file mode 100644 index 0000000000000000000000000000000000000000..eb32e1e62496e266007b875be0dbc14ea89f9fba --- /dev/null +++ b/src/main/java/com/syncleus/aparapi/examples/extension/StopWatch.java @@ -0,0 +1,25 @@ +/** + * 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; + +public class StopWatch{ + long start = 0L; + + public void start() { + start = System.nanoTime(); + } + + public void print(String _str) { + long end = (System.nanoTime() - start) / 1000000; + System.out.println(_str + " " + end); + } + +} diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/SwapExample.java b/src/main/java/com/syncleus/aparapi/examples/extension/SwapExample.java similarity index 79% rename from samples/extension/src/com/amd/aparapi/sample/extension/SwapExample.java rename to src/main/java/com/syncleus/aparapi/examples/extension/SwapExample.java index 5fc28eb414e2f36b79279b6ca617bb8bffa958d0..dbb87fa0e6a27d679aa28d37e4a765beabd66aac 100644 --- a/samples/extension/src/com/amd/aparapi/sample/extension/SwapExample.java +++ b/src/main/java/com/syncleus/aparapi/examples/extension/SwapExample.java @@ -1,4 +1,14 @@ -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; diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/fft.cl b/src/main/java/com/syncleus/aparapi/examples/extension/fft.cl similarity index 100% rename from samples/extension/src/com/amd/aparapi/sample/extension/fft.cl rename to src/main/java/com/syncleus/aparapi/examples/extension/fft.cl diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/mandel.cl b/src/main/java/com/syncleus/aparapi/examples/extension/mandel.cl similarity index 100% rename from samples/extension/src/com/amd/aparapi/sample/extension/mandel.cl rename to src/main/java/com/syncleus/aparapi/examples/extension/mandel.cl diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/mandel2.cl b/src/main/java/com/syncleus/aparapi/examples/extension/mandel2.cl similarity index 100% rename from samples/extension/src/com/amd/aparapi/sample/extension/mandel2.cl rename to src/main/java/com/syncleus/aparapi/examples/extension/mandel2.cl diff --git a/samples/extension/src/com/amd/aparapi/sample/extension/squarer.cl b/src/main/java/com/syncleus/aparapi/examples/extension/squarer.cl similarity index 100% rename from samples/extension/src/com/amd/aparapi/sample/extension/squarer.cl rename to src/main/java/com/syncleus/aparapi/examples/extension/squarer.cl