Event-driven spiking network with delayed plastic synapses
/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
An event-driven simulation of a spiking network of N integer leaky integrate-and-fire neurons
with adaptive thresholds, refractory periods, delayed synapses and a simple plasticity rule. The
CPU source is the exact specification; in short (mix64 = SplitMix64 finaliser, all arithmetic
on integers):
- Neurons. Neuron
iis inhibitory ifi % 5 == 4and excitatory otherwise. Each neuron has a membrane valuev, a threshold offsettheta, a refractory counter, the time of its last spike and a trace; all start at zero (last spike at-10^6). - Synapses (CSR by source). Neuron
ihas fan-outf_i = S/2 + (h_i mod S)(0 whenS = 0) withh_i = mix64(SEED ^ (0x9E3779B97F4A7C15 * (i+1))), multiplied by 4 for hubs ((h_i >> 32) mod 100 == 0, about 1% of the neurons). Synapses are numbered contiguously in neuron order; synapsesof neuroniusesh = mix64(SEED ^ (0xD1B54A32D192ED03 * (s+1)) ^ 0x5851F42D4C957F2D): if(h & 1023) < 717it is local, with target(i + ((h >> 10) mod 8193) - 4096) mod Nand delay1 + ((h >> 24) mod min(D, 4)); otherwise its target is(h >> 10) mod Nand its delay1 + ((h >> 40) mod D). The initial weight is8 + ((h >> 50) mod 40)for an excitatory source and-16 - ((h >> 50) mod 64)for an inhibitory one. - Step
t(t = 0 .. T-1), phase 1 for every neuron: takeinfrom the input ring slott mod Dand clear it. If the refractory counter is positive, decrement it and setv = -100; otherwisev = clamp(v - (v >> 4) + in + ext, -2000, 4000)whereext = AEXTif the low 16 bits ofmix64(SEED ^ (0xA0761D6478BD642F * (t+1)) ^ (0xE7037ED1A0B428DB * (i+1)))are belowPEXT, else 0. Thentheta -= theta >> 6. If the counter is zero andv >= 1000 + thetathe neuron spikes:v = -100, the counter becomes 3 (excitatory) or 1 (inhibitory),thetagrows by 200 or 50, the spike time and the neuron's spike count are updated. Finally the trace is 2 if the neuron spiked within the last 4 steps (t - last < 4), else 1 ifv > 500, else 0. - Phase 2: every neuron that spiked at step
tdelivers along all its synapses: slot(t + delay) mod Dof the target receivesweight * 1(excitatory source) orweight * 4(inhibitory source). After delivering, an excitatory synapse is updated from its target's trace: weightmax(1, w - 2)if the trace is 2,min(63, w + 1)if it is 1. Phase 1 of a step completes before its phase 2, so the result does not depend on the order of deliveries.
Input format
One line: N S D T PEXT AEXT SEED.
Output format
snn N=<N> excitatory=<number of excitatory neurons> synapses=<total synapses> D=<D> T=<T>
step <t> spikes=<spikes at step t> (t = floor(T*k/20) for k = 0..19 and t = T-1, distinct, in order)
spikes exc=<total excitatory spikes> inh=<total inhibitory spikes> events=<synaptic deliveries>
rate_permille exc=<exc spikes * 1000 / (exc neurons * T)> inh=<likewise> (0 when undefined)
count_hash <sum_i mix64((i << 24) | count_i)>
step_hash <sum_t mix64((t << 32) | spikes_t)>
state_hash <sum_i mix64((i << 32) ^ (uint32)v_i ^ ((uint32)theta_i << 40))>
weight_sum <sum of final weights> weight_hash <sum_s mix64((s << 8) | (uint8)w_s)>
All hashes are sums modulo 2^64.
Hidden inputs
1 <= N <= 2,000,000,0 <= S <= 600,1 <= D <= 32,0 <= T <= 100,000,0 <= PEXT <= 65536,0 <= AEXT <= 5000, any 64-bitSEED.- Correctness inputs include a single neuron without synapses, a single neuron with self-synapses,
five neurons with dense multi-edges and
D = 32,T = 0, no external drive (a silent network), saturating drive,D = 1,N = 2,000,000with a very sparse network, the largest fan-out withD = 32, a short run of the timing shape, and random small configurations. - The timing input has about 500,000 neurons,
S = 300(about 1.5e8 synapses),D = 16,PEXT = 6000,AEXT = 500and about 4,500 steps; after a short transient under 1% of the neurons spike in a step, so each step delivers about a million synaptic events.
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: One input with about 500,000 neurons, S = 300 (about 1.5e8 synapses), D = 16, PEXT = 6000, AEXT = 500 and about 4500 steps.
/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.