Skip to content

Commit f79589b

Browse files
committed
Merge remote-tracking branch 'official/develop' into feature/no-gpu-direct-support
2 parents 3183d21 + 73255b0 commit f79589b

17 files changed

Lines changed: 280 additions & 58 deletions

.github/workflows/idefix-ci-doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Check out repo
19-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
19+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2020
with:
2121
persist-credentials: false
2222
- name: install doxygen

.github/workflows/idefix-ci-jobs.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
runs-on: self-hosted
2929
steps:
3030
- name: Check out repo
31-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
31+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3232
with:
3333
submodules: recursive
3434
persist-credentials: false
@@ -47,7 +47,7 @@ jobs:
4747
runs-on: self-hosted
4848
steps:
4949
- name: Check out repo
50-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
50+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
5151
with:
5252
submodules: recursive
5353
persist-credentials: false
@@ -64,7 +64,7 @@ jobs:
6464
runs-on: self-hosted
6565
steps:
6666
- name: Check out repo
67-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
67+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6868
with:
6969
submodules: recursive
7070
persist-credentials: false
@@ -87,7 +87,7 @@ jobs:
8787
runs-on: self-hosted
8888
steps:
8989
- name: Check out repo
90-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
90+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
9191
with:
9292
submodules: recursive
9393
persist-credentials: false
@@ -109,7 +109,7 @@ jobs:
109109
runs-on: self-hosted
110110
steps:
111111
- name: Check out repo
112-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
112+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
113113
with:
114114
submodules: recursive
115115
persist-credentials: false
@@ -125,7 +125,7 @@ jobs:
125125
runs-on: self-hosted
126126
steps:
127127
- name: Check out repo
128-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
128+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
129129
with:
130130
submodules: recursive
131131
persist-credentials: false
@@ -141,7 +141,7 @@ jobs:
141141
runs-on: self-hosted
142142
steps:
143143
- name: Check out repo
144-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
144+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
145145
with:
146146
submodules: recursive
147147
persist-credentials: false
@@ -163,7 +163,7 @@ jobs:
163163
runs-on: self-hosted
164164
steps:
165165
- name: Check out repo
166-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
166+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
167167
with:
168168
submodules: recursive
169169
persist-credentials: false
@@ -187,7 +187,7 @@ jobs:
187187
runs-on: self-hosted
188188
steps:
189189
- name: Check out repo
190-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
190+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
191191
with:
192192
submodules: recursive
193193
persist-credentials: false
@@ -203,7 +203,7 @@ jobs:
203203
runs-on: self-hosted
204204
steps:
205205
- name: Check out repo
206-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
206+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
207207
with:
208208
submodules: recursive
209209
persist-credentials: false
@@ -223,7 +223,7 @@ jobs:
223223
runs-on: self-hosted
224224
steps:
225225
- name: Check out repo
226-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
226+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
227227
with:
228228
submodules: recursive
229229
persist-credentials: false
@@ -237,7 +237,7 @@ jobs:
237237
runs-on: self-hosted
238238
steps:
239239
- name: Check out repo
240-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
240+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
241241
with:
242242
submodules: recursive
243243
persist-credentials: false
@@ -255,7 +255,7 @@ jobs:
255255
runs-on: self-hosted
256256
steps:
257257
- name: Check out repo
258-
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
258+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
259259
with:
260260
submodules: recursive
261261
persist-credentials: false

.github/workflows/idefix-ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
if: ${{ github.repository == 'idefix-code/idefix' || github.repository == 'glesur/idefix' }}
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
20+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2121
with:
2222
persist-credentials: false
23-
- uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1
23+
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
2424
with:
2525
python-version: 3.x
26-
- uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # v3.0.0
27-
- uses: pre-commit-ci/lite-action@50143aaf27e2c42e75a5e06185a471d9582e89df # v1.0.0
26+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
27+
- uses: pre-commit-ci/lite-action@5d6cc0eb514c891a40562a58a8e71576c5c7fb43 # v1.1.0
2828
if: always()
2929

3030
icc-jobs:

CMakeLists.txt

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ option(Idefix_PYTHON "Enable python bindings (requires pybind11)" OFF)
1919
option(Idefix_MPI_GPU_DIRECT "Enable usage of GPU direct to avoid CPU-GPU copies for MPI messages." ON)
2020
option(Idefix_MPI_GPU_FORCE_COPY "When GPU_DIRECT is disabled, force using transfers for validation purpose." OFF)
2121
mark_as_advanced(Idefix_MPI_GPU_FORCE_TRANSFERS)
22+
option(Idefix_SUPPRESS_FMA "Disable FMA (fused multiply-add) contraction/codegen. Useful for code validation across architectures." OFF)
2223
set(Idefix_PROBLEM_DIR "${CMAKE_BINARY_DIR}" CACHE STRING "Problem directory to build for.")
2324
set(Idefix_CXX_FLAGS "" CACHE STRING "Additional compiler/linker flag")
2425
set(Idefix_DEFS "definitions.hpp" CACHE FILEPATH "Problem definition header file")
@@ -49,6 +50,8 @@ include(ReplaceIdefixSource)
4950
include(AddIdefixSource)
5051
include(SetIdefixProperty)
5152
include(SetRequiredBuildSettingsForGCC8)
53+
include(CheckHdf5ParallelSupport)
54+
include(SuppressFMA)
5255

5356
#Idefix requires Cuda Lambdas (experimental)
5457
if(Kokkos_ENABLE_CUDA)
@@ -64,6 +67,8 @@ include_directories(${Kokkos_INCLUDE_DIRS_RET})
6467
# Add Idefix CXX Flags
6568
add_compile_options(${Idefix_CXX_FLAGS})
6669

70+
71+
6772
# Add filesystem libraries for GCC8
6873
set_required_build_settings_for_GCC8()
6974

@@ -124,12 +129,25 @@ if(Idefix_HDF5)
124129
PUBLIC src/output/xdmf.cpp
125130
PUBLIC src/output/xdmf.hpp
126131
)
127-
find_package(HDF5 REQUIRED)
128-
target_link_libraries(idefix "${HDF5_LIBRARIES}")
132+
# Prefer imported targets (matches older working behavior), then fall back.
133+
find_package(HDF5 QUIET COMPONENTS C)
134+
if(NOT HDF5_FOUND)
135+
find_package(HDF5 REQUIRED MODULE COMPONENTS C)
136+
endif()
137+
138+
set(_idefix_hdf5_link_items "${HDF5_LIBRARIES}")
139+
if(TARGET hdf5::hdf5)
140+
set(_idefix_hdf5_link_items hdf5::hdf5)
141+
elseif(TARGET HDF5::HDF5)
142+
set(_idefix_hdf5_link_items HDF5::HDF5)
143+
endif()
144+
145+
target_link_libraries(idefix ${_idefix_hdf5_link_items})
129146
message(STATUS "Found HDF5 include directories: ${HDF5_INCLUDE_DIRS}")
130147
target_include_directories(idefix PUBLIC "${HDF5_INCLUDE_DIRS}")
131148
if(Idefix_MPI)
132-
if(NOT HDF5_IS_PARALLEL)
149+
CheckHdf5ParallelSupport("${_idefix_hdf5_link_items}")
150+
if(NOT IDEFIX_HDF5_IS_PARALLEL)
133151
message(FATAL_ERROR "Parallel HDF5 required for Idefix_MPI but the found HDF5 library does not support it")
134152
endif()
135153
endif()
@@ -178,15 +196,15 @@ endif()
178196
if(Idefix_EVOLVE_VECTOR_POTENTIAL)
179197
add_compile_definitions("EVOLVE_VECTOR_POTENTIAL")
180198
endif()
181-
#update version.hpp if possible
199+
200+
# determine idefix version from git
182201
git_describe(GIT_SHA1)
183202
set(Idefix_VERSION ${Idefix_VERSION_MAJOR}.${Idefix_VERSION_MINOR}.${Idefix_VERSION_PATCH}-${GIT_SHA1})
184-
file(WRITE ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_GIT_COMMIT \"${GIT_SHA1}\"\n")
185-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION_MAJOR \"${Idefix_VERSION_MAJOR}\"\n")
186-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION_MINOR \"${Idefix_VERSION_MINOR}\"\n")
187-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION_PATCH \"${Idefix_VERSION_PATCH}\"\n")
188-
file(APPEND ${CMAKE_SOURCE_DIR}/src/version.hpp "#define IDEFIX_VERSION \"${Idefix_VERSION}\"\n")
189-
203+
configure_file(
204+
${CMAKE_SOURCE_DIR}/src/version.h.in
205+
${CMAKE_BINARY_DIR}/build/generated/version.h
206+
@ONLY
207+
)
190208

191209
if(NOT ${Idefix_DEFS} STREQUAL "definitions.hpp")
192210
add_compile_definitions("DEFINITIONS_FILE=\"${Idefix_DEFS}\"")
@@ -280,6 +298,21 @@ target_include_directories(idefix PUBLIC
280298

281299
target_link_libraries(idefix Kokkos::kokkos)
282300

301+
# Generate header with compiler information (name, flags, path)
302+
configure_file(
303+
${CMAKE_SOURCE_DIR}/src/compiler_info.h.in
304+
${CMAKE_BINARY_DIR}/build/generated/compiler_info.h
305+
@ONLY
306+
)
307+
# Make sure the generated header is on the include path
308+
target_include_directories(idefix PRIVATE ${CMAKE_BINARY_DIR}/build/generated)
309+
310+
# disable FMA if needed
311+
if(Idefix_SUPPRESS_FMA)
312+
message(STATUS "FMA (fused multiply-add) contraction/codegen is disabled")
313+
target_suppress_fma(idefix)
314+
endif()
315+
283316
message(STATUS "Idefix final configuration")
284317
if(Idefix_EVOLVE_VECTOR_POTENTIAL)
285318
message(STATUS " MHD: ${Idefix_MHD} (Vector potential)")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
include(CheckCSourceCompiles)
2+
3+
# Check whether the HDF5 library found by find_package(HDF5) supports parallel
4+
# (MPI-IO) access, and store the result in IDEFIX_HDF5_IS_PARALLEL in the
5+
# caller's scope.
6+
#
7+
# Usage: CheckHdf5ParallelSupport(<hdf5_link_items>)
8+
# where <hdf5_link_items> is the list of HDF5 targets/libraries to link against.
9+
#
10+
# Some CMake/HDF5 combinations do not reliably set HDF5_IS_PARALLEL (e.g. when
11+
# HDF5 is found via its CMake config package rather than the FindHDF5 module).
12+
# Combine metadata checks with a compile+link probe for the MPI-IO symbols to
13+
# reliably detect parallel HDF5.
14+
function(CheckHdf5ParallelSupport hdf5_link_items)
15+
set(_idefix_hdf5_is_parallel FALSE)
16+
if(HDF5_IS_PARALLEL OR HDF5_C_IS_PARALLEL)
17+
set(_idefix_hdf5_is_parallel TRUE)
18+
endif()
19+
20+
if(NOT _idefix_hdf5_is_parallel AND DEFINED HDF5_C_COMPILER_EXECUTABLE)
21+
execute_process(
22+
COMMAND "${HDF5_C_COMPILER_EXECUTABLE}" -showconfig
23+
OUTPUT_VARIABLE _idefix_hdf5_showconfig
24+
ERROR_QUIET
25+
)
26+
if(_idefix_hdf5_showconfig MATCHES "Parallel HDF5:[ \t]*yes")
27+
set(_idefix_hdf5_is_parallel TRUE)
28+
endif()
29+
endif()
30+
31+
set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS} ${MPI_C_INCLUDE_DIRS})
32+
set(CMAKE_REQUIRED_LIBRARIES ${hdf5_link_items} MPI::MPI_C)
33+
check_c_source_compiles(
34+
"#include <mpi.h>
35+
#include <hdf5.h>
36+
int main(void) {
37+
hid_t plist = H5Pcreate(H5P_FILE_ACCESS);
38+
H5Pset_fapl_mpio(plist, MPI_COMM_WORLD, MPI_INFO_NULL);
39+
H5Pclose(plist);
40+
return 0;
41+
}"
42+
IDEFIX_HDF5_HAS_MPI_IO
43+
)
44+
45+
if(IDEFIX_HDF5_HAS_MPI_IO)
46+
set(_idefix_hdf5_is_parallel TRUE)
47+
endif()
48+
49+
set(IDEFIX_HDF5_IS_PARALLEL ${_idefix_hdf5_is_parallel} PARENT_SCOPE)
50+
endfunction()

cmake/SuppressFMA.cmake

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#[[============================================================================
2+
SuppressFMA.cmake
3+
4+
Provides an option and a function to optionally disable fused
5+
multiply-add (FMA) code generation / contraction for a Kokkos-based CXX
6+
target.
7+
8+
Kokkos wraps the real device compiler behind nvcc_wrapper (CUDA) or
9+
hipcc (HIP), which makes CMAKE_CXX_COMPILER_ID report the *underlying
10+
host* compiler (e.g. "GNU" or "Clang") instead of "NVIDIA" or "Clang
11+
as HIP". Backend detection therefore relies on the Kokkos_ENABLE_*
12+
variables exported by KokkosConfig.cmake / set by the Kokkos build,
13+
and only falls back to CMAKE_CXX_COMPILER_ID for the plain host
14+
compilers (no CUDA/HIP backend active):
15+
16+
- Kokkos_ENABLE_HIP ON -> AMD HIP (hipcc, clang-based) : -ffp-contract=off
17+
- Kokkos_ENABLE_CUDA ON -> NVIDIA nvcc (via nvcc_wrapper) : --fmad=false
18+
- otherwise, CMAKE_CXX_COMPILER_ID selects among:
19+
GNU : gcc/g++
20+
Intel : classic icc/icpc
21+
IntelLLVM : Intel oneAPI icx/icpx
22+
Clang : LLVM clang++
23+
AppleClang : Xcode clang++
24+
NVHPC : NVIDIA HPC SDK (nvc++), e.g. for OpenMPTarget/OpenACC
25+
26+
Usage (after find_package(Kokkos) so Kokkos_ENABLE_* are defined):
27+
include(SuppressFMA.cmake)
28+
add_library(mylib source.cpp)
29+
target_link_libraries(mylib PUBLIC Kokkos::kokkos)
30+
target_suppress_fma(mylib)
31+
32+
============================================================================]]
33+
34+
include_guard(GLOBAL)
35+
36+
# Determine the CXX FMA-suppression flags for the active Kokkos backend /
37+
# CXX compiler. Returns the list of flags (possibly empty) via out_var.
38+
function(_fma_suppression_flags_cxx out_var)
39+
set(flags "")
40+
set(id "${CMAKE_CXX_COMPILER_ID}")
41+
42+
# Kokkos backend takes priority: nvcc_wrapper/hipcc hide the real
43+
# device compiler from CMAKE_CXX_COMPILER_ID.
44+
if(Kokkos_ENABLE_HIP)
45+
set(flags "-ffp-contract=off")
46+
47+
elseif(Kokkos_ENABLE_CUDA)
48+
set(flags "--fmad=false")
49+
50+
elseif(id STREQUAL "GNU")
51+
include(CheckCXXCompilerFlag)
52+
check_cxx_compiler_flag("-mno-fma" IDEFIX_HAS_MNO_FMA)
53+
set(flags "-ffp-contract=off")
54+
if(IDEFIX_HAS_MNO_FMA)
55+
list(APPEND flags "-mno-fma")
56+
endif()
57+
elseif(id MATCHES "^(Clang|AppleClang|CrayClang)$")
58+
set(flags "-ffp-contract=off")
59+
60+
elseif(id STREQUAL "Intel")
61+
# Intel classic compiler
62+
set(flags "-fp-model=precise" "-no-fma")
63+
64+
elseif(id STREQUAL "IntelLLVM")
65+
# Intel oneAPI compiler (clang-based)
66+
set(flags "-ffp-contract=off" "-fp-model=strict")
67+
68+
elseif(id STREQUAL "NVHPC")
69+
# NVIDIA HPC SDK (formerly PGI), e.g. OpenMPTarget/OpenACC backend
70+
set(flags "-Mnofma") # untested
71+
endif()
72+
73+
set(${out_var} "${flags}" PARENT_SCOPE)
74+
endfunction()
75+
76+
# target_suppress_fma(<target>)
77+
#
78+
# Applies compiler-specific FMA-suppression flags to <target>'s CXX
79+
# sources, but only when the SUPPRESS_FMA option is ON. Safe to call
80+
# unconditionally.
81+
function(target_suppress_fma target)
82+
83+
if(NOT TARGET ${target})
84+
message(FATAL_ERROR "target_suppress_fma: '${target}' is not a target")
85+
endif()
86+
87+
_fma_suppression_flags_cxx(cxx_flags)
88+
89+
if(cxx_flags)
90+
foreach(flag IN LISTS cxx_flags)
91+
target_compile_options(${target} PRIVATE
92+
$<$<COMPILE_LANGUAGE:CXX>:${flag}>
93+
)
94+
endforeach()
95+
else()
96+
message(VERBOSE
97+
"target_suppress_fma: no FMA-suppression flag known for "
98+
"CXX compiler '${CMAKE_CXX_COMPILER_ID}' "
99+
"(Kokkos_ENABLE_CUDA=${Kokkos_ENABLE_CUDA}, "
100+
"Kokkos_ENABLE_HIP=${Kokkos_ENABLE_HIP}) (target ${target})")
101+
endif()
102+
endfunction()

0 commit comments

Comments
 (0)