Skip to content

Conversation

@ruisv
Copy link
Contributor

@ruisv ruisv commented May 6, 2025

fixes #27289

🚀 CUDA 12.9 Compatibility Fix

File: modules/core/include/opencv2/core/private.cuda.hpp
Starting with CUDA 12.9, NVIDIA removed the helper API nppGetStreamContext() from public headers.
As a result, any module (e.g., OpenCV’s CUDA parts) that attempted to build with CUDA 12.9+ would fail at compile time:

err1

🔧 What I did

  1. 🧯 Add version guard for legacy toolkits
#if CUDA_VERSION < 12090
    nppSafeCall(nppGetStreamContext(&nppStreamContext)); 
#else
    // Manual context construction below
  1. 🛠 Manually construct NppStreamContext for CUDA ≥ 12.9
int device = 0;
cudaSafeCall(cudaGetDevice(&device));

cudaDeviceProp prop{};
cudaSafeCall(cudaGetDeviceProperties(&prop, device));

nppStreamContext.nCudaDeviceId = device;
nppStreamContext.nMultiProcessorCount = prop.multiProcessorCount;
nppStreamContext.nMaxThreadsPerMultiProcessor = prop.maxThreadsPerMultiProcessor;
nppStreamContext.nMaxThreadsPerBlock = prop.maxThreadsPerBlock;
nppStreamContext.nSharedMemPerBlock = prop.sharedMemPerBlock;
nppStreamContext.nCudaDevAttrComputeCapabilityMajor = prop.major;
nppStreamContext.nCudaDevAttrComputeCapabilityMinor = prop.minor;

✅ Tested

cuda-version 12.9

  • npp module builds successfully:
    wechat_2025-05-06_233443_510
  • project builds successfully:
    wechat_2025-05-06_234157_358

@asmorkalov asmorkalov added category: build/install category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib labels May 6, 2025
@asmorkalov
Copy link
Contributor

/cc @cudawarped

@cudawarped
Copy link
Contributor

@asmorkalov If its not a bug, should OpenCV's DeviceInfo be used instead of CUDA toolkit's cudaGetDevice/cudaGetDeviceProperties?

Fix working on Windows 11 with CUDA toolkit 12.9.

@asmorkalov
Copy link
Contributor

@cudawarped Thanks a lot for the prompt feedback. Both current solution and DeviceInfo usage looks good to me.

@asmorkalov asmorkalov self-requested a review May 7, 2025 08:26
@asmorkalov asmorkalov self-assigned this May 7, 2025
Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

Tested manually with Ubuntu 24.04 and Cuda 12.9.

@asmorkalov asmorkalov merged commit 1c421be into opencv:4.x May 16, 2025
27 of 28 checks passed
@ruisv ruisv deleted the ruisv-cuda1209-npp-patch-1 branch May 21, 2025 15:50
@asmorkalov asmorkalov mentioned this pull request May 27, 2025
emgucv pushed a commit to emgucv/opencv that referenced this pull request Jun 5, 2025
CUDA 12.9 support: build NppStreamContext manually
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure with CUDA 12.9: nppGetStreamContext() removed from headers

3 participants