clray
view 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 |
line source
1 #include <stdio.h>
2 #include <assert.h>
3 #include "ocl.h"
5 int main()
6 {
7 int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
8 int res[16];
9 int count = sizeof data / sizeof *data;
11 for(int i=0; i<count; i++) {
12 printf("%d ", data[i]);
13 }
14 putchar('\n');
16 CLProgram prog("test");
17 if(!prog.load("test.cl")) {
18 return 1;
19 }
20 if(!prog.set_arg(0, ARG_RD, sizeof data, data)) {
21 return 1;
22 }
23 if(!prog.set_arg(1, ARG_WR, sizeof res, res)) {
24 return 1;
25 }
27 if(!prog.run(1, 16)) {
28 return 1;
29 }
31 CLMemBuffer *mbuf = prog.get_arg_buffer(1);
32 map_mem_buffer(mbuf, MAP_RD);
34 for(int i=0; i<count; i++) {
35 printf("%d ", res[i]);
36 }
37 putchar('\n');
38 unmap_mem_buffer(mbuf);
40 return 0;
41 }