Firewall policy audit with bit-vector packet classification
/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 firewall policy audit: a policy of R prioritised 5-field rules is replayed against E
configuration epochs of traffic. Everything is generated from the seed (see gen_rule,
rule_at and gen_packet in the CPU source).
- Rules. Rule
r(lower index = higher priority) has an inclusive range per field: source IPv4, destination IPv4 (prefixes drawn around 48 generated "networks", or an arbitrary range), source port, destination port and protocol, and an action in 0..3 (0 accept, 1 deny, 2 log, 3 rate-limit). Rule bands go from specific host/service rules at the top to broad rules at the bottom. The last ruleR-1is the default: wildcard, deny. Between epochs every rule is rewritten with probability 1/8 per epoch (new version), and in every epoch each non-default rule is disabled with probability 1/16 (a disabled rule matches nothing). - Packets. Epoch
ehasPpackets; packetiis either aimed at a (priority-skewed) rule of that epoch's policy -- a uniform point inside that rule's five ranges -- or is background traffic; it also has a length in [64, 1500].
Per epoch the program:
- builds the bit-vector classifier: per field the sorted unique boundary points
{0} U {lo_r} U {hi_r + 1}over the enabled rules (the elementary intervals), and for every interval theR-bit vector of enabled rules whose range contains it; - classifies every packet: per field the interval of the value (binary search), AND of the five bit vectors, the lowest set bit is the matching rule (the default rule always matches);
- accumulates per-rule hit and byte counters and prints the epoch report.
Input format
One line: R E P SEED with 1 <= R <= 32768, 1 <= E <= 64, 0 <= P <= 10^9, SEED an
unsigned 64-bit integer.
Output format
Per epoch:
epoch e rules <enabled> iv K0 K1 K2 K3 K4 dead <enabled rules with no hit> default <hits of rule R-1> act a0 a1 a2 a3 accbytes <bytes of accept rules> hash <h_e>
where K_f is the number of elementary intervals of field f, a_k the packets matched by
rules with action k, and h_e = sum over rules with hits of mix64((hits << 24) ^ bytes ^ r*0x9E3779B97F4A7C15).
Then total packets <E*P> never <non-default rules never hit> hash <sum_e mix64(h_e ^ (e+1)*0xD6E8FEB86659FD93)>
and the 10 rules with the most hits over all epochs (top k rule r hits <n> bytes <n>, ties
by smaller r). Sums are modulo 2^64.
Hidden inputs
Correctness inputs (12 files) include R = 1 (default rule only), a single packet, P = 0,
R = 65 (word boundary), R = 20000, seeds 0 and 2^64-1 and random inputs with
R <= 4096, E <= 6, P <= 60000. 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.