Port an OpenMP program computing the full DDT (differential uniformity) and Walsh spectrum (linearity) of thousands of keyed 10/11-bit S-boxes to CUDA
harbor run -t elfsong/cpu2gpu-bits-sbox-spectraharbor download elfsong/cpu2gpu-bits-sbox-spectra/app/cpu/main.cpp is a multicore CPU program (C++17, OpenMP). It is built as
/app/bin/cpu_baseline with g++ -O3 -march=native -fopenmp -std=c++17 and run as
cpu_baseline INPUT_FILE
It reads one input file and writes its result to stdout.
Each query describes a family of S-boxes S_p : {0..2^m-1} -> {0..2^m-1} for the
consecutive parameters p = p0 .. p0+N-1. S_p is built from mix64(seed ^ (p * 0x9FB21C651E98DF25)):
a keyed chain of an affine multiply, a chi-like y ^= rot(y,r1) & rot(y,r2), a second
multiply, an and-not step and a final addition, all mod 2^m (exact definition in the CPU
source). S_p is not necessarily a permutation.
For each S-box the program computes:
delta (differential uniformity): the maximum, over input differences a != 0 and all
output differences b (including b = 0), of #{x : S(x) ^ S(x^a) = b}; ndelta is
the number of (a, b) pairs attaining it.lin (linearity): the maximum, over output masks b != 0 and all input masks a
(including a = 0), of |sum_x (-1)^(popcount(b & S(x)) + popcount(a & x))|; nlin is
the number of (a, b) pairs attaining it.Q
m p0 N seed
... (Q lines)
Four lines per query, in input order:
qi m=M sumDelta=.. sumLin=.. hash=..
delta: v:count v:count ... (histogram of delta, ascending values)
lin: v:count ... (histogram of lin, ascending values)
best: p/delta/ndelta/lin/nlin ...
hash is the sum over p of mix64(p ^ (delta<<40) ^ (lin<<20) ^ (ndelta<<7) ^ (nlin<<50))
modulo 2^64. best lists the (up to) 8 S-boxes with the smallest (delta, lin, p).
When N = 0 the histogram and best lines are empty after the colon.
4 <= m <= 11, 0 <= N <= 4000, p0 + N may wrap modulo 2^64 (64-bit unsigned
arithmetic), seed any 64-bit value.N = 0, N = 1, every m from 4 to 11, and a range that
wraps around 2^64.m = 10 with 3400..4000 S-boxes or
m = 11 with 800..920 S-boxes.Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
/app/gpu/main.cu is collected. It is compiled with
nvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked.
The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust,
libcu++) are allowed.system(, popen(, fork(, exec*, dlopen(, getenv(,
#include <filesystem>, /tests/, /proc/. The program may read only the input file it is given./app/bin/gpu_run [--backend auto|local|remote] [--repeat N] [--quiet] SOURCE.cu INPUT_FILE.... The default uses GPU_RUNNER_URL
when configured, otherwise a GPU attached to this sandbox. Sandbox GPU access is
configured independently from verification; a CPU-only sandbox needs a runner URL.reward = min(2, t_reference / t_yours) using the medians./app/inputs/ holds a few public inputs. /app/bin/run_public.sh compiles your port with the
flags above and compares it against the CPU baseline on each of them.