SAC preprocessing of binary CSPs: AC-4 closure plus singleton probing rounds
/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 constraint-solver front-end that preprocesses a batch of generated binary CSPs with arc consistency (AC) followed by singleton arc consistency (SAC) and recommends the first branching variable.
Each instance has n variables with domains that are subsets of {0..d-1} (d <= 64, one
bit per value) and e binary constraints. Everything is generated from the instance seed
with the SplitMix64 finaliser mix64 (see the CPU source for the exact formulas):
- constraint
cjoinsx != y(half of them local:ywithin 8 positions afterx, modn), - its relation is one of four families chosen by a hash, all governed by the tightness
t(per mille): a modular band((al*a + be*b + ga) mod M) < W, a disjunctive precedencea + g1 <= b or b + g2 <= a, a forbidden-distance set|a-b| not in F, or a random table, - the initial domain of every variable is a hashed subset of
{0..d_v-1}(never empty).
The pipeline per instance:
- AC: the arc-consistent closure (largest sub-domains in which every value has a
support on every incident constraint), computed by AC-4 (support counters + worklist).
If a domain empties the instance is
INCONSISTENT. - SAC rounds (at most
R): for every variable with at least 2 values and every valueaof it, a probe setsD(x) = {a}on a private copy and computes the AC closure. The probe fails if a domain empties; otherwise its impact is the number of values it removed from the other variables. After all probes of a round, all failed pairs are removed together and AC is re-established on the base domains (wipeout =>INCONSISTENT). A round without failed probes ends the process with statusSAC; ifRrounds pass, the status isCAPPED. - Branching recommendation: from the probes of the last round, the variable (with at least 2 values left) whose successful probes have the largest total impact (ties: lowest index).
All reported values are properties of unique AC closures, so they do not depend on the order in which removals are propagated; any correct propagation scheme (counters, bit-parallel revisions, synchronous sweeps...) gives the same output.
Input format
K
n d e t R seed (K lines, one instance each)
Output format
Per instance:
instance <i> n <n> d <d> e <e> dom0 <initial total domain size> ac <size after AC | WIPEOUT>
round <r> base <size> probes <P> failed <F> impact <sum of impacts of successful probes> best <x> <a> <impact>
...
summary <i> status <SAC|CAPPED|INCONSISTENT> rounds <r> final <size> pruned <dom0-final> branch <x> <score> digest <16 hex digits>
One round line per executed SAC round. best is the successful probe with the largest
impact, ties broken by smallest x then smallest a (- - 0 if no probe succeeded).
digest = sum over v of mix64(v * 0x9E3779B97F4A7C15 XOR D(v)) (mod 2^64) over the final
domains. For an inconsistent instance the summary is
final 0 pruned <dom0> branch - 0 digest 0; if no variable qualifies for branching,
branch - 0 is printed.
Hidden inputs
1 <= K <= 12, 1 <= n <= 1024, 1 <= d <= 64, 0 <= e <= 4000 (e is forced to 0
when n = 1), 0 <= t <= 1000, 1 <= R <= 64, seeds are 63-bit integers. Correctness
inputs (11 files) include n = 1, single-valued domains, e = 0, a wipeout in the initial
AC, a round cap R = 1, the largest n = 1024, full 64-value domains, random mixes and
small instances near the SAC phase transition. The timing input has 10 instances near the
phase transition with n in [260, 320], d in {32, 48}, e in [4.5n, 5n], t in
[535, 585] and R = 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 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.
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.
- For public GPU experiments, use
/app/bin/gpu_run [--backend auto|local|remote] [--repeat N] [--quiet] SOURCE.cu INPUT_FILE.... The default usesGPU_RUNNER_URLwhen configured, otherwise a GPU attached to this sandbox. Sandbox GPU access is configured independently from verification; a CPU-only sandbox needs a runner URL. - 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 10 generated CSPs near the SAC phase transition, n in [260, 320] variables, domains of 32 or 48 values, about 5n constraints, tightness 0.535-0.585; each needs several SAC rounds of thousands of probes. 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.