Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global CMake for tutorials #91

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1b2b56a
Add a root CMakeLists.txt
cedricchevalier19 May 12, 2024
50bf4e0
More exercises in the global CMake
cedricchevalier19 May 12, 2024
56003c8
CMake directory order follows tutorial
cedricchevalier19 May 12, 2024
6268211
Adding SIMD to CMakeLists.txt
cedricchevalier19 May 12, 2024
dec987e
Use `find_package(Kokkos REQUIRED)` in all exercises
cedricchevalier19 Jun 3, 2024
4f30736
`subview` now compiles with the DefaultExecutionSpace.
cedricchevalier19 Jun 3, 2024
f2cc0c8
Add CMake warnings when using device enabled Kokkos for the 2 first e…
cedricchevalier19 Jun 5, 2024
9ebf652
Adding 'instances' exercise to main CMake
cedricchevalier19 Jun 5, 2024
c4451a0
Adding 'scatter_view/Usage' to CMake
cedricchevalier19 Jun 5, 2024
1a9d282
Adding 'random_number' to CMake
cedricchevalier19 Jun 5, 2024
1b1dedc
Comment out some Kokkos call in Begin exercises
cedricchevalier19 Jun 5, 2024
1a07316
Adding 'unique_token' to CMake
cedricchevalier19 Jun 5, 2024
9bce058
Adding 'unordered_map' to CMake
cedricchevalier19 Jun 5, 2024
7c6a676
Adding 'virtual_functions' to CMake
cedricchevalier19 Jun 5, 2024
8b5cd95
List exercises to add to global cmake.
cedricchevalier19 Jun 5, 2024
5779c0f
Add `fortran_interface` to global cmake
cedricchevalier19 Jun 5, 2024
dacde70
Add `multi_gpu_cuda` to global cmake
cedricchevalier19 Jun 5, 2024
2bc96df
Add `minimd` to global cmake
cedricchevalier19 Jun 5, 2024
46fa1d0
Cleaning up exercise makefile.
cedricchevalier19 Jun 5, 2024
d6e6530
Fetch Kokkos sources into CMAKE_BINARY_DIR
cedricchevalier19 Jun 5, 2024
fe583b3
Use list(APPEND CMAKE_MODULE_PATH)
cedricchevalier19 Jun 11, 2024
5656d32
Fix no newline at end-of-file
cedricchevalier19 Jun 11, 2024
af3141e
Remove warning fixes that are not related to CMake
cedricchevalier19 Jun 11, 2024
5ccfe61
Use Kokkos_ENABLE_CUDA
cedricchevalier19 Jun 11, 2024
7bdf80c
Explicitly list accelerator backends for the 2 first exercise
cedricchevalier19 Jun 11, 2024
bfe7e16
Missing some newline at end-of-file
cedricchevalier19 Jun 11, 2024
798effa
Remove unneeded comment
cedricchevalier19 Jun 13, 2024
a451ee4
Add "" for appending to CMAKE_MODULE_PATH
cedricchevalier19 Jun 13, 2024
0e178f0
Only one top-level CMakeLists.txt
cedricchevalier19 Jun 14, 2024
90f978c
Make KokkostTutorials_FORECE_INTERNAL_Kokkos an official CMake option
cedricchevalier19 Jun 14, 2024
40db39d
Update README.md
cedricchevalier19 Jun 14, 2024
96cf66d
Add `KokkosTutorials_FORCE_EXTERNAL_Kokkos` option
cedricchevalier19 Jun 14, 2024
dba7191
Allow to configure Kokkos source dir
cedricchevalier19 Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorials)

add_subdirectory(Exercises)
44 changes: 44 additions & 0 deletions Exercises/.cmake/FindKokkos.cmake
cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Early return if Kokkos is already set up
# We do not use Kokkos_FOUND as it is not globally defined
if (TARGET Kokkos::kokkos)
return()
endif ()

set(SPACK_CXX $ENV{SPACK_CXX})
if (SPACK_CXX)
message("found spack compiler ${SPACK_CXX}")
set(CMAKE_CXX_COMPILER ${SPACK_CXX} CACHE STRING "the C++ compiler" FORCE)
set(ENV{CXX} ${SPACK_CXX})
masterleinad marked this conversation as resolved.
Show resolved Hide resolved
endif ()

if (NOT CMAKE_BUILD_TYPE)
set(default_build_type "RelWithDebInfo")
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING
"Choose the type of build, options are: Debug, Release, RelWithDebInfo and MinSizeRel."
FORCE)
endif ()

set(Kokkos_COMMON_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/dep/Kokkos)

if (NOT KokkosTutorials_FORCE_INTERNAL_Kokkos)
find_package(Kokkos CONFIG)
endif ()
cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved

if (Kokkos_FOUND)
message(STATUS "Found Kokkos: ${Kokkos_DIR} (version \"${Kokkos_VERSION}\")")
else ()
if (EXISTS ${Kokkos_COMMON_SOURCE_DIR})
add_subdirectory(${Kokkos_COMMON_SOURCE_DIR} Kokkos)
else ()
include(FetchContent)
FetchContent_Declare(
Kokkos
GIT_REPOSITORY https://github.com/kokkos/kokkos.git
GIT_TAG 4.0.01
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the latest release? Did you intend to update in a separate pull request?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought a separate PR made more sense.

SOURCE_DIR ${Kokkos_COMMON_SOURCE_DIR}
)
FetchContent_MakeAvailable(Kokkos)
set(Kokkos_FOUND True)
endif ()
endif ()
13 changes: 11 additions & 2 deletions Exercises/01/Begin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial01)
include(../../common.cmake)

# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake)
cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved

find_package(Kokkos REQUIRED)

if (Kokkos_ENABLE_CUDA OR Kokkos_ENABLE_HIP OR Kokkos_ENABLE_SYCL OR Kokkos_ENABLE_OPENMPTARGET OR Kokkos_ENABLE_HPX)
message(WARNING "${CMAKE_CURRENT_SOURCE_DIR}"
"a Kokkos accelerator backend is enabled, it might cause issue with the current program"
"Please recompile with only a host backend enabled (e.g. -DKokkos_ENABLE_OPENMP=ON)")
endif ()

add_executable(01_Exercise exercise_1_begin.cpp)
target_link_libraries(01_Exercise Kokkos::kokkos)

cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions Exercises/01/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial01)

add_subdirectory(Begin)
add_subdirectory(Solution)
14 changes: 11 additions & 3 deletions Exercises/01/Solution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial01)
include(../../common.cmake)

add_executable(01_Exercise exercise_1_solution.cpp)
target_link_libraries(01_Exercise Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

if (Kokkos_ENABLE_CUDA OR Kokkos_ENABLE_HIP OR Kokkos_ENABLE_SYCL OR Kokkos_ENABLE_OPENMPTARGET OR Kokkos_ENABLE_HPX)
message(WARNING "${CMAKE_CURRENT_SOURCE_DIR}"
"a Kokkos accelerator backend is enabled, it might cause issue with the current program"
"Please recompile with only a host backend enabled (e.g. -DKokkos_ENABLE_OPENMP=ON)")
endif ()

add_executable(01_Solution exercise_1_solution.cpp)
target_link_libraries(01_Solution Kokkos::kokkos)
14 changes: 11 additions & 3 deletions Exercises/02/Begin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial02)
include(../../common.cmake)

add_executable(02_Exercise exercise_2_begin.cpp)
target_link_libraries(02_Exercise Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

if (Kokkos_ENABLE_CUDA OR Kokkos_ENABLE_HIP OR Kokkos_ENABLE_SYCL OR Kokkos_ENABLE_OPENMPTARGET OR Kokkos_ENABLE_HPX)
message(WARNING "${CMAKE_CURRENT_SOURCE_DIR}"
"A Kokkos accelerator backend is enabled, it might cause issue with the current program"
"Please recompile with only a host backend enabled (e.g. -DKokkos_ENABLE_OPENMP=ON)")
endif ()
Comment on lines +9 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be moved into a separate function instead of repeating it?

Copy link
Member

@dalg24 dalg24 Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like a kokkos_tutorials_warn_cpu_only_program() function or whatnot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that each exercise can be used as a standalone. I think factorizing with a function or macro makes the example less clear, and I wish I could avoid including a separate (but shared) file at the terminal CMakeLists.txt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It some way it is akin to the weird find kokkos module isn't it? I'd slightly prefer reusing code as Jakob suggested

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had trouble finding the proper solution as the Kokkos_DEVICES variable is not apparent. If I do a function, I will hide the details that might be useful to copy and paste for some users. That's the reason why it is better to be transparent there.
There are only two such exercises; we will probably not have to touch the CMakeLists.txt too often, so the function is not worth it.

However, I can add a comment explaining what this conditional does for better logic readability (which is the function's main advantage for me).


add_executable(02_Exercise exercise_2_begin.cpp)
target_link_libraries(02_Exercise Kokkos::kokkos)
5 changes: 5 additions & 0 deletions Exercises/02/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial02)

add_subdirectory(Begin)
add_subdirectory(Solution)
14 changes: 11 additions & 3 deletions Exercises/02/Solution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial02)
include(../../common.cmake)

add_executable(02_Exercise exercise_2_solution.cpp)
target_link_libraries(02_Exercise Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

if (Kokkos_ENABLE_CUDA OR Kokkos_ENABLE_HIP OR Kokkos_ENABLE_SYCL OR Kokkos_ENABLE_OPENMPTARGET OR Kokkos_ENABLE_HPX)
message(WARNING "${CMAKE_CURRENT_SOURCE_DIR}"
"A Kokkos accelerator backend is enabled, it might cause issue with the current program"
"Please recompile with only a host backend enabled (e.g. -DKokkos_ENABLE_OPENMP=ON)")
endif ()

add_executable(02_Solution exercise_2_solution.cpp)
target_link_libraries(02_Solution Kokkos::kokkos)
8 changes: 5 additions & 3 deletions Exercises/03/Begin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial03)
include(../../common.cmake)

add_executable(03_Exercise exercise_3_begin.cpp)
target_link_libraries(03_Exercise Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(03_Exercise exercise_3_begin.cpp)
target_link_libraries(03_Exercise Kokkos::kokkos)
5 changes: 5 additions & 0 deletions Exercises/03/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial03)

add_subdirectory(Begin)
add_subdirectory(Solution)
8 changes: 5 additions & 3 deletions Exercises/03/Solution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial03)
include(../../common.cmake)

add_executable(03_Exercise exercise_3_solution.cpp)
target_link_libraries(03_Exercise Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(03_Solution exercise_3_solution.cpp)
target_link_libraries(03_Solution Kokkos::kokkos)
8 changes: 5 additions & 3 deletions Exercises/04/Begin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial04)
include(../../common.cmake)

add_executable(04_Exercise exercise_4_begin.cpp)
target_link_libraries(04_Exercise Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(04_Exercise exercise_4_begin.cpp)
target_link_libraries(04_Exercise Kokkos::kokkos)
5 changes: 5 additions & 0 deletions Exercises/04/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial04)

add_subdirectory(Begin)
add_subdirectory(Solution)
8 changes: 5 additions & 3 deletions Exercises/04/Solution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial04)
include(../../common.cmake)

add_executable(04_Exercise exercise_4_solution.cpp)
target_link_libraries(04_Exercise Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(04_Solution exercise_4_solution.cpp)
target_link_libraries(04_Solution Kokkos::kokkos)
40 changes: 40 additions & 0 deletions Exercises/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorialExercices)
cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved

# These directories follow IntroFull order of introduction

add_subdirectory(01)
add_subdirectory(02)
add_subdirectory(03)
add_subdirectory(04)

add_subdirectory(dualview)
add_subdirectory(mdrange)
add_subdirectory(subview)
add_subdirectory(scatter_view)
add_subdirectory(team_policy)
add_subdirectory(team_vector_loop)
add_subdirectory(team_scratch_memory)
add_subdirectory(tasking)
add_subdirectory(simd)
# FIXME update the code
# add_subdirectory(simd_warp)

# These directories are "independent" and listed in alphabetical order
cedricchevalier19 marked this conversation as resolved.
Show resolved Hide resolved

add_subdirectory(advanced_reductions)
add_subdirectory(fortran-kokkosinterface) # TODO, Add a check for fortran
add_subdirectory(instances)
add_subdirectory(multi_gpu_cuda)
add_subdirectory(parallel_scan)
add_subdirectory(tools_minimd)
add_subdirectory(random_number)
add_subdirectory(unique_token)
add_subdirectory(unordered_map)
add_subdirectory(virtualfunction)

# Not done yet
# TODO, require Kokkos Kernels
# add_subdirectory(kokkoskernels)
# require remote spaces
# add_subdirectory(vectorshift)
9 changes: 6 additions & 3 deletions Exercises/advanced_reductions/Begin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial01)
include(../../common.cmake)
project(KokkosTutorialAdvancedReductions)

# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(AdvancedReductions advanced_reductions.cpp)
target_link_libraries(AdvancedReductions Kokkos::kokkos)

3 changes: 2 additions & 1 deletion Exercises/advanced_reductions/Begin/advanced_reductions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ int main(int argc, char *argv[]) {
n, KOKKOS_LAMBDA(int i) { view(i) = 1 + i / 10.; });

double result;
Kokkos::parallel_reduce(n, GeometricMean{view}, result);
// EXERCISE uncomment the following line when GeometricMean is implemented
// Kokkos::parallel_reduce(n, GeometricMean{view}, result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here, please propose this change as its own PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was necessary in order to compile this exercise. I will comment out the add_subdirectory and do a separate PR.


auto host_view =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, view);
Expand Down
5 changes: 5 additions & 0 deletions Exercises/advanced_reductions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorialAdvancedReductions)

add_subdirectory(Begin)
add_subdirectory(Solution)
11 changes: 7 additions & 4 deletions Exercises/advanced_reductions/Solution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorial01)
include(../../common.cmake)
project(KokkosTutorialAdvancedReductions)

add_executable(AdvancedReductions advanced_reductions.cpp)
target_link_libraries(AdvancedReductions Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(AdvancedReductions_Solution advanced_reductions.cpp)
target_link_libraries(AdvancedReductions_Solution Kokkos::kokkos)
35 changes: 0 additions & 35 deletions Exercises/common.cmake

This file was deleted.

8 changes: 5 additions & 3 deletions Exercises/dualview/Begin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorialDualView)
include(../../common.cmake)

add_executable(dualview dual_view_exercise.cpp)
target_link_libraries(dualview Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(dualview dual_view_exercise.cpp)
target_link_libraries(dualview Kokkos::kokkos)
5 changes: 5 additions & 0 deletions Exercises/dualview/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorialDualView)

add_subdirectory(Begin)
add_subdirectory(Solution)
8 changes: 5 additions & 3 deletions Exercises/dualview/Solution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(KokkosTutorialDualView)
include(../../common.cmake)

add_executable(dualview dual_view_exercise.cpp)
target_link_libraries(dualview Kokkos::kokkos)
# Add a custom module path for find_package
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.cmake")

find_package(Kokkos REQUIRED)

add_executable(dualview_Solution dual_view_exercise.cpp)
target_link_libraries(dualview_Solution Kokkos::kokkos)
Loading