Closed christosa-rfpro closed 8 months ago
Greetings! I think this is a correct approach. The accessor needs the stride because the stride explains how to turn a (data handle, 1-D index) pair into a "reference" to the element. I agree that it's good to separate "information that belongs in the layout mapping" from "information that belongs in the accessor"; mdspan's design encourages that. However, in this case, the stride is truly part of how the accessor accesses elements.
The discussion in https://github.com/kokkos/mdspan/issues/117 solves a similar problem. There, the user has an array allocated as char
(bytes), but representing some larger type. Here, you have an array allocated as double
, but representing some larger type. Your struct v4d
should have the same minimum alignment requirement as double
, so as long as your storage array of double
is correctly aligned for double
, you shouldn't have to worry about misaligned access.
The typical mdspan idiom in this case would be to allocate a 2-D mdspan of double
, like mdspan<double, extents<size_t, dynamic_extent, 4>, layout_left>
, and then access (x, y, z, w) using submdspan(x, k, full_extent)
. There's nothing wrong with your approach, but a lot of users don't bother with creating custom accessors and proxy reference types. It's also easier to experiment with the performance effects of different layouts that way.
Very interesting points, thank you!
Thanks for commenting! Please feel free to reopen this issue or open a new one if you have any questions. Thanks!
Hi,
Consider an array of
4*N
double
s arranged like this:It might help to visualise the array in two dimensions:
I want to use an
mdspan
to view that array as a collection ofOne way to achieve this is with the following accessor:
For example:
I wonder if having
const_v4d_accessor::stride
abusesmdspan
's interface because that information is typically part of the layout. Do you think this approach makes any sense? Is there a better alternative?Thanks, Christos