hardware-counters
uma_invariance.py
"""
Which measured quantities are MACHINE-INVARIANT properties of an application,
and which are machine RESPONSES?
This matters for non-circular prediction. If a quantity is intrinsic to the
application (same on any machine), it can be measured once on a cheap source
machine and reused. If it is a response to the microarchitecture, it cannot.
Cycles are clearly a response (cyc_cir/cyc_a2 spans 0.38-1.67). The question
is whether anything is stable enough to serve as a transferable signature.
"""
import os, sys
import numpy as np, pandas as pd
D = os.environ.get("DISS_ROOT", "/work/project/project/user")
a2 = pd.read_csv(f"{D}/data/runs_expanded.csv")
cir = pd.read_csv(f"{D}/data/cirrus_persets.csv")
KEYS = ["app", "size", "ncore", "nthread"]
CTRS = ["PAPI_TOT_INS", "PAPI_TOT_CYC", "PAPI_FP_OPS", "PAPI_FP_INS",
"PAPI_L1_DCA", "PAPI_L2_DCM", "PAPI_L2_DCH", "PAPI_TLB_DM"]
def merge(df):
agg = {c: "median" for c in CTRS if c in df.columns}
agg["runtime_s"] = "median"
return df[df.runtime_s > 0].groupby(KEYS, as_index=False).agg(agg)
A, C = merge(a2), merge(cir)
m = pd.merge(A, C, on=KEYS, suffixes=("_a2", "_cir"))
print(f"matched configurations: {len(m)}\n")
print("ratio cirrus/archer2 -- lower spread means more machine-invariant")
print(f"{'quantity':16s} {'median':>8s} {'IQR':>16s} {'sd log10':>9s}")
print("-" * 54)
rows = []
for c in CTRS + ["runtime_s"]:
ca, cc = f"{c}_a2", f"{c}_cir"
if ca not in m or cc not in m:
continue
r = pd.to_numeric(m[cc], errors="coerce") / pd.to_numeric(m[ca], errors="coerce")
r = r.replace([np.inf, -np.inf], np.nan).dropna()
r = r[r > 0]
if len(r) < 20:
continue
sd = np.log10(r).std()
rows.append((c, sd))
print(f"{c:16s} {r.median():8.3f} {r.quantile(.25):7.3f}-{r.quantile(.75):<7.3f} {sd:9.3f}")
print()
best = sorted(rows, key=lambda x: x[1])[:3]
print("most invariant:", ", ".join(f"{k} (sd {v:.3f})" for k, v in best))
print("\nIf instruction count is markedly more stable than cycle count, then")
print("instructions can serve as a transferable application signature and the")
print("machine-specific part is confined to instructions-per-cycle, which cheap")
print("microbenchmarks on the target could supply.")