@@ -63,35 +63,49 @@ else()
63
63
message (STATUS "OpenACC not found" )
64
64
endif ()
65
65
66
-
67
66
# Find CUDA Toolkit; it's not required,
68
67
# but other things (like CUB) depend on it.
69
68
find_package (CUDAToolkit)
70
69
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
+
71
89
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" )
74
98
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" )
77
100
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" )
94
106
endif ()
107
+
108
+ set (MINIWEATHER_CUB_FOUND (${CUB_TEST_FILE_0_FOUND} AND ${CUB_TEST_FILE_1_FOUND} ))
95
109
endif ()
96
110
97
111
# Please see Kokkos' CMake instructions:
@@ -161,8 +175,10 @@ target_compile_options(test_unique_mdarray PRIVATE
161
175
/W4>
162
176
)
163
177
178
+ message (STATUS "Enabled miniWeather_serial" )
164
179
add_executable (miniWeather_serial miniWeather_mdspan.cpp miniWeather_common.cpp)
165
180
target_include_directories (miniWeather_serial PRIVATE "${PROJECT_SOURCE_DIR} " )
181
+ target_compile_definitions (miniWeather_serial PRIVATE MINIWEATHER_SERIAL)
166
182
167
183
# If building with Kokkos, we've already added the mdspan headers
168
184
# to the include path (see above).
@@ -177,6 +193,7 @@ target_compile_options(miniWeather_serial PRIVATE
177
193
)
178
194
179
195
if (kokkos_POPULATED)
196
+ message (STATUS "Enabled miniWeather_kokkos_serial" )
180
197
add_executable (miniWeather_kokkos_serial miniWeather_mdspan.cpp miniWeather_common.cpp)
181
198
target_include_directories (miniWeather_kokkos_serial PRIVATE "${PROJECT_SOURCE_DIR} " )
182
199
@@ -196,6 +213,7 @@ endif()
196
213
if (kokkos_POPULATED AND OpenACC_FOUND)
197
214
set (Kokkos_ENABLE_OPENACC ON )
198
215
216
+ message (STATUS "Enabled miniWeather_kokkos_openacc" )
199
217
add_executable (miniWeather_kokkos_openacc miniWeather_mdspan.cpp miniWeather_common.cpp)
200
218
target_include_directories (miniWeather_kokkos_openacc PRIVATE "${PROJECT_SOURCE_DIR} " )
201
219
@@ -213,9 +231,13 @@ if (kokkos_POPULATED AND OpenACC_FOUND)
213
231
)
214
232
endif ()
215
233
234
+ # We don't have a "pure OpenACC" version yet.
235
+ if (FALSE )
216
236
if (OpenACC_FOUND)
237
+ message (STATUS "Enabled miniWeather_openacc" )
217
238
add_executable (miniWeather_openacc miniWeather_mdspan.cpp miniWeather_common.cpp)
218
239
target_include_directories (miniWeather_openacc PRIVATE "${PROJECT_SOURCE_DIR} " )
240
+ target_compile_definitions (miniWeather_openacc PRIVATE MINIWEATHER_OPENACC)
219
241
220
242
# If building with Kokkos, we've already added the mdspan headers
221
243
# to the include path (see above).
@@ -230,13 +252,18 @@ if (OpenACC_FOUND)
230
252
/W4>
231
253
)
232
254
endif ()
255
+ endif ()
233
256
257
+ set (MINIWEATHER_HAVE_STDPAR (${CMAKE_CXX_STANDARD} GREATER_EQUAL 23))
234
258
# 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" )
236
260
237
261
if (MINIWEATHER_ENABLE_STDPAR)
262
+ message (STATUS "Enabled miniWeather_stdpar_cpu" )
238
263
add_executable (miniWeather_stdpar_cpu miniWeather_mdspan.cpp miniWeather_common.cpp)
239
264
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)
240
267
241
268
# If building with Kokkos, we've already added the mdspan headers
242
269
# to the include path (see above).
@@ -254,8 +281,11 @@ if (MINIWEATHER_ENABLE_STDPAR)
254
281
endif ()
255
282
256
283
if (MINIWEATHER_ENABLE_STDPAR)
284
+ message (STATUS "Enabled miniWeather_stdpar_gpu" )
257
285
add_executable (miniWeather_stdpar_gpu miniWeather_mdspan.cpp miniWeather_common.cpp)
258
286
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)
259
289
260
290
# If building with Kokkos, we've already added the mdspan headers
261
291
# to the include path (see above).
@@ -273,8 +303,11 @@ if (MINIWEATHER_ENABLE_STDPAR)
273
303
endif ()
274
304
275
305
if (MINIWEATHER_ENABLE_STDPAR AND OpenACC_FOUND)
306
+ message (STATUS "Enabled miniWeather_stdpar_openacc" )
276
307
add_executable (miniWeather_stdpar_openacc miniWeather_mdspan.cpp miniWeather_common.cpp)
277
308
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)
278
311
279
312
# If building with Kokkos, we've already added the mdspan headers
280
313
# to the include path (see above).
@@ -291,3 +324,34 @@ if (MINIWEATHER_ENABLE_STDPAR AND OpenACC_FOUND)
291
324
target_compile_options (miniWeather_stdpar_openacc PRIVATE "-stdpar=gpu:acc" )
292
325
target_link_options (miniWeather_stdpar_openacc PRIVATE "-stdpar=gpu:acc" )
293
326
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 ()
0 commit comments