Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
32 changes: 27 additions & 5 deletions quest/src/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@

#include <cstdlib>

// Platform-specific includes for RAM querying
#if defined(__linux__)
#include <sys/sysinfo.h>
#elif defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>
#elif defined(_WIN32)
#include <windows.h>
#endif



/*
Expand Down Expand Up @@ -196,11 +206,23 @@ 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)
#if defined(__linux__)
struct sysinfo info;
if (sysinfo(&info) == 0)
return (qindex) info.totalram * info.mem_unit;
#elif defined(__APPLE__)
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;
#elif defined(_WIN32)
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
if (GlobalMemoryStatusEx(&statex))
return (qindex) statex.ullTotalPhys;
#endif
// fallback: throw exception
throw (mem::COULD_NOT_QUERY_RAM) false;
}

Expand Down
Loading