Conformer-ensemble strain relaxation with an exact fixed-point bonded force field
/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 conformer-ensemble strain-relaxation job with a bonded molecular-mechanics force field, in
exact fixed-point arithmetic (coordinates Q20 A, energies Q20 kcal/mol, forces Q20 kcal/mol/A;
all products and quotients are 64-bit integer operations with C++ truncating division and
arithmetic right shifts; isqrt64 is the exact floor square root). The CPU source is the exact
specification.
- Topology.
NRESresidues, each with a backbone N-CA-C(=O) linked by peptide bonds and a 0-6 atom side chain on CA (chains with occasional branches; some side chains close a 5- or 6-membered ring onto an ancestor, ring carbons become aromatic). Nine atom types. From the bond graph the program enumerates bonds, angles (every neighbour pair of every atom), Urey-Bradley 1-3 terms (angles centred on CA or backbone C), proper dihedrals (every bond j-k with neighbours i of j and l of k,i != k,l != j,l != i) and one 1-4 pair per dihedral. Parameters come from a fixed hash of the (canonicalised) type tuple. Each atom gets a preconditioneralpha = 2^29 / HwhereHsums the stiffness of the terms it belongs to. - Conformers. Conformer
cgrows the atoms along the build tree on a diamond lattice (bond vectors(+-1,+-1,+-1) * r0/sqrt(3), an unused tetrahedral direction chosen by hash) plus uniform noise of +-0.15 A per coordinate. - Energy and forces (5 classes): bonds and Urey-Bradley
k (r - r0)^2; anglesk (cos - cos0)^2with analytic gradient of the cosine; proper dihedralssum_t k_t (1 + s_t T_{n_t}(cos phi))(ChebyshevT_1..T_3, signs = +-1) with the gradient ofcos phithrough the cross productsm = b1 x b2,n = b2 x b3(bond vectors reduced to Q12, skipped when|m|^2or|n|^2is below(0.05 A^2)^2); 1-4 pairseps (s^6 - 2 s^3)withs = min(sig^2/r^2, 4). Every term adds its forces to its 2-4 atoms (they sum to zero). - Relaxation.
NSTEPsteps; each evaluates energies and forces at the current geometry and moves every coordinate byclamp((F * alpha) >> 30, -0.05 A, +0.05 A). After the last step the geometry is evaluated once more (NSTEP + 1evaluations in total). - Report. Ensemble sums of the initial and final energy per class, the ensemble total at
steps
c*NSTEP/4(c = 0..4), per-conformer RMS forceisqrt(sum (F>>12)^2 / (3N)), the low-energy window and the 10 lowest final energies (ties by conformer index). Energies are printed in 1/1000 kcal/mol as(E * 1000) >> 20(128-bit product).
Input format
One line: NRES NCONF NSTEP SEED.
Output format
TOPO atoms=<N> bonds=<n> angles=<n> ub=<n> dihedrals=<n> dterms=<cosine terms> pairs=<n> alphasum=<sum of alpha>
INIT bond=<E> angle=<E> ub=<E> dihed=<E> pair=<E> total=<E> (ensemble sums before relaxation)
FINAL bond=<E> angle=<E> ub=<E> dihed=<E> pair=<E> total=<E> (after NSTEP steps)
TRAJ <ensemble total at steps 0, NSTEP/4, NSTEP/2, 3*NSTEP/4, NSTEP>
FORCE rms_sum=<sum of per-conformer RMS force> rms_max=<max>
WINDOW emin=<E> emax=<E> median=<E of rank NCONF/2> within10=<conformers within 10 kcal/mol of emin>
BEST <rank> conf=<c> e=<final total> relief=<initial total - final total> (min(NCONF,10) lines)
COORDHASH <hash of all final coordinates>
(WINDOW is omitted when NCONF = 0.)
Hidden inputs
Limits: 1 <= NRES <= 2000, 0 <= NCONF <= 20000, 0 <= NSTEP <= 1000, NRES * NCONF <= 10^6.
Correctness inputs (14 files) include a single residue with NSTEP = 0, NCONF = 0,
NSTEP = 1 and NSTEP = 3 (coinciding checkpoints), a 400-residue molecule with 2 conformers, a
2-residue molecule with 33 conformers, and random runs with NRES in [5, 80], NCONF in
[1, 16], NSTEP in [5, 60].
The timing input has NRES = 200 (about 1400 atoms, 1900 angles, 2400 dihedrals), NCONF
uniform in [2100, 2300] and NSTEP = 100.
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 relaxes about 2200 conformers of a 200-residue molecule (about 1400 atoms and 9000 bonded terms) for 100 steps, i.e. about 3e8 atom-step 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.