Support deterministic kernels inside conditional body graphs#3
Open
johnnynunez wants to merge 2 commits into
Open
Support deterministic kernels inside conditional body graphs#3johnnynunez wants to merge 2 commits into
johnnynunez wants to merge 2 commits into
Conversation
Python.h defines feature-test macros such as _XOPEN_SOURCE and must be included before standard headers. warp.h transitively includes glibc <features.h> (crt.h -> assert.h), so including it before Python.h triggers a macro redefinition warning that fails the -Werror build on newer glibc where _XOPEN_SOURCE defaults to 800. Signed-off-by: johnnynunez <johnnynuca14@gmail.com>
CUDA forbids memory-allocation nodes inside conditional body graphs (wp.capture_while / wp.capture_if), but deterministic launches allocated scatter/counter buffers and CUB workspaces with stream-ordered allocations on the capturing stream. Capturing a deterministic kernel inside a conditional body therefore failed with 'Conditional body graph contains an unsupported operation (memory allocation)'. MuJoCo Warp hits this on every solver step, which iterates via wp.capture_while. Redirect deterministic buffer allocations to a dedicated non-capturing stream while capture is active, under a temporarily relaxed thread capture mode (cudaThreadExchangeStreamCaptureMode), and synchronize the allocation stream before captured work consumes the memory. The captured graph then contains no allocation nodes; buffer lifetime is still tied to the graph via _deterministic_buffer_refs. Because allocation-time initialization no longer replays with the graph, record explicit fill_/zero_ resets on the capturing stream so replays start from clean buffer state. Adds wp_cuda_thread_exchange_capture_mode native API and capture_while regression tests covering the scatter and consumed-return counter paths. Signed-off-by: johnnynunez <johnnynuca14@gmail.com>
This was referenced Jun 10, 2026
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.
Description
Companion fixes for NVIDIA#1355, unblocking mujoco_warp (which launches solver kernels inside
wp.capture_while).CUDA forbids memory-allocation nodes inside conditional body graphs, but
launch_deterministicrecorded stream-ordered allocations for scatter/counter buffers and CUB workspaces on the capturing stream. Capturing a deterministic kernel insidewp.capture_while/wp.capture_iftherefore failed with "Conditional body graph contains an unsupported operation (memory allocation)". This implements the reusable-workspace direction anticipated indesign/deterministic-execution.md:cudaThreadExchangeStreamCaptureMode), and the allocation stream is synchronized before captured work consumes the memory. The captured graph contains zero allocation nodes; buffer lifetime stays tied to the graph via_deterministic_buffer_refs.fill_/zero_resets are recorded on the capturing stream so each replay starts from clean buffer state.wp_cuda_thread_exchange_capture_modenative API and twocapture_whileregression tests (scatter and consumed-return counter paths) modeled on the mujoco_warp solver pattern.Also includes a one-line build fix:
fastcall.cppmust includePython.hbeforewarp.h, otherwise_XOPEN_SOURCEis redefined and the -Werror build fails on newer glibc (defaults to 800).Testing
On RTX PRO 6000 Blackwell (sm_120, CUDA 13.3):
step()underwp.ScopedCapture+capture_whilewithDeterministicMode.RUN_TO_RUN: previously crashed, now runs with bit-identical graph replays