Virtual screening: Morgan-style fingerprints and weighted-Tanimoto top-K search
/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 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.
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: 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).
/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.