Skip to content

Commit

Permalink
Add Loki processing in idem mode
Browse files Browse the repository at this point in the history
  • Loading branch information
reuterbal committed Nov 20, 2024
1 parent d242ec7 commit 5e8a297
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ ecbuild_add_option(
REQUIRED_PACKAGES "OpenMP COMPONENTS Fortran"
)

ecbuild_add_option(
FEATURE LOKI
DEFAULT ON
DESCRIPTION "Use Loki source-to-source processing"
REQUIRED_PACKAGES "loki"
)

set( _PRECISIONS "" )
ecbuild_add_option(
FEATURE DOUBLE_PRECISION
Expand Down Expand Up @@ -126,6 +133,9 @@ foreach( PREC IN LISTS _PRECISIONS )
add_subdirectory(ifsrrtm ifsrrtm.${PREC})
add_subdirectory(radiation radiation.${PREC})
add_subdirectory(ifs ifs.${PREC})
if( HAVE_LOKI )
add_subdirectory(loki loki.${PREC})
endif()
add_subdirectory(driver driver.${PREC})
endforeach()

Expand Down
26 changes: 26 additions & 0 deletions driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ ecbuild_add_executable(
driver_lib.${PREC}
)

if( TARGET ecrad_loki.${PREC} )
# Use a different module directory here to avoid conflicts because
# ifs_blocking.F90 is built twice but its .mod file is written to
# the same module directory
set( _CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}" )
get_target_property( CMAKE_Fortran_MODULE_DIRECTORY ecrad_loki.${PREC} Fortran_MODULE_DIRECTORY )

ecbuild_add_executable(
TARGET ecrad_loki_${PREC}
SOURCES
ecrad_ifs_driver_blocked.F90
ifs_blocking.F90
ecrad_driver_read_input.F90
ecrad_driver_config.F90
DEFINITIONS
$<$<NOT:${HAVE_OMP}>:NO_OPENMP>
LIBS
ecrad_loki.${PREC}
ecrad_base.${PREC}
$<${HAVE_OMP}:OpenMP::OpenMP_Fortran>
)

# Reset the module directory
set( CMAKE_Fortran_MODULE_DIRECTORY "${_CMAKE_Fortran_MODULE_DIRECTORY}" )
endif()

# For ecrad_ifs_driver_blocked we have to disable bounds checking
# (which is enabled in Debug builds) because sequence association
# and values initialized to -9999 for unused arguments is used in
Expand Down
4 changes: 4 additions & 0 deletions ifs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ ecbuild_add_library(
ecrad.${PREC}
ecrad_base.${PREC}
)

# Export the list of sources for Loki processing
list( TRANSFORM ifs_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" )
set( ifs_SOURCES ${ifs_SOURCES} PARENT_SCOPE )
4 changes: 4 additions & 0 deletions ifsaux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ ecbuild_add_library(
PRIVATE_LIBS ecrad_base.${PREC}
)
install( TARGETS ecrad_ifsaux.${PREC} EXPORT ecrad-targets )

# Export the list of sources for Loki processing
list( TRANSFORM ifsaux_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" )
set( ifsaux_SOURCES ${ifsaux_SOURCES} PARENT_SCOPE )
4 changes: 4 additions & 0 deletions ifsrrtm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,7 @@ install(
DESTINATION ${ecrad_${PREC}_INSTALL_INCLUDEDIR}
)
install( TARGETS ifsrrtm.${PREC} EXPORT ecrad-targets )

# Export the list of sources for Loki processing
list( TRANSFORM ifsrrtm_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" )
set( ifsrrtm_SOURCES ${ifsrrtm_SOURCES} PARENT_SCOPE )
54 changes: 54 additions & 0 deletions loki/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# (C) Copyright 2014- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

set( CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )

set( ecrad_loki_SOURCE_DIRS "" )
set( target_list
ecrad_ifsaux.${PREC}
ecrad_utilities.${PREC}
ifsrrtm.${PREC}
ecrad.${PREC}
ifs.${PREC}
)

foreach( tgt IN LISTS target_list )
get_target_property( ${tgt}_SOURCE_DIR ${tgt} SOURCE_DIR )
list( APPEND ecrad_loki_SOURCE_DIRS "${${tgt}_SOURCE_DIR}" )
endforeach()

ecbuild_add_library(
TARGET
ecrad_loki.${PREC}
SOURCES
${ifsaux_SOURCES}
${utilities_SOURCES}
${ifsrrtm_SOURCES}
${radiation_SOURCES}
${ifs_SOURCES}
PRIVATE_INCLUDES
${ecrad_loki_SOURCE_DIRS}
PUBLIC_INCLUDES
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_Fortran_MODULE_DIRECTORY}>"
"$<INSTALL_INTERFACE:${ecrad_${PREC}_INSTALL_INCLUDEDIR}>"
PRIVATE_LIBS
ecrad_base.${PREC}
NetCDF::NetCDF_Fortran
$<${HAVE_OMP}:OpenMP::OpenMP_Fortran>
)

loki_transform_target(
TARGET ecrad_loki.${PREC}
MODE idem
CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/ecrad_loki.config
PLAN ${CMAKE_CURRENT_BINARY_DIR}/ecrad_loki_plan.${PREC}.cmake
SOURCES ${ecrad_loki_SOURCE_DIRS}
NO_PLAN_SOURCEDIR
)
97 changes: 97 additions & 0 deletions loki/ecrad_loki.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# -------------------------------------------------------------------
# Loki source transformation configurations
# -------------------------------------------------------------------
# This file contains configurations for multiple source transformation
# pipelines and batch processing settings to apply Loki transformations
# to the ecrad source tree.


# Loki batch scheduler configuration
# -------------------------------------------------------------------
# The Loki batch scheduler performs automated discovery of call trees
# from a select set of seed subroutines. Whenever it adds new
# nodes to the call tree, the following default behaviour will be
# honoured, unless it is specifically overwritten below.

[default]
role = 'kernel' # Role to determine how to transform a routine
expand = true # Automatically expand call tree to subroutine calls
strict = true # Throw exceptions during dicovery
enable_imports = true # Chase dependencies incurred via imports

# Ensure that we are never adding these to the tree, and thus
# do not attempt to look up the source files for these.
disable = [
'delta_eddington*', 'fast_expm_exchange', 'date_and_time', 'get_command',
'rng_type', 'radiation_reverse', 'yomhook', 'netcdf', 'ec_lun',
]

# Prune these modules from the tree to ensure they are not processed by
# transformations
ignore = ['parkind1', 'easy_netcdf']


# Frontend argument overrides
# -------------------------------------------------------------------
# Certain modules hard depend on preprocessing
[frontend_args]

[frontend_args."radiation_random_numbers.F90"]
preprocess = true

[frontend_args."radiation_spartacus_sw.F90"]
preprocess = true

[frontend_args."radiation_two_stream.F90"]
preprocess = true


# Call tree entry points ("driver" subroutines)
# -------------------------------------------------------------------
#
# Note that Loki differentiates between "driver" routines, which act as
# call tree roots and contain the offload and parallelisation loops, and
# "kernel" routines that only contain compute loops and are called
# from drivers or other kernels within parallel sections.
[routines]

[routines.radiation]
role = 'driver'
expand = true


# Define specific transformation settings
# -------------------------------------------------------------------
# The section configures the invididual steps of the transformation
# pipelines. Importantly, it also defines the class name and Python
# module that Transformation objects will be instatiated from.
[transformations]

# A set of utility transformations
# -------------------------------------------------------------------
[transformations.Idem]
classname = 'IdemTransformation'
module = 'loki.transformations'

# Housekeeping and other transformations
# -------------------------------------------------------------------
[transformations.Sanitise]
classname = 'SanitiseTransformation'
module = 'loki.transformations'
options = { resolve_associate_mappings = true }

[transformations.FileWriteTransformation]
classname = 'FileWriteTransformation'
module = 'loki.transformations'
options = { include_module_var_imports = true }


# Full transformation pipelines
# -------------------------------------------------------------------
# The entries below are mapped to the "mode" entry point in
# loki-transform.py. The define the set of transformation and the
# order in which they are applies to the complete call tree.
[pipelines]

[pipelines.idem]
transformations = ['Idem']
4 changes: 4 additions & 0 deletions radiation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ if( CMAKE_Fortran_COMPILER_ID MATCHES "Intel" )
set_source_files_properties( radiation_mcica_sw.F90 PROPERTIES COMPILE_OPTIONS "-vecabi=cmdtarget")
set_source_files_properties( radiation_cloud_generator.F90 PROPERTIES COMPILE_OPTIONS "-vecabi=cmdtarget")
endif()

# Export the list of sources for Loki processing
list( TRANSFORM radiation_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" )
set( radiation_SOURCES ${radiation_SOURCES} PARENT_SCOPE )
24 changes: 13 additions & 11 deletions test/ifs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ function( add_ecrad_ifs_test )
DEPENDS config_${_PAR_NAME}_${PREC}
)

foreach( binary ecrad_${PREC} ecrad_ifs_${PREC} ecrad_ifs_blocked_${PREC} )

ecbuild_add_test(
TARGET ${binary}_${_PAR_NAME}_net
COMMAND ${binary}
ARGS
${CONFIG_NET_NAM}
${TEST_IFS_INPUT}
output_${binary}_${_PAR_NAME}_net.nc
DEPENDS config_${_PAR_NAME}_${PREC}_net
)
foreach( binary ecrad_${PREC} ecrad_ifs_${PREC} ecrad_ifs_blocked_${PREC} ecrad_loki_${PREC} )

if( TARGET ${binary} )
ecbuild_add_test(
TARGET ${binary}_${_PAR_NAME}_net
COMMAND ${binary}
ARGS
${CONFIG_NET_NAM}
${TEST_IFS_INPUT}
output_${binary}_${_PAR_NAME}_net.nc
DEPENDS config_${_PAR_NAME}_${PREC}_net
)
endif()

endforeach()

Expand Down
4 changes: 4 additions & 0 deletions utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ install(
DESTINATION ${ecrad_${PREC}_INSTALL_INCLUDEDIR}
)
install( TARGETS ecrad_utilities.${PREC} EXPORT ecrad-targets )

# Export the list of sources for Loki processing
list( TRANSFORM utilities_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" )
set( utilities_SOURCES ${utilities_SOURCES} PARENT_SCOPE )

0 comments on commit 5e8a297

Please sign in to comment.