Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ venv.bak/

# mkdocs documentation
/site
/deploy
.deploy-docs-workdir/

# mypy
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
rev: v2.3.3
hooks:
- id: autoflake
args:
Expand All @@ -11,12 +11,12 @@ repos:
--expand-star-imports,
]
- repo: https://github.com/pycqa/isort
rev: 7.0.0
rev: 8.0.1
hooks:
- id: isort
args: ["--filter-files"]
- repo: https://github.com/psf/black
rev: 25.11.0
rev: 26.5.1
hooks:
- id: black
args: [--safe]
Expand Down
5 changes: 5 additions & 0 deletions codecarbon/core/hardware_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def _spec_from_hardware(hw) -> Dict[str, Any]:
spec["rapl_include_dram"] = getattr(intel, "rapl_include_dram", False)
spec["rapl_prefer_psys"] = getattr(intel, "rapl_prefer_psys", False)
spec["rapl_dir"] = getattr(intel, "_lin_rapl_dir", DEFAULT_RAPL_DIR)
elif hw._mode == "windows_emi" and hasattr(hw, "_intel_interface"):
spec["rapl_include_dram"] = getattr(
hw._intel_interface, "emi_include_dram", False
)
return spec
if kind == HardwareKind.APPLE_CHIP:
return {
Expand Down Expand Up @@ -238,6 +242,7 @@ def clear_cache() -> None:
("codecarbon.core.gpu_amd", "clear_rocm_system_cache"),
("codecarbon.core.cpu", "clear_powergadget_cache"),
("codecarbon.core.powermetrics", "clear_powermetrics_cache"),
("codecarbon.core.windows_emi", "clear_emi_cache"),
):
mod = sys.modules.get(mod_name)
if mod is not None:
Expand Down
6 changes: 2 additions & 4 deletions codecarbon/core/powermetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ def _has_powermetrics_sudo() -> bool:
_, stderr = process.communicate()

if re.search(r"[sudo].*password", stderr):
logger.debug(
"""Not using PowerMetrics, sudo password prompt detected.
logger.debug("""Not using PowerMetrics, sudo password prompt detected.
If you want to enable Powermetrics please modify your sudoers file
as described in :
https://docs.codecarbon.io/latest/explanation/methodology/#power-usage
"""
)
""")
return False
if process.returncode != 0:
raise Exception("Return code != 0")
Expand Down
35 changes: 26 additions & 9 deletions codecarbon/core/resource_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from concurrent.futures import ThreadPoolExecutor
from typing import List, Union

from codecarbon.core import cpu, gpu, powermetrics
from codecarbon.core import cpu, gpu, powermetrics, windows_emi
from codecarbon.core.config import normalize_gpu_ids
from codecarbon.core.hardware_cache import get_cached_tdp, get_or_run_setup
from codecarbon.core.util import (
Expand Down Expand Up @@ -73,6 +73,20 @@ def _setup_power_gadget(self):
self.tracker._conf["cpu_model"] = hardware_cpu.get_model()
return True

def _setup_windows_emi(self):
"""Set up CPU tracking using the Windows Energy Meter Interface (RAPL)."""
logger.info("Tracking CPU via the Windows Energy Meter Interface (RAPL)")
self.cpu_tracker = "Windows EMI"
hardware_cpu = CPU.from_utils(
output_dir=self.tracker._output_dir,
mode="windows_emi",
tracking_mode=self.tracker._tracking_mode,
rapl_include_dram=self.tracker._rapl_include_dram,
)
self.tracker._hardware.append(hardware_cpu)
self.tracker._conf["cpu_model"] = hardware_cpu.get_model()
return True

def _setup_rapl(self):
"""Set up CPU tracking using RAPL interface."""
logger.info("Tracking Intel CPU via RAPL interface")
Expand Down Expand Up @@ -118,7 +132,8 @@ def _get_install_instructions(self):
return "Mac OS detected: Please install Intel Power Gadget or enable PowerMetrics sudo to measure CPU"
elif is_windows_os():
return (
"Windows OS detected: Please install Intel Power Gadget to measure CPU"
"Windows OS detected: CPU power reading via the Energy Meter "
"Interface requires Windows 11 on bare metal (not a VM)"
)
elif is_linux_os():
return "Linux OS detected: Please ensure RAPL files exist, and are readable, at /sys/class/powercap/intel-rapl/subsystem to measure CPU"
Expand Down Expand Up @@ -222,9 +237,13 @@ def _try_platform_cpu_backend(self) -> bool:
elif powermetrics.is_powermetrics_available():
self._setup_powermetrics()
return True
elif is_windows_os() and cpu.is_powergadget_available():
self._setup_power_gadget()
return True
elif is_windows_os():
if windows_emi.is_emi_available():
self._setup_windows_emi()
return True
if cpu.is_powergadget_available():
self._setup_power_gadget()
return True
return False

def set_CPU_tracking(self):
Expand Down Expand Up @@ -298,13 +317,11 @@ def _run_full_hardware_setup(self) -> None:
cpu_future.result()
gpu_future.result()

logger.info(
f"""The below tracking methods have been set up:
logger.info(f"""The below tracking methods have been set up:
RAM Tracking Method: {self.ram_tracker}
CPU Tracking Method: {self.cpu_tracker}
GPU Tracking Method: {self.gpu_tracker}
"""
)
""")

def set_CPU_GPU_ram_tracking(self):
"""
Expand Down
Loading
Loading