From 82b99bfaa673265778df511b36ab22f0563049c0 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Fri, 9 Oct 2026 14:24:51 +0100 Subject: Batch executor, stage 5 of design 025: the sums into cells at once from round 0 (sums_in_words): the rows and e's in four bytes first (vector code) up to the first round whose e is not a whole number below 2^32, then each round's sums in turn in integers for a one- or four-byte cell while it stays in its bytes, as a number for an eight-byte cell while finite; where one is not so the executor's way goes on from that round and sum (nothing faulted or widened before it); join 4.9% fewer cycles; SUMS_SOURCE in check.py (sixteen rows met again and again, a one-byte column widened mid-batch, a four-byte one past 2^32, a masked fraction), 7,912 rounds at once and 3,228 the other way, the same three ways; seeds 1 2 3 5 23 (default and PURE_SELECT=all), the fixed sources (also sanitized) and the unit tests pass --- tests/check.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'tests/check.py') diff --git a/tests/check.py b/tests/check.py index 1d98f05..91ac114 100644 --- a/tests/check.py +++ b/tests/check.py @@ -1227,6 +1227,63 @@ on go { """ +# Sums into cells in whole numbers (SUMS_SOURCE, docs/design/025's stage 5): +# sixteen rows met again and again, a one-byte column widened to four in the +# middle of a batch, a four-byte one past 2^32 (to eight), and a masked +# fraction where the whole numbers stop. +SUMS_SOURCE = """record Total { + region = 0 + amount = 0 +} +state totals = 0 +state tinies = 0 +state bigs = 0 +state mixed = 0 +input go = message { + n: u32 + q: u32 +} +on go { + let t: list of Total by region + let u: list of Total by region + let w: list of Total by region + let m: list of Total by region + for r in 0 .. 16 { + t.add(Total { region: r }) + u.add(Total { region: r }) + w.add(Total { region: r }) + m.add(Total { region: r }) + } + for o in 0 .. go.n { + let region = o - floor(o / 16) * 16 + t[region].amount = t[region].amount + (o - floor(o / 1000) * 1000) + u[region].amount = u[region].amount + 1 + w[region].amount = w[region].amount + 1500000000 + if o - floor(o / go.q) * go.q == 0 { m[region].amount = m[region].amount + 0.5 } + } + let a = 0 + let b = 0 + let c = 0 + let d = 0 + for x in t { + a = a + x.amount * (x.region + 1) + } + for x in u { + b = b + x.amount * (x.region + 1) + } + for x in w { + c = c + x.amount + } + for x in m { + d = d + x.amount * (x.region + 1) + } + totals = a + tinies = b + bigs = c + mixed = d +} +""" + # Columns read in place (VIEW_SOURCE, docs/design/025's stage 4): a local # holding a row's field while the batch sets that field (its last value # written back after the sets), a set whose value is the same column three @@ -1758,6 +1815,19 @@ def module_assumptions(aup, pure, work): assert outputs[name] == outputs['batches'], ('reduce', name, next((a, b) for a, b in zip(outputs[name].splitlines(), outputs['batches'].splitlines()) if a != b)) faults = [json.loads(line)['fault'] for line in outputs['batches'].splitlines() if line.startswith('{"states"')] assert 'none' in faults and 'work' in faults, faults + source, program = work / 'sums.aup', work / 'sums.pmod' # sums into cells in whole numbers, against the rounds one by one + source.write_text(SUMS_SOURCE) + compile_module(aup, source, program) + given = ''.join(f'message go {struct.pack("