Port an OpenMP exhaustive exact-cover search that counts all packings of distinct random polyominoes into boards with blocked cells to CUDA and make it fast
harbor run -t elfsong/cpu2gpu-enum-polyomino-packharbor download elfsong/cpu2gpu-enum-polyomino-pack/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.
Each instance is a rectangular board (at most 64 cells) with some blocked cells and a list
of P polyomino pieces. A packing places every piece exactly once (any of its 8
rotations/reflections, deduplicated, translated onto the grid) so that pieces do not
overlap, never cover a blocked cell, and together cover every free cell. Pieces are
distinguishable by their index, so two pieces with the same shape swapped give two packings.
For every instance the program counts all packings by exhaustive search (fill the first free cell in row-major order, try every unused piece/orientation whose first cell lands there) and reports the count plus two order-independent fingerprints of the set of packings.
T
R C P
<R lines of C characters: '.' free, '#' blocked>
s_1 r c r c ... (piece 1: s_1 cells as row/column pairs)
...
s_P r c r c ...
(next instance ...)
R*C <= 64, C <= 64, 0 <= P <= 21, piece sizes 3..6. The total piece area always equals
the number of free cells.
One line per instance, in input order:
R C P COUNT HASH MINSIG
p (0-based, input order) covering board cells mask
(bit r*C+c), key = mix64(mask XOR ((p+1) * 0xD6E8FEB86659FD93)) (64-bit wrap).
A packing's signature sig is the sum of the keys of its pieces modulo 2^64.HASH = sum of mix64(sig) over all packings mod 2^64, MINSIG = smallest sig;
both printed as 16 lowercase hex digits. mix64 is the SplitMix64 finaliser in the CPU source.COUNT is 0 the line is R C P 0 0 -. An instance with no pieces and no free cells
has exactly one (empty) packing with sig = 0.Boards are generated by randomly blocking a few cells and partitioning the remaining cells into random connected pieces, so at least one packing always exists. Correctness inputs include 1-row strips (many congruent straight pieces, counts up to ~10^6), tiny boards, a fully blocked board with zero pieces, boards of 4x4 to 8x8 and 5x10, 3x12, 7x7. In most instances piece shapes are pairwise non-congruent. The timing input has 80 8x8 boards with 3-4 blocked cells and exactly 12 pairwise non-congruent pieces of 4-6 cells; the work per board varies by an order of magnitude.
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.
/app/gpu/main.cu is collected. It is compiled with
nvcc -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.system(, popen(, fork(, exec*, dlopen(, getenv(,
#include <filesystem>, /tests/, /proc/. The program may read only the input file it is given.nvcc works 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.reward = min(2, t_reference / t_yours) using the medians./app/inputs/ holds a few public inputs. /app/bin/run_public.sh compiles your port with the
flags above and compares it against the CPU baseline on each of them.