Virtual screening: Morgan-style fingerprints and weighted-Tanimoto top-K search
/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
A complete ligand-based virtual-screening run on a generated compound library. Everything is
derived from SEED with the SplitMix64 finaliser mix64 (exact rules in the CPU source):
- Library generation. Molecule
m(0 <= m < NLIB) is a valence-respecting random graph (elements C N O S F Cl Br P with maximum valences 4 3 2 2 1 1 1 3,AMIN..AMAXheavy atoms, spanning tree with single/double/triple bonds, then up to 3 ring closures of size 5-7 that mark ring atoms and ring bonds). Each molecule consumes a counter-based draw stream; a stream may carry mutation layers that replace individual draws by an alternative stream, which turns a head molecule into close analogues. A quarter of the library are singletons, the rest belong to analogue series of 32 consecutive indices (m >> 5) built around a common head. - Morgan / ECFP-style fingerprints. Every atom gets a 32-bit identifier from its invariants
(element, degree, implicit-hydrogen count, ring flag).
RADIUSsynchronous rounds then replace each identifier by a hash of (round, own identifier, the sorted list of(bond code, neighbour identifier)keys). All identifiers of all rounds form a multiset; a distinct identifier that occursctimes sets the bitsh(id, o) mod NBITSforo = 1..min(c,3)(count folding),NBITS = 64 * NWORDS. - Library statistics. For every bit the number of library molecules that set it. Bits are ranked
by (count descending, bit index ascending); ranks
[0, NBITS/8)form class 0,[NBITS/8, NBITS/2)class 1,[NBITS/2, 7*NBITS/8)class 2, the rest class 3, with class weights1, 2, 3, 5(rare bits weigh more). The weighted popcount of a fingerprint iswpop(x) = sum_c w_c * popcount(x & M_c). - Queries. Query
qis either a de novo molecule (parent = -1) or an analogue of library moleculeparent(its draw stream plus one more mutation layer). - Weighted-Tanimoto search. For every query and every library molecule:
inter = wpop(q & m),uni = wpop(q) + wpop(m) - inter, similarityinter / uni. Each query keeps theTOPKbest molecules ordered by (similarity descending, library index ascending), and counts the hits with similarity>= 0.30(10*inter >= 3*uni) and>= 0.50(2*inter >= uni). Internally a candidate is the key((inter << 40) / uni) << 22 | (0x3FFFFF - m)(larger is better); the printed score isscore6 = ((key >> 22) * 1000000) >> 40. - Report as below. All arithmetic is integer; the output is exact.
Input format
One line: NLIB NQUERY RADIUS NWORDS TOPK AMIN AMAX SEED.
Output format
LIB n=<NLIB> atoms=<total library atoms> bits=<total set bits> fphash=<fingerprint hash> wsum=<sum of library wpop>
CLASS cnt_r1=<count at rank NBITS/8> cnt_r2=<at NBITS/2> cnt_r3=<at 7*NBITS/8> cnt_last=<at NBITS-1>
Q <q> parent=<p|-1> n=<atoms> w=<wpop(query)> hits30=<h> hits50=<h> top: <id>:<score6> ... (first min(NQUERY,24) queries; "top: -" if empty)
SUMMARY queries=<NQUERY> hits30=<total> hits50=<total> parent_top1=<#queries whose best hit is their parent> tophash=<hash of all top lists>
TOP1HIST <10 counts of the best similarity per query in tenths, bin = min(9, ((key>>22)*10)>>40)>
fphash is the sum (mod 2^64) of mix64(word ^ (m * 0x9E3779B97F4A7C15 + w)) over all library
fingerprint words; tophash is the sum of mix64((q << 8 | rank) ^ (id * 0xD1B54A32D192ED03) ^ (score6 << 40))
over all queries and ranks.
Hidden inputs
Limits: 0 <= NLIB <= 4000000, 0 <= NQUERY <= 4096, 1 <= RADIUS <= 4, 1 <= NWORDS <= 32,
1 <= TOPK <= 32, 1 <= AMIN <= AMAX <= 64.
Correctness inputs (14 files) include an empty library, a single molecule, no queries, one-atom
molecules with TOPK larger than the library, 64-bit fingerprints with TOPK = 1 and radius 4,
64-atom molecules, a library smaller than one analogue series, and random runs with
NLIB in [2000, 30000], NQUERY in [16, 64], any radius, NWORDS in {4, 8, 16, 24, 32}.
The timing input has NLIB uniform in [1.9e6, 2.1e6], NQUERY = 1200, RADIUS = 3,
NWORDS = 32 (2048-bit fingerprints), TOPK = 16, AMIN in [11, 13], AMAX in [46, 50].
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.
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.
- For public GPU experiments, use
/app/bin/gpu_run [--backend auto|local|remote] [--repeat N] [--quiet] SOURCE.cu INPUT_FILE.... The default usesGPU_RUNNER_URLwhen configured, otherwise a GPU attached to this sandbox. Sandbox GPU access is configured independently from verification; a CPU-only sandbox needs a runner URL. - 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.
- 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 about 2.0 million library molecules of 11-50 heavy atoms, radius-3 fingerprints of 2048 bits, and 1200 queries with top-16 lists (about 2.4e9 weighted-Tanimoto evaluations). 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.