Skip to content

Commit

Permalink
CI: make sure to use Clang as CUDA compiler on Clang+CUDA builds
Browse files Browse the repository at this point in the history
- set CMAKE_CUDA_COMPILER=clang++ in CI script
- changed CUDA arch specification with SPIRIT_CUDA_ARCH to number only (dropped prefix "sm_") in order to be able to set CMAKE_CUDA_ARCHITECTURES needed for Clang properly (which only expects a number)
  • Loading branch information
muellan committed Jun 7, 2023
1 parent 0a219e8 commit 2edff73
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,22 @@ jobs:
run: |
sudo apt-get --purge remove "clang*"
wget --no-verbose -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main"
sudo apt update
sudo apt install xorg-dev libglu1-mesa-dev libgtk-3-dev clang-16 lldb-16 lld-16 libomp-16-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 16
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 16
sudo apt install xorg-dev libglu1-mesa-dev libgtk-3-dev clang-17 lldb-17 lld-17 libomp-17-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 10
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 10
- name: 📚 Install NVIDIA HPC SDK
- name: 📚 Install CUDA Toolkit
if: matrix.parallelisation == 'cuda'
shell: bash
run: |
curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg
echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | sudo tee /etc/apt/sources.list.d/nvhpc.list
sudo apt update -y
sudo apt install -y nvhpc-23-3
echo "/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/bin" >> $GITHUB_PATH
echo "/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/math_libs/lib64" >> $GITHUB_PATH
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
echo "/usr/local/cuda-12.1/bin" >> $GITHUB_PATH
echo "/usr/local/cuda-12.1/lib64" >> $GITHUB_PATH
- name: 📚 Install LLVM (MacOS)
if: matrix.os == 'macos-13'
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
if: matrix.parallelisation == 'cuda'
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_FLAGS -DSPIRIT_USE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/cuda/
run: cmake $GITHUB_WORKSPACE -DCMAKE_CUDA_COMPILER=clang++ -DSPIRIT_CUDA_ARCH=70 -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_FLAGS -DSPIRIT_USE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-12.1/

- name: ⚙ Configure with OpenMP
if: matrix.parallelisation == 'openmp'
Expand Down Expand Up @@ -239,14 +239,14 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Force downgrade to gcc-10 on Ubuntu 22.04 to avoid a bug in gcc-11.3 header
if: matrix.config.os == 'ubuntu-22.04'
- name: Force upgrade to gcc-12 on Ubuntu 22.04
if: matrix.os == 'ubuntu-22.04'
shell: bash
run: |
sudo apt-get --purge remove "g++*"
sudo apt install g++-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
sudo apt install g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 10
- name: 📚 Install NVIDIA HPC SDK and some libs
shell: bash
Expand Down Expand Up @@ -470,21 +470,21 @@ jobs:
run: ctest -C $BUILD_TYPE --rerun-failed --output-on-failure

build-cuda:
runs-on: ${{ matrix.config.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
config:
- os: ubuntu-22.04
env:
BUILD_TYPE: Release
CMAKE_FLAGS: -DSPIRIT_UI_USE_IMGUI=OFF -DSPIRIT_UI_CXX_USE_QT=OFF -DSPIRIT_USE_CUDA=ON -DSPIRIT_CUDA_ARCH=sm_70
CMAKE_FLAGS: -DSPIRIT_UI_USE_IMGUI=OFF -DSPIRIT_UI_CXX_USE_QT=OFF -DSPIRIT_USE_CUDA=ON -DSPIRIT_CUDA_ARCH=70

steps:
- uses: actions/checkout@v3

- name: Force downgrade to gcc-10 on Ubuntu 22.04 to avoid a bug in gcc-11.3 header
if: matrix.config.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-22.04'
shell: bash
run: |
sudo apt-get --purge remove "g++*"
Expand Down Expand Up @@ -763,4 +763,4 @@ jobs:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: ${{ steps.changelog.outputs.changelog }}
draft: true
draft: true
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ set( SPIRIT_USE_THREADS OFF CACHE BOOL "Use std threads to speed up certa
set( SPIRIT_USE_FFTW ON CACHE BOOL "If available, use the FFTW library instead of kissFFT." )
### Set the scalar type used in the Spirit library
set( SPIRIT_SCALAR_TYPE "double" CACHE STRING "The scalar type to be used in the Spirit library." )
### Set the compute capability for CUDA compilation
set( SPIRIT_CUDA_ARCH "sm_60" CACHE STRING "The CUDA compute architecture to use in case of a CUDA build." )
### Set the compute capability for CUDA compilation (note: specify without prefix "sm_")
set( SPIRIT_CUDA_ARCH "60" CACHE STRING "The CUDA compute architecture to use in case of a CUDA build." )
####################################################################
### CMake Verbosity
option( SPIRIT_PRINT_SOURCES "Print Headers and Sources from Cmake." OFF )
Expand Down Expand Up @@ -303,4 +303,4 @@ install( FILES ${CMAKE_CURRENT_LIST_DIR}/ui-cpp/ui-imgui/thirdparty/stb/LICENSE

######### Write VERSION.txt ########################################
file( WRITE "${CMAKE_SOURCE_DIR}/VERSION.txt" "${SPIRIT_META_NAME_VERSION}" )
####################################################################
####################################################################
20 changes: 14 additions & 6 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ option( SPIRIT_USE_FFTW "If available, use the FFTW library instead of k
### Set the scalar type used in the Spirit library
option( SPIRIT_SCALAR_TYPE "Use std threads to speed up certain parts of the code." "double" )
### Set the compute capability for CUDA compilation
option( SPIRIT_CUDA_ARCH "Use std threads to speed up certain parts of the code." "sm_60" )
option( SPIRIT_CUDA_ARCH "Use std threads to speed up certain parts of the code." "60" )
####################################################################


Expand Down Expand Up @@ -146,20 +146,28 @@ if( SPIRIT_USE_CUDA )
set( SPIRIT_CUDA_LIBS "${CUDA_LIBRARIES};${CUDA_CUFFT_LIBRARIES};${CUDA_curand_LIBRARY}" )
set( FFT_LIB ${CUDA_CUFFT_LIBRARIES} )

if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "NVHPC" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "NVCC" )
set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo -arch=${SPIRIT_CUDA_ARCH} --expt-relaxed-constexpr --expt-extended-lambda" )
if( "${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA" )
set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo -arch=sm_${SPIRIT_CUDA_ARCH} --expt-relaxed-constexpr --expt-extended-lambda" )
### Deactivate CUDA warning inside Eigen such as "warning: __host__ annotation is ignored on a function("Quaternion") that is explicitly defaulted on its first declaration"
set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe=\"--diag_suppress=esa_on_defaulted_function_ignored\"")
### Display warning number when writing a warning
set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--display_error_number\"" )

set( META_COMPILER "${META_COMPILER} and nvcc" )
set( META_COMPILER_VERSION "${META_COMPILER_VERSION} and ${CUDA_VERSION}" )
set( META_COMPILER_FULL "${META_COMPILER_FULL} and nvcc (${CUDA_VERSION}) for cuda arch \\\"${SPIRIT_CUDA_ARCH}\\\"" )
set( META_COMPILER_FULL "${META_COMPILER_FULL} and nvcc (${CUDA_VERSION}) for cuda arch \\\"sm_${SPIRIT_CUDA_ARCH}\\\"" )

elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "NVHPC")
set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -cuda" )

set( META_COMPILER "${META_COMPILER}" )
set( META_COMPILER_VERSION "${META_COMPILER_VERSION} and ${CUDA_VERSION}" )
set( META_COMPILER_FULL "${META_COMPILER_FULL} and nvcc (${CUDA_VERSION}) for cuda arch \\\"sm_${SPIRIT_CUDA_ARCH}\\\"" )

else()
set( CMAKE_CUDA_ARCHITECTURES ${SPIRIT_CUDA_ARCH} )
# set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -D__STRICT_ANSI__" )
# set( SPIRIT_COMPILE_DEFINITIONS "${SPIRIT_COMPILE_DEFINITIONS} -D__STRICT_ANSI__" )

set( META_COMPILER "${META_COMPILER}" )
set( META_COMPILER_VERSION "${META_COMPILER_VERSION} and CUDA ${CUDA_VERSION}" )
set( META_COMPILER_FULL "${META_COMPILER_FULL} and (CUDA ${CUDA_VERSION}) for cuda arch \\\"${SPIRIT_CUDA_ARCH}\\\"" )
Expand Down Expand Up @@ -741,4 +749,4 @@ if( SPIRIT_PRINT_SOURCES )
endif()
MESSAGE( STATUS ">> --------------------- Spirit done ---------------------------------- <<" )
message( STATUS ">> CMake CXX Flags: ${CMAKE_CXX_FLAGS}" )
MESSAGE( STATUS ">> -------------------------------------------------------------------- <<" )
MESSAGE( STATUS ">> -------------------------------------------------------------------- <<" )

0 comments on commit 2edff73

Please sign in to comment.