Skip to content

Commit

Permalink
Use CMake HIP language feature, update CI and switch to C++17 (#54)
Browse files Browse the repository at this point in the history
* Use CMake language feature for HIP to fix #53
* Fix compilation with ROCm 6.0
* Upgrade to C++17 from C++11
* Update CI
  • Loading branch information
AdhocMan committed Mar 11, 2024
1 parent 2865e66 commit 4652d85
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 1,070 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
#########################
CPU:
# The type of runner that the job will run on
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand All @@ -33,7 +33,7 @@ jobs:

steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- uses: actions/checkout@v4


- name: Print build config
Expand All @@ -43,8 +43,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libfftw3-dev make g++ clang wget git make
cd ${HOME} && wget https://github.com/Kitware/CMake/releases/download/v3.11.4/cmake-3.11.4-Linux-x86_64.tar.gz && tar -xzvf cmake-3.11.4-Linux-x86_64.tar.gz
sudo apt-get install -y libfftw3-dev make g++ clang wget git make cmake
- name: Install MPI
if: ${{ matrix.use_mpi }}
Expand All @@ -57,7 +56,7 @@ jobs:
cd build
mkdir -p install_dir
export INSTALL_DIR=$(pwd)/install_dir
CXX=${COMPILER} ${HOME}/cmake-3.11.4-Linux-x86_64/bin/cmake .. -DSPFFT_BUILD_TESTS=OFF -DSPFFT_OMP=${USE_OMP} -DSPFFT_MPI=${USE_MPI} -DSPFFT_SINGLE_PRECISION=${USE_FLOAT} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
CXX=${COMPILER} cmake .. -DSPFFT_BUILD_TESTS=OFF -DSPFFT_OMP=${USE_OMP} -DSPFFT_MPI=${USE_MPI} -DSPFFT_SINGLE_PRECISION=${USE_FLOAT} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
make -j2
make VERBOSE=1 install
test -f ${INSTALL_DIR}/lib/libspfft.so
Expand All @@ -70,7 +69,7 @@ jobs:
rm -rf build
mkdir -p build
cd build
CXX=${COMPILER} ${HOME}/cmake-3.11.4-Linux-x86_64/bin/cmake .. -DSPFFT_BUILD_TESTS=ON -DSPFFT_OMP=${USE_OMP} -DSPFFT_MPI=${USE_MPI} -DSPFFT_SINGLE_PRECISION=${USE_FLOAT} -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
CXX=${COMPILER} cmake .. -DSPFFT_BUILD_TESTS=ON -DSPFFT_OMP=${USE_OMP} -DSPFFT_MPI=${USE_MPI} -DSPFFT_SINGLE_PRECISION=${USE_FLOAT} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_FLAGS="-Wno-error=maybe-uninitialized"
make -j2
- name: Run tests
Expand All @@ -89,45 +88,51 @@ jobs:
# Build with CUDA
#################
CUDA:
runs-on: ubuntu-18.04
container: nvidia/cuda:9.2-devel-ubuntu18.04
runs-on: ubuntu-22.04
container: nvidia/cuda:11.0.3-devel-ubuntu20.04

steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install dependencies
run: |
apt-get update
apt-get install -y libfftw3-dev make g++ mpi-default-dev wget git make
cd ${HOME} && wget https://github.com/Kitware/CMake/releases/download/v3.14.6/cmake-3.14.6-Linux-x86_64.tar.gz && tar -xzvf cmake-3.14.6-Linux-x86_64.tar.gz
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y libfftw3-dev make g++ mpi-default-dev wget git make
cd ${HOME} && wget https://github.com/Kitware/CMake/releases/download/v3.18.0/cmake-3.18.0-Linux-x86_64.tar.gz && tar -xzvf cmake-3.18.0-Linux-x86_64.tar.gz
- name: Build
run: |
cd ${GITHUB_WORKSPACE}
mkdir -p build
cd build
${HOME}/cmake-3.14.6-Linux-x86_64/bin/cmake .. -DSPFFT_BUILD_TESTS=ON -DSPFFT_GPU_BACKEND=CUDA -DSPFFT_OMP=OFF
${HOME}/cmake-3.18.0-Linux-x86_64/bin/cmake .. -DSPFFT_BUILD_TESTS=ON -DSPFFT_GPU_BACKEND=CUDA -DSPFFT_OMP=OFF
make -j2
#################
# Build with ROCm
#################
ROCM:
runs-on: ubuntu-18.04
container: adhocman/master:ubuntu18.04_rocm
runs-on: ubuntu-22.04
container: rocm/dev-ubuntu-22.04:5.3-complete

steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install dependencies
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y libfftw3-dev make g++ mpi-default-dev wget git make
cd ${HOME} && wget https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0-linux-x86_64.tar.gz && tar -xzvf cmake-3.21.0-linux-x86_64.tar.gz
- name: Build
run: |
cd ${GITHUB_WORKSPACE}
mkdir -p build
cd build
/root/cmake-3.11.4-Linux-x86_64/bin/cmake .. -DSPFFT_BUILD_TESTS=ON -DSPFFT_GPU_BACKEND=ROCM -DCMAKE_PREFIX_PATH=/opt/rocm
${HOME}/cmake-3.21.0-linux-x86_64/bin/cmake .. -DSPFFT_BUILD_TESTS=ON -DSPFFT_GPU_BACKEND=ROCM -DCMAKE_PREFIX_PATH=/opt/rocm
make -j2
33 changes: 11 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.11 FATAL_ERROR) # 3.11 to avoid issues with OpenMP + CUDA
cmake_minimum_required(VERSION 3.18 FATAL_ERROR) # 3.18 for C++17
project(SpFFT LANGUAGES CXX VERSION 1.0.6)
set(SPFFT_SO_VERSION 1)
set(SPFFT_VERSION ${PROJECT_VERSION})
Expand All @@ -22,22 +22,9 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

# set language and standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CUDA_STANDARD 11)

# set CUDA flags
if(NOT CMAKE_CUDA_FLAGS_RELEASE)
set(CMAKE_CUDA_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Flags used by CUDA compiler at given build type." FORCE)
endif()
if(NOT CMAKE_CUDA_FLAGS_RELWITHDEBINFO)
set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Flags used by CUDA compiler at given build type." FORCE)
endif()
if(NOT CMAKE_CUDA_FLAGS_MINSIZEREL)
set(CMAKE_CUDA_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING "Flags used by CUDA compiler at given build type." FORCE)
endif()
if(NOT CMAKE_CUDA_FLAGS_DEBUG)
set(CMAKE_CUDA_FLAGS_DEBUG "-g" CACHE STRING "Flags used by CUDA compiler at given build type." FORCE)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_HIP_STANDARD 17)

#add local module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/modules)
Expand Down Expand Up @@ -129,6 +116,10 @@ endif()

# ROCM
if(SPFFT_ROCM)
cmake_minimum_required(VERSION 3.21 FATAL_ERROR) # hip support only added in 3.21

enable_language(HIP)

find_package(hip CONFIG REQUIRED)
find_package(rocfft CONFIG REQUIRED)
find_package(hipfft CONFIG) # hipfft within rocfft is deprecated. Use separate hipfft if available (not required).
Expand All @@ -144,11 +135,9 @@ if(SPFFT_ROCM)

list(APPEND SPFFT_EXTERNAL_LIBS hip::host roc::rocfft)

# FindHIP module provides compilation command for GPU code
find_package(HIP MODULE REQUIRED)
if(NOT HIP_HCC_FLAGS)
message(STATUS "Using default AMD gpu targets: gfx803, gfx900, gfx906. Set HIP_HCC_FLAGS to override.")
set(HIP_HCC_FLAGS ${HIP_HCC_FLAGS} --amdgpu-target=gfx803 --amdgpu-target=gfx900 --amdgpu-target=gfx906)
# Previously used option for flags.
if(HIP_HCC_FLAGS)
message(WARNING "HIP_HCC_FLAGS has no effect. Use CMAKE_HIP_FLAGS for flags and CMAKE_HIP_ARCHITECTURES for arch instead.")
endif()
endif()

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ A transform can be computed in-place and out-of-place. Addtionally, an internall
Documentation can be found [here](https://spfft.readthedocs.io/en/latest/).

## Requirements
- C++ Compiler with C++11 support. Supported compilers are:
- GCC 6 and later
- C++ Compiler with C++17 support. Supported compilers are:
- GCC 7 and later
- Clang 5 and later
- ICC 19.0 and later
- CMake 3.11 and later
- CMake 3.18 and later (3.21 for ROCm)
- Library providing a FFTW 3.x interface (FFTW3 or Intel MKL)
- For multi-threading: OpenMP support by the compiler
- For compilation with GPU support:
- CUDA 9.0 and later for Nvidia hardware
- ROCm 3.5 and later for AMD hardware
- CUDA 11.0 and later for Nvidia hardware
- ROCm 5.0 and later for AMD hardware

## Installation
The build system follows the standard CMake workflow. Example:
Expand All @@ -72,6 +72,7 @@ make -j8 install
| SPFFT_INSTALL | ON | Add library to install target |
| SPFFT_FORTRAN | OFF | Build Fortran interface module |

**_NOTE:_** When compiling with CUDA or ROCM (HIP), the standard `CMAKE_CUDA_ARCHITECTURES` and `CMAKE_HIP_ARCHITECTURES` options should be defined as well. `HIP_HCC_FLAGS` is no longer in use.

## Examples
Further exmples for C++, C and Fortran can be found in the "examples" folder.
Expand Down

0 comments on commit 4652d85

Please sign in to comment.