Skip to content

Export CUDA Array Interface v3 (with stream) from TensorGPU - #6496

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1790004929-cai-v3-export
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1790004929-cai-v3-export

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Category:

New feature (non-breaking change which adds functionality)

Description:

DALI already consumes CUDA Array Interface v3 objects (it honors the stream entry when wrapping external memory in TensorGPU/TensorListGPU), but on the producer side TensorGPU.__cuda_array_interface__ still advertised version 2 with no stream information, so consumers (CuPy, Numba, PyTorch, ...) had no way to synchronize with DALI's stream other than a full device sync.

This PR upgrades the exported interface to version 3 and populates the stream entry from the tensor's AccessOrder:

if order.is_device():
    if ready_event: order.wait(ready_event)   # so syncing with the exported stream suffices
    stream = order.stream()
    d["stream"] = 1 if stream == 0 else 2 if stream == cudaStreamPerThread else int(stream)
else:                                         # host-synchronous data
    if ready_event: host.wait(ready_event)
    d["stream"] = None                        # no synchronization required

0 is never exported, as required by the spec; 1/2 are the v3 aliases for the legacy / per-thread default streams (mirroring the mapping already used on the consumer side in FillTensorFromCudaArray).

Additional information:

Affected modules and functionalities:

  • dali/python/backend_impl.cc: ArrayInterfaceRepr<GPUBackend> now reports version = 3 and a stream entry; TensorGPU docstrings updated.
  • dali/test/python/test_backend_impl_gpu.py: new tests for the exported v3 interface.

Key points relevant for the review:

  • The ready_event handling: when the tensor carries a ready event, the exported stream is made to wait on it so that a consumer synchronizing only with stream (as CAI v3 mandates) observes complete data.
  • Behavior for tensors with host-synchronous order: stream=None, meaning no synchronization is needed on the consumer's side.
  • CPU __array_interface__ is unchanged.

Tests:

  • Existing tests apply
    • test_backend_impl_gpu.py: test_cuda_array_interface_* (CuPy interop via the exported interface)
  • New tests added
    • Python tests
      • test_backend_impl_gpu.py: test_cuda_array_interface_v3_export_pipeline_output, test_cuda_array_interface_v3_export_custom_stream, test_cuda_array_interface_v3_export_default_stream
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: DALI-2853

@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@copy-pr-bot

copy-pr-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with no outstanding correctness or repository-rule violations identified.

Summary

Upgrades TensorGPU.__cuda_array_interface__ exports from CUDA Array Interface v2 to v3.

  • Exposes the tensor's producing CUDA stream, including the required aliases for default streams.
  • Makes the exported stream wait for any ready event so consumers can synchronize correctly.
  • Reports host-synchronous tensors with stream=None.
  • Updates Python-facing documentation and adds deterministic interoperability tests.

Reviews (2) · Last reviewed commit: "Export CUDA Array Interface v3 (with str..."

greptile-apps[bot]

This comment was marked as resolved.

DALI already consumes CAI v3 (stream field) when wrapping external memory;
now TensorGPU.__cuda_array_interface__ also reports version 3 and a stream
entry derived from the tensor's AccessOrder (1/2 for the default streams,
None for host-synchronous data), waiting on the ready event when present.

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1790004929-cai-v3-export branch from 3d097d9 to 089e66e Compare September 21, 2026 16:01

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@JanuszL

JanuszL commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

!build

@dali-automaton

Copy link
Copy Markdown
Collaborator

CI MESSAGE: [69073475]: BUILD STARTED

@dali-automaton

Copy link
Copy Markdown
Collaborator

CI MESSAGE: [69073475]: BUILD PASSED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants