gpu_info_nvcuda.h 2.3 KB

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