gpu_info.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #define LOG(verbose, ...) \
  28. do { \
  29. if (verbose) { \
  30. fprintf(stderr, __VA_ARGS__); \
  31. } \
  32. } while (0)
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #define GPU_ID_LEN 64
  37. #define GPU_NAME_LEN 96
  38. typedef struct mem_info {
  39. char *err; // If non-nill, caller responsible for freeing
  40. char gpu_id[GPU_ID_LEN];
  41. char gpu_name[GPU_NAME_LEN];
  42. uint64_t total;
  43. uint64_t free;
  44. uint64_t used;
  45. // Compute Capability
  46. int major;
  47. int minor;
  48. int patch;
  49. } mem_info_t;
  50. void cpu_check_ram(mem_info_t *resp);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #include "gpu_info_cudart.h"
  55. #include "gpu_info_nvcuda.h"
  56. #include "gpu_info_nvml.h"
  57. #include "gpu_info_oneapi.h"
  58. #endif // __GPU_INFO_H__
  59. #endif // __APPLE__