Skip to content

Reviving Kokkos Kernels backend #306

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Conversation

lucbv
Copy link
Contributor

@lucbv lucbv commented May 23, 2025

Refreshing some of the implementation of the Kokkos Kernels backend so that we can re-compile and run the tests.
Mostly changing namespaces and a few signatures that changed, especially that of std::extents.
The mdspan_to_view test compiles and fails at runtime because the checks are not correct.
utest_dot_kokkos_exe test compiles and passes.

Note: something is not working with the complex test and I'm choosing to ignore it for the time being but if you have ideas for it let me know...

Let me know if you want the general approach I took to be changed or if modifying the other tests along the same lines would be reasonable?

lucbv added 7 commits May 21, 2025 13:12
Some things have changed including various namespaces
headers and signatures. With dot seems to compile correctly
unfortunately something related to conjugate is failing at
compile time. Let's fix that and try to run the dot_kk test.

Signed-off-by: Luc Berger-Vergiat <[email protected]>
Not quite sure why overloads are defined for non complex types?

Signed-off-by: Luc Berger-Vergiat <[email protected]>
It looks like various changes were made over time and did not necessarily
propagate to the Kokkos Kernels implementation which now creates some
issues in the namespace hierarchy...

Signed-off-by: Luc Berger-Vergiat <[email protected]>
Signed-off-by: Luc Berger-Vergiat <[email protected]>
@lucbv lucbv requested review from mhoemmen and crtrott May 23, 2025 00:01
Comment on lines 27 to 28
return extent1 == Kokkos::dynamic_extent ||
extent2 == Kokkos::dynamic_extent ||
Copy link
Contributor

Choose a reason for hiding this comment

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

For an include file that might be exposed to users, should we consider using the namespace macro instead of hard-coding it as "Kokkos"?

Suggested change
return extent1 == Kokkos::dynamic_extent ||
extent2 == Kokkos::dynamic_extent ||
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
return extent1 == dynamic_extent ||
extent2 == dynamic_extent ||

Copy link
Member

Choose a reason for hiding this comment

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

Kokkos promises the mdspan types in the Kokkos namespace. In the future these may be aliases to std:: classes but they are not right now (we don't have a full C++26 compatible std implementation, even the C++23 ones which exist can't support GPUs). Since KokkosKernels depends on core I think it's fine to use the Kokkos namespace here.

@mhoemmen
Copy link
Contributor

I wasn't able to comment on the relevant line of code, but one generally can't include <execution> directly (alas). https://github.com/kokkos/stdBLAS/blob/main/include/experimental/__p1673_bits/macros.hpp explains.

#if defined(LINALG_HAS_EXECUTION)
#  include <execution>
#endif

{
const auto size = v.extent(0);
if (size == 0) {
throw std::runtime_error("abs_max() requires non-empty input");
}
const auto i = std::experimental::linalg::vector_idx_abs_max(v);
const auto i = MDSPAN_IMPL_STANDARD_NAMESPACE::MDSPAN_IMPL_PROPOSED_NAMESPACE::linalg::vector_idx_abs_max(v);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see comments elsewhere on use of namespace macros vs. hard-coding "Kokkos"; thanks!

Copy link
Contributor

@mhoemmen mhoemmen left a comment

Choose a reason for hiding this comment

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

Thanks for taking this up! : - )

I'm totally fine with merging this after some fixes that I discussed in the comments. In particular, if you could please fix the non-kokkos-kernels test rather than commenting out those lines of code, that would be most excellent; thanks!

For the longer term, we should think about where projects like this should live. The software dependency diagram has an uncomfortable cycle: KokkosCore depends on the C++ Standard Library, kokkos-kernels depends on KokkosCore, std::linalg depends on kokkos-kernels?!?

@crtrott
Copy link
Member

crtrott commented May 28, 2025

Thanks for taking this up! : - )

I'm totally fine with merging this after some fixes that I discussed in the comments. In particular, if you could please fix the non-kokkos-kernels test rather than commenting out those lines of code, that would be most excellent; thanks!

For the longer term, we should think about where projects like this should live. The software dependency diagram has an uncomfortable cycle: KokkosCore depends on the C++ Standard Library, kokkos-kernels depends on KokkosCore, std::linalg depends on kokkos-kernels?!?

First this isn't actually a standard library implementation here. If (or maybe optimistically "when") we contribute this stuff I am not sure that we could move the KokkosKernels impl with it. But if we did the answer to the dependency thing is simple. std::linalg -> KokkosKernels -> KokkosCore -> std stuff not including linalg (i.e. mdspan and what not). These internal dependencies in the library are not uncommon. The same would be true for calling cuBLAS or oneMKL inside the standard implementation. Both of those also have a dependency on the standard library. Same is already true for stuff like using TBB inside the parallel algorithms implementation.

Next commit will tackle the issues associated with namespaces.

Signed-off-by: Luc Berger-Vergiat <[email protected]>
@lucbv
Copy link
Contributor Author

lucbv commented May 28, 2025

Considering that I include <mdspan/mdspan.hpp> in linalg_kokkoskernels we are guaranteed that MDSPAN_IMPL_STANDARD_NAMESPACE::MDSPAN_IMPL_PROPOSED_NAMESPACE:: will resolve to Kokkos::Experimental. On the other hand I do not mind using the macros to have a smooth transition in case we ever move toward including <experimental/mdspan>.

@lucbv lucbv requested a review from mhoemmen May 28, 2025 23:16
@mhoemmen
Copy link
Contributor

@lucbv wrote:

Considering that I include <mdspan/mdspan.hpp> in linalg_kokkoskernels we are guaranteed that MDSPAN_IMPL_STANDARD_NAMESPACE::MDSPAN_IMPL_PROPOSED_NAMESPACE:: will resolve to Kokkos::Experimental. On the other hand I do not mind using the macros to have a smooth transition in case we ever move toward including <experimental/mdspan>.

Main thing is to pick one or the other : - )

@@ -290,10 +290,6 @@ namespace {
{
using MDSPAN_IMPL_STANDARD_NAMESPACE :: MDSPAN_IMPL_PROPOSED_NAMESPACE :: linalg::impl::has_conj;

static_assert(! has_conj<int>::value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious -- what was wrong with these static_asserts? Why was this test affected by the kokkos-kernels back-end?

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