Skip to content

Commit cf5e789

Browse files
committed
Merge branch 'origin/jgfouca/rrtmgp_remove_yakl' into master (PR #7345)
Remove YAKL backend support for eamxx/rrtmgp The rrtmgp standalone submodule will still need YAKL support due to other parts of E3SM still using YAKL. I will investigate transitioning these parts to Kokkos at some point. Change Homme cmake to use known Kokkos cmake vars that indicate the device type, don't rely on arbitrary settings for these that come from eamxx. [BFB]
2 parents dcc57a1 + 7cdc48d commit cf5e789

30 files changed

+48
-4018
lines changed

components/eamxx/CMakeLists.txt

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ else()
6868
endif()
6969

7070
####################################################################
71-
# Kokkos/YAKL-related settings #
71+
# Kokkos related settings #
7272
####################################################################
7373

7474
if (Kokkos_ENABLE_CUDA)
@@ -95,31 +95,25 @@ endif()
9595
option (Kokkos_ENABLE_SERIAL "" ON)
9696

9797
set (EAMXX_ENABLE_GPU FALSE CACHE BOOL "")
98-
set (CUDA_BUILD FALSE CACHE BOOL "") #needed for yakl if kokkos vars are not visible there?
99-
set (HIP_BUILD FALSE CACHE BOOL "") #needed for yakl if kokkos vars are not visible there?
100-
set (SYCL_BUILD FALSE CACHE BOOL "") #needed for yakl if kokkos vars are not visible there?
10198

10299
# Determine if this is a Cuda build.
103100
if (Kokkos_ENABLE_CUDA)
104101
# Add CUDA as a language for CUDA builds
105102
enable_language(CUDA)
106103
set (EAMXX_ENABLE_GPU TRUE CACHE BOOL "" FORCE)
107-
set (CUDA_BUILD TRUE CACHE BOOL "" FORCE) #needed for yakl if kokkos vars are not visible there?
108104
endif ()
109105

110106
# Determine if this is a HIP build.
111107
if (Kokkos_ENABLE_HIP)
112108
# Add CUDA as a language for CUDA builds
113109
enable_language(HIP)
114110
set (EAMXX_ENABLE_GPU TRUE CACHE BOOL "" FORCE)
115-
set (HIP_BUILD TRUE CACHE BOOL "" FORCE) #needed for yakl if kokkos vars are not visible there?
116111
endif ()
117112

118113
# Determine if this is a sycl build.
119114
if (Kokkos_ENABLE_SYCL)
120115
#enable_language(SYCL)
121116
set (EAMXX_ENABLE_GPU TRUE CACHE BOOL "" FORCE)
122-
set (SYCL_BUILD TRUE CACHE BOOL "" FORCE) #needed for yakl if kokkos vars are not visible there?
123117
endif ()
124118

125119
if( NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "[Cc]lang" )
@@ -220,17 +214,8 @@ endif()
220214
# and then adding to eamxx_config.h:
221215
# #cmakedefine RRTMGP_EXPENSIVE_CHECKS
222216
option (SCREAM_RRTMGP_DEBUG "Turn on extra debug checks in RRTMGP" ${SCREAM_DEBUG})
223-
224-
option(SCREAM_RRTMGP_ENABLE_YAKL "Use YAKL under rrtmgp" FALSE)
225-
option(SCREAM_RRTMGP_ENABLE_KOKKOS "Use Kokkos under rrtmgp" TRUE)
226-
if (SCREAM_RRTMGP_ENABLE_YAKL)
227-
add_definitions("-DRRTMGP_ENABLE_YAKL")
228-
endif()
229-
230-
if (SCREAM_RRTMGP_ENABLE_KOKKOS)
231-
add_definitions("-DRRTMGP_ENABLE_KOKKOS")
232-
endif()
233-
217+
# This can be removed once rrtmgp is kokkos-only.
218+
add_definitions("-DRRTMGP_ENABLE_KOKKOS")
234219

235220
set(SCREAM_DOUBLE_PRECISION TRUE CACHE BOOL "Set to double precision (default True)")
236221

@@ -618,8 +603,6 @@ function (print_var var)
618603
endfunction ()
619604

620605
print_var(EAMXX_ENABLE_GPU)
621-
print_var(CUDA_BUILD)
622-
print_var(HIP_BUILD)
623606
print_var(SCREAM_MACHINE)
624607
print_var(SCREAM_DYNAMICS_DYCORE)
625608
print_var(SCREAM_DOUBLE_PRECISION)

components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/kokkos_rrtmgp/shell_commands

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/yakl_rrtmgp/shell_commands

Lines changed: 0 additions & 2 deletions
This file was deleted.

components/eamxx/src/physics/rrtmgp/CMakeLists.txt

Lines changed: 7 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -2,153 +2,24 @@ include(EkatUtils)
22
include(EkatSetCompilerFlags)
33
include(ScreamUtils)
44

5-
# Copied from EKAT, YAKL is an interface target so requires special
6-
# handling. Get rid of this once RRTMGP is using kokkos.
7-
macro (SetCudaFlagsYakl targetName)
8-
if (Kokkos_ENABLE_CUDA)
9-
# We must find CUDA
10-
find_package(CUDA REQUIRED)
11-
12-
# Still check if CUDA_FOUND is true, since we don't know if the particular
13-
# FindCUDA.cmake module being used is checking _FIND_REQUIRED
14-
if (NOT CUDA_FOUND)
15-
message (FATAL_ERROR "Error! Unable to find CUDA.")
16-
endif()
17-
18-
set(options CUDA_LANG)
19-
set(args1v)
20-
set(argsMv FLAGS)
21-
cmake_parse_arguments(SCF "${options}" "${args1v}" "${argsMv}" ${ARGN})
22-
23-
if (SCF_FLAGS)
24-
set (FLAGS ${SCF_FLAGS})
25-
else ()
26-
# We need host-device lambdas
27-
set (FLAGS --expt-extended-lambda)
28-
29-
IsDebugBuild (SCF_DEBUG)
30-
if (SCF_DEBUG)
31-
# Turn off fused multiply add for debug so we can stay BFB with host
32-
list (APPEND FLAGS --fmad=false)
33-
endif()
34-
endif()
35-
36-
# Set the flags on the target
37-
if (SCF_CUDA_LANG)
38-
# User is setting the src files language to CUDA
39-
target_compile_options (${targetName} INTERFACE
40-
"$<$<COMPILE_LANGUAGE:CUDA>:${FLAGS}>")
41-
else()
42-
# We assume the user is setting the src files lang to CXX
43-
target_compile_options (${targetName} INTERFACE
44-
"$<$<COMPILE_LANGUAGE:CXX>:${FLAGS}>")
45-
endif()
46-
endif()
47-
endmacro()
48-
49-
##################################
50-
# YAKL #
51-
##################################
52-
53-
# RRTMGP++ requires YAKL
54-
if (SCREAM_RRTMGP_ENABLE_YAKL)
55-
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_ci)
56-
if (TARGET yakl)
57-
# Other E3SM components are building YAKL...
58-
message ("It appears some other part of E3SM is building YAKL.\n"
59-
"We will reuse that, but if this is a debug build we will\n"
60-
"add the --fmad=false flag to the cuda flags used by YAKL\n")
61-
else ()
62-
# Prepare CUDA/HIP flags for YAKL
63-
if (CUDA_BUILD)
64-
string(REPLACE ";" " " KOKKOS_CUDA_OPTIONS_STR "${KOKKOS_CUDA_OPTIONS}")
65-
set(YAKL_ARCH "CUDA")
66-
set(YAKL_CUDA_FLAGS "-DYAKL_ARCH_CUDA ${KOKKOS_CUDA_OPTIONS_STR} --expt-relaxed-constexpr -ccbin ${CMAKE_CXX_COMPILER}")
67-
string (REPLACE " " ";" YAKL_CUDA_FLAGS_LIST ${YAKL_CUDA_FLAGS})
68-
endif()
69-
if (HIP_BUILD)
70-
set(YAKL_ARCH "HIP")
71-
set(YAKL_HIP_FLAGS "-DYAKL_ARCH_HIP -O3 -D__HIP_ROCclr__ -D__HIP_ARCH_GFX90A__=1 --rocm-path=${ROCM_PATH} --offload-arch=gfx90a -x hip")
72-
string (REPLACE " " ";" YAKL_HIP_FLAGS_LIST ${YAKL_HIP_FLAGS})
73-
endif()
74-
if (SYCL_BUILD)
75-
set(YAKL_ARCH "SYCL")
76-
set(YAKL_SYCL_FLAGS " -fp-model precise -DYAKL_ARCH_SYCL -\-intel -fsycl -fsycl-targets=spir64_gen -mlong-double-64")
77-
string (REPLACE " " ";" YAKL_SYCL_FLAGS_LIST ${YAKL_SYCL_FLAGS})
78-
endif()
79-
80-
set (YAKL_SOURCE_DIR ${SCREAM_BASE_DIR}/../../externals/YAKL)
81-
add_subdirectory(${YAKL_SOURCE_DIR} ${CMAKE_BINARY_DIR}/externals/YAKL)
82-
83-
# Set some additional flag/cpp option on the yakl target
84-
85-
cmake_policy (SET CMP0079 NEW) # Allow to link to a tgt from a different directory
86-
87-
# EAMxx *requires* MPI, so simply look for it, then link against it
88-
find_package(MPI REQUIRED COMPONENTS C)
89-
target_link_libraries (yakl INTERFACE MPI::MPI_C)
90-
91-
# For debug builds, set -DYAKL_DEBUG
92-
if (CMAKE_BUILD_TYPE_ci STREQUAL "debug")
93-
target_compile_definitions(yakl INTERFACE YAKL_DEBUG)
94-
endif()
95-
endif()
96-
97-
# See eamxx/src/dynamics/homme/CMakeLists.txt for an explanation of this
98-
# workaround.
99-
if ((SCREAM_MACHINE STREQUAL "ascent" OR SCREAM_MACHINE STREQUAL "pm-gpu") AND CMAKE_BUILD_TYPE_ci STREQUAL "debug")
100-
SetCudaFlagsYakl(yakl CUDA_LANG FLAGS -UNDEBUG)
101-
else()
102-
SetCudaFlagsYakl(yakl CUDA_LANG)
103-
endif()
104-
105-
list(APPEND CMAKE_MODULE_PATH ${YAKL_SOURCE_DIR})
106-
include (yakl_utils)
107-
endif()
108-
1095
##################################
1106
# RRTMGP #
1117
##################################
1128

1139
set(EAM_RRTMGP_DIR ${SCREAM_BASE_DIR}/../eam/src/physics/rrtmgp)
11410
# Build RRTMGP library; this builds the core RRTMGP external source as a library named "rrtmgp"
11511
# NOTE: The external RRTMGP build needs some fixes to work with CUDA in a library build, so for now we will build these ourselves
116-
set(EXTERNAL_SRC
117-
${EAM_RRTMGP_DIR}/external/cpp/rrtmgp/kernels/mo_gas_optics_kernels.cpp
118-
${EAM_RRTMGP_DIR}/external/cpp/rrtmgp/mo_rrtmgp_util_reorder.cpp
119-
${EAM_RRTMGP_DIR}/external/cpp/rte/expand_and_transpose.cpp
120-
${EAM_RRTMGP_DIR}/external/cpp/rte/kernels/mo_fluxes_broadband_kernels.cpp
121-
${EAM_RRTMGP_DIR}/external/cpp/rte/kernels/mo_optical_props_kernels.cpp
122-
${EAM_RRTMGP_DIR}/external/cpp/rte/kernels/mo_rte_solver_kernels.cpp
123-
${EAM_RRTMGP_DIR}/external/cpp/extensions/fluxes_byband/mo_fluxes_byband_kernels.cpp
124-
${EAM_RRTMGP_DIR}/external/cpp/examples/all-sky/mo_garand_atmos_io.cpp
125-
${EAM_RRTMGP_DIR}/external/cpp/examples/all-sky/mo_load_cloud_coefficients.cpp
126-
${EAM_RRTMGP_DIR}/external/cpp/examples/mo_load_coefficients.cpp
127-
)
128-
add_library(rrtmgp ${EXTERNAL_SRC})
129-
target_compile_definitions(rrtmgp PUBLIC EAMXX_HAS_RRTMGP)
130-
EkatDisableAllWarning(rrtmgp)
131-
if (SCREAM_RRTMGP_ENABLE_YAKL)
132-
yakl_process_target(rrtmgp)
133-
else()
134-
if (CUDA_BUILD)
135-
target_compile_options(rrtmgp PUBLIC $<$<COMPILE_LANGUAGE:CXX>:--expt-relaxed-constexpr>)
136-
endif()
12+
add_library(rrtmgp INTERFACE)
13+
target_compile_definitions(rrtmgp INTERFACE EAMXX_HAS_RRTMGP)
14+
if (Kokkos_ENABLE_CUDA)
15+
target_compile_options(rrtmgp INTERFACE $<$<COMPILE_LANGUAGE:CXX>:--expt-relaxed-constexpr>)
13716
endif()
13817

139-
# NOTE: cannot use 'PUBLIC' in target_link_libraries,
140-
# since yakl_process_target already used it
141-
# with the "plain" signature
14218
if (NOT TARGET Kokkos::kokkos)
14319
find_package(Kokkos REQUIRED)
14420
endif ()
145-
if (SCREAM_RRTMGP_ENABLE_YAKL)
146-
target_link_libraries(rrtmgp yakl Kokkos::kokkos)
147-
else()
148-
target_link_libraries(rrtmgp Kokkos::kokkos)
149-
endif()
150-
target_include_directories(rrtmgp PUBLIC
151-
${SCREAM_BASE_DIR}/../../externals/YAKL
21+
target_link_libraries(rrtmgp INTERFACE Kokkos::kokkos)
22+
target_include_directories(rrtmgp INTERFACE
15223
${EAM_RRTMGP_DIR}/external/cpp
15324
${EAM_RRTMGP_DIR}/external/cpp/extensions/cloud_optics
15425
${EAM_RRTMGP_DIR}/external/cpp/examples
@@ -166,29 +37,14 @@ target_include_directories(rrtmgp PUBLIC
16637
# separates out the code that comprises the core RRTMGP library from the extensions
16738
# and examples that we have modified for use in SCREAM specifically.
16839

169-
# However, due to the mix of YAKL and Kokkos, we split the target in two:
170-
# - scream_rrtmgp: kokkos-based interface to EAMxx
171-
# - scream_rrtmgp_yakl: source codes to be built with YAKL flags/options
172-
173-
##################################
174-
# SCREAM_RRTMGP_YAKL #
175-
##################################
176-
17740
set(SCREAM_RRTMGP_SOURCES_INTERFACE
17841
eamxx_rrtmgp_interface.cpp
17942
)
18043

18144
add_library(eamxx_rrtmgp_interface ${SCREAM_RRTMGP_SOURCES_INTERFACE})
182-
if (SCREAM_RRTMGP_ENABLE_YAKL)
183-
yakl_process_target(eamxx_rrtmgp_interface)
184-
endif()
185-
186-
# NOTE: cannot use 'PUBLIC' in target_link_libraries,
187-
# since yakl_process_target already used it
188-
# with the "plain" signature
18945

19046
find_library(NETCDF_C netcdf HINTS ${NetCDF_C_PATH} PATH_SUFFIXES lib lib64)
191-
target_link_libraries(eamxx_rrtmgp_interface ${NETCDF_C} rrtmgp scream_share Kokkos::kokkos)
47+
target_link_libraries(eamxx_rrtmgp_interface PUBLIC ${NETCDF_C} rrtmgp scream_share Kokkos::kokkos)
19248
target_include_directories(eamxx_rrtmgp_interface PUBLIC
19349
${CMAKE_CURRENT_SOURCE_DIR})
19450
target_include_directories(eamxx_rrtmgp_interface SYSTEM PUBLIC
@@ -213,19 +69,6 @@ target_include_directories(scream_rrtmgp PUBLIC
21369
${CMAKE_CURRENT_SOURCE_DIR}
21470
${CMAKE_CURRENT_BINARY_DIR}/modules)
21571

216-
# If yakl builds with LANG!=CXX, then the yakl CPP defines don't transfer to scream
217-
# targets, b/c of the lang difference. So, if YAKL_ARCH is set, we add
218-
# ${YAKL_${YAKL_ARCH}_FLAGS} flags to the CXX flags of scream_rrtmgp.
219-
# In particular, this will ensure that all the yakl macros
220-
# are correctly defined in YAKL headers, depending on the backend
221-
if (SCREAM_RRTMGP_ENABLE_YAKL)
222-
if (YAKL_ARCH)
223-
target_compile_options(scream_rrtmgp PUBLIC
224-
"$<$<COMPILE_LANGUAGE:CXX>:${YAKL_${YAKL_ARCH}_FLAGS_LIST}>")
225-
endif()
226-
endif()
227-
228-
22972
# Ensure RRTMGP lookup tables are present in the data dir
23073
set (RRTMGP_TABLES
23174
scream/init/rrtmgp-data-sw-g112-210809.nc

0 commit comments

Comments
 (0)