clray

annotate src/clray.cc @ 0:5767277e049f

first test works, let's try to make a raytracer now...
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 12 Jul 2010 05:56:47 +0300
parents
children 0b0e4d18d53f
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <assert.h>
nuclear@0 3 #include "ocl.h"
nuclear@0 4
nuclear@0 5 int main()
nuclear@0 6 {
nuclear@0 7 int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
nuclear@0 8 int res[16];
nuclear@0 9 int count = sizeof data / sizeof *data;
nuclear@0 10
nuclear@0 11 for(int i=0; i<count; i++) {
nuclear@0 12 printf("%d ", data[i]);
nuclear@0 13 }
nuclear@0 14 putchar('\n');
nuclear@0 15
nuclear@0 16 CLProgram prog("test");
nuclear@0 17 if(!prog.load("test.cl")) {
nuclear@0 18 return 1;
nuclear@0 19 }
nuclear@0 20 if(!prog.set_arg(0, ARG_RD, sizeof data, data)) {
nuclear@0 21 return 1;
nuclear@0 22 }
nuclear@0 23 if(!prog.set_arg(1, ARG_WR, sizeof res, res)) {
nuclear@0 24 return 1;
nuclear@0 25 }
nuclear@0 26
nuclear@0 27 if(!prog.run(1, 16)) {
nuclear@0 28 return 1;
nuclear@0 29 }
nuclear@0 30
nuclear@0 31 CLMemBuffer *mbuf = prog.get_arg_buffer(1);
nuclear@0 32 map_mem_buffer(mbuf, MAP_RD);
nuclear@0 33
nuclear@0 34 for(int i=0; i<count; i++) {
nuclear@0 35 printf("%d ", res[i]);
nuclear@0 36 }
nuclear@0 37 putchar('\n');
nuclear@0 38 unmap_mem_buffer(mbuf);
nuclear@0 39
nuclear@0 40 return 0;
nuclear@0 41 }