[Mirror] Move CMake logic from snapshotted Kokkos package to Trilinos#77
[Mirror] Move CMake logic from snapshotted Kokkos package to Trilinos#77
Conversation
|
CDash for AT1 results [Only accessible from Sandia networks] |
There was a problem hiding this comment.
Code Review
This pull request refactors Kokkos configuration within Trilinos by moving several settings from packages/kokkos/cmake/kokkos_configure_trilinos.cmake to a new top-level file cmake/TrilinosKokkosSettings.cmake. It also adds quadmath as an optional dependency. Feedback highlights several issues with the new settings file: a missing else block for OpenMP configuration, potential syntax errors due to unquoted variable expansions in if statements, and an assert_defined call that will likely fail because it runs before the variables are initialized by TriBITS. Additionally, a setting to disable external GTest was lost during the refactor and should be restored if still required.
| if(NOT ${Trilinos_ENABLE_OpenMP} STREQUAL "") | ||
| set(Kokkos_ENABLE_OPENMP ${Trilinos_ENABLE_OpenMP} CACHE BOOL "Whether to build OpenMP backend" FORCE) | ||
| endif() |
There was a problem hiding this comment.
The else block that sets Kokkos_ENABLE_OPENMP to OFF is missing here, which is inconsistent with the CUDA and HPX blocks below. This will cause the assert_defined call on line 26 to fail if Trilinos_ENABLE_OpenMP is not set. Additionally, the variable expansion in the if condition should be quoted to prevent syntax errors if the variable is undefined or empty.
if(NOT "${Trilinos_ENABLE_OpenMP}" STREQUAL "")
set(Kokkos_ENABLE_OPENMP ${Trilinos_ENABLE_OpenMP} CACHE BOOL "Whether to build OpenMP backend" FORCE)
else()
set(Kokkos_ENABLE_OPENMP OFF CACHE BOOL "Whether to build OpenMP backend" FORCE)
endif()
| assert_defined( | ||
| Kokkos_ENABLE_SERIAL | ||
| Kokkos_ENABLE_OPENMP | ||
| Kokkos_ENABLE_THREADS | ||
| Kokkos_ENABLE_HPX | ||
| Kokkos_ENABLE_CUDA | ||
| Kokkos_ENABLE_HIP | ||
| Kokkos_ENABLE_SYCL | ||
| Kokkos_ENABLE_OPENACC | ||
| ) |
There was a problem hiding this comment.
This assert_defined call will likely cause the configuration to fail because variables such as Kokkos_ENABLE_THREADS, Kokkos_ENABLE_HIP, Kokkos_ENABLE_SYCL, and Kokkos_ENABLE_OPENACC are not initialized in this script. Since this file is included before TRIBITS_PROJECT() in the top-level CMakeLists.txt, these variables will be undefined unless explicitly provided by the user. In the original implementation, this check occurred within the Kokkos package configuration after TriBITS had initialized these variables.
| set(Kokkos_ENABLE_OPENMP ${Trilinos_ENABLE_OpenMP} CACHE BOOL "Whether to build OpenMP backend" FORCE) | ||
| endif() | ||
|
|
||
| if(NOT ${TPL_ENABLE_CUDA} STREQUAL "") |
| set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "Whether to build CUDA backend" FORCE) | ||
| endif() | ||
|
|
||
| if(NOT ${TPL_ENABLE_HPX} STREQUAL "") |
| if(CMAKE_PROJECT_NAME STREQUAL "Trilinos") | ||
| set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Whether to build Serial backend" FORCE) | ||
|
|
||
| if(NOT ${Trilinos_ENABLE_OpenMP} STREQUAL "") | ||
| set(Kokkos_ENABLE_OPENMP ${Trilinos_ENABLE_OpenMP} CACHE BOOL "Whether to build OpenMP backend" FORCE) | ||
| else() | ||
| set(Kokkos_ENABLE_OPENMP OFF CACHE BOOL "Whether to build OpenMP backend" FORCE) | ||
| endif() | ||
| # Trilinos sets some TPL dependency options using different names. | ||
| # We handle the translation here. | ||
| # This can cause isssues if Trilinos is built against an external Kokkos. | ||
|
|
||
| if(NOT ${TPL_ENABLE_CUDA} STREQUAL "") | ||
| set(Kokkos_ENABLE_CUDA ${TPL_ENABLE_CUDA} CACHE BOOL "Whether to build CUDA backend" FORCE) | ||
| else() | ||
| set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "Whether to build CUDA backend" FORCE) | ||
| endif() | ||
| ASSERT_DEFINED(Kokkos_ENABLE_quadmath) | ||
| set(Kokkos_ENABLE_LIBQUADMATH ${Kokkos_ENABLE_quadmath} CACHE BOOL "Whether to enable the LIBQUADMATH library" FORCE) | ||
|
|
||
| if(NOT ${TPL_ENABLE_HPX} STREQUAL "") | ||
| set(Kokkos_ENABLE_HPX ${TPL_ENABLE_HPX} CACHE BOOL "Whether to build HPX backend" FORCE) | ||
| else() | ||
| set(Kokkos_ENABLE_HPX OFF CACHE BOOL "Whether to build HPX backend" FORCE) | ||
| endif() | ||
| ASSERT_DEFINED(Kokkos_ENABLE_DLlib) | ||
| set(Kokkos_ENABLE_LIBDL ${Kokkos_ENABLE_DLlib} CACHE BOOL "Whether to enable the LIBDL library" FORCE) | ||
|
|
||
| if(NOT ${TPL_ENABLE_quadmath} STREQUAL "") | ||
| set(Kokkos_ENABLE_LIBQUADMATH ${TPL_ENABLE_quadmath} CACHE BOOL "Whether to enable the LIBQUADMATH library" FORCE) | ||
| else() | ||
| set(Kokkos_ENABLE_LIBQUADMATH OFF CACHE BOOL "Whether to enable the LIBQUADMATH library" FORCE) | ||
| endif() | ||
|
|
||
| if(NOT ${TPL_ENABLE_DLlib} STREQUAL "") | ||
| set(Kokkos_ENABLE_LIBDL ${TPL_ENABLE_DLlib} CACHE BOOL "Whether to enable the LIBDL library" FORCE) | ||
| else() | ||
| set(Kokkos_ENABLE_LIBDL OFF CACHE BOOL "Whether to enable the LIBDL library" FORCE) | ||
| endif() | ||
|
|
||
| set(Kokkos_ENABLE_COMPLEX_ALIGN OFF CACHE BOOL "Whether to align Kokkos::complex to 2*alignof(RealType)") | ||
|
|
||
| # FIXME_TRILINOS We run into problems when trying to use an external GTest in Trilinos CI | ||
| set(CMAKE_DISABLE_FIND_PACKAGE_GTest ON) | ||
|
|
||
| assert_defined( | ||
| Kokkos_ENABLE_SERIAL | ||
| Kokkos_ENABLE_OPENMP | ||
| Kokkos_ENABLE_THREADS | ||
| Kokkos_ENABLE_HPX | ||
| Kokkos_ENABLE_CUDA | ||
| Kokkos_ENABLE_HIP | ||
| Kokkos_ENABLE_SYCL | ||
| Kokkos_ENABLE_OPENACC | ||
| ) | ||
|
|
||
| if(Kokkos_ENABLE_SERIAL | ||
| AND NOT Kokkos_ENABLE_OPENMP | ||
| AND NOT Kokkos_ENABLE_THREADS | ||
| AND NOT Kokkos_ENABLE_HPX | ||
| AND NOT Kokkos_ENABLE_CUDA | ||
| AND NOT Kokkos_ENABLE_HIP | ||
| AND NOT Kokkos_ENABLE_SYCL | ||
| AND NOT Kokkos_ENABLE_OPENACC | ||
| ) | ||
| if(NOT DEFINED Kokkos_ENABLE_ATOMICS_BYPASS) | ||
| set(Kokkos_ENABLE_ATOMICS_BYPASS ON | ||
| CACHE BOOL "Whether to make atomics non-atomic for non-threaded MPI-only use cases" FORCE | ||
| ) | ||
| endif() | ||
| endif() | ||
| endif() |
There was a problem hiding this comment.
426ce91 to
6e34d9e
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the Kokkos configuration logic within Trilinos by introducing a new CMake file, TrilinosKokkosSettings.cmake, to centralize backend enablement settings. However, the current implementation introduces critical issues: the logic for Kokkos_ENABLE_ATOMICS_BYPASS is evaluated too early, potentially causing race conditions in threaded builds, and the forced disabling of CUDA and HPX backends prevents proper auto-detection. Additionally, the removal of GTest configuration and backend variable assertions from the original package configuration file requires further review to ensure build stability.
| if(Kokkos_ENABLE_SERIAL | ||
| AND NOT Kokkos_ENABLE_OPENMP | ||
| AND NOT Kokkos_ENABLE_THREADS | ||
| AND NOT Kokkos_ENABLE_HPX | ||
| AND NOT Kokkos_ENABLE_CUDA | ||
| AND NOT Kokkos_ENABLE_HIP | ||
| AND NOT Kokkos_ENABLE_SYCL | ||
| AND NOT Kokkos_ENABLE_OPENACC | ||
| ) | ||
| if(NOT DEFINED Kokkos_ENABLE_ATOMICS_BYPASS) | ||
| set(Kokkos_ENABLE_ATOMICS_BYPASS ON | ||
| CACHE BOOL "Whether to make atomics non-atomic for non-threaded MPI-only use cases" FORCE | ||
| ) | ||
| endif() | ||
| endif() |
There was a problem hiding this comment.
The logic for Kokkos_ENABLE_ATOMICS_BYPASS is evaluated too early here. Since it runs before TRIBITS_PROJECT(), it only sees variables set explicitly by the user. If a backend (like OpenMP or CUDA) is enabled by TriBITS defaults or through package dependencies, this check will incorrectly conclude that only Serial is enabled and force Kokkos_ENABLE_ATOMICS_BYPASS to ON. This can lead to race conditions in threaded builds. Furthermore, variables like Kokkos_ENABLE_THREADS, Kokkos_ENABLE_HIP, etc., are checked here but not yet defined by Kokkos's internal logic. This logic should remain in a location that is processed after all backend enablement decisions are finalized, such as within the Kokkos package configuration.
| else() | ||
| set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "Whether to build CUDA backend" FORCE) | ||
| endif() |
There was a problem hiding this comment.
The else block forcing Kokkos_ENABLE_CUDA to OFF when TPL_ENABLE_CUDA is empty is problematic. Since this file is included before TRIBITS_PROJECT(), TPL_ENABLE_CUDA will be empty unless explicitly set by the user via the command line. Forcing it to OFF here effectively disables TriBITS's ability to auto-detect CUDA or enable it via other dependency logic. It is also inconsistent with the OpenMP logic at line 7 which correctly avoids the else block.
endif()
| else() | ||
| set(Kokkos_ENABLE_HPX OFF CACHE BOOL "Whether to build HPX backend" FORCE) | ||
| endif() |
6e34d9e to
1dc1660
Compare
Signed-off-by: Christian Glusa <caglusa@sandia.gov>
1dc1660 to
d22dbc0
Compare
Automated mirror of upstream PR trilinos#15113 @trilinos/kokkos
Motivation
Move CMake logic from the snapshotted Kokkos package to Trilinos. Hopefully this will make it less awkward to deal with Trilinos specifc deviations from Kokkos defaults. Add a missing optional dependency on quadmath to Kokkos.
Testing
In a serial build I saw no difference in the CMakeCache.txt before and after the change. Let's see how badly the AT will fail...