Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (51 sloc) 1.42 KB
left := float(-2.0);
right := float(1.0);
top := float(1.0);
bottom := float(-1.0);
ntrials := 3;
__device__ uint8 mandelbrot_gpu(int xi, int yi, int xn, int yn,
float left, float right, float top, float bottom)
{
iter := 0;
x0 := left + (right - left) / float(xn) * float(xi);
y0 := bottom + (top - bottom) / float(yn) * float(yi);
x := float(0);
y := float(0);
float xtemp;
while (iter < 255 && x * x + y * y < float(4)) {
xtemp = x * x - y * y + x0;
y = float(2) * x * y + y0;
x = xtemp;
iter++;
}
return uint8(iter);
}
void bench_gpu(int img_width, int img_height, int ntrials)
{
uint8 shades[img_height, img_width];
float64 runtimes[ntrials];
float64 start;
float64 finish;
for (trial in :ntrials)
{
start = time();
pfor (yi in 0:img_height, xi in 0:img_width) {
shades[yi, xi] = mandelbrot_gpu(xi, yi, img_width, img_height,
left, right, top, bottom);
}
finish = time();
runtimes[trial] = finish - start;
}
printf("GPU %dx%d: ", img_width, img_height);
for (rt in runtimes)
printf("%.4f ", rt);
printf("\n");
}
int vec_main()
{
img_heights := {480, 600, 768, 864, 960};
img_widths := {640, 800, 1024, 1152, 1280};
for (i in 0:len(img_heights))
bench_gpu(img_widths[i], img_heights[i], ntrials);
return 0;
}