gpu_info.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // Compute Capability
  45. int major;
  46. int minor;
  47. int patch;
  48. } mem_info_t;
  49. void cpu_check_ram(mem_info_t *resp);
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #include "gpu_info_cudart.h"
  54. #include "gpu_info_nvcuda.h"
  55. #include "gpu_info_oneapi.h"
  56. #endif // __GPU_INFO_H__
  57. #endif // __APPLE__