Repository navigation
Avoid atomics in deterministic actuation derivative, contact force and sleep kernels - #1935
Closed
johnnynunez wants to merge 7 commits into
Closed
johnnynunez wants to merge 7 commits into
johnnynunez wants to merge 7 commits into
Conversation
With `DeterminismType.ATOMICS`, `_qderiv_actuator_passive_actuation_sparse` scattered `moment_i * moment_j * vel` into `qDeriv` with a float atomic compiled in Warp's `RUN_TO_RUN` mode, which records and sorts every contribution. With the implicit integrators that launch took about 786 us per step on the Franka Panda benchmark with 32768 worlds, against 19 us for the default kernel, and about 4269 us against 22 us on the Unitree G1 benchmark with 8192 worlds. The deterministic variant now lets the thread of the first actuator of each world accumulate all the actuators of that world in ascending order with plain loads and stores. Each element has one writer and a fixed summation order, and the compiled kernel has no atomic left, so Warp neither allocates scatter buffers nor sorts. The update is written as `x = x + y` because Warp compiles `+=` on an array element to an atomic. The launch now takes about 39 us per step on the Franka Panda benchmark and 60 us on the Unitree G1 benchmark. The factory signature, its `RUN_TO_RUN` module options and the default kernel are unchanged: the generated CUDA source of the default variant is the same as before. Add a test that compares the deterministic derivatives with MuJoCo and with the default kernel for one and two worlds, on a model where every degree of freedom is driven by several actuators.
The deterministic variant of `_cfrc_ext_contact` added the wrench of each contact to its two bodies with float atomics, which Warp's RUN_TO_RUN mode replays through scatter buffers. The deterministic kernel now stores the force of each contact in its own slot and marks, with an integer maximum, the first constraint row of the contacts of each body. `_cfrc_ext_contact_body` then runs one thread per body, which walks the constraint rows from that mark and adds the contacts of its body in row order. The default kernel is not edited. Unitree G1 (8192 worlds), time per step of the launches: 383 us before, 91 us now for the two kernels, 34 us for the default kernel.
The deterministic variants of `_update_sleep_bodies` and `_update_sleep_dofs` allocated a list slot with an atomic counter, which Warp's RUN_TO_RUN mode replays with a counting pass and a prefix scan. The body list is now written by the thread of the first body of each world, in ascending order. The dof list is written with one thread per tree: the thread counts the dofs of the awake trees before its tree and writes the dofs of its tree after them. The default kernels are unchanged. ALOHA clutter (256 worlds, four launches per step), time per step: `_update_sleep_bodies` 1025 us before, 120 us now, 73 us by default; `_update_sleep_dofs` 890 us before, 66 us now, 59 us by default.
This was referenced Nov 10, 2026
Open
With opt.deterministic & ATOMICS, _cfrc_ext_contact_body walks the constraint rows of a world from the first contact of each body and read the type of every row it landed on, to step over rows that are not contacts. The contact rows are the last rows of a world (the constraint kernels rely on it already), so every row the walk lands on is the first row of a contact: the load of efc.type and its branch are removed. The default kernel is not edited. unitree_g1_flat, 8192 worlds, Nsight Systems, us of GPU time per step: _cfrc_ext_contact_body 10.7 -> 9.0 (three runs: 9.0, 9.2, 8.9) _cfrc_ext_contact 8.6 -> 8.7 default _cfrc_ext_contact 9.7 Measured on top of this and rejected (body kernel + contact kernel): stopping the walk of a body at its last contact row 9.1 + 9.0; force and position of a contact in one element 8.3 + 9.0; bodies, force and position in one struct per contact 8.4 + 9.1.
This was referenced Nov 12, 2026
Contributor
Author
|
Benchmarks on main 60dbbdf:
"fails": Warp's scatter buffer for a kernel exceeds int32: the solver's (#1933) on main and with this PR alone, the actuation derivative's on the G1 without this PR. With NONE this PR is within 0.1% of main on the three benchmarks. |
Collaborator
|
@johnnynunez plan for now is to utilize warp's built-in deterministic atomics functionality |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
opt.deterministic=ATOMICS,_qderiv_actuator_passive_actuation_sparse,_cfrc_ext_contact,_update_sleep_bodiesand_update_sleep_dofsrun float atomics or atomic counters in Warp'sRUN_TO_RUNmode. Their deterministic variants now need no scatter buffers: one thread per world sums the derivatives in order, one thread per body adds its contacts in constraint row order (new kernel_cfrc_ext_contact_body), and one thread per tree writes its awake dofs. The default kernels generate the same CUDA source as before.Launch time per step, before to after (default): Unitree G1 with 8192 worlds, derivatives 3360 to 63 us (22) and contact forces 385 to 100 us (32); ALOHA clutter with 256 worlds, sleep lists 1995 to 191 us (133).
mjwarp-testspeedon franka_emika_panda with ATOMICS, median of 3: 4.88M to 11.36M steps/s; NONE is unchanged (44.8M).Merges cleanly with #1932 and #1933. #1790 and #1680 edit the same sleep kernels and will conflict.
cc @thowell @adenzler-nvidia