Skip to content

Batched: allowing dynrankview in get_extent get_stride#3036

Merged
lucbv merged 8 commits intokokkos:developfrom
lucbv:drv_batched_utils
Apr 20, 2026
Merged

Batched: allowing dynrankview in get_extent get_stride#3036
lucbv merged 8 commits intokokkos:developfrom
lucbv:drv_batched_utils

Conversation

@lucbv
Copy link
Copy Markdown
Contributor

@lucbv lucbv commented Apr 16, 2026

Supersedes #3034 @japlews
Some downstream libraries and applications like Intrepid2 use dynamic rank views and we need to allow them to get passed in as input parameters.

Some downstream libraries and applications like Intrepid2
use dynamic rank views and we need to allow them to get
passed in as input parameters.

Signed-off-by: Luc Berger-Vergiat <lberge@sandia.gov>
@lucbv lucbv self-assigned this Apr 16, 2026
@ndellingwood
Copy link
Copy Markdown
Contributor

@lucbv error in the cuda builds,

/home/runner/_work/kokkos-kernels/kokkos-kernels/kokkos-kernels/batched/KokkosBatched_Util.hpp(686): error: device code does not support exception handling
        throw std::runtime_error("KokkosBatched: ViewType must have rank 0, 1 or 2.");

Copy link
Copy Markdown
Contributor

@yasahi-hpc yasahi-hpc left a comment

Choose a reason for hiding this comment

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

We cannot make runtime checks in these helpers.
Rather, it is better to add runtime checks in implementation details of TeamGemm.
Since it is not implemented for rank 3+, it is safer to check these in non-debug mode as well

#ifndef NDEBUG
  if constexpr (Kokkos::is_dyn_rank_view_v<AViewType >) {
     if (A.rank() > 2) return 1;
  }
  if constexpr (Kokkos::is_dyn_rank_view_v<BViewType >) {
     if (B.rank() > 2) return 1;
  }
  if constexpr (Kokkos::is_dyn_rank_view_v<CViewType >) {
     if (C.rank() > 2) return 1;
  }
#endif

https://github.com/kokkos/kokkos-kernels/blob/3a452e13b8236248414971f051e4800eb1901d62/batched/dense/impl/KokkosBatched_Gemm_Team_Impl.hpp#L29-#L47

Comment thread batched/KokkosBatched_Util.hpp
Comment thread batched/KokkosBatched_Util.hpp
Comment thread batched/KokkosBatched_Util.hpp
Comment thread batched/KokkosBatched_Util.hpp
lucbv added 2 commits April 16, 2026 20:06
Signed-off-by: Luc Berger <lberge@sandia.gov>
Signed-off-by: Luc Berger <lberge@sandia.gov>
Comment thread batched/KokkosBatched_Util.hpp Outdated
Signed-off-by: Luc Berger <lberge@sandia.gov>
@lucbv
Copy link
Copy Markdown
Contributor Author

lucbv commented Apr 17, 2026

I removed the runtime check on the DynRankView but I keep the check on being a view or DynRankView

Comment thread batched/KokkosBatched_Util.hpp Outdated
Signed-off-by: Luc Berger <lberge@sandia.gov>
Copy link
Copy Markdown
Contributor

@yasahi-hpc yasahi-hpc left a comment

Choose a reason for hiding this comment

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

I have changed my mind.
Although this check is inconsistent with other checks in batched APIs, we need to ensure that this helper is not used for rank 3+ view.

Still, it is preferable to do this kind of rank checks in the implementation detail.
You also need to include #include <Kokkos_Assert.hpp>

Comment thread batched/KokkosBatched_Util.hpp
Comment thread batched/KokkosBatched_Util.hpp
lucbv added 3 commits April 17, 2026 13:40
We really do require these views to have only rank 0, 1 or 2
as we later on index with the raw pointer directly and will
only use two extents and strides to do so...

Signed-off-by: Luc Berger-Vergiat <lberge@sandia.gov>
Signed-off-by: Luc Berger-Vergiat <lberge@sandia.gov>
Signed-off-by: Luc Berger-Vergiat <lberge@sandia.gov>
Copy link
Copy Markdown
Contributor

@ndellingwood ndellingwood left a comment

Choose a reason for hiding this comment

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

@lucbv should this be cherry-picked to 5.1.1, or does this workaround changes after the 5.1.0 release?

@lucbv
Copy link
Copy Markdown
Contributor Author

lucbv commented Apr 17, 2026

The additional checks might break downstream users so it might be good to do it in 5.2.0 to have a full integration with Trilinos

@ndellingwood
Copy link
Copy Markdown
Contributor

@lucbv should we test this with Trilinos@develop before merge?

@lucbv
Copy link
Copy Markdown
Contributor Author

lucbv commented Apr 20, 2026

@ndellingwood we should at least test once against Trilinos in my opinion, this restricts a bit the API so it could bite users...

@lucbv lucbv merged commit c026ec5 into kokkos:develop Apr 20, 2026
27 of 28 checks passed
@yasahi-hpc
Copy link
Copy Markdown
Contributor

@ndellingwood we should at least test once against Trilinos in my opinion, this restricts a bit the API so it could bite users...

Concerning that this previously does not accept DynRankView, I think this PR still relaxes the usage
I agree it would be better to test against Trilinos with debug build to check KOKKOS_EXPECTS satisfied

@ndellingwood
Copy link
Copy Markdown
Contributor

No failures in the nightly Trilinos jobs due to this change last night 👍

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.

3 participants