Weighted mixed-tile tilings of a board with holes
/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 board of H rows and W columns has holes: cell c = r*W + col is a hole when
mix64(seed ^ (c*0xC2B2AE3D27D4EB4F + 0x165667B19E3779F9)) mod 1000 < RHO. Every
non-hole cell must be covered by exactly one tile, tiles may not cover holes or leave the
board, and the 9 tile types have weights w0..w8 (weight 0 disables a type). A tile is
anchored at its first cell in row-major order; its cells relative to the anchor (dr, dc):
| k | tile | cells |
|---|---|---|
| 0 | monomino | (0,0) |
| 1 | horizontal domino | (0,0) (0,1) |
| 2 | vertical domino | (0,0) (1,0) |
| 3 | L | (0,0) (0,1) (1,0) |
| 4 | L | (0,0) (0,1) (1,1) |
| 5 | L | (0,0) (1,0) (1,1) |
| 6 | L | (0,0) (1,-1) (1,0) |
| 7 | horizontal I-tromino | (0,0) (0,1) (0,2) |
| 8 | vertical I-tromino | (0,0) (1,0) (2,0) |
The weight of a tiling is the product of its tile weights. The program computes the sum
of the weights of all tilings modulo the prime P with a cell-by-cell broken-profile DP
whose state is the occupancy bitmask of the 2W cells starting at the current cell
(bit j = cell idx + j; holes count as occupied), i.e. 4^W states.
Input format
W H P RHO SEED
w0 w1 w2 w3 w4 w5 w6 w7 w8
Output format
W=<W> H=<H> P=<P> holes=<number of holes> states=<4^W>
row <r> sum <S> hash <X> (one line per checkpoint row)
tilings <T>
Checkpoint rows are floor((j+1)*H/8) - 1 for j = 0..7 plus H-1, each once, in
increasing order. After finishing row r the window starts at cell (r+1)*W;
S is the sum of all window-state values modulo P and X is the sum over all states
i of mix64((i << 32) | value[i]) modulo 2^64 (values in [0, P)). T is the total
weight of complete tilings (the value of the empty window after the last cell).
Hidden inputs
1 <= W <= 11,1 <= H <= 2000,0 <= RHO <= 1000, weights in[0, P)with at least two non-zero.Pis a prime with2 <= P < 2^30(small primes appear in correctness inputs).- Correctness inputs include
1x1and one-column boards, single tile families (dominoes only, L-trominoes only, I-trominoes only), an all-hole board, andW = 10, 11with few rows. - The timing input has the shape and size of
/app/inputs/timing_example.in.
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:
/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.