Skip to content

Conversation

cedricchevalier19
Copy link
Member

@cedricchevalier19 cedricchevalier19 commented May 13, 2024

The goal is to provide a joint built for all exercises (and their solutions).

This way, compilation is straightforward for IDE users.

  • Currently, most of the exercises are built using the top-level CMake.

  • However, not all builds make sense, as CUDA builds are wrong for the first exercises. I have put configuration warnings when Kokkos is not configured correctly, as explaining why it is not working is still valuable.

  • I have also refactored the fetch_content implementation: it is now called in an overloaded find_package to keep CMakeLists.txt as standard as possible.

The user can set three CMake variables to control the build system:

  • CMAKE_DISABLE_FIND_PACKAGE_Kokkos: to force a build of a custom Kokkos and ignore any installed Kokkos
  • CMAKE_REQUIRE_FIND_PACKAGE_Kokkos: to force finding an installed Kokkos and to fail if not found
  • KokkosTutorials_KOKKOS_SOURCE_PATH: to specify a Kokkos source directory and by-pass fetch_content when building a custom Kokkos.

I can improve the global CMake by using external_project for the first exercises to "sandbox" their builds and allow a custom Kokkos.

@cedricchevalier19 cedricchevalier19 mentioned this pull request Jun 5, 2024
4 tasks
@cedricchevalier19
Copy link
Member Author

One difficulty is that the first 3-4 exercises are not perfect Kokkos code and can have issue when a Kokkos device backend is enabled.

@cedricchevalier19 cedricchevalier19 self-assigned this Jun 5, 2024
@cedricchevalier19 cedricchevalier19 marked this pull request as ready for review June 10, 2024 14:18
@cedricchevalier19
Copy link
Member Author

@JBludau and @dalg24, I finally decided to follow your advice and I've factorized the code checking for a gpu. Furthermore, to apply the good practice described in the documentation to use either find_package and fetch_content, I have reverted to hide the magic behind a custom FindKokkos.cmake.

I can update the CI to use the new global CMake but I think it is better to leave it to a separate PR, this one being already too large.

I do not understand the issue with Windows but it looks similar to the one of #107.

else ()
if (EXISTS ${KokkosTutorials_KOKKOS_SOURCE_DIR})
add_subdirectory(${KokkosTutorials_KOKKOS_SOURCE_DIR} Kokkos)
else ()
Copy link

Choose a reason for hiding this comment

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

Leave early here too?

Copy link
Member

Choose a reason for hiding this comment

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

Not blocking but do you know how does that play with multi-config generators?

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 will test and report it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It worked for my experiments.

@pzehner
Copy link

pzehner commented Feb 26, 2025

So, creating a custom FindKokkos.cmake is not a good idea?

else ()
if (EXISTS ${KokkosTutorials_KOKKOS_SOURCE_DIR})
add_subdirectory(${KokkosTutorials_KOKKOS_SOURCE_DIR} Kokkos)
else ()
Copy link
Member

Choose a reason for hiding this comment

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

Not blocking but do you know how does that play with multi-config generators?

Copy link

@pzehner pzehner left a comment

Choose a reason for hiding this comment

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

I still have some concerns with the setup script.

# the default directory is inside the source tree.
# This might break if the default in source directory is called from multiple cmake instances at the same time.

set(KokkosTutorials_KOKKOS_SOURCE_DIR "dep/kokkos" CACHE PATH "Description for KokkosTutorials_KOKKOS_SOURCE_DIR")
Copy link

Choose a reason for hiding this comment

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

Please update the help message.

Also, this downloads Kokkos in the build directory. One point of Damien was to use a common directory to not re-download it for every exercice, and I pretty much agree with him. In my experience though, since we have several projects cascading, it is tedious to do it right (maybe with CMAKE_CURRENT_LIST_DIR).

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be OK now.

Copy link

@pzehner pzehner left a comment

Choose a reason for hiding this comment

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

Good job for updating the PR, I think we're almost there!

set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING
"Choose the type of build, options are: Debug, Release, RelWithDebInfo and MinSizeRel."
FORCE)
endif ()
Copy link

Choose a reason for hiding this comment

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

Then, if Kokkos is already found, the build type is not specified for the files of the tutorial. Is it what we want?

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've kept how it was working. I do not really see any added value and I am happy to remove this part.

Copy link

Choose a reason for hiding this comment

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

It's true that CMake always let the user choose what kind of build they want.

# Where to find Kokkos' source code. This might be set by the user.
# In order to automatically share the download between exercises when they are compiled individually,
# the default directory is inside the source tree.
# This might break if the default in source directory is called from multiple cmake instances at the same time.
Copy link

Choose a reason for hiding this comment

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

Can you elaborate?

Copy link
Member Author

Choose a reason for hiding this comment

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

If several CMake instances download at the same time I am not it will always work.

Copy link

Choose a reason for hiding this comment

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

I see, maybe you can rework the sentence then.

Comment on lines +8 to +9
message(WARNING "This example requires CUDA, enable with -DKokkos_ENABLE_CUDA=ON")
return()
Copy link

Choose a reason for hiding this comment

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

Suggested change
message(WARNING "This example requires CUDA, enable with -DKokkos_ENABLE_CUDA=ON")
return()
message(FATAL_ERROR "This example requires CUDA, enable with -DKokkos_ENABLE_CUDA=ON")

The code will not compile without Cuda.

Copy link

Choose a reason for hiding this comment

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

Oh wait, if you do a global build, this would cancel it completely.

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 am open to make it a fatal error but it means that we should protect the add_subdirectory.And potentially lose track of what is compiled or not.

Copy link

@pzehner pzehner Jul 28, 2025

Choose a reason for hiding this comment

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

You can always do the check in the parent CMakeLists.txt and do not add_subdirectory. It sounds like code duplication, although not dramatic for me.

Comment on lines +8 to +9
message(WARNING "This example requires CUDA, enable with -DKokkos_ENABLE_CUDA=ON")
return()
Copy link

Choose a reason for hiding this comment

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

Suggested change
message(WARNING "This example requires CUDA, enable with -DKokkos_ENABLE_CUDA=ON")
return()
message(FATAL_ERROR "This example requires CUDA, enable with -DKokkos_ENABLE_CUDA=ON")

Copy link

Choose a reason for hiding this comment

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

Oh wait, if you do a global build, this would cancel it completely.

@pzehner
Copy link

pzehner commented Jul 28, 2025

There is also a missing include:

diff --git a/Exercises/unique_token/Begin/unique_token.cpp b/Exercises/unique_token/Begin/unique_token.cpp
index 0af6bec..800a4f4 100644
--- a/Exercises/unique_token/Begin/unique_token.cpp
+++ b/Exercises/unique_token/Begin/unique_token.cpp
@@ -1,4 +1,5 @@
 #include<Kokkos_Core.hpp>
+#include <iostream>
 
 // EXERCISE: need to remove the ifdef...
 #ifdef KOKKOS_ENABLE_OPENMP

cedricchevalier19 and others added 2 commits July 28, 2025 15:09
Co-authored-by: Paul Zehner <[email protected]>
Co-authored-by: Paul Zehner <[email protected]>
Copy link
Contributor

@JBludau JBludau left a comment

Choose a reason for hiding this comment

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

the rest seems reasonable

Comment on lines +1 to +8
Exercises/dep
*.o
*.host
*.cuda
KokkosCore_config.h
KokkosCore_config.tmp
*.a

Copy link
Contributor

Choose a reason for hiding this comment

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

I am in general against .gitignores if possible ... I want to see what changed and I think devs should be aware of what they push ...

Copy link

@pzehner pzehner Jul 28, 2025

Choose a reason for hiding this comment

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

I think most of it can go out, besides Exercises/dep, since we're only relying on CMake. But I would add build*/.

I removed the .gitignore after a build to see what git status gives, and it's Kokkos sources and the build directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants