Marine systems simulation
CNetPanelForcesOcl.h
1#ifndef CNetPanelForcesOcl_h
2#define CNetPanelForcesOcl_h
3
4#include <CL/opencl.h>
5#include <cstring>
6#include <iostream>
7#include "sfh/timers/ProfilerWallclock.h"
8#include "sfh/filters/FIR.h"
9
11public:
12 /*
13 // Arrays on the GPU
14 cl_mem cl_a;
15 cl_mem cl_b;
16 cl_mem cl_c;
17 int num; //the size of our arrays
18 */
19
20 size_t workGroupSize[1]; //N dimensional array of workgroup size we must pass to the kernel
21
22 //default constructor initializes OpenCL context and automatically chooses platform and device
24 //default destructor releases OpenCL objects and frees device memory
26
27 //load an OpenCL program from a file
28 //the path is relative to the CL_SOURCE_DIR set in CMakeLists.txt
29 void LoadProgram(const char* relative_path);
30
31 //setup the data for the kernel
32 //these are implemented in part1.cpp (in the future we will make these more general)
33 void Initialize(
34 int* aiPosIndex,
35 int* aiVelIndex,
36 int* aiNetConn,
37 float* adNodesDistMesh,
38 float* adMesdDet,
39 float* adEATwine,
40 float* adMeshBarLength_unstretched,
41 float* adKnotDiameter,
42 float* adKnotMomStiff_contact,
43 float* adNodeWeight,
44 float* adDampingCoeff,
45 float* adKKnot,
46 float* adTwineDragNormal,
47 float* adTwineDiameter,
48 float m_CnLinearLimitAngle,
49 float m_CnLinear,
50 float m_CnTurb,
51 float m_CnLam,
52 float m_TurbLimit,
53 float m_LamLimit,
54 float m_Ct_nominal,
55 float m_CnKnots_nominal,
56 int iNodes,
57 int iPanels);
58 //execute the kernel
59 void StartNetPanelForcCalc(const double* const adPosAndVel, float* afWaterVel_ned);
60 void GetNetPanelForces(double* adForces);
61
62 void InitializeGlBuffer(unsigned int bufobj);
63private:
64
65 //handles for creating an opencl context
66 cl_platform_id platform;
67
68 //device variables
69 cl_device_id* devices;
70 cl_uint numDevices;
71 unsigned int deviceUsed;
72
73 cl_context context;
74
75 cl_command_queue command_queue;
76 cl_program program;
77 cl_kernel kernel;
78
79
80 //debugging variables
81 cl_int err;
82 cl_event event;
83
84 //buildExecutable is called by loadProgram
85 //build runtime executable from a program
86 void BuildExecutable();
87
88 char *FileContents(const char *filename, int *length);
89
90 cl_int GetPlatformID(cl_platform_id* clSelectedPlatformID);
91 const char* GetErrorString(cl_int error);
92
93
94 int m_iNodes;
95 int m_iPanels;
96 bool m_bAllOK;
97
98 cl_mem cmPinnedBufInPos;
99 cl_mem cmDevBufInPos;
100 float* cDataInPos;
101 cl_mem cmPinnedBufInVel;
102 cl_mem cmDevBufInVel;
103 float* cDataInVel;
104 cl_mem cmPinnedBufInWaterVel;
105 cl_mem cmDevBufInWaterVel;
106 float* cDataInWaterVel;
107
108 cl_mem cmPinnedBufOutForce;
109 cl_mem cmDevBufOutForce;
110 float* cDataOutForce;
111
112
113 //cl_mem cl_afPos;
114 //cl_mem cl_afVel;
115 //cl_mem cl_afWaterVel_ned;
116 //cl_mem cl_afNodeForces;
117 cl_mem cl_afNodesDistMesh;
118 cl_mem cl_afMesdDet;
119 cl_mem cl_afEATwine;
120 cl_mem cl_afMeshBarLength_unstretched;
121 cl_mem cl_afKnotDiameter;
122 cl_mem cl_afKnotMomStiff_contact;
123 cl_mem cl_afNodeWeight;
124 cl_mem cl_afDampingCoeff;
125 cl_mem cl_afKKnot;
126 cl_mem cl_afTwineDragNormal;
127 cl_mem cl_afTwineDiameter;
128 cl_mem cl_CnLinearLimitAngle;
129 cl_mem cl_CnLinear;
130 cl_mem cl_CnTurb;
131 cl_mem cl_CnLam;
132 cl_mem cl_TurbLimit;
133 cl_mem cl_LamLimit;
134 cl_mem cl_Ct_nominal;
135 cl_mem cl_CnKnots_nominal;
136
137 // Rendering
138 cl_mem cl_renderbuffer;
139
140 float* m_afElementForces;
141 float* m_afElementNodesPos;
142 float* m_afElementNodesVel;
143 int* m_aiPosIndex;
144 int* m_aiVelIndex;
145 int* m_aiNetConn;
146
147 sfh::timers::ProfilerWallclock m_Profiler;
148 sfh::filters::FIR m_ProfileFilter;
149};
150
151#endif
Definition: CNetPanelForcesOcl.h:10