From a6c8f66f4b7b543398ed6d31d84414ef34244448 Mon Sep 17 00:00:00 2001 From: Roll249 <80768386+Roll249@users.noreply.github.com> Date: Sat, 31 May 2025 06:50:50 +0000 Subject: [PATCH 1/2] Implement cross-platform RAM capacity query in mem_tryGetLocalRamCapacityInBytes() for Linux, macOS, and Windows. Falls back to exception if not available. --- quest/src/core/memory.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/quest/src/core/memory.cpp b/quest/src/core/memory.cpp index 36eedb596..74d228598 100644 --- a/quest/src/core/memory.cpp +++ b/quest/src/core/memory.cpp @@ -196,11 +196,37 @@ qindex mem_getMaxNumKrausMapMatricesBeforeLocalMemSizeofOverflow(int numQubits) qindex mem_tryGetLocalRamCapacityInBytes() { - - /// @todo attempt to find total Ram - - // if we're unable to find total RAM, throw an exception - // (which the caller should catch and gracefully continue) + // Linux: parse /proc/meminfo + #if defined(__linux__) + FILE* meminfo = fopen("/proc/meminfo", "r"); + if (meminfo) { + char line[256]; + while (fgets(line, sizeof(line), meminfo)) { + if (sscanf(line, "MemTotal: %lu kB", &mem_total_kb) == 1) { + fclose(meminfo); + return (qindex)mem_total_kb * 1024; + } + } + fclose(meminfo); + } + // macOS: use sysctl + #elif defined(__APPLE__) + #include + #include + int mib[2] = {CTL_HW, HW_MEMSIZE}; + int64_t memsize = 0; + size_t len = sizeof(memsize); + if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0 && memsize > 0) + return (qindex)memsize; + // Windows: use GlobalMemoryStatusEx + #elif defined(_WIN32) + #include + MEMORYSTATUSEX statex; + statex.dwLength = sizeof(statex); + if (GlobalMemoryStatusEx(&statex)) + return (qindex)statex.ullTotalPhys; + #endif + // fallback: throw exception throw (mem::COULD_NOT_QUERY_RAM) false; } From 6b5b7e214f6f602a92d249af6f022d215ac16552 Mon Sep 17 00:00:00 2001 From: Roll249 <80768386+Roll249@users.noreply.github.com> Date: Sat, 31 May 2025 06:51:45 +0000 Subject: [PATCH 2/2] add --- build/CMakeCache.txt | 53 ++++++++++++++++++++++++++++++ build/CMakeFiles/cmake.check_cache | 1 + 2 files changed, 54 insertions(+) create mode 100644 build/CMakeCache.txt create mode 100644 build/CMakeFiles/cmake.check_cache diff --git a/build/CMakeCache.txt b/build/CMakeCache.txt new file mode 100644 index 000000000..cea205a33 --- /dev/null +++ b/build/CMakeCache.txt @@ -0,0 +1,53 @@ +# This is the CMakeCache file. +# For build in directory: /workspaces/QuEST/build +# It was generated by CMake: /usr/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + + +######################## +# INTERNAL cache entries +######################## + +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/workspaces/QuEST/build +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=16 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/usr/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Unix Makefiles +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/workspaces/QuEST +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.16 + diff --git a/build/CMakeFiles/cmake.check_cache b/build/CMakeFiles/cmake.check_cache new file mode 100644 index 000000000..3dccd7317 --- /dev/null +++ b/build/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file