]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use Kokkos CMake targets
authorDaniel Arndt <arndtd@ornl.gov>
Tue, 30 May 2023 17:21:10 +0000 (13:21 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Wed, 31 May 2023 12:57:23 +0000 (08:57 -0400)
cmake/modules/FindDEAL_II_KOKKOS.cmake

index d305640cfb3095aa08d8499c05100b634f20dd61..96a5812b7d5f056754d1f6be0a8f94e898e1f18b 100644 (file)
@@ -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 "\\$<\\$<LINK_LANGUAGE:CXX>:([^>]*)>" "\\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 "\\$<\\$<COMPILE_LANGUAGE:CXX>:([^>]*)>" "\\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()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.