energy
zeus.monitor.energy
Measure the GPU time and energy consumption of a block of code.
Measurement
dataclass
Measurement result of one window.
Attributes:
Name | Type | Description |
---|---|---|
time |
float
|
Time elapsed (in seconds) during the measurement window. |
energy |
dict[int, float]
|
Maps GPU indices to the energy consumed (in Joules) during the
measurement window. GPU indices are from the DL framework's perspective
after applying |
Source code in zeus/monitor/energy.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
total_energy
cached
property
total_energy
Total energy consumed (in Joules) during the measurement window.
ZeusMonitor
Measure the GPU energy and time consumption of a block of code.
Works for multi-GPU and heterogeneous GPU types. Aware of CUDA_VISIBLE_DEVICES
.
For instance, if CUDA_VISIBLE_DEVICES=2,3
, GPU index 1
passed into gpu_indices
will be interpreted as CUDA device 3
.
You can mark the beginning and end of a measurement window, during which the GPU energy and time consumed will be recorded. Multiple concurrent measurement windows are supported.
For Volta or newer GPUs, energy consumption is measured very cheaply with the
nvmlDeviceGetTotalEnergyConsumption
API. On older architectures, this API is
not supported, so a separate Python process is used to poll nvmlDeviceGetPowerUsage
to get power samples over time, which are integrated to compute energy consumption.
Integration Example
from zeus.monitor import ZeusMontior
# Time/Energy measurements for four GPUs will begin and end at the same time.
gpu_indices = [0, 1, 2, 3]
monitor = ZeusMonitor(gpu_indices)
# Mark the beginning of a measurement window. You can use any string
# as the window name, but make sure it's unique.
monitor.begin_window("entire_training")
# Actual work
training(x, y)
# Mark the end of a measurement window and retrieve the measurment result.
result = monitor.end_window("entire_training")
# Print the measurement result.
time_consumed, energy_consumed = prof_result.time, prof_result.energy
print(f"Training took {time_consumed} seconds.")
for gpu_idx, gpu_energy in zip(gpu_indices, energy_consumed):
print(f"GPU {gpu_idx} consumed {gpu_energy} Joules.")
Attributes:
Name | Type | Description |
---|---|---|
gpu_indices |
`list[int]`
|
Indices of all the CUDA devices to monitor, from the
DL framework's perspective after applying |
nvml_gpu_indices |
`list[int]`
|
Indices of all the CUDA devices to monitor, from NVML/system's perspective. |
Source code in zeus/monitor/energy.py
55 56 57 58 59 60 61 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 90 91 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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
_is_new_arch_flags
cached
property
_is_new_arch_flags
A list of flags indicating whether each GPU is Volta or newer.
__init__
__init__(gpu_indices=None, approx_instant_energy=False, log_file=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gpu_indices |
list[int] | None
|
Indices of all the CUDA devices to monitor. Time/Energy measurements
will begin and end at the same time for these GPUs (i.e., synchronized).
If None, all the GPUs available will be used. |
None
|
approx_instant_energy |
bool
|
When the execution time of a measurement window is
shorter than the NVML energy counter's update period, energy consumption may
be observed as zero. In this case, if |
False
|
log_file |
str | Path | None
|
Path to the log CSV file. If |
None
|
Source code in zeus/monitor/energy.py
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 |
|
_is_new_arch
cached
_is_new_arch(gpu)
Return whether the GPU is Volta or newer.
Source code in zeus/monitor/energy.py
179 180 181 182 183 184 185 |
|
_get_instant_power
_get_instant_power()
Measure the power consumption of all GPUs at the current time.
Source code in zeus/monitor/energy.py
192 193 194 195 196 197 198 199 200 |
|
begin_window
begin_window(key, sync_cuda=True)
Begin a new measurement window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Unique name of the measurement window. |
required |
sync_cuda |
bool
|
Whether to synchronize CUDA before starting the measurement window.
(Default: |
True
|
Source code in zeus/monitor/energy.py
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 |
|
end_window
end_window(key, sync_cuda=True, cancel=False)
End a measurement window and return the time and energy consumption.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Name of an active measurement window. |
required |
sync_cuda |
bool
|
Whether to synchronize CUDA before ending the measurement window.
(default: |
True
|
cancel |
bool
|
Whether to cancel the measurement window. If |
False
|
Source code in zeus/monitor/energy.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
_log
_log(message, gpu_index=None, level=logging.INFO)
Print out message with prefix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
The message to log out. |
required |
gpu_index |
int | None
|
The index of GPU for GPU-level logging. Should be |
None
|
level |
int
|
The logging level to use. (Default: |
INFO
|
Source code in zeus/monitor/energy.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|