Skip to content

GH-47677: [C++][GPU] Allow building with CUDA 13#48259

Merged
raulcd merged 4 commits intoapache:mainfrom
pitrou:gh47677-cuda13
Nov 28, 2025
Merged

GH-47677: [C++][GPU] Allow building with CUDA 13#48259
raulcd merged 4 commits intoapache:mainfrom
pitrou:gh47677-cuda13

Conversation

@pitrou
Copy link
Member

@pitrou pitrou commented Nov 26, 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 Revert #536 "perf: remove context threading in various pointer abstractions" NVIDIA/numba-cuda#611

Are these changes tested?

Yes, on CI.

Are there any user-facing changes?

No.

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

@github-actions crossbow submit cuda

@github-actions
Copy link

⚠️ GitHub issue #47677 has been automatically assigned in GitHub to PR creator.

@github-actions
Copy link

Revision: 60f974c

Submitted crossbow builds: ursacomputing/crossbow @ actions-c2a5e1506b

Task Status
test-cuda-cpp-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

@github-actions crossbow submit cuda

@github-actions
Copy link

Revision: 42610fe

Submitted crossbow builds: ursacomputing/crossbow @ actions-719d93fe63

Task Status
test-cuda-cpp-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-cpp-ubuntu-24.04-cuda-13.0.2 GitHub Actions
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-python-ubuntu-24.04-cuda-13.0.2 GitHub Actions

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

So, the 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'

Did Numba change its CUDA interaction APIs again? @gmarkall

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

This is presumably happening in

def to_numba(self):
"""Return numba memory pointer of CudaBuffer instance.
"""
import ctypes
from numba.cuda.cudadrv.driver import MemoryPointer
return MemoryPointer(self.context.to_numba(),
pointer=ctypes.c_void_p(self.address),
size=self.size)

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

@github-actions crossbow submit cudapython*

@github-actions
Copy link

Revision: ed01642

Submitted crossbow builds: ursacomputing/crossbow @ actions-bc22ec352a

Task Status
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-python-ubuntu-24.04-cuda-13.0.2 GitHub Actions

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

Ok, given that the tests now fail for other reasons, I think we might just disable them on CI and let interested parties contribute.

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

@github-actions crossbow submit cudapython*

@github-actions
Copy link

Revision: 5080baf

Submitted crossbow builds: ursacomputing/crossbow @ actions-d5735696f4

Task Status
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-python-ubuntu-24.04-cuda-13.0.2 GitHub Actions

Comment on lines 94 to 99
#if CUDA_VERSION >= 13000
RETURN_NOT_OK(StatusFromCuda(cuCtxCreate_v4(&ctx, /*ctxCreateParams=*/nullptr,
/*flags=*/0, device_->handle())));
#else
RETURN_NOT_OK(StatusFromCuda(cuCtxCreate(&ctx, /*flags=*/0, device_->handle())));
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

@gmarkall Does this fix look ok?

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Nov 26, 2025
@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

@github-actions crossbow submit cudapython*

@github-actions
Copy link

Revision: 9423f81

Submitted crossbow builds: ursacomputing/crossbow @ actions-c59a2b88bb

Task Status
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-python-ubuntu-24.04-cuda-13.0.2 GitHub Actions

Result<CUcontext> NonPrimaryRawContext() {
CUcontext ctx;
#if CUDA_VERSION >= 13000
RETURN_NOT_OK(StatusFromCuda(cuCtxCreate_v4(&ctx, /*ctxCreateParams=*/nullptr,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure cuCtxCreate_v4 is designated as a public API. For CUDA 13, cuCtxCreate is #defined as cuCtxCreate_v4, so I think I'd be inclined to write this as:

Suggested change
RETURN_NOT_OK(StatusFromCuda(cuCtxCreate_v4(&ctx, /*ctxCreateParams=*/nullptr,
RETURN_NOT_OK(StatusFromCuda(cuCtxCreate(&ctx, /*ctxCreateParams=*/nullptr,

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

(unrelated, but using a #define isn't very nice for non-C languages that would want to access the driver API through FFI)

Copy link
Contributor

Choose a reason for hiding this comment

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

That is from the 12.6 API and this was removed in the 13.0 API: https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__CTX.html#group__CUDA__CTX (but not the ABI).

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, weirdly it succeeds on the 13.0.2 CUDA build... But, yes, I can just switch to calling the macro.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way it's defined in the cuda.h header is that cuCtxCreate is a macro defined as cuCtxCreate_v4:

#define cuCtxCreate cuCtxCreate_v4
...
CUresult CUDAAPI cuCtxCreate(CUcontext *pctx, CUctxCreateParams *ctxCreateParams, unsigned int flags, CUdevice dev);

This was an API breaking change in CUDA 13. If you want to generically support CUDA 12 and CUDA 13, I'd recommend using the cuGetProcAddress API (https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__DRIVER__ENTRY__POINT.html#group__CUDA__DRIVER__ENTRY__POINT_1gcae5adad00590572ab35b2508c2d6e0d) which is similar to using dlsym and allows you to work against the ABI which is guaranteed to never be broken.

@pitrou
Copy link
Member Author

pitrou commented Nov 26, 2025

@github-actions crossbow submit cudacpp*

@pitrou pitrou marked this pull request as ready for review November 26, 2025 14:48
@github-actions
Copy link

Revision: 9ea7b75

Submitted crossbow builds: ursacomputing/crossbow @ actions-03152c375f

Task Status
test-cuda-cpp-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-cpp-ubuntu-24.04-cuda-13.0.2 GitHub Actions

@gmarkall
Copy link
Contributor

Did Numba change its CUDA interaction APIs again? @gmarkall

That was a change made in NVIDIA/numba-cuda#536 and it did change a public API. I had failed to foresee that there would be an effect outside of Numba-CUDA. This change has only just made it into a published release in the last few days, so let me assess what the best way forward is and post an update here.

PR to restore the public-facing surface of these APIs to what it was before is here: NVIDIA/numba-cuda#610 - my intention is that if this is merged, to make another release shortly afterwards so that the latest version is consistent with earlier versions.

gmarkall added a commit to gmarkall/numba-cuda that referenced this pull request Nov 26, 2025
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.
@pitrou
Copy link
Member Author

pitrou commented Nov 27, 2025

@raulcd @jorisvandenbossche What do you think? Should we wait for Numba-Cuda to publish a new release or should we just merge this PR with a skip as currently done?

@raulcd
Copy link
Member

raulcd commented Nov 27, 2025

Should we wait for Numba-Cuda to publish a new release or should we just merge this PR with a skip as currently done?

Given that we are going to lose access to the cuda runners for an unspecified amount of time starting this weekend I'd rather merge with the skip and create a follow up issue to remove the skip once we have runners again and can validate.

@pitrou
Copy link
Member Author

pitrou commented Nov 27, 2025

@raulcd Do you want to give this a review?

@pitrou
Copy link
Member Author

pitrou commented Nov 27, 2025

@github-actions crossbow submit cuda

@github-actions
Copy link

Revision: 00fccbb

Submitted crossbow builds: ursacomputing/crossbow @ actions-23548261b9

Task Status
test-cuda-cpp-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-cpp-ubuntu-24.04-cuda-13.0.2 GitHub Actions
test-cuda-python-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-cuda-python-ubuntu-24.04-cuda-13.0.2 GitHub Actions

@gmarkall
Copy link
Contributor

@raulcd @jorisvandenbossche What do you think? Should we wait for Numba-Cuda to publish a new release or should we just merge this PR with a skip as currently done?

FWIW, I'm hoping to resolve the Numba-CUDA issue and publish a new release today.

@pitrou
Copy link
Member Author

pitrou commented Nov 27, 2025

FWIW, I'm hoping to resolve the Numba-CUDA issue and publish a new release today.

Actually testing Numba interop may still require GH-47371 to be fixed, though.

@gmarkall
Copy link
Contributor

Thanks for the pointer - I'll move onto that issue shortly afterwards.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Nov 27, 2025
gmarkall added a commit to NVIDIA/numba-cuda that referenced this pull request Nov 27, 2025
…ctions" (#611)

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 link
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

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

Thanks @pitrou .

Thanks @gmarkall for the pointer to the API change.

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting changes Awaiting changes labels Nov 28, 2025
@raulcd raulcd merged commit ab4a096 into apache:main Nov 28, 2025
49 checks passed
@raulcd raulcd removed the awaiting merge Awaiting merge label Nov 28, 2025
@conbench-apache-arrow
Copy link

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit ab4a096.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

@pitrou pitrou deleted the gh47677-cuda13 branch November 28, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants