clray

view src/clray.cc @ 1:0b0e4d18d53f

added non-buffer args
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 12 Jul 2010 07:00:19 +0300
parents 5767277e049f
children 41d6253492ad
line source
1 #include <stdio.h>
2 #include <assert.h>
3 #include "ocl.h"
5 struct Sphere {
6 cl_float4 pos;
7 cl_float radius;
9 cl_float4 color;
10 } __attribute__((packed));
12 struct Ray {
13 cl_float4 origin, dir;
14 } __attribute__((packed));
17 int main()
18 {
19 int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
20 int res[16];
21 int count = sizeof data / sizeof *data;
23 for(int i=0; i<count; i++) {
24 printf("%d ", data[i]);
25 }
26 putchar('\n');
28 CLProgram prog("test");
29 if(!prog.load("test.cl")) {
30 return 1;
31 }
32 if(!prog.set_arg_buffer(0, ARG_WR, sizeof res, res)) {
33 return 1;
34 }
35 if(!prog.set_arg_buffer(1, ARG_RD, sizeof data, data)) {
36 return 1;
37 }
38 if(!prog.set_argi(2, 100)) {
39 return 1;
40 }
42 if(!prog.run(1, 16)) {
43 return 1;
44 }
46 CLMemBuffer *mbuf = prog.get_arg_buffer(1);
47 map_mem_buffer(mbuf, MAP_RD);
49 for(int i=0; i<count; i++) {
50 printf("%d ", res[i]);
51 }
52 putchar('\n');
53 unmap_mem_buffer(mbuf);
55 return 0;
56 }