|
20 | 20 | libLoadLock = threading.Lock() |
21 | 21 |
|
22 | 22 | if rocmsmiLib is None: |
23 | | - rocm_path = Path(os.getenv("ROCM_PATH", os.getenv("ROCM_HOME") or "/opt/rocm")) |
24 | | - |
| 23 | + # Example ROCM_SMI_LIB_PATH |
| 24 | + # - /opt/dtk-24.04.3/rocm_smi/lib |
| 25 | + # - /opt/rocm/rocm_smi/lib |
25 | 26 | rocmsmi_lib_path = os.getenv("ROCM_SMI_LIB_PATH") |
26 | 27 | if not rocmsmi_lib_path: |
27 | | - rocmsmi_lib_path = str(rocm_path / "lib") |
| 28 | + # Example ROCM_PATH/ROCM_HOME |
| 29 | + # - /opt/dtk-24.04.3 |
| 30 | + # - /opt/rocm |
| 31 | + rocm_path = Path(os.getenv("ROCM_HOME", os.getenv("ROCM_PATH") or "/opt/rocm")) |
| 32 | + rocmsmi_lib_path = str(rocm_path / "rocm_smi" / "lib") |
| 33 | + else: |
| 34 | + rocm_path = Path(rocmsmi_lib_path).parent.parent |
28 | 35 |
|
29 | 36 | rocmsmi_lib_loc = Path(rocmsmi_lib_path) / "librocm_smi64.so" |
30 | 37 | if rocmsmi_lib_loc.exists(): |
31 | | - rocmsmi_bindings_path = rocm_path / "libexec" / "rocm_smi" |
| 38 | + rocmsmi_bindings_paths = [ |
| 39 | + (rocm_path / "rocm_smi" / "bindings"), |
| 40 | + (rocm_path / "libexec" / "rocm_smi"), |
| 41 | + ] |
| 42 | + rocmsmi_bindings_path = None |
| 43 | + for p in rocmsmi_bindings_paths: |
| 44 | + if p.exists(): |
| 45 | + rocmsmi_bindings_path = p |
| 46 | + break |
| 47 | + |
32 | 48 | if rocmsmi_bindings_path.exists(): |
33 | 49 | if str(rocmsmi_bindings_path) not in sys.path: |
34 | 50 | sys.path.append(str(rocmsmi_bindings_path)) |
@@ -197,18 +213,21 @@ def rsmi_dev_target_graphics_version_get(device=0): |
197 | 213 | if not rocmsmiLib: |
198 | 214 | raise ROCMSMIError(ROCMSMI_ERROR_UNINITIALIZED) |
199 | 215 |
|
200 | | - c_version = c_uint64() |
201 | | - ret = rocmsmiLib.rsmi_dev_target_graphics_version_get(device, byref(c_version)) |
202 | | - _rocmsmiCheckReturn(ret) |
203 | | - version = str(c_version.value) |
204 | | - if len(version) == 4: |
205 | | - dev_name = rsmi_dev_name_get(device) |
206 | | - if "Instinct MI2" in dev_name: |
207 | | - hex_part = str(hex(int(version[2:]))).replace("0x", "") |
208 | | - version = version[:2] + hex_part |
209 | | - else: |
210 | | - version = str(c_version.value // 10 + c_version.value % 10) |
211 | | - return "gfx" + version |
| 216 | + try: |
| 217 | + c_version = c_uint64() |
| 218 | + ret = rocmsmiLib.rsmi_dev_target_graphics_version_get(device, byref(c_version)) |
| 219 | + _rocmsmiCheckReturn(ret) |
| 220 | + version = str(c_version.value) |
| 221 | + if len(version) == 4: |
| 222 | + dev_name = rsmi_dev_name_get(device) |
| 223 | + if "Instinct MI2" in dev_name: |
| 224 | + hex_part = str(hex(int(version[2:]))).replace("0x", "") |
| 225 | + version = version[:2] + hex_part |
| 226 | + else: |
| 227 | + version = str(c_version.value // 10 + c_version.value % 10) |
| 228 | + return "gfx" + version |
| 229 | + except AttributeError: |
| 230 | + return None |
212 | 231 |
|
213 | 232 |
|
214 | 233 | def rsmi_dev_temp_metric_get(device=0, sensor=None, metric=None): |
@@ -240,17 +259,32 @@ def rsmi_dev_power_cap_get(device=0): |
240 | 259 | return c_power_cap.value // 1000000 |
241 | 260 |
|
242 | 261 |
|
243 | | -def rsmi_dev_power_get(device=0): |
| 262 | +def rsmi_dev_power_ave_get(device=0): |
244 | 263 | if not rocmsmiLib: |
245 | 264 | raise ROCMSMIError(ROCMSMI_ERROR_UNINITIALIZED) |
246 | 265 |
|
| 266 | + c_device_chip = c_uint32(0) |
247 | 267 | c_power = c_uint64() |
248 | | - c_power_type = rsmi_power_type_t() |
249 | | - ret = rocmsmiLib.rsmi_dev_power_get(device, byref(c_power), byref(c_power_type)) |
| 268 | + ret = rocmsmiLib.rsmi_dev_power_ave_get(device, c_device_chip, byref(c_power)) |
250 | 269 | _rocmsmiCheckReturn(ret) |
251 | 270 | return c_power.value // 1000000 |
252 | 271 |
|
253 | 272 |
|
| 273 | +def rsmi_dev_power_get(device=0): |
| 274 | + if not rocmsmiLib: |
| 275 | + raise ROCMSMIError(ROCMSMI_ERROR_UNINITIALIZED) |
| 276 | + |
| 277 | + try: |
| 278 | + c_power = c_uint64() |
| 279 | + c_power_type = rsmi_power_type_t() |
| 280 | + ret = rocmsmiLib.rsmi_dev_power_get(device, byref(c_power), byref(c_power_type)) |
| 281 | + _rocmsmiCheckReturn(ret) |
| 282 | + return c_power.value // 1000000 |
| 283 | + except NameError: |
| 284 | + # Fallback for older versions without rsmi_dev_power_get |
| 285 | + return rsmi_dev_power_ave_get(device) |
| 286 | + |
| 287 | + |
254 | 288 | def rsmi_dev_node_id_get(device=0): |
255 | 289 | if not rocmsmiLib: |
256 | 290 | raise ROCMSMIError(ROCMSMI_ERROR_UNINITIALIZED) |
|
0 commit comments