[Pkg-opencl-devel] [beignet] 06/09: restore mandelbrot

Andreas Beckmann anbe at moszumanska.debian.org
Fri Oct 31 21:38:18 UTC 2014


This is an automated email from the git hooks/post-receive script.

anbe pushed a commit to branch master-non-dfsg-free
in repository beignet.

commit 9b3e5fd8595bac2ccc40e54627a6c83262253648
Author: Andreas Beckmann <anbe at debian.org>
Date:   Fri Oct 31 18:38:20 2014 +0100

    restore mandelbrot
---
 kernels/compiler_mandelbrot.cl                |  47 ++++++++++++++++++++++++++
 kernels/compiler_mandelbrot_alternate.cl      |  38 +++++++++++++++++++++
 kernels/compiler_mandelbrot_alternate_ref.bmp | Bin 0 -> 196662 bytes
 kernels/compiler_mandelbrot_ref.bmp           | Bin 0 -> 196662 bytes
 4 files changed, 85 insertions(+)

diff --git a/kernels/compiler_mandelbrot.cl b/kernels/compiler_mandelbrot.cl
new file mode 100644
index 0000000..d15ccd0
--- /dev/null
+++ b/kernels/compiler_mandelbrot.cl
@@ -0,0 +1,47 @@
+// Used to ID into the 1D array, so that we can use
+// it effectively as a 2D array
+inline int ID(int x, int y, int width) { return 4*width*y + x*4; }
+inline float mapX(float x) { return x*3.25f - 2.f; }
+inline float mapY(float y) { return y*2.5f - 1.25f; }
+
+__kernel void compiler_mandelbrot(__global char *out) {
+  int x_dim = get_global_id(0);
+  int y_dim = get_global_id(1);
+  int width = get_global_size(0);
+  int height = get_global_size(1);
+  int idx = ID(x_dim, y_dim, width);
+
+  float x_origin = mapX((float) x_dim / (float) width);
+  float y_origin = mapY((float) y_dim / (float) height);
+
+  // The Escape time algorithm, it follows the pseduocode from Wikipedia
+  // _very_ closely
+  float x = 0.0f;
+  float y = 0.0f;
+
+  int iteration = 0;
+
+  // This can be changed, to be more or less precise
+  int max_iteration = 256;
+  while(x*x + y*y <= 4 && iteration < max_iteration) {
+    float xtemp = x*x - y*y + x_origin;
+    y = 2*x*y + y_origin;
+    x = xtemp;
+    iteration++;
+  }
+
+  if(iteration == max_iteration) {
+    // This coordinate did not escape, so it is in the Mandelbrot set
+    out[idx] = 0;
+    out[idx + 1] = 0;
+    out[idx + 2] = 0;
+    out[idx + 3] = 255;
+  } else {
+    // This coordinate did escape, so color based on quickly it escaped
+    out[idx] = iteration;
+    out[idx + 1] = iteration;
+    out[idx + 2] = iteration;
+    out[idx + 3] = 255;
+  }
+
+}
diff --git a/kernels/compiler_mandelbrot_alternate.cl b/kernels/compiler_mandelbrot_alternate.cl
new file mode 100644
index 0000000..ab6fb07
--- /dev/null
+++ b/kernels/compiler_mandelbrot_alternate.cl
@@ -0,0 +1,38 @@
+inline int offset(int x, int y, int width) { return width*y + x; }
+inline float mapX(float x) {return x*3.25f - 2.f;}
+inline float mapY(float y) {return y*2.5f - 1.25f;}
+
+__kernel void compiler_mandelbrot_alternate(__global uint *out,
+                                            float rcpWidth,
+                                            float rcpHeight,
+                                            float criterium)
+{
+  int xDim = get_global_id(0);
+  int yDim = get_global_id(1);
+  int width = get_global_size(0);
+  int height = get_global_size(1);
+  int idx = offset(xDim, yDim, width);
+
+  float xOrigin = mapX((float) xDim * rcpWidth);
+  float yOrigin = mapY((float) yDim * rcpHeight);
+  float x = 0.0f;
+  float y = 0.0f;
+
+  float iteration = 256.f;
+
+  bool breakCond = true;
+  while (breakCond) {
+    const float xtemp = mad(-y,y,mad(x,x,xOrigin));
+    y = mad(2.f*x, y, yOrigin);
+    x = xtemp;
+    iteration -= 1.f;
+    breakCond = -mad(y,y,mad(x,x, -criterium)) * iteration > 0.f;
+  }
+
+  const uint iIteration = 256 - (uint) iteration;
+  const uint isBlack = (iIteration == 256);
+  const uint black = 255 << 24;
+  const uint nonBlack = iIteration | (iIteration << 8) | (iIteration << 16) | (255 << 24);
+  out[idx] = select(nonBlack, black, isBlack);
+}
+
diff --git a/kernels/compiler_mandelbrot_alternate_ref.bmp b/kernels/compiler_mandelbrot_alternate_ref.bmp
new file mode 100644
index 0000000..011d583
Binary files /dev/null and b/kernels/compiler_mandelbrot_alternate_ref.bmp differ
diff --git a/kernels/compiler_mandelbrot_ref.bmp b/kernels/compiler_mandelbrot_ref.bmp
new file mode 100644
index 0000000..494bf8b
Binary files /dev/null and b/kernels/compiler_mandelbrot_ref.bmp differ

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/beignet.git



More information about the Pkg-opencl-devel mailing list