HPCW 3.0
Loading...
Searching...
No Matches
cloudsc.cmake
Go to the documentation of this file.
1# Copyright (c) 2020 - 2025 David Guibert
2# Copyright (c) 2024 - 2025 Antoine Morvan
3# Copyright (c) 2024 - 2025 Niclas Schroeter
4# All rights reserved.
5#
6# SPDX-License-Identifier: Apache-2.0
7
8option(ENABLE_cloudsc_single_precision "Build CLOUDSC in single precision" OFF)
9set(cloudsc_block_size "" CACHE STRING "The block size argument for CLOUDSC")
10
11if(cloudsc_block_size STREQUAL "")
12 if(ENABLE_cloudsc_single_precision)
13 set(cloudsc_block_size "32")
14 else()
15 set(cloudsc_block_size "16")
16 endif()
17endif()
18
19option(ENABLE_cloudsc_gpu "Enable cloudsc gpu prototypes" OFF)
20cmake_dependent_option(ENABLE_cloudsc_acc "Enable cloudsc acc components" ON "ENABLE_cloudsc_gpu" OFF)
21option(ENABLE_cloudsc_omp "Enable cloudsc openMP components" ON)
22cmake_dependent_option(ENABLE_cloudsc_omp_gpu "Enable cloudsc openMP components (gpu)" ON "ENABLE_cloudsc_gpu" OFF)
23set(cloudsc_omp OFF)
24if(ENABLE_cloudsc_omp)
25 set(cloudsc_omp ON)
26endif()
27if(ENABLE_cloudsc_omp_gpu)
28 set(cloudsc_omp ON)
29endif()
30cmake_dependent_option(ENABLE_cloudsc_cuda "Enable cloudsc cuda components" ON "ENABLE_cloudsc_gpu" OFF)
31cmake_dependent_option(ENABLE_cloudsc_hip "Enable cloudsc hip components" ON "ENABLE_cloudsc_gpu" OFF)
32
33set_property(GLOBAL PROPERTY cloudsc_can_use_system TRUE)
34set_property(GLOBAL PROPERTY cloudsc_depends ecbuild hdf5)
35set_property(GLOBAL PROPERTY cloudsc_depends_optional mpi)
36if(ENABLE_cloudsc_gpu)
37 set_property(GLOBAL APPEND PROPERTY cloudsc_depends cuda)
38endif()
39
40set(cloudsc_cmake_args "" CACHE STRING "Custom CMake arguments for CloudSC")
41set(cloudsc_build_args "" CACHE STRING "Custom Make arguments for CloudSC")
42
43if(cloudsc_enabled)
44 if(USE_SYSTEM_cloudsc)
45
46 message(STATUS "cloudsc: enabled (system installed)")
47
48 function(find_cloudsc_program BIN)
49 find_program(CLOUDSC_EXE ${BIN} REQUIRED)
50 get_filename_component(CLOUDSC_EXE_DIR "${CLOUDSC_EXE}" DIRECTORY)
51 set_if_not_present(ENV{PATH} "$ENV{PATH}" "${CLOUDSC_EXE_DIR}")
52 endfunction()
53
54 find_cloudsc_program("dwarf-cloudsc-fortran")
55
56 if(ENABLE_cloudsc_acc)
57 find_cloudsc_program("dwarf-cloudsc-gpu-scc-k-caching")
58 endif()
59 if(ENABLE_cloudsc_omp_gpu)
60 find_cloudsc_program("dwarf-cloudsc-gpu-omp-scc-hoist")
61 endif()
62 if(ENABLE_cloudsc_cuda)
63 find_cloudsc_program("dwarf-cloudsc-c-cuda-k-caching")
64 endif()
65 if(ENABLE_cloudsc_hip)
66 find_cloudsc_program("dwarf-cloudsc-hip-k-caching")
67 endif()
68
69 # dummy cloudsc external project to get tests
70 ExternalProject_Data_Add(
71 cloudsc
72 ${cloudsc_revision}
73 CONFIGURE_COMMAND ""
74 BUILD_COMMAND ""
75 INSTALL_COMMAND
76 ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/config-files
77 <INSTALL_DIR>/share/dwarf-p-cloudsc
78 COMMAND ${CMAKE_COMMAND} -E make_directory
79 <BINARY_DIR>/test-dwarf-p-cloudsc)
80
81 ExternalProject_Get_Property(cloudsc INSTALL_DIR)
82 ExternalProject_Get_Property(cloudsc BINARY_DIR)
83 set(cloudsc_DIR ${INSTALL_DIR})
84 set(cloudsc_INPUT_DIR ${cloudsc_DIR}/share/dwarf-p-cloudsc)
85 set(cloudsc_BIN_DIR ${BINARY_DIR})
86
87 else()
88 message(STATUS "cloudsc: enabled (internally built)")
89 set(cloudsc_depends_ep ecbuild)
90 if(USE_SYSTEM_hdf5)
91 list(APPEND cloudsc_depends_ep hdf5::hdf5)
92 else()
93 list(APPEND cloudsc_depends_ep hdf5)
94 endif()
95 if(mpi_enabled)
96 list(APPEND cloudsc_depends_ep MPI::MPI_C MPI::MPI_Fortran)
97 endif()
98
99 ExternalProject_Data_Add(
100 cloudsc
101 ${cloudsc_revision}
102 DEPENDS ${cloudsc_depends_ep}
103
104 # execute 'true' instead of the patch command when condition is true
105 PATCH_COMMAND $<IF:$<NOT:$<BOOL:${ENABLE_cloudsc_omp}>>,true,${Patch_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/projects/cloudsc_omp_link.patch>
106 COMMAND $<IF:$<BOOL:${ENABLE_cloudsc_omp_gpu}>,true,${Patch_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/projects/cloudsc_no_omp_target.patch>
107
108 CONFIGURE_COMMAND env
109 PATH=$ENV{PATH} CPATH=$ENV{CPATH} C_INCLUDE_PATH=$ENV{C_INCLUDE_PATH}
110 LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} LIBRARY_PATH=$ENV{LIBRARY_PATH}
111 PKG_CONFIG_PATH=<INSTALL_DIR>/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}
112 CC=${MPI_C_COMPILER} CXX=${MPI_CXX_COMPILER} FC=${MPI_Fortran_COMPILER}
113 ecbuild -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
114 -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
115 -DCMAKE_Fortran_COMPILER:FILEPATH=${CMAKE_Fortran_COMPILER}
116 -DCMAKE_Fortran_FLAGS=${CMAKE_Fortran_FLAGS}
117 -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
118 -DCMAKE_INSTALL_PREFIX:FILEPATH=<INSTALL_DIR>
119
120 -DENABLE_CLOUDSC_C=OFF
121 -DENABLE_CLOUDSC_FORTRAN=ON
122 # OpenACC
123 -DENABLE_ACC:BOOL=${ENABLE_cloudsc_acc}
124 -DENABLE_CLOUDSC_GPU_SCC_K_CACHING=${ENABLE_cloudsc_acc}
125 # OpenMP
126 -DENABLE_OMP:BOOL=${cloudsc_omp}
127 -DENABLE_CLOUDSC_GPU_OMP_SCC_HOIST=${ENABLE_cloudsc_omp_gpu}
128 # Cuda
129 -DENABLE_CUDA:BOOL=${ENABLE_cloudsc_cuda}
130 -DENABLE_CLOUDSC_C_CUDA=${ENABLE_cloudsc_cuda}
131 # HIP
132 -DENABLE_HIP:BOOL=${ENABLE_cloudsc_hip}
133 -DENABLE_CLOUDSC_HIP:BOOL=${ENABLE_cloudsc_hip}
134
135 -DENABLE_MPI:BOOL=${mpi_enabled}
136 -DENABLE_SINGLE_PRECISION=${ENABLE_cloudsc_single_precision}
137
138 -DCMAKE_POLICY_DEFAULT_CMP0104=NEW # initialize CMAKE_CUDA_ARCHITECTURES https://cmake.org/cmake/help/latest/policy/CMP0104.html
139 ${default_cmake_args} ${cloudsc_cmake_args}
140 <SOURCE_DIR>
141 BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j${BUILD_PARALLEL_LEVEL} ${default_build_args} ${cloudsc_build_args}
142 INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} -j${BUILD_PARALLEL_LEVEL} install
143 COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/config-files
144 <INSTALL_DIR>/share/dwarf-p-cloudsc
145 COMMAND ${CMAKE_COMMAND} -E make_directory
146 <BINARY_DIR>/test-dwarf-p-cloudsc)
147
148 ExternalProject_Get_Property(cloudsc INSTALL_DIR)
149 set(cloudsc_DIR ${INSTALL_DIR})
150 set(cloudsc_INPUT_DIR ${cloudsc_DIR}/share/dwarf-p-cloudsc)
151
152 set_if_not_present(ENV{PATH} "$ENV{PATH}" "${cloudsc_DIR}/bin")
153 set_if_not_present(
154 ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}" "${cloudsc_DIR}/lib"
155 "${cloudsc_DIR}/lib64")
156
157 ExternalProject_Get_Property(cloudsc BINARY_DIR)
158 set(cloudsc_BIN_DIR ${BINARY_DIR})
159 endif()
160
161 # common for all tests
162 add_test(
163 NAME cloudsc-stage-in
164 COMMAND $<TARGET_FILE:job_launcher> --name=cloudsc-stage-in
165 --log-dir=${LOG_DIR}
166 --
167 cp ${cloudsc_INPUT_DIR}/{reference.h5,input.h5} .
168 WORKING_DIRECTORY ${cloudsc_BIN_DIR}/test-dwarf-p-cloudsc)
169
170 set_tests_properties(cloudsc-stage-in PROPERTIES FIXTURES_SETUP _setup-cloudsc)
171
172 function(link_cloudsc_tests testname validation)
173 set_tests_properties(${testname} PROPERTIES FIXTURES_REQUIRED _setup-cloudsc)
174 if(TEST ${validation})
175 set_tests_properties(${testname} PROPERTIES FIXTURES_SETUP _run-${testname})
176 set_tests_properties(${validation} PROPERTIES FIXTURES_REQUIRED _run-${testname})
177 endif()
178 endfunction()
179
180 function(add_cloudsc_test testname executable args)
181 add_test(
182 NAME cloudsc-${testname}
183 COMMAND
184 env CPATH=$ENV{CPATH} C_INCLUDE_PATH=$ENV{C_INCLUDE_PATH}
185 PATH=$ENV{PATH} LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}
186 LIBRARY_PATH=$ENV{LIBRARY_PATH} $<TARGET_FILE:job_launcher>
187 --name=cloudsc-${testname}
188 --log-dir=${LOG_DIR}
189 --
190 ${executable} ${args}
191 WORKING_DIRECTORY ${cloudsc_BIN_DIR}/test-dwarf-p-cloudsc)
192
193 # The validation is expected to fail for single precision due to a lack
194 # of references in CLOUDSC itself.
195 if(NOT ENABLE_cloudsc_single_precision)
196 add_test(
197 NAME cloudsc-${testname}-validation
198 COMMAND
199 $<TARGET_FILE:job_launcher> --name=cloudsc-${testname}-validation
200 --log-dir=${LOG_DIR}
201 --
202 ${CMAKE_SOURCE_DIR}/validation/cloudsc.sh
203 ${LOG_DIR}/cloudsc-${testname}.log
204 WORKING_DIRECTORY ${cloudsc_BIN_DIR}/test-dwarf-p-cloudsc)
205 endif()
206
207 link_cloudsc_tests(cloudsc-${testname}
208 cloudsc-${testname}-validation)
209 endfunction()
210
211 # the first parameter is the number of threads (need to be adapted in the job-launcher)
212 add_cloudsc_test(fortran-small dwarf-cloudsc-fortran "\${OMP_NUM_THREADS-1} 16384 ${cloudsc_block_size}")
213 add_cloudsc_test(fortran-medium dwarf-cloudsc-fortran "\${OMP_NUM_THREADS-1} 131072 ${cloudsc_block_size}")
214 add_cloudsc_test(fortran-big dwarf-cloudsc-fortran "\${OMP_NUM_THREADS-1} 524288 ${cloudsc_block_size}")
215
216 # OpenACC
217 if(ENABLE_cloudsc_acc)
218 add_cloudsc_test(gpu-acc dwarf-cloudsc-gpu-scc-k-caching "1 163840 128")
219 endif()
220 # OpenMP
221 if(ENABLE_cloudsc_omp_gpu)
222 add_cloudsc_test(gpu-omp dwarf-cloudsc-gpu-omp-scc-hoist "1 163840 128")
223 endif()
224 # Cuda
225 if(ENABLE_cloudsc_cuda)
226 add_cloudsc_test(gpu-cuda dwarf-cloudsc-c-cuda-k-caching "1 163840 128")
227 endif()
228 # HIP
229 if(ENABLE_cloudsc_hip)
230 add_cloudsc_test(gpu-hip dwarf-cloudsc-hip-k-caching "1 163840 128")
231 endif()
232
233 if(mpi_enabled)
234 add_cloudsc_test(mpi-nproma32 dwarf-cloudsc-fortran "\${OMP_NUM_THREADS-1} 2097152 32")
235 add_cloudsc_test(mpi-nproma64 dwarf-cloudsc-fortran "\${OMP_NUM_THREADS-1} 2097152 64")
236 add_cloudsc_test(mpi-nproma128 dwarf-cloudsc-fortran "\${OMP_NUM_THREADS-1} 2097152 128")
237 add_cloudsc_test(mpi-nproma256 dwarf-cloudsc-fortran "\${OMP_NUM_THREADS-1} 2097152 256")
238 endif()
239
240endif(cloudsc_enabled)