mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 04:44:33 +01:00
The Huffman-coded dictionary (ab60368) made a lookup ~3x the old one's instructions, and the audio ISR looked words up: at every word start (sy_word_next) and again at every syllable (sy_take reads the word again). Now: - sing_init (felucca_init, at boot): every word the generator can sing in English (the bank's 268, SCAT_EN, the vocable) resolved once into the pool (lyb_at / lyb_ph, 1773 of 1856 B), published last (lyb_ok). sy_gen_word returns where its word sits in it. - lyr_set (the main loop: NAME, the editor, a project load): each track's TEXT lyric's words resolved with the text (lyc[]: per word its end, n, ns, the phonemes; 192 B a track), under a seqlock (odd while written: core 1 sings too); the token scan shared (sy_tok). - sy_word_next takes the word's phonemes from there; sy_take from the word's, kept per track (sing_w, the pool: sing[] and the RAM region keep their layout, so no other audio code changes). A word not there (a cache not built yet, a lyric past 192 B, its text changing that moment) is looked up as before: the same result. Cost, tests/cpu_vg.c's new peak/VOICE.EN6 (TRACKS 6: six VOICE EN tracks, three TEXT of one-syllable words, W1 W9 S3, each starting a word in the same block, 24 rounds; the instructions of that whole block, callgrind, x86-64; the same test built on each tree): worst mean 0.8.9 (front-coded bytes) 162664 155512ab60368(Huffman, in the ISR) 199747 184869 (+23 %) now 146604 141990 (-10 % against 0.8.9) added to tests/cpu_baseline_vg.txt (cpu_vg.py: peak/* the worst block of a section's rounds, not per sample). tests/target_budget.txt: formant_block (sing_block inlined) 296 -> 297 loop instructions (sy_tok and sy_take_entry kept calls); every other render loop, the RAM code (22408 B) and the RAM region (79024 B) as before. Same sound: tests/voice_test.c checks every cached word against sy_word (the 283 generator words, 79 words of nine TEXT lyrics: apostrophes, joins, melismas, capitals, long words, non-words), and renders a VOICE EN track (TEXT, W1, W7, W16, S1, S5; 54 notes each) with the caches and without, sample for sample identical (with the generator's entries corrupted it fails); hostsim / ui_test build the generator's words as the firmware does, so every golden render, demo and test runs through them: all bit for bit as before. image 540840 -> 541640 B (+800); pool 295812 -> 300016 B (spare 24672 -> 20480 B); RAM region, LOWBUF, RAM code unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
70 lines
3.2 KiB
Python
70 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
"""(JIANT 0.6.83) the audio path's CPU under valgrind (tests/cpu_vg.c): instructions per sample, section by section,
|
|
against tests/cpu_baseline_vg.txt (peak/*: instructions in the worst single block of the section's rounds). callgrind's
|
|
counts are exact (the same on every run of the same build), so the
|
|
tolerance is small: a section more than TOL over its baseline fails; one far under only notes it.
|
|
python3 tests/cpu_vg.py BINARY [BASELINE] (run_tests.sh, when valgrind is there)
|
|
BUDGET_UPDATE=1 rewrites the baseline (on purpose: look at the diff)."""
|
|
import glob, os, re, subprocess, sys, tempfile
|
|
|
|
TOL = 0.08 # +8 %: a real change, never noise
|
|
SAMPLES = 256 * 32 # cpu_vg.c NB blocks of CTL samples
|
|
|
|
binary = sys.argv[1]
|
|
base_path = sys.argv[2] if len(sys.argv) > 2 else "tests/cpu_baseline_vg.txt"
|
|
out = tempfile.mkdtemp(prefix="cpu_vg_")
|
|
prefix = os.path.join(out, "cg.out")
|
|
r = subprocess.run(["valgrind", "--tool=callgrind", "--collect-atstart=yes", "--instr-atstart=no",
|
|
f"--callgrind-out-file={prefix}", binary], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True)
|
|
if r.returncode:
|
|
print("cpu_vg: the run failed\n" + r.stderr[-2000:])
|
|
sys.exit(1)
|
|
now = {}
|
|
for f in glob.glob(prefix + "*"):
|
|
txt = open(f, errors="replace").read()
|
|
m = re.search(r"^desc: Trigger: Client Request: (\S+)", txt, re.M)
|
|
t = re.search(r"^(?:totals|summary): (\d+)", txt, re.M)
|
|
if m and t and m.group(1).startswith("peak/"): # (0.9.0) one block each: the worst of its rounds (.rNN)
|
|
k = re.sub(r"\.r\d+$", "", m.group(1))
|
|
now[k] = max(now.get(k, 0), int(t.group(1)))
|
|
elif m and t:
|
|
now[m.group(1)] = int(t.group(1)) / SAMPLES
|
|
if not now:
|
|
print("cpu_vg: no sections measured")
|
|
sys.exit(1)
|
|
|
|
base = {}
|
|
if os.path.exists(base_path):
|
|
for line in open(base_path):
|
|
p = line.split()
|
|
if len(p) == 2 and not line.startswith("#"):
|
|
base[p[0]] = float(p[1])
|
|
|
|
if os.environ.get("BUDGET_UPDATE"):
|
|
with open(base_path, "w") as fo:
|
|
fo.write("# JIANT audio path CPU under valgrind (tests/cpu_vg.c, tests/cpu_vg.py): instructions per sample,\n"
|
|
"# x86-64 gcc -O2. Exact counts; the check allows +8 %. Rewritten by BUDGET_UPDATE=1.\n")
|
|
for k in sorted(now):
|
|
fo.write(f"{k} {now[k]:.0f}\n")
|
|
print(f"cpu_vg: {len(now)} sections written to {base_path}")
|
|
sys.exit(0)
|
|
|
|
bad = 0
|
|
for k in sorted(now):
|
|
b = base.get(k)
|
|
if b is None:
|
|
print(f"cpu_vg: {k:12s} {now[k]:8.0f} instructions / sample no baseline (BUDGET_UPDATE=1 adds it)")
|
|
continue
|
|
d = now[k] / b - 1
|
|
state = "ok"
|
|
if d > TOL:
|
|
state = f"OVER BUDGET (+{d * 100:.1f} %, limit +{TOL * 100:.0f} %)"
|
|
bad += 1
|
|
elif d < -0.25:
|
|
state = f"ok, {-d * 100:.0f} % under (BUDGET_UPDATE=1 to keep it)"
|
|
unit = "instructions, the worst block" if k.startswith("peak/") else "instructions / sample"
|
|
print(f"cpu_vg: {k:12s} {now[k]:8.0f} {unit} (baseline {b:.0f}, {d * 100:+.1f} %) {state}")
|
|
print("cpu_vg: " + ("FAILED" if bad else "all within budget"))
|
|
sys.exit(1 if bad else 0)
|