Skip to content

Commit

Permalink
Catch PermissionError and raise with more information
Browse files Browse the repository at this point in the history
  • Loading branch information
wbjin committed Aug 25, 2024
1 parent 8430a42 commit 0f1fc7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions zeus/device/cpu/rapl.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def __init__(self, message: str) -> None:
"""Initialize Zeus Exception."""
super().__init__(message)

class ZeusRAPLPermissionError(ZeusBaseCPUError):
"""Zeus GPU exception that wraps No Permission to perform GPU operation."""

def __init__(self, message: str) -> None:
"""Intialize the exception object."""
super().__init__(message)

class RAPLFile:
"""RAPL File class for each RAPL file.
Expand All @@ -169,6 +175,10 @@ def __init__(self, path: str) -> None:
self.last_energy = float(energy_file.read().strip())
except FileNotFoundError as err:
raise ZeusRAPLFileInitError("Error reading package energy") from err
except PermissionError as err:
raise ZeusRAPLPermissionError(
"Can't read file due to permission error"
) from err
try:
with open(
os.path.join(path, "max_energy_range_uj"), "r"
Expand Down
8 changes: 8 additions & 0 deletions zeus/monitor/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dataclasses import dataclass
from functools import cached_property

from zeus.device.cpu.rapl import ZeusRAPLPermissionError
from zeus.monitor.power import PowerMonitor
from zeus.utils.logging import get_logger
from zeus.utils.framework import sync_execution as sync_execution_fn
Expand Down Expand Up @@ -186,6 +187,13 @@ def __init__(
self.cpus = get_cpus()
except ZeusCPUInitError:
self.cpus = EmptyCPUs()
except ZeusRAPLPermissionError as err:
raise RuntimeError(
"SYS_ADMIN capability is required to modify GPU power limits. See "
"https://ml.energy/zeus/getting_started/#system-privileges "
"for more information or disable CPU measurement by passing cpu_indices=None to "
"ZeusMonitor"
) from err

# Resolve GPU indices. If the user did not specify `gpu_indices`, use all available GPUs.
self.gpu_indices = (
Expand Down

0 comments on commit 0f1fc7d

Please sign in to comment.