Skip to content

Commit

Permalink
Fixes to the SYCL CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
reuterbal committed Apr 26, 2024
1 parent 78a2a27 commit 0e6c9c0
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 55 deletions.
88 changes: 57 additions & 31 deletions src/cloudsc_sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,39 @@ ecbuild_add_option( FEATURE CLOUDSC_SYCL
CONDITION (Serialbox_FOUND OR HDF5_FOUND) AND HAVE_SYCL
)

if( HAVE_CLOUDSC_SYCL )
if( HAVE_CLOUDSC_SYCL AND NOT HAVE_SINGLE_PRECISION )

if ( NOT HAVE_SINGLE_PRECISION )
unset(SYCL_COMPILE_OPTIONS)
if( CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM" )
set(SYCL_COMPILE_OPTIONS -gline-tables-only -fsycl -fsycl-targets=spir64 -fsycl-early-optimizations)
endif()

if (CLOUDSC_MATH STREQUAL "C")
set(GPU_MATH "1")
elseif (CLOUDSC_MATH STREQUAL "STD")
set(GPU_MATH "2")
elseif(CLOUDSC_MATH STREQUAL "SYCL")
set(GPU_MATH "3")
else ()
if (CLOUDSC_MATH STREQUAL "C")
set(GPU_MATH "1")
endif()
ecbuild_info("Building SYCL variant using C math interface")
elseif (CLOUDSC_MATH STREQUAL "STD")
set(GPU_MATH "2")
ecbuild_info("Building SYCL variant using C++ STL math interface")
elseif(CLOUDSC_MATH STREQUAL "SYCL")
set(GPU_MATH "3")
ecbuild_info("Building SYCL variant using SYCL math interface")
else ()
set(GPU_MATH "1")
ecbuild_info("Building SYCL variant using C math interface")
endif()

if (SYCL_SUB_GROUP_SIZE)
set(SUB_GROUP_SIZE "${SYCL_SUB_GROUP_SIZE}")
else ()
if (SYCL_SUB_GROUP_SIZE)
set(SUB_GROUP_SIZE "${SYCL_SUB_GROUP_SIZE}")
else ()
set(SUB_GROUP_SIZE "16")
endif()
endif()

ecbuild_add_library(
TARGET dwarf-cloudsc-scc-sycl-lib
INSTALL_HEADERS LISTED
SOURCES
cloudsc/yoecldp_c.h
cloudsc/load_state.h
cloudsc/load_state.h
cloudsc/load_state.cpp
cloudsc/cloudsc_c.kernel
cloudsc/cloudsc_driver.h
Expand All @@ -46,7 +53,7 @@ if( HAVE_CLOUDSC_SYCL )
cloudsc/cloudsc_validate.cpp
cloudsc/mycpu.h
cloudsc/mycpu.cpp
PUBLIC_INCLUDES
PUBLIC_INCLUDES
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cloudsc>
PUBLIC_LIBS
Expand All @@ -63,11 +70,15 @@ if( HAVE_CLOUDSC_SYCL )
target_compile_definitions(dwarf-cloudsc-scc-sycl-lib PUBLIC GPU_MATH=${GPU_MATH})
target_compile_definitions(dwarf-cloudsc-scc-sycl-lib PUBLIC SUB_GROUP_SIZE=${SUB_GROUP_SIZE})

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-sycl-lib PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

add_sycl_to_target(
TARGET
dwarf-cloudsc-scc-sycl-lib
SOURCES
cloudsc/cloudsc_c.kernel
TARGET
dwarf-cloudsc-scc-sycl-lib
SOURCES
cloudsc/cloudsc_c.kernel
)

ecbuild_add_executable(
Expand All @@ -76,6 +87,10 @@ if( HAVE_CLOUDSC_SYCL )
LIBS dwarf-cloudsc-scc-sycl-lib
)

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-sycl PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

ecbuild_add_test(
TARGET dwarf-cloudsc-sycl-serial
COMMAND bin/dwarf-cloudsc-scc-sycl
Expand Down Expand Up @@ -117,18 +132,25 @@ if( HAVE_CLOUDSC_SYCL )
target_compile_definitions(dwarf-cloudsc-scc-hoist-sycl-lib PUBLIC GPU_MATH=${GPU_MATH})
target_compile_definitions(dwarf-cloudsc-scc-hoist-sycl-lib PUBLIC SUB_GROUP_SIZE=${SUB_GROUP_SIZE})

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-hoist-sycl-lib PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

add_sycl_to_target(
TARGET
dwarf-cloudsc-scc-hoist-sycl-lib
SOURCES
cloudsc/cloudsc_c_hoist.kernel
TARGET
dwarf-cloudsc-scc-hoist-sycl-lib
SOURCES
cloudsc/cloudsc_c_hoist.kernel
)

ecbuild_add_executable(
TARGET dwarf-cloudsc-scc-hoist-sycl
SOURCES dwarf_cloudsc.cpp
LIBS dwarf-cloudsc-scc-hoist-sycl-lib
)
if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-hoist-sycl PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

ecbuild_add_test(
TARGET dwarf-cloudsc-sycl-hoist-serial
Expand Down Expand Up @@ -171,18 +193,25 @@ if( HAVE_CLOUDSC_SYCL )
target_compile_definitions(dwarf-cloudsc-scc-k-caching-sycl-lib PUBLIC GPU_MATH=${GPU_MATH})
target_compile_definitions(dwarf-cloudsc-scc-k-caching-sycl-lib PUBLIC SUB_GROUP_SIZE=${SUB_GROUP_SIZE})

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-k-caching-sycl-lib PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

add_sycl_to_target(
TARGET
dwarf-cloudsc-scc-k-caching-sycl-lib
SOURCES
cloudsc/cloudsc_c_k_caching.kernel
TARGET
dwarf-cloudsc-scc-k-caching-sycl-lib
SOURCES
cloudsc/cloudsc_c_k_caching.kernel
)

ecbuild_add_executable(
TARGET dwarf-cloudsc-scc-k-caching-sycl
SOURCES dwarf_cloudsc.cpp
LIBS dwarf-cloudsc-scc-k-caching-sycl-lib
)
if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-k-caching-sycl PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

ecbuild_add_test(
TARGET dwarf-cloudsc-sycl-k-caching-serial
Expand All @@ -206,6 +235,3 @@ if( HAVE_CLOUDSC_SYCL )
endif()

endif()
else()
ecbuild_info( "Serialbox not found, disabling SYCL version" )
endif()
95 changes: 71 additions & 24 deletions src/cloudsc_sycl_sp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,39 @@ ecbuild_add_option( FEATURE CLOUDSC_SYCL
CONDITION (Serialbox_FOUND OR HDF5_FOUND) AND HAVE_SYCL
)

if( HAVE_CLOUDSC_SYCL )
if( HAVE_CLOUDSC_SYCL AND HAVE_SINGLE_PRECISION )

if ( HAVE_SINGLE_PRECISION )
unset(SYCL_COMPILE_OPTIONS)
if( CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM" )
set(SYCL_COMPILE_OPTIONS -gline-tables-only -fsycl -fsycl-targets=spir64 -fsycl-early-optimizations -Xsycl-target-backend "-options -cl-fast-relaxed-match")
endif()

if (CLOUDSC_MATH STREQUAL "C")
if (CLOUDSC_MATH STREQUAL "C")
set(GPU_MATH "1")
elseif (CLOUDSC_MATH STREQUAL "STD")
ecbuild_info("Building SYCL variant using C math interface")
elseif (CLOUDSC_MATH STREQUAL "STD")
set(GPU_MATH "2")
elseif(CLOUDSC_MATH STREQUAL "SYCL")
ecbuild_info("Building SYCL variant using C++ STL math interface")
elseif(CLOUDSC_MATH STREQUAL "SYCL")
set(GPU_MATH "3")
else ()
ecbuild_info("Building SYCL variant using SYCL math interface")
else ()
set(GPU_MATH "1")
endif()
ecbuild_info("Building SYCL variant using C math interface")
endif()

if (SYCL_SUB_GROUP_SIZE)
if (SYCL_SUB_GROUP_SIZE)
set(SUB_GROUP_SIZE "${SYCL_SUB_GROUP_SIZE}")
else ()
else ()
set(SUB_GROUP_SIZE "16")
endif()
endif()

ecbuild_add_library(
TARGET dwarf-cloudsc-scc-sycl-lib
INSTALL_HEADERS LISTED
SOURCES
cloudsc/yoecldp_c.h
cloudsc/load_state.h
cloudsc/load_state.h
cloudsc/load_state.cpp
cloudsc/cloudsc_c.kernel
cloudsc/cloudsc_driver.h
Expand All @@ -46,15 +53,15 @@ if( HAVE_CLOUDSC_SYCL )
cloudsc/cloudsc_validate.cpp
cloudsc/mycpu.h
cloudsc/mycpu.cpp
PUBLIC_INCLUDES
PUBLIC_INCLUDES
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cloudsc>
PUBLIC_LIBS
$<${HAVE_HDF5}:hdf5::hdf5>
$<${HAVE_HDF5}:hdf5::hdf5>
$<${HAVE_SERIALBOX}:Serialbox::Serialbox_C>
$<${HAVE_OMP}:OpenMP::OpenMP_C>
DEFINITIONS
${CLOUDSC_DEFINITIONS}
$<${HAVE_OMP}:OpenMP::OpenMP_C>
DEFINITIONS
${CLOUDSC_DEFINITIONS}
)

target_compile_definitions(dwarf-cloudsc-scc-sycl-lib PUBLIC C_MATH=1)
Expand All @@ -63,12 +70,27 @@ if( HAVE_CLOUDSC_SYCL )
target_compile_definitions(dwarf-cloudsc-scc-sycl-lib PUBLIC GPU_MATH=${GPU_MATH})
target_compile_definitions(dwarf-cloudsc-scc-sycl-lib PUBLIC SUB_GROUP_SIZE=${SUB_GROUP_SIZE})

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-sycl-lib PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

add_sycl_to_target(
TARGET
dwarf-cloudsc-scc-sycl-lib
SOURCES
cloudsc/cloudsc_c.kernel
)

ecbuild_add_executable(
TARGET dwarf-cloudsc-scc-sycl-sp
TARGET dwarf-cloudsc-scc-sycl
SOURCES dwarf_cloudsc.cpp
LIBS dwarf-cloudsc-scc-sycl-lib
)

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-sycl PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

ecbuild_add_test(
TARGET dwarf-cloudsc-sycl-serial
COMMAND bin/dwarf-cloudsc-scc-sycl
Expand Down Expand Up @@ -109,11 +131,25 @@ if( HAVE_CLOUDSC_SYCL )
target_compile_definitions(dwarf-cloudsc-scc-hoist-sycl-lib PUBLIC GPU_MATH=${GPU_MATH})
target_compile_definitions(dwarf-cloudsc-scc-hoist-sycl-lib PUBLIC SUB_GROUP_SIZE=${SUB_GROUP_SIZE})

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-hoist-sycl-lib PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

add_sycl_to_target(
TARGET
dwarf-cloudsc-scc-hoist-sycl-lib
SOURCES
cloudsc/cloudsc_c_hoist.kernel
)

ecbuild_add_executable(
TARGET dwarf-cloudsc-scc-hoist-sycl-sp
TARGET dwarf-cloudsc-scc-hoist-sycl
SOURCES dwarf_cloudsc.cpp
LIBS dwarf-cloudsc-scc-hoist-sycl-lib
)
if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-hoist-sycl PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

ecbuild_add_test(
TARGET dwarf-cloudsc-sycl-hoist-serial
Expand All @@ -124,7 +160,7 @@ if( HAVE_CLOUDSC_SYCL )
)

######
if (True)

ecbuild_add_library(
TARGET dwarf-cloudsc-scc-k-caching-sycl-lib
INSTALL_HEADERS LISTED
Expand Down Expand Up @@ -156,11 +192,26 @@ if( HAVE_CLOUDSC_SYCL )
target_compile_definitions(dwarf-cloudsc-scc-k-caching-sycl-lib PUBLIC GPU_MATH=${GPU_MATH})
target_compile_definitions(dwarf-cloudsc-scc-k-caching-sycl-lib PUBLIC SUB_GROUP_SIZE=${SUB_GROUP_SIZE})

if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-k-caching-sycl-lib PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()

add_sycl_to_target(
TARGET
dwarf-cloudsc-scc-k-caching-sycl-lib
SOURCES
cloudsc/cloudsc_c_k_caching.kernel
)

ecbuild_add_executable(
TARGET dwarf-cloudsc-scc-k-caching-sycl-sp
TARGET dwarf-cloudsc-scc-k-caching-sycl
SOURCES dwarf_cloudsc.cpp
LIBS dwarf-cloudsc-scc-k-caching-sycl-lib
)
if( DEFINED SYCL_COMPILE_OPTIONS )
target_compile_options(dwarf-cloudsc-scc-k-caching-sycl PUBLIC ${SYCL_COMPILE_OPTIONS})
endif()


ecbuild_add_test(
TARGET dwarf-cloudsc-sycl-k-caching-serial
Expand All @@ -185,7 +236,3 @@ if( HAVE_CLOUDSC_SYCL )
endif()

endif()
endif()
else()
ecbuild_info( "Serialbox not found, disabling SYCL version" )
endif()

0 comments on commit 0e6c9c0

Please sign in to comment.