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

Function assertQuregFitsInCpuMem

quest/src/core/validation.cpp:1620–1657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1618}
1619
1620void assertQuregFitsInCpuMem(int numQubits, int isDensMatr, int isDistrib, QuESTEnv env, const char* caller) {
1621
1622 // attempt to fetch RAM, and simply return if we fail; if we unknowingly
1623 // didn't have enough RAM, then alloc validation will trigger later
1624 size_t memPerNode = 0;
1625 try {
1626 memPerNode = mem_tryGetLocalRamCapacityInBytes();
1627 } catch(mem::COULD_NOT_QUERY_RAM e) {
1628 return;
1629 }
1630
1631 // check whether qureg (considering if distributed) fits between node memory(s).
1632 // note this sets numQuregNodes=1 only when distribution is impossible/switched-off,
1633 // but not when it would later be automatically disabled. that's fine; the auto-deployer
1634 // will never disable distribution if local RAM can't store the qureg, so we don't need to
1635 // validate the auto-deployed-to-non-distributed scenario. we only need to ensure that
1636 // auto-deploying-to-distribution is permitted by memory capacity.
1637 int numQuregNodes = (isDistrib == 0 || ! env.isDistributed)? 1 : env.numNodes;
1638 bool quregFitsInMem = mem_canQuregFitInMemory(numQubits, isDensMatr, numQuregNodes, memPerNode);
1639
1640 // make error message specific to whether qureg is local or distributed
1641 string msg = (numQuregNodes == 1)?
1642 report::NEW_QUREG_CANNOT_FIT_INTO_NON_DISTRIB_CPU_MEM :
1643 report::NEW_QUREG_CANNOT_FIT_INTO_POTENTIALLY_DISTRIB_CPU_MEM;
1644
1645 tokenSubs vars = {
1646 {"${IS_DENS}", isDensMatr},
1647 {"${NUM_QUBITS}", numQubits},
1648 {"${QCOMP_BYTES}", sizeof(qcomp)},
1649 {"${EXP_BASE}", (isDensMatr)? 4 : 2},
1650 {"${RAM_SIZE}", memPerNode}};
1651
1652 if (numQuregNodes > 1)
1653 vars["${NUM_NODES}"] = numQuregNodes;
1654
1655 // require expensive node consensus in case of heterogeneous RAMs
1656 assertAllNodesAgreeThat(quregFitsInMem, msg, vars, caller);
1657}
1658
1659void assertQuregFitsInGpuMem(int numQubits, int isDensMatr, int isDistrib, int isGpuAccel, QuESTEnv env, const char* caller) {
1660

Callers 1

validate_newQuregParamsFunction · 0.85

Calls 3

mem_canQuregFitInMemoryFunction · 0.85
assertAllNodesAgreeThatFunction · 0.85

Tested by

no test coverage detected