Skip to content

Store completion tables with the rows innermost - #1069

Merged
perlinm merged 9 commits into
mainfrom
perf/dist-table-layout
Nov 26, 2026
Merged

perlinm merged 9 commits into
mainfrom
perf/dist-table-layout

Conversation

@perlinm

@perlinm perlinm commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Motivation

The Brouwer-Zimmermann scan looks up the completion bounds of one prefix for consecutive rows s of a search basis, with the same values on each block. The completion tables stored each row's tables contiguously, so these lookups were offsets[-1] bytes apart and each one missed the caches. On codes whose search spends its time in tabled layers, these lookups took 56-100 ns each and most of the search's time. Examples are a [[232,...]] pair-partition code, a lifted-product code, and a hypergraph-product code of gross-code size.

Changes

completion_bounds.py indexes the tables as (offsets[b] + x) * (num_rows - 1) + s, so that the lookups of one prefix share cache lines. The fill collects the tables of up to 64 rows in a tile and transposes it into place, reading the tile a word at a time. Tables without blocks, which have offsets[-1] == 0, return the bound zero before any row arithmetic, as the lookup did before. The stored bounds, the decisions made from them, and the cost model are unchanged. Section 3.9 of brouwer_zimmermann.md describes the layout.

Validation

On 39 small and medium codes, distances by both methods equal the baseline, the literature, and each other. The numbers of supports weighed, lookups and skips per layer are identical on three instances. A test checks the bounds of every row and block of a 67-row basis, more rows than one tile holds, against their definition, and one checks tables without blocks.

Brouwer-Zimmermann distance searches, 1 thread, warm; paired runs, medians of 3:

Code Before → after
[[232,...]] pair-partition code 8.11 → 4.84 s (1.67x)
lifted bivariate-bicycle code of 90 qubits 6.88 → 5.51 s (1.25x)
hypergraph product of gross-code size (single runs) 149-163 → 118-131 s (about 1.25x)
codes whose lookups are each the first of their prefix (e.g. a quantum Tanner code, the gross code) unchanged

Building the tables takes about 1.6 times as long, which is tens of milliseconds on these codes.

perlinm and others added 9 commits November 25, 2026 14:56
A scan looks up the completion bounds of one prefix for consecutive rows s,
with the same values on each block.  With each row's tables contiguous, these
lookups were offsets[-1] bytes apart and each missed the caches.  Index the
tables as (offsets[b] + x) * (num_rows - 1) + s instead, so that they share
cache lines.  The stored bounds, the decisions made from them, and the cost
model are unchanged.

The fill collects the tables of up to 64 rows in a tile and transposes it into
place, reading the tile a word at a time.  A test checks the bounds of a basis
of more rows than one tile holds against their definition.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tables without blocks, such as NO_TABLES and the tables of tails without
ones, have offsets[-1] == 0, so counting their rows divided by zero.  Return
the bound zero for them before counting, as the lookup did before the rows
moved innermost.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The test of a basis of many rows checked one random bound from each row of
its tables, on blocks of four columns.  Check instead every entry of the
tables against the least weight of each value plus two rows, found by
enumerating the pairs on each block.  The tails cover the cases of the
transposing fill: fewer and more rows of tables than the 64 that it
transposes at once, blocks of fewer than eight values and of 256 values, and
narrower last blocks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Check the bounds that completion tables give from every row, not only their
entries, against the least weights found by enumerating pairs.  Replace the
tails of fewer rows of tables than one tile with tails of three tiles, so that
rows past the first 128 are stored and looked up, and add tails with an entry
of 16, the largest distance.  Fill storage that starts with a value that no
entry takes, so that entries left unwritten show, and fill a strided view, so
that the tables fill the storage given and leave the bytes between them
unchanged.  Drop the tails of 66 rows, whose cases the others cover.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Check every entry and every bound of completion tables for each combination
of 130 or 258 rows, which cross tiles of rows and row 256, and blocks of 1, 2
or 8 columns, so that rows of tables of several words cross tiles too.  Fill
both contiguous storage and every other byte of storage, check that the bytes
between entries stay unchanged, and look the bounds up in the strided tables.
This covers the case of strided storage of the test of building in place,
which is dropped.  Compute the least weights from each row by adding the pairs
of that row to those from the next row, so that 258 rows stay quick as plain
Python.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add tails of 65 rows on blocks of one column, whose 64 rows of tables fill
exactly one tile, to the cases whose every entry and bound are checked, and
keep of the larger tails only those of 258 rows.  Fill every other byte of
storage backward instead of forward, so that the tables and their bounds are
also checked with a negative stride.  Bound the tables without blocks with
their own block width, which is zero for NO_TABLES.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Draw the cases whose every entry and bound are checked at random: row counts
that straddle the tiles of 64 rows of tables, column counts that straddle the
words of 64 columns, blocks of 1, 2 or 8 columns, and sparse tails, so that
rows differ and single ones fall in late rows and columns.  Each seed has a
full last tile, a later partial tile of several rows, more than 256 rows, and
later tiles of blocks past the first word or of more than four words, and
fills contiguous and reversed storage.  These replace the fixed cases of 258
and 65 rows.

Check that the byte shifts take each byte of a word to its lowest byte on
machines of either byte order, from copies of the module imported as if on
each.  Check also that a bound stopped early at a limit is at most the bound
and at least the smaller of the bound and the limit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add later tiles of blocks of sixteen columns, whose tile rows hold more than
64 words, to the random cases whose every entry and bound are checked.  Fill
tables as plain Python from copies of the module imported as if on machines of
either byte order, with words that view memory in that order, and check their
entries and bounds, instead of checking only the byte shifts.  Fill every
other byte of storage forward through the build, and check the bytes between
entries and the bounds from every row.

Check also the bounds of two equal rows of 260 ones, which pass the largest
byte, with the contract of early stops at every limit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Check one fixed case of a full and a partial tile of 64 rows, natively and
as on a big-endian machine, and drop the cases that the existing tests
already guard or that test behavior this change leaves unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@perlinm
perlinm merged commit 6615974 into main Nov 26, 2026
9 checks passed
@perlinm
perlinm deleted the perf/dist-table-layout branch November 26, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant