annotate src/ocl.h @ 11:d9a1bab1c3f5
ported to windows
author |
John Tsiombikas |
date |
Sat, 31 Jul 2010 22:23:57 +0100 |
parents |
0b0e4d18d53f |
children |
85fd61f374d9 |
rev |
line source |
nuclear@0
|
1 #ifndef OCL_H_
|
nuclear@0
|
2 #define OCL_H_
|
nuclear@0
|
3
|
nuclear@0
|
4 #include <vector>
|
nuclear@0
|
5 #include <string>
|
nuclear@0
|
6 #ifndef __APPLE__
|
nuclear@8
|
7 #include <CL/cl.h>
|
nuclear@0
|
8 #else
|
nuclear@0
|
9 #include <OpenCL/opencl.h>
|
nuclear@0
|
10 #endif
|
nuclear@0
|
11
|
nuclear@0
|
12 enum {
|
nuclear@0
|
13 ARG_RD = CL_MEM_READ_ONLY,
|
nuclear@0
|
14 ARG_WR = CL_MEM_WRITE_ONLY,
|
nuclear@0
|
15 ARG_RDWR = CL_MEM_READ_WRITE
|
nuclear@0
|
16 };
|
nuclear@0
|
17
|
nuclear@0
|
18 enum {
|
nuclear@0
|
19 MAP_RD = CL_MAP_READ,
|
nuclear@0
|
20 MAP_WR = CL_MAP_WRITE,
|
nuclear@0
|
21 MAP_RDWR = CL_MAP_READ | CL_MAP_WRITE
|
nuclear@0
|
22 };
|
nuclear@0
|
23
|
nuclear@0
|
24 struct CLMemBuffer {
|
nuclear@0
|
25 cl_mem mem;
|
nuclear@0
|
26 size_t size;
|
nuclear@0
|
27 void *ptr;
|
nuclear@0
|
28 };
|
nuclear@0
|
29
|
nuclear@0
|
30 CLMemBuffer *create_mem_buffer(int rdwr, size_t sz, void *buf);
|
nuclear@0
|
31 void destroy_mem_buffer(CLMemBuffer *mbuf);
|
nuclear@0
|
32
|
nuclear@0
|
33 void *map_mem_buffer(CLMemBuffer *mbuf, int rdwr);
|
nuclear@0
|
34 void unmap_mem_buffer(CLMemBuffer *mbuf);
|
nuclear@0
|
35
|
nuclear@0
|
36 bool write_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *src);
|
nuclear@0
|
37 bool read_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *dest);
|
nuclear@0
|
38
|
nuclear@1
|
39 enum {
|
nuclear@1
|
40 ARGTYPE_NONE,
|
nuclear@1
|
41
|
nuclear@1
|
42 ARGTYPE_INT,
|
nuclear@1
|
43 ARGTYPE_FLOAT,
|
nuclear@1
|
44 ARGTYPE_FLOAT4,
|
nuclear@1
|
45 ARGTYPE_MEM_BUF
|
nuclear@1
|
46 };
|
nuclear@1
|
47
|
nuclear@1
|
48 struct CLArg {
|
nuclear@1
|
49 int type;
|
nuclear@1
|
50 union {
|
nuclear@1
|
51 int ival;
|
nuclear@1
|
52 float fval;
|
nuclear@1
|
53 cl_float4 vval;
|
nuclear@1
|
54 CLMemBuffer *mbuf;
|
nuclear@1
|
55 } v;
|
nuclear@1
|
56 };
|
nuclear@1
|
57
|
nuclear@0
|
58
|
nuclear@0
|
59 class CLProgram {
|
nuclear@0
|
60 private:
|
nuclear@0
|
61 std::string kname;
|
nuclear@0
|
62 cl_program prog;
|
nuclear@0
|
63 cl_kernel kernel;
|
nuclear@1
|
64 std::vector<CLArg> args;
|
nuclear@0
|
65 bool built;
|
nuclear@0
|
66
|
nuclear@0
|
67 public:
|
nuclear@0
|
68 CLProgram(const char *kname);
|
nuclear@0
|
69 ~CLProgram();
|
nuclear@0
|
70
|
nuclear@0
|
71 bool load(const char *fname);
|
nuclear@0
|
72
|
nuclear@1
|
73 bool set_argi(int arg, int val);
|
nuclear@1
|
74 bool set_argf(int arg, float val);
|
nuclear@1
|
75 bool set_arg_buffer(int arg, int rdwr, size_t sz, void *buf);
|
nuclear@0
|
76 CLMemBuffer *get_arg_buffer(int arg);
|
nuclear@0
|
77
|
nuclear@0
|
78 bool build();
|
nuclear@0
|
79
|
nuclear@0
|
80 bool run() const;
|
nuclear@0
|
81 bool run(int dim, ...) const;
|
nuclear@0
|
82 };
|
nuclear@0
|
83
|
nuclear@0
|
84 #endif /* OCL_H_ */
|