| 2936 | } |
| 2937 | |
| 2938 | void validate_newKrausMapAllocs(KrausMap map, const char* caller) { |
| 2939 | |
| 2940 | // unlike other post-creation allocation validation, this function |
| 2941 | // expects that when allocation failed and the heap fields have already |
| 2942 | // been cleared, that any nested field (like map.matrices) has had the |
| 2943 | // outer pointer set to null. Otherwise, we would illegally attempt to |
| 2944 | // enumerate the outer pointer to check non-null-ness of inner pointers, |
| 2945 | // which would segmentation fault after the outer pointer was freed! |
| 2946 | // Ergo, we know map.matrices=nullptr whenever anything else failed |
| 2947 | // (and is nullptr), so we must check it last so as not to false report |
| 2948 | // it as the cause of the failure! |
| 2949 | |
| 2950 | // we expensively get node consensus about malloc failure, in case of heterogeneous hardware/loads, |
| 2951 | // but we avoid this if validation is anyway disabled |
| 2952 | if (!global_isValidationEnabled) |
| 2953 | return; |
| 2954 | |
| 2955 | // prior validation gaurantees this will not overflow |
| 2956 | qindex matrListMem = map.numMatrices * mem_getLocalMatrixMemoryRequired(map.numQubits, true, 1); |
| 2957 | tokenSubs vars = { |
| 2958 | {"${NUM_BYTES}", matrListMem}, |
| 2959 | {"${NUM_MATRICES}", map.numMatrices}, |
| 2960 | {"${NUM_QUBITS}", map.numQubits}}; |
| 2961 | |
| 2962 | // assert the teeny-tiny heap flag was alloc'd |
| 2963 | assertAllNodesAgreeThat(mem_isAllocated(map.isApproxCPTP), report::NEW_HEAP_FLAG_ALLOC_FAILED, {{"${NUM_BYTES}", sizeof(*(map.isApproxCPTP))}}, caller); |
| 2964 | |
| 2965 | // assert that the superoperator itself was allocated (along with its own heap fields) |
| 2966 | bool isInKrausMap = true; |
| 2967 | assertNewSuperOpAllocs(map.superop, isInKrausMap, caller); |
| 2968 | |
| 2969 | // assert the list of Kraus operator matrices, and all matrices nad rows therein, were allocated |
| 2970 | // (this must be done last, since caller sets .matrices=nullptr) whenever an inner alloc failed |
| 2971 | bool krausAreAlloc = mem_isOuterAllocated(map.matrices); |
| 2972 | assertAllNodesAgreeThat(krausAreAlloc, report::NEW_KRAUS_MAP_CPU_MATRICES_ALLOC_FAILED, vars, caller); |
| 2973 | } |
| 2974 | |
| 2975 | void validate_newInlineKrausMapDimMatchesVectors(int numQubits, int numOperators, vector<vector<vector<qcomp>>> matrices, const char* caller) { |
| 2976 |
no test coverage detected