clray
view src/ocl.h @ 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 #ifndef OCL_H_
2 #define OCL_H_
4 #include <vector>
5 #include <string>
6 #ifndef __APPLE__
7 #include <CL/opencl.h>
8 #else
9 #include <OpenCL/opencl.h>
10 #endif
12 enum {
13 ARG_RD = CL_MEM_READ_ONLY,
14 ARG_WR = CL_MEM_WRITE_ONLY,
15 ARG_RDWR = CL_MEM_READ_WRITE
16 };
18 enum {
19 MAP_RD = CL_MAP_READ,
20 MAP_WR = CL_MAP_WRITE,
21 MAP_RDWR = CL_MAP_READ | CL_MAP_WRITE
22 };
24 struct CLMemBuffer {
25 cl_mem mem;
26 size_t size;
27 void *ptr;
28 };
30 CLMemBuffer *create_mem_buffer(int rdwr, size_t sz, void *buf);
31 void destroy_mem_buffer(CLMemBuffer *mbuf);
33 void *map_mem_buffer(CLMemBuffer *mbuf, int rdwr);
34 void unmap_mem_buffer(CLMemBuffer *mbuf);
36 bool write_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *src);
37 bool read_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *dest);
40 class CLProgram {
41 private:
42 std::string kname;
43 cl_program prog;
44 cl_kernel kernel;
45 std::vector<CLMemBuffer*> mbuf;
46 bool built;
48 public:
49 CLProgram(const char *kname);
50 ~CLProgram();
52 bool load(const char *fname);
54 bool set_arg(int arg, int rdwr, size_t sz, void *buf);
55 CLMemBuffer *get_arg_buffer(int arg);
57 bool build();
59 bool run() const;
60 bool run(int dim, ...) const;
61 };
63 #endif /* OCL_H_ */