| 2717 | } |
| 2718 | |
| 2719 | void assertNewSuperOpAllocs(SuperOp op, bool isInKrausMap, const char* caller) { |
| 2720 | |
| 2721 | // this validation is called AFTER the caller has checked for failed |
| 2722 | // allocs and (in that scenario) freed every pointer, but does not |
| 2723 | // overwrite any pointers to nullptr, so the failed alloc is known. |
| 2724 | // This is only safe to do so (rather than making the caller set ptrs |
| 2725 | // to nullptr) because the struct contains only 1D pointers (no nesting) |
| 2726 | |
| 2727 | tokenSubs vars = {{"${NUM_BYTES}", mem_getLocalSuperOpMemoryRequired(op.numQubits)}}; |
| 2728 | |
| 2729 | // we expensively get node consensus about malloc failure, in case of heterogeneous hardware/loads, |
| 2730 | // but we avoid this if validation is anyway disabled |
| 2731 | if (!global_isValidationEnabled) |
| 2732 | return; |
| 2733 | |
| 2734 | // assert CPU array of rows was alloc'd successfully |
| 2735 | auto msg = (isInKrausMap)? |
| 2736 | report::NEW_KRAUS_MAPS_SUPER_OP_CPU_ELEMS_ALLOC_FAILED: |
| 2737 | report::NEW_SUPER_OP_CPU_ELEMS_ALLOC_FAILED; |
| 2738 | |
| 2739 | // note .cpuElems size is not included in error msg; fine since quadratically smaller than .cpuElemsFlat |
| 2740 | bool isAlloc = mem_isAllocated(op.cpuElemsFlat) && mem_isOuterAllocated(op.cpuElems); |
| 2741 | assertAllNodesAgreeThat(isAlloc, msg, vars, caller); |
| 2742 | |
| 2743 | // optionally assert GPU memory was malloc'd successfully |
| 2744 | msg = (isInKrausMap)? |
| 2745 | report::NEW_KRAUS_MAPS_SUPER_OP_GPU_ELEMS_ALLOC_FAILED: |
| 2746 | report::NEW_SUPER_OP_GPU_ELEMS_ALLOC_FAILED; |
| 2747 | if (getQuESTEnv().isGpuAccelerated) |
| 2748 | assertAllNodesAgreeThat(mem_isAllocated(util_getGpuMemPtr(op)), msg, vars, caller); |
| 2749 | |
| 2750 | // assert the teeny-tiny heap flag was alloc'd |
| 2751 | vars["${NUM_BYTES}"] = sizeof(*(op.wasGpuSynced)); |
| 2752 | assertAllNodesAgreeThat(mem_isAllocated(op.wasGpuSynced), report::NEW_HEAP_FLAG_ALLOC_FAILED, vars, caller); |
| 2753 | } |
| 2754 | |
| 2755 | void validate_newSuperOpAllocs(SuperOp op, const char* caller) { |
| 2756 |
no test coverage detected