Skip to content

Commit

Permalink
Refactor CMake and CI scripting (#316)
Browse files Browse the repository at this point in the history
Move from Gnu Make to CMake/Ninja as the build system and update continuous integration. See the PR history for details. 

---------

Co-authored-by: Chiel van Heerwaarden <chielvanheerwaarden@gmail.com>
Co-authored-by: Robert Pincus <Robert.Pincus@columbia.edu>
Co-authored-by: Alexander Soklev <alex@makepath.com>
  • Loading branch information
4 people authored Dec 23, 2024
1 parent bda5e7e commit e13d20e
Show file tree
Hide file tree
Showing 40 changed files with 970 additions and 820 deletions.
25 changes: 25 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
with section("parse"):
additional_commands = {"check_python3_package": {"pargs": 1, "kwargs": {"CODE": 1}}}

with section("format"):
dangle_parens = True
max_lines_hwrap = 0
keyword_case = "upper"
autosort = True

with section("lint"):
# The formatter sometimes fails to fit the code into the line limit (C0301) and can
# disagree with the linter regarding the indentation (C0307):
disabled_codes = ["C0301", "C0307"]
# Names of local variables must be in lowercase but sometimes we need to
# override standard CMake variables:
local_var_pattern = "CMAKE_[0-9A-Z_]+|[a-z][0-9a-z_]+"
# The standard names of the languages in CMake are C and Fortran. Names of
# private variables must be in lowercase but can have substings "C" and
# "Fortran":
private_var_pattern = (
"([a-z_][0-9a-z_]*_)?(C|Fortran)(_[a-z_][0-9a-z_]*)?|[a-z_][0-9a-z_]+"
)
# The standard name of the language in CMake is Fortran. Names of public
# variables must be in uppercase but can have substring "Fortran":
public_var_pattern = "([A-Z][0-9A-Z_]*_)?Fortran(_[A-Z][0-9A-Z_]*)?|[A-Z][0-9A-Z_]+"
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Formatted entire CMake code base with cmake-format
45b43632309cff022326472a8be0fdd5efc8f5c8
11 changes: 7 additions & 4 deletions .github/workflows/check-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
API:
runs-on: ubuntu-22.04
env:
# Core variables:
FC: gfortran-12
FCFLAGS: "-ffree-line-length-none -m64 -std=f2008 -march=native -fbounds-check -fmodule-private -fimplicit-none -finit-real=nan -g -DRTE_USE_CBOOL"
RRTMGP_ROOT: ${{ github.workspace }}
FFLAGS: "-m64 -std=f2008 -march=native -fbounds-check -fmodule-private -fimplicit-none -finit-real=nan"
RTE_KERNELS: extern
CMAKE_BUILD_PARALLEL_LEVEL: 8
VERBOSE:
steps:
#
# Check out repository under $GITHUB_WORKSPACE
Expand All @@ -31,4 +31,7 @@ jobs:
- name: Build libraries
run: |
$FC --version
make -j4 libs
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DKERNEL_MODE=$RTE_KERNELS
cmake --build build
88 changes: 32 additions & 56 deletions .github/workflows/containerized-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@ jobs:
include:
# Set flags for Intel Fortran Compiler Classic
- fortran-compiler: ifort
fcflags: -m64 -g -traceback -heap-arrays -assume realloc_lhs -extend-source 132 -check bounds,uninit,pointers,stack -stand f08 -diag-disable=10448
fcflags: -m64 -traceback -heap-arrays -assume realloc_lhs -extend-source 132 -check bounds,uninit,pointers,stack -stand f08 -diag-disable=10448
build-type: RelWithDebInfo
# Set flags for Intel Fortran Compiler
- fortran-compiler: ifx
rte-kernels: default
fcflags: -debug -traceback -O0 -heap-arrays -assume realloc_lhs -extend-source 132 -stand f08
build-type: None
- fortran-compiler: ifx
rte-kernels: accel
fcflags: -debug -traceback -O0 -heap-arrays -assume realloc_lhs -extend-source 132 -stand f08 -fiopenmp -fopenmp-targets=spir64
build-type: None
# Set flags for NVIDIA Fortran compiler
- fortran-compiler: nvfortran
rte-kernels: default
fcflags: -Mallocatable=03 -Mstandard -Mbounds -Mchkptr -Kieee -Mchkstk
build-type: None
- fortran-compiler: nvfortran
rte-kernels: accel
fcflags: -Mallocatable=03 -Mstandard -Mbounds -Mchkptr -Kieee -Mchkstk -acc
build-type: None
# Set container images
- fortran-compiler: ifort
image: ghcr.io/earth-system-radiation/rte-rrtmgp-ci:oneapi
Expand All @@ -46,86 +51,57 @@ jobs:
container:
image: ${{ matrix.image }}
env:
# Core variables:
FC: ${{ matrix.fortran-compiler }}
FCFLAGS: ${{ matrix.fcflags }} -DRTE_USE_${{ matrix.fpmodel}}
# Make variables:
NFHOME: /opt/netcdf-fortran
RRTMGP_ROOT: ${{ github.workspace }}
RRTMGP_DATA: ${{ github.workspace }}/rrtmgp-data
RTE_KERNELS: ${{ matrix.rte-kernels }}
RUN_CMD:
FFLAGS: ${{ matrix.fcflags }}
NetCDF_Fortran_ROOT: /opt/netcdf-fortran
CMAKE_BUILD_PARALLEL_LEVEL: 8
VERBOSE:
# TODO: add missing test dependencies and run them in parallel:
# CTEST_PARALLEL_LEVEL: 8
CTEST_OUTPUT_ON_FAILURE: 1
# https://github.com/earth-system-radiation/rte-rrtmgp/issues/194
OMP_TARGET_OFFLOAD: DISABLED
FAILURE_THRESHOLD: 7.e-4

steps:
#
# Checks-out repository under $GITHUB_WORKSPACE
# Check out repository under $GITHUB_WORKSPACE
#
- uses: actions/checkout@v4
- name: Check out code
uses: actions/checkout@v4
#
# Check out data
# Install required tools
#
- name: Check out data
uses: actions/checkout@v4
with:
repository: earth-system-radiation/rrtmgp-data
path: rrtmgp-data
ref: v1.8.2
- name: Install Required Tools
run: |
apt-get update
apt-get install -y git cmake ninja-build
#
# Build libraries, examples and tests (expect success)
#
- name: Build libraries, examples and tests (expect success)
id: build-success
if: matrix.fortran-compiler != 'ifx' || matrix.rte-kernels != 'accel'
run: |
$FC --version
make -j4 libs
#
# Build libraries, examples and tests (expect failure)
#
- name: Build libraries, examples and tests (expect failure)
if: steps.build-success.outcome == 'skipped'
shell: bash
run: |
$FC --version
make -j4 libs 2> >(tee make.err >&2) && {
echo "Unexpected success"
exit 1
} || {
grep make.err -e 'Internal compiler error' && {
echo "Expected failure"
} || {
echo "Unexpected failure"
exit 1
}
}
cmake -S . -B build -G "Ninja" \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DRTE_ENABLE_SP=`test 'x${{ matrix.fpmodel }}' = xSP && echo ON || echo OFF` \
-DKERNEL_MODE=${{ matrix.rte-kernels }} \
-DBUILD_TESTING=ON
cmake --build build
#
# Run examples and tests
#
- name: Run examples and tests
working-directory: build
if: steps.build-success.outcome != 'skipped'
run: make -j4 tests
#
# Relax failure thresholds for single precision
#
- name: Relax failure threshold for single precision
if: matrix.fpmodel == 'SP' && steps.build-success.outcome != 'skipped'
run: echo "FAILURE_THRESHOLD=3.5e-1" >> $GITHUB_ENV
#
# Compare the results
#
- name: Compare the results
if: steps.build-success.outcome != 'skipped'
run: make -j4 check
run: ctest
#
# Generate validation plots
#
- name: Generate validation plots
if: matrix.fortran-compiler == 'ifort' && matrix.rte-kernels == 'default' && matrix.fpmodel == 'DP'
working-directory: tests
run: python validation-plots.py
run: |
cmake --build build --target validation-plots
#
# Upload validation plots
#
Expand All @@ -134,4 +110,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: valdiation-plot
path: tests/validation-figures.pdf
path: build/tests/validation-figures.pdf
Loading

0 comments on commit e13d20e

Please sign in to comment.