-
Notifications
You must be signed in to change notification settings - Fork 98
Using
The documentation here gives a brief introduction to using Kokkos Kernels in your external project.
Kokkos Kernels uses modern C++ to provide performance portability. Modern CMake provides by far the most robust and cleanest usage of modern C++ relative to raw Makfiles or Autools. CMake is strongly encouraged in your Kokkos-dependent projects and is the only fully supported method for building.
What makes CMake so friendly for modern C++? Below is the full code needed for using Kokkos-Kernels in your build system. Consider this CMakeLists.txt
for project that builds a library myMathLib
:
cmake_minimum_required(VERSION 3.13)
project(myMath CXX)
add_library(myMathLib <LIST_OF_SOURCE_FILES>)
find_package(KokkosKernels REQUIRED)
target_link_libraries(myMathLib Kokkos::kokkoskernels)
The project is now fully configured to build and link against Kokkos Kernels and Kokkos itself. All include directories and linker flags are automatically configured through CMake transitive properties. Beyond that, Kokkos provides all the required vendor-specific compiler flags for your compiler and backend. In the same way that your C++ code is portable (no vendor-specific code), Kokkos and Kokkos Kernels make your build system vendor- and compiler-agnostic.
When configuring your CMake project, you minimally need to point your build to an installed Kokkos Kernels:
cmake \
-DCMAKE_CXX_COMPILER=<COMPILER_USED_FOR_KOKKOS> \
-DKokkosKernels_ROOT=<KOKKOSKERNELS_INSTALL_PREFIX>
or the find_package
will fail to locate Kokkos Kernels.
If you only use Kokkos Kernels you do not need to specify Kokkos_ROOT
.
Another less preferred, but supported method is building Kokkos and Kokkos Kernels in-tree directly as part of your project (rather than installing).
In this case your CMakeLists.txt
file should look like:
cmake_minimum_required(VERSION 3.13)
project(myMath CXX)
add_subdirectory(kokkos)
add_subdirectory(kokkos-kernels)
add_library(myMathLib <LIST_OF_SOURCE_FILES>)
target_link_libraries(myMathLib Kokkos::kokkoskernels)
The Kokkos and Kokkos Kernels source code could be provided by, e.g. git submodules or CMake FetchContent
(not covered here).
- CMake 3.13 is encouraged as a minimum. Kokkos 3.0 was released with only 3.10 as a requirement, but 3.13 is likely to be required for future versions.
- If using < 3.13, you may need force a CMake "policy" for finding packages. We recommend adding
cmake_policy(SET CMP0074 NEW)