clray

view src/ocl.h @ 20:63a6b46f58a0

fixed
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 09 Aug 2010 12:55:40 +0100
parents 85fd61f374d9
children 97cfd9675310
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 = 0);
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;
57 CLArg();
58 };
61 class CLProgram {
62 private:
63 std::string kname;
64 cl_program prog;
65 cl_kernel kernel;
66 std::vector<CLArg> args;
67 bool built;
69 public:
70 CLProgram(const char *kname);
71 ~CLProgram();
73 bool load(const char *fname);
75 bool set_argi(int arg, int val);
76 bool set_argf(int arg, float val);
77 bool set_arg_buffer(int arg, int rdwr, size_t sz, void *buf = 0);
78 CLMemBuffer *get_arg_buffer(int arg);
79 int get_num_args() const;
81 bool build();
83 bool run() const;
84 bool run(int dim, ...) const;
85 };
87 #endif /* OCL_H_ */