Skip to content

Commit dd9943d

Browse files
committed
Fix builds and disable builds that don't currently work
We have a CUB (ForEachInExtents) version, but it hasn't been tested yet, because HPC SDK 25.1 doesn't have a new enough CUB version yet.
1 parent c9ac577 commit dd9943d

11 files changed

+852
-195
lines changed

cpp-mdspan/CMakeLists.txt

+86-22
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,49 @@ else()
6363
message(STATUS "OpenACC not found")
6464
endif()
6565

66-
6766
# Find CUDA Toolkit; it's not required,
6867
# but other things (like CUB) depend on it.
6968
find_package(CUDAToolkit)
7069

70+
set(MINIWEATHER_CUB_FOUND FALSE)
71+
72+
if (CUDAToolkit_FOUND AND (NOT (DEFINED CUB_INCLUDE_DIR)))
73+
# Check whether CUDA Toolkit's include directory has CUB in it.
74+
find_path(CUB_INCLUDE_DIR
75+
NAMES cub/cub.cuh
76+
PATHS
77+
${CUDAToolkit_INCLUDE_DIRS}
78+
/usr/include
79+
/usr/local/include
80+
DOC "Path to CUB include directory."
81+
)
82+
message(STATUS "Discovered CUB_INCLUDE_DIR: ${CUB_INCLUDE_DIR}")
83+
if (CUDAToolkit_VERSION VERSION_LESS "12.8.0")
84+
message(STATUS "CUDAToolkit_VERSION 12.6.85 is known to lack ForEachInExtents. \
85+
Your CUDAToolkit_VERSION is ${CUDAToolkit_VERSION}.")
86+
endif()
87+
endif()
88+
7189
if (DEFINED CUB_INCLUDE_DIR)
72-
if (EXISTS "${CUB_INCLUDE_DIR}/cub/cub.cuh")
73-
message(STATUS "User-defined CUB_INCLUDE_DIR: ${CUB_INCLUDE_DIR}")
90+
set(CUB_TEST_FILE_0 "${CUB_INCLUDE_DIR}/cub/cub.cuh")
91+
set(CUB_TEST_FILE_0_FOUND FALSE)
92+
# This was added to later versions of CUB.
93+
set(CUB_TEST_FILE_1 "${CUB_INCLUDE_DIR}/cub/device/device_for_each.cuh")
94+
set(CUB_TEST_FILE_1_FOUND FALSE)
95+
96+
if (EXISTS "${CUB_TEST_FILE_0}")
97+
message(STATUS "User-defined CUB_INCLUDE_DIR ${CUB_INCLUDE_DIR} contains cub/cub.cuh")
7498
else()
75-
message(FATAL_ERROR "CUB_INCLUDE_DIR=\"{CUB_INCLUDE_DIR}\" is \
76-
defined but \"${CUB_INCLUDE_DIR}/cub/cub.cuh\" does not exist.")
99+
message(STATUS "User-defined CUB_INCLUDE_DIR ${CUB_INCLUDE_DIR} does NOT contain cub/cub.cuh")
77100
endif()
78-
else()
79-
if (CUDAToolkit_FOUND)
80-
# Check whether CUDA Toolkit's include directory has CUB in it.
81-
find_path(CUB_INCLUDE_DIR
82-
NAMES cub/cub.cuh
83-
PATHS
84-
${CUDAToolkit_INCLUDE_DIRS}
85-
/usr/include
86-
/usr/local/include
87-
DOC "Path to CUB include directory."
88-
)
89-
message(STATUS "Discovered CUB_INCLUDE_DIR: ${CUB_INCLUDE_DIR}")
90-
if (CUDAToolkit_VERSION VERSION_LESS "12.8.0")
91-
message(STATUS "CUDAToolkit_VERSION 12.6.85 is known to lack ForEachInExtents. \
92-
Your CUDAToolkit_VERSION is ${CUDAToolkit_VERSION}.")
93-
endif()
101+
102+
if (EXISTS "${CUB_TEST_FILE_1}")
103+
message(STATUS "User-defined CUB_INCLUDE_DIR ${CUB_INCLUDE_DIR} contains cub/device/device_for_each.cuh")
104+
else()
105+
message(STATUS "User-defined CUB_INCLUDE_DIR ${CUB_INCLUDE_DIR} does NOT contain cub/device/device_for_each.cuh")
94106
endif()
107+
108+
set(MINIWEATHER_CUB_FOUND (${CUB_TEST_FILE_0_FOUND} AND ${CUB_TEST_FILE_1_FOUND}))
95109
endif()
96110

97111
# Please see Kokkos' CMake instructions:
@@ -161,8 +175,10 @@ target_compile_options(test_unique_mdarray PRIVATE
161175
/W4>
162176
)
163177

178+
message(STATUS "Enabled miniWeather_serial")
164179
add_executable(miniWeather_serial miniWeather_mdspan.cpp miniWeather_common.cpp)
165180
target_include_directories(miniWeather_serial PRIVATE "${PROJECT_SOURCE_DIR}")
181+
target_compile_definitions(miniWeather_serial PRIVATE MINIWEATHER_SERIAL)
166182

167183
# If building with Kokkos, we've already added the mdspan headers
168184
# to the include path (see above).
@@ -177,6 +193,7 @@ target_compile_options(miniWeather_serial PRIVATE
177193
)
178194

179195
if (kokkos_POPULATED)
196+
message(STATUS "Enabled miniWeather_kokkos_serial")
180197
add_executable(miniWeather_kokkos_serial miniWeather_mdspan.cpp miniWeather_common.cpp)
181198
target_include_directories(miniWeather_kokkos_serial PRIVATE "${PROJECT_SOURCE_DIR}")
182199

@@ -196,6 +213,7 @@ endif()
196213
if (kokkos_POPULATED AND OpenACC_FOUND)
197214
set(Kokkos_ENABLE_OPENACC ON)
198215

216+
message(STATUS "Enabled miniWeather_kokkos_openacc")
199217
add_executable(miniWeather_kokkos_openacc miniWeather_mdspan.cpp miniWeather_common.cpp)
200218
target_include_directories(miniWeather_kokkos_openacc PRIVATE "${PROJECT_SOURCE_DIR}")
201219

@@ -213,9 +231,13 @@ if (kokkos_POPULATED AND OpenACC_FOUND)
213231
)
214232
endif()
215233

234+
# We don't have a "pure OpenACC" version yet.
235+
if (FALSE)
216236
if (OpenACC_FOUND)
237+
message(STATUS "Enabled miniWeather_openacc")
217238
add_executable(miniWeather_openacc miniWeather_mdspan.cpp miniWeather_common.cpp)
218239
target_include_directories(miniWeather_openacc PRIVATE "${PROJECT_SOURCE_DIR}")
240+
target_compile_definitions(miniWeather_openacc PRIVATE MINIWEATHER_OPENACC)
219241

220242
# If building with Kokkos, we've already added the mdspan headers
221243
# to the include path (see above).
@@ -230,13 +252,18 @@ if (OpenACC_FOUND)
230252
/W4>
231253
)
232254
endif()
255+
endif()
233256

257+
set(MINIWEATHER_HAVE_STDPAR (${CMAKE_CXX_STANDARD} GREATER_EQUAL 23))
234258
# Option to enable stdpar
235-
set(MINIWEATHER_ENABLE_STDPAR DETECT CACHE STRING "Enable stdpar using the -stdpar flag")
259+
set(MINIWEATHER_ENABLE_STDPAR ${MINIWEATHER_HAVE_STDPAR} CACHE BOOL "Enable stdpar using the -stdpar flag")
236260

237261
if (MINIWEATHER_ENABLE_STDPAR)
262+
message(STATUS "Enabled miniWeather_stdpar_cpu")
238263
add_executable(miniWeather_stdpar_cpu miniWeather_mdspan.cpp miniWeather_common.cpp)
239264
target_include_directories(miniWeather_stdpar_cpu PRIVATE "${PROJECT_SOURCE_DIR}")
265+
target_compile_definitions(miniWeather_stdpar_cpu PRIVATE MINIWEATHER_STDPAR)
266+
target_compile_definitions(miniWeather_stdpar_cpu PRIVATE MINIWEATHER_STDPAR_CPU)
240267

241268
# If building with Kokkos, we've already added the mdspan headers
242269
# to the include path (see above).
@@ -254,8 +281,11 @@ if (MINIWEATHER_ENABLE_STDPAR)
254281
endif()
255282

256283
if (MINIWEATHER_ENABLE_STDPAR)
284+
message(STATUS "Enabled miniWeather_stdpar_gpu")
257285
add_executable(miniWeather_stdpar_gpu miniWeather_mdspan.cpp miniWeather_common.cpp)
258286
target_include_directories(miniWeather_stdpar_gpu PRIVATE "${PROJECT_SOURCE_DIR}")
287+
target_compile_definitions(miniWeather_stdpar_gpu PRIVATE MINIWEATHER_STDPAR)
288+
target_compile_definitions(miniWeather_stdpar_gpu PRIVATE MINIWEATHER_STDPAR_GPU)
259289

260290
# If building with Kokkos, we've already added the mdspan headers
261291
# to the include path (see above).
@@ -273,8 +303,11 @@ if (MINIWEATHER_ENABLE_STDPAR)
273303
endif()
274304

275305
if (MINIWEATHER_ENABLE_STDPAR AND OpenACC_FOUND)
306+
message(STATUS "Enabled miniWeather_stdpar_openacc")
276307
add_executable(miniWeather_stdpar_openacc miniWeather_mdspan.cpp miniWeather_common.cpp)
277308
target_include_directories(miniWeather_stdpar_openacc PRIVATE "${PROJECT_SOURCE_DIR}")
309+
target_compile_definitions(miniWeather_stdpar_openacc PRIVATE MINIWEATHER_STDPAR)
310+
target_compile_definitions(miniWeather_stdpar_openacc PRIVATE MINIWEATHER_STDPAR_OPENACC)
278311

279312
# If building with Kokkos, we've already added the mdspan headers
280313
# to the include path (see above).
@@ -291,3 +324,34 @@ if (MINIWEATHER_ENABLE_STDPAR AND OpenACC_FOUND)
291324
target_compile_options(miniWeather_stdpar_openacc PRIVATE "-stdpar=gpu:acc")
292325
target_link_options(miniWeather_stdpar_openacc PRIVATE "-stdpar=gpu:acc")
293326
endif()
327+
328+
# Option to enable CUB
329+
set(MINIWEATHER_ENABLE_CUB ${MINIWEATHER_CUB_FOUND} CACHE BOOL "Enable CUB")
330+
331+
if (MINIWEATHER_ENABLE_CUB)
332+
message(STATUS "Enabled miniWeather_cub")
333+
add_executable(miniWeather_cub miniWeather_mdspan.cpp miniWeather_common.cpp)
334+
target_include_directories(miniWeather_cub PRIVATE "${PROJECT_SOURCE_DIR}")
335+
target_compile_definitions(miniWeather_cub PRIVATE MINIWEATHER_CUB)
336+
337+
# If building with Kokkos, we've already added the mdspan headers
338+
# to the include path (see above).
339+
if (NOT kokkos_POPULATED)
340+
target_link_libraries(miniWeather_cub PRIVATE std::mdspan)
341+
endif()
342+
target_compile_options(miniWeather_cub PRIVATE
343+
$<$<OR:$<CXX_COMPILER_ID:NVHPC>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
344+
-Wall>
345+
$<$<CXX_COMPILER_ID:MSVC>:
346+
/W4>
347+
)
348+
# Building CUB with nvc++ requires the "-cuda" flag
349+
target_compile_options(miniWeather_cub PRIVATE
350+
$<$<OR:$<CXX_COMPILER_ID:NVHPC>>:
351+
-cuda>
352+
)
353+
target_link_options(miniWeather_cub PRIVATE
354+
$<$<OR:$<CXX_COMPILER_ID:NVHPC>>:
355+
-cuda>
356+
)
357+
endif()

cpp-mdspan/build/cmake-kermit.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ SRC_ROOT=/raid/mhoemmen/src/miniWeather/cpp-mdspan
1111
# "-stdpar": "Could not find librt library, needed by CUDA::cudart_static"
1212
# Adding "-rt" to LDFLAGS didn't seem to help.
1313

14+
# Current version of stdpar code requires C++23,
15+
# because it uses std::ranges::views::cartesian_product.
16+
# nvc++ might not support that yet.
17+
MINIWEATHER_ENABLE_STDPAR=OFF
18+
19+
# We don't have ForEachInExtents yet with 25.1.
20+
MINIWEATHER_ENABLE_CUB=OFF
21+
1422
KOKKOS_ROOT="/raid/mhoemmen/src/kokkos/kokkos"
1523
# -DFETCHCONTENT_SOURCE_DIR_Kokkos="${KOKKOS_ROOT}"
1624
# -DKokkos_ROOT="${KOKKOS_ROOT}"
@@ -21,7 +29,8 @@ LDFLAGS="${PNETCDF_LDFLAGS}" CXXFLAGS="${PNETCDF_CXXFLAGS}" cmake \
2129
-DCMAKE_Fortran_COMPILER=mpif90 \
2230
-DCMAKE_VERBOSE_MAKEFILE=ON \
2331
-DFETCHCONTENT_SOURCE_DIR_KOKKOS="${KOKKOS_ROOT}" \
24-
-DMINIWEATHER_ENABLE_STDPAR=ON \
32+
-DMINIWEATHER_ENABLE_STDPAR=${MINIWEATHER_ENABLE_STDPAR} \
33+
-DMINIWEATHER_ENABLE_CUB=${MINIWEATHER_ENABLE_CUB} \
2534
${SRC_ROOT}
2635

2736
# -DCMAKE_CXX_FLAGS="-stdpar"

cpp-mdspan/miniWeather_common.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include "miniWeather_common.hpp"
22

33
std::unique_ptr<double[]>
4-
make_unique_array_3d(host_memory_space, int X, int Y, int Z) {
4+
make_unique_array_3d(host_serial_execution_policy, host_memory_space, int X, int Y, int Z) {
55
return std::make_unique<double[]>(X * Y * Z);
66
}
77

88
std::unique_ptr<double[]>
9-
make_unique_array_1d(host_memory_space, int X) {
9+
make_unique_array_1d(host_serial_execution_policy, host_memory_space, int X) {
1010
return std::make_unique<double[]>(X);
1111
}
1212

0 commit comments

Comments
 (0)