|
18 | 18 | #include "logger/ur_logger.hpp" |
19 | 19 | #include "platform.hpp" |
20 | 20 | #include "ur_util.hpp" |
| 21 | +#include <nvml.h> |
21 | 22 |
|
22 | 23 | int getAttribute(ur_device_handle_t device, CUdevice_attribute attribute) { |
23 | 24 | int value; |
@@ -1085,11 +1086,64 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, |
1085 | 1086 | case UR_DEVICE_INFO_GPU_EU_COUNT_PER_SUBSLICE: |
1086 | 1087 | case UR_DEVICE_INFO_GPU_HW_THREADS_PER_EU: |
1087 | 1088 | case UR_DEVICE_INFO_IP_VERSION: |
1088 | | - case UR_DEVICE_INFO_CURRENT_CLOCK_THROTTLE_REASONS: |
1089 | | - case UR_DEVICE_INFO_FAN_SPEED: |
1090 | | - case UR_DEVICE_INFO_MIN_POWER_LIMIT: |
1091 | | - case UR_DEVICE_INFO_MAX_POWER_LIMIT: |
1092 | 1089 | return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; |
| 1090 | + case UR_DEVICE_INFO_CURRENT_CLOCK_THROTTLE_REASONS: { |
| 1091 | + unsigned long long ClocksEventReasons; |
| 1092 | + UR_CHECK_ERROR(nvmlDeviceGetCurrentClocksEventReasons(hDevice->getNVML(), |
| 1093 | + &ClocksEventReasons)); |
| 1094 | + ur_device_throttle_reasons_flags_t ThrottleReasons = 0; |
| 1095 | + constexpr unsigned long long NVMLThrottleFlags[] = { |
| 1096 | + nvmlClocksThrottleReasonSwPowerCap, |
| 1097 | + nvmlClocksThrottleReasonHwThermalSlowdown || |
| 1098 | + nvmlClocksThrottleReasonSwThermalSlowdown, |
| 1099 | + nvmlClocksThrottleReasonHwPowerBrakeSlowdown, |
| 1100 | + nvmlClocksThrottleReasonApplicationsClocksSetting}; |
| 1101 | + |
| 1102 | + constexpr ur_device_throttle_reasons_flags_t UrThrottleFlags[] = { |
| 1103 | + UR_DEVICE_THROTTLE_REASONS_FLAG_POWER_CAP, |
| 1104 | + UR_DEVICE_THROTTLE_REASONS_FLAG_THERMAL_LIMIT, |
| 1105 | + UR_DEVICE_THROTTLE_REASONS_FLAG_PSU_ALERT, |
| 1106 | + UR_DEVICE_THROTTLE_REASONS_FLAG_SW_RANGE}; |
| 1107 | + |
| 1108 | + for (size_t i = 0; |
| 1109 | + i < sizeof(NVMLThrottleFlags) / sizeof(NVMLThrottleFlags[0]); ++i) { |
| 1110 | + if (ClocksEventReasons & NVMLThrottleFlags[i]) { |
| 1111 | + ThrottleReasons |= UrThrottleFlags[i]; |
| 1112 | + ClocksEventReasons &= ~NVMLThrottleFlags[i]; |
| 1113 | + } |
| 1114 | + } |
| 1115 | + if (ClocksEventReasons) { |
| 1116 | + ThrottleReasons |= UR_DEVICE_THROTTLE_REASONS_FLAG_OTHER; |
| 1117 | + } |
| 1118 | + return ReturnValue(ThrottleReasons); |
| 1119 | + } |
| 1120 | + case UR_DEVICE_INFO_MIN_POWER_LIMIT: |
| 1121 | + case UR_DEVICE_INFO_MAX_POWER_LIMIT: { |
| 1122 | + unsigned int minLimit, maxLimit; |
| 1123 | + auto NVMLHandle = hDevice->getNVML(); |
| 1124 | + auto NVMLError = nvmlDeviceGetPowerManagementLimitConstraints( |
| 1125 | + NVMLHandle, &minLimit, &maxLimit); |
| 1126 | + if (NVMLError == NVML_ERROR_NOT_SUPPORTED) { |
| 1127 | + if (propName == UR_DEVICE_INFO_MAX_POWER_LIMIT) { |
| 1128 | + UR_CHECK_ERROR( |
| 1129 | + nvmlDeviceGetPowerManagementLimit(NVMLHandle, &maxLimit)); |
| 1130 | + return ReturnValue(static_cast<int32_t>(maxLimit)); |
| 1131 | + } else if (propName == UR_DEVICE_INFO_MIN_POWER_LIMIT) { |
| 1132 | + return ReturnValue(static_cast<int32_t>(-1)); |
| 1133 | + } |
| 1134 | + } |
| 1135 | + if (propName == UR_DEVICE_INFO_MAX_POWER_LIMIT) { |
| 1136 | + return ReturnValue(static_cast<int32_t>(maxLimit)); |
| 1137 | + } else if (propName == UR_DEVICE_INFO_MIN_POWER_LIMIT) { |
| 1138 | + return ReturnValue(static_cast<int32_t>(minLimit)); |
| 1139 | + } |
| 1140 | + break; |
| 1141 | + } |
| 1142 | + case UR_DEVICE_INFO_FAN_SPEED: { |
| 1143 | + unsigned int Speed; |
| 1144 | + UR_CHECK_ERROR(nvmlDeviceGetFanSpeed(hDevice->getNVML(), &Speed)); |
| 1145 | + return ReturnValue(static_cast<int32_t>(Speed)); |
| 1146 | + } |
1093 | 1147 | case UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP: |
1094 | 1148 | return ReturnValue( |
1095 | 1149 | static_cast<ur_exp_device_2d_block_array_capability_flags_t>(0)); |
|
0 commit comments