Opens a larger view. Escape closes it.

hardware-counters

probe_sets.py

"""
Can each counter set be treated as an independent training sample?

Each of the 5 sets is a separate execution of the same binary/config with a
different PAT_RT_PERFCTR selection, and each records its own Thread Time and
(in most sets) PAPI_TOT_CYC. If so, the dataset is ~200 rows, not 40.
"""
import re, subprocess, pathlib, collections

PR = "/opt/cray/pe/perftools/23.09.0/bin/pat_report"
BASE = pathlib.Path("/work/project/project/user/runs/sweep")
VAL = re.compile(r"^  (?P<n>[A-Z][A-Za-z0-9_:]*)\s+"
                 r"(?:(?:[\d.]+)\s*(?:[GMK]/sec|W)\s+)?"
                 r"(?P<v>\d[\d,]*(?:\.\d+)?)\s*"
                 r"(?:ops|instr|cycles|J|refs|misses|hits|secs)?\s*$")
TIME = re.compile(r"^  Thread Time\s+([\d.]+)\s+secs")

have_time = collections.Counter()
have_cyc  = collections.Counter()
ncounters = collections.Counter()
total = 0

for d in sorted(BASE.glob("*_c*")):
    if not d.is_dir():
        continue
    for s in "ABCDE":
        exp = d / f"exp_{s}"
        if not exp.exists():
            continue
        total += 1
        out = subprocess.run([PR, "-O", "hwpc", str(exp)],
                             capture_output=True, text=True, timeout=300).stdout
        t = None
        vals = {}
        for line in out.splitlines():
            if "PAT_RT_PERFCTR" in line:
                break
            mt = TIME.match(line)
            if mt:
                t = float(mt.group(1))
            m = VAL.match(line)
            if m and m.group("n") != "Thread":
                vals[m.group("n")] = m.group("v")
        if t:
            have_time[s] += 1
        if "PAPI_TOT_CYC" in vals:
            have_cyc[s] += 1
        ncounters[s] += len(vals)

print(f"experiment dirs scanned: {total}")
print()
print("per set:  dirs with Thread Time / with PAPI_TOT_CYC / avg #counters")
for s in "ABCDE":
    n = 40
    print(f"  set {s}:  {have_time[s]:3d}/{n}   {have_cyc[s]:3d}/{n}    "
          f"{ncounters[s]/max(n,1):.1f}")
print()
print("If Thread Time is present for nearly all, each set is an independent")
print("timed run and the dataset is ~200 samples rather than 40.")