Adaptive quadtree refinement around algebraic curves with exact 128-bit interval predicates, 2:1 balance and Morton-ordered leaves
/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
For each of several independent scenes, an adaptive quadtree over the square [-H, H]^2
(H = 2^(D-1), integer coordinates) is refined wherever one of up to 16 bivariate integer
polynomials may vanish, then made 2:1 balanced, and its leaves are listed in Morton order. All
arithmetic is exact (128-bit integers); the CPU source is the reference for every detail.
Cells. A cell of level L (0 <= L <= D) has side s = 2^(D-L) and a Morton code that
interleaves its column index i (even bits) and row index j (odd bits); it is the closed box
[i*s - H, i*s - H + s] x [j*s - H, j*s - H + s]. The root is level 0, code 0.
Polynomials. Polynomial k has a depth limit d_k, an origin (ox_k, oy_k) and terms
c * X^a * Y^b with X = x - ox_k, Y = y - oy_k, a, b >= 0, a + b <= 6. Its enclosure over a
cell is computed term by term: the exact ranges of X^a and Y^b over the cell's intervals, the
product interval from the four endpoint products, scaled by c, and summed. The polynomial may
vanish in the cell if the summed interval contains 0. The partial derivatives dp/dX and dp/dY
(coefficients times exponents, same origin) are tested the same way.
Refinement. Cells are evaluated level by level starting from the root. A cell tests the
polynomials that may vanish in its parent (all of them for the root; the enclosure is inclusion
monotone, so this equals testing all). A = polynomials that may vanish; the cell is singular
if for some k in A both partial derivatives may vanish too, and crossing if |A| >= 2. A cell
of level L < D is refined (gets 4 children) iff A is not empty and
L < min(D, max_{k in A} d_k + (E if crossing or singular else 0)).
Balance. Leaves sharing an edge or a corner must differ by at most one level. The minimal such
refinement is built from fine to coarse: for L = D-1 .. 1, for every internal node of level L,
the parents of all cells of its 3 x 3 neighbourhood at level L (clipped to the domain) become
internal. balance_added counts the internal nodes created this way.
Leaves. The children of internal nodes that are not internal themselves (or the root alone).
A leaf of level L and code m has key ((m << 2(D-L)) << 5) | L; with keys sorted ascending
(r = rank from 0), hash = sum_r mix64((r * 0x9E3779B97F4A7C15) ^ key_r) mod 2^64 (mix64 is
the SplitMix64 finaliser).
Input format
scenes S
scene D E K (then K polynomial lines)
poly d_k ox_k oy_k T a_1 b_1 c_1 ... a_T b_T c_T
Output format
Per scene:
scene s depth D leaves NL internal M balance_added A crossing X singular Y hash H
level L evaluated e refined r internal i leaves l (levels with any nonzero count)
crossing and singular count evaluated cells; evaluated and refined are per level before
balancing, internal and leaves per level after it.
Hidden inputs
1 <= S <= 8,1 <= D <= 20,0 <= E <= 6,0 <= K <= 16,0 <= d_k <= D,1 <= T <= 28,|ox_k|, |oy_k| <= H; for the polynomial and both partial derivatives,sum |c| (H + |ox|)^a (H + |oy|)^b < 2^125.- Curves: circles, ellipses and hyperbolas, elliptic cubics (with nodes and cusps), lemniscates, three- and four-petal roses (multiple points), Cassini ovals, products of two circles, products of 2-4 lines, dense random polynomials of degree 3-6, and lines on the domain border.
- Correctness inputs include
D = 1,K = 0, constant polynomials, depth limits 0, curves on the domain border, 16 polynomials in one scene, depth coming only from crossings,D = 20with the largest coefficient magnitudes, and every curve family alone. - The timing input has 8 scenes with
D = 20,Ein 1..3 and 12-16 curves each (every family at least once, depth limits 19-20; 13-14 for products of curves, 18-19 for random polynomials): about 6e8 evaluated cells and 5e8 leaves in total.
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 8 scenes of depth 20, each with 12-16 curves (circles, conics, cubics, lemniscates, roses, Cassini ovals, products of circles or lines, random sextics), about 6e8 evaluated cells and 5e8 leaves in total. 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.