Qrack  9.0
General classical-emulating-quantum development framework
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Qrack::OCLEngine Class Reference

"Qrack::OCLEngine" manages the single OpenCL context. More...

#include <oclengine.hpp>

Public Member Functions

DeviceContextPtr GetDeviceContextPtr (const int64_t &dev=-1)
 Get a pointer one of the available OpenCL contexts, by its index in the list of all contexts. More...
 
std::vector< DeviceContextPtrGetDeviceContextPtrVector ()
 Get the list of all available devices (and their supporting objects). More...
 
void SetDeviceContextPtrVector (std::vector< DeviceContextPtr > vec, DeviceContextPtr dcp=nullptr)
 Set the list of DeviceContextPtr object available for use. More...
 
int GetDeviceCount ()
 Get the count of devices in the current list. More...
 
size_t GetDefaultDeviceID ()
 Get default device ID. More...
 
void SetDefaultDeviceContext (DeviceContextPtr dcp)
 Pick a default device, for QEngineOCL instances that don't specify a preferred device. More...
 
size_t GetActiveAllocSize (const int64_t &dev)
 
size_t AddToActiveAllocSize (const int64_t &dev, size_t size)
 
size_t SubtractFromActiveAllocSize (const int64_t &dev, size_t size)
 
void ResetActiveAllocSize (const int64_t &dev)
 
 OCLEngine (OCLEngine const &)=delete
 
void operator= (OCLEngine const &)=delete
 

Static Public Member Functions

static OCLEngineInstance ()
 Get a pointer to the Instance of the singleton. (The instance will be instantiated, if it does not exist yet.) More...
 
static std::string GetDefaultBinaryPath ()
 Get default location for precompiled binaries: More...
 
static InitOClResult InitOCL (bool buildFromSource=false, bool saveBinaries=false, std::string home="*", std::vector< int64_t > maxAllocVec={ -1 })
 Initialize the OCL environment, with the option to save the generated binaries. More...
 

Private Member Functions

 OCLEngine ()
 

Static Private Member Functions

static cl::Program MakeProgram (bool buildFromSource, std::string path, std::shared_ptr< OCLDeviceContext > devCntxt)
 Make the program, from either source or binary. More...
 
static void SaveBinary (cl::Program program, std::string path, std::string fileName)
 Save the program binary: More...
 

Private Attributes

std::vector< size_t > activeAllocSizes
 
std::vector< int64_t > maxActiveAllocSizes
 
std::mutex allocMutex
 
std::vector< DeviceContextPtrall_device_contexts
 
DeviceContextPtr default_device_context
 

Static Private Attributes

static const std::vector< OCLKernelHandlekernelHandles
 
static const std::string binary_file_prefix
 
static const std::string binary_file_ext
 

Detailed Description

"Qrack::OCLEngine" manages the single OpenCL context.

Constructor & Destructor Documentation

◆ OCLEngine() [1/2]

Qrack::OCLEngine::OCLEngine ( OCLEngine const &  )
delete

◆ OCLEngine() [2/2]

Qrack::OCLEngine::OCLEngine ( )
private

Member Function Documentation

◆ AddToActiveAllocSize()

size_t Qrack::OCLEngine::AddToActiveAllocSize ( const int64_t &  dev,
size_t  size 
)
inline

◆ GetActiveAllocSize()

size_t Qrack::OCLEngine::GetActiveAllocSize ( const int64_t &  dev)
inline

◆ GetDefaultBinaryPath()

static std::string Qrack::OCLEngine::GetDefaultBinaryPath ( )
inlinestatic

Get default location for precompiled binaries:

◆ GetDefaultDeviceID()

size_t Qrack::OCLEngine::GetDefaultDeviceID ( )
inline

Get default device ID.

◆ GetDeviceContextPtr()

DeviceContextPtr Qrack::OCLEngine::GetDeviceContextPtr ( const int64_t &  dev = -1)

Get a pointer one of the available OpenCL contexts, by its index in the list of all contexts.

"Qrack::OCLEngine" manages the single OpenCL context

◆ GetDeviceContextPtrVector()

std::vector< DeviceContextPtr > Qrack::OCLEngine::GetDeviceContextPtrVector ( )

Get the list of all available devices (and their supporting objects).

◆ GetDeviceCount()

int Qrack::OCLEngine::GetDeviceCount ( )
inline

Get the count of devices in the current list.

◆ InitOCL()

InitOClResult Qrack::OCLEngine::InitOCL ( bool  buildFromSource = false,
bool  saveBinaries = false,
std::string  home = "*",
std::vector< int64_t >  maxAllocVec = { -1 } 
)
static

Initialize the OCL environment, with the option to save the generated binaries.

Binaries will be saved/loaded from the folder path "home". This returns a Qrack::OCLInitResult object which should be passed to SetDeviceContextPtrVector().

◆ Instance()

static OCLEngine& Qrack::OCLEngine::Instance ( )
inlinestatic

Get a pointer to the Instance of the singleton. (The instance will be instantiated, if it does not exist yet.)

◆ MakeProgram()

cl::Program Qrack::OCLEngine::MakeProgram ( bool  buildFromSource,
std::string  path,
std::shared_ptr< OCLDeviceContext devCntxt 
)
staticprivate

Make the program, from either source or binary.

◆ operator=()

void Qrack::OCLEngine::operator= ( OCLEngine const &  )
delete

◆ ResetActiveAllocSize()

void Qrack::OCLEngine::ResetActiveAllocSize ( const int64_t &  dev)
inline

◆ SaveBinary()

void Qrack::OCLEngine::SaveBinary ( cl::Program  program,
std::string  path,
std::string  fileName 
)
staticprivate

Save the program binary:

◆ SetDefaultDeviceContext()

void Qrack::OCLEngine::SetDefaultDeviceContext ( DeviceContextPtr  dcp)

Pick a default device, for QEngineOCL instances that don't specify a preferred device.

◆ SetDeviceContextPtrVector()

void Qrack::OCLEngine::SetDeviceContextPtrVector ( std::vector< DeviceContextPtr vec,
DeviceContextPtr  dcp = nullptr 
)

Set the list of DeviceContextPtr object available for use.

If one takes the result of GetDeviceContextPtrVector(), trims items from it, and sets it with this method, (at initialization, before any QEngine objects depend on them,) all resources associated with the removed items are freed.

◆ SubtractFromActiveAllocSize()

size_t Qrack::OCLEngine::SubtractFromActiveAllocSize ( const int64_t &  dev,
size_t  size 
)
inline

Member Data Documentation

◆ activeAllocSizes

std::vector<size_t> Qrack::OCLEngine::activeAllocSizes
private

◆ all_device_contexts

std::vector<DeviceContextPtr> Qrack::OCLEngine::all_device_contexts
private

◆ allocMutex

std::mutex Qrack::OCLEngine::allocMutex
private

◆ binary_file_ext

const std::string Qrack::OCLEngine::binary_file_ext
staticprivate

◆ binary_file_prefix

const std::string Qrack::OCLEngine::binary_file_prefix
staticprivate

◆ default_device_context

DeviceContextPtr Qrack::OCLEngine::default_device_context
private

◆ kernelHandles

const std::vector< OCLKernelHandle > Qrack::OCLEngine::kernelHandles
staticprivate

◆ maxActiveAllocSizes

std::vector<int64_t> Qrack::OCLEngine::maxActiveAllocSizes
private

The documentation for this class was generated from the following files: