| 2641 | } |
| 2642 | |
| 2643 | void assertSuperOpFitsInCpuMem(int numQubits, bool isInKrausMap, const char* caller) { |
| 2644 | |
| 2645 | // attempt to fetch RAM, and simply return if we fail; if we unknowingly |
| 2646 | // didn't have enough RAM, then alloc validation will trigger later |
| 2647 | size_t memPerNode = 0; |
| 2648 | try { |
| 2649 | memPerNode = mem_tryGetLocalRamCapacityInBytes(); |
| 2650 | } catch(mem::COULD_NOT_QUERY_RAM e) { |
| 2651 | return; |
| 2652 | } |
| 2653 | |
| 2654 | bool matrFitsInMem = mem_canSuperOpFitInMemory(numQubits, memPerNode); |
| 2655 | |
| 2656 | tokenSubs vars = { |
| 2657 | {"${NUM_QUBITS}", numQubits}, |
| 2658 | {"${QCOMP_BYTES}", sizeof(qcomp)}, |
| 2659 | {"${RAM_SIZE}", memPerNode}}; |
| 2660 | |
| 2661 | /// @todo |
| 2662 | /// seek expensive node consensus in case of heterogeneous RAM - alas this may induce |
| 2663 | /// unnecessary slowdown (due to sync and broadcast) in applications allocating many |
| 2664 | /// small matrices in the heap. If this turns out to be the case, we could opt to |
| 2665 | /// enforce consensus only when the needed memory is large (e.g. >1GB) and ergo the |
| 2666 | /// chance of it fitting into some node RAM but not others isn't negligible. |
| 2667 | auto msg = (isInKrausMap)? |
| 2668 | report::NEW_KRAUS_MAPS_SUPER_OP_CANNOT_FIT_INTO_CPU_MEM: |
| 2669 | report::NEW_SUPER_OP_CANNOT_FIT_INTO_CPU_MEM; |
| 2670 | assertAllNodesAgreeThat(matrFitsInMem, msg, vars, caller); |
| 2671 | } |
| 2672 | |
| 2673 | void assertSuperOpFitsInGpuMem(int numQubits, int isEnvGpuAccel, bool isInKrausMap, const char* caller) { |
| 2674 |
no test coverage detected