Exact fixed-point P1 tetrahedral finite-element assembly into CSR on a randomly numbered unstructured mesh
/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
Exact (fixed-point integer) assembly of P1 finite-element matrices on an unstructured tetrahedral
mesh, repeated for several coefficient fields on a deforming mesh, each followed by a matrix-vector
product. All hashes use the SplitMix64 finaliser mix64 of the CPU source; all model data come from
SEED exactly as in the CPU source.
- Mesh. An
NHX x NHY x NHZgrid of cells with spacing 32 and integer coordinates: corner(i, j, k)at32*(i, j, k)plus a hashed jitter in[-3, 3]^3, and one centre vertex per cell at32*(i, j, k) + 16plus a jitter in[-2, 2]^3. A cell is removed when its hash (per mille) is belowDROPor when it lies in one ofNSPHspherical cavities (integer test in cell-index space). Each kept cell is split into 12 tetrahedra: each of its 6 faces is cut along one diagonal (chosen by a hash of the global face id, so both cells sharing a face agree) and each half-face triangle forms a tetrahedron with the cell's centre vertex. A tetrahedron's vertex order is (centre, three face corners), with the last two swapped when needed so thatD = 6 * volume > 0. - Numbering. Vertex labels are a pseudo-random permutation of
[0, NV)(4-round Feistel network with cycle walking) of the structured ids (NV= all corners + one centre per cell, kept or not; vertices without elements have empty rows). Element12*rank(cell) + localis stored at positionpgiven by another such permutation of[0, E). - Pattern. The
NV x NVCSR pattern: entry(i, j)exists iff verticesiandjshare an element (includingi = j). - Assemblies
a = 0 .. NASM-1. Every vertex is displaced by a hashed offset in{-1, 0, 1}^3(elements stay valid). For elementpwith verticesv0..v3, edgese_m = x(v_m) - x(v0), cofactor vectorsb1 = e2 x e3,b2 = e3 x e1,b3 = e1 x e2,b0 = -(b1 + b2 + b3),D = e1 . b1,R = floor(2^40 / (6 D)), and coefficientscin[1, 64],sin[0, 15]hashed from(a, p), the element-matrix entry(m, n)is((c * (b_m . b_n) * R) >> 24) + floor(s * D * 65536 * (1 + [m == n]) / 120)(64-bit, arithmetic shift), added into CSR slot(v_m, v_n)for all 16 pairs. Everything is exact int64 (no overflow), so the matrix does not depend on summation order. - Product.
y = K xin int64 withx_j = (hash & 0xFFFF) - 32768.
Input format
One line: NHX NHY NHZ NASM NSPH DROP SEED (1 <= NHX, NHY, NHZ <= 1024, NHX*NHY*NHZ <= 3000000,
1 <= NASM <= 16, 0 <= NSPH <= 16, 0 <= DROP <= 1000, SEED unsigned 64-bit).
Output format
mesh hexes NH kept P vertices NV tets E
pattern nnz Z empty Z0 maxrow M hash H
asm A trace T total S hash HV ysum Y yhash HY (NASM lines, A = 0..NASM-1)
empty= rows without entries,maxrow= longest row,hash= sum over all pattern entries ofmix64(i << 32 | j)modulo 2^64.- Per assembly:
trace= sum ofK_ii;total= sum of allK_ij;hash= sum over entries ofmix64(mix64(i << 32 | j) ^ K_ij);ysum= sum ofy_i;yhash= sum ofmix64(y_i ^ (i * 0x9E3779B97F4A7C15))(sums modulo 2^64; signed ones printed as int64).
All values are exact integers; the order of the entries inside your data structures does not matter.
Hidden inputs
- Grids from
1 x 1 x 1up to 126 cells per side,1 <= NASM <= 16,0 <= NSPH <= 16,0 <= DROP <= 1000. - Correctness inputs include a single cell, a grid with every cell removed (no elements, all rows
empty), one-cell-thick rods and slabs, 16 assemblies, 16 cavities, half of the cells dropped, and
a
40^3grid. - The timing input has 114-126 cells per side (about 1.4-1.9M kept cells, 16-23M tetrahedra, about
40-60M CSR entries), 3-8 cavities,
DROP20-80 and 7-9 assemblies.
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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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.
- 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 114-126 cells per side (about 16-23M tetrahedra and 40-60M CSR entries) and 7-9 assemblies, each followed by one product K x. 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 public input examples for understanding the input format.