gpu_info_cpu.c 1.02 KB
Newer Older
1
2
3
4
5
6
7
8
#include "gpu_info.h"
// Fallbacks for CPU mode

#ifdef _WIN32
#include <sysinfoapi.h>
void cpu_check_ram(mem_info_t *resp) {
  resp->err = NULL;
  MEMORYSTATUSEX info;
9
  info.dwLength = sizeof(info);
10
11
12
  if (GlobalMemoryStatusEx(&info) != 0) {
    resp->total = info.ullTotalPhys;
    resp->free = info.ullAvailPhys;
Daniel Hiltgen's avatar
Daniel Hiltgen committed
13
    snprintf(&resp->gpu_id[0], GPU_ID_LEN, "0");
14
  } else {
15
    resp->err = LOAD_ERR();
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  }
  return;
}

#elif __linux__
#include <errno.h>
#include <string.h>
#include <sys/sysinfo.h>
void cpu_check_ram(mem_info_t *resp) {
  struct sysinfo info;
  resp->err = NULL;
  if (sysinfo(&info) != 0) {
    resp->err = strdup(strerror(errno));
  } else {
    resp->total = info.totalram * info.mem_unit;
    resp->free = info.freeram * info.mem_unit;
Daniel Hiltgen's avatar
Daniel Hiltgen committed
32
    snprintf(&resp->gpu_id[0], GPU_ID_LEN, "0");
33
34
35
36
37
38
39
40
41
42
43
44
45
  }
  return;
}

#elif __APPLE__
// TODO consider an Apple implementation that does something useful
// mem_info_t cpu_check_ram() {
//   mem_info_t resp = {0, 0, NULL};
//   return resp;
// }
#else
#error "Unsupported platform"
#endif