33# This script builds the Haero high-performance aerosool toolkit with specific
44# settings so mam4xx can be linked against it. Run it like this:
55#
6- # `./build-haero.sh <prefix> <device> <precision> <build_type>
6+ # `./build-haero.sh <prefix> <device> <precision> <build_type> [gpu_type] [gpu_arch]
77#
88# where
99# * <prefix> is the installation prefix (e.g. /usr/local) in which you
1414# floating point numbers used in Haero. Default: double
1515# * <build_type> (either `Debug` or `Release`) determines whether Haero is built
1616# optimized or for debugging. Default: Debug
17+ # OPTIONAL Args (REQUIRED for GPU builds)
18+ # * [gpu_type] (`nvidia`, `amd`, `intel`) this is the "brand" of GPU
19+ # * [gpu_arch] (e.g., HOPPER90, AMD_GFX90A, INTEL_PVC) this is the "model" of
20+ # GPU, indicating the generation, compute capability, etc.
21+ # * A list of many options is found in $HAERO_ROOT/setup
22+ # * The full list of options may be found on the kokkos docs site:
23+ # https://kokkos.org/kokkos-core-wiki/get-started/configuration-guide.html#architectures
1724#
1825# NOTE: This script disables MPI, since the mam4xx team is focused on single-
1926# NOTE: node parallelism. If you need an MPI-enabled build of Haero, please
@@ -23,20 +30,14 @@ PREFIX=$1
2330DEVICE=$2
2431PRECISION=$3
2532BUILD_TYPE=$4
26- # Turn off search for yaml libraries. EKAT will build yaml-cpp from submodules.
33+ GPU_TYPE=$5
34+ DEVICE_ARCH=$6
35+ # Turn off search for yaml libraries. EKAT will build yaml-cpp from submodules.
2736SKIP_FIND_YAML_CPP=ON
2837
29- # Default compilers (can be overridden by environment variables)
30- if [[ -z $CC ]]; then
31- CC=cc
32- fi
33- if [[ -z $CXX ]]; then
34- CXX=c++
35- fi
36-
3738if [[ " $PREFIX " == " " ]]; then
3839 echo " Haero installation prefix was not specified!"
39- echo " Usage: $0 <prefix> <device> <precision> <build_type>"
40+ echo " Usage: $0 <prefix> <device> <precision> <build_type> [gpu_type] [gpu_arch] "
4041 exit
4142fi
4243
@@ -64,7 +65,8 @@ if [[ "$PRECISION" != "single" && "$PRECISION" != "double" ]]; then
6465 exit
6566fi
6667if [[ " $BUILD_TYPE " != " Debug" && " $BUILD_TYPE " != " Release" ]]; then
67- echo " Invalid optimization specified: $BUILD_TYPE (must be Debug or Release)"
68+ echo " Invalid optimization specified: $BUILD_TYPE "
69+ echo " Must be Debug or Release (case-sensitive)"
6870 exit
6971fi
7072
@@ -77,32 +79,103 @@ git clone
[email protected] :eagles-project/haero.git .haero || exit
7779cd .haero || exit
7880git submodule update --init --recursive || exit
7981
80- # Are we on a special machine?
81- cd machines
82- echo $( pwd)
83- for MACHINE_FILE in $( ls)
84- do
85- MACHINE=${MACHINE_FILE/ \. sh/ }
86- echo $MACHINE
87- echo ` hostname` | grep -q " $MACHINE "
88- host_match=$?
89- echo $SYSTEM_NAME | grep -q " $MACHINE "
90- sys_match=$?
91- if [ $host_match -eq 0 ] || [ $sys_match -eq 0 ]; then
92- echo " Found machine file $MACHINE_FILE . Setting up environment for $MACHINE ..."
93- source ./$MACHINE .sh
94- fi
95- done
82+ cd ..
9683
97- cd ../..
98-
99- # Configure Haero with the given selections.
84+ # ==============================================================================
85+ # below are the default compiler choices for gpu builds and are set based on
86+ # the command line args.
87+ # ==============================================================================
10088if [[ " $DEVICE " == " gpu" ]]; then
10189 ENABLE_GPU=ON
90+ if [[ " $GPU_TYPE " == " " ]]; then
91+ echo " ERROR: GPU_TYPE not provided for GPU build."
92+ echo " Must be nvidia, amd, or intel (case-sensitive)"
93+ exit
94+ elif [[ " $GPU_TYPE " != " nvidia" && " $GPU_TYPE " != " amd" && " $GPU_TYPE " != " intel" ]]; then
95+ echo " Device provided as 'gpu', but invalid GPU_TYPE specified: ${GPU_TYPE} ."
96+ echo " Must be nvidia, amd, or intel (case-sensitive)"
97+ exit
98+ fi
99+ if [[ " $DEVICE_ARCH " == " " ]]; then
100+ echo " ERROR: DEVICE_ARCH not provided for GPU build."
101+ exit
102+ fi
103+ # ==============================================================================
104+ # NVIDIA GPU + gcc
105+ # NOTE: if CXX is set to nvcc_wrapper, then this must be the same path used
106+ # in the `sed` command below
107+ # This happens by default via the $nvcw variable and should typically work
108+ # unless your environment differs from the default
109+ # ==============================================================================
110+ if [[ " $GPU_TYPE " == " nvidia" ]]; then
111+ echo " GPU_TYPE given as nvidia (${DEVICE_ARCH} )--setting default compilers."
112+ echo " and modifying nvcc_wrapper with correct architecture flag."
113+ CXX=" $( pwd) /.haero/ext/ekat/extern/kokkos/bin/nvcc_wrapper"
114+ nvcw=$CXX
115+ CC=gcc
116+ echo " C++ compiler: ${CXX} "
117+ echo " C compiler: ${CC} "
118+ # ==========================================================================
119+ if [[ -x " $nvcw " ]]; then
120+ # FIXME: this will not work for compute capbility 10.0
121+ CUDA_GEN=${DEVICE_ARCH: (-2)}
122+ # FIXME: this assumes a default value in nvcc_wrapper
123+ sed -i s/default_arch=\" sm_70\" /default_arch=\" sm_" $CUDA_GEN " \" /g " ${nvcw} "
124+ echo " ===================================================================="
125+ echo " nvcc_wrapper modified--verify that default_arch=sm_${CUDA_GEN} "
126+ echo " ===================================================================="
127+ grep -i " default_arch=" " ${nvcw} "
128+ echo " ===================================================================="
129+ else
130+ echo " ERROR: nvcc_wrapper not found at expected location for nvidia gpu build."
131+ exit
132+ fi
133+ # ==============================================================================
134+ # AMD GPU + HIP and clang
135+ # ==============================================================================
136+ elif [[ " $GPU_TYPE " == " amd" ]]; then
137+ echo " GPU_TYPE given as amd--setting default compilers."
138+ CXX=hipcc
139+ CC=amdclang
140+ echo " C++ compiler: ${CXX} "
141+ echo " C compiler: ${CC} "
142+ # ==============================================================================
143+ # Intel GPU + intel compilers
144+ # ==============================================================================
145+ elif [[ " $GPU_TYPE " == " intel" ]]; then
146+ echo " GPU_TYPE given as intel--setting default compilers."
147+ CXX=icpx
148+ CC=icx
149+ echo " C++ compiler: ${CXX} "
150+ echo " C compiler: ${CC} "
151+ # ==============================================================================
152+ else
153+ echo " Device provided as 'gpu', but invalid GPU_TYPE specified: ${GPU_TYPE} ."
154+ echo " Must be nvidia, amd, or intel (case-sensitive)"
155+ echo " More importantly... how did we get here?"
156+ exit
157+ fi
102158else
103159 ENABLE_GPU=OFF
104160fi
105161
162+ if [[ " $DEVICE " == " cpu" ]]; then
163+ # Default cpu compilers (can be overridden by environment variables)
164+ echo " Setting compilers for CPU device."
165+ if [[ -z $CC ]]; then
166+ echo " 'CC' environment variable not found--setting to default (gcc)"
167+ CC=gcc
168+ fi
169+ if [[ -z $CXX ]]; then
170+ echo " 'CXX' environment variable not found--setting to default (g++)"
171+ CXX=g++
172+ fi
173+ fi
174+
175+ # ==============================================================================
176+ # DON'T CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU'RE DOING
177+ # ==============================================================================
178+
106179echo " Configuring Haero with the given selections (WITHOUT MPI)..."
107180cmake -S ./.haero -B ./.haero/build \
108181 -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
@@ -113,11 +186,13 @@ cmake -S ./.haero -B ./.haero/build \
113186 -DHAERO_ENABLE_MPI=OFF \
114187 -DHAERO_ENABLE_GPU=$ENABLE_GPU \
115188 -DHAERO_PRECISION=$PRECISION \
189+ -DKokkos_ARCH_$DEVICE_ARCH :BOOL=ON \
190+ -DHAERO_DEVICE_ARCH=$DEVICE_ARCH \
116191 || exit
117192
118193echo " Building and installing Haero in $PREFIX ..."
119194cd .haero/build || exit
120- make -j8 install
195+ make -j8 install || exit
121196
122197cd ../../
123198echo " Haero has been installed in $PREFIX . Set HAERO_DIR to this directory in"
0 commit comments