forked from unitaryfund/qrack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benn Bollay
committed
Feb 28, 2018
1 parent
76bcf0a
commit c7ddaa0
Showing
14 changed files
with
488 additions
and
3,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/doc/* | ||
*.o | ||
qrackcl.hpp | ||
qregistercl.hpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// (C) Daniel Strano 2017. All rights reserved. | ||
// | ||
// This is a header-only, quick-and-dirty, multithreaded, universal quantum register | ||
// simulation, allowing (nonphysical) register cloning and direct measurement of | ||
// probability and phase, to leverage what advantages classical emulation of qubits | ||
// can have. | ||
// | ||
// Licensed under the GNU General Public License V3. | ||
// See LICENSE.md in the project root or https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// for details. | ||
|
||
#include <iostream> | ||
|
||
#include "oclengine.hpp" | ||
|
||
#include "qregistercl.hpp" | ||
|
||
namespace Qrack { | ||
|
||
/// "Qrack::OCLEngine" manages the single OpenCL context | ||
|
||
// Public singleton methods to get pointers to various methods | ||
cl::Context* OCLEngine::GetContextPtr() { return &context; } | ||
cl::CommandQueue* OCLEngine::GetQueuePtr() { return &queue; } | ||
cl::Kernel* OCLEngine::GetApply2x2Ptr() { return &apply2x2; } | ||
cl::Kernel* OCLEngine::GetROLPtr() { return &rol; } | ||
cl::Kernel* OCLEngine::GetRORPtr() { return &ror; } | ||
cl::Kernel* OCLEngine::GetADDPtr() { return &add; } | ||
cl::Kernel* OCLEngine::GetSUBPtr() { return ⊂ } | ||
cl::Kernel* OCLEngine::GetADDCPtr() { return &addc; } | ||
cl::Kernel* OCLEngine::GetSUBCPtr() { return &subc; } | ||
|
||
OCLEngine::OCLEngine() { InitOCL(0, 0); } | ||
OCLEngine::OCLEngine(int plat, int dev) { InitOCL(plat, dev); } | ||
OCLEngine::OCLEngine(OCLEngine const&) {} | ||
OCLEngine& OCLEngine::operator=(OCLEngine const& rhs) { return *this; } | ||
|
||
void OCLEngine::InitOCL(int plat, int dev) | ||
{ | ||
// get all platforms (drivers), e.g. NVIDIA | ||
|
||
cl::Platform::get(&all_platforms); | ||
|
||
if (all_platforms.size() == 0) { | ||
std::cout << " No platforms found. Check OpenCL installation!\n"; | ||
exit(1); | ||
} | ||
default_platform = all_platforms[plat]; | ||
std::cout << "Using platform: " << default_platform.getInfo<CL_PLATFORM_NAME>() << "\n"; | ||
|
||
// get default device (CPUs, GPUs) of the default platform | ||
default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices); | ||
if (all_devices.size() == 0) { | ||
std::cout << " No devices found. Check OpenCL installation!\n"; | ||
exit(1); | ||
} | ||
|
||
// use device[1] because that's a GPU; device[0] is the CPU | ||
default_device = all_devices[dev]; | ||
std::cout << "Using device: " << default_device.getInfo<CL_DEVICE_NAME>() << "\n"; | ||
|
||
// a context is like a "runtime link" to the device and platform; | ||
// i.e. communication is possible | ||
context = cl::Context({ default_device }); | ||
|
||
// create the program that we want to execute on the device | ||
cl::Program::Sources sources; | ||
|
||
sources.push_back({ (const char*)qregister_cl, (long unsigned int)qregister_cl_len }); | ||
|
||
program = cl::Program(context, sources); | ||
if (program.build({ default_device }) != CL_SUCCESS) { | ||
std::cout << "Error building: " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(default_device) << std::endl; | ||
exit(1); | ||
} | ||
|
||
queue = cl::CommandQueue(context, default_device); | ||
apply2x2 = cl::Kernel(program, "apply2x2"); | ||
rol = cl::Kernel(program, "rol"); | ||
ror = cl::Kernel(program, "ror"); | ||
add = cl::Kernel(program, "add"); | ||
sub = cl::Kernel(program, "sub"); | ||
addc = cl::Kernel(program, "addc"); | ||
subc = cl::Kernel(program, "subc"); | ||
} | ||
|
||
OCLEngine* OCLEngine::m_pInstance = NULL; | ||
OCLEngine* OCLEngine::Instance() | ||
{ | ||
if (!m_pInstance) | ||
m_pInstance = new OCLEngine(); | ||
return m_pInstance; | ||
} | ||
|
||
OCLEngine* OCLEngine::Instance(int plat, int dev) | ||
{ | ||
if (!m_pInstance) { | ||
m_pInstance = new OCLEngine(plat, dev); | ||
} else { | ||
std::cout << "Warning: Tried to reinitialize OpenCL environment with platform and device." << std::endl; | ||
} | ||
return m_pInstance; | ||
} | ||
|
||
} // namespace Qrack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.