From: Daniel Arndt Date: Tue, 30 May 2023 17:21:10 +0000 (-0400) Subject: Use Kokkos CMake targets X-Git-Tag: v9.5.0-rc1~137^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ceb7418a826b8c5d8d556790f93e7d68d3737a9;p=dealii.git Use Kokkos CMake targets --- diff --git a/cmake/modules/FindDEAL_II_KOKKOS.cmake b/cmake/modules/FindDEAL_II_KOKKOS.cmake index d305640cfb..96a5812b7d 100644 --- a/cmake/modules/FindDEAL_II_KOKKOS.cmake +++ b/cmake/modules/FindDEAL_II_KOKKOS.cmake @@ -32,7 +32,6 @@ if(DEAL_II_TRILINOS_WITH_KOKKOS OR DEAL_II_PETSC_WITH_KOKKOS) # Let deal.II know that we have found Kokkos set(KOKKOS_FOUND ON) else() - # silence a warning when including FindKOKKOS.cmake set(CMAKE_CXX_EXTENSIONS OFF) find_package(Kokkos 3.7.0 QUIET @@ -40,56 +39,20 @@ else() ) if(Kokkos_FOUND) - # We are only interested in Kokkos if it is not part of Trilinos - if(TARGET Kokkos::kokkos AND TARGET Kokkos::kokkoscore) - get_property(KOKKOS_INSTALL_INCLUDE_DIR TARGET Kokkos::kokkos PROPERTY INTERFACE_INCLUDE_DIRECTORIES) - get_property(KOKKOS_EXTRA_LD_FLAGS_FULL TARGET Kokkos::kokkoscore PROPERTY INTERFACE_LINK_OPTIONS) - string(REGEX REPLACE "\\$<\\$:([^>]*)>" "\\1" KOKKOS_EXTRA_LD_FLAGS "${KOKKOS_EXTRA_LD_FLAGS_FULL}") - string(REPLACE ";" " " KOKKOS_EXTRA_LD_FLAGS "${KOKKOS_EXTRA_LD_FLAGS}") - get_property(KOKKOS_COMPILE_FLAGS_FULL TARGET Kokkos::kokkoscore PROPERTY INTERFACE_COMPILE_OPTIONS) - string(REGEX REPLACE "\\$<\\$:([^>]*)>" "\\1" KOKKOS_COMPILE_FLAGS "${KOKKOS_COMPILE_FLAGS_FULL}") - string(REPLACE ";" " " KOKKOS_COMPILE_FLAGS "${KOKKOS_COMPILE_FLAGS}") - - # Kokkos links transitively with OpenMP so that we need to find OpenMP again. - # Since we are not using target_link_libraries, we have to extract the compile flag manually. - if(Kokkos_VERSION VERSION_GREATER_EQUAL 4.0.00 AND Kokkos_ENABLE_OPENMP) - string(APPEND KOKKOS_COMPILE_FLAGS " ${OpenMP_CXX_FLAGS}") - endif() - - # We need to disable SIMD vectorization for CUDA device code. - # Otherwise, nvcc compilers from version 9 on will emit an error message like: - # "[...] contains a vector, which is not supported in device code". We - # would like to set the variable in check_01_cpu_feature but at that point - # we don't know if CUDA support is enabled in Kokkos - if(Kokkos_ENABLE_CUDA) - set(DEAL_II_VECTORIZATION_WIDTH_IN_BITS 0) - # Require lambda support to use Kokkos as a backend - KOKKOS_CHECK(OPTIONS CUDA_LAMBDA) - endif() - - deal_ii_find_library(KOKKOS_CORE_LIBRARY - NAMES kokkoscore - HINTS ${KOKKOS_DIR}/lib ${Kokkos_DIR}/lib $ENV{Kokkos_DIR}/lib - PATH_SUFFIXES - lib${LIB_SUFFIX} lib64 lib - ) - - deal_ii_find_library(KOKKOS_CONTAINERS_LIBRARY - NAMES kokkoscontainers - HINTS ${KOKKOS_DIR}/lib ${Kokkos_DIR}/lib $ENV{Kokkos_DIR}/lib - PATH_SUFFIXES - lib${LIB_SUFFIX} lib64 lib - ) - else() - set(Kokkos_FOUND FALSE) + # We need to disable SIMD vectorization for CUDA device code. + # Otherwise, nvcc compilers from version 9 on will emit an error message like: + # "[...] contains a vector, which is not supported in device code". We + # would like to set the variable in check_01_cpu_feature but at that point + # we don't know if CUDA support is enabled in Kokkos + if(Kokkos_ENABLE_CUDA) + set(DEAL_II_VECTORIZATION_WIDTH_IN_BITS 0) + # Require lambda support to use Kokkos as a backend + KOKKOS_CHECK(OPTIONS CUDA_LAMBDA) endif() endif() + set(_target Kokkos::kokkos) process_feature(KOKKOS - LIBRARIES REQUIRED KOKKOS_CORE_LIBRARY KOKKOS_CONTAINERS_LIBRARY - INCLUDE_DIRS REQUIRED KOKKOS_INSTALL_INCLUDE_DIR - CXX_FLAGS OPTIONAL KOKKOS_COMPILE_FLAGS - LINKER_FLAGS OPTIONAL KOKKOS_EXTRA_LD_FLAGS - CLEAR KOKKOS_DIR KOKKOS_CORE_LIBRARY KOKKOS_CONTAINERS_LIBRARY + TARGETS REQUIRED _target ) endif()