Skip to content

Catch up generated files - #3078

Merged
mdboom merged 1 commit into
NVIDIA:mainfrom
mdboom:fix-cyclical-garbage
Oct 12, 2026
Merged

mdboom merged 1 commit into
NVIDIA:mainfrom
mdboom:fix-cyclical-garbage

Conversation

@mdboom

@mdboom mdboom commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

This catches up the generated cuda_bindings files with two changes:

!546: Handle nesting of unions and structs correctly. This affects how these structs are declared (making more constructions possible) but does not actually have any runtime impact.

!586: Handle cyclical garbage correctly. An agent rightfully identified that reference cycles between automatically generated classes would never be collected. Unfortunately, Cython does not offer a way to handle this correctly and optimally (no way to override tp_visit and tp_traverse), so I've had to revert back to the old approach of an extra boolean flag to indicate whether we own the memory pointed to (rather than using NULL for this). This is a latent bug -- no known uses of it in the wild.

@mdboom mdboom added this to the cuda.bindings 13.5.0 & 12.9.10 milestone Oct 12, 2026
@mdboom mdboom self-assigned this Oct 12, 2026
@mdboom mdboom added bug Something isn't working P0 High priority - Must do! cuda.bindings Everything related to the cuda.bindings module labels Oct 12, 2026
@coderabbitai

coderabbitai Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/cuda-python/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: da74eb20-a0ab-47df-8a2b-7e41d15b3d3f

📥 Commits

Reviewing files that changed from the base of the PR and between c7e6f09 and 7627c1b.


📒 Files selected for processing (5)
  • cuda_bindings/cuda/bindings/cufile.pyx
  • cuda_bindings/cuda/bindings/cycufile.pxd
  • cuda_bindings/cuda/bindings/cydriver.pxd
  • cuda_bindings/cuda/bindings/cyruntime.pxd
  • cuda_bindings/cuda/bindings/nvml.pyx

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.



📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved memory handling for CUDA and NVML data wrappers, reducing the risk of invalid memory access when data is copied or shared.
    • Preserved read-only behavior when wrapping nested NVML data.
  • Compatibility
    • Updated CUDA and cuFile type bindings to use types defined by their corresponding headers, while keeping the represented fields unchanged.

Walkthrough

Anonymous CUDA aggregates now map to types derived from their header members. cuFile and NVML pointer-backed wrappers track allocation ownership separately from Python owners. cuFile buffer operations use complete anonymous struct sizes, and selected NVML child wrappers receive the supplied read-only setting.

Changes

cuFile types and wrappers

Layer / File(s) Summary
Aggregate type aliases
cuda_bindings/cuda/bindings/cycufile.pxd
cuFile aggregate declarations now alias types derived from their corresponding header members.
Wrapper sizing and ownership
cuda_bindings/cuda/bindings/cufile.pyx
POD buffer operations use full struct sizes. The wrappers distinguish owned allocations from borrowed pointers and retain optional Python owners.

CUDA driver and runtime type aliases

Layer / File(s) Summary
Header member type mappings
cuda_bindings/cuda/bindings/cydriver.pxd, cuda_bindings/cuda/bindings/cyruntime.pxd
Anonymous aggregate declarations now reference types derived from CUDA header members. Their declared fields and union alternatives remain in place.

NVML pointer wrappers

Layer / File(s) Summary
Pointer ownership
cuda_bindings/cuda/bindings/nvml.pyx
Pointer-backed wrappers record whether storage is owned or borrowed, retain optional Python owners, and free only owned allocations.
Nested wrapper caches
cuda_bindings/cuda/bindings/nvml.pyx
Selected child-wrapper caches use renamed attributes. Pointer-based children receive the supplied read-only setting.

Suggested reviewers: rwgk


Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 7627c

This updates generated CUDA bindings so nested anonymous types map to the real header types. Wrapper objects now track memory ownership explicitly, which avoids uncollectable reference cycles. No concrete defects were identified, and the change looks ready to merge.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@brandon-b-miller brandon-b-miller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

Since this is mostly generated code, to review I tried to find a place where this claim failed to hold:

does not actually have any runtime impact

So I measured before/after this change vs main and found no changes

cuda_bindings_driver__anon_pod17    base_sizeof=128  head_sizeof=128  same
cuda_bindings_runtime__anon_pod5    base_sizeof=56   head_sizeof=56   same
...
0 of 59 expressions change size

@brandon-b-miller

Copy link
Copy Markdown
Contributor

CI Errors look like a flake (503)

@mdboom
mdboom enabled auto-merge (squash) October 12, 2026 20:47
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

@mdboom
mdboom merged commit 9b28da6 into NVIDIA:main Oct 12, 2026
239 of 241 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 13, 2026
Removed preview folders for the following PRs:
- PR #3045
- PR #3053
- PR #3054
- PR #3055
- PR #3078
- PR #3079
- PR #3080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.bindings Everything related to the cuda.bindings module P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants