gpu_info_nvcuda.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef __APPLE__
  2. #ifndef __GPU_INFO_NVCUDA_H__
  3. #define __GPU_INFO_NVCUDA_H__
  4. #include "gpu_info.h"
  5. // Just enough typedef's to dlopen/dlsym for memory information
  6. typedef enum cudaError_enum {
  7. CUDA_SUCCESS = 0,
  8. CUDA_ERROR_INVALID_VALUE = 1,
  9. CUDA_ERROR_OUT_OF_MEMORY = 2,
  10. CUDA_ERROR_NOT_INITIALIZED = 3,
  11. CUDA_ERROR_INSUFFICIENT_DRIVER = 35,
  12. CUDA_ERROR_NO_DEVICE = 100,
  13. CUDA_ERROR_SYSTEM_DRIVER_MISMATCH = 803,
  14. CUDA_ERROR_UNKNOWN = 999,
  15. // Other values omitted for now...
  16. } CUresult;
  17. typedef enum CUdevice_attribute_enum {
  18. CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75,
  19. CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76,
  20. // TODO - not yet wired up but may be useful for Jetson or other
  21. // integrated GPU scenarios with shared memory
  22. CU_DEVICE_ATTRIBUTE_INTEGRATED = 18
  23. } CUdevice_attribute;
  24. typedef void *nvcudaDevice_t; // Opaque is sufficient
  25. typedef struct nvcudaMemory_st {
  26. uint64_t total;
  27. uint64_t free;
  28. } nvcudaMemory_t;
  29. typedef struct nvcudaDriverVersion {
  30. int major;
  31. int minor;
  32. } nvcudaDriverVersion_t;
  33. typedef struct CUuuid_st {
  34. unsigned char bytes[16];
  35. } CUuuid;
  36. typedef int CUdevice;
  37. typedef void* CUcontext;
  38. typedef struct nvcuda_handle {
  39. void *handle;
  40. uint16_t verbose;
  41. int driver_major;
  42. int driver_minor;
  43. CUresult (*cuInit)(unsigned int Flags);
  44. CUresult (*cuDriverGetVersion)(int *driverVersion);
  45. CUresult (*cuDeviceGetCount)(int *);
  46. CUresult (*cuDeviceGet)(CUdevice* device, int ordinal);
  47. CUresult (*cuDeviceGetAttribute)(int* pi, CUdevice_attribute attrib, CUdevice dev);
  48. CUresult (*cuDeviceGetUuid)(CUuuid* uuid, CUdevice dev); // signature compatible with cuDeviceGetUuid_v2
  49. CUresult (*cuDeviceGetName)(char *name, int len, CUdevice dev);
  50. // Context specific aspects
  51. CUresult (*cuCtxCreate_v3)(CUcontext* pctx, void *params, int len, unsigned int flags, CUdevice dev);
  52. CUresult (*cuMemGetInfo_v2)(uint64_t* free, uint64_t* total);
  53. CUresult (*cuCtxDestroy)(CUcontext ctx);
  54. } nvcuda_handle_t;
  55. typedef struct nvcuda_init_resp {
  56. char *err; // If err is non-null handle is invalid
  57. nvcuda_handle_t ch;
  58. int num_devices;
  59. CUresult cudaErr;
  60. } nvcuda_init_resp_t;
  61. void nvcuda_init(char *nvcuda_lib_path, nvcuda_init_resp_t *resp);
  62. void nvcuda_bootstrap(nvcuda_handle_t ch, int device_id, mem_info_t *resp);
  63. void nvcuda_get_free(nvcuda_handle_t ch, int device_id, uint64_t *free, uint64_t *total);
  64. void nvcuda_release(nvcuda_handle_t ch);
  65. #endif // __GPU_INFO_NVCUDA_H__
  66. #endif // __APPLE__