diff --git a/src/hypertool/utils.py b/src/hypertool/utils.py index b7945465ca9def51098ec4d60913e29fef380b04..135e8f504febdefb086d8a7db4a63041417a622f 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"}