📄 fractal.br
字号:
// fractal.br// tests kernel splitting of an iterative construct#include <stdio.h>kernel void mandelbrotIterate( float4 x<>, float4 y<>, float4 cx<>, float4 cy<>, out float4 outX<>, out float4 outY<> ){ float4 tx = x*x - y*y + cx; float4 ty = 2*x*y + cy; outX = tx; outY = ty;}kernel void mandelbrot( float4 cx<>, float4 cy<>, out float4 outInside<> ){ float4 x = cx; float4 y = cy; mandelbrotIterate( x, y, cx, cy, x, y ); // 0 mandelbrotIterate( x, y, cx, cy, x, y ); // 1 mandelbrotIterate( x, y, cx, cy, x, y ); // 2 mandelbrotIterate( x, y, cx, cy, x, y ); // 3 mandelbrotIterate( x, y, cx, cy, x, y ); // 4 mandelbrotIterate( x, y, cx, cy, x, y ); // 5 mandelbrotIterate( x, y, cx, cy, x, y ); // 6 mandelbrotIterate( x, y, cx, cy, x, y ); // 7 mandelbrotIterate( x, y, cx, cy, x, y ); // 8 mandelbrotIterate( x, y, cx, cy, x, y ); // 9 mandelbrotIterate( x, y, cx, cy, x, y ); // 10 mandelbrotIterate( x, y, cx, cy, x, y ); // 11 mandelbrotIterate( x, y, cx, cy, x, y ); // 12 mandelbrotIterate( x, y, cx, cy, x, y ); // 13 mandelbrotIterate( x, y, cx, cy, x, y ); // 14 mandelbrotIterate( x, y, cx, cy, x, y ); // 15 mandelbrotIterate( x, y, cx, cy, x, y ); // 16 mandelbrotIterate( x, y, cx, cy, x, y ); // 17 mandelbrotIterate( x, y, cx, cy, x, y ); // 18 mandelbrotIterate( x, y, cx, cy, x, y ); // 19 mandelbrotIterate( x, y, cx, cy, x, y ); // 20 mandelbrotIterate( x, y, cx, cy, x, y ); // 21 mandelbrotIterate( x, y, cx, cy, x, y ); // 22 mandelbrotIterate( x, y, cx, cy, x, y ); // 23 mandelbrotIterate( x, y, cx, cy, x, y ); // 24 mandelbrotIterate( x, y, cx, cy, x, y ); // 25 mandelbrotIterate( x, y, cx, cy, x, y ); // 26 mandelbrotIterate( x, y, cx, cy, x, y ); // 27 mandelbrotIterate( x, y, cx, cy, x, y ); // 28 mandelbrotIterate( x, y, cx, cy, x, y ); // 29 mandelbrotIterate( x, y, cx, cy, x, y ); // 30 mandelbrotIterate( x, y, cx, cy, x, y ); // 31 mandelbrotIterate( x, y, cx, cy, x, y ); // 32 mandelbrotIterate( x, y, cx, cy, x, y ); // 33 mandelbrotIterate( x, y, cx, cy, x, y ); // 34 mandelbrotIterate( x, y, cx, cy, x, y ); // 35 mandelbrotIterate( x, y, cx, cy, x, y ); // 36 mandelbrotIterate( x, y, cx, cy, x, y ); // 37 mandelbrotIterate( x, y, cx, cy, x, y ); // 38 mandelbrotIterate( x, y, cx, cy, x, y ); // 39 outInside = (x*x + y*y) < 4; }/*#define WIDTH 640#define HEIGHT 480#define STREAM_WIDTH (WIDTH/4)#define STREAM_HEIGHT HEIGHT#define DATA_SIZE (WIDTH*HEIGHT)void main(){ float4 inputX<STREAM_HEIGHT,STREAM_WIDTH>; float* inputX_data; float4 inputY<STREAM_HEIGHT,STREAM_WIDTH>; float* inputY_data; float4 output<STREAM_HEIGHT,STREAM_WIDTH>; float* output_data; unsigned char* image_data; int i, j; float x, y; FILE* outputFile; inputX_data = (float*)malloc( DATA_SIZE * sizeof(float) ); inputY_data = (float*)malloc( DATA_SIZE * sizeof(float) ); output_data = (float*)malloc( DATA_SIZE * sizeof(float) ); image_data = (unsigned char*)malloc( DATA_SIZE * sizeof(unsigned char) ); outputFile = fopen( "output.pgm", "wb" ); fprintf( outputFile, "P5\n" ); fprintf( outputFile, "%d\n", WIDTH ); // w fprintf( outputFile, "%d\n", HEIGHT ); // h fprintf( outputFile, "255\n" ); for( j = 0; j < HEIGHT; j++ ) { y = 3.0f * (float)(j) * (1.0f / (HEIGHT-1)) - 1.5f; for( i = 0; i < WIDTH; i++ ) { x = 4.0f * (float)(i) * (1.0f / (WIDTH-1)) - 2.0f; inputX_data[j*WIDTH+i] = x; inputY_data[j*WIDTH+i] = y; } } streamRead( inputX, inputX_data ); streamRead( inputY, inputY_data ); mandelbrot( inputX, inputY, output ); streamWrite( output, output_data ); for( i = 0; i < DATA_SIZE; i++ ) image_data[i] = output_data[i] != 0 ? 0 : 255; fwrite( image_data, DATA_SIZE, 1, outputFile ); fclose( outputFile );}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -