1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
diff --git a/rocm_smi.py b/rocm_smi.py
index 3903b5b..b138855 100755
--- a/rocm_smi.py
+++ b/rocm_smi.py
@@ -1081,6 +1081,11 @@ def setPowerOverDrive(deviceList, value, autoRespond):
return
confirmOutOfSpecWarning(autoRespond)
+
+ # Value in Watt - stored early this way to avoid pythons float -> int -> str conversion after dividing a number
+ strValue = value
+ # Our Watt value converted for sysfs as microWatt
+ value = int(value) * 1000000
for device in deviceList:
if not isDPMAvailable(device):
@@ -1092,27 +1097,28 @@ def setPowerOverDrive(deviceList, value, autoRespond):
continue
power_cap_path = os.path.join(hwmon, 'power1_cap')
- max_power_cap = str(int(getSysfsValue(device, 'power_cap_max')) / 1000000)
- min_power_cap = str(int(getSysfsValue(device, 'power_cap_min')) / 1000000)
+ # Avoid early unnecessary conversions
+ max_power_cap = int(getSysfsValue(device, 'power_cap_max'))
+ min_power_cap = int(getSysfsValue(device, 'power_cap_min'))
- if int(value) < int(min_power_cap):
- printLog(device, 'Unable to set Power OverDrive to less than ' + min_power_cap + 'W')
+ if value < min_power_cap:
+ printLog(device, 'Unable to set Power OverDrive to less than ' + str(min_power_cap / 1000000) + 'W')
RETCODE = 1
return
- if int(value) > int(max_power_cap):
- printLog(device, 'Unable to set Power OverDrive to more than ' + max_power_cap + 'W')
+ if value > max_power_cap:
+ printLog(device, 'Unable to set Power OverDrive to more than ' + str(max_power_cap / 1000000) + 'W')
RETCODE = 1
return;
- if writeToSysfs(power_cap_path, str(int(value) * 1000000)):
- if int(value) != 0:
- printLog(device, 'Successfully set Power OverDrive to ' + value + 'W')
+ if writeToSysfs(power_cap_path, str(value)):
+ if value != 0:
+ printLog(device, 'Successfully set Power OverDrive to ' + strValue + 'W')
else:
printLog(device, 'Successfully reset Power OverDrive')
else:
- if int(value) != 0:
- printLog(device, 'Unable to set Power OverDrive to ' + value + 'W')
+ if value != 0:
+ printLog(device, 'Unable to set Power OverDrive to ' + strValue + 'W')
else:
printLog(device, 'Unable to reset Power OverDrive to default')
|