Cohort pileup with depth cap, genotype likelihoods, allele-frequency EM and concordance
/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
A cohort germline SNP-calling job, end to end, in exact integer arithmetic (the CPU source is the
specification; hh(seed,a,b) = mix64(seed + mix64(a*0x9E3779B97F4A7C15 + b)), mix64 = SplitMix64
finaliser).
- Reference and truth. Column
cof aG-column reference has basehh(seed,0,c) & 3; about 0.3% of columns are truth SNP sites with an alternative base and a population allele frequencyf(Q16). Each sample carries the alternative allele on haplotypehwhenhh(seed, 3, s<<40 | c<<1 | h) & 0xFFFF < f. - Reads. Sample
shasR_s = floor(G*COV/RLEN) * (96 + hh(seed,7,s) % 65) / 128reads of query lengthRLEN. Each read is generated from its own hash: start position (uniform, or 12% of reads inside one ofNHOT400-bp amplicon hotspots, which creates very deep columns), mapping quality (8% are mis-mapped with low MAPQ and extra errors), haplotype, optional soft clips, up to two insertions/deletions and the resulting CIGAR (S? M (I|D M){0,2} S?). Read bases and base qualities are hashed per (sample, read, query offset); the true base is the haplotype base, replaced by an error with a quality-dependent probability. Each sample's reads are coordinate-sorted by (start, read index). - Pileup. For every (sample, column) the program collects the eligible observations of the
reads that cover the column: reads with
MAPQ >= MQMIN; an aligned base with raw quality>= BQMIN, or a deletion. Only theCAPobservations with the smallest read keys (khi << 32 | read index) are kept (depth cap). A kept base gets the effective qualitymin(baseQ, MAPQ, 6 + 4*d), wheredis the distance in query bases to the nearest CIGAR boundary with a clip/insertion/deletion (no cap for a pure-match read). - Genotype likelihoods. From the kept bases, integer costs (eighth-bit units) for the 10 diploid genotypes; for a candidate site they are reduced to (ref/ref, ref/alt, alt/alt) and normalised.
- Allele-frequency EM. For each candidate column (alternative allele = the non-reference base
with the largest cohort evidence; needs evidence
>= 64and one sample with>= 2alt bases of evidence>= 140) a fixed-point EM over all samples estimatesf(Q16, at most 24 rounds, stop when it moves by<= 1). - Calls and concordance. Per-sample genotype calls (posterior argmax, integer GQ), site QUAL,
site calls (
QUAL >= 30,f >= 200, at least one confident carrier), and comparison with the truth: TP/FP/FN sites and a genotype concordance matrix on TP sites.
Input format
One line: G S COV RLEN CAP MQMIN BQMIN NHOT seed.
Output format
reads=<total reads> eligible=<eligible obs> kept=<kept obs> kept_del=<kept deletions> capped=<(sample,column) pairs over CAP>
depth_hist <8 counts of eligible depth: 0, 1, 2-3, 4-7, 8-15, 16-31, 32-63, >=64>
candidates=.. called=.. truth=.. tp=.. fp=.. fn=.. fn_carriers=.. em_iters=..
conc RR <called RR> <RA> <AA> <no-call> (rows: truth genotype, TP sites only)
conc RA ...
conc AA ...
af_sum=.. qual_sum=.. site_hash=<16 hex> call_hash=<16 hex>
site <pos> <ref> <alt> af=<Q16> qual=<QUAL> carriers=<n> (first 10 called sites by position)
The hashes are wrapping 64-bit sums over called sites (and over their samples), so they do not depend on evaluation order.
Hidden inputs
1 <= G <= 8000000, 1 <= S <= 64, 1 <= COV <= 60, 64 <= RLEN <= 300, 1 <= CAP <= 64,
0 <= MQMIN <= 60, 0 <= BQMIN <= 41, 0 <= NHOT <= 256, any 64-bit seed.
Correctness inputs (12 files) include a genome with no reads, reads longer than the genome,
CAP = 1, 64 samples without filters, the strictest filters, no hotspots, many hotspots with
deep capping and random small cohorts. The timing input has about 3M columns, 48 samples,
coverage 40, RLEN = 250, CAP = 60, MQMIN = 20, BQMIN = 13 and 96 hotspots.
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 writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- 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. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout is rejected.
- GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: About 50000 to 60000 genomic columns across 48 samples at 40-fold coverage.
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.