-
Notifications
You must be signed in to change notification settings - Fork 49
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
Compile as cmake language #555
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,20 @@ There are numerous device backends, options, and architecture-specific optimizat | |
```` | ||
which activates the OpenMP backend. All the options controlling device backends, options, architectures, and third-party libraries (TPLs) are given in [CMake Keywords](../keywords). | ||
|
||
## Separate Compilation via CMake Language | ||
|
||
Kokkos supports separating the compilation of source files using Kokkos from others. This is controlled similar to a CMake language. The feature requires Kokkos to be compiled with the keyword `Kokkos_ENABLE_COMPILE_AS_CMAKE_LANGUAGE=ON`. The availability of the feature can be checked via `find_package(Kokkos COMPONENTS separable_compilation)`. | ||
JBludau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The `kokkos_compilation` CMake function marks files in the application's source that contain Kokkos code to be compiled with the correct compiler and flags. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify here how Specifically, I have a library target with GPU kernels that should be compiled with nvcc, and an executable target that should be compiled with plain gcc (because it's a pain to keep the whole code compatible with nvcc). Can I link the executable target with # Kernels library (compile with nvcc)
add_library(mykernels ...)
# Need to link kokkos for kernels obviously
target_link_libraries(mykernels PRIVATE Kokkos::kokkos)
# Compile kernels with nvcc
kokkos_compilation(TARGET mykernels)
# Executable (compile with gcc)
add_executable(myexec main.cpp)
# Use some kokkos functions and launch kernels in executable
target_link_libraries(myexec PRIVATE mykernels Kokkos::kokkos)
# Will myexec compile with gcc or nvcc now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In it's current state To get what you want to work you would need to separate your Kokkos dependent files into a subdirectory, create a library, wrap our interfaces and then link this library to Kokkos with But you can not call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification! So does this mean only targets that I have marked with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But I guess the question if you want to separate the compilation mainly depends on what classes you use in the interfaces of your functions (which translates to INTERFACE?PUBLIC vs. PRIVATE in |
||
````cmake | ||
# this function is provided to easily select which files use the same compiler as Kokkos | ||
# GLOBAL --> all files | ||
# TARGET --> all files in a target | ||
# SOURCE --> specific source files | ||
# DIRECTORY --> all files in directory | ||
# PROJECT --> all files/targets in a project/subproject | ||
kokkos_compilation(SOURCE example.cpp) | ||
```` | ||
The example in `examples/cmake_build_installed_kk_as_language` can help get you started. | ||
|
||
## Known Issues<a name="KnownIssues"></a> | ||
|
||
|
@@ -61,6 +75,9 @@ which activates the OpenMP backend. All the options controlling device backends, | |
|
||
* In a mixed C++/Fortran code, CMake will use the C++ linker by default. If you override this behavior and use Fortran as the link language, the link may break because Kokkos adds linker flags expecting the linker to be C++. Prior to CMake 3.18, Kokkos has no way of detecting in downstream projects that the linker was changed to Fortran. From CMake 3.18, Kokkos can use generator expressions to avoid adding flags when the linker is not C++. Note: Kokkos will not add any linker flags in this Fortran case. The user will be entirely on their own to add the appropriate linker flags. | ||
|
||
### MSVC | ||
* Building an application that uses Kokkos with Microsoft Visual Studio and the `Cuda` backend enabled, requires the use of the CMake language feature, see [Separate Compilation](#separate-compilation-via-cmake-language). | ||
|
||
## Raw Makefile | ||
|
||
Raw Makefiles are only supported via inline builds. See below. | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -151,6 +151,10 @@ General options | |||||||||||
* Aggressively vectorize loops | ||||||||||||
* ``OFF`` | ||||||||||||
|
||||||||||||
* * ``Kokkos_ENABLE_COMPILE_AS_CMAKE_LANGUAGE`` | ||||||||||||
* Enables Kokkos behaving like a CMake language, see `Separate Compilation <building.html#separate-compilation-via-cmake-language>`_. | ||||||||||||
* ``OFF`` | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must be three lines not four for rendering the table correctly. |
||||||||||||
Debugging | ||||||||||||
--------- | ||||||||||||
.. list-table:: | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it is now from you, but I am wondering why "separate compilation"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's technically "separable compilation" and was introduced in kokkos/kokkos#3136 with meaning such as "the compilation settings can be different for every target; they are separable".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no hard feelings about this. My line of reasoning was: Currently we don't offer the possibility to separate the compilation but rather we kind of force the separation when
Kokkos_ENABLE_COMPILE_AS_CMAKE_LANGUAGE=ON
, as the source files and targets that use kokkos will require to have properties set by cmake manually or might not compileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, but most people will read this as "it is the way to do libraries."
Separable
is slightly better.