diff --git a/samples/mandel/mandel.bat b/samples/mandel/mandel.bat index 8e3babad4fd2ae4ff362646cfbb56abcaea312c5..cc0a662ecb295372facef7a3c49d2d5ff72ad9fb 100644 --- a/samples/mandel/mandel.bat +++ b/samples/mandel/mandel.bat @@ -1,7 +1,8 @@ java ^ -Djava.library.path=../../com.amd.aparapi.jni/dist ^ -Dcom.amd.aparapi.executionMode=%1 ^ - -Dcom.amd.aparapi.enableProfiling=true ^ + -Dcom.amd.aparapi.enableProfiling=false ^ + -Dcom.amd.aparapi.enableShowGeneratedOpenCL=true ^ -classpath ../../com.amd.aparapi/dist/aparapi.jar;mandel.jar ^ com.amd.aparapi.sample.mandel.Main diff --git a/samples/mandel/mandel2D.bat b/samples/mandel/mandel2D.bat index a3825670d08eaf2a43bd36c6c3b65dad818061e9..620df5ae3118895870e2a5774e03e18585148c9c 100644 --- a/samples/mandel/mandel2D.bat +++ b/samples/mandel/mandel2D.bat @@ -1,6 +1,8 @@ java ^ -Djava.library.path=../../com.amd.aparapi.jni/dist ^ -Dcom.amd.aparapi.executionMode=%1 ^ + -Dcom.amd.aparapi.enableProfiling=false ^ + -Dcom.amd.aparapi.enableShowGeneratedOpenCL=true ^ -classpath ../../com.amd.aparapi/dist/aparapi.jar;mandel.jar ^ com.amd.aparapi.sample.mandel.Main2D diff --git a/samples/mandel/src/com/amd/aparapi/sample/mandel/Main.java b/samples/mandel/src/com/amd/aparapi/sample/mandel/Main.java index f5f661047dcf15ac8cb436a4f1a0f4cbb0943d00..2e041c0c1e40087829420e5210bcfa38974f71e3 100644 --- a/samples/mandel/src/com/amd/aparapi/sample/mandel/Main.java +++ b/samples/mandel/src/com/amd/aparapi/sample/mandel/Main.java @@ -88,11 +88,11 @@ public class Main{ /** Mandelbrot image height. */ final private int height; - /** Palette used for each iteration value 0..maxIterations. */ - final private int pallette[]; + /** Maximum iterations for Mandelbrot. */ + final private int maxIterations = 64; - /** Maximum iterations we will check for. */ - final private int maxIterations; + /** Palette which maps iteration values to RGB values. */ + @Constant final private int pallette[] = new int[maxIterations + 1]; /** Mutable values of scale, offsetx and offsety so that we can modify the zoom level and position of a view. */ private float scale = .0f; @@ -109,12 +109,17 @@ public class Main{ * @param _rgb Mandelbrot image RGB buffer * @param _pallette Mandelbrot image palette */ - public MandelKernel(int _width, int _height, int[] _rgb, int[] _pallette) { + public MandelKernel(int _width, int _height, int[] _rgb) { + //Initialize palette values + for (int i = 0; i < maxIterations; i++) { + float h = i / (float) maxIterations; + float b = 1.0f - h * h; + pallette[i] = Color.HSBtoRGB(h, 1f, b); + } + width = _width; height = _height; rgb = _rgb; - pallette = _pallette; - maxIterations = pallette.length - 1; } @@ -170,19 +175,6 @@ public class Main{ /** Mandelbrot image height. */ final Range range = Range.create(width * height); - /** Maximum iterations for Mandelbrot. */ - final int maxIterations = 256; - - /** Palette which maps iteration values to RGB values. */ - final int pallette[] = new int[maxIterations + 1]; - - //Initialize palette values - for (int i = 0; i < maxIterations; i++) { - float h = i / (float) maxIterations; - float b = 1.0f - h * h; - pallette[i] = Color.HSBtoRGB(h, 1f, b); - } - /** Image for Mandelbrot view. */ final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final BufferedImage offscreen = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); @@ -220,7 +212,7 @@ public class Main{ final int[] rgb = ((DataBufferInt) offscreen.getRaster().getDataBuffer()).getData(); final int[] imageRgb = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); // Create a Kernel passing the size, RGB buffer and the palette. - final MandelKernel kernel = new MandelKernel(width, height, rgb, pallette); + final MandelKernel kernel = new MandelKernel(width, height, rgb); float defaultScale = 3f; @@ -275,9 +267,10 @@ public class Main{ kernel.setScaleAndOffset(scale, x, y); kernel.execute(range); List<ProfileInfo> profileInfo = kernel.getProfileInfo(); - if (profileInfo != null) { + if (profileInfo != null && profileInfo.size() > 0) { for (ProfileInfo p : profileInfo) { - System.out.print(" " + p.getType() + " " + p.getLabel() + " " +(p.getStart()/1000)+" .. " +(p.getEnd()/1000)+ " "+ (p.getEnd() - p.getStart()) / 1000 + "us"); + System.out.print(" " + p.getType() + " " + p.getLabel() + " " + (p.getStart() / 1000) + " .. " + + (p.getEnd() / 1000) + " " + (p.getEnd() - p.getStart()) / 1000 + "us"); } System.out.println(); } diff --git a/samples/mandel/src/com/amd/aparapi/sample/mandel/Main2D.java b/samples/mandel/src/com/amd/aparapi/sample/mandel/Main2D.java index 5e6b85a3c3da3096f91c3dce28a96db95607808c..fc03bc10f421b5ad6eaeae39cce225b9bb684206 100644 --- a/samples/mandel/src/com/amd/aparapi/sample/mandel/Main2D.java +++ b/samples/mandel/src/com/amd/aparapi/sample/mandel/Main2D.java @@ -48,11 +48,13 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; +import java.util.List; import javax.swing.JComponent; import javax.swing.JFrame; import com.amd.aparapi.Kernel; +import com.amd.aparapi.ProfileInfo; import com.amd.aparapi.Range; /** @@ -80,11 +82,11 @@ public class Main2D{ /** RGB buffer used to store the Mandelbrot image. This buffer holds (width * height) RGB values. */ final private int rgb[]; - /** Palette used for each iteration value 0..maxIterations. */ - final private int pallette[]; - /** Maximum iterations we will check for. */ - final private int maxIterations; + final private int maxIterations = 64; + + /** Palette maps iteration values to RGB values. */ + @Constant final private int pallette[] = new int[maxIterations + 1]; /** Mutable values of scale, offsetx and offsety so that we can modify the zoom level and position of a view. */ private float scale = .0f; @@ -101,11 +103,15 @@ public class Main2D{ * @param _rgb Mandelbrot image RGB buffer * @param _pallette Mandelbrot image palette */ - public MandelKernel(int[] _rgb, int[] _pallette) { - + public MandelKernel(int[] _rgb) { rgb = _rgb; - pallette = _pallette; - maxIterations = pallette.length - 1; + + //Initialize palette + for (int i = 0; i < maxIterations; i++) { + float h = i / (float) maxIterations; + float b = 1.0f - h * h; + pallette[i] = Color.HSBtoRGB(h, 1f, b); + } } @@ -156,19 +162,6 @@ public class Main2D{ final Range range = Range.create2D(768, 768); System.out.println("range= " + range); - /** Maximum iterations for Mandelbrot. */ - final int maxIterations = 256; - - /** Palette which maps iteration values to RGB values. */ - final int pallette[] = new int[maxIterations + 1]; - - //Initialize palette values - for (int i = 0; i < maxIterations; i++) { - float h = i / (float) maxIterations; - float b = 1.0f - h * h; - pallette[i] = Color.HSBtoRGB(h, 1f, b); - } - /** Image for Mandelbrot view. */ final BufferedImage image = new BufferedImage(range.getGlobalSize(0), range.getGlobalSize(1), BufferedImage.TYPE_INT_RGB); final BufferedImage offscreen = new BufferedImage(range.getGlobalSize(0), range.getGlobalSize(1), BufferedImage.TYPE_INT_RGB); @@ -206,7 +199,7 @@ public class Main2D{ final int[] rgb = ((DataBufferInt) offscreen.getRaster().getDataBuffer()).getData(); final int[] imageRgb = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); // Create a Kernel passing the size, RGB buffer and the palette. - final MandelKernel kernel = new MandelKernel(rgb, pallette); + final MandelKernel kernel = new MandelKernel(rgb); float defaultScale = 3f; @@ -259,6 +252,15 @@ public class Main2D{ // Set the scale and offset, execute the kernel and force a repaint of the viewer. kernel.setScaleAndOffset(scale, x, y); kernel.execute(range); + List<ProfileInfo> profileInfo = kernel.getProfileInfo(); + if (profileInfo != null && profileInfo.size() > 0) { + for (ProfileInfo p : profileInfo) { + System.out.print(" " + p.getType() + " " + p.getLabel() + " " + (p.getStart() / 1000) + " .. " + + (p.getEnd() / 1000) + " " + (p.getEnd() - p.getStart()) / 1000 + "us"); + } + System.out.println(); + } + System.arraycopy(rgb, 0, imageRgb, 0, rgb.length); viewer.repaint(); }