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 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.
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 the shape and size of /app/inputs/timing_example.in.
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).
/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./app/inputs/timing_example.in has 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.