Experimental GPU simulator
An experimental GPU port of RocketSim, not used for training yet.
9 min read
gpu-sim/ is an experimental port of RocketSim's physics to the GPU, written in
NVIDIA Warp. It steps many independent arenas in parallel and is
checked against RocketSim with our own scenarios and physlab compare. Training doesn't use it
yet: it can't drive a car on the ground, and there is no GPU training environment. It's an optional
research track that builds on the CPU simulator rather than replacing it.
The work is split into stages named by what they add: B for the ball, C for cars, E for the RL environment (What each stage covers).
The goal isn't "close enough". Every stage so far reproduces RocketSim 0.2.11 + patch P1 bit for bit, so the GPU can eventually stand in for the CPU env without changing what a policy learns.
B1 · Ball + arena
done 51 scenarios (41 shared + 10 GPU-owned edge cases), 29,865 / 29,865 samples bit-identical, events included. Throughput with contact is about the same as 28 CPU threads.
C1 · Car free flight
done 29 scenarios, 3,871 / 3,871 car-ticks bit-identical. About 0.95 G car-ticks/s, ~18× RocketSim on 28 threads.
C2 · Car on flat ground
next Wheel raycasts, suspension, tire friction, ground jumps. Its throughput gate decides whether the GPU path continues.
Where it lives#
gpu-sim/ is its own uv project (Python 3.12, warp-lang==1.18.0, numpy==2.5.4). It is not
part of the root pyproject.toml, and it doesn't need a CUDA toolkit, because Warp bundles NVRTC.
Rust is needed once, to build the oracle.
How it stays bit-exact#
Getting bit-identical output from a GPU port of a Bullet-derived physics engine needed four things.
Exact data from RocketSim itself (the oracle).
tools/make_oracle.pycopiesvendor/rocketsimand applies 9 visibility-only substitutions, making some internal modules and fieldspub. No logic changes. The oracle then dumps what would be hard to rederive:Bullet's local triangle points and normals;
internal-edge info;
BVH leaf visit order;
broadphase proxy AABBs;
the full broadphase grid with every cell's ordered handle list.
ArenaGeometryre-verifies the dump against the.cmffiles bit for bit.Replaying RocketSim's broadphase exactly. Contact order affects the sequential-impulse solver. The GPU therefore replays RocketSim's grid cell lists, not a "body order" approximation. It visits the statics listed in the cell of the ball box's min corner, in insertion order, and leaves a manifold frozen when RocketSim would.
Line-by-line ports with fixed float semantics.
Contacts, manifolds, internal-edge correction and the solver are ported from the Rust sources, with glam's operation order written out by hand.
Every module sets
fuse_fp=False(no FMA contraction) andfast_math=False. Every calling module needs this too, because Warp compiles a@wp.funcinto the caller's module.
The CPU's libm, reproduced. RocketSim calls Rust's f32
sin/cos, which on Windows are UCRTsinf/cosf, and those aren't correctly rounded everywhere.--trig crt(the default) evaluates in f64, rounds to f32, and applies an exhaustive exception table. The oracle enumerates all 2.16e9 f32 inputs with |x| ≤ π and finds 89,808 sin and 103,142 cos inputs that differ.The table is keyed by the hash of
ucrtbase.dll.Without it, 31 ticks in two scenarios end up 1 ulp off.
A few hard-won lessons from building it:
Warp scalar unary minus loses the sign of zero. In Warp 1.18,
-xon a scalarfloat32gives+0forx = +0. The car kernel useswpmath.neg(x)(x·−1) wherever a zero's sign can reach the output.The quaternion is not persistent state. RocketSim re-derives it from the rotation matrix every tick, so the GPU does the same.
Event slots are a memory trade-off. Traces use E = 32 events per env per tick. The API and benchmark default of 8 drops events in reachable states, up to 93 in one tick for random states. Events never feed back into physics.
What each stage covers#
| Stage | Scope | Status |
|---|---|---|
| B1 Ball + arena | Clamp, quantize (P1), damping, plane and mesh contacts, persistent manifolds, internal-edge correction, the ball-only solver, integration, events | done 2026-10-15 |
| B2 Ball performance | Split integrate/contact kernels, compaction of contacting envs, fewer registers. Target ≥ 1.5× B1 at 256k envs | optional, not started |
| C1 Car free flight | Jump, double jump, flip impulse and torque, flip cancel, z-damp, pitch lock, boost, air throttle, air control; a conservative contact-free validity window | done 2026-10-15 |
| C2 Car on flat ground | 4 wheel raycasts on the floor plane, suspension, friction curves, sticky force, ground jumps, landings | next |
| C3 Car vs arena mesh | Wheel rays against the mesh BVH, hitbox vs planes and mesh, wall driving, auto-flip | planned |
| C4 Car–ball | Sphere vs car OBB, shared solver island, RocketSim's extra hit impulse | planned |
| C5 Car–car | Box–box contacts, bumps and demos, respawn | planned |
| E1 RL environment | Torch-native batched env with the task-JSON layout, on-device auto-reset, matching the CPU BatchEnv | after C2 |
The C1 validity window. Cars are only judged while no contact of any kind is possible. In Soccar,
every car origin must be inside |x| ≤ 3350, |y| ≤ 3200, 195 ≤ z ≤ 1920 uu, and more than 205 uu from
the ball and from every other car. The 195 uu floor clears the boost-pad pickup cylinders. The
predicate is conservative: in every scenario where it fires, it fires before RocketSim's first
divergence from free flight. Traces record c1_valid_until_tick.
Performance so far#
All numbers are from an RTX 4070 next to an i7-14700K (28 threads). The GPU was shared with a running Rocket League client, so GPU numbers are lower bounds.
| Workload | GPU | CPU RocketSim, 28 threads | Ratio |
|---|---|---|---|
| Ball, random states with contact (1M envs) | ~74–75 M env-ticks/s | 70–82 M (depends on scheduling) | ≈ 1× |
| Ball, resting/rolling on the floor (1M envs) | 54.6 M | 46.8 M | 1.2× |
Ball, free flight in the_void | 1.29 G | 150 M | 8.6× |
| Car free flight (≥ 65k cars) | ~0.95–0.98 G car-ticks/s | 53 M | ~18× |
What the numbers say:
These are physics-only numbers. Training doesn't use the GPU simulator, so none of this makes training faster today.
Integration is cheap on the GPU. Contact is the bottleneck. The B1 megakernel has a large register footprint and a 348-byte local stack, so occupancy is low. Splitting the kernel and compacting contacting envs is B2 work.
C1 flatters the GPU, because free flight has no contacts. The real question is decided at C2/C3, where wheel rays and arena contacts come in.
Long launches matter.
step(n)loops ticks inside one kernel launch. Shortstep(8)launches lose about 30% for the ball and 10–20% for cars.Memory favours the GPU. About 160 B per car, against ~815 KB per one-car RocketSim arena.
Why not Bullet3 OpenCL?#
Bullet3's GPU pipeline was built and measured before Warp was chosen. It was 6–30× slower than one RocketSim CPU thread, non-deterministic, and wrong out of the box (restitution hard-coded to 0). See Alternatives considered.
Using it#
just gpu-sync # create the gpu-sim venv (add --extra torch for zero-copy torch views)
just gpu-cache # build the oracle, dump geometry + libm trig table, size the bounds
just gpu-test # pytest gpu-sim/tests (146 tests)
just gpu-run scenarios/ball/ball-drop-center-500.json recordings/ball-drop-center-500.gpu-warp.jsonl
just gpu-batch # ~80 scenarios as one GPU batch + RocketSim references + compare
just gpu-validate # gpu-batch, then random ball arenas and random cars bit for bit
just gpu-bench --envs 65536,1048576 --readback --cpu-baseline
just gpu-car-bench --cpu-baseline --with-ballgpu-batch writes gpu-sim/out/gpu/summary.{md,json}. RocketSim references come from a physlab
binary, looked up in this order:
--physlab;$PHYSLAB_EXE;a frozen copy at
gpu-sim/.cache/bin/physlab.exe(present: the 06:52 build, sha256 465b8327…, that all B1 round-2 and C1 results used);target/release/physlab.exe.
The reference cache is keyed by that binary's sha256, so a rebuild with different vendor patches
can't silently reuse stale references. The current target/release build (12:19, sha256
bb5d684d0ffa05c0) hasn't been run against the GPU suite. Against the real game, GPU-vs-real error
equals RocketSim-vs-real exactly on the 37 scenarios with real captures. Details:
Using gpu-sim.
From Python:
from gpusim.sim import BatchBallSim
from gpusim.carsim import BatchCarSim
sim = BatchBallSim(n_envs, device="cuda:0", trig="crt")
sim.set_state(env_ids, pos_uu, vel_uu_s, angvel_rad_s, mode) # mode 1 = soccar, 0 = the_void
sim.step(1200) # ONE kernel launch looping 1200 ticks
state = sim.get_state()
cars = BatchCarSim(n_cars, device="cuda:0", trig="crt")
cars.set_controls(axes, buttons, every=8) # axes [rows,N,5]; buttons bit0 jump, 1 boost, 2 handbrake
cars.step(1200)Open questions#
Throughput with contact. B1 matches 28 CPU threads but doesn't beat them. Re-measure on an idle GPU before trying the B2 ideas.
atan2has no exact table (it has a 2-D domain). It's only used by the internal-edge correction, and no suite tick has shown an effect.C1 coverage gaps. Ported code that only runs after contact (
is_jumping, auto-flip continuation,on_groundbranches) is unexercised until C2.Thread mapping for C4. One thread per car, or one per arena once cars can touch the ball? Running the ball kernel separately already costs about a third of car throughput.