clray

annotate 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
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@12 30 CLMemBuffer *create_mem_buffer(int rdwr, size_t sz, void *buf = 0);
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;
John@14 56
John@14 57 CLArg();
nuclear@1 58 };
nuclear@1 59
nuclear@0 60
nuclear@0 61 class CLProgram {
nuclear@0 62 private:
nuclear@0 63 std::string kname;
nuclear@0 64 cl_program prog;
nuclear@0 65 cl_kernel kernel;
nuclear@1 66 std::vector<CLArg> args;
nuclear@0 67 bool built;
nuclear@0 68
nuclear@0 69 public:
nuclear@0 70 CLProgram(const char *kname);
nuclear@0 71 ~CLProgram();
nuclear@0 72
nuclear@0 73 bool load(const char *fname);
nuclear@0 74
nuclear@1 75 bool set_argi(int arg, int val);
nuclear@1 76 bool set_argf(int arg, float val);
nuclear@12 77 bool set_arg_buffer(int arg, int rdwr, size_t sz, void *buf = 0);
nuclear@0 78 CLMemBuffer *get_arg_buffer(int arg);
John@14 79 int get_num_args() const;
nuclear@0 80
nuclear@0 81 bool build();
nuclear@0 82
nuclear@0 83 bool run() const;
nuclear@0 84 bool run(int dim, ...) const;
nuclear@0 85 };
nuclear@0 86
nuclear@0 87 #endif /* OCL_H_ */