Skip to content

Commit eca4a54

Browse files
authored
Merge pull request #445 from eagles-project/mjs/m4x/intel-sycl-build
Enables building mam4xx on Intel GPUs with SYCL
2 parents 7721254 + 829d12e commit eca4a54

File tree

7 files changed

+179
-61
lines changed

7 files changed

+179
-61
lines changed

.github/workflows/at2_gcc-cuda.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ jobs:
6868
build-type: ${{ fromJSON(needs.define_matrix.outputs.build_type) }}
6969
fp-precision: ${{ fromJSON(needs.define_matrix.outputs.precision) }}
7070
name: gcc-cuda / ${{ matrix.build-type }} - ${{ matrix.fp-precision }}
71+
env:
72+
# relative path to nvcc_wrapper from mam4xx root
73+
haero_nvcw: "haero_src/ext/ekat/extern/kokkos/bin/nvcc_wrapper"
7174
steps:
7275
- name: Check out the repository
7376
uses: actions/checkout@v4
@@ -79,7 +82,6 @@ jobs:
7982
uses: actions/checkout@v4
8083
with:
8184
repository: eagles-project/haero
82-
ref: 017fea932381777f48b2585f86d6ab48fe4b8d09
8385
submodules: recursive
8486
path: haero_src
8587
- name: Show action trigger
@@ -100,49 +102,56 @@ jobs:
100102
echo "H100 detected--setting Hopper90 architecture"
101103
echo "Hopper=ON" >> $GITHUB_ENV
102104
echo "CUDA_ARCH=90" >> $GITHUB_ENV
103-
ARCH=90
105+
echo "CUDA_DEVICE=HOPPER90" >> $GITHUB_ENV
104106
;;
105107
*"A100"*)
106108
echo "A100 detected--setting Ampere80 architecture"
107109
echo "Ampere=ON" >> $GITHUB_ENV
108110
echo "CUDA_ARCH=80" >> $GITHUB_ENV
111+
echo "CUDA_DEVICE=AMPERE80" >> $GITHUB_ENV
109112
;;
110113
*"V100"*)
111114
echo "V100 detected--setting Volta70 architecture"
112115
echo "Volta=ON" >> $GITHUB_ENV
113116
echo "CUDA_ARCH=70" >> $GITHUB_ENV
117+
echo "CUDA_DEVICE=VOLTA70" >> $GITHUB_ENV
114118
;;
115119
*)
116120
echo "Unsupported GPU model: $gpu_model"
117121
exit 1
118122
;;
119123
esac
124+
- name: Set nvcc_wrapper Arch
125+
run: |
126+
nvcw="$(pwd)/${haero_nvcw}"
127+
sed -i s/default_arch=\"sm_70\"/default_arch=\"sm_"$CUDA_ARCH"\"/g "${nvcw}"
128+
echo "===================================="
129+
grep -i "default_arch=" "${nvcw}"
120130
- name: Building Haero (${{ matrix.build-type }}, ${{ matrix.fp-precision }} precision)
121131
run: |
132+
nvcw="$(pwd)/${haero_nvcw}"
122133
cmake -S haero_src -B haero_build \
123134
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
124135
-DCMAKE_INSTALL_PREFIX="haero_install" \
125136
-DCMAKE_C_COMPILER=gcc \
126-
-DCMAKE_CXX_COMPILER=g++ \
137+
-DCMAKE_CXX_COMPILER="${nvcw}" \
127138
-DHAERO_ENABLE_MPI=OFF \
128139
-DHAERO_ENABLE_GPU=ON \
129-
-DHAERO_PRECISION=${{ matrix.fp-precision }}
140+
-DHAERO_PRECISION=${{ matrix.fp-precision }} \
141+
-DKokkos_ARCH_$CUDA_DEVICE=ON \
142+
-DHAERO_DEVICE_ARCH=$CUDA_DEVICE
130143
cd haero_build
131144
make -j
132145
make install
133-
- name: Set nvcc_wrapper Arch
134-
run: |
135-
sed -i s/default_arch=\"sm_70\"/default_arch=\"sm_"$CUDA_ARCH"\"/g `pwd`/haero_install/bin/nvcc_wrapper
136-
echo "===================================="
137-
grep -i "default_arch=" `pwd`/haero_install/bin/nvcc_wrapper
138146
- name: Configuring MAM4xx (${{ matrix.build-type }}, ${{ matrix.fp-precision }} precision)
139147
run: |
148+
nvcw="$(pwd)/${haero_nvcw}"
140149
cmake -S . -B build \
141-
-DCMAKE_CXX_COMPILER=`pwd`/haero_install/bin/nvcc_wrapper \
150+
-DCMAKE_CXX_COMPILER="${nvcw}" \
142151
-DCMAKE_C_COMPILER=gcc \
143-
-DCMAKE_INSTALL_PREFIX=`pwd`/install \
152+
-DCMAKE_INSTALL_PREFIX=$(pwd)/install \
144153
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
145-
-DMAM4XX_HAERO_DIR=`pwd`/haero_install \
154+
-DMAM4XX_HAERO_DIR=$(pwd)/haero_install \
146155
-DNUM_VERTICAL_LEVELS=72 \
147156
-DENABLE_COVERAGE=OFF \
148157
-DENABLE_SKYWALKER=ON \
@@ -151,7 +160,7 @@ jobs:
151160
- name: Building MAM4xx (${{ matrix.build-type }}, ${{ matrix.fp-precision }} precision)
152161
run: |
153162
cd build
154-
make
163+
make -j
155164
- name: Running tests (${{ matrix.build-type }}, ${{ matrix.fp-precision }} precision)
156165
run: |
157166
cd build

.github/workflows/gh_gcc-cpu.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ jobs:
5454
prec: ${{ inputs.precision || 'ALL' }}
5555
run: |
5656
case ${{ env.prec }} in
57-
"Debug")
57+
"single")
5858
echo 'precision=["single"]' >> "$GITHUB_OUTPUT" ;;
59-
"Release")
59+
"double")
6060
echo 'precision=["double"]' >> "$GITHUB_OUTPUT" ;;
6161
"ALL")
6262
echo 'precision=["single", "double"]' >> "$GITHUB_OUTPUT" ;;
@@ -108,7 +108,6 @@ jobs:
108108
uses: actions/checkout@v3
109109
with:
110110
repository: eagles-project/haero
111-
ref: 017fea932381777f48b2585f86d6ab48fe4b8d09
112111
submodules: recursive
113112
path: haero_src
114113

@@ -130,9 +129,9 @@ jobs:
130129
- name: Configuring MAM4xx (${{ matrix.build-type }}, ${{ matrix.fp-precision }} precision)
131130
run: |
132131
cmake -S . -B build \
133-
-DCMAKE_INSTALL_PREFIX=`pwd`/install \
132+
-DCMAKE_INSTALL_PREFIX=$(pwd)/install \
134133
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
135-
-DMAM4XX_HAERO_DIR=`pwd`/haero_install \
134+
-DMAM4XX_HAERO_DIR=$(pwd)/haero_install \
136135
-DNUM_VERTICAL_LEVELS=72 \
137136
-DENABLE_COVERAGE=ON \
138137
-G "Unix Makefiles"

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ set(CLANG_FORMAT_VERSION 14)
4242
# Set compilers, linkers, and flags from Haero.
4343
set(CMAKE_CXX_STANDARD ${HAERO_CXX_STANDARD})
4444
set(CMAKE_CXX_COMPILER ${HAERO_CXX_COMPILER})
45-
set(CMAKE_CXX_FLAGS ${HAERO_CXX_FLAGS})
45+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HAERO_CXX_FLAGS}")
4646

4747
set(CMAKE_C_STANDARD ${HAERO_C_STANDARD})
4848
set(CMAKE_C_COMPILER ${HAERO_C_COMPILER})

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,38 @@ of parameters. Check out the comments at the top of `build-haero.sh`.
4343

4444
You can build a CPU-capable version of HAERO with some defaults set by typing
4545

46+
```shell
47+
./build-haero.sh <install-path>
4648
```
47-
./build-haero.sh <path>
49+
50+
The extended syntax to fully configure other types of build is
51+
52+
```shell
53+
./build-haero.sh <install-path> <device> <precision> <build-type> [device-arch]
54+
```
55+
56+
in which the options are:
57+
58+
```shell
59+
device: {cpu, gpu}
60+
precision: {single, double}
61+
build-type: {Debug, Release}
4862
```
4963

50-
where `<path>` is a directory to which HAERO will be installed. If you'd rather
51-
install HAERO yourself, you can follow the instructions in the
64+
and the semi-optional `device-arch` argument must correspond to
65+
[those accepted by Kokkos](https://kokkos.org/kokkos-core-wiki/get-started/configuration-guide.html#architectures)
66+
and is likely required for a properly-configured GPU build.
67+
That is to say, the `device-arch` option **should** be set for GPU builds, and
68+
building for GPU without that argument is unsupported.
69+
70+
If you'd rather install HAERO yourself, you can follow the instructions in the
5271
[HAERO repository](https://github.com/eagles-project/haero). Make sure you run
5372
all the steps, including `make install`.
5473

5574
If you're on a machine that requires modules to get access to compilers, etc,
5675
use
5776
```
58-
source build-haero.sh <path>
77+
source build-haero.sh <path> [...]
5978
```
6079
to make sure your environment is updated.
6180

build-haero.sh

Lines changed: 107 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
@@ -14,6 +14,13 @@
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
2330
DEVICE=$2
2431
PRECISION=$3
2532
BUILD_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.
2736
SKIP_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-
3738
if [[ "$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
4142
fi
4243

@@ -64,7 +65,8 @@ if [[ "$PRECISION" != "single" && "$PRECISION" != "double" ]]; then
6465
exit
6566
fi
6667
if [[ "$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
6971
fi
7072

@@ -77,32 +79,103 @@ git clone [email protected]:eagles-project/haero.git .haero || exit
7779
cd .haero || exit
7880
git 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+
# ==============================================================================
10088
if [[ "$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
102158
else
103159
ENABLE_GPU=OFF
104160
fi
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+
106179
echo "Configuring Haero with the given selections (WITHOUT MPI)..."
107180
cmake -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

118193
echo "Building and installing Haero in $PREFIX..."
119194
cd .haero/build || exit
120-
make -j8 install
195+
make -j8 install || exit
121196

122197
cd ../../
123198
echo "Haero has been installed in $PREFIX. Set HAERO_DIR to this directory in"

setup

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ cmake \
9999
-DMAM4XX_HAERO_DIR=\$HAERO_DIR \
100100
-DNUM_VERTICAL_LEVELS=\$NUM_VERTICAL_LEVELS \
101101
-DENABLE_SKYWALKER=ON \
102-
-DCMAKE_CUDA_ARCHITECTURES=80 \
103102
\$OPTIONS \
104103
-G "\$GENERATOR" \
105104
\$SOURCE_DIR
@@ -120,4 +119,3 @@ echo " 1. cd $1"
120119
echo " 2. Edit config.sh"
121120
echo " 3. ./config.sh"
122121
echo " 4. Build using 'make -j'."
123-

0 commit comments

Comments
 (0)