gpu_info_cpu.c 915 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. snprintf(&resp->gpu_id[0], GPU_ID_LEN, "0");
  13. } else {
  14. resp->err = LOAD_ERR();
  15. }
  16. return;
  17. }
  18. #elif __linux__
  19. #include <errno.h>
  20. #include <string.h>
  21. #include <sys/sysinfo.h>
  22. void cpu_check_ram(mem_info_t *resp) {
  23. struct sysinfo info;
  24. resp->err = NULL;
  25. if (sysinfo(&info) != 0) {
  26. resp->err = strdup(strerror(errno));
  27. } else {
  28. resp->total = info.totalram * info.mem_unit;
  29. resp->free = info.freeram * info.mem_unit;
  30. snprintf(&resp->gpu_id[0], GPU_ID_LEN, "0");
  31. }
  32. return;
  33. }
  34. #elif __APPLE__
  35. // Unused - see gpu_darwin.go
  36. #else
  37. #error "Unsupported platform"
  38. #endif