Skip to content

Commit 380a016

Browse files
committed
Merge branch 'hypre-cuda-fixes' into tsmp-pdaf-patched
2 parents 71d9009 + 258fb92 commit 380a016

3 files changed

Lines changed: 74 additions & 51 deletions

File tree

.github/workflows/linux.yml

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
jobs:
66
style-check:
7-
runs-on: ubuntu-22.04
7+
runs-on: ubuntu-24.04
88
name: Check Style
99
steps:
1010
- name: Checkout commit
@@ -121,9 +121,9 @@ jobs:
121121
memory_manager: "none"
122122
}
123123
- {
124-
name: "Ubuntu 22.04 GCC Python",
125-
os: ubuntu-22.04,
126-
cudaos: 'ubuntu2204',
124+
name: "Ubuntu 24.04 GCC Python",
125+
os: ubuntu-24.04,
126+
cudaos: 'ubuntu2404',
127127
cc: "gcc", cxx: "g++", fc: "gfortran",
128128
python: "true",
129129
backend: "none",
@@ -143,9 +143,9 @@ jobs:
143143
memory_manager: "none"
144144
}
145145
- {
146-
name: "Ubuntu 22.04 GCC OMP",
147-
os: ubuntu-22.04,
148-
cudaos: 'ubuntu2204',
146+
name: "Ubuntu 24.04 GCC OMP",
147+
os: ubuntu-24.04,
148+
cudaos: 'ubuntu2404',
149149
cc: "gcc", cxx: "g++", fc: "gfortran",
150150
python: "false",
151151
backend: "omp",
@@ -156,7 +156,7 @@ jobs:
156156
- {
157157
name: "Ubuntu 24.04 LLVM OASIS3-MCT Build",
158158
os: ubuntu-24.04,
159-
cudaos: 'ubuntu2204',
159+
cudaos: 'ubuntu2404',
160160
cc: "clang-18", cxx: "clang++-18", fc: "gfortran",
161161
python: "false",
162162
backend: "omp",
@@ -181,7 +181,7 @@ jobs:
181181
cc: "gcc", cxx: "g++", fc: "gfortran",
182182
python: "false",
183183
backend: "cuda",
184-
cudaos: 'ubuntu2204',
184+
cudaos: 'ubuntu2404',
185185
amps_layer: mpi1,
186186
netcdf: "false",
187187
memory_manager: "umpire"
@@ -203,7 +203,7 @@ jobs:
203203
cc: "gcc", cxx: "g++", fc: "gfortran",
204204
python: "false",
205205
backend: "kokkos",
206-
cudaos: 'ubuntu2204',
206+
cudaos: 'ubuntu2404',
207207
amps_layer: mpi1,
208208
netcdf: "false",
209209
memory_manager: "umpire"
@@ -217,15 +217,7 @@ jobs:
217217
sudo apt-get -qq update
218218
sudo apt-get -qq install curl cmake build-essential tcl-dev tk-dev gfortran hdf5-helpers libcurl4 libcurl4-gnutls-dev
219219
220-
- name: HDF5 and OpenMPI Install on Ubuntu 22.04
221-
if: matrix.config.os == 'ubuntu-22.04'
222-
run: |
223-
sudo apt-get -qq update
224-
sudo apt -qq install libhdf5-openmpi-103 libhdf5-openmpi-dev
225-
226-
# libhdf5-openmpi-103 has been renamed in Ubuntu 24.04.
227-
- name: HDF5 and OpenMPI Install on Ubuntu 24.04
228-
if: matrix.config.os == 'ubuntu-24.04'
220+
- name: HDF5 and OpenMPI Install
229221
run: |
230222
sudo apt-get -qq update
231223
sudo apt -qq install libhdf5-openmpi-103-1t64 libhdf5-openmpi-dev
@@ -305,27 +297,13 @@ jobs:
305297
fi
306298
echo "$HOME/depend/cmake-3.26.5-linux-x86_64/bin" >> $GITHUB_PATH
307299
308-
- name: NVidia Driver Install
300+
- name: NVidia compiler and CUDA toolkit Install
309301
if: matrix.config.backend == 'cuda' || matrix.config.backend == 'kokkos'
310-
run: |
311-
sudo add-apt-repository -y ppa:graphics-drivers
312-
sudo apt-get update -qq
313-
sudo apt-get install -y nvidia-driver-535
314-
315-
- name: CUDA Install
316-
if: matrix.config.backend == 'cuda' || matrix.config.backend == 'kokkos'
317-
run: |
318-
export CUDA_VERSION_MAJOR_MINOR=12.4.0
319-
export CUDA_SHORT=12.4
320-
export CUDA_OS=${{ matrix.config.cudaos }}
321-
./bin/install-cuda.sh
322-
export CUDA_HOME=/usr/local/cuda-${CUDA_SHORT}
323-
echo "CUDA_HOME=${CUDA_HOME}" >> $GITHUB_ENV
324-
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
325-
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
326-
export LIBRARY_PATH=${CUDA_HOME}/lib64/stubs
327-
echo "LIBRARY_PATH=${LIBRARY_PATH}" >> $GITHUB_ENV
328-
echo "${CUDA_HOME}/bin" >> $GITHUB_PATH
302+
uses: awalsh128/cache-apt-pkgs-action@latest
303+
with:
304+
packages: nvidia-cuda-toolkit nvidia-cuda-dev
305+
version: 1.0
306+
execute_install_scripts: true
329307

330308
- name: UCX
331309
if: matrix.config.backend == 'cuda' || matrix.config.backend == 'kokkos'
@@ -366,11 +344,12 @@ jobs:
366344
if [[ "$CACHE_HIT" != 'true' ]]; then
367345
git clone --recursive https://github.com/LLNL/Umpire.git
368346
cd Umpire
369-
mkdir build
370-
cd build
371-
cmake ../ -DCMAKE_INSTALL_PREFIX=$PARFLOW_DEP_DIR/Umpire -DENABLE_CUDA=On
372-
make
373-
make install
347+
cmake -S . -B bld \
348+
-DCMAKE_CXX_COMPILER=mpicxx \
349+
-DCMAKE_INSTALL_PREFIX="${PARFLOW_DEP_DIR}/Umpire" \
350+
-DENABLE_CUDA="ON"
351+
cmake --build bld --parallel 4
352+
cmake --install bld
374353
fi
375354
echo "UMPIRE_FLAGS=-Dumpire_ROOT=$PARFLOW_DEP_DIR/Umpire" >> $GITHUB_ENV
376355
@@ -469,13 +448,27 @@ jobs:
469448
CACHE_HIT: ${{steps.cache-parflow-dependencies.outputs.cache-hit}}
470449
run: |
471450
if [[ "$CACHE_HIT" != 'true' ]]; then
472-
URL=https://github.com/hypre-space/hypre/archive/v2.26.0.tar.gz
473-
mkdir hypre
474-
cd hypre
475-
curl -L $URL | tar --strip-components=1 -xz
476-
cd src
477-
./configure --prefix=$PARFLOW_DEP_DIR
478-
make -j 2 install
451+
# Download
452+
wget https://github.com/hypre-space/hypre/archive/v2.33.0.tar.gz
453+
tar xf v2.33.0.tar.gz && cd hypre-2.33.0
454+
455+
# Set Hypre accelerator backend
456+
if [[ "${{ matrix.config.backend }}" == "cuda" ]]; then
457+
BACKEND="CUDA" # GPU
458+
else
459+
BACKEND="OPENMP" # CPU
460+
fi
461+
462+
# Install Hypre. See https://hypre.readthedocs.io/en/latest/ch-misc.html#build-system-options
463+
cmake -S src -B bld \
464+
-DCMAKE_C_COMPILER=mpicc \
465+
-DCMAKE_CXX_COMPILER=mpicxx \
466+
-DCMAKE_INSTALL_PREFIX="${PARFLOW_DEP_DIR}" \
467+
-DHYPRE_ENABLE_MPI="ON" \
468+
-DHYPRE_ENABLE_${BACKEND}="ON"
469+
cmake --build bld --parallel 4
470+
cmake --install bld
471+
echo "" && echo "Successfully built Hypre-${BACKEND}"
479472
fi
480473
481474
- name: ParFlow CMake Configure

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,30 @@ if ( ${PARFLOW_AMPS_LAYER} IN_LIST PARFLOW_AMPS_LAYER_REQUIRE_MPI )
225225
set(PARFLOW_HAVE_MPI "yes")
226226
set(HAVE_MPI ${PARFLOW_HAVE_MPI})
227227
message(STATUS "Found MPIEXEC: ${MPIEXEC}")
228+
229+
# Need to pass MPI include header to nvcc to avoid missing <mpi.h> error at amps.h.
230+
if (${PARFLOW_HAVE_CUDA})
231+
if (MPI_C_INCLUDE_DIRS)
232+
# Construct the compiler string for the include directories.
233+
foreach(dir ${MPI_C_INCLUDE_DIRS})
234+
string(APPEND CUDA_MPI_INCLUDES "-I${dir} ")
235+
endforeach()
236+
else()
237+
# Guess MPI include dir from MPI_HOME (if it exists)
238+
# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindMPI.cmake?ref_type=heads#L120
239+
if(DEFINED CACHE{MPI_HOME})
240+
set(CUDA_MPI_INCLUDES -I${MPI_HOME}/include)
241+
elseif(DEFINED ENV{MPI_HOME})
242+
set(CUDA_MPI_INCLUDES -I$ENV{MPI_HOME}/include)
243+
endif()
244+
endif()
245+
246+
if(CUDA_MPI_INCLUDES)
247+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_MPI_INCLUDES}")
248+
else()
249+
message(WARNING "MPI include dir not found. This might cause compile problems when building CUDA sources with MPI headers.")
250+
endif()
251+
endif()
228252
endif (${MPI_C_FOUND})
229253

230254
endif ( ${PARFLOW_AMPS_LAYER} IN_LIST PARFLOW_AMPS_LAYER_REQUIRE_MPI )

cmake/modules/FindHypre.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ if (Hypre_FOUND AND NOT TARGET Hypre::Hypre)
149149
list(APPEND _cuda_targets CUDA::cusparse)
150150
endif()
151151

152+
if(TARGET CUDA::cusolver_static)
153+
list(APPEND _cuda_targets CUDA::cusolver_static)
154+
elseif(TARGET CUDA::cusolver)
155+
list(APPEND _cuda_targets CUDA::cusolver)
156+
endif()
157+
152158
string(JOIN ", " _hypre_cuda_targets ${_cuda_targets})
153159
target_link_libraries(Hypre::Hypre INTERFACE ${_cuda_targets})
154160
message(STATUS "Found Hypre with CUDA backend. The ff. CUDA targets will be added to the linker options: ${_hypre_cuda_targets}")

0 commit comments

Comments
 (0)