gpu_info.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef __APPLE__
  2. #ifndef __GPU_INFO_H__
  3. #define __GPU_INFO_H__
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #ifndef _WIN32
  8. #include <dlfcn.h>
  9. #define LOAD_LIBRARY(lib, flags) dlopen(lib, flags)
  10. #define LOAD_SYMBOL(handle, sym) dlsym(handle, sym)
  11. #define LOAD_ERR() dlerror()
  12. #define UNLOAD_LIBRARY(handle) dlclose(handle)
  13. #else
  14. #include <windows.h>
  15. #define LOAD_LIBRARY(lib, flags) LoadLibrary(lib)
  16. #define LOAD_SYMBOL(handle, sym) GetProcAddress(handle, sym)
  17. #define UNLOAD_LIBRARY(handle) FreeLibrary(handle)
  18. // TODO - refactor this with proper error message handling on windows
  19. inline static char *LOAD_ERR() {
  20. static char errbuf[8];
  21. snprintf(errbuf, 8, "0x%lx", GetLastError());
  22. return errbuf;
  23. }
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef struct mem_info {
  29. uint64_t total;
  30. uint64_t free;
  31. char *err; // If non-nill, caller responsible for freeing
  32. } mem_info_t;
  33. void cpu_check_ram(mem_info_t *resp);
  34. #ifdef __cplusplus
  35. }
  36. #endif
  37. #include "gpu_info_cuda.h"
  38. #include "gpu_info_rocm.h"
  39. #endif // __GPU_INFO_H__
  40. #endif // __APPLE__