power
zeus.monitor.power
Monitor the power usage of GPUs.
PowerMonitor
Monitor power usage from GPUs.
This class acts as a lower level wrapper around a Python process that polls
the power consumption of GPUs. This is primarily used by
ZeusMonitor
for older architecture GPUs that
do not support the nvmlDeviceGetTotalEnergyConsumption API.
Warning
Since the monitor spawns a child process, it should not be instantiated as a global variable. Python puts a protection to prevent creating a process in global scope. Refer to the "Safe importing of main module" section in the Python documentation for more details.
Attributes:
Name | Type | Description |
---|---|---|
gpu_indices |
list[int]
|
Indices of the GPUs to monitor. |
update_period |
int
|
Update period of the power monitor in seconds.
Holds inferred update period if |
Source code in zeus/monitor/power.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
__init__
__init__(
gpu_indices=None,
update_period=None,
power_csv_path=None,
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gpu_indices |
list[int] | None
|
Indices of the GPUs to monitor. If None, monitor all GPUs. |
None
|
update_period |
float | None
|
Update period of the power monitor in seconds. If None, infer the update period by max speed polling the power counter for each GPU model. |
None
|
power_csv_path |
str | None
|
If given, the power polling process will write measurements to this path. Otherwise, a temporary file will be used. |
None
|
Source code in zeus/monitor/power.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
_stop
_stop()
Stop monitoring power usage.
Source code in zeus/monitor/power.py
165 166 167 168 169 170 171 |
|
_update_df
_update_df()
Add rows to the power dataframe from the CSV file.
Source code in zeus/monitor/power.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
get_energy
get_energy(start_time, end_time)
Get the energy used by the GPUs between two times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time |
float
|
Start time of the interval, from time.time(). |
required |
end_time |
float
|
End time of the interval, from time.time(). |
required |
Returns:
Type | Description |
---|---|
dict[int, float] | None
|
A dictionary mapping GPU indices to the energy used by the GPU between the |
dict[int, float] | None
|
two times. GPU indices are from the DL framework's perspective after |
dict[int, float] | None
|
applying |
dict[int, float] | None
|
If there are no power readings, return None. |
Source code in zeus/monitor/power.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
get_power
get_power(time=None)
Get the power usage of the GPUs at a specific time point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time |
float | None
|
Time point to get the power usage at. If None, get the power usage at the last recorded time point. |
None
|
Returns:
Type | Description |
---|---|
dict[int, float] | None
|
A dictionary mapping GPU indices to the power usage of the GPU at the |
dict[int, float] | None
|
specified time point. GPU indices are from the DL framework's perspective |
dict[int, float] | None
|
after applying |
dict[int, float] | None
|
If there are no power readings (e.g., future timestamps), return None. |
Source code in zeus/monitor/power.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
infer_counter_update_period
infer_counter_update_period(gpu_indicies)
Infer the update period of the NVML power counter.
NVML counters can update as slow as 10 Hz depending on the GPU model, so there's no need to poll them too faster than that. This function infers the update period for each unique GPU model and selects the fastest-updating period detected. Then, it returns half the period to ensure that the counter is polled at least twice per update period.
Source code in zeus/monitor/power.py
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 57 58 59 |
|
_infer_counter_update_period_single
_infer_counter_update_period_single(gpu_index)
Infer the update period of the NVML power counter for a single GPU.
Source code in zeus/monitor/power.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
_polling_process
_polling_process(
gpu_indices, power_csv_path, update_period
)
Run the power monitor.
Source code in zeus/monitor/power.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|