nuclear@0: #ifndef OCL_H_ nuclear@0: #define OCL_H_ nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: #ifndef __APPLE__ nuclear@8: #include nuclear@0: #else nuclear@0: #include nuclear@0: #endif nuclear@0: nuclear@0: enum { nuclear@0: ARG_RD = CL_MEM_READ_ONLY, nuclear@0: ARG_WR = CL_MEM_WRITE_ONLY, nuclear@0: ARG_RDWR = CL_MEM_READ_WRITE nuclear@0: }; nuclear@0: nuclear@0: enum { nuclear@0: MAP_RD = CL_MAP_READ, nuclear@0: MAP_WR = CL_MAP_WRITE, nuclear@0: MAP_RDWR = CL_MAP_READ | CL_MAP_WRITE nuclear@0: }; nuclear@0: nuclear@0: struct CLMemBuffer { nuclear@0: cl_mem mem; nuclear@0: size_t size; nuclear@0: void *ptr; nuclear@0: }; nuclear@0: nuclear@0: CLMemBuffer *create_mem_buffer(int rdwr, size_t sz, void *buf); nuclear@0: void destroy_mem_buffer(CLMemBuffer *mbuf); nuclear@0: nuclear@0: void *map_mem_buffer(CLMemBuffer *mbuf, int rdwr); nuclear@0: void unmap_mem_buffer(CLMemBuffer *mbuf); nuclear@0: nuclear@0: bool write_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *src); nuclear@0: bool read_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *dest); nuclear@0: nuclear@1: enum { nuclear@1: ARGTYPE_NONE, nuclear@1: nuclear@1: ARGTYPE_INT, nuclear@1: ARGTYPE_FLOAT, nuclear@1: ARGTYPE_FLOAT4, nuclear@1: ARGTYPE_MEM_BUF nuclear@1: }; nuclear@1: nuclear@1: struct CLArg { nuclear@1: int type; nuclear@1: union { nuclear@1: int ival; nuclear@1: float fval; nuclear@1: cl_float4 vval; nuclear@1: CLMemBuffer *mbuf; nuclear@1: } v; nuclear@1: }; nuclear@1: nuclear@0: nuclear@0: class CLProgram { nuclear@0: private: nuclear@0: std::string kname; nuclear@0: cl_program prog; nuclear@0: cl_kernel kernel; nuclear@1: std::vector args; nuclear@0: bool built; nuclear@0: nuclear@0: public: nuclear@0: CLProgram(const char *kname); nuclear@0: ~CLProgram(); nuclear@0: nuclear@0: bool load(const char *fname); nuclear@0: nuclear@1: bool set_argi(int arg, int val); nuclear@1: bool set_argf(int arg, float val); nuclear@1: bool set_arg_buffer(int arg, int rdwr, size_t sz, void *buf); nuclear@0: CLMemBuffer *get_arg_buffer(int arg); nuclear@0: nuclear@0: bool build(); nuclear@0: nuclear@0: bool run() const; nuclear@0: bool run(int dim, ...) const; nuclear@0: }; nuclear@0: nuclear@0: #endif /* OCL_H_ */