diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 81b1644fc..5fb177b3b 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -305,7 +305,7 @@ changes the harness sets the base for the next. | `metric` | A deterministic count per frame or per command buffer: submissions, passes, barriers, bytes copied, pipelines created | It is larger than the base's | | `instructions` | User-space CPU instructions per draw or per dispatch | It is more than 1% over the base's | | `gauge` | Live objects of one resource kind, the key ending in the point it was read at: `@100` and `@200` (loop iterations), `@drop` (after the device dropped) | `@drop` is not 0, or `@200` differs from `@100`; for the memory pool's `blocks`, which frees allocations an earlier workload left idle once the most bytes in use over its window falls and the device is quiet for 20 ms, only `@200` over `@100` | -| `time` | A duration in microseconds: what a program waits on in a harness workload's run, timed on the host: its last command buffer's commit-to-complete time where the workload times it (the others' lateness is a column of the harness's table and no record), else the host wall time a run adds (a run's GPU time is a record of its own, `harness-gpu-/`, parked) | Only as a cross-GPU outlier: its ratio to the base's is more than 1.25 times the median of that ratio over at least 3 GPUs | +| `time` | A duration in microseconds: what a program waits on in a harness workload's run, timed on the host: its last command buffer's commit-to-complete time where the workload times it (the others' lateness is a column of the harness's table and no record), else the host wall time a run adds (a run's GPU time is a record of its own, `harness-gpu-/`, parked here and judged by the harness budget) | Only as a cross-GPU outlier: its ratio to the base's is more than 1.25 times the median of that ratio over at least 3 GPUs | | `size` | The size a harness row whose size follows the device ran at (`long_4cb`) | The leg's two runtimes ran the row at different sizes: its times are then not compared (the harness budget) | Every cache has a test that fills it past its capacity and records its gauge. @@ -343,7 +343,15 @@ and the parked records. On each GPU, a harness row timed on both runtimes in the the old's, times the row's floor on that GPU where it has one: the widest ratio between two of the old runtime's own runs of the row there (`scripts/matrix/floors.tsv`, measured again when the harness or the old runtime's build changes), so a difference within the old runtime's own spread -is not the new runtime's. A row over it fails its leg unless a ruling, made after the work on that +is not the new runtime's. A row with a GPU time on both runtimes is judged on its GPU time +instead, against the floor of the old runtime's GPU time from the same runs +(`scripts/matrix/gpu-floors.tsv`), its times shown beside it: a single kernel's GPU time spreads +a few percent where its host time spreads up to 1.3 (the XTX's `simd_reduce`: GPU p50 36.96-37.12 +µs over 8 runs, host time 44.9-55.8 µs). The frame and burst rows (`WALL_ROWS` in +`scripts/matrix/results.py`), whose GPU time spans the gaps between their command buffers and +spreads as widely, stay on their times and the instructions gate. A row whose GPU time varies on +one card itself (`CARD_VARIANCE`: the XTX's `sampling` and `constant_managed`) is named on the +leg's line as the card's variance and fails nothing. A row over it fails its leg unless a ruling, made after the work on that row, gave it a ceiling on that GPU (`HARNESS_CEILINGS` in `scripts/matrix/results.py`); a ceiling is never taken from a measured ratio, and the greater of a row's ceiling and floor sets its limit. A listed row fails its leg past its ceiling times 1.03, the noise allowance parity gets, and one @@ -357,14 +365,15 @@ included, are given that size (the harness's `--size`); each run records it as `size harness-/`, and a row the two runtimes ran at different sizes fails, uncompared, its times measuring different work. A row over its limit is re-timed once in its leg before the leg ends: two pairs of runs of the row -alone, old then new, then new then old (A B B A). It fails only if the median of the pairs' ratios -is past its limit too. A leg re-times at most 8 rows, the furthest over first; a row it does not -re-time is judged by its one time. The pairs are kept as `harness-retime///` records, parked for the -`time` rule. +alone, old then new, then new then old (A B B A). It fails only if the median of the pairs' ratios, +of the times it is judged on, is past its limit too. A leg re-times at most 8 rows, the furthest +over first; a row it does not re-time is judged by its one time. The pairs are kept as +`harness-retime///` and `harness-retime-gpu///` records, +parked for the `time` rule. Each row's GPU time on each runtime, the p50 over its timed runs of a run's first GPU start to its -last GPU end, is recorded as `time harness-gpu-/` where the row has one. It is -judged by nothing: the budget's lines show it beside the row's times, and it is parked for the -`time` rule. `run` and `show` print, under each leg's line, every harness row's time and GPU time +last GPU end, is recorded as `time harness-gpu-/` where the row has one. The budget +judges a row on it as above, and shows it beside the times of a row it does not judge on it; it is +parked for the `time` rule. `run` and `show` print, under each leg's line, every harness row's time and GPU time on both runtimes and the ratio of the times. The budget goes with the old runtime. diff --git a/scripts/matrix/gpu-floors.tsv b/scripts/matrix/gpu-floors.tsv new file mode 100644 index 000000000..beac21413 --- /dev/null +++ b/scripts/matrix/gpu-floors.tsv @@ -0,0 +1,28 @@ +# The old runtime's own spread of each harness row's GPU time per GPU leg: the widest ratio +# between two of its runs' GPU p50 (`harness-gpu-old/`) in one leg, the largest of its times +# over the smallest. results.HARNESS_GPU_FLOORS reads it, for the rows judged on their GPU time +# (results.gpu_judged): the frame and burst rows, judged on their host time, have none here, and +# any other row or leg missing here has a GPU floor of 1. From the same runs as +# floors.tsv: the harness of 4cc7963005, 4 runs of `harness --runtime old` per leg in the order +# A B B A (8 on 1002:744c, A B B A twice), each its own process with a fresh driver shader cache +# and store. Floors here, not reds: 8086:3e9b texture_read 1.075 and 8086:a7a0 wide_bindings 1.097 +# are those GPUs' own spread. 1002:744c sampling 1.246 and constant_managed 1.115 are that card's +# own variance in GPU time (results.CARD_VARIANCE). +row 1002:15bf 1002:1900 1002:699f 1002:744c 10de:1e87 10de:2204 8086:3e9b 8086:a7a0 +alu 1.015 1.017 1.000 1.007 1.011 1.034 1.012 1.000 +bandwidth 1.011 1.008 1.000 1.003 1.001 1.002 1.021 1.010 +constant_managed 1.004 1.002 1.006 1.115 1.011 1.004 1.000 1.001 +constant_private 1.015 1.002 1.002 1.026 1.009 1.013 1.000 1.000 +constexpr_sampling 1.003 1.013 1.000 1.024 1.006 1.002 1.004 1.018 +dispatch_chain 1.048 1.024 1.006 1.007 1.007 1.001 1.016 1.005 +image_filter 1.000 1.009 1.000 1.012 1.003 1.003 1.008 1.003 +long_4cb 1.011 1.017 1.000 1.003 1.018 1.006 1.000 1.000 +narrow_ints 1.003 1.002 1.000 1.008 1.006 1.018 1.000 1.000 +sampling 1.020 1.006 1.001 1.246 1.001 1.003 1.069 1.003 +simd_reduce 1.005 1.004 1.001 1.004 1.002 1.003 1.030 1.006 +texture_read 1.002 1.012 1.002 1.009 1.002 1.038 1.075 1.014 +threadgroup_scan 1.001 1.009 1.001 1.050 1.008 1.004 1.006 1.001 +vote_loop 1.002 1.002 1.000 1.025 1.008 1.028 1.000 1.000 +waves 1.001 1.004 1.000 1.003 1.001 1.009 1.000 1.008 +wide_bindings 1.029 1.025 1.001 1.002 1.021 1.000 1.001 1.097 +zero_products 1.005 1.002 1.000 1.025 1.000 1.015 1.001 1.000 diff --git a/scripts/matrix/matrix b/scripts/matrix/matrix index d62ddee55..997e8e7d4 100755 --- a/scripts/matrix/matrix +++ b/scripts/matrix/matrix @@ -285,7 +285,7 @@ def harness_runs(manifest_dir, command, leg, windows=False): processes. After the last runtime's runs, before its suite's line, the rows over their limits (results.RETIME_SELECT, at most results.RETIME_ROWS, the furthest over first) are each re-timed alone in results.RETIME_PAIRS pairs, old then new, then new then old, their - times kept as harness-retime/// (results.harness_budget). A row whose size + times and GPU times kept (results.RETIME_KEEP) for results.harness_budget. A row whose size follows the device is sized by the first runtime's run, and every later run, warm and re-timed ones included, is given that size (`--size`), so each runtime times the same work. Each runtime's main run also has a fresh empty store for its pipelines (`--store`), so its first @@ -303,10 +303,11 @@ def harness_runs(manifest_dir, command, leg, windows=False): unprofile = '\n export LOCALAPPDATA="$saved_local" USERPROFILE="$saved_profile"' creates = f"'{results.HARNESS_CREATES}*'" rename = r"s#^M2V-MATRIX \([a-z]*\) harness-$runtime/\([a-z]*\)/first_use_#M2V-MATRIX \1 harness-$runtime-warm/\2/first_use_#p" - retime = r"s#^M2V-MATRIX time harness-$timed/$row #M2V-MATRIX time harness-retime/$row/$pair/$timed #p" outputs = " ".join(f'"$out/{runtime}"' for runtime in HARNESS_RUNTIMES) - limits = "\n".join(f" {leg_id}) limits='{results.harness_limits(leg_id)}' ;;" - for leg_id in sorted(set(results.HARNESS_CEILINGS) | set(results.HARNESS_FLOORS))) + limits = "\n".join(f" {leg_id}) limits='{results.harness_limits(leg_id)}' " + f"gpulimits='{results.harness_limits(leg_id, gpu=True)}' ;;" + for leg_id in sorted(set(results.HARNESS_CEILINGS) | set(results.HARNESS_FLOORS) + | set(results.HARNESS_GPU_FLOORS))) sized = r"s#^\([a-z0-9_]*\) *[a-z]* *sized to \([0-9][0-9]*\) .*#--size \1=\2#p" return f"""rc=0 out=$(mktemp -d) || exit 3 @@ -338,15 +339,15 @@ def harness_runs(manifest_dir, command, leg, windows=False): if [ "$runtime" = {HARNESS_RUNTIMES[-1]} ]; then case "{leg}" in {limits} - *) limits= ;; + *) limits= gpulimits= ;; esac select='{results.RETIME_SELECT}' - rows=$(awk -v limits="$limits" -v budget={results.HARNESS_BUDGET!r} "$select" {outputs} | sort -rn | head -n {results.RETIME_ROWS} | cut -d' ' -f2) + rows=$(awk -v limits="$limits" -v gpulimits="$gpulimits" -v wallre='{results.WALL_RE}' -v budget={results.HARNESS_BUDGET!r} "$select" {outputs} | sort -rn | head -n {results.RETIME_ROWS} | cut -d' ' -f2) for row in $rows; do for pair in $(seq {results.RETIME_PAIRS}); do case $pair in 2) order="new old" ;; *) order="old new" ;; esac for timed in $order; do - CARGO_MANIFEST_DIR={manifest_dir} {command} --runtime $timed $sizes --only "$row" 2>&1 | sed -n "{retime}" + CARGO_MANIFEST_DIR={manifest_dir} {command} --runtime $timed $sizes --only "$row" 2>&1 | sed -n "{results.RETIME_KEEP}" done done done diff --git a/scripts/matrix/results.py b/scripts/matrix/results.py index 10198af1a..4ba174b8d 100644 --- a/scripts/matrix/results.py +++ b/scripts/matrix/results.py @@ -70,10 +70,10 @@ PARKED_TESTS = { #: entries the cold run just wrote, a fraction of a millisecond on Mesa. So are the re-timed pairs #: of a row over its budget (harness-retime/, RETIME_PAIRS), and the creation rows' first samples #: from the later processes (harness-first/, FIRST_RUNS): harness_budget judges them. So are the -#: rows' GPU times (harness-gpu-/, HARNESS_GPU): reported beside the times the budget -#: judges, and judged by nothing. +#: rows' GPU times (harness-gpu-/, HARNESS_GPU) and their re-timed pairs' +#: (harness-retime-gpu/): harness_budget judges a row on its GPU time where gpu_judged says so. PARKED_RECORDS = ("harness-old/", "harness-new-warm/", "harness-retime/", "harness-first/", - "harness-gpu-") + "harness-gpu-", "harness-retime-gpu/") #: The phrase that opens the subject of a commit allowed to change the old runtime's output: until #: the cutover, the translator's output through `Device::new` moves only in such a commit. Only the @@ -297,10 +297,13 @@ def time_outliers(times, bases): #: The harness budget: on each GPU, a harness row's time on the new runtime over its time on the -#: old, both timed in the same leg, is at most this. A row's time is what a program waits on, timed -#: on the host (the harness's `run::matrix_time`): a run's mean commit-to-complete time where the -#: row times its command buffers', else the host wall time a run adds; a run's GPU time is -#: reported beside it (HARNESS_GPU) and judged by nothing. It is a rule of its own, apart from +#: old, both timed in the same leg, is at most this. A row with a GPU time on both runtimes is +#: judged on it (gpu_judged), its host time shown beside it: on the GPUs measured, the old +#: runtime's own spread of a single kernel's GPU time is a few percent where its host time spreads +#: up to 1.3 (gpu-floors.tsv against floors.tsv). The others, and the frame and burst rows +#: (WALL_ROWS), are judged on their time as a program waits on it, timed on the host (the +#: harness's `run::matrix_time`): a run's mean commit-to-complete time where the row times its +#: command buffers', else the host wall time a run adds. It is a rule of its own, apart from #: TIME_OUTLIER and PARKED_RECORDS: those judge a time against its base commit's across GPUs and #: park the old runtime's outliers, while this compares the two runtimes within one leg, the old #: runtime's time the reference. It ends with the cutover, with the old runtime. @@ -309,9 +312,35 @@ HARNESS_NEW = "harness-new/" HARNESS_OLD = "harness-old/" #: A harness row's GPU time on each runtime, `harness-gpu-/`: the p50 over its timed #: runs of a run's first GPU start to its last GPU end, scaled like its time where the device -#: sizes the row, and absent where the row has none. harness_budget's lines and harness_rows show -#: it beside the row's time; it is parked (PARKED_RECORDS), so no rule judges it. +#: sizes the row, and absent where the row has none. harness_budget judges a row on it where +#: gpu_judged says so, and shows it beside the row's time otherwise; it is parked for TIME_OUTLIER +#: (PARKED_RECORDS). HARNESS_GPU = "harness-gpu-" +#: The rows judged on their host time even where they have a GPU time, by the start of their +#: names: a frame's or a burst's command buffers, whose GPU time spans the gaps between them and +#: spreads on the old runtime as widely as the host time on several GPUs (gpu-floors.tsv's +#: measurement: 1.68 on the Iris Xe's frame_5cb, 1.43 on the UHD 630's burst_160_shared). The +#: planner's ruling: these keep the host time's floor and the instructions gate. +WALL_ROWS = ("frame", "burst") +#: WALL_ROWS as the re-time selection's awk pattern. +WALL_RE = "^(" + "|".join(WALL_ROWS) + ")" +#: Rows whose GPU time varies on one card itself, by GPU leg, with what was seen: harness_budget +#: judges them on their GPU time against their GPU floor like any other, never fails a leg for +#: them, and names them as the card's variance, so no one chases them as the new runtime's. +CARD_VARIANCE = { + "1002:744c": { + "sampling": "its GPU p50 on the old runtime ran 16.3-20.3 us over 8 runs (m3-max-45546)", + "constant_managed": "its GPU p50 on the old runtime is 66.8-69.2 or 74.4 us run to run " + "(m3-max-45546)", + }, +} + + +def gpu_judged(times, row): + """Whether harness_budget judges ROW on its GPU time: it has one on both runtimes in TIMES, and + it is not a WALL_ROWS row.""" + return not row.startswith(WALL_ROWS) and all( + (times.get(f"{HARNESS_GPU}{runtime}/{row}") or 0) > 0 for runtime in ("old", "new")) def gpu_beside(times, runtime, row): @@ -321,7 +350,8 @@ def gpu_beside(times, runtime, row): #: The harness rows over HARNESS_BUDGET that a ruling gave a ceiling, per GPU leg, each a ratio of -#: host times: a row past its ceiling fails its leg, so an open row can neither hide nor grow. A +#: the times its row is judged on (gpu_judged): a row past its ceiling fails its leg, so an open +#: row can neither hide nor grow. A #: ceiling is ruled after the work on its row, never taken from a measured ratio; a fix lowers it #: to the ratio the row then reaches, and a row within HARNESS_BUDGET leaves the list. A row over #: HARNESS_BUDGET with no ceiling fails its leg. @@ -352,29 +382,39 @@ def read_floors(text): #: The old runtime's own spread per harness row on each GPU leg, the row's floor: the widest ratio #: between two of the old runtime's runs of the row in one leg, old over old (`floors.tsv`, beside -#: this file). A row is past its limit only past HARNESS_BUDGET times the greater of its floor and -#: its ceiling (row_limit): a difference within the old runtime's own spread is not the new -#: runtime's. The table is measured again when the harness or the old runtime's build changes; a -#: row or leg it does not list has a floor of 1. +#: this file), of its host time; HARNESS_GPU_FLOORS is the same of its GPU time (`gpu-floors.tsv`, +#: from the same runs), the floor of a row judged on it (gpu_judged). A row is past its limit only +#: past HARNESS_BUDGET times the greater of its floor and its ceiling (row_limit): a difference +#: within the old runtime's own spread is not the new runtime's. The tables are measured again +#: when the harness or the old runtime's build changes; a row or leg one does not list has a floor +#: of 1 there. HARNESS_FLOORS = read_floors((Path(__file__).resolve().parent / "floors.tsv").read_text()) +HARNESS_GPU_FLOORS = read_floors((Path(__file__).resolve().parent / "gpu-floors.tsv").read_text()) -def row_limit(leg_id, row): +def row_floor(leg_id, row, gpu=False): + """ROW's floor on LEG_ID: of its GPU time where GPU, else of its host time; 1 where none is + listed.""" + return (HARNESS_GPU_FLOORS if gpu else HARNESS_FLOORS).get(leg_id, {}).get(row, 1.0) + + +def row_limit(leg_id, row, gpu=False): """ROW's limit on LEG_ID, new over old: HARNESS_BUDGET times the greater of its ceiling - (HARNESS_CEILINGS) and its floor (HARNESS_FLOORS), each 1 where none is listed.""" + (HARNESS_CEILINGS) and its floor (row_floor, of its GPU time where GPU), each 1 where none is + listed.""" return HARNESS_BUDGET * max(HARNESS_CEILINGS.get(leg_id, {}).get(row, 1.0), - HARNESS_FLOORS.get(leg_id, {}).get(row, 1.0)) + row_floor(leg_id, row, gpu)) -def past_limit(leg_id, row): - """How a line names ROW's limit on LEG_ID once past it: the budget, or its ceiling or floor, - whichever sets it, with the allowance.""" +def past_limit(leg_id, row, gpu=False): + """How a line names ROW's limit on LEG_ID once past it: the budget, or its ceiling or floor + (its GPU floor where GPU), whichever sets it, with the allowance.""" ceiling = HARNESS_CEILINGS.get(leg_id, {}).get(row, 1.0) - floor = HARNESS_FLOORS.get(leg_id, {}).get(row, 1.0) + floor = row_floor(leg_id, row, gpu) if max(ceiling, floor) <= 1.0: return f"past {HARNESS_BUDGET}" - name, value = ("ceiling", ceiling) if ceiling >= floor else ("floor", floor) - return f"past its {name} {value} with its allowance, {row_limit(leg_id, row):.3f}" + name, value = ("ceiling", ceiling) if ceiling >= floor else ("GPU floor" if gpu else "floor", floor) + return f"past its {name} {value} with its allowance, {row_limit(leg_id, row, gpu):.3f}" #: The harness's creation rows, by the start of their names. A leg times them apart from the @@ -419,44 +459,62 @@ def first_samples(times, row): #: A row over its limit in a leg (row_limit) is re-timed once in that leg before the leg ends #: (the matrix's harness_runs): RETIME_PAIRS pairs of runs of the row alone, old then new, then new -#: then old (A B B A), kept as -#: `harness-retime///`. harness_budget judges such a row by the median of its -#: pairs' ratios, new over old, so a clock episode in one run decides nothing while a regression in -#: every pair still fails. At most RETIME_ROWS rows of a leg, the furthest over first; a row that -#: was not re-timed is judged by its one time. +#: then old (A B B A), its times kept as `harness-retime///` and its GPU times +#: as `harness-retime-gpu///` (RETIME_KEEP). harness_budget judges such a row +#: by the median of its pairs' ratios, new over old, of the times it judges the row on, so a clock +#: episode in one run decides nothing while a regression in every pair still fails. At most +#: RETIME_ROWS rows of a leg, the furthest over first; a row that was not re-timed is judged by its +#: one time. RETIME_PAIRS = 2 RETIME_ROWS = 8 HARNESS_RETIME = "harness-retime/" +HARNESS_RETIME_GPU = "harness-retime-gpu/" +#: The sed program (`sed -n`) each re-timed run's output goes through: the row's time and GPU time +#: alone, the shell giving `$timed`, `$row` and `$pair`. +RETIME_KEEP = (r"s#^M2V-MATRIX time harness-$timed/$row #M2V-MATRIX time harness-retime/$row/$pair/$timed #p;" + r"s#^M2V-MATRIX time harness-gpu-$timed/$row #M2V-MATRIX time harness-retime-gpu/$row/$pair/$timed #p") #: The awk program the leg runs over its runtimes' output to choose the rows it re-times: each row -#: timed on both whose ratio, new over old, is over its limit, as `ratio row`. Its limit is LIMITS' -#: (`row=limit ...`, harness_limits) or BUDGET: harness_budget's comparison, of the same decimals. -RETIME_SELECT = r"""BEGIN { n = split(limits, l, " "); for (i = 1; i <= n; i++) { split(l[i], p, "="); limit[p[1]] = p[2] } } +#: timed on both whose ratio, new over old, is over its limit, as `ratio row`: of its GPU times +#: where it has them on both and does not match WALLRE (gpu_judged), against GPULIMITS', else of +#: its times, against LIMITS' (`row=limit ...`, harness_limits), or BUDGET where a row has no +#: limit listed: harness_budget's comparison, of the same decimals. +RETIME_SELECT = r"""function read(text, into, n, i, l, p) { n = split(text, l, " "); for (i = 1; i <= n; i++) { split(l[i], p, "="); into[p[1]] = p[2] } } +BEGIN { read(limits, limit); read(gpulimits, glimit) } $1 == "M2V-MATRIX" && $2 == "time" && $3 ~ /^harness-(old|new)\/[^\/]+$/ { split($3, k, "/"); t[k[1] "/" k[2]] = $4; rows[k[2]] = 1 } +$1 == "M2V-MATRIX" && $2 == "time" && $3 ~ /^harness-gpu-(old|new)\/[^\/]+$/ { + split($3, k, "/"); g[k[1] "/" k[2]] = $4 +} END { for (row in rows) { old = t["harness-old/" row]; new = t["harness-new/" row] if (old == "" || new == "" || old + 0 <= 0) continue - m = (row in limit) ? limit[row] + 0 : budget + 0 - if (new / old > m) printf "%.6f %s\n", new / old, row + gold = g["harness-gpu-old/" row] + 0; gnew = g["harness-gpu-new/" row] + 0 + if (row !~ wallre && gold > 0 && gnew > 0) { r = gnew / gold; m = (row in glimit) ? glimit[row] + 0 : budget + 0 } + else { r = new / old; m = (row in limit) ? limit[row] + 0 : budget + 0 } + if (r > m) printf "%.6f %s\n", r, row } }""" -def harness_limits(leg_id): - """The rows of LEG_ID with a ceiling or a floor as RETIME_SELECT's LIMITS, `row=limit ...`: - each its row_limit, written so that it reads back as the same double.""" - rows = set(HARNESS_CEILINGS.get(leg_id, {})) | set(HARNESS_FLOORS.get(leg_id, {})) - return " ".join(f"{row}={row_limit(leg_id, row)!r}" for row in sorted(rows) - if row_limit(leg_id, row) != HARNESS_BUDGET) +def harness_limits(leg_id, gpu=False): + """The rows of LEG_ID with a ceiling or a floor (of their GPU time where GPU) as + RETIME_SELECT's LIMITS (GPULIMITS where GPU), `row=limit ...`: each its row_limit, written so + that it reads back as the same double.""" + floors = HARNESS_GPU_FLOORS if gpu else HARNESS_FLOORS + rows = set(HARNESS_CEILINGS.get(leg_id, {})) | set(floors.get(leg_id, {})) + return " ".join(f"{row}={row_limit(leg_id, row, gpu)!r}" for row in sorted(rows) + if row_limit(leg_id, row, gpu) != HARNESS_BUDGET) -def retimed(times, row): - """ROW's re-timed pairs' ratios, new over old, in pair order; None unless every pair has both.""" +def retimed(times, row, gpu=False): + """ROW's re-timed pairs' ratios, new over old, of its GPU times where GPU, else of its times, in + pair order; None unless every pair has both.""" + kept = HARNESS_RETIME_GPU if gpu else HARNESS_RETIME ratios = [] for pair in range(1, RETIME_PAIRS + 1): - old, new = (times.get(f"{HARNESS_RETIME}{row}/{pair}/{runtime}") for runtime in ("old", "new")) + old, new = (times.get(f"{kept}{row}/{pair}/{runtime}") for runtime in ("old", "new")) if not old or new is None: return None ratios.append(new / old) @@ -466,7 +524,11 @@ def retimed(times, row): def harness_budget(leg_id, leg): """The harness budget on LEG, the parsed leg LEG_ID: each row timed on both runtimes (`harness-new/` and `harness-old/`) against its limit, row_limit: HARNESS_BUDGET times - the greater of its ceiling (HARNESS_CEILINGS) and its floor (HARNESS_FLOORS). Returns + the greater of its ceiling (HARNESS_CEILINGS) and its floor. A row with a GPU time on both + runtimes that is not a WALL_ROWS row (gpu_judged) is judged on its GPU times against its GPU + floor (HARNESS_GPU_FLOORS), its times shown beside them; any other on its times against its + floor (HARNESS_FLOORS). A CARD_VARIANCE row is never a problem: past its limit, or over the + budget within it, it is named with what its card was seen to do. Returns (problems, parked): a row past its limit is a problem, and so is a row whose time was recorded more than once (twice by a suite, or by two suites), which has no one time to judge. A row past its limit that the leg re-timed (RETIME_PAIRS) is judged by the median of its pairs' ratios @@ -521,22 +583,34 @@ def harness_budget(leg_id, leg): elif row in ceilings: parked.append(f"{line}, its ceiling {ceilings[row]}") continue - ratio = new / old - line = (f"harness budget {row}: new {new:.1f} us{gpu_beside(times, 'new', row)} over old " - f"{old:.1f} us{gpu_beside(times, 'old', row)} is {ratio:.3f}") + gpu = gpu_judged(times, row) + if gpu: + limit = row_limit(leg_id, row, gpu) + gnew, gold = (times[f"{HARNESS_GPU}{runtime}/{row}"] for runtime in ("new", "old")) + ratio = gnew / gold + line = (f"harness budget {row}: GPU p50 new {gnew:.1f} us over old {gold:.1f} us is " + f"{ratio:.3f} (time new {new:.1f} us over old {old:.1f} us is {new / old:.3f})") + else: + ratio = new / old + line = (f"harness budget {row}: new {new:.1f} us{gpu_beside(times, 'new', row)} over old " + f"{old:.1f} us{gpu_beside(times, 'old', row)} is {ratio:.3f}") + variance = CARD_VARIANCE.get(leg_id, {}).get(row) if ratio > limit: - past = f"{line}, {past_limit(leg_id, row)}" - ratios = retimed(times, row) - if ratios is None: - problems.append(past) - continue - median = statistics.median(ratios) - pairs = (f"{past}; re-timed in {RETIME_PAIRS} pairs, " - f"{', '.join(f'{r:.3f}' for r in ratios)}, median {median:.3f}") - if median > limit: - problems.append(pairs) + past = f"{line}, {past_limit(leg_id, row, gpu)}" + ratios = retimed(times, row, gpu) + if ratios is not None: + median = statistics.median(ratios) + past = (f"{past}; re-timed in {RETIME_PAIRS} pairs, " + f"{', '.join(f'{r:.3f}' for r in ratios)}, median {median:.3f}") + if median <= limit: + parked.append(f"{past}, within: judged by the median") + continue + if variance: + parked.append(f"{past}: the card's own variance, not judged ({variance})") else: - parked.append(f"{pairs}, within: judged by the median") + problems.append(past) + elif variance and ratio > HARNESS_BUDGET: + parked.append(f"{line}, within its limit: the card's own variance ({variance})") elif row not in ceilings: continue elif ratio > HARNESS_BUDGET: diff --git a/scripts/matrix/test_results.py b/scripts/matrix/test_results.py index 937c83c21..47587e32e 100644 --- a/scripts/matrix/test_results.py +++ b/scripts/matrix/test_results.py @@ -8,10 +8,14 @@ the summary, then each test's captured output, indented, after a header naming t import subprocess import unittest +from pathlib import Path from unittest import mock import results +#: The cards' variance rows as stored, before a test patches them away. +CARD_VARIANCE_STORED = results.CARD_VARIANCE + NEXTEST = """\ Starting 3 tests across 1 binary FAIL [ 0.002s] (1/3) metal2vulkan-rt tests::breaks @@ -228,10 +232,20 @@ class RuleTests(unittest.TestCase): class HarnessBudgetTests(unittest.TestCase): def setUp(self): - # The rules below on no floors unless a test gives its own. - floors = mock.patch.object(results, "HARNESS_FLOORS", {}) - floors.start() - self.addCleanup(floors.stop) + # The rules below on no floors and no card's variance unless a test gives its own. + for name in ("HARNESS_FLOORS", "HARNESS_GPU_FLOORS", "CARD_VARIANCE"): + patch = mock.patch.object(results, name, {}) + patch.start() + self.addCleanup(patch.stop) + + def select(self, leg_id, lines): + """The rows the leg's re-time selection chooses from LINES, as the matrix runs it.""" + run = subprocess.run(["awk", "-v", f"limits={results.harness_limits(leg_id)}", "-v", + f"gpulimits={results.harness_limits(leg_id, gpu=True)}", "-v", + f"wallre={results.WALL_RE}", "-v", f"budget={results.HARNESS_BUDGET!r}", + results.RETIME_SELECT], + input="\n".join(lines) + "\n", capture_output=True, text=True, check=True) + return sorted(line.split()[1] for line in run.stdout.splitlines()) def budget(self, leg_id, times): return results.harness_budget(leg_id, leg_of(recs(time=times))) @@ -447,10 +461,17 @@ class HarnessBudgetTests(unittest.TestCase): def test_the_floors_table_reads_per_leg_and_row(self): text = "# a comment\nrow a b\nframe 1.10 -\nalu 1.00 1.02\n" self.assertEqual(results.read_floors(text), {"a": {"frame": 1.1, "alu": 1.0}, "b": {"alu": 1.02}}) - # The stored table: every floor is a ratio of at least 1, on a leg id. - for leg, rows in results.HARNESS_FLOORS.items(): - self.assertRegex(leg, r"^[0-9a-f]{4}:[0-9a-f]{4}$") - self.assertTrue(all(value >= 1.0 for value in rows.values()), leg) + # The stored tables: every floor is a ratio of at least 1, on a leg id; the GPU floors name no + # row judged on its host time, and each card's variance row has a GPU floor. + floors = results.read_floors((Path(results.__file__).parent / "floors.tsv").read_text()) + gpu_floors = results.read_floors((Path(results.__file__).parent / "gpu-floors.tsv").read_text()) + for table in (floors, gpu_floors): + for leg, rows in table.items(): + self.assertRegex(leg, r"^[0-9a-f]{4}:[0-9a-f]{4}$") + self.assertTrue(all(value >= 1.0 for value in rows.values()), leg) + self.assertFalse([row for rows in gpu_floors.values() for row in rows if row.startswith(results.WALL_ROWS)]) + for leg, rows in CARD_VARIANCE_STORED.items(): + self.assertTrue(set(rows) <= set(gpu_floors[leg]), leg) def test_a_leg_re_times_the_rows_the_budget_would_fail_on_their_one_time(self): ceilings = {"a": {"listed": 2.0, "edge": 2.0}} @@ -461,10 +482,7 @@ class HarnessBudgetTests(unittest.TestCase): lines += ["M2V-MATRIX time harness-new/authored/first_use_wait_total 900.000", "M2V-MATRIX gauge harness-new/alu/buffers@100 2", "a table row"] with mock.patch.object(results, "HARNESS_CEILINGS", ceilings): - run = subprocess.run(["awk", "-v", f"limits={results.harness_limits('a')}", "-v", - f"budget={results.HARNESS_BUDGET!r}", results.RETIME_SELECT], - input="\n".join(lines) + "\n", capture_output=True, text=True, check=True) - chosen = sorted(line.split()[1] for line in run.stdout.splitlines()) + chosen = self.select("a", lines) records = {f"harness-{runtime}/{row}": pair[i] for row, pair in times.items() for i, runtime in enumerate(("old", "new"))} failed = sorted(line.split()[2].rstrip(":") for line in self.budget("a", records)[0]) @@ -475,32 +493,95 @@ class HarnessBudgetTests(unittest.TestCase): def test_re_timed_pairs_are_parked_records(self): self.assertTrue(f"{results.HARNESS_RETIME}vote_loop/1/new".startswith(results.PARKED_RECORDS)) + self.assertTrue(f"{results.HARNESS_RETIME_GPU}vote_loop/1/new".startswith(results.PARKED_RECORDS)) - def test_a_row_s_gpu_time_is_shown_beside_its_time_and_judged_by_nothing(self): + def test_a_row_with_a_gpu_time_is_judged_on_it_and_a_frame_or_burst_row_on_its_time(self): times = {"harness-old/frame": 100.0, "harness-new/frame": 120.0, "harness-gpu-old/frame": 80.25, "harness-gpu-new/frame": 81.0, + "harness-old/burst_160": 100.0, "harness-new/burst_160": 101.0, + "harness-gpu-old/burst_160": 50.0, "harness-gpu-new/burst_160": 90.0, "harness-old/alu": 100.0, "harness-new/alu": 100.0, - "harness-gpu-old/alu": 10.0, "harness-gpu-new/alu": 900.0} + "harness-gpu-old/alu": 10.0, "harness-gpu-new/alu": 900.0, + "harness-old/simd_reduce": 45.0, "harness-new/simd_reduce": 55.0, + "harness-gpu-old/simd_reduce": 37.0, "harness-gpu-new/simd_reduce": 37.1} + frame = ("harness budget frame: new 120.0 us (GPU p50 81.0 us) over old 100.0 us (GPU p50 80.2 us) " + "is 1.200, past 1.03") + alu = ("harness budget alu: GPU p50 new 900.0 us over old 10.0 us is 90.000 (time new 100.0 us over old " + "100.0 us is 1.000), past 1.03") with mock.patch.object(results, "HARNESS_CEILINGS", {}): - self.assertEqual(self.budget("a", times), ([ - "harness budget frame: new 120.0 us (GPU p50 81.0 us) over old 100.0 us (GPU p50 80.2 us) " - "is 1.200, past 1.03"], [])) - # Only one runtime's GPU time: the other's line shows none. - del times["harness-gpu-old/frame"] + # alu is past on its GPU time, its time level; simd_reduce is within on its GPU time, its + # time 1.22 past; frame is judged on its time, burst_160 on its time, whatever their GPU's. + self.assertEqual(self.budget("a", times), ([alu, frame], [])) + self.assertTrue(results.gpu_judged(times, "alu")) + self.assertFalse(results.gpu_judged(times, "burst_160")) + # Only one runtime's GPU time: the row is judged on its time, the other's line showing none. + del times["harness-gpu-old/frame"], times["harness-gpu-old/alu"] self.assertEqual(self.budget("a", times)[0], [ "harness budget frame: new 120.0 us (GPU p50 81.0 us) over old 100.0 us is 1.200, past 1.03"]) + # The re-time selection makes the same choice. + times["harness-gpu-old/alu"] = 10.0 + lines = [f"M2V-MATRIX time {key} {value:.3f}" for key, value in times.items()] + self.assertEqual(self.select("a", lines), ["alu", "frame"]) # A GPU time's cross-GPU outlier is named and fails no leg. key = f"{results.HARNESS_GPU}new/frame" bases = {leg: {key: 100} for leg in "abcd"} failing, parked = results.time_outliers( {"a": {key: 100}, "b": {key: 101}, "c": {key: 99}, "d": {key: 150}}, bases) self.assertEqual((failing, list(parked)), ({}, ["d"])) - # The re-time selection reads the rows' times alone. - lines = "\n".join(f"M2V-MATRIX time {key} {value:.3f}" for key, value in times.items()) + "\n" - with mock.patch.object(results, "HARNESS_CEILINGS", {}): - run = subprocess.run(["awk", "-v", "limits=", "-v", f"budget={results.HARNESS_BUDGET!r}", - results.RETIME_SELECT], input=lines, capture_output=True, text=True, check=True) - self.assertEqual([line.split()[1] for line in run.stdout.splitlines()], ["frame"]) + + def test_a_row_judged_on_its_gpu_time_takes_its_gpu_floor_and_its_re_timed_gpu_pairs(self): + times = {"harness-old/sampling": 35.0, "harness-new/sampling": 36.0, + "harness-gpu-old/sampling": 16.0, "harness-gpu-new/sampling": 17.6} + line = ("harness budget sampling: GPU p50 new 17.6 us over old 16.0 us is 1.100 (time new 36.0 us over " + "old 35.0 us is 1.029), past its GPU floor 1.05 with its allowance, 1.082") + with mock.patch.object(results, "HARNESS_CEILINGS", {}), \ + mock.patch.object(results, "HARNESS_FLOORS", {"a": {"sampling": 1.3}}): + # Its host time's floor is not its limit. + self.assertEqual(len(self.budget("a", times)[0]), 1) + with mock.patch.object(results, "HARNESS_GPU_FLOORS", {"a": {"sampling": 1.1}}): + self.assertEqual(self.budget("a", times), ([], [])) + self.assertEqual(results.harness_limits("a", gpu=True), f"sampling={1.1 * results.HARNESS_BUDGET!r}") + with mock.patch.object(results, "HARNESS_GPU_FLOORS", {"a": {"sampling": 1.05}}): + self.assertEqual(self.budget("a", times), ([line], [])) + lines = [f"M2V-MATRIX time {key} {value:.3f}" for key, value in times.items()] + self.assertEqual(self.select("a", lines), ["sampling"]) + # Its re-timed GPU pairs judge it, not its re-timed times. + pairs = dict(times, **{"harness-retime/sampling/1/old": 35.0, "harness-retime/sampling/1/new": 50.0, + "harness-retime/sampling/2/old": 35.0, "harness-retime/sampling/2/new": 50.0, + "harness-retime-gpu/sampling/1/old": 16.0, + "harness-retime-gpu/sampling/1/new": 16.2, + "harness-retime-gpu/sampling/2/old": 16.0, + "harness-retime-gpu/sampling/2/new": 16.4}) + self.assertEqual(self.budget("a", pairs), ([], [ + f"{line}; re-timed in 2 pairs, 1.012, 1.025, median 1.019, within: judged by the median"])) + + def test_a_card_s_variance_row_is_named_and_fails_nothing(self): + times = {"harness-old/sampling": 35.0, "harness-new/sampling": 36.0, + "harness-gpu-old/sampling": 16.0, "harness-gpu-new/sampling": 20.0} + variance = {"a": {"sampling": "its GPU p50 ran 16-20 us"}} + with mock.patch.object(results, "HARNESS_CEILINGS", {}), \ + mock.patch.object(results, "CARD_VARIANCE", variance): + self.assertEqual(self.budget("a", times), ([], [ + "harness budget sampling: GPU p50 new 20.0 us over old 16.0 us is 1.250 (time new 36.0 us over " + "old 35.0 us is 1.029), past 1.03: the card's own variance, not judged (its GPU p50 ran 16-20 us)"])) + # Within its limit and over the budget, it is named too. + with mock.patch.object(results, "HARNESS_GPU_FLOORS", {"a": {"sampling": 1.3}}): + self.assertEqual(self.budget("a", times)[1], [ + "harness budget sampling: GPU p50 new 20.0 us over old 16.0 us is 1.250 (time new 36.0 us " + "over old 35.0 us is 1.029), within its limit: the card's own variance (its GPU p50 ran " + "16-20 us)"]) + # Another GPU's row is judged. + self.assertEqual(len(self.budget("b", times)[0]), 1) + + def test_a_re_timed_run_keeps_the_row_s_time_and_gpu_time(self): + output = ["M2V-MATRIX time harness-new/sampling 36.000", "M2V-MATRIX time harness-gpu-new/sampling 17.600", + "M2V-MATRIX time harness-new/alu 10.000", "a table row"] + keep = results.RETIME_KEEP.replace("$timed", "new").replace("$row", "sampling").replace("$pair", "2") + run = subprocess.run(["sed", "-n", keep], input="\n".join(output) + "\n", capture_output=True, text=True, + check=True) + self.assertEqual(run.stdout.splitlines(), [ + "M2V-MATRIX time harness-retime/sampling/2/new 36.000", + "M2V-MATRIX time harness-retime-gpu/sampling/2/new 17.600"]) def test_every_row_shows_its_times_and_gpu_times_on_both_runtimes(self): times = {"harness-old/frame": 100.0, "harness-new/frame": 120.0,