Skip to content

Commit

Permalink
Modular build: allowing to build "common" only
Browse files Browse the repository at this point in the history
Refactoring the CMake logic to allow us to build the common
directory and its content as an independent module. The idea
is to propagate this to other more meaningful modules so that
we can have faster compilation.

Signed-off-by: Luc Berger-Vergiat <lberge@sandia.gov>
  • Loading branch information
lucbv committed Sep 15, 2022
1 parent 764a8ff commit dc77279
Show file tree
Hide file tree
Showing 41 changed files with 285 additions and 193 deletions.
127 changes: 120 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ KOKKOSKERNELS_PACKAGE()
IF (NOT KOKKOSKERNELS_HAS_TRILINOS)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
KOKKOSKERNELS_ADD_OPTION(
"ENABLE_EXAMPLES"
OFF
"ENABLE_EXAMPLES"
OFF
BOOL
"Whether to build examples. Default: OFF"
)
Expand Down Expand Up @@ -94,6 +94,13 @@ KOKKOSKERNELS_ADD_OPTION(
"Whether to build docs. Default: OFF"
)

KOKKOSKERNELS_ADD_OPTION(
"ENABLE_REMAINDER"
ON
BOOL
"Whether to build library remainder components. Default: ON"
)

SET(KokkosKernels_INSTALL_TESTING OFF CACHE INTERNAL
"Whether to build tests and examples against installation")
IF (KokkosKernels_INSTALL_TESTING)
Expand All @@ -106,7 +113,10 @@ IF (KokkosKernels_INSTALL_TESTING)
INCLUDE(cmake/kokkos_backends.cmake)
# Only build the tests
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(perf_test)
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(unit_test)
IF(KokkosKernels_ENABLE_REMAINDER)
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(unit_test)
ENDIF()
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(common/unit_test)
KOKKOSKERNELS_ADD_EXAMPLE_DIRECTORIES(example)
ELSE()
# Regular build, not install testing
Expand Down Expand Up @@ -222,15 +232,118 @@ ELSE()
ENDFOREACH()
MESSAGE("=======================")
MESSAGE("")



## configure the library
KOKKOSKERNELS_CONFIGURE_FILE(KokkosKernels_config.h)

SET(KK_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR})

#I don't want the complexity of sometimes interface/sometimes not
#Just minimally force an empty dummy file
SET(SOURCES src/dummy.cpp)



# Skip building Kokkos Kernels if we are doing an installation test
ADD_SUBDIRECTORY(src)
IF (KokkosKernels_ENABLE_REMAINDER)
INCLUDE(src/CMakeLists.txt)
ENDIF()
INCLUDE(common/CMakeLists.txt)



# For now, don't add the ETI headers to complete list of headers
# This will break some IDEs and won't properly display headers in the file list
# However, because of the behavior of TRIBITS_ADD_LIBRARY
# I can't add the ETI headers with them getting double-installed
# with a bunch of headers in the wrong location
# This doesn't change pre-existing behavior before the ETI changes
#LIST(APPEND HEADERS ${ETI_HEADERS})
#-----------------------------------------------------------------------------

KOKKOSKERNELS_ADD_LIBRARY(
kokkoskernels
HEADERS ${HEADERS}
SOURCES ${SOURCES}
)

# It does not seem to be possible to automatically have headers installed
# in the correct subdirectory structure using HEADERS and ADD_LIBRARY with tribits
# Force the specializations to be installed in a subdirectory
INSTALL(FILES ${ETI_HEADERS} DESTINATION ${KOKKOSKERNELS_HEADER_INSTALL_DIR}/generated_specializations_hpp/)

IF (KOKKOSKERNELS_HAS_TRILINOS)
#no linking commands required - tribits does this
ELSE()
ADD_LIBRARY(Kokkos::kokkoskernels ALIAS kokkoskernels)
TARGET_LINK_LIBRARIES(kokkoskernels PUBLIC Kokkos::kokkos)
FOREACH(DIR ${KK_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES(kokkoskernels PUBLIC $<BUILD_INTERFACE:${DIR}>)
ENDFOREACH()
TARGET_INCLUDE_DIRECTORIES(kokkoskernels PUBLIC
$<INSTALL_INTERFACE:${KOKKOSKERNELS_HEADER_INSTALL_DIR}>)
ENDIF()

IF (KOKKOS_ENABLE_SYCL)
SET(KOKKOSKERNELS_INTEL_ARCHS ${Kokkos_ARCH})
LIST(FILTER KOKKOSKERNELS_INTEL_ARCHS INCLUDE REGEX ".*INTEL.*")
LIST(LENGTH KOKKOSKERNELS_INTEL_ARCHS KOKKOSKERNELS_INTEL_ARCHS_NUM)
IF(KOKKOSKERNELS_INTEL_ARCHS_NUM GREATER_EQUAL 1)
IF (NOT BUILD_SHARED_LIBS)
MESSAGE(SEND_ERROR
"At the moment, we require KokkosKernels (and Kokkos) to be built as "
"shared libraries to allow querying free and total device memory!"
)
ENDIF()
TARGET_LINK_LIBRARIES(kokkoskernels PUBLIC ze_loader)
ENDIF()
ENDIF()

KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC LAPACK)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC BLAS)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CBLAS)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC LAPACKE)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC SUPERLU)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CHOLMOD)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC MKL)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CUBLAS)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CUSPARSE)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC ROCBLAS)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC ROCSPARSE)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC METIS)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC ARMPL)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC MAGMA)
# Not yet here KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC MAGMA)



IF (KokkosKernels_ENABLE_INSTALL_TEST)
ADD_SUBDIRECTORY(install_test)
MESSAGE("The install test has been enabled, you will need to peform: make install before running the tests otherwise install_test will fail")
ENDIF ()
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(perf_test)
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(unit_test)
KOKKOSKERNELS_ADD_EXAMPLE_DIRECTORIES(example)
IF(KokkosKernels_ENABLE_TESTS OR KokkosKernels_ENABLE_TESTS_AND_PERFSUITE)
SET(GTEST_SOURCE_DIR ${KOKKOSKERNELS_TOP_SOURCE_DIR}/tpls/gtest)

KOKKOSKERNELS_ADD_TEST_LIBRARY(
kokkoskernels_gtest
HEADERS ${GTEST_SOURCE_DIR}/gtest/gtest.h
SOURCES ${GTEST_SOURCE_DIR}/gtest/gtest-all.cc
)
# Disables pthreads, this is a problem for serial builds in Trilinos & Sierra if it's enabled.
TARGET_COMPILE_DEFINITIONS(kokkoskernels_gtest PUBLIC "-DGTEST_HAS_PTHREAD=0")
TARGET_INCLUDE_DIRECTORIES(kokkoskernels_gtest PUBLIC $<BUILD_INTERFACE:${GTEST_SOURCE_DIR}>)

#Gtest minimally requires C++11
TARGET_COMPILE_FEATURES(kokkoskernels_gtest PUBLIC cxx_std_11)
ENDIF()
IF (KokkosKernels_ENABLE_REMAINDER)
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(perf_test)
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(unit_test)
KOKKOSKERNELS_ADD_EXAMPLE_DIRECTORIES(example)
ENDIF()
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(common/unit_test)

KOKKOSKERNELS_PACKAGE_POSTPROCESS()
IF (KokkosKernels_ENABLE_DOCS)
Expand Down
9 changes: 9 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Adding source directory to the build
LIST(APPEND KK_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/src)
LIST(APPEND KK_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/src/impl)
LIST(APPEND KK_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/src/tpls)
LIST(APPEND KK_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/unit_test)

# Adding unit-tests
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/common)
KOKKOSKERNELS_INCLUDE_DIRECTORIES(REQUIRED_DURING_INSTALLATION_TESTING ${CMAKE_CURRENT_SOURCE_DIR}/common)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
97 changes: 97 additions & 0 deletions common/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#####################
# #
# Add include files #
# #
#####################

KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/test_common)
KOKKOSKERNELS_INCLUDE_DIRECTORIES(REQUIRED_DURING_INSTALLATION_TESTING ${PACKAGE_SOURCE_DIR}/test_common)

#####################
# #
# Define unit-tests #
# #
#####################

#####################
# #
# Add GPU backends #
# #
#####################
IF (KOKKOS_ENABLE_CUDA)
KOKKOSKERNELS_ADD_UNIT_TEST(
common_cuda
SOURCES
${PACKAGE_SOURCE_DIR}/unit_test/Test_Main.cpp
backends/Test_Cuda_Common.cpp
COMPONENTS common
)
ENDIF ()

IF (KOKKOS_ENABLE_HIP)
KOKKOSKERNELS_ADD_UNIT_TEST(
common_hip
SOURCES
${PACKAGE_SOURCE_DIR}/unit_test/Test_Main.cpp
backends/Test_HIP_Common.cpp
COMPONENTS common
)
ENDIF ()

IF (KOKKOS_ENABLE_SYCL)
KOKKOSKERNELS_ADD_UNIT_TEST(
common_sycl
SOURCES
${PACKAGE_SOURCE_DIR}/unit_test/Test_Main.cpp
backends/Test_SYCL_Common.cpp
COMPONENTS common
)
ENDIF ()

IF (KOKKOS_ENABLE_OPENMPTARGET)
# KOKKOSKERNELS_ADD_UNIT_TEST(
# common_openmptarget
# SOURCES
# ${PACKAGE_SOURCE_DIR}/unit_test/Test_Main.cpp
# backends/Test_OpenMPTarget_Common.cpp
# COMPONENTS common
# )
ENDIF ()



#####################
# #
# Add CPU backends #
# #
#####################
IF (KOKKOS_ENABLE_SERIAL)
KOKKOSKERNELS_ADD_UNIT_TEST(
common_serial
SOURCES
${PACKAGE_SOURCE_DIR}/unit_test/Test_Main.cpp
backends/Test_Serial_Common.cpp
COMPONENTS common
)
ENDIF ()

IF (KOKKOS_ENABLE_OPENMP)
KOKKOSKERNELS_ADD_UNIT_TEST(
common_openmp
SOURCES
${PACKAGE_SOURCE_DIR}/unit_test/Test_Main.cpp
backends/Test_OpenMP_Common.cpp
COMPONENTS common
)
ENDIF ()

IF (KOKKOS_ENABLE_THREADS)
KOKKOSKERNELS_ADD_UNIT_TEST(
common_threads
SOURCES
${PACKAGE_SOURCE_DIR}/unit_test/Test_Main.cpp
backends/Test_Threads_Common.cpp
COMPONENTS common
)
ENDIF ()

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
#include <Test_Common_Sorting.hpp>
#include <Test_Common_IOUtils.hpp>
#include <Test_Common_Error.hpp>
#include <Test_Common_Controls.hpp>

#endif // TEST_COMMON_HPP
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <KokkosKernels_Utils.hpp>
#include <KokkosKernels_Sorting.hpp>
#include <KokkosKernels_default_types.hpp>
#include <KokkosSparse_CrsMatrix.hpp>
// #include <KokkosSparse_CrsMatrix.hpp>
#include <Kokkos_ArithTraits.hpp>
#include <Kokkos_Complex.hpp>
#include <cstdlib>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit dc77279

Please sign in to comment.