gpu_info_oneapi.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef __APPLE__
  2. #ifndef __GPU_INFO_ONEAPI_H__
  3. #define __GPU_INFO_ONEAPI_H__
  4. #include "gpu_info.h"
  5. #define ZE_MAX_DEVICE_NAME 256
  6. #define ZE_MAX_DEVICE_UUID_SIZE 16
  7. #define ZES_STRING_PROPERTY_SIZE 64
  8. #define ZE_BIT(_i) (1 << _i)
  9. // Just enough typedef's to dlopen/dlsym for memory information
  10. typedef enum ze_result_t {
  11. ZE_RESULT_SUCCESS = 0,
  12. // Other values omitted for now...
  13. } ze_result_t;
  14. typedef uint8_t ze_bool_t;
  15. typedef struct _zes_driver_handle_t *zes_driver_handle_t;
  16. typedef struct _zes_device_handle_t *zes_device_handle_t;
  17. typedef struct _zes_mem_handle_t *zes_mem_handle_t;
  18. typedef enum _ze_structure_type_t {
  19. ZE_STRUCTURE_TYPE_FORCE_UINT32 = 0x7fffffff
  20. } ze_structure_type_t;
  21. typedef enum _zes_structure_type_t {
  22. ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES = 0x1,
  23. ZES_STRUCTURE_TYPE_MEM_PROPERTIES = 0xb,
  24. ZES_STRUCTURE_TYPE_MEM_STATE = 0x1e,
  25. ZES_STRUCTURE_TYPE_DEVICE_EXT_PROPERTIES = 0x2d,
  26. ZES_STRUCTURE_TYPE_FORCE_UINT32 = 0x7fffffff
  27. } zes_structure_type_t;
  28. typedef enum _zes_mem_type_t {
  29. ZES_MEM_TYPE_FORCE_UINT32 = 0x7fffffff
  30. } zes_mem_type_t;
  31. typedef enum _zes_mem_loc_t {
  32. ZES_MEM_LOC_SYSTEM = 0,
  33. ZES_MEM_LOC_DEVICE = 1,
  34. ZES_MEM_LOC_FORCE_UINT32 = 0x7fffffff
  35. } zes_mem_loc_t;
  36. typedef enum _zes_mem_health_t {
  37. ZES_MEM_HEALTH_FORCE_UINT32 = 0x7fffffff
  38. } zes_mem_health_t;
  39. typedef struct _ze_device_uuid_t {
  40. uint8_t id[ZE_MAX_DEVICE_UUID_SIZE];
  41. } ze_device_uuid_t;
  42. typedef struct _zes_uuid_t {
  43. uint8_t id[ZE_MAX_DEVICE_UUID_SIZE];
  44. } zes_uuid_t;
  45. typedef enum _ze_device_type_t {
  46. ZE_DEVICE_TYPE_GPU = 1,
  47. ZE_DEVICE_TYPE_CPU = 2,
  48. ZE_DEVICE_TYPE_FPGA = 3,
  49. ZE_DEVICE_TYPE_MCA = 4,
  50. ZE_DEVICE_TYPE_VPU = 5,
  51. ZE_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
  52. } ze_device_type_t;
  53. typedef enum _zes_device_type_t {
  54. ZES_DEVICE_TYPE_GPU = 1,
  55. ZES_DEVICE_TYPE_CPU = 2,
  56. ZES_DEVICE_TYPE_FPGA = 3,
  57. ZES_DEVICE_TYPE_MCA = 4,
  58. ZES_DEVICE_TYPE_VPU = 5,
  59. ZES_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
  60. } zes_device_type_t;
  61. typedef uint32_t ze_device_property_flags_t;
  62. typedef enum _ze_device_property_flag_t {
  63. ZE_DEVICE_PROPERTY_FLAG_INTEGRATED = ZE_BIT(0),
  64. ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE = ZE_BIT(1),
  65. ZE_DEVICE_PROPERTY_FLAG_ECC = ZE_BIT(2),
  66. ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING = ZE_BIT(3),
  67. ZE_DEVICE_PROPERTY_FLAG_FORCE_UINT32 = 0x7fffffff
  68. } ze_device_property_flag_t;
  69. typedef uint32_t zes_device_property_flags_t;
  70. typedef enum _zes_device_property_flag_t {
  71. ZES_DEVICE_PROPERTY_FLAG_INTEGRATED = ZE_BIT(0),
  72. ZES_DEVICE_PROPERTY_FLAG_SUBDEVICE = ZE_BIT(1),
  73. ZES_DEVICE_PROPERTY_FLAG_ECC = ZE_BIT(2),
  74. ZES_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING = ZE_BIT(3),
  75. ZES_DEVICE_PROPERTY_FLAG_FORCE_UINT32 = 0x7fffffff
  76. } zes_device_property_flag_t;
  77. typedef struct _ze_device_properties_t {
  78. ze_structure_type_t stype;
  79. void *pNext;
  80. ze_device_type_t type;
  81. uint32_t vendorId;
  82. uint32_t deviceId;
  83. ze_device_property_flags_t flags;
  84. uint32_t subdeviceId;
  85. uint32_t coreClockRate;
  86. uint64_t maxMemAllocSize;
  87. uint32_t maxHardwareContexts;
  88. uint32_t maxCommandQueuePriority;
  89. uint32_t numThreadsPerEU;
  90. uint32_t physicalEUSimdWidth;
  91. uint32_t numEUsPerSubslice;
  92. uint32_t numSubslicesPerSlice;
  93. uint32_t numSlices;
  94. uint64_t timerResolution;
  95. uint32_t timestampValidBits;
  96. uint32_t kernelTimestampValidBits;
  97. ze_device_uuid_t uuid;
  98. char name[ZE_MAX_DEVICE_NAME];
  99. } ze_device_properties_t;
  100. typedef struct _zes_device_properties_t {
  101. zes_structure_type_t stype;
  102. void *pNext;
  103. ze_device_properties_t core;
  104. uint32_t numSubdevices;
  105. char serialNumber[ZES_STRING_PROPERTY_SIZE];
  106. char boardNumber[ZES_STRING_PROPERTY_SIZE];
  107. char brandName[ZES_STRING_PROPERTY_SIZE];
  108. char modelName[ZES_STRING_PROPERTY_SIZE];
  109. char vendorName[ZES_STRING_PROPERTY_SIZE];
  110. char driverVersion[ZES_STRING_PROPERTY_SIZE];
  111. } zes_device_properties_t;
  112. typedef struct _zes_device_ext_properties_t {
  113. zes_structure_type_t stype;
  114. void *pNext;
  115. zes_uuid_t uuid;
  116. zes_device_type_t type;
  117. zes_device_property_flags_t flags;
  118. } zes_device_ext_properties_t;
  119. typedef struct _zes_mem_properties_t {
  120. zes_structure_type_t stype;
  121. void *pNext;
  122. zes_mem_type_t type;
  123. ze_bool_t onSubdevice;
  124. uint32_t subdeviceId;
  125. zes_mem_loc_t location;
  126. uint64_t physicalSize;
  127. int32_t busWidth;
  128. int32_t numChannels;
  129. } zes_mem_properties_t;
  130. typedef struct _zes_mem_state_t {
  131. zes_structure_type_t stype;
  132. const void *pNext;
  133. zes_mem_health_t health;
  134. uint64_t free;
  135. uint64_t size;
  136. } zes_mem_state_t;
  137. typedef struct oneapi_handle {
  138. void *handle;
  139. uint16_t verbose;
  140. uint32_t num_drivers;
  141. zes_driver_handle_t *drivers;
  142. uint32_t *num_devices;
  143. zes_device_handle_t **devices;
  144. // TODO Driver major, minor information
  145. // int driver_major;
  146. // int driver_minor;
  147. ze_result_t (*zesInit)(int);
  148. ze_result_t (*zesDriverGet)(uint32_t *pCount, zes_driver_handle_t *phDrivers);
  149. ze_result_t (*zesDeviceGet)(zes_driver_handle_t hDriver, uint32_t *pCount,
  150. zes_device_handle_t *phDevices);
  151. ze_result_t (*zesDeviceGetProperties)(zes_device_handle_t hDevice,
  152. zes_device_properties_t *pProperties);
  153. ze_result_t (*zesDeviceEnumMemoryModules)(zes_device_handle_t hDevice,
  154. uint32_t *pCount,
  155. zes_mem_handle_t *phMemory);
  156. ze_result_t (*zesMemoryGetProperties)(zes_mem_handle_t hMemory,
  157. zes_mem_properties_t *pProperties);
  158. ze_result_t (*zesMemoryGetState)(zes_mem_handle_t hMemory,
  159. zes_mem_state_t *pState);
  160. } oneapi_handle_t;
  161. typedef struct oneapi_init_resp {
  162. char *err; // If err is non-null handle is invalid
  163. oneapi_handle_t oh;
  164. } oneapi_init_resp_t;
  165. typedef struct oneapi_version_resp {
  166. ze_result_t status;
  167. char *str; // Contains version or error string if status != 0
  168. } oneapi_version_resp_t;
  169. void oneapi_init(char *oneapi_lib_path, oneapi_init_resp_t *resp);
  170. void oneapi_check_vram(oneapi_handle_t h, int driver, int device,
  171. mem_info_t *resp);
  172. void oneapi_release(oneapi_handle_t h);
  173. int oneapi_get_device_count(oneapi_handle_t h, int driver);
  174. #endif // __GPU_INFO_INTEL_H__
  175. #endif // __APPLE__