Skip to content

Support ICON GPU #64

@kvrigor

Description

@kvrigor

To be done after #53. @s-poll 's ICON GPU build script should be retrofitted to BuildICON.cmake.

#!/bin/bash

# ICON
#
# ------------------------------------------
# Copyright (C) 2004-2025, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss
# Contact information: icon-model.org
# See AUTHORS.TXT for a list of authors
# See LICENSES/ for license information
# SPDX-License-Identifier: BSD-3-Clause
# ------------------------------------------

set -eu
unset CDPATH
ulimit -c 0

MODULES="Stages/2025 NVHPC ParaStationMPI ecCodes netCDF-Fortran netCDF CMake"
BUILD_ENV="module --force purge; module load ${MODULES}; module list;"
eval "${BUILD_ENV}"

script_dir=$(cd "$(dirname "$0")"; pwd)
icon_dir=$(cd "${script_dir}/../.."; pwd)

NVHPC_ROOT=$EBROOTNVHPC
MPI_ROOT=$EBROOTPSMPI

HDF5_ROOT=$EBROOTHDF5 
HDF5_LIBS='-lhdf5_hl -lhdf5'

NETCDF_ROOT=$EBROOTNETCDF
NETCDF_LIBS='-lnetcdf'

PNETCDF_ROOT=$EBROOTPNETCDF
PNETCDF_LIBS='-lpnetcdf'

NETCDFF_ROOT=$EBROOTNETCDFMINFORTRAN
NETCDFF_LIBS='-lnetcdff'

BLAS_LAPACK_LIBS='-llapack -lblas'

ECCODES_ROOT=$EBROOTECCODES
ECCODES_LIBS='-leccodes'

XML2_ROOT=$EBROOTLIBXML2
XML2_LIBS='-lxml2'

################################################################################

CC="${MPI_ROOT}/bin/mpicc"
CFLAGS='-g -O2'

# Let YAC find LAPACK with the C compiler:
ICON_YAC_CFLAGS='-fortranlibs'

CPPFLAGS="-I${HDF5_ROOT}/include -I${NETCDF_ROOT}/include -I${ECCODES_ROOT}/include -I${XML2_ROOT}/include"

FC="${MPI_ROOT}/bin/mpif90"
FCFLAGS="-I${NETCDFF_ROOT}/include -g -O2 -Mrecursive -Mallocatable=03 -Mstack_arrays -Minfo=accel,inline -acc=gpu,verystrict -gpu=cc90"

# CUDA compiler must be from the same prefix as the Fortran compiler:
CUDACXX='nvcc'
CUDAFLAGS='-arch=sm_90 -g -O3'

LDFLAGS="-c++libs -nvmalloc -cuda -L${HDF5_ROOT}/lib -L${NETCDF_ROOT}/lib -L${PNETCDF_ROOT}/lib -L${NETCDFF_ROOT}/lib -L${ECCODES_ROOT}/lib64"
LIBS="-Wl,--as-needed ${XML2_LIBS} ${ECCODES_LIBS} ${BLAS_LAPACK_LIBS} ${NETCDFF_LIBS} ${NETCDF_LIBS} ${HDF5_LIBS} "

MPI_LAUNCH=false

EXTRA_CONFIG_ARGS='--enable-gpu --enable-mpi-gpu --disable-mpi-checks --disable-ocean --disable-jsbach --disable-coupling --disable-rte-rrtmgp --enable-ecrad'

EXTRA_CONFIG_ARGS+=' --enable-realloc-buf --enable-pgi-inlib'

################################################################################

"${icon_dir}/configure" \
BUILD_ENV="${BUILD_ENV}" \
CC="${CC}" \
CFLAGS="${CFLAGS}" \
CPPFLAGS="${CPPFLAGS}" \
CUDACXX="${CUDACXX}" \
CUDAFLAGS="${CUDAFLAGS}" \
FC="${FC}" \
FCFLAGS="${FCFLAGS}" \
ICON_YAC_CFLAGS="${ICON_YAC_CFLAGS}" \
LDFLAGS="${LDFLAGS}" \
LIBS="${LIBS}" \
MPI_LAUNCH="${MPI_LAUNCH}" \
${EXTRA_CONFIG_ARGS} \
"$@"

for arg in "$@"; do
  case $arg in
    -help | --help | --hel | --he | -h | -help=r* | --help=r* | --hel=r* | --he=r* | -hr* | -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
      test -n "${EXTRA_CONFIG_ARGS}" && echo '' && echo "This wrapper script ('$0') calls the configure script with the following extra arguments, which might override the default values listed above: ${EXTRA_CONFIG_ARGS}"
      exit 0 ;;
  esac
done

# Copy runscript-related files when building out-of-source:
if test $(pwd) != $(cd "${icon_dir}"; pwd); then
  echo "Copying runscript input files from the source directory..."
  rsync -uavz ${icon_dir}/run . --exclude='*.in' --exclude='.*' --exclude='standard_*'
  ln -sf -t run/ ${icon_dir}/run/standard_*
  ln -sf set-up.info run/SETUP.config
  rsync -uavz ${icon_dir}/externals . --exclude='.git' --exclude='*.f90' --exclude='*.F90' --exclude='*.c' --exclude='*.h' --exclude='*.Po' --exclude='tests' --exclude='*.mod' --exclude='*.o'
  rsync -uavz ${icon_dir}/make_runscripts .
  rsync -uavz ${icon_dir}/scripts .
  ln -sf ${icon_dir}/data
  ln -sf ${icon_dir}/vertical_coord_tables
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    ICONInvolves ICONcmakeAll matters regarding CMake

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Housekeeping

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions