From a7db7bced3aa759285a81da73d93c5dcdc2ecaee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Cuevas?= Date: Thu, 29 Aug 2013 19:31:20 +0200 Subject: [PATCH] First commit --- .Makefile.swp | Bin 0 -> 12288 bytes .main.c.swp | Bin 0 -> 36864 bytes .mandel_classic.c.swp | Bin 0 -> 45056 bytes .mandelbrot_kernel.cl.swp | Bin 0 -> 12288 bytes .sum_kernel.cl.swp | Bin 0 -> 12288 bytes .vector_add_kernel.cl.swp | Bin 0 -> 12288 bytes CL | 1 + Makefile | 38 ++++ frag_shader.glsl | 38 ++++ main.c | 209 +++++++++++++++++ mandel_classic.c | 462 ++++++++++++++++++++++++++++++++++++++ mandel_classic.o | Bin 0 -> 7200 bytes mandelbrot_kernel.cl | 45 ++++ mandelclassic | Bin 0 -> 11941 bytes test | Bin 0 -> 10172 bytes test.c | 301 +++++++++++++++++++++++++ test.o | Bin 0 -> 5136 bytes vector_add_kernel.cl | 12 + 18 files changed, 1106 insertions(+) create mode 100644 .Makefile.swp create mode 100644 .main.c.swp create mode 100644 .mandel_classic.c.swp create mode 100644 .mandelbrot_kernel.cl.swp create mode 100644 .sum_kernel.cl.swp create mode 100644 .vector_add_kernel.cl.swp create mode 120000 CL create mode 100644 Makefile create mode 100644 frag_shader.glsl create mode 100644 main.c create mode 100644 mandel_classic.c create mode 100644 mandel_classic.o create mode 100644 mandelbrot_kernel.cl create mode 100755 mandelclassic create mode 100755 test create mode 100644 test.c create mode 100644 test.o create mode 100644 vector_add_kernel.cl diff --git a/.Makefile.swp b/.Makefile.swp new file mode 100644 index 0000000000000000000000000000000000000000..ca472e6402486ce6ee8b815076d0cf5e2dd036af GIT binary patch literal 12288 zcmeI2O=}ZD7{@1~hk&)BC+)%M3(^RiwCO2hE$7Avn=8-G#QP^F#`(ny8^=mTo5%neAOmE843GgbKnBPF8912+ z>{gCFN9m`s@~>uNZfML7X&?h+fDDiUGC&5%02v?yWPl8i0Wv@aPM`q~FYWK0W$ZVI z-~aDF|Nj_e>^t}dzJmAQ9WY=W6u=p98vHuP*cb2_d;%ZA9(V&@ftO$hY=cd38C(KC zM;Lnx_P}ef4W0oXl))^R1QTEkBsHEu$5b*IAOmE843GgbKnBPF86X4yfq{HJe>3Xv zYemh|Z;^%aj0ps{(pV;x^uh{b#kISuD-SC?Ic6+BHC?L}IQ|#i`8(_JtiDonHx_Qk zQ@4H#OY#1q;Eqmbnk5UmlAY*F(%YIw^fF{yla1Ln-M8%@*G@Zml(mvpF|?-HK)Xd0 zHWVTHuGK4XC`R`eJ1B54|AFl2#8Ya2c|bbLu2yyGrLKueK`2zWDNE}ME*=JXJv}tz zjK!v_j_PnnZP|7ty(a2GSaJvOkebe_Q`4p`mExwU9HGNj;B&`OLBkY~&c%pSlRWiV zb#Tu%Q5tuAzu8FhrFZ$TnAI|O7M3>L`usrTfn117D*KyBcRDh(+_nS5RS-&!FX4GN z6uouHL%D+h&3$S4Qdb2YZ$+N4o-#>qNv^}26D{TWNqdX&1pU=&RbL3Su$+8xUvn|Z HzPJAa8N(Zv literal 0 HcmV?d00001 diff --git a/.main.c.swp b/.main.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..98ad4a8de0a41d9273c037077e4eb3da9ec6931d GIT binary patch literal 36864 zcmeI53ydU3d4T8a_;J`A#39ioT%hg@tJ%G|-Mt5AE518Br z?%eY4{h3VQge&U+>3zOxpavE?Na2jwLa2jwLa2jwL za2jwL_^G(Yy~XJ+xBGefz1x1r=dZN;m)Y;P zbezA!?!U%<*E-I}*S*pnzq{l7rFMUZ{q{P}+gcsGw`4cSva>flX)0I7=iC$nD{I_32%iwycC|mAn^`(I~3s6 z@Og|JpM%FBf)M85Wv~tY1tZ1#U>>f9E8uAiCuiYy*baY-q2h1gH{loHr{Sv@U%mp5 z!C5H6oiGD~a20$VL&~ROV~T01Dzyb(qz~^!cyRQwIqKjMoWkqP@#X1SFdC#RDVv5<`@f!unqrWSOzYE0E@`f%A>@k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FyOe)T2V9F19wiokzCoWMB!ENp`6Ui_oqTFIIN3obI_8-@vgr zQP+~#G#x74WZgt^;yku(Abs<@&lZ-;Ok0q@Qrl)_r7kglZuUa)xTWsT3#bsK>c+m( zE>G9`S=6EsUJWE-NUXrUCi_b=^JB@+e|mV?tMnA)r;_y zWONzq$GW0u-_=DbgO!z96=nlH=*Q$DX3mV^bmmfLX}_|{0$IiGp;he`TEoj1q?V;< zFRCtCmsf{gF$`_56u7T0G>)P3{`AVPOW(M0u1Qou#x@82b)I?ZyZocfOlDtipwEt) zC7l*8dC8JOtN_!tqL4HI9yFrG{o0~xja@=z+5&xg`??M7dr6_(Dh{dj4)i1FR&ii) zfEU&(4)Ulc=24&D?JD3iNq<&V4xzI1M-rI1M-rI1M-rI1M-rI1M-rI1M-r{9kK82DRxe zwrBK;hfV^02#dKWanMH2^N)j;|4v4@O}jW9XtXYTwN&j|y)Mf!#l_M_1>|J@7ad71 AIRF3v literal 0 HcmV?d00001 diff --git a/.mandel_classic.c.swp b/.mandel_classic.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..a715f0d7eadd6fb71f09df2f070c30b2b19c8d06 GIT binary patch literal 45056 zcmeI537AyHoxmHfh=SzPXiPNn1Yx^}xfn!1j)(&&$|VC{#BH0NH%voM_t4!lOoPOj zD4KX}HmsW!Hydy8i;CzP6O9|s1a-f-nwZ3RBpWZpdlOuD)$H$IRqyKVIT(hh>+A3P z&3mt2o&Ty=um1J^RkO7I)Y)^b3AN)Q{5~6rG+Z!z;a(zN#XuTae2xx08i@U0Wj4Y^RszvITP*Po@+3d@5O+>?Nk~b|`^R0y`yv zjzUY#!~-JZ8phU3xRE1{v<^CO@lHh%dJZKJN+6U#D1lG{p#(w+gc1lP5K7>aErCM& z;K;cYVGmP`z07e?$R&2b&By`Pj#} zuQbQ!&C$8*tj2Hj_XVA?`hl*HOH!w`^Gsugc1lP5K17FKq!Gw0-*## z34{^|B@jv=lt3tfPoxAAe6&A*SR}F; zOo9d&3;V)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3;KMiZ3TG)Y#DtK8OE)@jGJZEB{{UzsbDh=y%WPL}t? zScdj9CA+<0SdO7-$JJ$ZK~(M~eJ>xT=y07@MAQ*6jLNEu83bV@tLvHHayiRU;;Z#0 z&=Q5Q+8n4Gnw>36>&Xovn1DW^lgcW(ch@mWP2s-W6eDj#Hiitqxrm)qrS z%3K|&4e7wl1ZHJmW&(?TimjmUt#?MH&vJ`kyd#y@iIS!td12dfO>Uz>=cOVQNUXUn zGfI|=FRj%yl~|{YWEW?#COq@vINeRcHriQ#wcP6^Xu$GJacU)TAAXRl7lT%}nZate zn9NKUF#+oR78sVsm n26TB7zFpyLSa=Y&RiNw6IJ3I$w1W*%t&8V_f>^RXmC@oir3qDQ literal 0 HcmV?d00001 diff --git a/.sum_kernel.cl.swp b/.sum_kernel.cl.swp new file mode 100644 index 0000000000000000000000000000000000000000..9fd3b55b2343ebd660beebc8e5957e0b7ace69f9 GIT binary patch literal 12288 zcmeI&%}T>S5C`zBCofj5dLQ-DR&8o~P!JDo1wTL#K`$b)O{Q%$W=pcEf~YSeK8z3G zV|e%GBt#JrN{@yA!Z7T|>?Xfk$abpdhsU&4sVix7O1(AaPe1clxsQ@kAxCVI@ewW3 zvFYD=fjeT|Q@Wvb66$MqOl0W+2aazWj*Jz>xAqN(0s9rlAF&UnApn6f1!B|P*q%}K z+GaJWTwPhFg~HjGn_xKvAOHafKmY;|fB*y_Fv$XDkWcWvcC@bCyMWnoOTbZm@@K z(FkyZqd$;Ax8(1oGsPm#yb5s-2641u4|R(L45(0HE?18 literal 0 HcmV?d00001 diff --git a/.vector_add_kernel.cl.swp b/.vector_add_kernel.cl.swp new file mode 100644 index 0000000000000000000000000000000000000000..e443a72af76eda34d2f4ecad0ede91cffb83d00d GIT binary patch literal 12288 zcmeI&&o2W(6bJBEXX@8K@Nj9XZ0UhS9I8Y}BqHG=vbNp9vUZy3ETX|5 z>g{F`y|h=&caqo1{CID7KDTD4Q90P!;idU1NgE^D-WcEe%pd38ibO`Wl}+Y*w6>1z z*>w>4J@(zF1)W`^&sEd59o*VZ0v&o1Rwwb2tWV=5P$##20*~Ja`YhQ7|PBvob|b`J{zKg z00bZa0SG_<0uX=z1Rwwb2teQ;3V8C-{xMJVE|Gly|Nj5~I!g2+@htHqaVrr^Y)Q;Y zlq4o3KE8AR;o0%Z5P$##AOHafKmY;|fB*y_Fn9uYStFKKKMam|mF3QPa^ai{H5r$A zO@50j=?2H)bhV@B0 zXvW4U$yA}bls>IQZg$a~uXNxi?~>hrFSuD{P99dOmHF?)TK7b~$Q`1)w5m}yHW3#* Zp5;c7OI%%{q|DDzlYv)GOUrtPz5w$|f|39L literal 0 HcmV?d00001 diff --git a/CL b/CL new file mode 120000 index 0000000..ec67360 --- /dev/null +++ b/CL @@ -0,0 +1 @@ +/opt/intel/opencl-1.2-3.0.67279/include/CL \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..954d8c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +# MandelCL Makefile +CC=gcc + +# Flags! +SDLFLAGS=$(shell sdl-config --cflags) + +# Comment this line and uncomment the next to get Julia fractals +CFLAGS=-c -Wall -O2 $(SDLFLAGS) +# CFLAGS=-c -Wall -O2 -DJULIA $(SDLFLAGS) +# CFLAGS=-c -Wall -ggdb $(SDLFLAGS) + +# Libs! +SDLLIBS=$(shell sdl-config --libs) + +LIBS=-lm -lpthread $(SDLLIBS) + +# Includes! + +INCLUDE=-I/usr/include/SDL + +all: mandelclassic test + +mandelclassic: mandel_classic.o + $(CC) $(INCLUDE) mandel_classic.o $(LIBS) -o mandelclassic + +mandelclassic.o: mandel_classic.c + $(CC) $(CFLAGS) $(INCLUDE) $(LIBS) mandel_classic.c -o mandel_classic.o + +test: test.o + $(CC) $(INCLUDE) test.o $(LIBS) -o test + +test.o: test.c + $(CC) $(CFLAGS) $(INCLUDE) $(LIBS) test.c -o test.o + +.PHONY: clean + +clean: + @rm *.o mandelclassic test diff --git a/frag_shader.glsl b/frag_shader.glsl new file mode 100644 index 0000000..29f9ccd --- /dev/null +++ b/frag_shader.glsl @@ -0,0 +1,38 @@ +void main(void) +{ + float zoom = float(iMouse.x) / float(iResolution.x); + float pos_x = ((float(gl_FragCoord.x) / float(iResolution.x)) * 3.5 * zoom) - (2.5 - (1.0 - zoom)); + float pos_y = ((float(gl_FragCoord.y) / float(iResolution.y)) * 2.0 * zoom) - (1.0 - (1.0 - zoom)); + float x = 0.0; + float y = 0.0; + + int iteration = 0; + float normal_iter = 0.0; + int max_iteration = 255; + float xtemp; + + while (iteration < max_iteration) + { + xtemp = x * x - y * y + pos_x; + y = 2.0 * x * y + pos_y; + if ((x * x) + (y * y) >= (4.0)) break; + + x = xtemp; + iteration++; + } + + if (iteration >= max_iteration) + { + gl_FragColor = vec4(0.0,0.0,0.0,1.0); + } + else if (iteration < 128) + { + normal_iter = float(iteration) / 255.0; + gl_FragColor = vec4(0,0.1 + normal_iter,normal_iter,1.0); + } + else + { + normal_iter = float(iteration) / 255.0; + gl_FragColor = vec4(1.0 - normal_iter, 1.0, 1.0 - normal_iter, 1.0); + } +} diff --git a/main.c b/main.c new file mode 100644 index 0000000..213c099 --- /dev/null +++ b/main.c @@ -0,0 +1,209 @@ +#include +#include +#include + +#ifdef __APPLE__ +#include +#else +#include +#endif + +#include + +#define MAX_SOURCE_SIZE (0x100000) + +int main(int argn, char **argv) { + + // Init SDL + if(SDL_Init(SDL_INIT_VIDEO) != 0) + fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError()); + + printf("SDL Initialized\n"); + + // Create screen surface + SDL_Surface *screen; + int res_x = 800; + int res_y = 600; + int current_line = 0; + int total_res = res_x * res_y; + + screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); + if(!screen) + fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError()); + + // Prepare the resolution and sizes and colors... + int i; + int temp; + const int ITERATIONS = 256; + int *red_scale = (int*)malloc(sizeof(int)*ITERATIONS); + int *blue_scale = (int*)malloc(sizeof(int)*ITERATIONS); + for(i = 0; i < ITERATIONS; i++) { + red_scale[i] = i; + blue_scale[i] = 255 - i; + } + + + // Load the kernel source code into the array source_str + FILE *fp; + char *source_str; + size_t source_size; + + fp = fopen("mandelbrot_kernel.cl", "r"); + if (!fp) { + fprintf(stderr, "Failed to load kernel.\n"); + exit(1); + } + source_str = (char*)malloc(MAX_SOURCE_SIZE); + source_size = fread( source_str, 1, MAX_SOURCE_SIZE, fp); + fclose( fp ); + + // Get platform and device information + cl_platform_id platform_id = NULL; + cl_device_id device_id = NULL; + cl_uint ret_num_devices; + cl_uint ret_num_platforms; + cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms); + ret = clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_GPU, 1, + &device_id, &ret_num_devices); + + // Create an OpenCL context + cl_context context = clCreateContext( NULL, 1, &device_id, NULL, NULL, &ret); + + // Create a command queue + cl_command_queue command_queue = clCreateCommandQueue(context, device_id, 0, &ret); + + // Create memory buffers on the device for returning iterations + cl_mem kernel_res_x = clCreateBuffer(context, CL_MEM_READ_ONLY, + sizeof(cl_int), NULL, &ret); + cl_mem kernel_res_y = clCreateBuffer(context, CL_MEM_READ_ONLY, + sizeof(cl_int), NULL, &ret); + cl_mem kernel_current_line = clCreateBuffer(context, CL_MEM_READ_ONLY, + sizeof(cl_int), NULL, &ret); + cl_mem graph_mem_obj = clCreateBuffer(context, CL_MEM_WRITE_ONLY, + res_x * sizeof(cl_int), NULL, &ret); + + // Copy resolution x and y for the kernel + ret = clEnqueueWriteBuffer(command_queue, kernel_res_x, CL_TRUE, 0, + sizeof(cl_int), &res_x, 0, NULL, NULL); + + ret = clEnqueueWriteBuffer(command_queue, kernel_res_y, CL_TRUE, 0, + sizeof(cl_int), &res_y, 0, NULL, NULL); + + ret = clEnqueueWriteBuffer(command_queue, kernel_current_line, CL_TRUE, 0, + sizeof(cl_int), ¤t_line, 0, NULL, NULL); + + // Create a program from the kernel source + cl_program program = clCreateProgramWithSource(context, 1, + (const char **)&source_str, (const size_t *)&source_size, &ret); + + // Build the program + ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL); + + // Create the OpenCL kernel + cl_kernel kernel = clCreateKernel(program, "mandelbrot_point", &ret); + + // Our screen in a linear array + int *graph_dots = (int*)malloc(total_res * sizeof(int)); + cl_int *graph_line = (cl_int*)malloc(res_x * sizeof(cl_int)); + + for (current_line = 0; current_line < 600; current_line++) + { + // Set the arguments of the kernel + ret = clEnqueueWriteBuffer(command_queue, kernel_current_line, CL_TRUE, 0, + sizeof(cl_int), ¤t_line, 0, NULL, NULL); + + ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), &kernel_res_x); + ret = clSetKernelArg(kernel, 1, sizeof(cl_mem), &kernel_res_y); + ret = clSetKernelArg(kernel, 2, sizeof(cl_mem), &kernel_current_line); + ret = clSetKernelArg(kernel, 3, sizeof(cl_mem), graph_mem_obj); + + // Execute the OpenCL kernel on the list + size_t global_item_size = res_x; // Process the entire screen + size_t local_item_size = 64; // Process in groups of 64 + ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, + &global_item_size, &local_item_size, 0, NULL, NULL); + + // Read the memory buffer graph_mem_obj on the device to the local variable graph_dots + ret = clEnqueueReadBuffer(command_queue, graph_mem_obj, CL_TRUE, 0, + res_x * sizeof(cl_int), graph_line, 0, NULL, NULL); + + for (i = 0; i < 800; i++) + { + graph_dots[(current_line * 800) + i] = graph_line[i]; + } + } + + // Display the result to the screen + /* for(i = 0; i < 3078; i++) + printf("Linear: %d -> %d\n", i, graph_dots[i]); */ + + printf("Rendering...\n"); + + int iteration; + Uint32 *pixel; + // Lock surface + SDL_LockSurface(screen); + // rank = screen->pitch/sizeof(Uint32); + pixel = (Uint32*)screen->pixels; + /* Draw all dots */ + for(i = 0;i < total_res;i++) + { + // Get the iterations for the point + // printf("Point %d\n", i); + iteration = graph_dots[i]; + if ((iteration < 1000) && (iteration >= 0)) { + pixel[i] = SDL_MapRGBA(screen->format, + red_scale[iteration], + 0, + blue_scale[iteration], + 255); + } + else + { + pixel[i] = SDL_MapRGBA(screen->format, + 0, + 0, + 0, + 255); + } + + } + // Unlock surface + SDL_UnlockSurface(screen); + + // Draw to the scree + SDL_Flip(screen); + + // Clean up + ret = clFlush(command_queue); + ret = clFinish(command_queue); + ret = clReleaseKernel(kernel); + ret = clReleaseProgram(program); + // ret = clReleaseMemObject(a_mem_obj); + // ret = clReleaseMemObject(b_mem_obj); + ret = clReleaseMemObject(graph_mem_obj); + ret = clReleaseCommandQueue(command_queue); + ret = clReleaseContext(context); + // free(A); + // free(B); + free(graph_dots); + + SDL_Event ev; + int active; + + active = 1; + while(active) + { + /* Handle events */ + while(SDL_PollEvent(&ev)) + { + if(ev.type == SDL_QUIT) + active = 0; /* End */ + } + } + + SDL_Quit(); + + return 0; +} + diff --git a/mandel_classic.c b/mandel_classic.c new file mode 100644 index 0000000..beabd01 --- /dev/null +++ b/mandel_classic.c @@ -0,0 +1,462 @@ +#include +#include +#include +#include +#include + +#include + +#define MAX_SOURCE_SIZE (0x100000) + + +#ifdef CACHE +int** cached_points; +int** cached_x; +int** cached_y; +#endif + +int *iteration_pixels; + +typedef struct point_args point_args; +struct point_args +{ + int res_x; + int res_y; + int image_x; + int image_y; + float zoom; + int max_iteration; + int thread_number; +}; + +typedef struct piece_args piece_args; +struct piece_args +{ + int res_x; + int res_y; + float zoom; + int max_iteration; + int total_threads; + int thread_number; +}; + + +int get_x (int linear_point, int width) +{ + return linear_point % width; +} + +int get_y (int linear_point, int height) +{ + return floor(linear_point / height); +} + +float map_x(int x, int width, float zoom) +{ +#ifndef JULIA + return (((float)x / (float)width) * (3.5 * zoom)) - (2.5 - (1.0 - zoom)); +#else + return (((float)x / (float)width) * (3.5 * zoom)) - (1.75 - (1.0 - zoom)); +#endif +} + +float map_y(int y, int height, float zoom) +{ + return (((float)y / (float)height) * (2.0 * zoom)) - (1.00001 - (1.0 - zoom)); +} + +#ifdef CACHE +int cached_iteration(float pos_x, float pos_y) +{ + float centered_x = pos_x + 2.5; + float centered_y = pos_y + 1.0; + float temp_x = floor(centered_x * 1000.0); + float temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + return cached_points[trs_pos_x][trs_pos_y]; +} + +float get_cached_x(float pos_x, float pos_y) +{ + float centered_x = pos_x + 2.5; + float centered_y = pos_y + 1.0; + float temp_x = floor(centered_x * 1000.0); + float temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + return cached_x[trs_pos_x][trs_pos_y]; +} + +float get_cached_y(float pos_x, float pos_y) +{ + float centered_x = pos_x + 2.5; + float centered_y = pos_y + 1.0; + float temp_x = floor(centered_x * 1000.0); + float temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + return cached_y[trs_pos_x][trs_pos_y]; +} + +void store_iteration(float pos_x, float pos_y, int iteration, float x, float y) +{ + float centered_x = pos_x + 2.5; + float centered_y = pos_y + 1.0; + float temp_x = floor(centered_x * 1000.0); + float temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + cached_points[trs_pos_x][trs_pos_y] = iteration; + cached_x[trs_pos_x][trs_pos_y] = x; + cached_y[trs_pos_x][trs_pos_y] = y; +} +#endif + +int mandelbrot_point(int res_x, int res_y, int image_x, int image_y, float zoom, int max_iteration) +{ + // Get the index of the current element + float pos_x = map_x(image_x, res_x, zoom); + float pos_y = map_y(image_y, res_y, zoom); + float x = 0.0; + float y = 0.0; + float q, x_term; + float xtemp, xx, yy; +#ifdef CACHE + int storeable = 1; +#endif + int iteration = 0; + + yy = y * y; + + // Period-2 bulb check + if (((x + 1) * (x + 1) + yy) < 0.0625) return 0; + + // Cardioid check + x_term = x - 0.25; + q = x_term * x_term + yy; + q = q * (q + x_term); + if (q > (0.25 * yy)) return 0; + +#ifdef CACHE + // Look up our cache + iteration = cached_iteration(pos_x, pos_y); + + if (iteration > 0) + { + x = get_cached_x(pos_x, pos_y); + y = get_cached_y(pos_x, pos_y); + yy = y * y; + } + if (iteration < 0) storeable = 0; +#endif + + while (iteration < max_iteration) + { + xx = x * x; + if ((xx) + (yy) > (4.0)) break; + y = (x + y) * (x + y) - xx - yy; + y = y + pos_y; + xtemp = xx - yy + pos_x; + + x = xtemp; + yy = y * y; + iteration++; + } + + if (iteration >= max_iteration) + { + return 0; + } + else + { +#ifdef CACHE + if (storeable == 1) + { + store_iteration(pos_x, pos_y, iteration, x, y); + } +#endif + return iteration; + } +} + +int julia_point(int res_x, int res_y, int image_x, int image_y, float zoom, int max_iteration) +{ + // Get the index of the current element + float pos_x = map_x(image_x, res_x, 1.0); + float pos_y = map_y(image_y, res_y, 1.0); + float x = pos_x; + float y = pos_y; + float xtemp, xx, yy; +#ifdef CACHE + int storeable = 1; +#endif + int iteration = 0; + +#ifdef CACHE + // Look up our cache + iteration = cached_iteration(pos_x, pos_y); + + if (iteration > 0) + { + x = get_cached_x(pos_x, pos_y); + y = get_cached_y(pos_x, pos_y); + yy = y * y; + } + if (iteration < 0) storeable = 0; +#endif + + while (iteration < max_iteration) + { + xx = x * x; + yy = y * y; + if ((xx) + (yy) > (4.0)) break; + y = pow((x + y), 2) - xx - yy; + y = y + 0.288; + xtemp = xx - yy + 0.353 + zoom; + + x = xtemp; + iteration++; + } + + if (iteration >= max_iteration) + { + return 0; + } + else + { +#ifdef CACHE + if (storeable == 1) + { + store_iteration(pos_x, pos_y, iteration, x, y); + } +#endif + return iteration; + } +} + +void *thread_launcher(void *arguments) +{ + piece_args *args; + args = (piece_args *) arguments; + + int x,y, small_res_x, small_res_y, init_x, init_y, limit_x, limit_y; + int iteration, split, piece_x, piece_y; + + if(args->total_threads != 1) + { + split = args->total_threads / 2; + } + else + { + split = 1; + } + + if (args->thread_number > 0) + { + piece_x = args->thread_number % split; + piece_y = floor((float)args->thread_number / (float)split); + } + else + { + piece_x = 0; + piece_y = 0; + } + + small_res_x = floor((float)args->res_x / (float)split); + small_res_y = floor((float)args->res_y / (float)split); + init_x = small_res_x * piece_x; + init_y = small_res_y * piece_y; + limit_x = init_x + small_res_x; + limit_y = init_y + small_res_y; + + for (y = init_y; y < limit_y; y++) + { + for (x = init_x; x < limit_x; x++) + { +#ifndef JULIA + iteration_pixels[x + (y * args->res_x)] = mandelbrot_point(args->res_x, args->res_y, x, y, args->zoom, args->max_iteration); +#else + iteration_pixels[x + (y * args->res_x)] = julia_point(args->res_x, args->res_y, x, y, args->zoom, args->max_iteration); +#endif + } + } +} + +int get_cpus() +{ + int number_of_cores = 0; + number_of_cores = sysconf(_SC_NPROCESSORS_ONLN); + return number_of_cores; +} + +int main(int argn, char **argv) +{ + // Init SDL + if(SDL_Init(SDL_INIT_VIDEO) != 0) + fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError()); + + printf("SDL Initialized\n"); + + // Create screen surface + SDL_Surface *screen; + int res_x = 800; + int res_y = 600; + + int number_threads = get_cpus(); + + printf("Number of threads autodetect: %d\n", number_threads); + +#ifdef CACHE + // Init our cached points + cached_points = malloc(res_y * 1000 * sizeof(int *)); + cached_x = malloc(res_y * 1000 * sizeof(float *)); + cached_y = malloc(res_y * 1000 * sizeof(float *)); + if (cached_points == NULL) + { + fprintf(stderr, "Bad luck, out of memory\n"); + return 2; + } + + int count; + for (count = 0; count < res_y * 1000; count++) + { + cached_points[count] = malloc(res_x * 1000 * sizeof(int)); + if(cached_points[count] == NULL) + { + fprintf(stderr, "Bad luck, out of memory\n"); + return 2; + } + cached_x[count] = malloc(res_x * 1000 * sizeof(float)); + cached_y[count] = malloc(res_x * 1000 * sizeof(float)); + /*for (count2 = 0; count2 < res_x * 100; count2++) + { + cached_points[count][count2] = -1; + }*/ + } + + printf("Cache ready\n"); +#endif + + // screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); + screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF); + if(!screen) + fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError()); + + // Prepare the resolution and sizes and colors, threads... + int i; + iteration_pixels = malloc(res_x * res_y * sizeof(int)); + pthread_t threads[number_threads]; + piece_args arguments[number_threads]; + + printf("Rendering...\n"); + + float zoom; + +#ifndef JULIA + for (zoom = 1.0; zoom > 0.0001 ; zoom = zoom * 0.98) +#else + for (zoom = 1.0; zoom > -2.5 ; zoom -= 0.01) +#endif + { + i = 0; + int iteration, max_iteration, x, y, res; + if((zoom < -0.02) && (zoom > -1.0)) + { + max_iteration = 100; + } + else + { + max_iteration = 170; + } + + int thread_count; + + for(thread_count = 0; thread_count < number_threads; thread_count++) + { + arguments[thread_count].res_x = res_x; + arguments[thread_count].res_y = res_y; + arguments[thread_count].zoom = zoom; + arguments[thread_count].max_iteration = max_iteration; + arguments[thread_count].total_threads = number_threads; + arguments[thread_count].thread_number = thread_count; + pthread_create( &threads[thread_count], NULL, thread_launcher, (void*) &arguments[thread_count]); + } + + for(thread_count = 0; thread_count < number_threads; thread_count++) + { + res = pthread_join(threads[thread_count], NULL); + if (res != 0) + { + printf("Error in %d thread\n", thread_count); + } + } + + int rank; + Uint32 *pixel; + rank = screen->pitch/sizeof(Uint32); + pixel = (Uint32*)screen->pixels; + + for(y = 0; y < res_y ; y++) + { + for(x = 0; x < res_x; x++) + { + iteration = iteration_pixels[x + y * res_x]; + if ((iteration < 128) && (iteration > 0)) { + pixel[x + y * rank] = SDL_MapRGBA(screen->format, + 0, + 20 + iteration, + 0, + 255); + } + else if ((iteration >= 128) && (iteration < max_iteration)) + { + pixel[x + y * rank] = SDL_MapRGBA(screen->format, + iteration, + 148, + iteration, + 255); + } + else + { + pixel[x + y * rank] = SDL_MapRGBA(screen->format, + 0, + 0, + 0, + 255); + } + } + } + + SDL_Flip(screen); + } + + // printf("Max Iteration value: %d\n", max_iter); + + SDL_Event ev; + int active; + + active = 1; + while(active) + { + /* Handle events */ + while(SDL_PollEvent(&ev)) + { + if(ev.type == SDL_QUIT) + active = 0; /* End */ + } + } + + SDL_Quit(); + + return 0; +} + diff --git a/mandel_classic.o b/mandel_classic.o new file mode 100644 index 0000000000000000000000000000000000000000..18eaf60ff216f6578042be9b6b0b760ed4247b4e GIT binary patch literal 7200 zcmbtY4RBM(5k6TC{;8uAiQ0M^QY)!Rg$pW52!W6mJzK)h9XUS)62}qPLVgM&vgMJU z0^|ogRZR0L1hkV*(>9q&ra!}UG9{TdO&Vr`z<`1L5rSp_ErAk}tDcs-+2Q;oUHG)URX>e}@)FPk<1Cq=AMW_ob+WvcAeK-b0^%s9X#(2(j z{fQWz1r~&`SD%wYJ_l0LTZa>jc0jQoB95fr)_#lAG2&jvk0|Z;O#v?on1MD^}hO z3+Ku-+tU{;^zn<(X$<%?>m7SX>nsEBeD3d`gxP?@nZ9}l-G==W3T-$D(*l4kGj$z8 zsKSImv!A4emc;63rJjdf>bifG5>!?xtCbEmcksYg z$@IP(D+BUCx0mJfd1%xg`cClmXN=A90qi{3br@><5!(JP zY`N1A>tX1GFabGcvUj0Oun-PIfQLaoib0!Autel--aC?d+>@Jt(l+-eo+W!$KwvDD zc#aG-#Z$2^XHQ&rMth=qG!%*>-G(Vhp~Za29-)xAbbIO7rCopgp$I+*KPSO*uN zekrZo;{-r8K2+{Cs|t&10}H-Cr(a{vBEwRy8v9;DV~=@8?m?OL%Ybpv@bBb+XXsC$ z;(e{HjF3G}tH?=zuEjWz`p>Qd*AnHm---cLgKcUx?BB^oRkMx*Ux7|FTkeJDz*Q)x z&y1;aj;ZPQ$5cb>Q|IhgjbCqo-OECR?ZS4_pnvNjC<;*~<8)^0j*Ne&-}8Z*c?Pxn zb9CD;z#V{U<|Ra+l$t7iM%XcE#W@T%mE(MjCVNYGzt2e4Krmj=>F)$xCB5IGrUz=( zY|U{sv$D@Ksb+86_bT|~CA>u231c(e)YG0*fsEESS_KxC#jAF1x}ha=+iB0FNdB<# zS5Iy_%Uo;oNrk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DQpi#m2AXABuYl1}tcrgA{qAUOD+BU!)7hEAGWwG!l%jScVbjMN%+`^|I5fv4EGKL&gz8PAKl68x9kkCzvhxS#Cecqd;Nc1Hp16?lsI&oO;GxlIz^ zg9FekrvFw6{8R}X=UvRtxf1xtCGg1-cm?FKn15Rd{Mr(DLkWCg34Cb@ytM>QxlP+@Hk>-Q`m4`_PF2KL@a zBC&Wp0nU2?!S_Z!(3(VC@92$3;g)Cq?(T?%Qa$0dTEaAmkf^RDLV7gb)6pBW+?z_0>hNZ#P8xgd*i!doJ2W=7OlM;?|75H0oMcxMzeP zr-VBtyj8+w{kVkBm-N?5I9}C-|7Ro|e}W7AB?-sBItBibgv;aRCEO$F&y?!!MhSO< zjD%*~l(iSI_cV^RiX`$U^l@%To$NiW-^bhdEkP3cN6jXAf^&h3d)u)BT-?Kk3vh7{ OgR3JW^i#ogko_C1!1C_^ literal 0 HcmV?d00001 diff --git a/mandelbrot_kernel.cl b/mandelbrot_kernel.cl new file mode 100644 index 0000000..029599b --- /dev/null +++ b/mandelbrot_kernel.cl @@ -0,0 +1,45 @@ +float map_x(int x, int width) +{ + return (((float)x / (float)width) * 3.5) - 2.5; +} + +float map_y(int y, int height) +{ + return (((float)y / (float)height) * 2.0) - 1.0; +} + +__kernel void mandelbrot_point(__global const int res_x, __global const int res_y, __global const int line, __global int *graph_line) +{ + // Get the index of the current element + int image_x = get_global_id(0); + int image_y = line; + float pos_x = map_x(image_x, res_x); + float pos_y = map_y(image_y, res_y); + float x = 0.0; + float y = 0.0; + + int iteration = 0; + int max_iteration = 255; + float xtemp; + + while (iteration < max_iteration) + { + xtemp = x * x - y * y + pos_x; + y = 2.0 * x * y + pos_y; + + x = xtemp; + iteration++; + + if ((x * x) + (y * y) >= (4.0)) break; + } + + if (iteration >= max_iteration) + { + graph_line[image_x] = 0; + } + else + { + graph_line[image_x] = iteration; + } + +} diff --git a/mandelclassic b/mandelclassic new file mode 100755 index 0000000000000000000000000000000000000000..389c684aa6d8d91a2c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Y)Q;rQA2$5NU$!tk$@Z*Me%a+dADkHJ6oFX8w;3Itoj_#g z?x@Y!hMP7HHbx_H-eUT5cP;)l)WS~RQ6NVS2(p8J+JV08YDsG3Od&g|m|f1#_VGi2 e*<~T@IQrw*E%dd8+Jj*_IM~J-J=7{`zWxugcaH4< literal 0 HcmV?d00001 diff --git a/test b/test new file mode 100755 index 0000000000000000000000000000000000000000..4db960e12f3d425da2abc5e65821cb75d751c009 GIT binary patch literal 10172 zcmcIqYj9h~bzT6ZM2jQ<>R~eyTiqm(EIT1W%Cby96kYHkf*QzDC{m>oN|z7;N^n4e z1}cTEiKnB>%3&Q@&J}y%e1Si zN^JBydv}2g5J>%_S{4>_Gg0li^ zViinff5=v`ML^2&s62(J5tB42vX-<$$k{;4C~g&iRW%}l))^d=R9Z-s%F6{+L=CFf z7_6j>DI6d@vUNnHkJR*WT+-9Rju~l>&?A=gP6)jdLQm41{X9GP#Ryb4dg?@ebygJ| z@hTD4%Kvke`vTaGi+X_K!wy4W*rD=>qyYnFl1jZVK#%PFxWOp|KNk+|+qmI#;Xr*j zG!!4HA8FcHzj1>*7IClV_LCg>uKn(At|9%QfTOaPYC=q>zq{|0!md>k;i82(rZ`Joc{GbQj!;0m6?uoZw(2!j6^ zo?`a=RSEpn68OmyIQ6Gu`7bWvhkHuMZ-Bg$eS)dW`yi1EpX7KgYbe0i3Hd^t0k1(m z5|`uZo5*r0t7NqmYA$ocE^*w>er(Uj8T$7ib?1#t>*(611%lDw{!mO0M!UAPgd;=2 zF8{u8kZIcf!N`yn)BRCh)0npPpw=nmTEhNVEEqG?iz*Lj$Di ze}IZ@Abw}7ufEZ}-r%*+P)KKhwDzFh7L7ucm@VPZFpunrgu`tIgF}W)hZNo!)OUpf z!N|5qAjsvu5Et2O^AC5nH+z^ifSjqgexts_aXrRjI%*tc1H;kKkUoHVQo5+;pdTh{ z!GK@)BVk`GX5fH^0<7KF(cGe~ht;>{9Bt*(9gS&oumQE9!RTk@|1{p|M}2`Y1y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Hj@!lu% z5$&E3Wep2FDe@l?_=CXd`?p-L16=Tjdi`Yy{BM94`(FN3 z3HcXF;J*S+elE2CVhQNKZTttX}RyR%p@L^n!9%9DXK_EUjcnB&cj(^(E6VNbgh6}F5>OJ?adyawtdT%oo!uOm#5j+MiO*tk=Ol#eJw`W^N3!|e4 z`N`h+uHPSv8@B)id`~z(=34+p&ijM9HUhH>?h)jR z(uIcHJqFy0SeTr5pW%02&FI*U+5|#FT09nnL+BQVY~X@B943d51$64q$X;qDh-O +#include +#include + +#include + +#define MAX_SOURCE_SIZE (0x100000) + + +#ifdef CACHE +int** cached_points; +int** cached_x; +int** cached_y; +#endif + +int get_x (int linear_point, int width) +{ + return linear_point % width; +} + +int get_y (int linear_point, int height) +{ + return floor(linear_point / height); +} + +double map_x(int x, int width, double zoom) +{ +#ifndef JULIA + return (((double)x / (double)width) * (3.5 * zoom)) - (2.5 - (1.0 - zoom)); +#else + return (((double)x / (double)width) * (3.5 * zoom)) - (1.7 - (1.0 - zoom)); +#endif +} + +double map_y(int y, int height, double zoom) +{ + return (((double)y / (double)height) * (2.0 * zoom)) - (1.0 - (1.0 - zoom)); +} + +#ifdef CACHE +int cached_iteration(double pos_x, double pos_y) +{ + double centered_x = pos_x + 2.5; + double centered_y = pos_y + 1.0; + double temp_x = floor(centered_x * 1000.0); + double temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + return cached_points[trs_pos_x][trs_pos_y]; +} + +double get_cached_x(double pos_x, double pos_y) +{ + double centered_x = pos_x + 2.5; + double centered_y = pos_y + 1.0; + double temp_x = floor(centered_x * 1000.0); + double temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + return cached_x[trs_pos_x][trs_pos_y]; +} + +double get_cached_y(double pos_x, double pos_y) +{ + double centered_x = pos_x + 2.5; + double centered_y = pos_y + 1.0; + double temp_x = floor(centered_x * 1000.0); + double temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + return cached_y[trs_pos_x][trs_pos_y]; +} + +void store_iteration(double pos_x, double pos_y, int iteration, double x, double y) +{ + double centered_x = pos_x + 2.5; + double centered_y = pos_y + 1.0; + double temp_x = floor(centered_x * 1000.0); + double temp_y = floor(centered_y * 1000.0); + + int trs_pos_x = (int)temp_x; + int trs_pos_y = (int)temp_y; + + cached_points[trs_pos_x][trs_pos_y] = iteration; + cached_x[trs_pos_x][trs_pos_y] = x; + cached_y[trs_pos_x][trs_pos_y] = y; +} +#endif + +int mandelbrot_point(int res_x, int res_y, int image_x, int image_y, double zoom, int max_iteration) +{ + return abs(floor(sin(((double)image_x + zoom) * 0.1) * 127) + floor(cos(((double)image_y + zoom) * 0.1) * 127)); +} + +int julia_point(int res_x, int res_y, int image_x, int image_y, double zoom, int max_iteration) +{ + // Get the index of the current element + double pos_x = map_x(image_x, res_x, 1.0); + double pos_y = map_y(image_y, res_y, 1.0); + double x = pos_x; + double y = pos_y; + double q, x_term; + double xtemp, xx, yy; +#ifdef CACHE + int storeable = 1; +#endif + int iteration = 0; + +#ifdef CACHE + // Look up our cache + iteration = cached_iteration(pos_x, pos_y); + + if (iteration > 0) + { + x = get_cached_x(pos_x, pos_y); + y = get_cached_y(pos_x, pos_y); + yy = y * y; + } + if (iteration < 0) storeable = 0; +#endif + + while (iteration < max_iteration) + { + xx = x * x; + yy = y * y; + if ((xx) + (yy) > (4.0)) break; + y = pow((x + y), 2) - xx - yy; + y = y + 0.288; + xtemp = xx - yy + 0.353 + zoom; + + x = xtemp; + iteration++; + } + + if (iteration >= max_iteration) + { + return 0; + } + else + { +#ifdef CACHE + if (storeable == 1) + { + store_iteration(pos_x, pos_y, iteration, x, y); + } +#endif + return iteration; + } +} + +int main(int argn, char **argv) { + // Init SDL + if(SDL_Init(SDL_INIT_VIDEO) != 0) + fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError()); + + printf("SDL Initialized\n"); + + // Create screen surface + SDL_Surface *screen; + int res_x = 800; + int res_y = 600; + int total_res = res_x * res_y; + +#ifdef CACHE + // Init our cached points + cached_points = malloc(res_y * 1000 * sizeof(int *)); + cached_x = malloc(res_y * 1000 * sizeof(double *)); + cached_y = malloc(res_y * 1000 * sizeof(double *)); + if (cached_points == NULL) + { + fprintf(stderr, "Bad luck, out of memory\n"); + return 2; + } + + int count; + for (count = 0; count < res_y * 1000; count++) + { + cached_points[count] = malloc(res_x * 1000 * sizeof(int)); + if(cached_points[count] == NULL) + { + fprintf(stderr, "Bad luck, out of memory\n"); + return 2; + } + cached_x[count] = malloc(res_x * 1000 * sizeof(double)); + cached_y[count] = malloc(res_x * 1000 * sizeof(double)); + /*for (count2 = 0; count2 < res_x * 100; count2++) + { + cached_points[count][count2] = -1; + }*/ + } + + printf("Cache ready\n"); +#endif + + // screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); + screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF); + if(!screen) + fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError()); + + // Prepare the resolution and sizes and colors... + int i; + int temp; + const int ITERATIONS = 256; + + printf("Rendering...\n"); + + double zoom; + +#ifndef JULIA + for (zoom = 1.0; zoom < 200.0 ; zoom += 1.0) +#else + for (zoom = 1.0; zoom > -2.5 ; zoom -= 0.01) +#endif + { + i = 0; + int iteration, max_iteration, x, y; + if((zoom < -0.02) && (zoom > -1.0)) + { + max_iteration = 100; + } + else + { + max_iteration = 255; + } + int col_value; + Uint32 *pixel; + int rank; + // Lock surface + // SDL_LockSurface(screen); + rank = screen->pitch/sizeof(Uint32); + pixel = (Uint32*)screen->pixels; + /* Draw all dots */ + for(y = 0;y < res_y;y++) + { + for(x = 0;x < res_x;x++) + { + #ifndef JULIA + iteration = mandelbrot_point(res_x, res_y, x, y, zoom, max_iteration); + #else + iteration = julia_point(res_x, res_y, x, y, zoom, max_iteration); + #endif + if ((iteration < 128) && (iteration > 0)) { + pixel[x + y * rank] = SDL_MapRGBA(screen->format, + 0, + 20 + iteration, + 0, + 255); + } + else if ((iteration >= 128) && (iteration < max_iteration)) + { + pixel[x + y * rank] = SDL_MapRGBA(screen->format, + iteration, + 200, + iteration, + 255); + } + else + { + pixel[x + y * rank] = SDL_MapRGBA(screen->format, + 0, + 0, + 0, + 255); + } + i++; + } + } + // Unlock surface + // SDL_UnlockSurface(screen); + + // Draw to the screen + SDL_Flip(screen); + } + + // printf("Max Iteration value: %d\n", max_iter); + + SDL_Event ev; + int active; + + active = 1; + while(active) + { + /* Handle events */ + while(SDL_PollEvent(&ev)) + { + if(ev.type == SDL_QUIT) + active = 0; /* End */ + } + } + + SDL_Quit(); + + return 0; +} + diff --git a/test.o b/test.o new file mode 100644 index 0000000000000000000000000000000000000000..261f5603d22c0028ade971b50bd09d92866fd8ce GIT binary patch literal 5136 zcmbW4Z)_Ar6u{@&15c>ChhnUvcEv-h;-(9T^)I*W)m}|eY(-nCmZRN+lWXsCw}*hr zpPWT6SmXnV$|p6(=m&{k{BP_*Rf-tJO0;6s=m#UIe@~-G)cW4+yu0ao7ZYDHGjD$L z=FOYg*_qv~E$uf{c|457!>(tg8d1i!%`E9bt_GQ(oyKw}b0_wnto!}%+>ueWF39WQ z>~}uS3hJf#Z_zlMealx+7v@KI1Ns=!2L<)6cMGcjOl&Qv-A5ov^&Y7EXE<#=2MTJ> zSX8aw4+DU0sXs8V>zdXV*fFr5fbSsA4&~pxz_&p3^XFb=NK@_+v&MrtlTm!Zf>~^k0GPz$RfD-$hmZhkMo+LdDhd zUx&?;7t#1&cuaOMt>Yqafh+b=Ht&H5j)ty+K)WHBu1}x}0peQsyjL*QuCdIEMt(H9 z`;8a3iSm zc4PciP=jxFRWUZARSOy(%D3g-&ito~*Qdx2ZODV6K+QpbuyeeD7WL&!?ed+LW_)jM z|K?9HZZW1NFNS@ZJ+XDm%H00f#=tc94v(Zc=Y69sd(hLieG22SJHVwk5Xzl2a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