Qrack  1.7
General classical-emulating-quantum development framework
oclengine.hpp
Go to the documentation of this file.
1 //
3 // (C) Daniel Strano 2017, 2018. All rights reserved.
4 //
5 // This is a multithreaded, universal quantum register simulation, allowing
6 // (nonphysical) register cloning and direct measurement of probability and
7 // phase, to leverage what advantages classical emulation of qubits can have.
8 //
9 // Licensed under the GNU General Public License V3.
10 // See LICENSE.md in the project root or https://www.gnu.org/licenses/gpl-3.0.en.html
11 // for details.
12 
13 #pragma once
14 
15 #if !ENABLE_OPENCL
16 #error OpenCL has not been enabled
17 #endif
18 
19 #ifdef __APPLE__
20 #include <OpenCL/cl.hpp>
21 #else
22 #include <CL/cl.hpp>
23 #endif
24 
25 namespace Qrack {
26 
28 class OCLEngine {
29 public:
31  static OCLEngine* Instance();
33  static OCLEngine* Instance(int plat, int dev);
35  cl::Context* GetContextPtr();
37  cl::CommandQueue* GetQueuePtr();
39  cl::Kernel* GetApply2x2Ptr();
41  cl::Kernel* GetApply2x2NormPtr();
43  cl::Kernel* GetXPtr();
45  cl::Kernel* GetSwapPtr();
47  cl::Kernel* GetROLPtr();
49  cl::Kernel* GetRORPtr();
51  cl::Kernel* GetINCPtr();
53  cl::Kernel* GetDECPtr();
55  cl::Kernel* GetINCCPtr();
57  cl::Kernel* GetDECCPtr();
59  cl::Kernel* GetLDAPtr();
61  cl::Kernel* GetADCPtr();
63  cl::Kernel* GetSBCPtr();
64 
65 private:
66  std::vector<cl::Platform> all_platforms;
67  cl::Platform default_platform;
68  std::vector<cl::Device> all_devices;
69  cl::Device default_device;
70  cl::Context context;
71  cl::Program program;
72  cl::CommandQueue queue;
73  cl::Kernel apply2x2;
74  cl::Kernel apply2x2norm;
75  cl::Kernel x;
76  cl::Kernel swap;
77  cl::Kernel rol;
78  cl::Kernel ror;
79  cl::Kernel inc;
80  cl::Kernel dec;
81  cl::Kernel incc;
82  cl::Kernel decc;
83  cl::Kernel indexedLda;
84  cl::Kernel indexedAdc;
85  cl::Kernel indexedSbc;
86 
87  OCLEngine(); // Private so that it can not be called
88  OCLEngine(int plat, int dev); // Private so that it can not be called
89  OCLEngine(OCLEngine const&); // copy constructor is private
90  OCLEngine& operator=(OCLEngine const& rhs); // assignment operator is private
92 
93  void InitOCL(int plat, int dev);
94 };
95 
96 } // namespace Qrack
std::vector< cl::Platform > all_platforms
Definition: oclengine.hpp:66
cl::Kernel swap
Definition: oclengine.hpp:76
cl::Kernel * GetROLPtr()
Get a pointer to the ROL function kernel.
Definition: oclengine.cpp:29
OCLEngine()
Definition: oclengine.cpp:39
cl::Kernel inc
Definition: oclengine.hpp:79
static OCLEngine * Instance()
Get a pointer to the Instance of the singleton. (The instance will be instantiated, if it does not exist yet.)
Definition: oclengine.cpp:100
cl::Kernel indexedSbc
Definition: oclengine.hpp:85
cl::Kernel * GetSwapPtr()
Get a pointer to the Swap function kernel.
Definition: oclengine.cpp:28
cl::Platform default_platform
Definition: oclengine.hpp:67
cl::Kernel * GetRORPtr()
Get a pointer to the ROR function kernel.
Definition: oclengine.cpp:30
cl::Kernel * GetLDAPtr()
Get a pointer to the IndexedLDA function kernel.
Definition: oclengine.cpp:35
static OCLEngine * m_pInstance
Definition: oclengine.hpp:91
cl::Program program
Definition: oclengine.hpp:71
std::vector< cl::Device > all_devices
Definition: oclengine.hpp:68
cl::Kernel * GetApply2x2NormPtr()
Get a pointer to the Apply2x2Norm function kernel.
Definition: oclengine.cpp:26
cl::Kernel * GetINCCPtr()
Get a pointer to the INCC function kernel.
Definition: oclengine.cpp:33
cl::CommandQueue * GetQueuePtr()
Get a pointer to the OpenCL queue.
Definition: oclengine.cpp:24
cl::Kernel decc
Definition: oclengine.hpp:82
cl::Kernel * GetApply2x2Ptr()
Get a pointer to the Apply2x2 function kernel.
Definition: oclengine.cpp:25
cl::Kernel indexedLda
Definition: oclengine.hpp:83
cl::Device default_device
Definition: oclengine.hpp:69
OCLEngine & operator=(OCLEngine const &rhs)
Definition: oclengine.cpp:42
cl::Kernel apply2x2
Definition: oclengine.hpp:73
cl::Kernel ror
Definition: oclengine.hpp:78
cl::CommandQueue queue
Definition: oclengine.hpp:72
cl::Kernel apply2x2norm
Definition: oclengine.hpp:74
cl::Kernel * GetDECPtr()
Get a pointer to the DEC function kernel.
Definition: oclengine.cpp:32
cl::Kernel rol
Definition: oclengine.hpp:77
cl::Kernel * GetADCPtr()
Get a pointer to the IndexedADC function kernel.
Definition: oclengine.cpp:36
void InitOCL(int plat, int dev)
Definition: oclengine.cpp:44
cl::Kernel * GetXPtr()
Get a pointer to the X function kernel.
Definition: oclengine.cpp:27
cl::Kernel * GetINCPtr()
Get a pointer to the INC function kernel.
Definition: oclengine.cpp:31
cl::Kernel incc
Definition: oclengine.hpp:81
"Qrack::OCLEngine" manages the single OpenCL context.
Definition: oclengine.hpp:28
cl::Context context
Definition: oclengine.hpp:70
cl::Kernel indexedAdc
Definition: oclengine.hpp:84
cl::Kernel x
Definition: oclengine.hpp:75
cl::Kernel * GetSBCPtr()
Get a pointer to the IndexedSBC function kernel.
Definition: oclengine.cpp:37
cl::Context * GetContextPtr()
Get a pointer to the OpenCL context.
Definition: oclengine.cpp:23
cl::Kernel * GetDECCPtr()
Get a pointer to the DECC function kernel.
Definition: oclengine.cpp:34
cl::Kernel dec
Definition: oclengine.hpp:80
Definition: complex16simd.hpp:21