20 #error OpenCL has not been enabled
26 #define BCI_ARG_LEN 10
27 #define CMPLX_NORM_LEN 6
28 #define REAL_ARG_LEN 2
32 typedef std::shared_ptr<cl::Buffer>
BufferPtr;
63 QueueItem(
OCLAPI ac,
size_t wic,
size_t lgs,
size_t ds, std::vector<BufferPtr> b,
size_t lbs)
131 if (error != CL_SUCCESS) {
132 if (error == CL_MEM_OBJECT_ALLOCATION_FAILURE) {
133 throw bad_alloc(
"CL_MEM_OBJECT_ALLOCATION_FAILURE in PoolItem::MakeBuffer()");
135 if (error == CL_OUT_OF_HOST_MEMORY) {
136 throw bad_alloc(
"CL_OUT_OF_HOST_MEMORY in PoolItem::MakeBuffer()");
138 if (error == CL_INVALID_BUFFER_SIZE) {
139 throw bad_alloc(
"CL_INVALID_BUFFER_SIZE in PoolItem::MakeBuffer()");
141 throw std::runtime_error(
"OpenCL error code on buffer allocation attempt: " + std::to_string(error));
194 #if defined(__APPLE__)
199 return (
real1*)toRet;
212 throw std::runtime_error(
"Failed to enqueue kernel, error code: " + std::to_string(
callbackError));
216 void tryOcl(std::string message, std::function<
int()> oclCall)
220 if (oclCall() == CL_SUCCESS) {
228 if (oclCall() == CL_SUCCESS) {
236 cl_int error = oclCall();
237 if (error == CL_SUCCESS) {
246 throw std::runtime_error(message +
", error code: " + std::to_string(error));
274 bool useHostMem =
false, int64_t devID = -1,
bool useHardwareRNG =
true,
bool ignored =
false,
313 tryOcl(
"Failed to write buffer", [&] {
314 return queue.enqueueWriteBuffer(
352 void QueueCall(
OCLAPI api_call,
size_t workItemCount,
size_t localGroupSize, std::vector<BufferPtr> args,
353 size_t localBuffSize = 0
U,
size_t deallocSize = 0
U)
356 throw bad_alloc(
"Local memory limits exceeded in QEngineOCL::QueueCall()");
367 const complex* mtrxs,
const std::vector<bitCapInt>& mtrxSkipPowers,
bitCapInt mtrxSkipValueMask);
389 return Compose(std::dynamic_pointer_cast<QEngineOCL>(toCopy), start);
413 const std::vector<bitLenInt>& controls);
415 const std::vector<bitLenInt>& controls);
417 const std::vector<bitLenInt>& controls);
419 const std::vector<bitLenInt>& controls);
421 const std::vector<bitLenInt>& controls);
426 const unsigned char* values,
bool resetValue =
true);
428 bitLenInt carryIndex,
const unsigned char* values);
430 bitLenInt carryIndex,
const unsigned char* values);
478 throw bad_alloc(
"VRAM limits exceeded in QEngineOCL::AddAlloc()");
493 BufferPtr toRet = std::make_shared<cl::Buffer>(
context, flags, size, host_ptr, &error);
494 if (error == CL_SUCCESS) {
502 toRet = std::make_shared<cl::Buffer>(
context, flags, size, host_ptr, &error);
503 if (error == CL_SUCCESS) {
511 toRet = std::make_shared<cl::Buffer>(
context, flags, size, host_ptr, &error);
512 if (error != CL_SUCCESS) {
513 if (error == CL_MEM_OBJECT_ALLOCATION_FAILURE) {
514 throw bad_alloc(
"CL_MEM_OBJECT_ALLOCATION_FAILURE in QEngineOCL::MakeBuffer()");
516 if (error == CL_OUT_OF_HOST_MEMORY) {
517 throw bad_alloc(
"CL_OUT_OF_HOST_MEMORY in QEngineOCL::MakeBuffer()");
519 if (error == CL_INVALID_BUFFER_SIZE) {
520 throw bad_alloc(
"CL_INVALID_BUFFER_SIZE in QEngineOCL::MakeBuffer()");
522 throw std::runtime_error(
"OpenCL error code on buffer allocation attempt: " + std::to_string(error));
596 return gs - (wic % gs);
617 void WaitCall(
OCLAPI api_call,
size_t workItemCount,
size_t localGroupSize, std::vector<BufferPtr> args,
618 size_t localBuffSize = 0
U);
655 const std::vector<bitLenInt>& controls);
657 bitLenInt length,
const std::vector<bitLenInt>& controls);
size_t AddToActiveAllocSize(const int64_t &dev, size_t size)
Definition: oclengine.hpp:305
size_t SubtractFromActiveAllocSize(const int64_t &dev, size_t size)
Definition: oclengine.hpp:322
static OCLEngine & Instance()
Get a pointer to the Instance of the singleton. (The instance will be instantiated,...
Definition: oclengine.hpp:248
BufferPtr ulongBuffer
Definition: qengine_cuda.hpp:123
~PoolItem()
Definition: qengine_opencl.hpp:124
BufferPtr cmplxBuffer
Definition: qengine_cuda.hpp:121
BufferPtr MakeBuffer(size_t size)
Definition: qengine_cuda.hpp:140
BufferPtr realBuffer
Definition: qengine_cuda.hpp:122
std::shared_ptr< real1 > angleArray
Definition: qengine_cuda.hpp:126
BufferPtr MakeBuffer(const cl::Context &context, size_t size)
Definition: qengine_opencl.hpp:127
PoolItem(cl::Context &context)
Definition: qengine_opencl.hpp:115
std::shared_ptr< real1 > probArray
Definition: qengine_cuda.hpp:125
OpenCL enhanced QEngineCPU implementation.
Definition: qengine_opencl.hpp:168
void SetQuantumState(const complex *inputState)
Set arbitrary pure quantum state, in unsigned int permutation basis.
Definition: opencl.cpp:2913
virtual void Apply2x2(bitCapIntOcl offset1, bitCapIntOcl offset2, complex const *mtrx, bitLenInt bitCount, bitCapIntOcl const *qPowersSorted, bool doCalcNorm, real1_f norm_thresh=REAL1_DEFAULT_ARG)=0
cl::Context context
Definition: qengine_opencl.hpp:183
void GetProbs(real1 *outputProbs)
Get all probabilities, in unsigned int permutation basis.
Definition: opencl.cpp:3043
real1_f GetExpectation(bitLenInt valueStart, bitLenInt valueLength)
Definition: opencl.cpp:1982
void INCDECBCDC(bitCapInt toMod, bitLenInt inOutStart, bitLenInt length, bitLenInt carryIndex)
Increment integer (BCD, with carry)
Definition: opencl.cpp:2398
void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubitIndex, const complex *mtrxs, const std::vector< bitCapInt > &mtrxSkipPowers, bitCapInt mtrxSkipValueMask)
Definition: opencl.cpp:1029
void CMUL(bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication by integer.
Definition: opencl.cpp:2498
void IFullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
Inverse of FullAdd.
Definition: opencl.cpp:2468
QEnginePtr CloneEmpty()
Clone this QEngine's settings, with a zeroed state vector.
Definition: opencl.cpp:3155
void checkCallbackError()
Definition: qengine_opencl.hpp:203
void INTBCDC(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt length, bitLenInt carryIndex)
Add or Subtract integer (BCD, with carry)
Definition: opencl.cpp:2363
void FullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
Quantum analog of classical "Full Adder" gate.
Definition: opencl.cpp:2462
size_t nrmGroupSize
Definition: qengine_opencl.hpp:175
void ArithmeticCall(OCLAPI api_call, const bitCapIntOcl(&bciArgs)[BCI_ARG_LEN], const unsigned char *values=NULL, bitCapIntOcl valuesLength=0U)
Definition: opencl.cpp:2002
int64_t GetDevice()
Get GPU device ID.
Definition: qengine_opencl.hpp:448
std::unique_ptr< real1[], void(*)(real1 *)> nrmArray
Definition: qengine_opencl.hpp:192
std::shared_ptr< complex > AllocStateVec(bitCapInt elemCount, bool doForceAlloc=false)
Definition: opencl.cpp:3270
bool usingHostRam
Definition: qengine_opencl.hpp:171
void CMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication modulo N by integer, (out of place)
Definition: opencl.cpp:2540
void INCDECC(bitCapInt toMod, bitLenInt inOutStart, bitLenInt length, bitLenInt carryIndex)
Common driver method behing INCC and DECC.
Definition: opencl.cpp:2212
void AddQueueItem(const QueueItem &item)
Definition: qengine_opencl.hpp:337
size_t FixWorkItemCount(size_t maxI, size_t wic)
Definition: qengine_opencl.hpp:579
void UpdateRunningNorm(real1_f norm_thresh=REAL1_DEFAULT_ARG)
Force a calculation of the norm of the state vector, in order to make it unit length before the next ...
Definition: opencl.cpp:3223
void FullAdx(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut, OCLAPI api_call)
Definition: opencl.cpp:2473
std::list< QueueItem > wait_queue_items
Definition: qengine_opencl.hpp:190
DeviceContextPtr device_context
Definition: qengine_opencl.hpp:188
size_t nrmGroupCount
Definition: qengine_opencl.hpp:174
void ClearBuffer(BufferPtr buff, bitCapIntOcl offset, bitCapIntOcl size)
Definition: opencl.cpp:3316
std::vector< EventVecPtr > wait_refs
Definition: qengine_opencl.hpp:189
bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qengine_opencl.hpp:385
void POWModNOut(bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Raise a classical base to a quantum power, modulo N, (out of place)
Definition: opencl.cpp:2449
void UniformParityRZ(bitCapInt mask, real1_f angle)
If the target qubit set parity is odd, this applies a phase factor of .
Definition: opencl.cpp:1098
bool unlockHostMem
Definition: qengine_opencl.hpp:172
void ProbMaskAll(bitCapInt mask, real1 *probsArray)
Direct measure of masked permutation probability.
Definition: opencl.cpp:1807
void SwitchHostPtr(bool useHostMem)
Switch to/from host/device state vector bufffer.
Definition: qengine_opencl.hpp:298
void CINT(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt start, bitLenInt length, const std::vector< bitLenInt > &controls)
Add or Subtract integer (without sign or carry, with controls)
Definition: opencl.cpp:2127
void INTS(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt length, bitLenInt overflowIndex)
Add or Subtract integer (with overflow, without carry)
Definition: opencl.cpp:2218
void MUL(bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Multiply by integer.
Definition: opencl.cpp:2405
void SetAmplitude(bitCapInt perm, complex amp)
Sets the representational amplitude of a full permutation.
Definition: opencl.cpp:2996
size_t totalOclAllocSize
Definition: qengine_opencl.hpp:176
bitCapInt IndexedLDA(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, const unsigned char *values, bool resetValue=true)
Set 8 bit register bits based on read from classical memory.
Definition: opencl.cpp:2757
void INCBCD(bitCapInt toAdd, bitLenInt start, bitLenInt length)
Increment integer (BCD)
Definition: opencl.cpp:2357
void ResetStateBuffer(BufferPtr nStateBuffer)
Definition: opencl.cpp:658
void ROL(bitLenInt shift, bitLenInt start, bitLenInt length)
"Circular shift left" - shift bits left, and carry last bits.
Definition: opencl.cpp:2097
real1_f CtrlOrAntiProb(bool controlState, bitLenInt control, bitLenInt target)
Definition: opencl.cpp:1671
void WaitCall(OCLAPI api_call, size_t workItemCount, size_t localGroupSize, std::vector< BufferPtr > args, size_t localBuffSize=0U)
Definition: opencl.cpp:404
void CPhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length, bitLenInt flagIndex)
The 6502 uses its carry flag also as a greater-than/less-than flag, for the CMP operation.
Definition: opencl.cpp:2883
PoolItemPtr GetFreePoolItem()
Definition: opencl.cpp:374
void Phase(complex topLeft, complex bottomRight, bitLenInt qubitIndex)
Apply a single bit transformation that only effects phase.
Definition: opencl.cpp:717
real1_f SumSqrDiff(QInterfacePtr toCompare)
Definition: qengine_opencl.hpp:457
void SetAmplitudePage(const complex *pagePtr, bitCapIntOcl offset, bitCapIntOcl length)
Copy a "page" of amplitudes from pagePtr into this QEngine's internal state.
Definition: opencl.cpp:153
void clDump()
Dumps the remaining asynchronous wait event list or queue of OpenCL events, for the current queue.
Definition: opencl.cpp:354
void ZeroAmplitudes()
Set all amplitudes to 0, and optionally temporarily deallocate state vector RAM.
Definition: opencl.cpp:99
void MULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: opencl.cpp:2432
void InitOCL(int64_t devID)
Definition: opencl.cpp:656
bool ForceMParity(bitCapInt mask, bool result, bool doForce=true)
Act as if is a measurement of parity of the masked set of qubits was applied, except force the (usual...
Definition: opencl.cpp:1913
std::mutex queue_mutex
Definition: qengine_opencl.hpp:181
void DIV(bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Divide by integer.
Definition: opencl.cpp:2422
void BitMask(bitCapIntOcl mask, OCLAPI api_call, real1_f phase=(real1_f) PI_R1)
Definition: opencl.cpp:988
void MULx(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Definition: opencl.cpp:2622
void NormalizeState(real1_f nrm=REAL1_DEFAULT_ARG, real1_f norm_thresh=REAL1_DEFAULT_ARG, real1_f phaseArg=ZERO_R1_F)
Apply the normalization factor found by UpdateRunningNorm() or on the fly by a single bit gate.
Definition: opencl.cpp:3165
void INCS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Increment integer (without sign, with carry)
Definition: opencl.cpp:2249
void INCDECSC(bitCapInt toMod, bitLenInt inOutStart, bitLenInt length, bitLenInt carryIndex)
Increment integer (with sign, with carry)
Definition: opencl.cpp:2320
void QueueCall(OCLAPI api_call, size_t workItemCount, size_t localGroupSize, std::vector< BufferPtr > args, size_t localBuffSize=0U, size_t deallocSize=0U)
Definition: qengine_opencl.hpp:352
void CMULModx(OCLAPI api_call, bitCapIntOcl toMod, bitCapIntOcl modN, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Definition: opencl.cpp:2714
void INT(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt length)
Add or Subtract integer (without sign or carry)
Definition: opencl.cpp:2101
cl_int callbackError
Definition: qengine_opencl.hpp:173
void CMULx(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Definition: opencl.cpp:2670
bitCapInt IndexedSBC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, const unsigned char *values)
Subtract based on an indexed load from classical memory.
Definition: opencl.cpp:2847
void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qengine_opencl.hpp:464
cl_map_flags lockSyncFlags
Definition: qengine_opencl.hpp:178
void CopyStateVec(QEnginePtr src)
Exactly copy the state vector of a different QEngine instance.
Definition: opencl.cpp:114
void MULModx(OCLAPI api_call, bitCapIntOcl toMod, bitCapIntOcl modN, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Definition: opencl.cpp:2643
std::shared_ptr< complex > stateVec
Definition: qengine_opencl.hpp:180
void Hash(bitLenInt start, bitLenInt length, const unsigned char *values)
Set 8 bit register bits based on read from classical memory.
Definition: opencl.cpp:2854
void clFinish(bool doHard=false)
Finishes the asynchronous wait event list or queue of OpenCL events.
Definition: opencl.cpp:330
QInterfacePtr Clone()
Clone this QInterface.
Definition: opencl.cpp:3130
void PhaseFlipX(OCLAPI api_call, const bitCapIntOcl *bciArgs)
Definition: opencl.cpp:2863
void CPOWModNOut(bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication modulo N by integer, (out of place)
Definition: opencl.cpp:2579
void Z(bitLenInt target)
Apply Pauli Z matrix to bit.
Definition: opencl.cpp:698
void AddAlloc(size_t size)
Definition: qengine_opencl.hpp:473
void INC(bitCapInt toAdd, bitLenInt start, bitLenInt length)
Increment integer (without sign, with carry)
Definition: opencl.cpp:2165
BufferPtr MakeBuffer(cl_mem_flags flags, size_t size, void *host_ptr=NULL)
Definition: qengine_opencl.hpp:488
void ApplyMx(OCLAPI api_call, const bitCapIntOcl *bciArgs, complex nrm)
Definition: opencl.cpp:1184
void INTC(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt length, bitLenInt carryIndex)
Add or Subtract integer (without sign, with carry)
Definition: opencl.cpp:2181
real1_f ExpectationBitsAll(const std::vector< bitLenInt > &bits, bitCapInt offset=0)
Get permutation expectation value of bits.
Definition: opencl.cpp:1944
void ProbRegAll(bitLenInt start, bitLenInt length, real1 *probsArray)
Definition: opencl.cpp:1719
bitCapIntOcl GetMaxSize()
Definition: qengine_opencl.hpp:361
void CDIV(bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled division by integer.
Definition: opencl.cpp:2520
size_t FixGroupSize(size_t wic, size_t gs)
Definition: qengine_opencl.hpp:590
void SubtractAlloc(size_t size)
Definition: qengine_opencl.hpp:482
void ReinitBuffer()
Definition: opencl.cpp:3309
void FreeAll()
Definition: opencl.cpp:89
void GetQuantumState(complex *outputState)
Get pure quantum state, in unsigned int permutation basis.
Definition: opencl.cpp:3027
real1_f ProbMask(bitCapInt mask, bitCapInt permutation)
Direct measure of masked permutation probability.
Definition: opencl.cpp:1757
void ROx(OCLAPI api_call, bitLenInt shift, bitLenInt start, bitLenInt length)
Definition: opencl.cpp:2072
void Apply2x2(bitCapIntOcl offset1, bitCapIntOcl offset2, const complex *mtrx, bitLenInt bitCount, const bitCapIntOcl *qPowersSorted, bool doCalcNorm, real1_f norm_thresh=REAL1_DEFAULT_ARG)
Definition: qengine_opencl.hpp:602
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Definition: qengine.hpp:270
cl::CommandQueue queue
Definition: qengine_opencl.hpp:182
void PhaseParity(real1_f radians, bitCapInt mask)
Parity phase gate.
Definition: opencl.cpp:747
void tryOcl(std::string message, std::function< int()> oclCall)
Definition: qengine_opencl.hpp:216
void QueueSetRunningNorm(real1_f runningNrm)
Add an operation to the (OpenCL) queue, to set the value of runningNorm, which is the normalization c...
Definition: qengine_opencl.hpp:336
void IMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Inverse of multiplication modulo N by integer, (out of place)
Definition: opencl.cpp:2441
void QueueSetDoNormalize(bool doNorm)
Add an operation to the (OpenCL) queue, to set the value of doNormalize, which controls whether to au...
Definition: qengine_opencl.hpp:335
bool IsZeroAmplitude()
Returns "true" only if amplitudes are all totally 0.
Definition: qengine_opencl.hpp:288
bitLenInt Compose(QEngineOCLPtr toCopy)
Definition: opencl.cpp:1329
BufferPtr stateBuffer
Definition: qengine_opencl.hpp:186
bitCapIntOcl OpIndexed(OCLAPI api_call, bitCapIntOcl carryIn, bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, const unsigned char *values)
Add or Subtract based on an indexed load from classical memory.
Definition: opencl.cpp:2791
void Invert(complex topRight, complex bottomLeft, bitLenInt qubitIndex)
Apply a single bit transformation that reverses bit probability and might effect phase.
Definition: opencl.cpp:705
void PopQueue(bool isDispatch)
Definition: opencl.cpp:413
real1_f ProbReg(bitLenInt start, bitLenInt length, bitCapInt permutation)
Direct measure of register permutation probability.
Definition: opencl.cpp:1706
void UnlockSync()
Unlocks synchronization between the state vector buffer and general RAM, so the state vector can be o...
Definition: opencl.cpp:310
EventVecPtr ResetWaitEvents(bool waitQueue=true)
Definition: opencl.cpp:387
void DispatchQueue()
Definition: opencl.cpp:446
bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start)
Definition: qengine_opencl.hpp:387
void SetPermutation(bitCapInt perm, complex phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: opencl.cpp:660
void SetDevice(int64_t dID)
Set GPU device ID.
Definition: opencl.cpp:523
bool didInit
Definition: qengine_opencl.hpp:170
void xMULx(OCLAPI api_call, const bitCapIntOcl *bciArgs, BufferPtr controlBuffer)
Definition: opencl.cpp:2594
real1_f ParSum(real1 *toSum, bitCapIntOcl maxI)
Definition: opencl.cpp:644
real1_f ProbParity(bitCapInt mask)
Overall probability of any odd permutation of the masked set of bits.
Definition: opencl.cpp:1892
complex GetAmplitude(bitCapInt perm)
Get the representational amplitude of a full permutation.
Definition: opencl.cpp:2978
bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qengine_opencl.hpp:465
void GetAmplitudePage(complex *pagePtr, bitCapIntOcl offset, bitCapIntOcl length)
Copy a "page" of amplitudes from this QEngine's internal state, into pagePtr.
Definition: opencl.cpp:138
real1_f Probx(OCLAPI api_call, const bitCapIntOcl *bciArgs)
Definition: opencl.cpp:1619
void Dispose(bitLenInt start, bitLenInt length)
Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separa...
Definition: opencl.cpp:1552
static const bitCapIntOcl OclMemDenom
1 / OclMemDenom is the maximum fraction of total OCL device RAM that a single state vector should occ...
Definition: qengine_opencl.hpp:252
int64_t deviceID
Definition: qengine_opencl.hpp:177
bitCapInt MAll()
Measure permutation state of all coherent bits.
Definition: opencl.cpp:2927
void ShuffleBuffers(QEnginePtr engine)
Swap the high half of this engine with the low half of another.
Definition: opencl.cpp:230
void CArithmeticCall(OCLAPI api_call, const bitCapIntOcl(&bciArgs)[BCI_ARG_LEN], bitCapIntOcl *controlPowers, bitLenInt controlLen, const unsigned char *values=NULL, bitCapIntOcl valuesLength=0U)
Definition: opencl.cpp:2007
void LockSync(cl_map_flags flags=(CL_MAP_READ|CL_MAP_WRITE))
Locks synchronization between the state vector buffer and general RAM, so the state vector can be dir...
Definition: opencl.cpp:287
void XMask(bitCapInt mask)
Masked X gate.
Definition: opencl.cpp:734
~QEngineOCL()
Definition: qengine_opencl.hpp:278
void ApplyM(bitCapInt mask, bool result, complex nrm)
Definition: opencl.cpp:1208
void CUniformParityRZ(const std::vector< bitLenInt > &controls, bitCapInt mask, real1_f angle)
If the controls are set and the target qubit set parity is odd, this applies a phase factor of .
Definition: opencl.cpp:1132
complex permutationAmp
Definition: qengine_opencl.hpp:179
BufferPtr nrmBuffer
Definition: qengine_opencl.hpp:187
bitCapInt IndexedADC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, const unsigned char *values)
Add based on an indexed load from classical memory.
Definition: opencl.cpp:2840
bitLenInt Allocate(bitLenInt start, bitLenInt length)
Allocate new "length" count of |0> state qubits at specified qubit index start position.
Definition: opencl.cpp:1608
void PhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length)
This is an expedient for an adaptive Grover's search for a function's global minimum.
Definition: opencl.cpp:2899
virtual bool isOpenCL()
Returns "true" if current simulation is OpenCL-based.
Definition: qengine_opencl.hpp:286
void CINC(bitCapInt toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: opencl.cpp:2170
std::vector< PoolItemPtr > poolItems
Definition: qengine_opencl.hpp:191
void FreeStateVec()
Definition: qengine_opencl.hpp:531
virtual void X(bitLenInt q)
Definition: qengine.hpp:183
void INTBCD(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt length)
Add or Subtract integer (BCD)
Definition: opencl.cpp:2327
void INTSC(OCLAPI api_call, bitCapIntOcl toMod, bitLenInt inOutStart, bitLenInt length, bitLenInt carryIndex)
Add or Subtract integer (with sign, with carry)
Definition: opencl.cpp:2299
QEngineOCL(bitLenInt qBitCount, bitCapInt initState, qrack_rand_gen_ptr rgp=nullptr, complex phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int64_t devID=-1, bool useHardwareRNG=true, bool ignored=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > ignored2={}, bitLenInt ignored4=0U, real1_f ignored3=FP_NORM_EPSILON_F)
Initialize a Qrack::QEngineOCL object.
Definition: opencl.cpp:67
BufferPtr MakeStateVecBuffer(std::shared_ptr< complex > nStateVec)
Definition: opencl.cpp:3296
real1_f FirstNonzeroPhase()
Get phase of lowest permutation nonzero amplitude.
Definition: qengine_opencl.hpp:289
void CIMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Inverse of controlled multiplication modulo N by integer, (out of place)
Definition: opencl.cpp:2561
void DecomposeDispose(bitLenInt start, bitLenInt length, QEngineOCLPtr dest)
Definition: opencl.cpp:1374
real1_f Prob(bitLenInt qubit)
PSEUDO-QUANTUM Direct measure of bit probability to be in |1> state.
Definition: opencl.cpp:1650
Abstract QEngine implementation, for all "Schroedinger method" engines.
Definition: qengine.hpp:31
virtual void Apply2x2(bitCapIntOcl offset1, bitCapIntOcl offset2, complex const *mtrx, bitLenInt bitCount, bitCapIntOcl const *qPowersSorted, bool doCalcNorm, real1_f norm_thresh=REAL1_DEFAULT_ARG)=0
bitCapIntOcl maxQPowerOcl
Definition: qengine.hpp:40
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1054
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:434
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:338
Definition: qengine_gpu_util.hpp:21
Half-precision floating-point type.
Definition: half.hpp:2222
virtual void Invert(const complex topRight, const complex bottomLeft, bitLenInt qubitIndex)
Apply a single bit transformation that reverses bit probability and might effect phase.
Definition: qinterface.hpp:493
virtual void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubitIndex, const complex *mtrxs)
Apply a "uniformly controlled" arbitrary single bit unitary transformation.
Definition: qinterface.hpp:590
virtual void Z(bitLenInt qubit)
Z gate.
Definition: qinterface.hpp:1087
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual void Phase(const complex topLeft, const complex bottomRight, bitLenInt qubitIndex)
Apply a single bit transformation that only effects phase.
Definition: qinterface.hpp:480
virtual real1_f FirstNonzeroPhase()
Get phase of lowest permutation nonzero amplitude.
Definition: qinterface.hpp:2709
Definition: complex16x2simd.hpp:25
std::complex< half_float::half > complex
Definition: qrack_types.hpp:62
std::shared_ptr< QEngine > QEnginePtr
Definition: qrack_types.hpp:141
std::shared_ptr< OCLDeviceContext > DeviceContextPtr
Definition: oclengine.hpp:47
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:28
constexpr real1_f ZERO_R1_F
Definition: qrack_types.hpp:152
std::shared_ptr< QEngineOCL > QEngineOCLPtr
Definition: qengine_opencl.hpp:34
std::shared_ptr< EventVec > EventVecPtr
Definition: oclengine.hpp:51
constexpr real1_f FP_NORM_EPSILON_F
Definition: qrack_types.hpp:245
const real1 ONE_R1
Definition: qrack_types.hpp:153
unsigned long cl_map_flags
Definition: qengine_cuda.hpp:31
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:22
const real1 REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:155
const real1 PI_R1
Definition: qrack_types.hpp:158
float real1_f
Definition: qrack_types.hpp:64
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:242
std::shared_ptr< PoolItem > PoolItemPtr
Definition: qengine_cuda.hpp:162
SPECIAL_2X2
Definition: qengine_gpu_util.hpp:19
@ NONE
Definition: qengine_gpu_util.hpp:19
OCLAPI
Definition: oclapi.hpp:19
const real1 REAL1_EPSILON
Definition: qrack_types.hpp:157
std::shared_ptr< void > BufferPtr
Definition: qengine_cuda.hpp:45
unsigned long cl_mem_flags
Definition: qengine_cuda.hpp:32
bitLenInt log2(bitCapInt n)
Definition: qrack_functions.hpp:26
MICROSOFT_QUANTUM_DECL void U(_In_ uintq sid, _In_ uintq q, _In_ double theta, _In_ double phi, _In_ double lambda)
(External API) 3-parameter unitary gate
Definition: pinvoke_api.cpp:1362
#define CL_MAP_WRITE
Definition: qengine_cuda.hpp:36
#define CL_MEM_READ_ONLY
Definition: qengine_cuda.hpp:40
#define CL_MAP_READ
Definition: qengine_cuda.hpp:35
#define BCI_ARG_LEN
Definition: qengine_opencl.hpp:26
#define CMPLX_NORM_LEN
Definition: qengine_opencl.hpp:27
#define REAL_ARG_LEN
Definition: qengine_opencl.hpp:28
#define bitLenInt
Definition: qrack_types.hpp:44
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:146
#define bitCapInt
Definition: qrack_types.hpp:105
#define bitCapIntOcl
Definition: qrack_types.hpp:91
#define QRACK_ALIGN_SIZE
Definition: qrack_types.hpp:147
Definition: qengine_cuda.hpp:50
QueueItem(OCLAPI ac, size_t wic, size_t lgs, size_t ds, std::vector< BufferPtr > b, size_t lbs)
Definition: qengine_opencl.hpp:63
QueueItem(real1_f runningNrm)
Definition: qengine_opencl.hpp:91
bool doNorm
Definition: qengine_cuda.hpp:59
size_t workItemCount
Definition: qengine_cuda.hpp:52
std::vector< BufferPtr > buffers
Definition: qengine_cuda.hpp:55
size_t deallocSize
Definition: qengine_cuda.hpp:54
QueueItem()
Definition: qengine_opencl.hpp:49
bool isSetRunningNorm
Definition: qengine_cuda.hpp:58
QueueItem(bool doNrm)
Definition: qengine_opencl.hpp:77
size_t localBuffSize
Definition: qengine_cuda.hpp:56
OCLAPI api_call
Definition: qengine_cuda.hpp:51
bool isSetDoNorm
Definition: qengine_cuda.hpp:57
size_t localGroupSize
Definition: qengine_cuda.hpp:53
real1 runningNorm
Definition: qengine_cuda.hpp:60