clray
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clray.cc Mon Jul 12 05:56:47 2010 +0300 1.3 @@ -0,0 +1,41 @@ 1.4 +#include <stdio.h> 1.5 +#include <assert.h> 1.6 +#include "ocl.h" 1.7 + 1.8 +int main() 1.9 +{ 1.10 + int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; 1.11 + int res[16]; 1.12 + int count = sizeof data / sizeof *data; 1.13 + 1.14 + for(int i=0; i<count; i++) { 1.15 + printf("%d ", data[i]); 1.16 + } 1.17 + putchar('\n'); 1.18 + 1.19 + CLProgram prog("test"); 1.20 + if(!prog.load("test.cl")) { 1.21 + return 1; 1.22 + } 1.23 + if(!prog.set_arg(0, ARG_RD, sizeof data, data)) { 1.24 + return 1; 1.25 + } 1.26 + if(!prog.set_arg(1, ARG_WR, sizeof res, res)) { 1.27 + return 1; 1.28 + } 1.29 + 1.30 + if(!prog.run(1, 16)) { 1.31 + return 1; 1.32 + } 1.33 + 1.34 + CLMemBuffer *mbuf = prog.get_arg_buffer(1); 1.35 + map_mem_buffer(mbuf, MAP_RD); 1.36 + 1.37 + for(int i=0; i<count; i++) { 1.38 + printf("%d ", res[i]); 1.39 + } 1.40 + putchar('\n'); 1.41 + unmap_mem_buffer(mbuf); 1.42 + 1.43 + return 0; 1.44 +}