Skip to content

Conversation

@gmarkall
Copy link
Contributor

This reverts commit 9a56516.

This changed the public API of MemoryPointer and related classes, and the context that they held was used by Arrow (see apache/arrow#48259 (comment)):

Numba interop tests fail with:

arrow-dev/lib/python3.12/site-packages/pyarrow/tests/test_cuda_numba_interop.py:233:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   TypeError: MemoryPointer.__init__() got multiple values for argument 'pointer'

This commit reverts the change, as it was intended to improve performance without changing functionality, but has had a functional change as a side effect. Following the merge of this PR, we should be able to remove some of the @require_context decorators with some more targeted changes.

NVIDIA#536)"

This reverts commit 9a56516.

This changed the public API of `MemoryPointer` and related classes, and
the context that they held was used by Arrow (see apache/arrow#48259 (comment)):

> Numba interop tests fail with:

```
arrow-dev/lib/python3.12/site-packages/pyarrow/tests/test_cuda_numba_interop.py:233:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   TypeError: MemoryPointer.__init__() got multiple values for argument 'pointer'
```

This commit reverts the change, as it was intended to improve
performance without changing functionality, but has had a functional
change as a side effect. Following the merge of this PR, we should be
able to remove some of the `@require_context` decorators with some more
targeted changes.
@copy-pr-bot
Copy link

copy-pr-bot bot commented Nov 26, 2025

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@gmarkall
Copy link
Contributor Author

/ok to test

@gmarkall gmarkall mentioned this pull request Nov 26, 2025
@greptile-apps
Copy link

greptile-apps bot commented Nov 26, 2025

Greptile Overview

Greptile Summary

This PR cleanly reverts PR #536, which removed the context parameter from memory pointer classes to improve performance. While that change successfully reduced overhead, it inadvertently broke the public API—specifically causing Apache Arrow's numba interop tests to fail with TypeError: MemoryPointer.__init__() got multiple values for argument 'pointer'.

Key Changes:

  • Restores context as the first parameter to MemoryPointer, AutoFreePointer, MappedMemory, PinnedMemory, and ManagedMemory constructors
  • Re-adds @require_context decorator to from_cuda_array_interface() in api.py
  • Updates all instantiation sites to pass context (usually via weakref.proxy(self.context) or devices.get_context())
  • Updates tests to reflect restored API

Justification:
The revert is necessary because external consumers like Apache Arrow depend on the existing signature. The performance optimization, while valuable, must be reimplemented without breaking the public API. The PR description correctly notes that targeted removal of @require_context decorators can be done in follow-up work.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk—it's a clean revert that restores the previous working API
  • The revert is straightforward and complete: all constructor signatures are correctly restored with context as the first parameter, all call sites are updated consistently, and tests are properly adjusted. The change fixes a critical breaking change in the public API that affected Apache Arrow integration. The diff is a nearly perfect inverse of the original PR perf: remove context threading in various pointer abstractions #536, preserving the pre-existing typo "Releease" which confirms accuracy
  • No files require special attention—all changes are consistent and correct

Important Files Changed

File Analysis

Filename Score Overview
numba_cuda/numba/cuda/api.py 5/5 Restores @require_context decorator and adds context parameter back to MemoryPointer constructor, fixing Arrow compatibility issue
numba_cuda/numba/cuda/cudadrv/devicearray.py 5/5 Restores context parameter to MemoryPointer constructor for NULL pointer creation in empty allocations
numba_cuda/numba/cuda/cudadrv/driver.py 5/5 Restores context parameter to all memory pointer class constructors (MemoryPointer, MappedMemory, PinnedMemory, ManagedMemory, AutoFreePointer) and their instantiation sites

Sequence Diagram

sequenceDiagram
    participant User as External User/Arrow
    participant API as from_cuda_array_interface()
    participant Context as CUDA Context
    participant MemPtr as MemoryPointer
    participant DevArray as DeviceNDArray
    
    Note over User,DevArray: Before Revert (PR #536 - BROKEN)
    User->>API: Call with cuda-array-interface
    API->>MemPtr: MemoryPointer(pointer, size, owner)
    Note over MemPtr: No context parameter!
    MemPtr-->>API: Memory pointer instance
    API->>DevArray: Create DeviceNDArray
    DevArray-->>User: Return array
    Note over User: ❌ Arrow breaks: multiple values for 'pointer'
    
    Note over User,DevArray: After Revert (Current PR - FIXED)
    User->>API: Call with cuda-array-interface
    API->>Context: current_context()
    Context-->>API: Context instance
    API->>MemPtr: MemoryPointer(context, pointer, size, owner)
    Note over MemPtr: Context restored as first param
    MemPtr->>MemPtr: Store context reference
    MemPtr-->>API: Memory pointer instance
    API->>DevArray: Create DeviceNDArray
    DevArray-->>User: Return array
    Note over User: ✅ Arrow works correctly
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@gmarkall
Copy link
Contributor Author

Following this PR: create an issue to track the work of re-removing @require_context and get_context() from from_cuda_array_interface().

@gmarkall gmarkall merged commit ae7b3bf into NVIDIA:main Nov 27, 2025
71 checks passed
gmarkall added a commit to gmarkall/numba-cuda that referenced this pull request Nov 27, 2025
- Revert NVIDIA#536 "perf: remove context threading in various pointer abstractions" (NVIDIA#611)
- fix: empty array type mismatch between host and device (NVIDIA#612)
- fix: warp vote operations must use a constant int for the `mode` parameter (NVIDIA#606)
gmarkall added a commit that referenced this pull request Nov 27, 2025
- Revert #536 "perf: remove context threading in various pointer
abstractions" (#611)
- fix: empty array type mismatch between host and device (#612)
- fix: warp vote operations must use a constant int for the `mode`
parameter (#606)
raulcd pushed a commit to apache/arrow that referenced this pull request Nov 28, 2025
### What changes are included in this PR?

1. Add compatibility fix for CUDA 13 in C++ CUDA tests
2. Add CI builds with CUDA 13
3. Disable Numba interop tests because of a regression in Numba-CUDA: see NVIDIA/numba-cuda#611

### Are these changes tested?

Yes, on CI.

### Are there any user-facing changes?

No.

* GitHub Issue: #47677

Authored-by: Antoine Pitrou <[email protected]>
Signed-off-by: Raúl Cumplido <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants