Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b47d472fe3 | ||
|
|
368644a392 |
No files matched your search
@@ -0,0 +1,97 @@
|
||||
# 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).
|
||||
@@ -87,6 +87,24 @@ lzply_hyper: lzply_hyper.o bch.o sha256.o
|
||||
bch_test: bch.c bch_test.c bch.h bch_polys.h
|
||||
$(CC) $(CFLAGS) -o $@ bch.c bch_test.c
|
||||
|
||||
# CUDA Chase-1 bench (experiments/cuda-chase): GPU port of the
|
||||
# deep-repair Chase-1 scan (t=8 only). Needs CUDA 13.x; NVCC is
|
||||
# /usr/local/cuda/bin/nvcc on hot_house (not on PATH by default).
|
||||
NVCC ?= /usr/local/cuda/bin/nvcc
|
||||
NVCCFLAGS = -O3 -arch=sm_86 -Xcompiler -O2
|
||||
|
||||
chase_bench_cpu: chase_bench.c bch.c bch.h bch_polys.h
|
||||
$(CC) $(CFLAGS) -o $@ chase_bench.c bch.c
|
||||
|
||||
chase_bench.o: chase_bench.c bch.h chase_cuda.h
|
||||
$(CC) $(CFLAGS) -DHAVE_CUDA -c -o $@ chase_bench.c
|
||||
|
||||
chase_cuda.o: chase_cuda.cu chase_cuda.h bch.h bch_polys.h
|
||||
$(NVCC) $(NVCCFLAGS) -c -o $@ chase_cuda.cu
|
||||
|
||||
chase_bench_cuda: chase_bench.o bch.o chase_cuda.o
|
||||
$(NVCC) -arch=sm_86 -o $@ chase_bench.o bch.o chase_cuda.o
|
||||
|
||||
# Reed-Solomon codec (rs.c) and the LZRS v1 archive layer
|
||||
# (lzrs_lib.c: LZRS entry encode/decode + header I/O + scan).
|
||||
# lz_rs links both plus the shared v4 core (liblzply.a).
|
||||
@@ -184,6 +202,6 @@ install: lzply lzply_mount lzply_stat lzply_heal lzply_check lzply_refresh lzply
|
||||
install -m 755 mount.lzply /sbin/mount.lzply
|
||||
|
||||
clean:
|
||||
rm -f lzply lzply_mount lzply_stat lzply_heal lzply_check lzply_refresh lzply_hyper lz_rs lzply_deep_repair bch_test rs_test crc16_test *.o liblzply.a liblzrs.a
|
||||
rm -f lzply lzply_mount lzply_stat lzply_heal lzply_check lzply_refresh lzply_hyper lz_rs lzply_deep_repair bch_test rs_test crc16_test chase_bench_cpu chase_bench_cuda *.o liblzply.a liblzrs.a
|
||||
|
||||
.PHONY: all test install clean
|
||||
@@ -1290,6 +1290,28 @@ static int compute_syndrome(const uint8_t *in, size_t in_len, size_t data_len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Public syndrome accessor, for the CUDA Chase scan (and any other
|
||||
* caller that needs S without a full decode). Same return codes as
|
||||
* compute_syndrome: 0 with S filled, 1 if the remainder is zero
|
||||
* (clean word), -1 on bad input. */
|
||||
int bch_block_syndrome(const uint8_t *in, size_t in_len, size_t data_len,
|
||||
const bch_poly_t *p, uint32_t *S)
|
||||
{
|
||||
if (!in || !p || !S)
|
||||
return -1;
|
||||
bch_ctx_t *ctx = bch_ctx_new(p);
|
||||
if (!ctx)
|
||||
return -1;
|
||||
const gf_tables_t *tab = gf_tables_for(p->m);
|
||||
if (!tab) {
|
||||
bch_ctx_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
int rc = compute_syndrome(in, in_len, data_len, p, ctx, tab, S);
|
||||
bch_ctx_free(ctx);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Column of the parity-check matrix for bit position pos:
|
||||
* col_j = alpha^(j*(nbits-1-pos)), j = 1..2t. Fills col[0..2t-1]. */
|
||||
static void col_at(size_t pos, size_t nbits, int t, const gf_tables_t *tab,
|
||||
|
||||
@@ -157,6 +157,12 @@ int bch_remainder_bruteforce(const uint8_t *data, size_t data_len,
|
||||
/* weight-(t+2) pattern. The list is what buys the rate. */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/* Syndrome S_1..S_2t of the received word (for the CUDA Chase scan).
|
||||
* Returns 0 with S filled, 1 if the remainder is zero (clean word),
|
||||
* -1 on bad input. S must hold 2*t uint32_t. */
|
||||
int bch_block_syndrome(const uint8_t *in, size_t in_len, size_t data_len,
|
||||
const bch_poly_t *p, uint32_t *S);
|
||||
|
||||
/* Maximum distinct candidate blocks returned per chase call. */
|
||||
#define BCH_CHASE_MAX_CANDS 64
|
||||
/* Maximum suspect positions considered by chase2. */
|
||||
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
/* chase_bench.c - CPU vs CUDA Chase-1 benchmark for deep repair.
|
||||
*
|
||||
* Reproduces the GPU-day baseline: Chase-1 exhaustive scan of one
|
||||
* 524265-byte BCH block (m=22, t=8, -e4), 9 errors, nbits=4,194,296
|
||||
* trials, ~181 s single-core (~23,200 trials/s).
|
||||
*
|
||||
* Usage: chase_bench --cpu | --cuda [--nerr N] [--seed S]
|
||||
* --cpu : time bch_chase1_block (CPU reference)
|
||||
* --cuda : time the CUDA Chase-1 scan (chase_cuda.cu)
|
||||
* Prints: trials, split_pass, codewords, candidates, seconds,
|
||||
* trials/s, and whether the original data is among the candidates.
|
||||
* Exit 0 iff the original data is among the candidates.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "bch.h"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
#include "chase_cuda.h"
|
||||
#endif
|
||||
|
||||
#define DFLT_D 524265
|
||||
#define DFLT_T 8
|
||||
#define DFLT_NERR 9
|
||||
|
||||
static uint64_t rng_state;
|
||||
static uint64_t xr(void)
|
||||
{
|
||||
uint64_t x = rng_state;
|
||||
x ^= x >> 12;
|
||||
x ^= x << 25;
|
||||
x ^= x >> 27;
|
||||
rng_state = x;
|
||||
return x * 0x2545F4914F6CDD1DULL;
|
||||
}
|
||||
|
||||
static double now_s(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return ts.tv_sec + ts.tv_nsec * 1e-9;
|
||||
}
|
||||
|
||||
static void flip_bit(uint8_t *buf, size_t pos)
|
||||
{
|
||||
buf[pos >> 3] ^= (uint8_t)(1u << (7 - (pos & 7)));
|
||||
}
|
||||
|
||||
/* FNV-1a hash over the candidate set, in order, for CPU/CUDA comparison. */
|
||||
static uint64_t cands_hash(const uint8_t *cands, int nc, size_t D)
|
||||
{
|
||||
uint64_t h = 0xcbf29ce484222325ULL;
|
||||
for (int i = 0; i < nc; i++) {
|
||||
const uint8_t *c = cands + (size_t)i * D;
|
||||
for (size_t j = 0; j < D; j++) {
|
||||
h ^= c[j];
|
||||
h *= 0x100000001b3ULL;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int use_cuda = 0;
|
||||
int nerr = DFLT_NERR;
|
||||
uint64_t seed = 12345;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "--cuda"))
|
||||
use_cuda = 1;
|
||||
else if (!strcmp(argv[i], "--cpu"))
|
||||
use_cuda = 0;
|
||||
else if (!strcmp(argv[i], "--nerr") && i + 1 < argc)
|
||||
nerr = atoi(argv[++i]);
|
||||
else if (!strcmp(argv[i], "--seed") && i + 1 < argc)
|
||||
seed = strtoull(argv[++i], NULL, 10);
|
||||
else {
|
||||
fprintf(stderr, "usage: %s [--cpu|--cuda] [--nerr N] [--seed S]\n",
|
||||
argv[0]);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
size_t D = DFLT_D;
|
||||
int t = DFLT_T;
|
||||
const bch_poly_t *p = bch_poly_for_data(D, t);
|
||||
if (!p) {
|
||||
fprintf(stderr, "no poly for D=%zu t=%d\n", D, t);
|
||||
return 1;
|
||||
}
|
||||
size_t slen = bch_block_stored_len(D, p);
|
||||
size_t nbits = (size_t)8 * D + (size_t)p->r;
|
||||
printf("poly: m=%d t=%d r=%d id=%04x D=%zu stored=%zu nbits=%zu\n",
|
||||
p->m, p->t, p->r, p->id, D, slen, nbits);
|
||||
fflush(stdout);
|
||||
uint8_t *data = malloc(D), *enc = malloc(slen), *dec = malloc(D);
|
||||
uint8_t *cands = malloc((size_t)BCH_CHASE_MAX_CANDS * D);
|
||||
if (!data || !enc || !dec || !cands)
|
||||
return 1;
|
||||
rng_state = seed;
|
||||
for (size_t i = 0; i < D; i++)
|
||||
data[i] = (uint8_t)xr();
|
||||
if (bch_encode_block(data, D, p, enc) != 0) {
|
||||
fprintf(stderr, "encode failed\n");
|
||||
return 1;
|
||||
}
|
||||
/* flip nerr distinct bit positions, deterministic */
|
||||
rng_state = seed ^ 0x9e3779b97f4a7c15ULL;
|
||||
size_t *errpos = malloc(sizeof(size_t) * (size_t)nerr);
|
||||
for (int i = 0; i < nerr; i++) {
|
||||
size_t pos;
|
||||
int dup;
|
||||
do {
|
||||
pos = (size_t)(xr() % nbits);
|
||||
dup = 0;
|
||||
for (int j = 0; j < i; j++)
|
||||
if (errpos[j] == pos)
|
||||
dup = 1;
|
||||
} while (dup);
|
||||
errpos[i] = pos;
|
||||
flip_bit(enc, pos);
|
||||
}
|
||||
printf("flipped %d bits at:", nerr);
|
||||
for (int i = 0; i < nerr; i++)
|
||||
printf(" %zu", errpos[i]);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
/* control: standard decode must fail */
|
||||
if (bch_decode_block(enc, slen, D, p, dec, NULL) == 0) {
|
||||
fprintf(stderr,
|
||||
"control FAILED: standard decode succeeded on %d-error word\n",
|
||||
nerr);
|
||||
return 1;
|
||||
}
|
||||
printf("control: standard decode fails as expected\n");
|
||||
fflush(stdout);
|
||||
size_t *susp = malloc(sizeof(size_t) * BCH_CHASE_MAX_SUSPECTS);
|
||||
int ns = bch_suspect_positions(enc, slen, D, p, susp, BCH_CHASE_MAX_SUSPECTS);
|
||||
printf("suspects: %d\n", ns);
|
||||
fflush(stdout);
|
||||
|
||||
double t0 = now_s();
|
||||
long trials = 0, split_pass = 0, codewords = 0;
|
||||
int nc = 0;
|
||||
if (!use_cuda) {
|
||||
bch_chase_stats_t cs;
|
||||
nc = bch_chase1_block(enc, slen, D, p, cands, BCH_CHASE_MAX_CANDS,
|
||||
susp, ns, &cs, -1);
|
||||
trials = cs.trials;
|
||||
split_pass = cs.split_pass;
|
||||
codewords = cs.codewords;
|
||||
printf("cpu: nc=%d partial=%d\n", nc, cs.partial);
|
||||
} else {
|
||||
#ifdef HAVE_CUDA
|
||||
nc = chase_cuda_scan1(enc, slen, D, p, cands, BCH_CHASE_MAX_CANDS,
|
||||
susp, ns, &trials, &split_pass, &codewords);
|
||||
printf("cuda: nc=%d\n", nc);
|
||||
#else
|
||||
fprintf(stderr, "built without CUDA support\n");
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
double dt = now_s() - t0;
|
||||
if (nc < 0) {
|
||||
fprintf(stderr, "scan failed\n");
|
||||
return 1;
|
||||
}
|
||||
printf("trials=%ld split_pass=%ld codewords=%ld candidates=%d\n",
|
||||
trials, split_pass, codewords, nc);
|
||||
printf("time=%.3f s rate=%.0f trials/s\n", dt, trials / dt);
|
||||
printf("cands_hash=0x%016llx\n",
|
||||
(unsigned long long)cands_hash(cands, nc, D));
|
||||
int found = 0;
|
||||
for (int i = 0; i < nc; i++)
|
||||
if (memcmp(cands + (size_t)i * D, data, D) == 0)
|
||||
found = 1;
|
||||
printf("original among candidates: %s\n", found ? "YES" : "NO");
|
||||
return found ? 0 : 1;
|
||||
}
|
||||
+611
@@ -0,0 +1,611 @@
|
||||
/* chase_cuda.cu - CUDA Chase-1 scan for deep repair (t=8, -e4).
|
||||
*
|
||||
* GPU mirror of bch_chase1_block (bch.c). One thread per trial
|
||||
* position runs Berlekamp-Massey + the lambda-splits test. Two
|
||||
* facts make the GPU version exactly equivalent to the CPU:
|
||||
*
|
||||
* 1. The CPU splits 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
|
||||
* therefore computes h = x^(2^m) mod lambda by m repeated
|
||||
* squarings and passes iff h == x, with no gcd at all.
|
||||
* L <= 1 always splits, matching the CPU.
|
||||
* 2. 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. That is exactly equivalent: any such write
|
||||
* would only raise the degree past t, and the final L would
|
||||
* still exceed t (deg(C) after an update equals the new L).
|
||||
*
|
||||
* After the scan, a second kernel runs the Chien search in parallel
|
||||
* for the (few) positions that passed: one thread per (position,
|
||||
* codeword bit) evaluates lambda at that bit by Horner. The host
|
||||
* then verifies each survivor by the syndrome-zero check: the
|
||||
* syndrome of the corrected word 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).
|
||||
*
|
||||
* GF arithmetic on the device is shift-and-XOR in registers (like
|
||||
* gf_mul_slow); division uses log/exp tables (only ~12 divs per
|
||||
* trial, and the BM early exit usually fires before many).
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <cuda_runtime.h>
|
||||
extern "C" {
|
||||
#include "bch.h"
|
||||
}
|
||||
#include "chase_cuda.h"
|
||||
|
||||
/* Only t=8 (-e4) is implemented: the benchmark case. */
|
||||
#define CT 8
|
||||
#define CT2 (2 * CT)
|
||||
|
||||
#define CHASE_CUDA_MAX_PASS 1048576u /* 1M passing positions (expect ~135) */
|
||||
|
||||
/* ---- GF(2^m) device helpers ---- */
|
||||
|
||||
/* Shift-and-XOR multiply (identical to gf_mul_slow in bch.c). */
|
||||
__device__ __forceinline__ uint32_t cu_gf_mul(uint32_t a, uint32_t b, uint32_t P, int m)
|
||||
{
|
||||
uint32_t r = 0;
|
||||
while (b) {
|
||||
if (b & 1)
|
||||
r ^= a;
|
||||
b >>= 1;
|
||||
a <<= 1;
|
||||
if (a & (1u << m))
|
||||
a ^= P;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Division via log/exp tables (identical to gf_div_tab; b != 0 by
|
||||
* construction - a previous discrepancy). */
|
||||
__device__ __forceinline__ uint32_t cu_gf_div_tab(uint32_t a, uint32_t b,
|
||||
const uint32_t *d_log,
|
||||
const uint32_t *d_exp,
|
||||
uint32_t N)
|
||||
{
|
||||
if (!a)
|
||||
return 0;
|
||||
int d = (int)d_log[a] - (int)d_log[b];
|
||||
if (d < 0)
|
||||
d += (int)N;
|
||||
return d_exp[d];
|
||||
}
|
||||
|
||||
/* Berlekamp-Massey on 2*CT syndromes. Returns L (0..CT) with
|
||||
* lambda[0..L] filled, or -1 if L exceeds CT at any point (trial
|
||||
* doomed: L never decreases, so the CPU would reject it too). */
|
||||
__device__ int cu_bm(const uint32_t *S, const uint32_t *d_log,
|
||||
const uint32_t *d_exp, uint32_t N, uint32_t P, int m,
|
||||
uint32_t *lambda)
|
||||
{
|
||||
uint32_t C[CT + 1], B[CT + 1], Tm[CT + 1];
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= CT; i++)
|
||||
C[i] = B[i] = 0;
|
||||
C[0] = B[0] = 1;
|
||||
int L = 0, shift = 1;
|
||||
uint32_t b = 1;
|
||||
for (int n = 0; n < CT2; n++) {
|
||||
uint32_t d = S[n];
|
||||
#pragma unroll
|
||||
for (int i = 1; i <= CT; i++)
|
||||
if (i <= L && C[i] && n - i >= 0)
|
||||
d ^= cu_gf_mul(C[i], S[n - i], P, m);
|
||||
if (d == 0) {
|
||||
shift++;
|
||||
continue;
|
||||
}
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= CT; i++)
|
||||
Tm[i] = C[i];
|
||||
uint32_t coef = cu_gf_div_tab(d, b, d_log, d_exp, N);
|
||||
int lim = CT - shift;
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= CT; i++)
|
||||
if (i <= lim && B[i])
|
||||
C[i + shift] ^= cu_gf_mul(coef, B[i], P, m);
|
||||
if (2 * L <= n) {
|
||||
L = n + 1 - L;
|
||||
if (L > CT)
|
||||
return -1;
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= CT; i++)
|
||||
B[i] = Tm[i];
|
||||
b = d;
|
||||
shift = 1;
|
||||
} else {
|
||||
shift++;
|
||||
}
|
||||
}
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= L; i++)
|
||||
lambda[i] = C[i];
|
||||
return L;
|
||||
}
|
||||
|
||||
/* out = a^2 mod mod (mod monic of degree L, 1 <= L <= CT). */
|
||||
__device__ void cu_square_mod(const uint32_t *a, int L, const uint32_t *mod,
|
||||
uint32_t P, int m, uint32_t *out)
|
||||
{
|
||||
uint32_t prod[2 * CT + 1];
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= 2 * CT; i++)
|
||||
prod[i] = 0;
|
||||
#pragma unroll
|
||||
for (int i = 0; i < CT; i++)
|
||||
if (i < L && a[i])
|
||||
prod[2 * i] ^= cu_gf_mul(a[i], a[i], P, m);
|
||||
for (int k = 2 * L - 2; k >= L; k--) {
|
||||
uint32_t c = prod[k];
|
||||
if (!c)
|
||||
continue;
|
||||
prod[k] = 0;
|
||||
#pragma unroll
|
||||
for (int j = 0; j < CT; j++)
|
||||
if (j < L && mod[j])
|
||||
prod[k - L + j] ^= cu_gf_mul(c, mod[j], P, m);
|
||||
}
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= CT; i++)
|
||||
out[i] = (i < L) ? prod[i] : 0;
|
||||
}
|
||||
|
||||
/* Splits test: h = x^(2^m) mod lambda; splits iff h == x (see the
|
||||
* header comment for why this is exactly the CPU's gcd test). */
|
||||
__device__ int cu_lambda_splits(const uint32_t *lambda, int L, int m, uint32_t P)
|
||||
{
|
||||
if (L <= 1)
|
||||
return 1;
|
||||
uint32_t cur[CT + 1], nxt[CT + 1];
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= CT; i++)
|
||||
cur[i] = nxt[i] = 0;
|
||||
cur[1] = 1;
|
||||
for (int i = 0; i < m; i++) {
|
||||
cu_square_mod(cur, L, lambda, P, m, nxt);
|
||||
#pragma unroll
|
||||
for (int j = 0; j <= CT; j++)
|
||||
cur[j] = nxt[j];
|
||||
}
|
||||
cur[1] ^= 1; /* h = cur - x */
|
||||
#pragma unroll
|
||||
for (int j = 0; j < CT; j++)
|
||||
if (j < L && cur[j])
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ---- kernel 1: BM + splits scan, one thread per trial position ---- */
|
||||
__global__ void chase1_scan_kernel(const uint32_t *d_S, const uint32_t *d_exp,
|
||||
const uint32_t *d_log, uint32_t N, uint32_t P,
|
||||
int m, size_t nbits, uint32_t *d_pass,
|
||||
uint32_t *d_pass_lambda, uint32_t *d_pass_L,
|
||||
unsigned int *d_npass, unsigned long long *d_split_pass)
|
||||
{
|
||||
size_t pp = (size_t)blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (pp >= nbits)
|
||||
return;
|
||||
uint32_t K = (uint32_t)(nbits - 1 - pp);
|
||||
uint32_t Sp[CT2];
|
||||
#pragma unroll
|
||||
for (int j = 1; j <= CT2; j++) {
|
||||
uint32_t e = (uint32_t)(((uint64_t)j * K) % N);
|
||||
Sp[j - 1] = d_S[j - 1] ^ d_exp[e];
|
||||
}
|
||||
uint32_t lambda[CT + 1];
|
||||
int L = cu_bm(Sp, d_log, d_exp, N, P, m, lambda);
|
||||
if (L < 0)
|
||||
return;
|
||||
uint32_t inv = cu_gf_div_tab(1, lambda[L], d_log, d_exp, N);
|
||||
uint32_t mono[CT + 1];
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= L; i++)
|
||||
mono[i] = cu_gf_mul(lambda[i], inv, P, m);
|
||||
if (!cu_lambda_splits(mono, L, m, P))
|
||||
return;
|
||||
atomicAdd(d_split_pass, 1ULL);
|
||||
unsigned int idx = atomicAdd(d_npass, 1u);
|
||||
if (idx >= CHASE_CUDA_MAX_PASS)
|
||||
return;
|
||||
d_pass[idx] = (uint32_t)pp;
|
||||
d_pass_L[idx] = (uint32_t)L;
|
||||
#pragma unroll
|
||||
for (int i = 0; i <= CT; i++)
|
||||
d_pass_lambda[(size_t)idx * (CT + 1) + i] = (i <= L) ? mono[i] : 0;
|
||||
}
|
||||
|
||||
/* ---- kernel 2: parallel Chien search for the survivors ----
|
||||
* One thread per (survivor, codeword bit): evaluates lambda at
|
||||
* x_p = alpha^(p-(n-1)) by Horner and records p if it is a root. */
|
||||
__global__ void chase1_chien_kernel(const uint32_t *d_pass_lambda,
|
||||
const uint32_t *d_pass_L,
|
||||
const uint32_t *d_exp, uint32_t N,
|
||||
uint32_t P, int m, size_t nbits,
|
||||
unsigned int npass, uint32_t *d_roots,
|
||||
uint32_t *d_nroots)
|
||||
{
|
||||
size_t tid = (size_t)blockIdx.x * blockDim.x + threadIdx.x;
|
||||
size_t total = (size_t)npass * nbits;
|
||||
if (tid >= total)
|
||||
return;
|
||||
unsigned int pi = (unsigned int)(tid / nbits);
|
||||
size_t p = tid % nbits;
|
||||
uint32_t L = d_pass_L[pi];
|
||||
const uint32_t *lam = d_pass_lambda + (size_t)pi * (CT + 1);
|
||||
long long off = (long long)p - (long long)(nbits - 1);
|
||||
long long em = off % (long long)N;
|
||||
if (em < 0)
|
||||
em += (long long)N;
|
||||
uint32_t x = d_exp[em];
|
||||
uint32_t v = lam[L];
|
||||
for (int j = (int)L - 1; j >= 0; j--)
|
||||
v = cu_gf_mul(v, x, P, m) ^ lam[j];
|
||||
if (v == 0) {
|
||||
unsigned int idx = atomicAdd(&d_nroots[pi], 1u);
|
||||
if (idx < (unsigned int)CT)
|
||||
d_roots[(size_t)pi * CT + idx] = (uint32_t)p;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- host side ---- */
|
||||
|
||||
int chase_cuda_available(void)
|
||||
{
|
||||
int n = 0;
|
||||
if (cudaGetDeviceCount(&n) != cudaSuccess)
|
||||
return 0;
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
/* GF(2^m) exp/log tables, built once per m and cached (host + device). */
|
||||
typedef struct {
|
||||
int m;
|
||||
uint32_t N, P;
|
||||
uint32_t *h_exp; /* host copy, for the syndrome-zero check */
|
||||
uint32_t *d_exp, *d_log;
|
||||
} cu_tables_t;
|
||||
static cu_tables_t g_tab;
|
||||
|
||||
static uint32_t gf_mul_alpha_h(uint32_t x, uint32_t P, int m)
|
||||
{
|
||||
uint32_t top = (x >> (m - 1)) & 1u;
|
||||
x <<= 1;
|
||||
if (top)
|
||||
x ^= P;
|
||||
return x & ((1u << m) - 1);
|
||||
}
|
||||
|
||||
static int cu_tables_for(int m)
|
||||
{
|
||||
if (g_tab.m == m && g_tab.d_exp)
|
||||
return 0;
|
||||
uint32_t P = bch_prim_poly[m];
|
||||
uint32_t N = (1u << m) - 1;
|
||||
uint32_t *exp = (uint32_t *)malloc((size_t)(N + 1) * sizeof(uint32_t));
|
||||
uint32_t *log = (uint32_t *)malloc((size_t)(N + 1) * sizeof(uint32_t));
|
||||
if (!exp || !log) {
|
||||
free(exp);
|
||||
free(log);
|
||||
return -1;
|
||||
}
|
||||
uint32_t x = 1;
|
||||
for (uint32_t i = 0; i <= N; i++) {
|
||||
exp[i] = x;
|
||||
log[x] = i;
|
||||
x = gf_mul_alpha_h(x, P, m);
|
||||
}
|
||||
log[0] = 0;
|
||||
uint32_t *d_exp = NULL, *d_log = NULL;
|
||||
if (cudaMalloc(&d_exp, (size_t)(N + 1) * sizeof(uint32_t)) != cudaSuccess ||
|
||||
cudaMalloc(&d_log, (size_t)(N + 1) * sizeof(uint32_t)) != cudaSuccess ||
|
||||
cudaMemcpy(d_exp, exp, (size_t)(N + 1) * sizeof(uint32_t),
|
||||
cudaMemcpyHostToDevice) != cudaSuccess ||
|
||||
cudaMemcpy(d_log, log, (size_t)(N + 1) * sizeof(uint32_t),
|
||||
cudaMemcpyHostToDevice) != cudaSuccess) {
|
||||
cudaFree(d_exp);
|
||||
cudaFree(d_log);
|
||||
free(exp);
|
||||
free(log);
|
||||
return -1;
|
||||
}
|
||||
free(g_tab.h_exp);
|
||||
g_tab.m = m;
|
||||
g_tab.N = N;
|
||||
g_tab.P = P;
|
||||
g_tab.h_exp = exp;
|
||||
g_tab.d_exp = d_exp;
|
||||
g_tab.d_log = d_log;
|
||||
free(log); /* device copy kept; host log not needed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void flip_bit(uint8_t *buf, size_t pos)
|
||||
{
|
||||
buf[pos >> 3] ^= (uint8_t)(1u << (7 - (pos & 7)));
|
||||
}
|
||||
|
||||
int chase_cuda_scan1(const uint8_t *in, size_t in_len, size_t data_len,
|
||||
const bch_poly_t *p, uint8_t *cands, int max_cands,
|
||||
const size_t *suspects, int nsuspects,
|
||||
long *trials_out, long *split_pass_out,
|
||||
long *codewords_out)
|
||||
{
|
||||
if (!in || !p || !cands || max_cands <= 0 || !trials_out ||
|
||||
!split_pass_out || !codewords_out)
|
||||
return -1;
|
||||
if (p->t != CT)
|
||||
return -2; /* only t=8 implemented */
|
||||
if (!chase_cuda_available())
|
||||
return -2;
|
||||
size_t stored = bch_block_stored_len(data_len, p);
|
||||
if (in_len != stored)
|
||||
return -1;
|
||||
int r = p->r, m = p->m;
|
||||
uint32_t N = (1u << m) - 1;
|
||||
uint32_t P = bch_prim_poly[m];
|
||||
size_t nbits = (size_t)8 * data_len + (size_t)r;
|
||||
|
||||
/* syndrome; also the clean-word early out (same as chase_setup) */
|
||||
uint32_t S[CT2];
|
||||
int src = bch_block_syndrome(in, in_len, data_len, p, S);
|
||||
if (src < 0)
|
||||
return -1;
|
||||
if (src == 1) {
|
||||
*trials_out = 0;
|
||||
*split_pass_out = 0;
|
||||
*codewords_out = 0;
|
||||
return 0;
|
||||
}
|
||||
if (cu_tables_for(m) != 0)
|
||||
return -2;
|
||||
|
||||
uint32_t *d_S = NULL, *d_pass = NULL, *d_pass_lambda = NULL,
|
||||
*d_pass_L = NULL, *d_roots = NULL, *d_nroots = NULL;
|
||||
unsigned int *d_npass = NULL;
|
||||
unsigned long long *d_split_pass = NULL;
|
||||
unsigned int npass = 0;
|
||||
unsigned long long split_pass = 0;
|
||||
int rc = -2;
|
||||
long codewords = 0;
|
||||
int nc = 0;
|
||||
uint32_t *h_pass = NULL, *h_pass_L = NULL, *h_roots = NULL, *h_nroots = NULL;
|
||||
|
||||
if (cudaMalloc(&d_S, CT2 * sizeof(uint32_t)) != cudaSuccess ||
|
||||
cudaMalloc(&d_pass, CHASE_CUDA_MAX_PASS * sizeof(uint32_t)) != cudaSuccess ||
|
||||
cudaMalloc(&d_pass_lambda, (size_t)CHASE_CUDA_MAX_PASS * (CT + 1) * sizeof(uint32_t)) != cudaSuccess ||
|
||||
cudaMalloc(&d_pass_L, CHASE_CUDA_MAX_PASS * sizeof(uint32_t)) != cudaSuccess ||
|
||||
cudaMalloc(&d_npass, sizeof(unsigned int)) != cudaSuccess ||
|
||||
cudaMalloc(&d_split_pass, sizeof(unsigned long long)) != cudaSuccess)
|
||||
goto out;
|
||||
if (cudaMemcpy(d_S, S, CT2 * sizeof(uint32_t), cudaMemcpyHostToDevice) != cudaSuccess)
|
||||
goto out;
|
||||
if (cudaMemset(d_npass, 0, sizeof(unsigned int)) != cudaSuccess ||
|
||||
cudaMemset(d_split_pass, 0, sizeof(unsigned long long)) != cudaSuccess)
|
||||
goto out;
|
||||
|
||||
/* kernel 1: BM + splits scan */
|
||||
{
|
||||
int block = 256;
|
||||
size_t grid = (nbits + (size_t)block - 1) / (size_t)block;
|
||||
chase1_scan_kernel<<<grid, block>>>(d_S, g_tab.d_exp, g_tab.d_log, N, P, m,
|
||||
nbits, d_pass, d_pass_lambda, d_pass_L,
|
||||
d_npass, d_split_pass);
|
||||
if (cudaDeviceSynchronize() != cudaSuccess)
|
||||
goto out;
|
||||
}
|
||||
if (cudaMemcpy(&npass, d_npass, sizeof(unsigned int), cudaMemcpyDeviceToHost) != cudaSuccess ||
|
||||
cudaMemcpy(&split_pass, d_split_pass, sizeof(unsigned long long), cudaMemcpyDeviceToHost) != cudaSuccess)
|
||||
goto out;
|
||||
*split_pass_out = (long)split_pass;
|
||||
*trials_out = (long)nbits;
|
||||
if (npass > CHASE_CUDA_MAX_PASS)
|
||||
npass = CHASE_CUDA_MAX_PASS; /* truncated; not expected (~135) */
|
||||
|
||||
if (npass > 0) {
|
||||
h_pass = (uint32_t *)malloc((size_t)npass * sizeof(uint32_t));
|
||||
h_pass_L = (uint32_t *)malloc((size_t)npass * sizeof(uint32_t));
|
||||
h_roots = (uint32_t *)malloc((size_t)npass * CT * sizeof(uint32_t));
|
||||
h_nroots = (uint32_t *)malloc((size_t)npass * sizeof(uint32_t));
|
||||
if (!h_pass || !h_pass_L || !h_roots || !h_nroots)
|
||||
goto out;
|
||||
if (cudaMemcpy(h_pass, d_pass, (size_t)npass * sizeof(uint32_t),
|
||||
cudaMemcpyDeviceToHost) != cudaSuccess ||
|
||||
cudaMemcpy(h_pass_L, d_pass_L, (size_t)npass * sizeof(uint32_t),
|
||||
cudaMemcpyDeviceToHost) != cudaSuccess)
|
||||
goto out;
|
||||
if (cudaMalloc(&d_roots, (size_t)npass * CT * sizeof(uint32_t)) != cudaSuccess ||
|
||||
cudaMalloc(&d_nroots, (size_t)npass * sizeof(uint32_t)) != cudaSuccess)
|
||||
goto out;
|
||||
if (cudaMemset(d_nroots, 0, (size_t)npass * sizeof(uint32_t)) != cudaSuccess)
|
||||
goto out;
|
||||
/* kernel 2: parallel Chien search for the survivors */
|
||||
{
|
||||
int block = 256;
|
||||
size_t total = (size_t)npass * nbits;
|
||||
size_t grid = (total + (size_t)block - 1) / (size_t)block;
|
||||
chase1_chien_kernel<<<grid, block>>>(d_pass_lambda, d_pass_L,
|
||||
g_tab.d_exp, N, P, m, nbits,
|
||||
npass, d_roots, d_nroots);
|
||||
if (cudaDeviceSynchronize() != cudaSuccess)
|
||||
goto out;
|
||||
}
|
||||
if (cudaMemcpy(h_roots, d_roots, (size_t)npass * CT * sizeof(uint32_t),
|
||||
cudaMemcpyDeviceToHost) != cudaSuccess ||
|
||||
cudaMemcpy(h_nroots, d_nroots, (size_t)npass * sizeof(uint32_t),
|
||||
cudaMemcpyDeviceToHost) != cudaSuccess)
|
||||
goto out;
|
||||
/* sort survivors by position ascending: the kernel's
|
||||
* atomic-append order is nondeterministic, but the CPU
|
||||
* scans ascending, so candidate order must be sorted. */
|
||||
for (unsigned int i = 0; i < npass; i++) {
|
||||
for (unsigned int j = i + 1; j < npass; j++) {
|
||||
if (h_pass[j] < h_pass[i]) {
|
||||
uint32_t t;
|
||||
t = h_pass[i]; h_pass[i] = h_pass[j]; h_pass[j] = t;
|
||||
t = h_pass_L[i]; h_pass_L[i] = h_pass_L[j]; h_pass_L[j] = t;
|
||||
t = h_nroots[i]; h_nroots[i] = h_nroots[j]; h_nroots[j] = t;
|
||||
for (int k = 0; k < CT; k++) {
|
||||
t = h_roots[(size_t)i * CT + k];
|
||||
h_roots[(size_t)i * CT + k] = h_roots[(size_t)j * CT + k];
|
||||
h_roots[(size_t)j * CT + k] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* host verification, in CPU order: suspects first in order, then
|
||||
* ascending positions skipping suspects. For each survivor with
|
||||
* a full root set, the corrected word's syndrome is
|
||||
* S ^ col(trial) ^ XOR col(root); it is a codeword iff that is
|
||||
* zero. Identical to the CPU's zero-remainder check. */
|
||||
{
|
||||
uint8_t *seen = (uint8_t *)malloc((size_t)max_cands * data_len);
|
||||
uint32_t *syn = (uint32_t *)malloc(CT2 * sizeof(uint32_t));
|
||||
if (!seen || !syn) {
|
||||
free(seen);
|
||||
free(syn);
|
||||
goto out;
|
||||
}
|
||||
/* order: suspects (that passed) first, then the rest ascending */
|
||||
unsigned char *is_susp = (unsigned char *)calloc(npass, 1);
|
||||
if (!is_susp) {
|
||||
free(seen);
|
||||
free(syn);
|
||||
goto out;
|
||||
}
|
||||
for (int s = 0; s < nsuspects && nc < max_cands; s++) {
|
||||
for (unsigned int pi = 0; pi < npass; pi++) {
|
||||
if (is_susp[pi] || h_pass[pi] != (uint32_t)suspects[s])
|
||||
continue;
|
||||
is_susp[pi] = 1;
|
||||
/* verify survivor pi */
|
||||
if (h_nroots[pi] != h_pass_L[pi])
|
||||
break;
|
||||
uint32_t K = (uint32_t)(nbits - 1 - h_pass[pi]);
|
||||
for (int j = 1; j <= CT2; j++) {
|
||||
uint32_t e = (uint32_t)(((uint64_t)j * K) % N);
|
||||
syn[j - 1] = S[j - 1] ^ g_tab.h_exp[e];
|
||||
}
|
||||
for (uint32_t ri = 0; ri < h_nroots[pi]; ri++) {
|
||||
uint32_t Kr = (uint32_t)(nbits - 1 - h_roots[(size_t)pi * CT + ri]);
|
||||
for (int j = 1; j <= CT2; j++) {
|
||||
uint32_t e = (uint32_t)(((uint64_t)j * Kr) % N);
|
||||
syn[j - 1] ^= g_tab.h_exp[e];
|
||||
}
|
||||
}
|
||||
int zero = 1;
|
||||
for (int j = 0; j < CT2; j++)
|
||||
if (syn[j]) {
|
||||
zero = 0;
|
||||
break;
|
||||
}
|
||||
if (!zero)
|
||||
break;
|
||||
codewords++;
|
||||
/* build the candidate data bytes and dedup */
|
||||
uint8_t *work = (uint8_t *)malloc(in_len);
|
||||
if (!work) {
|
||||
free(seen);
|
||||
free(syn);
|
||||
free(is_susp);
|
||||
goto out;
|
||||
}
|
||||
memcpy(work, in, in_len);
|
||||
flip_bit(work, h_pass[pi]);
|
||||
for (uint32_t ri = 0; ri < h_nroots[pi]; ri++)
|
||||
flip_bit(work, h_roots[(size_t)pi * CT + ri]);
|
||||
int dup = 0;
|
||||
for (int c = 0; c < nc; c++)
|
||||
if (memcmp(seen + (size_t)c * data_len, work, data_len) == 0) {
|
||||
dup = 1;
|
||||
break;
|
||||
}
|
||||
if (!dup) {
|
||||
memcpy(cands + (size_t)nc * data_len, work, data_len);
|
||||
memcpy(seen + (size_t)nc * data_len, work, data_len);
|
||||
nc++;
|
||||
}
|
||||
free(work);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (unsigned int pi = 0; pi < npass && nc < max_cands; pi++) {
|
||||
if (is_susp[pi])
|
||||
continue;
|
||||
/* verify survivor pi (same as above, ascending order) */
|
||||
if (h_nroots[pi] != h_pass_L[pi])
|
||||
continue;
|
||||
uint32_t K = (uint32_t)(nbits - 1 - h_pass[pi]);
|
||||
for (int j = 1; j <= CT2; j++) {
|
||||
uint32_t e = (uint32_t)(((uint64_t)j * K) % N);
|
||||
syn[j - 1] = S[j - 1] ^ g_tab.h_exp[e];
|
||||
}
|
||||
for (uint32_t ri = 0; ri < h_nroots[pi]; ri++) {
|
||||
uint32_t Kr = (uint32_t)(nbits - 1 - h_roots[(size_t)pi * CT + ri]);
|
||||
for (int j = 1; j <= CT2; j++) {
|
||||
uint32_t e = (uint32_t)(((uint64_t)j * Kr) % N);
|
||||
syn[j - 1] ^= g_tab.h_exp[e];
|
||||
}
|
||||
}
|
||||
int zero = 1;
|
||||
for (int j = 0; j < CT2; j++)
|
||||
if (syn[j]) {
|
||||
zero = 0;
|
||||
break;
|
||||
}
|
||||
if (!zero)
|
||||
continue;
|
||||
codewords++;
|
||||
uint8_t *work = (uint8_t *)malloc(in_len);
|
||||
if (!work) {
|
||||
free(seen);
|
||||
free(syn);
|
||||
free(is_susp);
|
||||
goto out;
|
||||
}
|
||||
memcpy(work, in, in_len);
|
||||
flip_bit(work, h_pass[pi]);
|
||||
for (uint32_t ri = 0; ri < h_nroots[pi]; ri++)
|
||||
flip_bit(work, h_roots[(size_t)pi * CT + ri]);
|
||||
int dup = 0;
|
||||
for (int c = 0; c < nc; c++)
|
||||
if (memcmp(seen + (size_t)c * data_len, work, data_len) == 0) {
|
||||
dup = 1;
|
||||
break;
|
||||
}
|
||||
if (!dup) {
|
||||
memcpy(cands + (size_t)nc * data_len, work, data_len);
|
||||
memcpy(seen + (size_t)nc * data_len, work, data_len);
|
||||
nc++;
|
||||
}
|
||||
free(work);
|
||||
}
|
||||
free(seen);
|
||||
free(syn);
|
||||
free(is_susp);
|
||||
}
|
||||
*codewords_out = codewords;
|
||||
rc = nc;
|
||||
|
||||
out:
|
||||
cudaFree(d_S);
|
||||
cudaFree(d_pass);
|
||||
cudaFree(d_pass_lambda);
|
||||
cudaFree(d_pass_L);
|
||||
cudaFree(d_npass);
|
||||
cudaFree(d_split_pass);
|
||||
cudaFree(d_roots);
|
||||
cudaFree(d_nroots);
|
||||
free(h_pass);
|
||||
free(h_pass_L);
|
||||
free(h_roots);
|
||||
free(h_nroots);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/* chase_cuda.h - CUDA Chase-1 scan for deep repair (t=8, -e4).
|
||||
*
|
||||
* GPU mirror of bch_chase1_block (bch.c) for one block: 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 (exactly equivalent to the CPU's
|
||||
* zero-remainder check: syndrome zero iff remainder zero, since
|
||||
* the syndrome's roots close under conjugation to the generator).
|
||||
*
|
||||
* Candidate order reproduces the CPU's: suspects first in order,
|
||||
* then ascending positions skipping suspects. Counts (trials,
|
||||
* split_pass, codewords) use the same definitions as
|
||||
* bch_chase_stats_t, so results are directly comparable.
|
||||
*/
|
||||
#ifndef LZPLY_CHASE_CUDA_H
|
||||
#define LZPLY_CHASE_CUDA_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "bch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 1 if a CUDA device is present, 0 otherwise. */
|
||||
int chase_cuda_available(void);
|
||||
|
||||
/* Chase-1 for one block on the GPU (t=8 only; returns -2 for other t
|
||||
* or when CUDA is unavailable/fails). Same candidate contract as
|
||||
* bch_chase1_block: returns the number of distinct candidate blocks
|
||||
* in `cands` (each data_len bytes, 0..max_cands), or -1 on bad
|
||||
* input. `suspects` may be NULL (with nsuspects 0). Stats are the
|
||||
* same counts as bch_chase_stats_t. */
|
||||
int chase_cuda_scan1(const uint8_t *in, size_t in_len, size_t data_len,
|
||||
const bch_poly_t *p, uint8_t *cands, int max_cands,
|
||||
const size_t *suspects, int nsuspects,
|
||||
long *trials_out, long *split_pass_out,
|
||||
long *codewords_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LZPLY_CHASE_CUDA_H */
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 3498895 1877890 867125 251131 3784195 2342946 1354710 492520 135908
|
||||
control: standard decode fails as expected
|
||||
suspects: 6
|
||||
cpu: nc=13 partial=0
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=166.680 s rate=25164 trials/s
|
||||
cands_hash=0x5c7f589a39df28b8
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 11 bits at: 7480 711379 3153510 1270250 3083353 1772972 938922 807275 94692 1349411 2303948
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cpu: nc=7 partial=0
|
||||
trials=4194296 split_pass=63 codewords=63 candidates=7
|
||||
time=159.671 s rate=26268 trials/s
|
||||
cands_hash=0x64657c5daf8fe7bd
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 10 bits at: 1752901 3737741 3059447 2051162 317292 620740 979055 1373300 3126232 2196530
|
||||
control: standard decode fails as expected
|
||||
suspects: 12
|
||||
cpu: nc=11 partial=0
|
||||
trials=4194296 split_pass=99 codewords=99 candidates=11
|
||||
time=164.670 s rate=25471 trials/s
|
||||
cands_hash=0x56c63d470502aee8
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 2917275 1921054 4031549 1001171 2122060 1902685 3634746 522053 2462819
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cpu: nc=13 partial=0
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=168.330 s rate=24917 trials/s
|
||||
cands_hash=0x67fdae628952aa68
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 12 bits at: 890570 2616517 4117318 731678 2468035 436493 204399 1066127 205524 3172107 3730223 2267138
|
||||
control: standard decode fails as expected
|
||||
suspects: 6
|
||||
cpu: nc=13 partial=0
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=166.697 s rate=25161 trials/s
|
||||
cands_hash=0x7e36640193d2f371
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 10 bits at: 2573515 3309936 1817927 223125 3836982 2344499 4025415 1674867 2505759 2533574
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=10
|
||||
trials=4194296 split_pass=90 codewords=90 candidates=10
|
||||
time=0.305 s rate=13738008 trials/s
|
||||
cands_hash=0xf0ac78a5c0db6077
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 12 bits at: 3172352 1071835 3926998 3247870 3251552 3325465 155676 3753442 1626860 3680006 2968890 315944
|
||||
control: standard decode fails as expected
|
||||
suspects: 6
|
||||
cuda: nc=13
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=0.316 s rate=13258809 trials/s
|
||||
cands_hash=0xff1b6acdbcda946e
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 1139622 1583101 138872 3986032 4059758 2290546 1200718 4107582 2213207
|
||||
control: standard decode fails as expected
|
||||
suspects: 6
|
||||
cuda: nc=9
|
||||
trials=4194296 split_pass=81 codewords=81 candidates=9
|
||||
time=0.292 s rate=14373237 trials/s
|
||||
cands_hash=0xc3dc7b7528027f2c
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,3 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 7 bits at: 3498895 1877890 867125 251131 3784195 2342946 1354710
|
||||
control FAILED: standard decode succeeded on 7-error word
|
||||
@@ -0,0 +1,3 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 8 bits at: 3498895 1877890 867125 251131 3784195 2342946 1354710 492520
|
||||
control FAILED: standard decode succeeded on 8-error word
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 3498895 1877890 867125 251131 3784195 2342946 1354710 492520 135908
|
||||
control: standard decode fails as expected
|
||||
suspects: 6
|
||||
cuda: nc=13
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=0.362 s rate=11601794 trials/s
|
||||
cands_hash=0x5c7f589a39df28b8
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 11 bits at: 3933902 465327 3816380 801717 1488751 2770697 1474470 2075870 803263 2125553 3564454
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=10
|
||||
trials=4194296 split_pass=90 codewords=90 candidates=10
|
||||
time=0.309 s rate=13562801 trials/s
|
||||
cands_hash=0x0828e3f1a1de3768
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 10 bits at: 1826361 717892 152487 785237 531434 2695038 3847765 1073156 1449180 1378323
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=14
|
||||
trials=4194296 split_pass=126 codewords=126 candidates=14
|
||||
time=0.332 s rate=12630048 trials/s
|
||||
cands_hash=0x2478043cdde3ae3e
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 10 bits at: 2607436 1927552 988006 2269250 396460 3929804 123706 24069 746876 2808087
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=12
|
||||
trials=4194296 split_pass=108 codewords=108 candidates=12
|
||||
time=0.322 s rate=13016562 trials/s
|
||||
cands_hash=0x06acc3a69443d342
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 11 bits at: 392468 3185225 2667856 3078904 524650 2513743 2343604 3018313 3280212 3273574 3523990
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=11
|
||||
trials=4194296 split_pass=99 codewords=99 candidates=11
|
||||
time=0.315 s rate=13299619 trials/s
|
||||
cands_hash=0xd0e203ae5074c351
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 12 bits at: 38571 3843158 2832380 2172314 3143789 732683 2822399 477706 1732523 3284823 1535823 1770581
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=9
|
||||
trials=4194296 split_pass=81 codewords=81 candidates=9
|
||||
time=0.285 s rate=14727206 trials/s
|
||||
cands_hash=0xa817ea75c23a4634
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 11 bits at: 7480 711379 3153510 1270250 3083353 1772972 938922 807275 94692 1349411 2303948
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=7
|
||||
trials=4194296 split_pass=63 codewords=63 candidates=7
|
||||
time=0.284 s rate=14768929 trials/s
|
||||
cands_hash=0x64657c5daf8fe7bd
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 3186922 2673650 95755 3163968 1448843 1728624 3938100 3106615 3246295
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=18
|
||||
trials=4194296 split_pass=162 codewords=162 candidates=18
|
||||
time=0.352 s rate=11929751 trials/s
|
||||
cands_hash=0x9fbf8f81ead3e086
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 10 bits at: 1752901 3737741 3059447 2051162 317292 620740 979055 1373300 3126232 2196530
|
||||
control: standard decode fails as expected
|
||||
suspects: 12
|
||||
cuda: nc=11
|
||||
trials=4194296 split_pass=99 codewords=99 candidates=11
|
||||
time=0.311 s rate=13481690 trials/s
|
||||
cands_hash=0x56c63d470502aee8
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 11 bits at: 2942199 3813690 55970 3322604 1721331 1106782 2795398 3273601 2978575 590496 1883743
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=16
|
||||
trials=4194296 split_pass=144 codewords=144 candidates=16
|
||||
time=0.334 s rate=12569297 trials/s
|
||||
cands_hash=0xab869c50c89764d7
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 11 bits at: 4193586 3139026 1537929 3333519 4177005 3421389 1477710 2478458 3490487 446536 2834840
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=12
|
||||
trials=4194296 split_pass=108 codewords=108 candidates=12
|
||||
time=0.318 s rate=13172288 trials/s
|
||||
cands_hash=0xc2ce80d884c0de3a
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 2917275 1921054 4031549 1001171 2122060 1902685 3634746 522053 2462819
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=13
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=0.321 s rate=13079187 trials/s
|
||||
cands_hash=0x67fdae628952aa68
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 12 bits at: 890570 2616517 4117318 731678 2468035 436493 204399 1066127 205524 3172107 3730223 2267138
|
||||
control: standard decode fails as expected
|
||||
suspects: 6
|
||||
cuda: nc=13
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=0.315 s rate=13309357 trials/s
|
||||
cands_hash=0x7e36640193d2f371
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 10 bits at: 1565866 3522582 366564 1232519 2738835 229635 1819150 3469645 3127283 2389929
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=13
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=0.326 s rate=12848095 trials/s
|
||||
cands_hash=0x69622442a318139d
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 12 bits at: 829773 1707577 251473 1166989 1877618 570817 1417188 517337 600769 4129883 74702 301529
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=15
|
||||
trials=4194296 split_pass=135 codewords=135 candidates=15
|
||||
time=0.332 s rate=12614960 trials/s
|
||||
cands_hash=0xf6dc42abffaa291f
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 10 bits at: 1126595 647008 1758360 1802814 1984026 2375369 1613697 336812 4049402 191539
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=8
|
||||
trials=4194296 split_pass=72 codewords=72 candidates=8
|
||||
time=0.290 s rate=14475440 trials/s
|
||||
cands_hash=0x41d95f8afa6ba1ce
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 3397325 2439328 2357346 3286739 3189071 982899 1409094 3266818 3890431
|
||||
control: standard decode fails as expected
|
||||
suspects: 3
|
||||
cuda: nc=11
|
||||
trials=4194296 split_pass=99 codewords=99 candidates=11
|
||||
time=0.303 s rate=13840509 trials/s
|
||||
cands_hash=0x3f83e1d877fff106
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 12 bits at: 1213157 78591 1181322 103384 1872122 2087522 3012246 3571933 208726 2725019 1244306 726765
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=13
|
||||
trials=4194296 split_pass=117 codewords=117 candidates=13
|
||||
time=0.321 s rate=13085423 trials/s
|
||||
cands_hash=0xaa142dccd701c52f
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 9 bits at: 3522960 2484215 2732983 881566 254204 1579905 254093 3743235 1848401
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=17
|
||||
trials=4194296 split_pass=153 codewords=153 candidates=17
|
||||
time=0.340 s rate=12347934 trials/s
|
||||
cands_hash=0xdca91931a24c5d24
|
||||
original among candidates: YES
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 11 bits at: 3292058 983773 450541 316762 2999583 1512213 3313778 3882320 2021991 1212694 1933913
|
||||
control: standard decode fails as expected
|
||||
suspects: 0
|
||||
cuda: nc=12
|
||||
trials=4194296 split_pass=108 codewords=108 candidates=12
|
||||
time=0.317 s rate=13216590 trials/s
|
||||
cands_hash=0x42fd41c1b975b1f5
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,9 @@
|
||||
poly: m=22 t=8 r=176 id=0050 D=524265 stored=524287 nbits=4194296
|
||||
flipped 12 bits at: 2923071 2946792 2830609 3426044 2307790 3343130 3761171 3197071 889853 557680 1404485 682587
|
||||
control: standard decode fails as expected
|
||||
suspects: 9
|
||||
cuda: nc=12
|
||||
trials=4194296 split_pass=108 codewords=108 candidates=12
|
||||
time=0.312 s rate=13429427 trials/s
|
||||
cands_hash=0x1aff72716b878008
|
||||
original among candidates: NO
|
||||
@@ -0,0 +1,64 @@
|
||||
control probe nerr=7 rc=1 : control FAILED: standard decode succeeded on 7-error word
|
||||
control probe nerr=8 rc=1 : control FAILED: standard decode succeeded on 8-error word
|
||||
=== cuda seed=11 nerr=9 2026-12-04T01:22:42Z ===
|
||||
done cuda seed=11 nerr=9 susp=6 cands=13 time=0.362s hash=0x5c7f589a39df28b8 orig=YES
|
||||
=== cuda seed=21 nerr=9 2026-12-04T01:22:43Z ===
|
||||
done cuda seed=21 nerr=9 susp=3 cands=18 time=0.352s hash=0x9fbf8f81ead3e086 orig=YES
|
||||
=== cuda seed=101 nerr=9 2026-12-04T01:22:44Z ===
|
||||
done cuda seed=101 nerr=9 susp=6 cands=9 time=0.292s hash=0xc3dc7b7528027f2c orig=YES
|
||||
=== cuda seed=777 nerr=9 2026-12-04T01:22:45Z ===
|
||||
done cuda seed=777 nerr=9 susp=3 cands=11 time=0.303s hash=0x3f83e1d877fff106 orig=YES
|
||||
=== cuda seed=31337 nerr=9 2026-12-04T01:22:46Z ===
|
||||
done cuda seed=31337 nerr=9 susp=0 cands=13 time=0.321s hash=0x67fdae628952aa68 orig=YES
|
||||
=== cuda seed=8675309 nerr=9 2026-12-04T01:22:47Z ===
|
||||
done cuda seed=8675309 nerr=9 susp=0 cands=17 time=0.340s hash=0xdca91931a24c5d24 orig=YES
|
||||
=== cuda seed=12 nerr=10 2026-12-04T01:22:48Z ===
|
||||
FAILED rc=1 seed=12 nerr=10 impl=cuda (see sweep2/cuda-seed12-nerr10.log)
|
||||
=== cuda seed=22 nerr=10 2026-12-04T01:22:48Z ===
|
||||
FAILED rc=1 seed=22 nerr=10 impl=cuda (see sweep2/cuda-seed22-nerr10.log)
|
||||
=== cuda seed=100 nerr=10 2026-12-04T01:22:49Z ===
|
||||
FAILED rc=1 seed=100 nerr=10 impl=cuda (see sweep2/cuda-seed100-nerr10.log)
|
||||
=== cuda seed=1234 nerr=10 2026-12-04T01:22:50Z ===
|
||||
FAILED rc=1 seed=1234 nerr=10 impl=cuda (see sweep2/cuda-seed1234-nerr10.log)
|
||||
=== cuda seed=55555 nerr=10 2026-12-04T01:22:51Z ===
|
||||
FAILED rc=1 seed=55555 nerr=10 impl=cuda (see sweep2/cuda-seed55555-nerr10.log)
|
||||
=== cuda seed=424242 nerr=10 2026-12-04T01:22:53Z ===
|
||||
FAILED rc=1 seed=424242 nerr=10 impl=cuda (see sweep2/cuda-seed424242-nerr10.log)
|
||||
=== cuda seed=13 nerr=11 2026-12-04T01:22:54Z ===
|
||||
FAILED rc=1 seed=13 nerr=11 impl=cuda (see sweep2/cuda-seed13-nerr11.log)
|
||||
=== cuda seed=31 nerr=11 2026-12-04T01:22:54Z ===
|
||||
FAILED rc=1 seed=31 nerr=11 impl=cuda (see sweep2/cuda-seed31-nerr11.log)
|
||||
=== cuda seed=2024 nerr=11 2026-12-04T01:22:55Z ===
|
||||
FAILED rc=1 seed=2024 nerr=11 impl=cuda (see sweep2/cuda-seed2024-nerr11.log)
|
||||
=== cuda seed=11111 nerr=11 2026-12-04T01:22:56Z ===
|
||||
FAILED rc=1 seed=11111 nerr=11 impl=cuda (see sweep2/cuda-seed11111-nerr11.log)
|
||||
=== cuda seed=98765 nerr=11 2026-12-04T01:22:57Z ===
|
||||
FAILED rc=1 seed=98765 nerr=11 impl=cuda (see sweep2/cuda-seed98765-nerr11.log)
|
||||
=== cuda seed=22222 nerr=11 2026-12-04T01:22:58Z ===
|
||||
FAILED rc=1 seed=22222 nerr=11 impl=cuda (see sweep2/cuda-seed22222-nerr11.log)
|
||||
=== cuda seed=14 nerr=12 2026-12-04T01:22:59Z ===
|
||||
FAILED rc=1 seed=14 nerr=12 impl=cuda (see sweep2/cuda-seed14-nerr12.log)
|
||||
=== cuda seed=42 nerr=12 2026-12-04T01:23:00Z ===
|
||||
FAILED rc=1 seed=42 nerr=12 impl=cuda (see sweep2/cuda-seed42-nerr12.log)
|
||||
=== cuda seed=1000 nerr=12 2026-12-04T01:23:01Z ===
|
||||
FAILED rc=1 seed=1000 nerr=12 impl=cuda (see sweep2/cuda-seed1000-nerr12.log)
|
||||
=== cuda seed=54321 nerr=12 2026-12-04T01:23:02Z ===
|
||||
FAILED rc=1 seed=54321 nerr=12 impl=cuda (see sweep2/cuda-seed54321-nerr12.log)
|
||||
=== cuda seed=77777 nerr=12 2026-12-04T01:23:03Z ===
|
||||
FAILED rc=1 seed=77777 nerr=12 impl=cuda (see sweep2/cuda-seed77777-nerr12.log)
|
||||
=== cuda seed=999999 nerr=12 2026-12-04T01:23:04Z ===
|
||||
FAILED rc=1 seed=999999 nerr=12 impl=cuda (see sweep2/cuda-seed999999-nerr12.log)
|
||||
=== cpu seed=11 nerr=9 2026-12-04T01:23:05Z ===
|
||||
done cpu seed=11 nerr=9 susp=6 cands=13 time=166.680s hash=0x5c7f589a39df28b8 orig=YES
|
||||
=== cpu seed=22 nerr=10 2026-12-04T01:25:52Z ===
|
||||
FAILED rc=1 seed=22 nerr=10 impl=cpu (see sweep2/cpu-seed22-nerr10.log)
|
||||
=== cpu seed=2024 nerr=11 2026-12-04T01:28:37Z ===
|
||||
FAILED rc=1 seed=2024 nerr=11 impl=cpu (see sweep2/cpu-seed2024-nerr11.log)
|
||||
=== cpu seed=42 nerr=12 2026-12-04T01:31:17Z ===
|
||||
FAILED rc=1 seed=42 nerr=12 impl=cpu (see sweep2/cpu-seed42-nerr12.log)
|
||||
=== cpu seed=31337 nerr=9 2026-12-04T01:34:04Z ===
|
||||
done cpu seed=31337 nerr=9 susp=0 cands=13 time=168.330s hash=0x67fdae628952aa68 orig=YES
|
||||
match column filled
|
||||
SWEEP DONE 2026-12-04T01:36:53Z
|
||||
.330s hash=0x67fdae628952aa68 orig=YES
|
||||
SWEEP DONE 2026-12-04T01:36:53Z
|
||||
@@ -0,0 +1,46 @@
|
||||
import glob, os, re, csv
|
||||
rows = []
|
||||
for path in sorted(glob.glob("sweep2/*-seed*-nerr*.log")):
|
||||
m = re.match(r"sweep2/(cpu|cuda)-seed(\d+)-nerr(\d+)\.log", path)
|
||||
if not m: continue
|
||||
impl, seed, nerr = m.group(1), int(m.group(2)), int(m.group(3))
|
||||
txt = open(path).read()
|
||||
def g(pat):
|
||||
mm = re.search(pat, txt, re.M)
|
||||
return mm.group(1) if mm else ""
|
||||
ctrl_fail = "control FAILED" in txt
|
||||
rows.append(dict(seed=seed, nerr=nerr, impl=impl,
|
||||
suspects=g(r"^suspects: (\d+)") or ("CTRL-FAIL" if ctrl_fail else ""),
|
||||
trials=g(r"^trials=(\d+)"),
|
||||
split_pass=g(r"split_pass=(\d+)"),
|
||||
codewords=g(r"codewords=(\d+)"),
|
||||
candidates=g(r"candidates=(\d+)"),
|
||||
time_s=g(r"^time=([0-9.]+)"), rate=g(r"rate=(\d+)"),
|
||||
hash=g(r"^cands_hash=(0x[0-9a-f]+)"),
|
||||
original=g(r"^original among candidates: ([A-Z]+)"),
|
||||
partial=g(r"partial=(\d+)"),
|
||||
note="control-fail: std decode succeeds (nerr<=t)" if ctrl_fail else ""))
|
||||
cuda = {(r["seed"], r["nerr"]): r["hash"] for r in rows if r["impl"]=="cuda" and r["hash"]}
|
||||
for r in rows:
|
||||
if r["impl"]=="cpu" and r["hash"]:
|
||||
k=(r["seed"], r["nerr"])
|
||||
r["match"] = "Y" if k in cuda and cuda[k]==r["hash"] else ("N" if k in cuda else "?")
|
||||
else:
|
||||
r["match"] = ""
|
||||
rows.sort(key=lambda r:(r["nerr"], r["seed"], r["impl"]))
|
||||
with open("sweep2/summary.csv","w",newline="") as f:
|
||||
w=csv.DictWriter(f, fieldnames=["seed","nerr","impl","suspects","trials","split_pass","codewords","candidates","time_s","rate_trials_s","hash","original","partial","match","note"])
|
||||
w.writeheader()
|
||||
for r in rows:
|
||||
w.writerow({"seed":r["seed"],"nerr":r["nerr"],"impl":r["impl"],"suspects":r["suspects"],"trials":r["trials"],"split_pass":r["split_pass"],"codewords":r["codewords"],"candidates":r["candidates"],"time_s":r["time_s"],"rate_trials_s":r["rate"],"hash":r["hash"],"original":r["original"],"partial":r["partial"],"match":r["match"],"note":r["note"]})
|
||||
print("rows:", len(rows))
|
||||
# speedup stats for cpu-verified pairs
|
||||
pairs=[]
|
||||
for r in rows:
|
||||
if r["impl"]=="cpu" and r["hash"]:
|
||||
c=[x for x in rows if x["impl"]=="cuda" and x["seed"]==r["seed"] and x["nerr"]==r["nerr"]]
|
||||
if c: pairs.append((r["seed"],r["nerr"],float(r["time_s"]),float(c[0]["time_s"])))
|
||||
for s,n,ct,gt in pairs:
|
||||
print(f"seed {s} nerr {n}: cpu {ct:.3f}s / cuda {gt:.3f}s = {ct/gt:.1f}x")
|
||||
print("max_cands hits (partial=1 or candidates>=64):", [ (r["seed"],r["nerr"],r["impl"],r["candidates"],r["partial"]) for r in rows if r["partial"]=="1" or (r["candidates"].isdigit() and int(r["candidates"])>=64) ])
|
||||
print("mismatches:", [ (r["seed"],r["nerr"]) for r in rows if r["match"]=="N" ])
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
# Chase-1 extended benchmark sweep #2 — hot_house (parrot), RTX 3080 Ti
|
||||
# Branch experiments/cuda-chase @ 368644a. Read-only benchmarking; no commits/pushes.
|
||||
# CUDA on all patterns; CPU on 5 spread across nerr values.
|
||||
# NOTE: nerr 7/8 cannot run the Chase scan: t=8 standard decode corrects
|
||||
# them, so the harness control check fails by design. Valid nerr: 9-12.
|
||||
set -u
|
||||
cd /root/cuda-chase/lzply || exit 1
|
||||
mkdir -p sweep2
|
||||
SUM=sweep2/summary.csv
|
||||
echo "seed,nerr,impl,suspects,trials,split_pass,codewords,candidates,time_s,rate_trials_s,hash,original,match" > "$SUM"
|
||||
|
||||
run_one() { # $1=impl(cpu|cuda) $2=seed $3=nerr
|
||||
local impl="$1" seed="$2" nerr="$3"
|
||||
local bin="./chase_bench_cpu" flag="--cpu"
|
||||
[ "$impl" = "cuda" ] && { bin="./chase_bench_cuda"; flag="--cuda"; }
|
||||
local log="sweep2/${impl}-seed${seed}-nerr${nerr}.log"
|
||||
echo "=== $impl seed=$seed nerr=$nerr $(date -u +%FT%TZ) ===" | tee -a sweep2/driver.log
|
||||
"$bin" $flag --seed "$seed" --nerr "$nerr" > "$log" 2>&1
|
||||
local rc=$?
|
||||
if [ $rc -ne 0 ]; then
|
||||
echo "FAILED rc=$rc seed=$seed nerr=$nerr impl=$impl (see $log)" | tee -a sweep2/driver.log
|
||||
echo "$seed,$nerr,$impl,,,,,,,,,,rc=$rc" >> "$SUM"
|
||||
return 1
|
||||
fi
|
||||
local susp trials sp cw nc t rate hash orig
|
||||
susp=$(grep -oP '^suspects: \K[0-9]+' "$log" || echo "?")
|
||||
trials=$(grep -oP '^trials=\K[0-9]+' "$log" || echo "?")
|
||||
sp=$(grep -oP 'split_pass=\K[0-9]+' "$log" || echo "?")
|
||||
cw=$(grep -oP 'codewords=\K[0-9]+' "$log" || echo "?")
|
||||
nc=$(grep -oP 'candidates=\K[0-9]+' "$log" || echo "?")
|
||||
t=$(grep -oP '^time=\K[0-9.]+' "$log" || echo "?")
|
||||
rate=$(grep -oP 'rate=\K[0-9]+' "$log" || echo "?")
|
||||
hash=$(grep -oP '^cands_hash=\K0x[0-9a-f]+' "$log" || echo "?")
|
||||
orig=$(grep -oP '^original among candidates: \K[A-Z]+' "$log" || echo "?")
|
||||
echo "$seed,$nerr,$impl,$susp,$trials,$sp,$cw,$nc,$t,$rate,$hash,$orig," >> "$SUM"
|
||||
echo "done $impl seed=$seed nerr=$nerr susp=$susp cands=$nc time=${t}s hash=$hash orig=$orig" | tee -a sweep2/driver.log
|
||||
return 0
|
||||
}
|
||||
|
||||
# Control probes: nerr 7/8 expected to fail (standard decode succeeds)
|
||||
for n in 7 8; do
|
||||
./chase_bench_cuda --cuda --seed 11 --nerr "$n" > "sweep2/cuda-seed11-nerr${n}.log" 2>&1
|
||||
echo "control probe nerr=$n rc=$? : $(tail -1 sweep2/cuda-seed11-nerr${n}.log)" | tee -a sweep2/driver.log
|
||||
done
|
||||
|
||||
# CUDA sweep: 24 new patterns, 6 seeds x nerr 9/10/11/12
|
||||
for n in 9 10 11 12; do
|
||||
case $n in
|
||||
9) seeds="11 21 101 777 31337 8675309" ;;
|
||||
10) seeds="12 22 100 1234 55555 424242" ;;
|
||||
11) seeds="13 31 2024 11111 98765 22222" ;;
|
||||
12) seeds="14 42 1000 54321 77777 999999" ;;
|
||||
esac
|
||||
for s in $seeds; do run_one cuda "$s" "$n"; done
|
||||
done
|
||||
|
||||
# CPU verification on 5 patterns spread across nerr/suspects (~170 s each)
|
||||
for spec in "11 9" "22 10" "2024 11" "42 12" "31337 9"; do
|
||||
set -- $spec; run_one cpu "$1" "$2"
|
||||
done
|
||||
|
||||
# Hash-match check: append match=Y/N to CPU rows by comparing with CUDA rows
|
||||
python3 - <<'PYEOF'
|
||||
import csv
|
||||
rows = list(csv.DictReader(open('sweep2/summary.csv')))
|
||||
cuda = {(r['seed'], r['nerr']): r['hash'] for r in rows if r['impl'] == 'cuda' and r['hash']}
|
||||
for r in rows:
|
||||
if r['impl'] == 'cpu' and r['hash']:
|
||||
k = (r['seed'], r['nerr'])
|
||||
r['match'] = 'Y' if k in cuda and cuda[k] == r['hash'] else ('N' if k in cuda else '?')
|
||||
with open('sweep2/summary.csv', 'w', newline='') as f:
|
||||
w = csv.DictWriter(f, fieldnames=list(rows[0].keys()))
|
||||
w.writeheader(); w.writerows(rows)
|
||||
print("match column filled")
|
||||
PYEOF
|
||||
|
||||
echo "SWEEP DONE $(date -u +%FT%TZ)" | tee -a sweep2/driver.log
|
||||
@@ -0,0 +1,32 @@
|
||||
seed,nerr,impl,suspects,trials,split_pass,codewords,candidates,time_s,rate_trials_s,hash,original,partial,match,note
|
||||
11,7,cuda,CTRL-FAIL,,,,,,,,,,,control-fail: std decode succeeds (nerr<=t)
|
||||
11,8,cuda,CTRL-FAIL,,,,,,,,,,,control-fail: std decode succeeds (nerr<=t)
|
||||
11,9,cpu,6,4194296,117,117,13,166.680,25164,0x5c7f589a39df28b8,YES,0,Y,
|
||||
11,9,cuda,6,4194296,117,117,13,0.362,11601794,0x5c7f589a39df28b8,YES,,,
|
||||
21,9,cuda,3,4194296,162,162,18,0.352,11929751,0x9fbf8f81ead3e086,YES,,,
|
||||
101,9,cuda,6,4194296,81,81,9,0.292,14373237,0xc3dc7b7528027f2c,YES,,,
|
||||
777,9,cuda,3,4194296,99,99,11,0.303,13840509,0x3f83e1d877fff106,YES,,,
|
||||
31337,9,cpu,0,4194296,117,117,13,168.330,24917,0x67fdae628952aa68,YES,0,Y,
|
||||
31337,9,cuda,0,4194296,117,117,13,0.321,13079187,0x67fdae628952aa68,YES,,,
|
||||
8675309,9,cuda,0,4194296,153,153,17,0.340,12347934,0xdca91931a24c5d24,YES,,,
|
||||
12,10,cuda,0,4194296,126,126,14,0.332,12630048,0x2478043cdde3ae3e,NO,,,
|
||||
22,10,cpu,12,4194296,99,99,11,164.670,25471,0x56c63d470502aee8,NO,0,Y,
|
||||
22,10,cuda,12,4194296,99,99,11,0.311,13481690,0x56c63d470502aee8,NO,,,
|
||||
100,10,cuda,3,4194296,90,90,10,0.305,13738008,0xf0ac78a5c0db6077,NO,,,
|
||||
1234,10,cuda,3,4194296,108,108,12,0.322,13016562,0x06acc3a69443d342,NO,,,
|
||||
55555,10,cuda,3,4194296,72,72,8,0.290,14475440,0x41d95f8afa6ba1ce,NO,,,
|
||||
424242,10,cuda,3,4194296,117,117,13,0.326,12848095,0x69622442a318139d,NO,,,
|
||||
13,11,cuda,0,4194296,99,99,11,0.315,13299619,0xd0e203ae5074c351,NO,,,
|
||||
31,11,cuda,0,4194296,108,108,12,0.318,13172288,0xc2ce80d884c0de3a,NO,,,
|
||||
2024,11,cpu,0,4194296,63,63,7,159.671,26268,0x64657c5daf8fe7bd,NO,0,Y,
|
||||
2024,11,cuda,0,4194296,63,63,7,0.284,14768929,0x64657c5daf8fe7bd,NO,,,
|
||||
11111,11,cuda,0,4194296,90,90,10,0.309,13562801,0x0828e3f1a1de3768,NO,,,
|
||||
22222,11,cuda,3,4194296,144,144,16,0.334,12569297,0xab869c50c89764d7,NO,,,
|
||||
98765,11,cuda,0,4194296,108,108,12,0.317,13216590,0x42fd41c1b975b1f5,NO,,,
|
||||
14,12,cuda,0,4194296,81,81,9,0.285,14727206,0xa817ea75c23a4634,NO,,,
|
||||
42,12,cpu,6,4194296,117,117,13,166.697,25161,0x7e36640193d2f371,NO,0,Y,
|
||||
42,12,cuda,6,4194296,117,117,13,0.315,13309357,0x7e36640193d2f371,NO,,,
|
||||
1000,12,cuda,6,4194296,117,117,13,0.316,13258809,0xff1b6acdbcda946e,NO,,,
|
||||
54321,12,cuda,3,4194296,135,135,15,0.332,12614960,0xf6dc42abffaa291f,NO,,,
|
||||
77777,12,cuda,0,4194296,117,117,13,0.321,13085423,0xaa142dccd701c52f,NO,,,
|
||||
999999,12,cuda,9,4194296,108,108,12,0.312,13429427,0x1aff72716b878008,NO,,,
|
||||
|
Reference in new issue
Block a user