Skip to content

Conversation

@Flying-dragon-boxing
Copy link
Collaborator

@Flying-dragon-boxing Flying-dragon-boxing commented Dec 26, 2025

<Copied from Flying-dragon-boxing#24 >

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Addresses the CMake CUDA configuration issues discussed in the repository.

Unit Tests and/or Case Tests for my changes

  • Existing CUDA CI workflow will validate these changes when CUDA builds are triggered.

What's changed?

Problem: CMake CUDA configuration had three critical bugs:

  1. Used undefined CUDA_VERSION variable (deprecated since CMake 3.10)
  2. find_package(CUDAToolkit) only called when architectures not manually defined, breaking version detection
  3. Default architectures included 60/70 which CUDA 13+ no longer supports, causing build failures

Changes:

  • CMakeLists.txt (lines 332-377):

    • Moved find_package(CUDAToolkit REQUIRED) to execute unconditionally when USE_CUDA=ON
    • Replaced CUDA_VERSION with CUDAToolkit_VERSION from FindCUDAToolkit module
    • Added conditional architecture selection:
      • CUDA < 13.0: includes architectures 60, 70, 75, 80, 86, 89, 90 (version-gated)
      • CUDA ≥ 13.0: excludes architectures < 75 (starts empty, appends 75+)
    • Fixed typo: "architechures" → "architectures"
  • docs/advanced/acceleration/cuda.md:

    • Updated to reflect version-dependent architecture selection behavior

Behavior changes:

  • CUDA 13+ builds will no longer fail due to unsupported architectures 60/70
  • C++ standard properly set to 17 for CUDA 13+ (was broken due to undefined variable)
  • Users can still override via CMAKE_CUDA_ARCHITECTURES or CUDAARCHS environment variable

Any changes of core modules? (ignore if not applicable)

No changes to core solver modules.

Original prompt

This section details on the original issue you should resolve

<issue_title>Potential CMake logic bugs with CUDA</issue_title>
<issue_description>### Describe the Code Quality Issue

Implementation in #6777 of CMakeLists.txt doesn't really detect the CUDA version. The CUDA version is a manually-defined variable, making this CXX 17 issue not automatically solved.

  if(CUDA_VERSION VERSION_GREATER_EQUAL "13.0")
    message(STATUS "CUDA ${CUDA_VERSION} detected. Setting CMAKE_CUDA_STANDARD to 17.")
    set_if_higher(CMAKE_CXX_STANDARD 17)
  endif()

Actually when executing find_package(CUDAToolkit REQUIRED), CMake automatically introduces a variable CUDAToolkit_VERSION. Is there any difficulty introducing this variable in your situation?

Also, CUDA 13 has dropped the support for older architectures lower than 75, which is not properly dealt with in our CMake configuration, causing ABACUS with CUDA 13 to refuse to build.

set(CMAKE_CUDA_ARCHITECTURES
        60 # P100
        70 # V100
        # Add your CUDA arch here Check the Compute Capability version of your
        # GPU at: https://en.wikipedia.org/wiki/CUDA#GPUs_supported
    )

Besides, when defining CMAKE_CUDA_ARCHITECTURES, our CMake configuration does NOT find CUDAToolkit anymore. Why?

  if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
    find_package(CUDAToolkit REQUIRED)

Additional Context

No response

Task list for Issue attackers (only for developers)

  • Identify the specific code file or section with the code quality issue.
  • Investigate the issue and determine the root cause.
  • Research best practices and potential solutions for the identified issue.
  • Refactor the code to improve code quality, following the suggested solution.
  • Ensure the refactored code adheres to the project's coding standards.
  • Test the refactored code to ensure it functions as expected.
  • Update any relevant documentation, if necessary.
  • Submit a pull request with the refactored code and a description of the changes made.</issue_description>

Comments on the Issue (you are @copilot in this section)

@Flying-dragon-boxing `CUDA_VERSION` is **deprecated** together with `FindCUDA` since CMake 3.10, we have already ported to `FindCUDAToolkit`, so we should use `CUDAToolkit_VERSION` instead. https://cmake.org/cmake/help/latest/module/FindCUDA.html

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

zhangzh-pku and others added 30 commits May 1, 2023 01:27
* run INPUT.Default() in every process in InputParaTest (deepmodeling#3490)

Co-authored-by: kirk0830 <[email protected]>

* add blas support for FindLAPACK.cmake (deepmodeling#3497)

* more unittest of QO: towards orbital selection (deepmodeling#3499)

* Fix: fix bug in mulliken charge calculation (deepmodeling#3503)

* fix phase

* fix case test

* Refactor: namespace Conv_Coulomb_Pot_K (deepmodeling#3446)

* Refactor: namespace Conv_Coulomb_Pot_K

* Refactor: namespace Conv_Coulomb_Pot_K

---------

Co-authored-by: wqzhou <[email protected]>

* enable the computation of all zeros in one function call (deepmodeling#3449)

Co-authored-by: wqzhou <[email protected]>

* replace ios.eof() by ios.good() to avoid meeting badbit and failbit in reading STRU (deepmodeling#3506)

* Build: add ccache to accelerate the testing process (deepmodeling#3509)

* Build: add ccache to accelerate the testing process

* Update test.yml

* Update test.yml

* Update test.yml

* Docs: to avoid the misunderstanding in docs (deepmodeling#3518)

* to avoid the misunderstanding in docs

* Update docs/quick_start/hands_on.md

Co-authored-by: Chun Cai <[email protected]>

---------

Co-authored-by: Chun Cai <[email protected]>

* Docs: fix a missing depencency in conda build env (deepmodeling#3508)

* Feature: Add ENABLE_RAPIDJSON option to control the output of abacus.json (deepmodeling#3519)

Add ENABLE_RAPIDJSON option to control the output of abacus.json

* Feature: add python wrapper for math sphbes (deepmodeling#3475)

* recommit for review

* add python wrapper

* remove timer since performace tests add

* Feature: support segment split in kline mode in KPT file and `out_band` band output precision control, `8` as default (deepmodeling#3493)

* add precision control

* correct serial version of nscf_band function

* fix issue 3482

* update unit and integrated test

* update document

* correct unittest and make compatible with false and true

* fix: bug in Autotest.sh when result.ref has no totaltimeref (deepmodeling#3523)

* Fix : unit test of module_xc (deepmodeling#3524)

* Fix: omit small magnetic moments to avoid numerical instability (deepmodeling#3530)

* update deltalambda

* avoid numerical error in orbMulP

* add constrain on Mi

* change case reference value

* Fix: fix multiple compiler warnings (deepmodeling#3515)

* Fix: add noreturn attribute to warning_quit

* Add type conversion

* fix string literal

* fix small number trunctuation

* Fix system call returned value not checked

* fix missing braket

* Refactor parameter_pool.cpp and parameter_pool.h

* remove duplicated return statements

* Change WARNING_QUIT occurances in tests

* Add warning message to help debug UT

* output the default precision flag (deepmodeling#3496)

Co-authored-by: kirk0830 <[email protected]>

* Build: Improving CMake performance for finding LibXC and ELPA (deepmodeling#3478)

* Fix for finding LibXC and ELPA

* For compatibility to previous routines

* syntax fix for FindELPA.cmake

* Update cmake/FindELPA.cmake

Co-authored-by: Chun Cai <[email protected]>

* Using CMake interface as default for finding LibXC

* update docs

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* update docs for installing pkg-config

* Update FindLibxc.cmake

* Update FindLibxc.cmake

* remove previous LibXC routine in CMakeLists.txt

Co-authored-by: Chun Cai <[email protected]>

* Update easy_install.md with Makefile-built LibXC supported

* Update easy_install.md to include different behavior in different version on finding ELPA

---------

Co-authored-by: Chun Cai <[email protected]>

* Docs: correct some docs about mp2 smearing method (deepmodeling#3533)

* correct some docs about mp2 smearing method

* add docs about mv method

* Feature : printing band density (deepmodeling#3501)

Co-authored-by: wenfei-li <[email protected]>
Co-authored-by: wqzhou <[email protected]>

* add some docs for PR#3501 (deepmodeling#3537)

* Feature: enable restart charge density mixing during SCF (deepmodeling#3542)

* add a new parameter mixing_restart

* do not update rho if iter==mixing_restart

* do not update rho if iter==mixing_restart-1

* reset mix and rho_mdata if iter==mixing_restart

* fix SCF exit directly since drho=0 if iter=GlobalV::MIXING_RESTART

* re-set_mixing in eachiterinit for PW and LCAO

* enable SCF restarts in esolver_ks::RUN

* add some UnitTests

* add some Docs

* new inputs added

* Update input-main.md (deepmodeling#3551)

Solve the format problem mentioned in issue 3543

* Build: fix compatibility issue against toolchain install (deepmodeling#3540)

* Fix for finding LibXC and ELPA

* For compatibility to previous routines

* syntax fix for FindELPA.cmake

* Update cmake/FindELPA.cmake

Co-authored-by: Chun Cai <[email protected]>

* Using CMake interface as default for finding LibXC

* update docs

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* update docs for installing pkg-config

* Update FindLibxc.cmake

* Update FindLibxc.cmake

* remove previous LibXC routine in CMakeLists.txt

Co-authored-by: Chun Cai <[email protected]>

* Update easy_install.md with Makefile-built LibXC supported

* Update easy_install.md to include different behavior in different version on finding ELPA

* fix compatibility issue against toolchain

* Change default ELPA install routine to old one

---------

Co-authored-by: Chun Cai <[email protected]>

* Test: Configure performance tests for math libraries (deepmodeling#3511)

* add performace test of sphbes functions.

* fix benchmark cmake errors

* add dependencies for docker

* update docs

* add performance tests for sphbes

* add google benchmark

* rewrite benchmark tests in fixtures

* disable internal testing in benchmark

* merge benchmark into integration test

---------

Co-authored-by: StarGrys <[email protected]>

* Configure Makefile Compiling, fix typos

* Fix Makefile Intel toolchains compile errors

* Fix even more PEXSI related Makefile compiling issues

* Update hsolver_pw.cpp (deepmodeling#3556)

when use_uspp==false, overlap matrix should be E.

* Fix: cuda build target (deepmodeling#3276)

* Fix: cuda buid target

* Update CMakeLists.txt

---------

Co-authored-by: Denghui Lu <[email protected]>

---------

Co-authored-by: wqzhou <[email protected]>
Co-authored-by: kirk0830 <[email protected]>
Co-authored-by: Haozhi Han <[email protected]>
Co-authored-by: Zhao Tianqi <[email protected]>
Co-authored-by: PeizeLin <[email protected]>
Co-authored-by: jinzx10 <[email protected]>
Co-authored-by: Chun Cai <[email protected]>
Co-authored-by: Peng Xingliang <[email protected]>
Co-authored-by: Jie Li <[email protected]>
Co-authored-by: Wenfei Li <[email protected]>
Co-authored-by: Denghui Lu <[email protected]>
Co-authored-by: YI Zeping <[email protected]>
Co-authored-by: wenfei-li <[email protected]>
Co-authored-by: jingan-181 <[email protected]>
Co-authored-by: StarGrys <[email protected]>
Co-authored-by: Haozhi Han <[email protected]>
Revert "Modify inputs and update to latest version"
Flying-dragon-boxing and others added 29 commits September 15, 2025 15:19
…+ architecture requirements

Co-authored-by: Flying-dragon-boxing <[email protected]>
…gic-bugs-cuda

Fix CMake CUDA logic: replace deprecated CUDA_VERSION and handle CUDA 13+ architecture requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential CMake logic bugs with CUDA