interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / coder / FORMAT.md

81 lines · 5286 bytes Raw Blame History Source

ERC1: coded E4M3 weight matrix, byte format

One file holds one matrix of rows x cols bytes (any byte values; E4M3 weights are the target). All integers are unsigned and little-endian. R is rows. There is no padding and no alignment.

OffsetWidthFieldValue
04magicbytes 45 52 43 31 (ERC1)
42version1
62flags0
84rows1 .. 2^32 - 1
124cols1 .. 2^32 - 1
164prob_bits14
204matrix_crc32CRC-32 of the original rows * cols bytes, row-major
248total_lenlength of this file in bytes
32512freq256 x u16: frequency of byte value 0 .. 255; the sum is 2^14
5444 (R + 1)offsetR + 1 x u32: start of row r's stream, counted from the first stream byte; offset[R] is the length of the stream area
548 + 4 R2 Rrow_crc16R x u16: CRC-16 of row r's stream bytes
548 + 6 R4header_crc32CRC-32 of bytes 0 .. 548 + 6 R - 1 (everything above)
552 + 6 Roffset[R]streamsrow 0's stream, row 1's stream, ...

Header size is 552 + 6 R bytes; the file is that plus offset[R] bytes.

One row stream

Static rANS over the model in freq, 14-bit probabilities, state in [2^23, 2^31), byte-wise renormalisation. Slot table: symbol s owns slots cum[s] .. cum[s] + freq[s] - 1, where cum[s] is the sum of freq below s.

Rows are independent: a row is decoded from its own stream, the table and cols. No state passes between rows.

What the decoder checks, in this order

Each refusal prints erc: refused NAME (and row N for a row) on stderr and exits 3.

NameCheck
TRUNCfewer than 32 bytes, or fewer bytes than the header size
MAGICbytes 0 .. 3 are not ERC1
VERSIONversion is not 1 or flags is not 0
FIELDprob_bits is not 14, or rows or cols is 0
LENGTHtotal_len differs from the file length
HDRCRCheader_crc32 differs from the CRC-32 of the header, frequency table, offsets and row CRCs
FREQthe 256 frequencies do not sum to 2^14
OFFSEToffset[0] is not 0, a stream is shorter than 4 bytes, an offset decreases, or offset[R] is not the stream area length
ROWCRCthe CRC-16 of the row's stream bytes differs from row_crc16[r] (checked before the row is decoded)
STATEthe initial state is below 2^23 or at least 2^31
EXHAUSTthe decoder needs a byte past the end of the row's stream
LEFTOVERthe row is decoded and bytes of its stream are unread
FINALthe row is decoded, every byte is read, and the state is not 2^23 (the encoder's start state)
MATCRCafter every row is decoded, the CRC-32 of the output differs from matrix_crc32 (only whole-matrix decode)

The checks from TRUNC to OFFSET run once when the file is opened (an info, decode, decode-row or bench call). Decoding one row alone checks the header, the table, the offsets and that row; it cannot check matrix_crc32. The STATE, EXHAUST, LEFTOVER and FINAL checks cost no bytes: a valid stream ends exactly at state 2^23 with no byte left. They alone let some single-bit stream flips through (the flip scan receipt counts them on real expert rows), which is why each row has a CRC-16. CRC-16 detects every single-bit flip in a stream of any length, and every burst of 16 bits or fewer.

Checksums

Size

file bytes = 552 + 6 R + sum of stream bytes. The measurement prototype counts 512 + 4 R + sum of stream bytes and no header, row CRCs or matrix CRC, so an ERC1 file is larger than the prototype's count by 40 + 2 R bytes for the same matrix (32 header, 4 for the extra offset, 4 header CRC, 2 R row CRCs; the 512 frequency bytes and the streams are identical).

Limits

The width of a field is the limit: rows and cols are u32, the stream area is at most 2^32 - 1 bytes (the encoder refuses a larger one, message the stream area is longer than a u32 offset can address). The program itself sizes its buffers from the input.