Skip to content

Conversation

OutisLi
Copy link
Contributor

@OutisLi OutisLi commented Oct 15, 2025

auto detect cuda version, if >= 13.0, set c++17

fix issue #5016

Summary by CodeRabbit

  • Chores
    • Build now detects the installed CUDA Toolkit version and adjusts configuration accordingly.
    • Automatically selects C++17 for host/device compilation when CUDA Toolkit 13.0+ is present.
    • Emits clearer build status messages showing detected CUDA version and chosen C++ standard.
    • Maintains existing version checks and does not change runtime behavior or public APIs.

@Copilot Copilot AI review requested due to automatic review settings October 15, 2025 04:25
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds CUDA 13.0+ detection to two CMake files: the top-level now gates C++17 upgrade on CUDAToolkit_VERSION >= 13.0 (when USE_CUDA_TOOLKIT is enabled), and the GPU CMake file adds a CUDA 13.0+ guard using CMAKE_CUDA_COMPILER_VERSION, setting CUDA/C++ standards to C++17 and emitting status messages.

Changes

Cohort / File(s) Summary
Top-level CUDA guard
source/CMakeLists.txt
Uses CUDAToolkit_VERSION (instead of CMAKE_CUDA_COMPILER_VERSION) to detect CUDA >= 13.0 when USE_CUDA_TOOLKIT is enabled; calls set_if_higher to set CMAKE_CXX_STANDARD to 17 and emits a STATUS message with the detected CUDA version.
GPU CUDA guard
source/lib/src/gpu/CMakeLists.txt
Normalizes version-check syntax to CMAKE_CUDA_COMPILER_VERSION, adds CUDA >= 13.0 branch that sets CMAKE_CUDA_STANDARD/C++ standard to 17 and logs a STATUS message; preserves existing NVCC/version reporting and 9.0 minimum check.

Sequence Diagram(s)

sequenceDiagram
  participant CMake as CMake (invocation)
  participant Top as source/CMakeLists.txt
  participant GPU as source/lib/src/gpu/CMakeLists.txt

  rect rgb(250,250,255)
    Note over CMake,Top: Early project configuration
  end

  CMake->>Top: evaluate USE_CUDA_TOOLKIT?
  alt USE_CUDA_TOOLKIT = ON
    Top->>Top: read CUDAToolkit_VERSION
    alt CUDAToolkit_VERSION >= 13.0
      Top->>CMake: set_if_higher(CMAKE_CXX_STANDARD, 17)
      Top->>CMake: status("Detected CUDA toolkit vX.Y.Z -> using C++17")
    else
      Top->>CMake: continue existing CUDA handling
    end
  else
    Top->>CMake: skip CUDA-toolkit-specific path
  end

  CMake->>GPU: later evaluate GPU CMake
  GPU->>GPU: read CMAKE_CUDA_COMPILER_VERSION
  alt version >= 13.0
    GPU->>CMake: set(CMAKE_CUDA_STANDARD 17)
    GPU->>CMake: status("Detected CUDA toolkit vX.Y.Z -> CUDA C++17")
  else
    GPU->>CMake: existing NVCC/version reporting and 9.0 check
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • caic99
  • wanghan-iapcm

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat:support CUDA 13.0+" directly and accurately describes the main change in the changeset. The modifications across both CMakeLists.txt files are specifically focused on detecting CUDA version 13.0 or higher and automatically setting the C++ standard to C++17 when this condition is met, which aligns perfectly with the stated title and the PR objectives. The title is concise, uses clear language with the standard "feat:" prefix to indicate a feature addition, and avoids vague terminology or unnecessary noise.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for CUDA 13.0+ by automatically detecting the CUDA version and setting the C++ standard to 17 when CUDA 13.0 or higher is detected, as required by newer CUDA versions.

Key changes:

  • Auto-detection of CUDA version in two CMake files
  • Conditional setting of C++17 standard for CUDA 13.0+
  • Status messages to inform users of the standard being set

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
source/lib/src/gpu/CMakeLists.txt Adds CUDA version check and sets CMAKE_CUDA_STANDARD to 17 for CUDA 13.0+
source/CMakeLists.txt Adds CUDA version check and sets CMAKE_CXX_STANDARD to 17 for CUDA 13.0+

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f00250 and e19495f.

📒 Files selected for processing (2)
  • source/CMakeLists.txt (1 hunks)
  • source/lib/src/gpu/CMakeLists.txt (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
source/CMakeLists.txt

📄 CodeRabbit inference engine (AGENTS.md)

Keep C++ build configuration up to date in CMake when changing C++ components (library, ops, APIs)

Files:

  • source/CMakeLists.txt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Test C++ (false)

Copy link

codecov bot commented Oct 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.23%. Comparing base (c41c366) to head (013e676).
⚠️ Report is 1 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #5017      +/-   ##
==========================================
- Coverage   84.23%   84.23%   -0.01%     
==========================================
  Files         709      709              
  Lines       70074    70075       +1     
  Branches     3619     3619              
==========================================
- Hits        59028    59026       -2     
- Misses       9880     9881       +1     
- Partials     1166     1168       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
source/lib/src/gpu/CMakeLists.txt (1)

29-29: Consider documenting the variable name difference between CMake files.

source/CMakeLists.txt uses CUDAToolkit_VERSION while this file uses CMAKE_CUDA_COMPILER_VERSION to detect CUDA version. Both represent the same CUDA toolkit version but come from different CMake discovery mechanisms:

  • CUDAToolkit_VERSION is set by find_package(CUDAToolkit)
  • CMAKE_CUDA_COMPILER_VERSION is set by enable_language(CUDA)

While this is necessary and correct for each context, a brief comment noting this distinction would reduce confusion for future maintainers reviewing version-gating logic across the build system.

Add an inline comment above the version checks in this file, for example:

  # Note: CMAKE_CUDA_COMPILER_VERSION is used here (set by enable_language(CUDA) above).
  # In source/CMakeLists.txt, CUDAToolkit_VERSION is used instead (from find_package).
  # Both represent the same CUDA version but are set by different CMake operations.
  if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0")
    set(CMAKE_CUDA_STANDARD 17)

Also applies to: 42-42, 47-53

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 983eba5 and 013e676.

📒 Files selected for processing (2)
  • source/CMakeLists.txt (1 hunks)
  • source/lib/src/gpu/CMakeLists.txt (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
source/CMakeLists.txt

📄 CodeRabbit inference engine (AGENTS.md)

Keep C++ build configuration up to date in CMake when changing C++ components (library, ops, APIs)

Files:

  • source/CMakeLists.txt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (cuda, cuda)
🔇 Additional comments (2)
source/CMakeLists.txt (1)

249-254: ✓ Correct placement and logic for CUDA 13.0+ host standard upgrade.

The check is correctly positioned after find_package(CUDAToolkit REQUIRED) (line 248), so CUDAToolkit_VERSION is now defined and the version comparison will work as intended. Using set_if_higher ensures the standard is only upgraded, never downgraded—appropriate for coexistence with PyTorch's own C++ version requirements (lines 338-341). The status message provides useful build diagnostics.

source/lib/src/gpu/CMakeLists.txt (1)

47-53: ✓ Device-side C++ standard correctly upgraded for CUDA 13.0+.

The CUDA device standard is appropriately initialized to 11 (line 13) and upgraded to 17 when CMAKE_CUDA_COMPILER_VERSION >= 13.0. Combined with the host-side upgrade in source/CMakeLists.txt, this ensures both device and host compilation standards align with CUDA 13+ requirements. Status messaging is helpful for debugging version-dependent builds.

@njzjz njzjz added this pull request to the merge queue Oct 17, 2025
Merged via the queue into deepmodeling:devel with commit 5c71262 Oct 17, 2025
60 checks passed
@OutisLi OutisLi deleted the pr/cuda13 branch October 20, 2025 01:46
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.

2 participants