Debian Codegraph @

debian/tests/mandelbrot

raw
1 #!/bin/bash
2
3 set -e
4
5 WORKDIR=$AUTOPKGTEST_ARTIFACTS
6 cd "$WORKDIR"
7
8 # Create the cpp file.
9 cat <<EOF > mandelbrot.cpp
10 #include "mandelbrot_ispc.h"
11 #include <iostream>
12 int main() {
13 unsigned int width = 768, height = 512;
14 unsigned int midWidth = width/2;
15 unsigned int midHeight = height/2;
16 float x0 = -2., x1 = 1.;
17 float y0 = -1., y1 = 1.;
18 int maxIterations = 256;
19 int *buf = new int[width*height];
20
21 ispc::mandelbrot_ispc(x0, y0, x1, y1, width, height, maxIterations, buf);
22 std::cout << buf[(midWidth-1)*(midHeight-1)] << "\t|";
23 std::cout << buf[(midWidth)*(midHeight-1)] << "\t|";
24 std::cout << buf[(midWidth+1)*(midHeight-1)] << "\t|" << std::endl;
25 std::cout << buf[(midWidth-1)*(midHeight)] << "\t|";
26 std::cout << buf[(midWidth)*(midHeight)] << "\t|";
27 std::cout << buf[(midWidth+1)*(midHeight)] << "\t|" << std::endl;
28 std::cout << buf[(midWidth-1)*(midHeight+1)] << "\t|";
29 std::cout << buf[(midWidth)*(midHeight+1)] << "\t|";
30 std::cout << buf[(midWidth+1)*(midHeight+1)] << "\t|" << std::endl;
31
32 return 0;
33 }
34 EOF
35
36 # Create the ispc file.
37 cat <<EOF > mandelbrot.ispc
38 static inline int mandel(float c_re, float c_im, int count) {
39 float z_re = c_re, z_im = c_im;
40 int i;
41 for (i = 0; i < count; ++i) {
42 if (z_re * z_re + z_im * z_im > 4.)
43 break;
44 float new_re = z_re*z_re - z_im*z_im;
45 float new_im = 2.f * z_re * z_im;
46 z_re = c_re + new_re;
47 z_im = c_im + new_im;
48 }
49 return i;
50 }
51 export void mandelbrot_ispc(uniform float x0, uniform float y0,
52 uniform float x1, uniform float y1,
53 uniform int width, uniform int height,
54 uniform int maxIterations,
55 uniform int output[])
56 {
57 float dx = (x1 - x0) / width;
58 float dy = (y1 - y0) / height;
59
60 for (uniform int j = 0; j < height; j++) {
61 foreach (i = 0 ... width) {
62 float x = x0 + i * dx;
63 float y = y0 + j * dy;
64
65 int index = j * width + i;
66 output[index] = mandel(x, y, maxIterations);
67 }
68 }
69 }
70 EOF
71
72
73 echo "detecting target architecture..."
74 ARCH=$(uname -m)
75 echo $ARCH
76 if [[ $ARCH == x86_64* ]]; then
77 echo "X64 Architecture"
78 ISPC_ARCH=x86-64
79 elif [[ $ARCH == i*86 ]]; then
80 echo "X32 Architecture"
81 ISPC_ARCH=x86
82 elif [[ $ARCH == arm* ]]; then
83 echo "ARM Architecture"
84 ISPC_ARCH=arm
85 elif [[ $ARCH == "aarch64" ]]; then
86 echo "Aarch64 Architecture"
87 ISPC_ARCH=aarch64
88 else
89 echo "Unsupported Architecture"
90 exit 1;
91 fi
92
93 echo "building..."
94 mkdir -p objs
95 ispc -O2 mandelbrot.ispc -o objs/mandelbrot_ispc.o -h objs/mandelbrot_ispc.h --arch=$ISPC_ARCH
96 g++ mandelbrot.cpp -Iobjs/ -O3 -Wall -c -o objs/mandelbrot.o
97 g++ -Iobjs/ -O3 -Wall -o mandelbrot objs/mandelbrot.o objs/mandelbrot_ispc.o -lm
98
99 echo "running..."
100 test -x mandelbrot
101 ./mandelbrot