clray

annotate 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
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@1 5 struct Sphere {
nuclear@1 6 cl_float4 pos;
nuclear@1 7 cl_float radius;
nuclear@1 8
nuclear@1 9 cl_float4 color;
nuclear@1 10 } __attribute__((packed));
nuclear@1 11
nuclear@1 12 struct Ray {
nuclear@1 13 cl_float4 origin, dir;
nuclear@1 14 } __attribute__((packed));
nuclear@1 15
nuclear@1 16
nuclear@0 17 int main()
nuclear@0 18 {
nuclear@0 19 int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
nuclear@0 20 int res[16];
nuclear@0 21 int count = sizeof data / sizeof *data;
nuclear@0 22
nuclear@0 23 for(int i=0; i<count; i++) {
nuclear@0 24 printf("%d ", data[i]);
nuclear@0 25 }
nuclear@0 26 putchar('\n');
nuclear@0 27
nuclear@0 28 CLProgram prog("test");
nuclear@0 29 if(!prog.load("test.cl")) {
nuclear@0 30 return 1;
nuclear@0 31 }
nuclear@1 32 if(!prog.set_arg_buffer(0, ARG_WR, sizeof res, res)) {
nuclear@0 33 return 1;
nuclear@0 34 }
nuclear@1 35 if(!prog.set_arg_buffer(1, ARG_RD, sizeof data, data)) {
nuclear@1 36 return 1;
nuclear@1 37 }
nuclear@1 38 if(!prog.set_argi(2, 100)) {
nuclear@0 39 return 1;
nuclear@0 40 }
nuclear@0 41
nuclear@0 42 if(!prog.run(1, 16)) {
nuclear@0 43 return 1;
nuclear@0 44 }
nuclear@0 45
nuclear@0 46 CLMemBuffer *mbuf = prog.get_arg_buffer(1);
nuclear@0 47 map_mem_buffer(mbuf, MAP_RD);
nuclear@0 48
nuclear@0 49 for(int i=0; i<count; i++) {
nuclear@0 50 printf("%d ", res[i]);
nuclear@0 51 }
nuclear@0 52 putchar('\n');
nuclear@0 53 unmap_mem_buffer(mbuf);
nuclear@0 54
nuclear@0 55 return 0;
nuclear@0 56 }