MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / allocSuperOp

Function allocSuperOp

quest/src/api/channels.cpp:125–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124
125SuperOp allocSuperOp(int numQubits) {
126
127 // this inner function will NOT validate, verify whether
128 // allocations succeeded, nor attempt to free memory if not
129
130 // prior validation ensures these never overflow
131 qindex numRows = powerOf2(2 * numQubits);
132 qindex numElems = numRows * numRows;
133
134 // attempt top allocate 1D memory
135 qcomp* cpuMem = cpu_allocArray(numElems); // nullptr if failed
136 qcomp* gpuMem = nullptr;
137 if (getQuESTEnv().isGpuAccelerated)
138 gpuMem = gpu_allocArray(numElems); // nullptr if failed
139
140 // prepare output SuperOp (avoiding C++20 designated initialiser)
141 SuperOp out;
142 out.numQubits = numQubits;
143 out.numRows = numRows;
144
145 // attemptedly allocate 2D alias for 1D CPU memory
146 out.cpuElems = cpu_allocAndInitMatrixWrapper(cpuMem, numRows); // nullptr if failed
147 out.cpuElemsFlat = cpuMem;
148 out.gpuElemsFlat = gpuMem;
149
150 // attemptedly allocate (un-initialised) flags in the heap so that struct copies are mutable
151 out.wasGpuSynced = cpu_allocHeapFlag(); // nullptr if failed
152
153 // if heap flag allocated, mark it as unsynced (caller will handle if allocation failed)
154 if (mem_isAllocated(out.wasGpuSynced))
155 *(out.wasGpuSynced) = 0;
156
157 // caller will handle if any above allocations failed
158 return out;
159}
160
161
162extern "C" SuperOp createSuperOp(int numQubits) {

Callers 2

createSuperOpFunction · 0.85
createKrausMapFunction · 0.85

Calls 7

powerOf2Function · 0.85
cpu_allocArrayFunction · 0.85
getQuESTEnvFunction · 0.85
gpu_allocArrayFunction · 0.85
cpu_allocHeapFlagFunction · 0.85
mem_isAllocatedFunction · 0.85

Tested by

no test coverage detected