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

Simplify code by relying on newer Kokkos versions. #16554

Closed
bangerth opened this issue Jan 26, 2024 · 5 comments
Closed

Simplify code by relying on newer Kokkos versions. #16554

bangerth opened this issue Jan 26, 2024 · 5 comments
Milestone

Comments

@bangerth
Copy link
Member

My understanding from the cmake scripts is that we require at least Kokkos 3.7. If this is correct, we could simplify the following code that to me looks like it is also supporting versions of Kokkos before 3.6:

#ifdef DEBUG
#  if KOKKOS_VERSION >= 30600
#    ifdef DEAL_II_HAVE_BUILTIN_EXPECT
#      define Assert(cond, exc)                                                \
        do                                                                     \
          {                                                                    \
            KOKKOS_IF_ON_HOST(({                                               \
              if (__builtin_expect(!(cond), false))                            \
                ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \
                  ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \
                    abort_or_throw_on_exception,                               \
                  __FILE__,                                                    \
                  __LINE__,                                                    \
                  __PRETTY_FUNCTION__,                                         \
                  #cond,                                                       \
                  #exc,                                                        \
                  exc);                                                        \
            }))                                                                \
            KOKKOS_IF_ON_DEVICE(({                                             \
              if (!(cond))                                                     \
                Kokkos::abort(#cond);                                          \
            }))                                                                \
          }                                                                    \
        while (false)
#    else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
#      define Assert(cond, exc)                                                \
        do                                                                     \
          {                                                                    \
            KOKKOS_IF_ON_HOST(({                                               \
              if (!(cond))                                                     \
                ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \
                  ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \
                    abort_or_throw_on_exception,                               \
                  __FILE__,                                                    \
                  __LINE__,                                                    \
                  __PRETTY_FUNCTION__,                                         \
                  #cond,                                                       \
                  #exc,                                                        \
                  exc);                                                        \
            }))                                                                \
            KOKKOS_IF_ON_DEVICE(({                                             \
              if (!(cond))                                                     \
                Kokkos::abort(#cond);                                          \
            }))                                                                \
          }                                                                    \
        while (false)
#    endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
#  else    /*if KOKKOS_VERSION >= 30600*/
#    ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
#      ifdef DEAL_II_HAVE_BUILTIN_EXPECT
#        define Assert(cond, exc)                                              \
          do                                                                   \
            {                                                                  \
              if (__builtin_expect(!(cond), false))                            \
                ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \
                  ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \
                    abort_or_throw_on_exception,                               \
                  __FILE__,                                                    \
                  __LINE__,                                                    \
                  __PRETTY_FUNCTION__,                                         \
                  #cond,                                                       \
                  #exc,                                                        \
                  exc);                                                        \
            }                                                                  \
          while (false)
#      else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
#        define Assert(cond, exc)                                              \
          do                                                                   \
            {                                                                  \
              if (!(cond))                                                     \
                ::dealii::deal_II_exceptions::internals::issue_error_noreturn( \
                  ::dealii::deal_II_exceptions::internals::ExceptionHandling:: \
                    abort_or_throw_on_exception,                               \
                  __FILE__,                                                    \
                  __LINE__,                                                    \
                  __PRETTY_FUNCTION__,                                         \
                  #cond,                                                       \
                  #exc,                                                        \
                  exc);                                                        \
            }                                                                  \
          while (false)
#      endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
#    else    /*#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
#      define Assert(cond, exc)     \
        do                          \
          {                         \
            if (!(cond))            \
              Kokkos::abort(#cond); \
          }                         \
        while (false)
#    endif /*ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
#  endif   /*KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST*/
#else      /*ifdef DEBUG*/
#  define Assert(cond, exc) \
    do                      \
      {                     \
      }                     \
    while (false)
#endif /*ifdef DEBUG*/
@bangerth bangerth added this to the Release 9.6 milestone Jan 26, 2024
@bangerth
Copy link
Member Author

To be clear, there are plenty of other places that could also be simplified:

> grep -r KOKKOS_VERSION include/ source/ examples/ tests/
include/deal.II/base/utilities.h:#  if KOKKOS_VERSION >= 30600
include/deal.II/base/tensor.h:#  if KOKKOS_VERSION >= 30600
include/deal.II/base/memory_space_data.h:#if KOKKOS_VERSION < 40000
include/deal.II/base/memory_space_data.h:#  if KOKKOS_VERSION < 40000
include/deal.II/base/exceptions.h:#if KOKKOS_VERSION >= 40200
include/deal.II/base/exceptions.h:#  if KOKKOS_VERSION >= 30600
include/deal.II/base/exceptions.h:#  else    /*if KOKKOS_VERSION >= 30600*/
include/deal.II/lac/vector_operations_internal.h:#if KOKKOS_VERSION < 30400
include/deal.II/lac/vector_operations_internal.h:#elif KOKKOS_VERSION < 30700
include/deal.II/lac/vector_operations_internal.h:#if KOKKOS_VERSION < 30400
include/deal.II/lac/vector_operations_internal.h:#elif KOKKOS_VERSION < 30700
include/deal.II/lac/la_parallel_vector.templates.h:#if KOKKOS_VERSION < 30400
include/deal.II/lac/la_parallel_vector.templates.h:#elif KOKKOS_VERSION < 30700
include/deal.II/lac/la_parallel_vector.templates.h:#    if KOKKOS_VERSION < 40000
include/deal.II/lac/la_parallel_vector.templates.h:#    if KOKKOS_VERSION < 40000
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 30600
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 20900
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 20900
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 20900
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 20900
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 20900
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 20900
include/deal.II/matrix_free/cuda_matrix_free.templates.h:#if KOKKOS_VERSION >= 20900
include/deal.II/matrix_free/cuda_tensor_product_kernels.h:#if KOKKOS_VERSION >= 40000
include/deal.II/matrix_free/cuda_tensor_product_kernels.h:#if KOKKOS_VERSION >= 40000
source/base/kokkos.cc:#if KOKKOS_VERSION >= 30700
source/base/kokkos.cc:#if KOKKOS_VERSION >= 30700
source/base/mpi.cc:#if KOKKOS_VERSION >= 30700

@masterleinad
Copy link
Member

The problem is that we support Trilinos versions that carry older Kokkos versions than 3.7.

@bangerth
Copy link
Member Author

Oh. I had looked into cmake/modules/FindDEAL_II_KOKKOS.cmake where it says

if(DEAL_II_TRILINOS_WITH_KOKKOS OR DEAL_II_PETSC_WITH_KOKKOS)
  # Let ArborX know that we have found Kokkos
  set(Kokkos_FOUND ON)
  # Let deal.II know that we have found Kokkos
  set(KOKKOS_FOUND ON)
else()
  # silence a warning when including FindKOKKOS.cmake
  set(CMAKE_CXX_EXTENSIONS OFF)
  find_package(Kokkos 3.7.0 QUIET
    HINTS ${KOKKOS_DIR} ${Kokkos_DIR} $ENV{Kokkos_DIR}
    )

from which I had assumed that 3.7 is the earliest supported version.

What is the earliest supported version?

@masterleinad
Copy link
Member

What is the earliest supported version?

https://www.dealii.org/current/external-libs/trilinos.html says we require Trilinos 12.14.1 if Kokkos is enabled in Trilinos. That version (released almost 5 years ago) bundles Kokkos 2.7.00 as far as I can tell (trilinos/Trilinos@626e32a).

@bangerth
Copy link
Member Author

Ugh. Well, it was a nice idea :-)

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

No branches or pull requests

2 participants