gpu_info_cpu.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "gpu_info.h"
  2. // Fallbacks for CPU mode
  3. #ifdef _WIN32
  4. #include <sysinfoapi.h>
  5. void cpu_check_ram(mem_info_t *resp) {
  6. resp->err = NULL;
  7. MEMORYSTATUSEX info;
  8. info.dwLength = sizeof(info);
  9. if (GlobalMemoryStatusEx(&info) != 0) {
  10. resp->total = info.ullTotalPhys;
  11. resp->free = info.ullAvailPhys;
  12. resp->major = 0;
  13. resp->minor = 0;
  14. snprintf(&resp->gpu_id[0], GPU_ID_LEN, "0");
  15. } else {
  16. resp->err = LOAD_ERR();
  17. }
  18. return;
  19. }
  20. #elif __linux__
  21. #include <errno.h>
  22. #include <string.h>
  23. #include <sys/sysinfo.h>
  24. void cpu_check_ram(mem_info_t *resp) {
  25. struct sysinfo info;
  26. resp->err = NULL;
  27. if (sysinfo(&info) != 0) {
  28. resp->err = strdup(strerror(errno));
  29. } else {
  30. resp->total = info.totalram * info.mem_unit;
  31. resp->free = info.freeram * info.mem_unit;
  32. resp->major = 0;
  33. resp->minor = 0;
  34. snprintf(&resp->gpu_id[0], GPU_ID_LEN, "0");
  35. }
  36. return;
  37. }
  38. #elif __APPLE__
  39. // TODO consider an Apple implementation that does something useful
  40. // mem_info_t cpu_check_ram() {
  41. // mem_info_t resp = {0, 0, NULL};
  42. // return resp;
  43. // }
  44. #else
  45. #error "Unsupported platform"
  46. #endif