clray

annotate src/ocl.h @ 0:5767277e049f

first test works, let's try to make a raytracer now...
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 12 Jul 2010 05:56:47 +0300
parents
children 0b0e4d18d53f
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@0 7 #include <CL/opencl.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@0 39
nuclear@0 40 class CLProgram {
nuclear@0 41 private:
nuclear@0 42 std::string kname;
nuclear@0 43 cl_program prog;
nuclear@0 44 cl_kernel kernel;
nuclear@0 45 std::vector<CLMemBuffer*> mbuf;
nuclear@0 46 bool built;
nuclear@0 47
nuclear@0 48 public:
nuclear@0 49 CLProgram(const char *kname);
nuclear@0 50 ~CLProgram();
nuclear@0 51
nuclear@0 52 bool load(const char *fname);
nuclear@0 53
nuclear@0 54 bool set_arg(int arg, int rdwr, size_t sz, void *buf);
nuclear@0 55 CLMemBuffer *get_arg_buffer(int arg);
nuclear@0 56
nuclear@0 57 bool build();
nuclear@0 58
nuclear@0 59 bool run() const;
nuclear@0 60 bool run(int dim, ...) const;
nuclear@0 61 };
nuclear@0 62
nuclear@0 63 #endif /* OCL_H_ */