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

Comparison with mdspan/mdarray #45

Open
xelatihy opened this issue Aug 9, 2020 · 1 comment
Open

Comparison with mdspan/mdarray #45

xelatihy opened this issue Aug 9, 2020 · 1 comment

Comments

@xelatihy
Copy link

xelatihy commented Aug 9, 2020

midspan and mdarray are being proposed for inclusion in the C++ standard library. Looking at this library, it seems that some of the basic concerns are the same, but the proposed model and solution is different. It would be very helpful for users that are deciding about which low-level type to use to have a comparison between the two approaches.

@dsharlet
Copy link
Owner

dsharlet commented Aug 10, 2020

Thanks for the good suggestion. I think this deserves e.g. a README section, but I'm not sure I have a strong enough understanding of mdspan and mdarray at this point for that. Here's my current thinking, please correct me if you know better!

Basic multi-dimensional array storage and access

  • mdspan looks like it is less flexible, and similarly easy to use, than array_ref.
  • basic_mdspan looks more flexible, but more verbose to use, than array_ref.

I think that as long as your LayoutPolicy is an affine mapping, and isn't a trivial shape type, this library will be easier to use. But LayoutPolicy can be anything, so basic_mdspan is more flexible, if you need something like tiled or other non-affine shapes.

The one significant thing I've noticed: it appears that layout_strides doesn't support compile-time constant strides, which is really critical for the stride 1 dimension at least. https://github.com/kokkos/mdspan#caveats mentions this as the first caveat. Hopefully the mdspan that becomes standard fixes this...

It's hard to compare mdarray because a lot of the detail is missing from the proposal, and I can't find an implementation to look at (like https://github.com/kokkos/mdspan), particularly tests can be very helpful (though TBH, I haven't found as many mdspan tests as I'd like).

It looks like the current design of mdarray is to own a "flat" container like std::vector (the ContainerPolicy). I started with a similar design, but found it to have some issues and ended up going with what I have now, which is array doing its own memory management with an std::allocator-like allocator object. To be honest, I'm struggling to remember exactly why I ended up giving up on the flat container approach. Part of it may have been what happens when shapes have padding, and there are elements in the array that are unaddressable by the shape (what these tests cover).

Higher-level algorithms

This library provides some higher level algorithms and tools that are integrated with the array types. I think the mdspan and mdarray proposals probably consider these things to be out of scope. Some examples are:

I think most of these could be implemented on top of mdspan, but there are some issues. For example, I can't see how to create a subspan with a constexpr extent, which is really a key part of tiling loops efficiently. This is why interval<> in this library is (unfortunately necessarily) represented [begin, begin + extent) instead of [begin, end).

Non-zero mins being part of the shape are also very helpful for tiling. Of course, the mins can be passed separately, but now it's not "transparent" tiling any more. But at the same time, people might prefer the numpy style slicing rather than the style this library uses (#24).

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