Felsenstein pruning under GTR + Gamma4 + I with codon-position rates
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
The phylogenetic log-likelihood of one seeded random rooted binary tree for seeded DNA site
patterns, computed by Felsenstein pruning under GTR + 4-category discrete Gamma + invariant sites +
codon-position rate multipliers, at E points (LAMBDA_e, ALPHA_e) (tree-length scale, gamma
shape). Every evaluation changes every transition matrix, so all partial likelihoods are recomputed
for every point. The CPU source is the exact specification; in outline (FP64 throughout):
- Tree. Leaves are
0..N-1; internal nodeN+j(j = 0..N-2) is created at stepjby a sequential SplitMix64-style generator seeded fromseed: it joins two subtrees taken from the active list (with probability 35% forj > 0the first one is the node created at stepj-1, otherwise a random active subtree; the second is random). Children therefore always have smaller indices than their parent; the root is2N-2. Branch lengths areblen = 0.001 - 0.08 * ln(1 - 0.999 u)for a uniformu.height= longest root-to-leaf edge count. - Model. GTR exchangeabilities
r_AC .. r_GTand frequenciespi(normalised to sum 1); the rate matrix is scaled to mean rate 1, symmetrised withsqrt(pi)and diagonalised by 12 cyclic Jacobi sweeps;P(t)[i][j] = sum_k sqrt(pi_j/pi_i) V_ik V_jk exp(lam_k t), clamped at 0. Category ratesr_c(c = 0..3) are Wilson-Hilferty approximations of the Gamma(alpha, alpha) quantiles at 1/8, 3/8, 5/8, 7/8 (cubes below 0.1^3 replaced by 1e-3), normalised to mean 1. Patternjhas codon positionm = j mod 3with multiplierM_m. The matrix used on the branch above nodevfor categorycand patternjisP(blen_v * LAMBDA_e * r_c * M_m). - Data. Tip states come from counter-based hashes of
(seed, taxon, pattern): a per-pattern ancestral base, a per-taxon divergence probability in [0.02, 0.55), and about 1/128 of the tip entries are ambiguity codesN(any base),R(A or G) orY(C or T). Pattern weights are integers 1..4. A pattern is invariant-compatible for the bases that every tip allows. - Pruning. For a tip with code set
S, its contribution to the parent issum_{t in S} P[s][t]. An internal node's partial is, per categorycand states, the product over its two children ofsum_t P_child(c)[s][t] * L_child(c, t). When all 16 values of a partial are below2^-256they are multiplied by2^256and a per-pattern counterkis incremented (the counts of both children are added); this changes only the representation. - Per-pattern likelihood. With
S = sum_c sum_s pi_s L_root(c, s):ln L_j = ln(0.25 (1-PINV) S) - 256 k ln 2when no base is compatible with all tips, otherwiseln L_j = ln(0.25 (1-PINV) S 2^(-256 k) + PINV * sum_{compatible s} pi_s). The output sums arelnL_e = sum_j w_j ln L_j, accumulated in fixed blocks of 1024 patterns; blockbofNBLKblocks also goes to groupfloor(8 b / NBLK).
The CPU program walks the whole tree for chunks of 32 patterns at a time and sums the blocks in a fixed order, so its output does not depend on the thread count.
Input format
N NPAT SEED
rAC rAG rAT rCG rCT rGT
piA piC piG piT
PINV M0 M1 M2
E
LAMBDA_1 ALPHA_1
...
LAMBDA_E ALPHA_E
SEED is an unsigned 64-bit integer; the other non-integer values are decimals.
Output format
taxa N patterns NPAT height H weight W
eval e lnL X (for e = 0..E-1)
groups e G0 G1 ... G7 (after each eval line)
W is the sum of the pattern weights. Floating-point values are printed with %.12e and compared
with a relative tolerance of 1e-9 plus an absolute tolerance of 1e-6; integer tokens and words
must match exactly. FP64 arithmetic is required (any summation order, FMA use or rescaling scheme
is fine; FP32 partials will not meet the tolerance).
Hidden inputs
2 <= N <= 2000, 1 <= NPAT <= 1050000, 1 <= E <= 8. Exchangeabilities in [0.2, 6],
frequencies in [0.1, 0.4] before normalisation (or all equal), 0 <= PINV <= 0.5, codon
multipliers in [0.2, 3], LAMBDA in [0.2, 3], ALPHA in [0.2, 5]. Correctness inputs include
N = 2 with one pattern, Jukes-Cantor parameters, very short and very long branches, the largest
tree (N = 2000, deep rescaling), NPAT values that are not multiples of 1024 and E = 8. The
timing input has 950-1050 taxa, 950,000-1,050,000 site patterns and 6 evaluations.
Your task
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.
This sandbox is for source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
How you are scored
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -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. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- Correctness: every hidden input (small edge cases plus the timing input) must pass.
Your output must have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 1e-09 and atol = 1e-06; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input has 950-1050 taxa (tree height about 30-40), 950,000-1,050,000 weighted site patterns and 6 (tree-length scale, gamma shape) evaluations, each recomputing all partials. Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds public input examples for understanding the input format.