-
Notifications
You must be signed in to change notification settings - Fork 163
Description
Summary
Find the available memory at runtime in an OS-agnostic manner (i.e. implement mem_tryGetLocalRamCapacityInBytes()
).
Context
Many QuEST functions involve allocating memory, either in RAM or a GPU's VRAM. QuEST often tries to predict when this allocation will fail (to avoid unacceptably slow memory paging) by first checking how much memory is actually available.
Checking available GPU memory is easy using CUDA functions like cudaMemGetInfo()
, as we do here. Alas, there is no de facto way to obtain the available RAM or CPU memory in C++
; one instead must use libraries or headers specific to different operating systems.
Details
The function mem_tryGetLocalRamCapacityInBytes()
is currently a stub which simply throws an error, indicating that the CPU memory could not be queried (which the caller gracefully handles, merely skipping the associated validation). The stub should be replaced with a platform-agnostic query.
Considerations:
- The implementation must be agnostic to both operating system and compiler, and fall-back to the current error-throw when the memory cannot be probed on the system. It is unacceptable to fail to compile or issue a compiler warning. It is ergo expected to make extensive use of preprocessor guards, like some existing bitwise functions.
- The returned memory is should be the total RAM capacity (ignoring the load currently consumed). This is because the main utility of this function is for getting order-of-magnitude estimates of memory to check whether a
Qureg
will principally fit. - No special considerations are needed in distributed settings. The function need only return the locally accessible memory, and can operate as if execution was local/serial.
Testing
An initial solution can be quickly tested locally by looking at the output of reportQuESTEnv()
, which currently includes...
[cpu]
cpuMemory.........unknown
where unknown
will be updated when mem_tryGetLocalRamCapacityInBytes()
returns a number (in lieu of throwing an exception).
When making a pull request to the devel
branch, the solution will be automatically tested across MacOS, Ubuntu and Windows (and using various compilers) by QuEST's compile CI which executes the automated examples. For example, this action includes [[[ report_quest_env_c.exe ]]]
which calls reportQuESTEnv()
, showing the current unknown
output.
Bonus
A related function mem_tryGetLocalRamFreeInBytes()
could also be implemented in memory.cpp
which returns the available CPU memory. In some sense, this is less important for validation than getting the total system RAM due to paging and swapping, while it may also be more challenging since it depends on the runtime environment rather than a static system attribute.