Tile-based analytic-coverage vector path renderer (flatten, cell walk, backdrop, ordered compositing)
/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 tile-based 2D vector-graphics renderer (the kind of pipeline used by GPU font / SVG / UI
renderers) draws an animated scene of P filled paths on a W x H canvas for F frames.
Every frame goes through the full pipeline below; all arithmetic is integer and the CPU source is
the reference for every detail (rounding, clipping, tie rules).
- Scene (generated once from
seed, seegen_scene): each path is a glyph-like shape (75%, radius 3-24 px), a blob (23%, 24-160 px) or a giant (2%, 160-700 px) with 3-16 cubic Bezier segments per contour, optionally a hole contour (reversed or same orientation), a fill rule (nonzero or even-odd), an RGB colour and an opacity. Coordinates are 24.8 fixed point. Centres may lie up to W/8 (H/8) outside the canvas. - Transform: in frame
fpathpis rotated by one of 16 tabulated angles ((rot0 + rspd*f) & 15,costableCOS16,>> 8arithmetic shifts) about its centre and translated byf * (vx, vy). - Flatten: every cubic gets
n= the smallest integer in[1, 48]withn^2 >= ceil(3*dd/128)(or 48), whereddis the largest absolute component of the two second differences of the control polygon; then+1points att = i/nare evaluated exactly in Bernstein form and rounded (floor((sum + n^3/2) / n^3)). Consecutive points form lines. - Cell walk: each line is split at pixel-row boundaries and then at pixel-column boundaries
(crossing coordinates use floor division, see
walk_line/row_piece), producing accumulation-rasterizer cell records(row, col, cover, area)withcover = signed dy(24.8) andarea = cover * (fx_entry + fx_exit). Rows outside[0, H)and cells right of the canvas are dropped; everything left of column 0 is lumped into a per-row gutter cell (cover only). Records of the same path and cell are merged (summed). - Tiling + backdrop: cells are grouped into 16x16 tiles. Along each tile row of a path the
per-pixel-row backdrop (sum of
coverof all cells to the left, including the gutter) is carried across tiles. Tiles touched by cells are edge instances; untouched tiles in a gap whose incoming backdrop gives non-zero coverage in at least one row are solid instances. - Coverage: for a pixel,
A2 = (backdrop + covers left of it in the row + own cover)*512 - own area. Nonzero:a = min(|A2|, 131072); even-odd:a = |A2| mod 262144, folded to262144 - aabove 131072.alpha8 = (a*255 + 65536) >> 17. - Compositing: tiles start from a fixed background gradient; the instances of a tile are
applied in increasing path index (z order) with
a = (alpha8*opacity + 127)/255anddst = (src*a + dst*(255-a) + 127)/255per channel. Only pixels inside the canvas count.
Input format
One line: W H F P seed (canvas width and height in pixels, number of frames, number of paths,
64-bit seed).
Output format
One line per frame:
frame f lines L cells C edge E solid S maxdepth D covered N invisible Z maxarea A@p areahash X img Y rgb R G B
L = flattened line segments, C = merged cell records (including gutter records), E/S =
edge/solid tile instances, D = largest number of instances on one tile, N = canvas pixels with
alpha8 > 0 for at least one path, Z = paths with zero total coverage, A@p = the largest
per-path coverage sum (sum of alpha8 over the path's canvas pixels) and the lowest path index
attaining it (0@-1 if all are zero), X = sum over paths of mix64(area*0x9E3779B97F4A7C15 + p),
Y = sum over canvas pixels of mix64((y*W+x)*0xD1B54A32D192ED03 ^ rgb) (all sums mod 2^64),
R G B = channel sums. A final total ... line aggregates all frames (see source).
Hidden inputs
Correctness inputs (15 files): canvases from 1x1 up to 512x400 (including sizes that are not
multiples of 16), P from 0 to 1500, F from 1 to 4. The timing input is 4096 4096 F P seed
with P in [36000, 44000] and F = 28 at scale 1.0. Valid ranges: 1 <= W, H <= 8000,
0 <= P < 2^20, F <= 64.
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: The timing input renders a 4096x4096 canvas with 36k-44k paths (2% of them giant) for 28 frames; one frame has about 3M lines, 9M merged cells and 1.8M tile instances. 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.