clray

view src/ocl.h @ 11:d9a1bab1c3f5

ported to windows
author John Tsiombikas
date Sat, 31 Jul 2010 22:23:57 +0100
parents 0b0e4d18d53f
children 85fd61f374d9
line source
1 #ifndef OCL_H_
2 #define OCL_H_
4 #include <vector>
5 #include <string>
6 #ifndef __APPLE__
7 #include <CL/cl.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);
39 enum {
40 ARGTYPE_NONE,
42 ARGTYPE_INT,
43 ARGTYPE_FLOAT,
44 ARGTYPE_FLOAT4,
45 ARGTYPE_MEM_BUF
46 };
48 struct CLArg {
49 int type;
50 union {
51 int ival;
52 float fval;
53 cl_float4 vval;
54 CLMemBuffer *mbuf;
55 } v;
56 };
59 class CLProgram {
60 private:
61 std::string kname;
62 cl_program prog;
63 cl_kernel kernel;
64 std::vector<CLArg> args;
65 bool built;
67 public:
68 CLProgram(const char *kname);
69 ~CLProgram();
71 bool load(const char *fname);
73 bool set_argi(int arg, int val);
74 bool set_argf(int arg, float val);
75 bool set_arg_buffer(int arg, int rdwr, size_t sz, void *buf);
76 CLMemBuffer *get_arg_buffer(int arg);
78 bool build();
80 bool run() const;
81 bool run(int dim, ...) const;
82 };
84 #endif /* OCL_H_ */