-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c6dfac
commit 2561338
Showing
6 changed files
with
127 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (C) 2023 Jae-Won Chung <jwnchung@umich.edu> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Time, energy, and power monitors for Zeus. | ||
The main class of this module is [`ZeusMonitor`](zeus.monitor.energy.ZeusMonitor). | ||
If users wish to monitor power consumption over time, the [`power`](zeus.monitor.power) | ||
module can come in handy. | ||
""" | ||
|
||
from zeus.monitor.energy import ZeusMonitor, Measurement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
from __future__ import annotations | ||
|
||
import time | ||
from typing import Optional | ||
|
||
import rich | ||
import typer | ||
|
||
from zeus.monitor.energy import ZeusMonitor | ||
|
||
app = typer.Typer(add_completion=False) | ||
|
||
|
||
@app.command() | ||
def energy(gpu_indices: Optional[list[int]] = None) -> None: | ||
"""Measure the time and energy of GPUs during the duration of the CLI program. | ||
This uses the `ZeusMonitor` class for measurement, ane thus `gpu_indices` respect | ||
the `CUDA_VISIBLE_DEVICES` environment variable. | ||
For instance, if `CUDA_VISIBLE_DEVICES=2,3`, GPU index `1` passed into `gpu_indices` | ||
will be interpreted as CUDA device `3`. | ||
Args: | ||
gpu_indices: Indices of GPUs to monitor. Not ommitted, all GPUs will be monitored. | ||
""" | ||
monitor = ZeusMonitor(gpu_indices) | ||
monitor.begin_window("zeus.monitor.energy") | ||
|
||
try: | ||
time.sleep(365 * 24 * 60 * 60) | ||
except KeyboardInterrupt: | ||
rich.print(monitor.end_window("zeus.monitor.energy")) | ||
|
||
|
||
@app.command() | ||
def power(gpu_indices: Optional[list[int]] = None) -> None: | ||
"""Monitor the power consumption of GPUs during the duration of the CLI program. | ||
Args: | ||
gpu_indices: Indices of GPUs to monitor. Not ommitted, all GPUs will be monitored. | ||
""" | ||
while True: | ||
print("Hi") | ||
time.sleep(1) | ||
|
||
if __name__ == "__main__": | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# ; Copyright (C) 2023 Jae-Won Chung <jwnchung@umich.edu> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Helpers that poll power usage from GPUs.""" | ||
|
||
from __future__ import annotations | ||
|
||
import pynvml | ||
|
||
|
||
def infer_counter_update_period() -> float: | ||
"""Infer the update period of the NVML power counter. | ||
NVML counters can sometimes be as slow as 10 Hz. | ||
""" | ||
return 100.0 | ||
|
||
|
||
class PowerMonitor: | ||
"""Monitor power usage from GPUs.""" | ||
|
||
def __init__(self, gpu_indices: list[int] | None = None) -> None: | ||
"""Initialize the power monitor.""" | ||
# Initialize NVML. | ||
pynvml.nvmlInit() |