Set-partitioned simulation of 24 cache configurations on a 300M-access trace
/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
Trace-driven simulation of up to 64 set-associative cache configurations on one long synthetic memory trace. The CPU source is the exact specification; in outline:
- Trace.
NACCrecords, generated in phases of 4096 accesses. Phasepdrawshp = mix64(seed ^ ((p+1) * 0x9E3779B97F4A7C15))(mix64= SplitMix64 finaliser), which picks the phase type (hp & 15) and an address-space idASID = (hp >> 4) & 3that also offsets the addresses. Types: strided sweeps inside a power-of-two region (types 0-4), uniform random 8-byte accesses in a working set of 8 KiB to 64 MiB (5-8), pointer chasing through a 2^20-nodenexttable with 64-byte nodes (9-12), and a hot stack frame (13-15). Each record packs the 48-bit byte address, the ASID (bits 48-49) and a write flag (bit 50). Records of the strided, random and stack phases are pure functions of(seed, p, offset); a pointer-chase phase walksnextsequentially from a seeded start node. Thenexttable itself is built once by a sequential 64-bit LCG (mostly short forward links, 1/8 random jumps). - Caches. A configuration is
L SL W POL WALLOC XR M0 M1 M2 M3:2^L-byte lines,2^SLsets,Wways, replacement policyPOL(0 LRU, 1 tree-PLRU, 2 SRRIP with 2-bit RRPV, 3 hashed-random), write-allocate flag, XOR-folded set index flag (set = (line ^ line>>SL ^ line>>2SL) mod 2^SL, elseline mod 2^SL), and a way mask per ASID. All caches start empty (LRU ranks = way index, RRPV = 3).- Hit (tag match): a write sets the line's dirty bit; LRU moves the way to MRU, PLRU updates the tree bits, SRRIP sets RRPV 0.
- Miss: counted (total, per ASID and per set). A write miss without write-allocate goes
around the cache. Otherwise the victim is chosen among the ASID's allowed ways (all ways for
PLRU, whose masks are ignored); an empty mask means bypass. Victim: the first invalid allowed
way; else LRU = oldest allowed way, PLRU = the way the tree bits point to, SRRIP = age all
allowed ways until one has RRPV 3 and take the first such, random = the k-th allowed way with
k = mix64(key_cfg ^ (set << 32) ^ fills_set) mod popcount(mask)(fills_setcounts random victim choices in the set). Evicting a dirty valid line counts a writeback. The new line is dirty iff the access is a write; LRU makes it MRU, SRRIP gives it RRPV 2.
- Execution. Accesses to different sets are independent, so the CPU program generates the
trace in chunks of 2^22 records, stably partitions each chunk by set index (once per distinct
(L, SL, XR)mapping, shared by the configurations using it) and simulates every set's accesses in trace order. Each set's result depends only on its own access sequence, so any partitioning or chunking that keeps per-set trace order gives identical output.
Input format
NACC SEED NCFG
L SL W POL WALLOC XR M0 M1 M2 M3 (NCFG lines)
SEED is an unsigned 64-bit integer; masks are unsigned integers using the low W bits.
Constraints: 3 <= L <= 12, 0 <= SL <= 16, 1 <= W <= 16 (a power of two for PLRU),
1 <= NCFG <= 64.
Output format
accesses NACC writes WR asid A0 A1 A2 A3 trace_hash TH
cfg i hits H misses M writebacks WB bypass B around AR amiss M0 M1 M2 M3 dirty D maxset X sethash S
One cfg line per configuration in input order. TH is the sum of mix64(record) over the
trace, D the number of dirty lines left at the end, X the largest per-set miss count and S
the sum over sets s of mix64((s << 32) ^ misses_s), all modulo 2^64. Output is compared exactly.
Hidden inputs
0 <= NACC <= 320000000, 1 <= NCFG <= 32, line sizes L in 4..8, 0 <= SL <= 16, all four
policies, associativities 1-16, masks drawn per ASID (sometimes 0, sometimes full), both write
policies and both index functions. Correctness inputs include NACC = 0 and 1, single-set and
direct-mapped caches, fully associative 16-way caches, 32 unrelated configurations and traces
that cross the CPU chunk boundary. The timing input has 280-320 million accesses and 24
configurations: 6 set mappings (32-128-byte lines, 1024-16384 sets, plain or XOR-folded index)
times the 4 policies.
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 280-320 million accesses and 24 configurations: 6 set mappings (32-128-byte lines, 1024-16384 sets, plain or XOR-folded index) times the 4 replacement policies, with random associativities up to 16, way masks and write policies. 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.