[Televiz] fix cross-device ProjectionLayer::submit, expose the CUDA device id - #922
Open
farbod-nv wants to merge 1 commit into
Open
[Televiz] fix cross-device ProjectionLayer::submit, expose the CUDA device id#922farbod-nv wants to merge 1 commit into
farbod-nv wants to merge 1 commit into
Conversation
…, diagnose mismatches VkContext binds CUDA to the GPU matching its Vulkan physical device, and that is not necessarily CUDA device 0 — Vulkan and CUDA enumerate GPUs in different orders, so auto-pick lands on a non-zero CUDA index on ordinary dual-GPU machines. Three consequences, all fixed here. ProjectionLayer::submit signalled cuda_done_writing without making viz's device current. cudaSetDevice is per-HOST-THREAD, so any app submitting from a worker thread (the common shape: session created on the main thread, frames submitted from a render thread) died with "cudaSignalExternalSemaphoresAsync(cuda_done_writing) failed: invalid argument". ImageLayerBase::submit has always taken this guard; this is the missing parity, so the two layer families now behave alike. VizSession had no way to report which CUDA device it landed on, leaving producers to guess 0 — interop is same-device only, and a wrong guess costs a peer copy per submit (1.17 ms vs 0.05 ms for a 1080p RGBD submit, measured on 2x RTX 6000 Ada) when it does not fail outright. Adds get_cuda_device_id() / VizSession.cuda_device_id, plus Config::physical_device_index (already in VkContext::Config, previously unreachable through VizSession) to move viz instead. The index is rejected, not ignored, for kXr and external_context, where the device is someone else's call. Finally, the errors themselves: CUDA reports every cross-device interop call as a bare "invalid argument", which reads like a bad parameter and sends people looking at shapes and stream handles. viz/core/cuda_error.hpp appends the diagnosis when the calling thread's device differs from viz's — both device ids, why it is not an argument problem, and the fix. Wired through every CUDA failure site in device_image, image_layer_base and projection_layer. Tests: message content (including staying quiet when the devices agree), config default, both physical_device_index rejections, no false rejection of -1, and the accessor against the context's own answer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (10)
📝 WalkthroughWalkthroughThe session can select a Vulkan physical device and expose its matched CUDA device ID through C++ and Python APIs. Invalid device selection with XR or external Vulkan contexts is rejected. CUDA interop paths now use shared error formatting with device-mismatch diagnostics. Tests cover session selection, CUDA device mapping, error messages, and exception behavior. Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant VizSession
participant VkContext
participant ImageLayerBase
participant CUDA_Runtime
participant cuda_error_message
Caller->>VizSession: create with physical_device_index
VizSession->>VkContext: initialize selected Vulkan device
VkContext-->>VizSession: matched CUDA device ID
ImageLayerBase->>CUDA_Runtime: select matched device and submit CUDA work
CUDA_Runtime-->>ImageLayerBase: operation result
ImageLayerBase->>cuda_error_message: format failures with device context
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
junjeechao
approved these changes
Aug 7, 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.
VkContextbinds CUDA to the GPU matching its Vulkan physical device — notnecessarily CUDA device 0, since Vulkan and CUDA enumerate GPUs in different
orders. Three fixes for what follows from that.
ProjectionLayer::submitnow pins viz's device before touching CUDA, asImageLayerBase::submitalready did. Without it, any app submitting from aworker thread (session created on the main thread, frames submitted from a
render thread) died on a multi-GPU box with
cudaSignalExternalSemaphoresAsync(cuda_done_writing) failed: invalid argument.VizSession::get_cuda_device_id()/.cuda_device_id— producers had noway to learn which GPU to allocate on and had to guess 0. Interop is
same-device only, and a wrong guess costs a peer copy per submit (1.17 ms vs
0.05 ms for a 1080p RGBD submit, 2x RTX 6000 Ada) when it doesn't fail
outright.
Config::physical_device_indexis also plumbed through to move vizinstead; it's rejected, not ignored, for kXr and
external_context.Better CUDA errors (
viz/core/cuda_error.hpp) — CUDA reports everycross-device interop call as a bare "invalid argument". Failures now append two
lines naming both devices and the fix, and stay silent when the devices agree.
Wired through every CUDA failure site in
device_image,image_layer_baseandprojection_layer.Tests: message content and length, the quiet case, config default, both
physical_device_indexrejections, and the accessor cross-checked against thecontext and
cudaGetDevice. Full viz suites pass (core 201/51, session 399/44,layers 410/42).
Found via a televiz crash on a dual-GPU workstation; the app-side workarounds in gr00t become no-ops once this ships in a wheel.
Summary by CodeRabbit
New Features
Bug Fixes
Tests