onnxruntime
c47718e2 - Fix data race in CUDA graph tests: add SynchronizeInputs/SynchronizeOutputs (#29398)

Commit
9 days ago
Fix data race in CUDA graph tests: add SynchronizeInputs/SynchronizeOutputs (#29398) ### Description CUDA graph tests were missing `synchronize_inputs()`/`synchronize_outputs()` calls around inference runs, creating a stream race between the default CUDA stream (host↔device copies) and the EP's compute stream. **`test_inference.cc`** (`CApiTest.basic_cuda_graph`, `RunWithCudaGraphAnnotation`): - Add `binding.SynchronizeInputs()` before each run - Add `binding.SynchronizeOutputs()` after each run, before reading results via `cudaMemcpy` **`onnxruntime_test_python_cudagraph.py`** (`run_model_with_cuda_graph`, `test_arena_with_cuda_graph`): - Add `io_binding.synchronize_inputs()` / `io_binding.synchronize_outputs()` around every `run_with_iobinding()` call, matching the pattern already used in `run_model_with_cuda_graph_annotation` ```python # Pattern now consistent across all CUDA graph test helpers: io_binding.synchronize_inputs() # ensure H2D copies visible to EP stream session.run_with_iobinding(io_binding, ro) io_binding.synchronize_outputs() # ensure EP computation done before D2H read np.testing.assert_allclose(y_ortvalue.numpy(), expected_y, ...) ``` ### Motivation and Context Without stream synchronization, the CUDA EP (running on a non-default stream) can race against `cudaMemcpy` calls issued on the default stream for input uploads and output reads. This is the same class of bug fixed in `CApiTest.basic_cuda_graph`; these tests had the identical omission. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Tianlei Wu <tlwu@microsoft.com>
Author
Parents
Loading