clray

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ocl.h	Mon Jul 12 05:56:47 2010 +0300
     1.3 @@ -0,0 +1,63 @@
     1.4 +#ifndef OCL_H_
     1.5 +#define OCL_H_
     1.6 +
     1.7 +#include <vector>
     1.8 +#include <string>
     1.9 +#ifndef __APPLE__
    1.10 +#include <CL/opencl.h>
    1.11 +#else
    1.12 +#include <OpenCL/opencl.h>
    1.13 +#endif
    1.14 +
    1.15 +enum {
    1.16 +	ARG_RD		= CL_MEM_READ_ONLY,
    1.17 +	ARG_WR		= CL_MEM_WRITE_ONLY,
    1.18 +	ARG_RDWR	= CL_MEM_READ_WRITE
    1.19 +};
    1.20 +
    1.21 +enum {
    1.22 +	MAP_RD		= CL_MAP_READ,
    1.23 +	MAP_WR		= CL_MAP_WRITE,
    1.24 +	MAP_RDWR	= CL_MAP_READ | CL_MAP_WRITE
    1.25 +};
    1.26 +
    1.27 +struct CLMemBuffer {
    1.28 +	cl_mem mem;
    1.29 +	size_t size;
    1.30 +	void *ptr;
    1.31 +};
    1.32 +
    1.33 +CLMemBuffer *create_mem_buffer(int rdwr, size_t sz, void *buf);
    1.34 +void destroy_mem_buffer(CLMemBuffer *mbuf);
    1.35 +
    1.36 +void *map_mem_buffer(CLMemBuffer *mbuf, int rdwr);
    1.37 +void unmap_mem_buffer(CLMemBuffer *mbuf);
    1.38 +
    1.39 +bool write_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *src);
    1.40 +bool read_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *dest);
    1.41 +
    1.42 +
    1.43 +class CLProgram {
    1.44 +private:
    1.45 +	std::string kname;
    1.46 +	cl_program prog;
    1.47 +	cl_kernel kernel;
    1.48 +	std::vector<CLMemBuffer*> mbuf;
    1.49 +	bool built;
    1.50 +
    1.51 +public:
    1.52 +	CLProgram(const char *kname);
    1.53 +	~CLProgram();
    1.54 +
    1.55 +	bool load(const char *fname);
    1.56 +
    1.57 +	bool set_arg(int arg, int rdwr, size_t sz, void *buf);
    1.58 +	CLMemBuffer *get_arg_buffer(int arg);
    1.59 +
    1.60 +	bool build();
    1.61 +
    1.62 +	bool run() const;
    1.63 +	bool run(int dim, ...) const;
    1.64 +};
    1.65 +
    1.66 +#endif	/* OCL_H_ */