/
cll.h
74 lines (62 loc) · 2.19 KB
/
cll.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef ADVCL_CLL_H_INCLUDED
#define ADVCL_CLL_H_INCLUDED
#define __CL_ENABLE_EXCEPTIONS
#include "CL/cl.hpp"
// issue with using cl_float4 from cl_platform.h
// http://www.khronos.org/message_boards/viewtopic.php?f=28&t=1848
// typedef cl_float cl_float4 __attribute__ ((__vector_size__ (16), __may_alias__));
typedef struct Vec4
{
float x,y,z,w;
Vec4(){};
//convenience functions
Vec4(float xx, float yy, float zz, float ww):
x(xx),
y(yy),
z(zz),
w(ww)
{}
void set(float xx, float yy, float zz, float ww=1.) {
x = xx;
y = yy;
z = zz;
w = ww;
}
} Vec4 __attribute__((aligned(16)));
class CL {
public:
//These are arrays we will use in this tutorial
std::vector<cl::Memory> cl_vbos; //0: position vbo, 1: color vbo
cl::Buffer cl_velocities; //particle velocities
cl::Buffer cl_pos_gen; //want to have the start points for reseting particles
cl::Buffer cl_vel_gen; //want to have the start velocities for reseting particles
int p_vbo; //position vbo
int c_vbo; //colors vbo
int num; //the number of particles
size_t array_size; //the size of our arrays num * sizeof(Vec4)
//default constructor initializes OpenCL context and automatically chooses platform and device
CL();
//default destructor releases OpenCL objects and frees device memory
~CL();
//load an OpenCL program from a string
void loadProgram(std::string kernel_source);
//setup the data for the kernel
void loadData(std::vector<Vec4> pos, std::vector<Vec4> vel, std::vector<Vec4> color);
//these are implemented in part1.cpp (in the future we will make these more general)
void popCorn();
//execute the kernel
void runKernel();
// real coders bare all
// private:
unsigned int deviceUsed;
std::vector<cl::Device> devices;
cl::Context context;
cl::CommandQueue queue;
cl::Program program;
cl::Kernel kernel;
//debugging variables
cl_int err;
///cl_event event;
cl::Event event;
};
#endif