From 4799058b0bab1d3a3d8cdfd968e857899bfac7cc Mon Sep 17 00:00:00 2001 From: mafooq <mafoqulhassan@gmail.com> Date: Thu, 10 Jul 2025 09:12:18 +0000 Subject: [PATCH] Feat#3: Fixed L3 cache parsing and added FLOPs annotation --- src/hypertool/utils.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/hypertool/utils.py b/src/hypertool/utils.py index b794546..135e8f5 100644 --- a/src/hypertool/utils.py +++ b/src/hypertool/utils.py @@ -143,17 +143,26 @@ def extract_cpu_features(): elif "CPU max MHz" in line: features["Clock (GHz)"] = round(float(line.split(":")[1].strip()) / 1000, 2) elif "L3 cache" in line: - value = line.split(":")[1].strip() - if value.endswith("K"): - features["L3_Cache"] = round(int(value[:-1]) / 1024, 2) - elif value.endswith("M"): - features["L3_Cache"] = float(value[:-1]) - else: - features["L3_Cache"] = 0.0 - - features.setdefault("Cores", os.cpu_count() or 4) - features.setdefault("Clock (GHz)", 2.5) - features.setdefault("L3_Cache", 8.0) + value = line.split(":")[1].strip().split()[0] # take first numeric part + value = re.sub(r"[^\d.]", "", value) # keep digits and dot only + try: + features["L3_Cache"] = float(value) + except ValueError: + features["L3_Cache"] = 8.0 # fallback + + features.setdefault("Cores", os.cpu_count() or 4) # Use actual core count or 4 core median configuration + features.setdefault( + "Clock (GHz)", 2.5 + ) # Conservative estimate for modern CPUs (average clock rate between AMD and Intel CPUs) + features.setdefault("L3_Cache", 8.0) # Typical L3 cache size for mid-tier CPUs + + # Fallback Values Justification: + # ------------------------------ + # Cores: 4 — Median logical core count for laptops, desktops, and cloud VMs + # Clock: 2.5 GHz — Conservative base frequency across modern CPUs + # L3 Cache: 8.0 MB — Common shared L3 cache size in mid-range CPUs + # These defaults ensure realistic performance estimation without exaggeration + # in case of parsing or access errors. return features except Exception as e: @@ -197,7 +206,7 @@ def get_energy_efficiency_annotation(): cpu_model = get_cpu_model() tdp = get_tdp(cpu_model) if not tdp: - return {"hyperai.eu/node-energy-efficiency": "unknown"} + return {"hyperai.eu/node-energy-efficiency": "unknown", "hyperai.eu/node-flops-per-sec": "unknown"} a = np.random.rand(1_000_000).astype(np.float32) b = np.random.rand(1_000_000).astype(np.float32) @@ -220,8 +229,8 @@ def get_energy_efficiency_annotation(): else: label = "very high" - return {"hyperai.eu/node-energy-efficiency": label} + return {"hyperai.eu/node-energy-efficiency": label, "hyperai.eu/node-flops-per-sec": round(flops_per_sec, 2)} except Exception as e: logging.error(f"Failed energy estimation: {e}") - return {"hyperai.eu/node-energy-efficiency": "unknown"} + return {"hyperai.eu/node-energy-efficiency": "unknown", "hyperai.eu/node-flops-per-sec": "unknown"} -- GitLab