Skip to content
Draft
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
12 changes: 12 additions & 0 deletions codecarbon/data/hardware/cpu_power.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4902,3 +4902,15 @@ TL-60,31
TL-64,35
X1150,17
X940,45
Apple M2,15
Apple M2 Pro,20
Apple M2 Max,30
Apple M2 Ultra,60
Apple M3,15
Apple M3 Pro,18
Apple M3 Max,30
Apple M3 Ultra,60
Apple M4,15
Apple M4 Pro,20
Apple M4 Max,35
Apple M4 Ultra,70
50 changes: 50 additions & 0 deletions tests/test_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,56 @@ def test_main_returns_unknown_when_cpu_detection_fails(self):
self.assertEqual(tdp.model, "Unknown")
self.assertIsNone(tdp.tdp)

def test_apple_m2_chips_have_correct_tdp(self):
for chip, expected_tdp in [
("Apple M2", 15),
("Apple M2 Pro", 20),
("Apple M2 Max", 30),
("Apple M2 Ultra", 60),
]:
with mock.patch("codecarbon.core.cpu.detect_cpu_model", return_value=chip):
tdp = TDP()
self.assertEqual(tdp.model, chip)
self.assertEqual(tdp.tdp, expected_tdp)

def test_apple_m3_chips_have_correct_tdp(self):
for chip, expected_tdp in [
("Apple M3", 15),
("Apple M3 Pro", 18),
("Apple M3 Max", 30),
("Apple M3 Ultra", 60),
]:
with mock.patch("codecarbon.core.cpu.detect_cpu_model", return_value=chip):
tdp = TDP()
self.assertEqual(tdp.model, chip)
self.assertEqual(tdp.tdp, expected_tdp)

def test_apple_m4_chips_have_correct_tdp(self):
for chip, expected_tdp in [
("Apple M4", 15),
("Apple M4 Pro", 20),
("Apple M4 Max", 35),
("Apple M4 Ultra", 70),
]:
with mock.patch("codecarbon.core.cpu.detect_cpu_model", return_value=chip):
tdp = TDP()
self.assertEqual(tdp.model, chip)
self.assertEqual(tdp.tdp, expected_tdp)

def test_unknown_apple_chip_falls_back_gracefully(self):
with (
mock.patch(
"codecarbon.core.cpu.detect_cpu_model",
return_value="Apple M5 Pro",
),
mock.patch("codecarbon.core.cpu.is_psutil_available", return_value=True),
mock.patch("codecarbon.core.cpu.count_cpus", return_value=10),
):
tdp = TDP()

self.assertEqual(tdp.model, "Apple M5 Pro")
self.assertEqual(tdp.tdp, 10 * DEFAULT_POWER_PER_CORE)


class TestResourceTrackerCPUTracking(unittest.TestCase):
def test_set_cpu_tracking_skips_tdp_when_rapl_available(self):
Expand Down