Skip to content

Commit 0b3153e

Browse files
Merge pull request #32 from CExA-project/fix/31-findkokkos
Better integration of Kokkos in the project
2 parents 25cbd5a + 9da3235 commit 0b3153e

File tree

14 files changed

+47
-47
lines changed

14 files changed

+47
-47
lines changed

cmake/modules/FindKokkos.cmake renamed to cmake/SetUpKokkos.cmake

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Setup Kokkos as either an external dependency, or an inlined dependency. In
2+
# the former, Kokkos has already been compiled and installed, and its install
3+
# path is given to CMake with `Kokkos_ROOT` option. In the later, Kokkos
4+
# sources are either already present as a Git submodule, or they are downloaded
5+
# by this script using CMake `FetchContent`; in either case Kokkos sources are
6+
# located in `/vendor/kokkos` and compiled along with the project, which means
7+
# that Kokkos options must be passed at configuration time. If the option
8+
# `CMAKE_DISABLE_FIND_PACKAGE_Kokkos` is `ON`, then no installed instance of
9+
# Kokkos will be used, and only the inline build of Kokkos will take place.
10+
# Conversely, if the option `CMAKE_REQUIRE_FIND_PACKAGE_Kokkos` is `ON`, then
11+
# only an installed instance of Kokkos will be used.
12+
#
13+
# See
14+
# https://kokkos.org/kokkos-core-wiki/get-started/integrating-kokkos-into-your-cmake-project.html#supporting-both-external-and-embedded-kokkos
15+
116
# set CMAKE_BUILD_TYPE if not defined
217
if(NOT CMAKE_BUILD_TYPE)
318
set(default_build_type "RelWithDebInfo")
@@ -12,27 +27,28 @@ if(NOT CMAKE_BUILD_TYPE)
1227
)
1328
endif()
1429

30+
set(
31+
CexaKokkosTutorials_KOKKOS_SOURCE_DIR
32+
"${CMAKE_CURRENT_LIST_DIR}/../vendor/kokkos"
33+
CACHE
34+
PATH
35+
"Path to the local source directory of Kokkos"
36+
)
37+
1538
# find Kokkos as an already existing target
1639
if(TARGET Kokkos::kokkos)
1740
return()
1841
endif()
1942

2043
# find Kokkos as installed
21-
find_package(Kokkos CONFIG)
44+
find_package(Kokkos QUIET)
2245
if(Kokkos_FOUND)
2346
message(STATUS "Kokkos provided as installed: ${Kokkos_DIR} (version \"${Kokkos_VERSION}\")")
2447

2548
return()
2649
endif()
2750

2851
# find Kokkos as an existing source directory
29-
set(
30-
CexaKokkosTutorials_KOKKOS_SOURCE_DIR
31-
"${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/kokkos"
32-
CACHE
33-
PATH
34-
"Path to the local source directory of Kokkos"
35-
)
3652
if(EXISTS "${CexaKokkosTutorials_KOKKOS_SOURCE_DIR}/CMakeLists.txt")
3753
message(STATUS "Kokkos provided as a source directory: ${CexaKokkosTutorials_KOKKOS_SOURCE_DIR}")
3854

@@ -50,8 +66,8 @@ include(FetchContent)
5066
FetchContent_Declare(
5167
kokkos
5268
DOWNLOAD_EXTRACT_TIMESTAMP ON
53-
URL https://github.com/kokkos/kokkos/releases/download/4.5.01/kokkos-4.5.01.zip
69+
URL https://github.com/kokkos/kokkos/releases/download/4.6.01/kokkos-4.6.01.tar.gz
70+
URL_HASH SHA256=b9d70e4653b87a06dbb48d63291bf248058c7c7db4bd91979676ad5609bb1a3a
5471
SOURCE_DIR ${CexaKokkosTutorials_KOKKOS_SOURCE_DIR}
5572
)
5673
FetchContent_MakeAvailable(kokkos)
57-
set(Kokkos_FOUND True)

exercises/01_first_program/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ The goal is to get familiar with the compiling process.
66
## Step 1: Simple Kokkos program
77

88
In `exercise`, open the file `main.cpp`, initialize and finalize Kokkos.
9-
Do not forget to add the header.
9+
Do not forget to include the header.
1010

1111
Add a call to the `Kokkos::print_configuration` function to print the configuration of Kokkos.
1212

1313
## Step 2: Compile the program with the serial backend
1414

15+
Open the `CMakeLists.txt` file and check its content.
16+
In all this tutorial, Kokkos is included to your build with the `/cmake/SetUpKokkos.cmake` script, either as an external dependency, or as an inlined dependency.
17+
In the former, Kokkos has already been compiled and installed, and its install path is given to CMake with `Kokkos_ROOT` option.
18+
In the later, Kokkos sources are either already present as a Git submodule, or they are downloaded by the script using CMake `FetchContent`; in either case Kokkos sources are located in `/vendor/kokkos` and compiled along with the project, which means that Kokkos options must be passed at configuration time.
19+
If the option `CMAKE_DISABLE_FIND_PACKAGE_Kokkos` is `ON`, then no installed instance of Kokkos will be used, and only the inline build of Kokkos will take place.
20+
Conversely, if the option `CMAKE_REQUIRE_FIND_PACKAGE_Kokkos` is `ON`, then only an installed instance of Kokkos will be used.
21+
1522
Compile your program using the serial backend.
1623
You can use the following commands:
1724

@@ -21,6 +28,7 @@ cmake -B build_serial
2128
cmake --build build_serial
2229
```
2330

31+
This would use build Kokkos along with your code.
2432
If you have already installed Kokkos in exercise 0, then you can use the following commands instead:
2533

2634
```sh

exercises/01_first_program/exercise/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(01FirstProgramExercise LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe01 main.cpp)
108
target_link_libraries(exe01 Kokkos::kokkos)

exercises/01_first_program/solution/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(01FirstProgramSolution LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe01solution main.cpp)
108
target_link_libraries(exe01solution Kokkos::kokkos)

exercises/02_basic_view/exercise/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(02BasicViewExercise LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe02 main.cpp)
108
target_link_libraries(exe02 Kokkos::kokkos)

exercises/02_basic_view/solution/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(02BasicViewSolution LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe02solution main.cpp)
108
target_link_libraries(exe02solution Kokkos::kokkos)

exercises/03_deep_copy/exercise/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(03DeepCopyExercise LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe03 main.cpp)
108
target_link_libraries(exe03 Kokkos::kokkos)

exercises/03_deep_copy/solution/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(03DeepCopySolution LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe03solution main.cpp)
108
target_link_libraries(exe03solution Kokkos::kokkos)

exercises/04_parallel_loop/exercise/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(04ParallelLoopExercise LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe04 main.cpp)
108
target_link_libraries(exe04 Kokkos::kokkos)

exercises/04_parallel_loop/solution/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required (VERSION 3.21)
22

33
project(04ParallelLoopSolution LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/modules")
6-
7-
find_package(Kokkos REQUIRED)
5+
include(../../../cmake/SetUpKokkos.cmake)
86

97
add_executable(exe04solution main.cpp)
108
target_link_libraries(exe04solution Kokkos::kokkos)

0 commit comments

Comments
 (0)