Langmuir
Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
openclhelper.h
Go to the documentation of this file.
1 #ifndef OPENCLHELPER_H
2 #define OPENCLHELPER_H
3 #define __CL_ENABLE_EXCEPTIONS
4 
5 #ifdef LANGMUIR_OPEN_CL
6 #include "cl.hpp"
7 #endif
8 
9 #include <QObject>
10 #include <QVector>
11 
12 namespace LangmuirCore
13 {
14 
15 class World;
16 class ChargeAgent;
17 
21 class OpenClHelper : public QObject
22 {
23 private:
24  Q_OBJECT
25  Q_DISABLE_COPY(OpenClHelper)
26 
27 public:
34  OpenClHelper(World &world, QObject *parent=0);
35 
39  void initializeOpenCL(int gpuID = -1);
40 
49  void launchCoulombKernel1();
50 
54  void launchCoulombKernel2();
55 
59  void launchGaussKernel1();
60 
64  void launchGaussKernel2();
65 
72  void copySiteAndChargeToHostVector(int index, int site, int charge = -1);
73 
78  double getOutputHost(int index) const;
79 
86  double getOutputHostFuture(int index) const;
87 
92 
100  bool toggleOpenCL(bool on);
101 
102 private:
107 
108 #ifdef LANGMUIR_OPEN_CL
109 
112  cl::Platform m_platform;
113 
117  cl::Context m_context;
118 
122  cl::Device m_device;
123 
127  cl::CommandQueue m_queue;
128 
132  cl::Kernel m_coulomb1K;
133 
137  cl::Kernel m_guass1K;
138 
142  cl::Kernel m_coulomb2K;
143 
147  cl::Kernel m_guass2K;
148 
160  QVector<int> m_sHost;
161 
165  QVector<int> m_qHost;
166 
170  QVector<double> m_oHost;
171 
175  cl::Buffer m_sDevice;
176 
180  cl::Buffer m_qDevice;
181 
185  cl::Buffer m_oDevice;
186 
193  int m_offset;
194 #endif // LANGMUIR_OPEN_CL
195 
196 };
197 }
198 
199 #endif // OPENCLHELPER_H
void copySiteAndChargeToHostVector(int index, int site, int charge=-1)
Does exactly what it says (host means the memory on the CPU)
double getOutputHostFuture(int index) const
Get the result stored in host memory (for future site)
void launchGaussKernel2()
Kernel2 calculates the coulomb potential with erf at current and future sites only.
World & m_world
Reference to World object.
Definition: openclhelper.h:106
A class to hold all objects in a simulation.
Definition: world.h:51
void compareHostAndDeviceForAllCarriers()
Compare GPU and CPU results.
void launchGaussKernel1()
Kernel1 calculates the coulomb potential with erf at every site.
double getOutputHost(int index) const
Get the result stored in host memory (for current site)
A class to run OpenCL calculations.
Definition: openclhelper.h:21
Definition: agent.h:12
void launchCoulombKernel1()
Kernel1 calculates the coulomb potential at every site.
OpenClHelper(World &world, QObject *parent=0)
Create THE OpenClHelper; don't make more than one.
bool toggleOpenCL(bool on)
Turn on/off OpenCL in a smart-way.
void initializeOpenCL(int gpuID=-1)
Perform the tedious boilerplate code to initialize OpenCL.
void launchCoulombKernel2()
Kernel2 calculates the coulomb potential at current and future sites only.