Files
lzply/CHASE_CUDA.md
cnmcdee 368644a392 CUDA Chase-1: GPU deep-repair scan, 453-512x vs CPU, identical results
One CUDA thread per trial position runs Berlekamp-Massey + the lambda-splits test (h = x^(2^m) mod lambda == x, exactly the CPU gcd test, since x^(2^m)-x is squarefree); a second kernel runs the Chien search in parallel for the survivors; the host verifies by the syndrome-zero check (exactly the CPU zero-remainder check). Candidate order reproduces the CPU (suspects first, then ascending).

Measured on RTX 3080 Ti, one 524265-byte block, m=22 t=8, 9 errors, 4194296 trials: CPU 171.571 s (24446 trials/s), CUDA 0.335-0.379 s (11.1-12.5M trials/s). Identical trials/split_pass/codewords/candidates and candidate-set hash on 5 patterns (seeds 12345, 999, 2, 3, 4), including suspect-path cases. Full suite green: bch_test 7975/0, rs_test 6243/0, crc16_test 530/0, run_rs_tests 61/0, run_tests 149/0, deep repair 47/0, hyper 56/0.
2026-12-03 20:00:10 -05:00

4.5 KiB
Raw Permalink Blame History

CUDA Chase-1 (deep repair) — experiments/cuda-chase

GPU port of the Chase-1 scan (bch_chase1_block, bch.c) for the -e4 case (m=22, t=8): one CUDA thread per trial position runs Berlekamp-Massey + the lambda-splits test; a second kernel runs the Chien search in parallel for the few survivors; the host verifies each by the syndrome-zero check. Candidate order and counts match the CPU exactly.

Files

  • chase_cuda.h / chase_cuda.cu — the CUDA implementation (chase_cuda_scan1, chase_cuda_available). Only t=8 is implemented; other t values return -2.
  • chase_bench.c — benchmark harness: builds one 524,265-byte block, flips N bits (default 9, seed 12345), checks the standard decode fails, then times --cpu (bch_chase1_block) or --cuda (chase_cuda_scan1) and prints trials / split_pass / codewords / candidates / seconds / trials/s / a hash of the candidate set in order / whether the original is among the candidates.
  • bch_block_syndrome() (bch.c/bch.h) — new public accessor for the syndrome S_1..S_2t of a received word (thin wrapper around the existing static compute_syndrome). Returns 0 with S filled, 1 if the remainder is zero (clean word), -1 on bad input.

Why the GPU version is exactly equivalent

  1. Splits test. The CPU test is gcd(lambda, x^(2^m)-x) of degree L. x^(2^m)-x is squarefree, so that gcd has degree L iff lambda divides x^(2^m)-x iff x^(2^m) mod lambda == x. The kernel computes h = x^(2^m) mod lambda by m repeated squarings and passes iff h == x — no gcd at all. L <= 1 always splits, matching the CPU.
  2. BM early exit. BM's L is non-decreasing, so a trial whose L exceeds t at any point is doomed; the kernel exits early and never writes C beyond index t. Exactly equivalent: any such write would only raise the degree past t (deg(C) after an update equals the new L).
  3. Verification. The corrected word's syndrome is S ^ col(trial) ^ XOR col(root), and syndrome zero iff remainder zero: the syndrome's roots close under conjugation to the generator, so a degree-<r binary remainder with all 2t syndrome roots is 0. The host checks this with the host exp table (no per-candidate decode needed).
  4. Order. The kernel's atomic-append order is nondeterministic, so the host sorts survivors by position ascending before verification; candidate order then reproduces the CPU's (suspects first in order, then ascending).

Measured (hot_house, RTX 3080 Ti, Dec 3 2026)

One 524,265-byte block, m=22, t=8, 9 errors, 4,194,296 trials.

case CPU CUDA hash
seed 12345, 9 errors 171.571 s (24,446 trials/s) 0.335–0.379 s (11.1–12.5M trials/s) 0xca5f43bdeb9d8c96 (both)
seed 999, 10 errors 158.573 s (26,450 trials/s) 0.328 s (12.8M trials/s) 0x5003477cf2b5970d (both)
  • seed 12345: trials 4,194,296, split_pass 135, codewords 135, candidates 15, original among candidates YES (both).
  • seed 999 (10 errors): split_pass 72, codewords 72, candidates 8, original NO on both — Chase-1 cannot fix t+2 errors (one trial flip leaves 9 > t=8); the 8 candidates are other codewords. That is the algorithm's limit, not an implementation difference.
  • Seeds 2/3/4 (suspect-path cases, 6/6/9 suspects) validated against the CPU the same way (hash match) — see /root/chase-cpu-seed{2,3,4}.log and the CUDA runs.

Speedup on the timed scan: 171.571 / 0.335 ≈ 512× (worst repeat 171.571 / 0.379 ≈ 453×). End-to-end wall clock including process start + CUDA context init: ~0.9 s vs ~172 s (~190×).

Build

# CPU-only bench
gcc -O2 -Wall -Wextra -o chase_bench_cpu chase_bench.c bch.c
# CUDA bench (nvcc pattern from the cuda-bch job)
/usr/local/cuda/bin/nvcc -O3 -arch=sm_86 -Xcompiler -O2 -c -o chase_cuda.o chase_cuda.cu
gcc -O2 -Wall -Wextra -DHAVE_CUDA -c -o chase_bench.o chase_bench.c
gcc -O2 -Wall -Wextra -c -o bch.o bch.c
/usr/local/cuda/bin/nvcc -arch=sm_86 -o chase_bench_cuda chase_bench.o bch.o chase_cuda.o

Limits / not done

  • t=8 only. Other t values need a template instantiation per t (the kernel is written with CT=8; the BM/splits code is t-generic in structure).
  • Chase-2 is not ported (pair scan; the same per-trial kernel applies, but the pair enumeration and candidate ordering need their own pass).
  • Counts are full-scan counts: if max_cands is hit, the CPU stops the scan early (partial stats) while the GPU runs the whole scan and then truncates. The candidate set still matches (first max_cands in CPU order). Not an issue for the benchmark (15 < 64 candidates).