Skip to content

Commit

Permalink
Refactor Kokkos and Gtest dependency in Trilinos
Browse files Browse the repository at this point in the history
- Changes from using KokkosCore to Kokkos in Trilinos@14.1
- Removes detect_kokkos_opts.cmake which is no longer needed
- Adds Gtest as a test dependency for Compadre package in Trilinos
- Renames UnitTests to CompadreGtests and skips these tests if
  Gtest is not found in Trilinos
  • Loading branch information
kuberry committed May 2, 2023
1 parent 493f3df commit e539dca
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 84 deletions.
31 changes: 16 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ else() # Raw CMake Project
set(KOKKOS_MIN "3.3.01")

if (Trilinos_PREFIX)
FIND_PACKAGE(Trilinos)
FIND_PACKAGE(Trilinos COMPONENTS Kokkos KokkosKernels OPTIONAL_COMPONENTS Gtest)

LIST(REVERSE Trilinos_INCLUDE_DIRS)
LIST(REMOVE_DUPLICATES Trilinos_INCLUDE_DIRS)
Expand Down Expand Up @@ -209,13 +209,17 @@ else() # Raw CMake Project
MESSAGE(" Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS}")
MESSAGE(" Trilinos_CXX_FLAGS = ${Trilinos_CXX_COMPILER_FLAGS}")

LIST(FIND Trilinos_PACKAGE_LIST KokkosCore KokkosCoreID)
IF (KokkosCoreID GREATER -1 )
MESSAGE(STATUS "Found KokkosCore inside Trilinos!")
IF ("${Trilinos_VERSION}" VERSION_GREATER_EQUAL "14.1")
set(CompadreKokkosPackageName "Kokkos")
ELSE ()
set(CompadreKokkosPackageName "KokkosCore")
ENDIF()
LIST(FIND Trilinos_PACKAGE_LIST ${CompadreKokkosPackageName} ${CompadreKokkosPackageName}ID)
IF (${CompadreKokkosPackageName}ID GREATER -1 )
MESSAGE(STATUS "Found ${CompadreKokkosPackageName} inside Trilinos!")
set(KOKKOS_IN_TRILINOS ON)
set(KokkosCore_FOUND ON)
ELSE()
MESSAGE(FATAL_ERROR "Found Trilinos but could not find KokkosCore.")
MESSAGE(FATAL_ERROR "Found Trilinos but could not find ${CompadreKokkosPackageName}.")
ENDIF()

LIST(FIND Trilinos_PACKAGE_LIST KokkosKernels KokkosKernelsID)
Expand All @@ -227,21 +231,18 @@ else() # Raw CMake Project
MESSAGE(FATAL_ERROR "Found Trilinos but could not find KokkosKernels.")
ENDIF()

LIST(FIND Trilinos_PACKAGE_LIST Gtest GtestID)

if(KOKKOS_IN_TRILINOS AND NOT(KOKKOSKERNELS_IN_TRILINOS))
MESSAGE(FATAL_ERROR "Kokkos found in Trilinos, but not KokkosKernels")
endif()

# Detect KokkosCore functionality from Trilinos
include(${CMAKE_CURRENT_LIST_DIR}/cmake/detect_kokkos_opts.cmake)
# cmake/detect_kokkos_opts.cmake populates KokkosCore_HAS_*
detect_kokkos_opts()

# get kokkos settings, change our settings, error to user if we something they requested is not enabled
if (KokkosCore_HAS_CUDA)
if (NOT KokkosCore_HAS_CUDA_LAMBDA)
list(FIND Kokkos_DEVICES CUDA cuda_index)
if (NOT cuda_index EQUAL -1)
list(FIND Kokkos_OPTIONS CUDA_LAMBDA cuda_lambda_index)
if (cuda_lambda_index EQUAL -1)
message(FATAL_ERROR "Please reconfigure Trilinos with -DKokkos_ENABLE_CUDA_LAMBDA:BOOL=ON")
endif()
message(STATUS "CUDA enabled in KokkosCore in Trilinos, setting Compadre_USE_CUDA to ON")
set(Compadre_USE_CUDA ON)
endif()

Expand Down
4 changes: 3 additions & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
tribits_package_define_dependencies(
LIB_REQUIRED_PACKAGES
KokkosCore KokkosContainers KokkosAlgorithms KokkosKernels
Kokkos KokkosKernels
LIB_OPTIONAL_TPLS
MPI CUDA
TEST_REQUIRED_PACKAGES
Gtest
)
62 changes: 0 additions & 62 deletions cmake/detect_kokkos_opts.cmake

This file was deleted.

15 changes: 10 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ if (Compadre_EXAMPLES)
add_exe_w_compadre(NeighborSearchTest NeighborSearchTest.cpp)

if (Compadre_TESTS)

add_exe_w_compadre(UnitTests Compadre_UnitTests.cpp)
if (Trilinos_PREFIX AND Trilinos_VERSION VERSION_GREATER_EQUAL 13.5)
TARGET_LINK_LIBRARIES(UnitTests PRIVATE Gtest::all_libs)
IF (GtestID GREATER -1 )
add_exe_w_compadre(UnitTests Compadre_UnitTests.cpp)
TARGET_LINK_LIBRARIES(UnitTests PRIVATE Gtest::all_libs)
ADD_TEST(CompadreGtests UnitTests)
ELSE()
ADD_TEST(NAME CompadreGtests COMMAND ${CMAKE_COMMAND} -E echo "77")
ENDIF()
else()
add_exe_w_compadre(UnitTests Compadre_UnitTests.cpp)
TARGET_LINK_LIBRARIES(UnitTests PRIVATE gtest)
ADD_TEST(CompadreGtests UnitTests)
endif()
ADD_TEST(UnitTests UnitTests)
SET_TESTS_PROPERTIES(UnitTests PROPERTIES LABELS "UnitTest;unittest;Unit;unit")
SET_TESTS_PROPERTIES(CompadreGtests PROPERTIES SKIP_REGULAR_EXPRESSION "77" LABELS "Gtest;UnitTest;unittest;Unit;unit")

# Host views tests for GMLS
ADD_TEST(NAME GMLS_Host_Dim3_QR COMMAND ${CMAKE_CURRENT_BINARY_DIR}/GMLS_Host_Test "--p" "4" "--nt" "200" "--d" "3" "${KOKKOS_THREADS_ARG}=2")
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ elseif (KOKKOS_IN_TRILINOS) # Kokkos found in Trilinos installation
target_include_directories(compadre PUBLIC ${Trilinos_INCLUDE_DIRS})
if(Trilinos_VERSION VERSION_LESS "13.5")
target_link_libraries(compadre PUBLIC kokkoscore)
else()
elseif(Trilinos_VERSION VERSION_LESS "14.1")
target_link_libraries(compadre PUBLIC KokkosCore::all_libs)
else()
target_link_libraries(compadre PUBLIC Kokkos::all_libs)
endif()
elseif (KOKKOS_BUILT_FOR_USER) # Kokkos built for user by this project
target_link_libraries(compadre PUBLIC Kokkos::kokkoscore)
Expand Down

0 comments on commit e539dca

Please sign in to comment.