mlco2 / mlco2/codecarbon

rapl_include_dram=True reads DRAM domains but never adds them to the energy total

Open
#1,305 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
323
Avg merge
1d 12h
Merged PRs (30d)
12

Description

On Linux, rapl_include_dram=True selects the DRAM RAPL domains and reads them every cycle, but their energy never reaches the reported total. The measurement is silently identical to rapl_include_dram=False, while the log claims DRAM is included.

Reproduction

On a machine exposing a top-level dram domain alongside package-0:

a = EmissionsTracker(rapl_include_dram=False)
b = EmissionsTracker(rapl_include_dram=True)

Both report the same CPU energy, even though b logs RAPL - Including 1 DRAM domain(s) for complete hardware power measurement (CPU+DRAM).

Root cause

Two naming conventions that were never tied together.

  • codecarbon/core/cpu.py:708 — domain selection correctly appends DRAM domains when rapl_include_dram is set.
  • codecarbon/core/cpu.py:772_create_rapl_files only assigns the Power-Gadget-compatible display name Processor Energy Delta_N(kWh) to domains whose name contains package or psys. A DRAM domain falls into the else and keeps its raw sysfs name dram.
  • codecarbon/external/hardware.py:390_get_energy_from_cpus sums only keys matching ^Processor Energy Delta_\d, so the dram entry is dropped. Same for power: codecarbon/core/cpu.py:849 only derives a Processor Power key from names containing Energy.

Windows EMI does not have this bug: codecarbon/core/windows_emi.py:581 names every selected channel Processor Energy Delta_N(kWh), DRAM included. So emi_include_dram=True works and rapl_include_dram=True does not.

Expected vs actual

Expected: with rapl_include_dram=True, reported CPU energy is package + DRAM (DRAM is typically 10-20% of package power on memory-heavy workloads).

Actual: DRAM energy is read, converted, logged, and discarded. Reported energy equals the package-only value.

Note this is a measurement change for anyone already setting the flag — their reported figures will (correctly) increase.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the RAPL flow in codecarbon/core/cpu.py at lines 708, 772, and 849, then trace aggregation in codecarbon/external/hardware.py:390 and compare the working naming path in codecarbon/core/windows_emi.py:581. Reproduce the package-only versus DRAM-enabled measurements and verify that DRAM contributes to the reported energy and power totals when rapl_include_dram=True.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.