gpu_info.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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() strdup(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. #define LOAD_ERR() ({\
  19. LPSTR messageBuffer = NULL; \
  20. size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
  21. NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); \
  22. char *resp = strdup(messageBuffer); \
  23. LocalFree(messageBuffer); \
  24. resp; \
  25. })
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. typedef struct mem_info {
  31. uint64_t total;
  32. uint64_t free;
  33. unsigned int count;
  34. char *err; // If non-nill, caller responsible for freeing
  35. } mem_info_t;
  36. void cpu_check_ram(mem_info_t *resp);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. #include "gpu_info_cuda.h"
  41. #include "gpu_info_rocm.h"
  42. #endif // __GPU_INFO_H__
  43. #endif // __APPLE__