Skip to content

[RFC] improve interoperability with mdspan #2545

@fwyzard

Description

@fwyzard

To make it easier to pass an alpaka::Buf to a kernel and use it with the alpaka::uniformElements loops, I am thinking of looking into:

  • defining alpaka::MdSpan<T, ...::dextents<...>, ...> as an alias for std::mdspan (c++23) or std::experimental::mdspan (from Kokkos's reference implementation), with the template arguments corresponding to what is returned by alpaka::experimental::getMdSpan<Buf> edit this exists already :-)
  • making alpaka::Buf implicitly convertible to alpaka::MdSpan (with the correct template arguments)
  • making alpaka::Vec implicitly convertible to std::array

This way we should be able to write (pseudo)code like

struct Kernel {
  void operator()(Acc3D const& acc, alpaka::MdSpan<float, 3> data, Vec3D size) const {
    for (auto index: alpaka::uniformElements(acc, size)) {
      use(data[index]);
    }
  }
};

void function(Queue& queue) {
  Vec3D size = { 32, 16, 50 };
  auto buf = alpaka::allocAsyncBuf<float>(queue, size);
  auto grid = alpala::WorkDivElements<Acc3D>{...};
  alpaka::exec<Acc3D>(queue, grid, Kernel{}, buf, size);
}

@psychocoderHPC can you remind me what are the limitations of std::mdspan that prompted you to implement your own version for alpaka 3 ?

@SimeonEhrig I remember we discussed this some time ago, but I cannot find the links to your code any more :-(

comments, ideas or objections ?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions