Skip to content

[Mirror] Move CMake logic from snapshotted Kokkos package to Trilinos#77

Open
csiefer2 wants to merge 1 commit intodevelopfrom
pr-mirror-15113
Open

[Mirror] Move CMake logic from snapshotted Kokkos package to Trilinos#77
csiefer2 wants to merge 1 commit intodevelopfrom
pr-mirror-15113

Conversation

@csiefer2
Copy link
Copy Markdown
Owner

@csiefer2 csiefer2 commented Apr 9, 2026

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...

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

CDash for AT1 results [Only accessible from Sandia networks]
CDash for AT2 results [Currently only accessible from Sandia networks]

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread cmake/TrilinosKokkosSettings.cmake Outdated
Comment on lines +7 to +9
if(NOT ${Trilinos_ENABLE_OpenMP} STREQUAL "")
set(Kokkos_ENABLE_OPENMP ${Trilinos_ENABLE_OpenMP} CACHE BOOL "Whether to build OpenMP backend" FORCE)
endif()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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()

Comment thread cmake/TrilinosKokkosSettings.cmake Outdated
Comment on lines +24 to +33
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
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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.

Comment thread cmake/TrilinosKokkosSettings.cmake Outdated
set(Kokkos_ENABLE_OPENMP ${Trilinos_ENABLE_OpenMP} CACHE BOOL "Whether to build OpenMP backend" FORCE)
endif()

if(NOT ${TPL_ENABLE_CUDA} STREQUAL "")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Variable expansions in if conditions should be quoted to prevent syntax errors if the variable is undefined or empty.

if(NOT "${TPL_ENABLE_CUDA}" STREQUAL "")

Comment thread cmake/TrilinosKokkosSettings.cmake Outdated
set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "Whether to build CUDA backend" FORCE)
endif()

if(NOT ${TPL_ENABLE_HPX} STREQUAL "")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Variable expansions in if conditions should be quoted to prevent syntax errors if the variable is undefined or empty.

if(NOT "${TPL_ENABLE_HPX}" STREQUAL "")

Comment on lines 1 to 13
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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic set(CMAKE_DISABLE_FIND_PACKAGE_GTest ON) was removed during this refactor and not relocated to TrilinosKokkosSettings.cmake. If this setting is still necessary for Trilinos CI to avoid conflicts with external GTest installations, it should be restored or moved to the new settings file.

@cgcgcg
Copy link
Copy Markdown

cgcgcg commented Apr 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +28 to +42
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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

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.

Comment on lines +14 to +16
else()
set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "Whether to build CUDA backend" FORCE)
endif()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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()

Comment on lines +21 to +23
else()
set(Kokkos_ENABLE_HPX OFF CACHE BOOL "Whether to build HPX backend" FORCE)
endif()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Similar to the CUDA logic above, forcing Kokkos_ENABLE_HPX to OFF when TPL_ENABLE_HPX is empty prevents auto-detection and is inconsistent with the OpenMP handling.

endif()

Signed-off-by: Christian Glusa <caglusa@sandia.gov>
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.

2 participants