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

Function freeHeapMatrix

quest/src/api/matrices.cpp:86–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84// type T can be CompMatr, DiagMatr or FullStateDiagMatr
85template <class T>
86void freeHeapMatrix(T matr) {
87
88 // WARNING: this is not overwriting any freed pointers with null,
89 // since the caller's struct is not changed. This is fine here,
90 // but would be an issue if the struct contained nested pointers,
91 // since caller would not know an outer pointer was freed and
92 // ergo that it should not be enumerated (to check/free inner ptr)
93
94 // free the 1D or 2D matrix - safe even if nullptr
95 if constexpr (util_isDenseMatrixType<T>()) {
96 cpu_deallocMatrixWrapper(matr.cpuElems);
97 cpu_deallocArray(matr.cpuElemsFlat);
98 } else
99 cpu_deallocArray(matr.cpuElems);
100
101 // we avoid invoking a GPU function in non-GPU mode
102 auto gpuPtr = util_getGpuMemPtr(matr);
103 if (mem_isAllocated(gpuPtr))
104 gpu_deallocArray(gpuPtr);
105
106 // free the teeny tiny heap flags
107 util_deallocEpsilonSensitiveHeapFlag(matr.isApproxUnitary);
108 util_deallocEpsilonSensitiveHeapFlag(matr.isApproxHermitian);
109 cpu_deallocHeapFlag(matr.wasGpuSynced);
110
111 // only diagonal matrices (which can be raised to
112 // exponents) need their negativity/zeroness checked
113 if constexpr (!util_isDenseMatrixType<T>()) {
114 util_deallocEpsilonSensitiveHeapFlag(matr.isApproxNonZero);
115 cpu_deallocHeapFlag(matr.isStrictlyNonNegative);
116 }
117}
118
119
120// type T can be CompMatr, DiagMatr or FullStateDiagMatr

Callers 2

validateAndDestroyMatrixFunction · 0.85

Calls 7

cpu_deallocMatrixWrapperFunction · 0.85
cpu_deallocArrayFunction · 0.85
util_getGpuMemPtrFunction · 0.85
mem_isAllocatedFunction · 0.85
gpu_deallocArrayFunction · 0.85
cpu_deallocHeapFlagFunction · 0.85

Tested by

no test coverage detected