Banded genotype linkage disequilibrium by AND-popcount over bit planes with missing data
/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.
What the program computes
Banded pairwise linkage disequilibrium between M bit-packed SNP columns of N diploid
samples with missing calls: for every SNP pair (i, j) with 0 < j - i <= WIN, the squared
Pearson correlation r^2 of the two genotype dosage columns over the samples called at both
SNPs, as an exact rational, then threshold counts, a histogram and per-SNP best partners.
Genotypes (all generated in the program; mix64 is the SplitMix64 finaliser of the CPU
source, arithmetic mod 2^64, sF..sX = mix64(SEED + 11) .. mix64(SEED + 18) in the order
sF, sA, sL, sO, sS, sM, sR, sX):
- Founders:
Ffounder haplotypes. At SNPiwith blockb = i / BLKand block frequencyfreq = 20 + mix64(sF ^ b) mod 961(permille), founderfocarries allele[mix64(sA ^ (fo << 32) ^ b) mod 1000 < freq], flipped whenmix64(sX ^ (fo << 32) ^ i) mod 1000 < FLIP. - Sample haplotype
h(0 <= h < 2N, samplesownsh = 2s, 2s+1) copies founders in segments:L_h = 40 + mix64(sL ^ h) mod 400,O_h = mix64(sO ^ h) mod L_h; at SNPiit copies foundermix64(sS ^ (h << 32) ^ ((i + O_h) / L_h)) mod F. - With
u = mix64(sM ^ (i << 32) ^ s), allelek(k = 0, 1) of samplesis flipped when(u >> 10k) mod 1024 < MUT; the dosagegis the number of 1 alleles (0, 1 or 2). The call is missing when(u >> 20) mod 1000 < miss_iwithmiss_i = mix64(sR ^ i) mod (MAXMISS + 1).
The CPU stores three bit planes per SNP (called, g >= 1, g == 2) and gets everything from
nine AND + popcount sums per pair. Over the samples called at both SNPs: n = their number,
Si, Sj = dosage sums, Qi, Qj = sums of squared dosages, P = sum of g_i * g_j.
A pair is valid when n >= NMIN, vi = n*Qi - Si^2 > 0 and vj = n*Qj - Sj^2 > 0. Then
r^2 = num / den with num = (n*P - Si*Sj)^2 and den = vi*vj (exact integers below 2^62), and
q = floor(num * (2^32 - 1) / den) (exact, 128-bit intermediate; 0 <= q <= 2^32 - 1).
Per valid pair: q goes into bin floor(q * 20 / 2^32) of a 20-bin histogram; the pair is
above threshold T = TN/TD when num * TD >= den * TN (exact); pairs above T2 add 1 to the
partner count of both SNPs. Each SNP's best partner maximises q, ties to the smallest partner
index (key q << 32 | (2^32 - 1 - partner), maximum over all valid pairs containing the SNP).
Input format
One line: M N WIN SEED F BLK FLIP MUT MAXMISS NMIN T1N T1D T2N T2D with
1 <= M <= 1,000,000, 1 <= N <= 16384, 0 <= WIN <= 100,000, SEED unsigned 64-bit,
1 <= F <= 64, 1 <= BLK <= 1,000,000, 0 <= FLIP <= 1000, 0 <= MUT <= 1023,
0 <= MAXMISS <= 999, 0 <= NMIN <= 16384, 1 <= T1D, T2D <= 65536, T1N <= T1D,
T2N <= T2D.
Output format
snps M samples N window WIN
pairs PAIRS valid VALID
above_t1 A1 above_t2 A2
hist H_0 ... H_19
qsum QS pairhash PH
partner_count_hash CH
best_partner_hash BH no_partner NP best_q_sum BQ
snp i strong C best J q Q (4 lines, i = 0, M/3, 2M/3, M-1 with integer division)
PAIRS= number of pairs in the band,VALID= valid pairs,A1/A2= valid pairs aboveT1/T2,QS= sum ofqmod 2^64.PH= sum over valid pairs ofmix64((i << 32 | j) ^ (q << 1))mod 2^64.CH= sum over SNPs ofmix64((i << 20) ^ count_i)mod 2^64 (count = partner count).BH= sum over SNPs ofmix64((i << 32) ^ (best_i + 1) ^ 0x5DEECE66D)mod 2^64 withbest_i = -1(sobest_i + 1 = 0) for a SNP without valid pairs;NPcounts those SNPs andBQsums the bestqof the others.- In the
snplinesJ = -1andQ = 0when the SNP has no valid pair.
Hex values are 16 lowercase digits.
Hidden inputs
Correctness inputs (15): a single SNP, WIN = 0, a single sample, a window larger than M,
N = 64, 65, 129 (word boundaries), one founder, no noise (MUT = FLIP = MAXMISS = 0, exact
r^2 = 1 ties) with T1 = 0/1, T2 = 1/1, MAXMISS = 999, MUT = 1023 with 64 founders,
thresholds with denominator 65536, and moderate sizes up to M = 3000, N = 8192,
WIN = 400; plus four random inputs with M <= 3000, N <= 3000, WIN <= 400 and any
parameter values in range. The timing input has M = 180,000-220,000, WIN = 1800-2000,
N = 8000-8192, F = 16-48, BLK = 30-120, FLIP = 20-120, MUT = 4-16,
MAXMISS = 40-150, NMIN = 74-80% of N, T1 in 0.1-0.3 and T2 in 0.5-0.85 (denominators
100-1000): 3.2e8 to 4.4e8 pairs.
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 CPU source is the specification: when this text and the code disagree, the code wins.
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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. Inputs are generated with a new random seed at grading time, so they cannot be known in advance. - Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- Speed: 180,000-220,000 SNPs x 8,000-8,192 samples (about 0.6 GB of bit planes), window 1800-2000, so 3.2e8 to 4.4e8 SNP pairs with nine popcount sums each. 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 a few public inputs./app/bin/run_public.shcompiles your port with the flags above and compares it against the CPU baseline on each of them.