Firewall policy audit with bit-vector packet classification
/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 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 R = 16384, E = 8 and
P = 25,000,000 packets per epoch.
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 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. - This sandbox has no GPU.
nvccworks 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. - 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.
- Speed: The timing input has a 16384-rule policy over 8 epochs (about 12-16k elementary intervals per address/port field) and 25 million packets per epoch, 200 million in total. 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.