-
Notifications
You must be signed in to change notification settings - Fork 9
Summary of ABQ comments on span
#46
Comments
Next question: where does this leave us on P0546There are some issues that still need to be addressed here, but it seems reasonable to leave this as a separate paper. There are a lot of rules you might want to discuss for Some of the major insights from looking at the analogous discussion with executors:
More on this later, but the amount of text here seems to me to justify the existence of a "generic" properties paper to explore the customization point design itself. We do still need P0856 and P0860 to be presented along with this, though, keeping in mind the following feedback from the end of the notes at the ABQ meeting:
|
Oh, one more "executors lesson" I forgot: it pays to be very careful and deliberate early on about the difference between properties and their values. For instance, you shouldn't have a property called |
I'm OK with that. Iteration is a 1-D thing. Multidimensional iteration usually wants to know the indices.
I've been prototyping stuff with This is relevant because one important use case for an mdspan would be viewing or slicing some independently managed memory allocation. If we want constructors that take |
Hm, how do we define the order in which the hooks get applied? What if they don't commute? I guess they are supposed to be orthogonal; does that really just mean that properties always need to behave as if these hooks commute? (Also, wouldn't you want to apply the post hooks in reverse order of the pre hooks?) |
Wouldn't that mean that |
Oh wait, you could use C++17 |
That
|
I think the easy answer is that you would specify that the hooks are invoked in the order that the properties are given, and if they don't commute then that's the property implementer's fault (but it at least means that the user can figure out what's going on). It would mean that the properties are order dependent, but if the property implementers are being orthogonal enough this order should almost never matter (a lot of these operations should be compiler-reorderable anyway). Another option is to say that the invocation order is implementation-defined, meaning that any code that relies on an invocation order for these hooks would be disallowed (or something like that). |
At least as I understand it, the |
The implementation of template <>
struct mdspan_property_attributes<restrict_access> {
template <typename MDSpanType>
struct pointer_type {
using type = typename MDSpanType::pointer_type __restrict;
};
// ...
}; It's a bit difficult to see how this composes with other properties, but you could specify that it works as a chain just like the other hooks, for instance. |
Example of the hook I suggested above for |
@dhollman wrote:
I like this better. |
Huh, works for recent enough Clang and Intel too, for me at least |
By "works", I don't mean that it just compiles. If you look at the instruction output, gcc "correctly" ends the two restrict overloads with |
@dhollman Ah, I see, thanks! |
Looking at the Kokkos code, I think I might be wrong about this — I must have been thinking of the atomics for arbitrary types thing from elsewhere. @crtrott and @hcedwar can correct me on this, but it looks like Kokkos implements the |
|
I'm going through the comments on
span
from Albuquerque to both understand wherespan
stands relative to incorporation into the IS (and as it relates to P0546, P0856, and P0860) and to make sure we haven't made the same mistakes inmdspan
. I'll enumerate summaries of the issues here (some with bulleted responses about how we've treated that inmdspan
)Comments from a thread titled "Questions raised while trying to implement " on the lib-ext reflector:
mdspan
doesn't define comparison operators, not evenoperator==
(could this be a problem/inconsistency for some people? Probably it's okay to just tell people to convert to span first, especially with the potential for deduction guides on the conversion operators)span
s of unequal extents, sincestd::equal
andstd::lexigraphical_compare
do thisspan<int>
andspan<long>
should be comparableconst
reference rather than by value, even though the paper itself recommends passingspan
by valuesubspan
to take anmdspan
by value for the same reasonspan
currently has (or had?) a constructor that takes aContiguousContainer
(i.e., aContainer
whose iterators meet the requirements of contiguous iterators [27.2.1]). This isn't implementable via SFINAE (or any other compile-time technique) since contiguous iterator is a runtime property.mdspan
doesn't have this constructor. It doesn't look like we're using the term "contiguous" in any contexts that would imply the need for SFINAE, but we should double-check thisnumeric_limits<ptrdiff_t>::max()
(e.g., as could be the case ifsizeof(value_type)
is much larger than 1), thenas_bytes()
andas_writable_bytes()
could introduce undefined behavior.size_t
here instead. (Also, seems like a good motivation for theT[][][]
syntax, so that we don't have to use-1
for a magic extent value)ptrdiff_t
, so maybe we shouldn't change anything.nullptr_t
constructor, since it's the same as the default constructornullptr_t
is a reasonable trait to have. Either way, we omitted discussion/description of this constructor in the paper, even though it's in the wording.Other Pre-meeting comments
span<int, 42>.subspan<0>()
shouldn't return aspan<dynamic_extent>
dynamic_extent
magic number. It doesn't look like we have that problem because oursubspan
extents are always given as normal function arguments rather than template arguments (though this seems like a bit of a shortcoming since it means we can't have a subspan with static extents other than the entirety of the parent's extent for a given rank)constexpr
mdspan
is not iterable (?!?) so this doesn't apply.length
andsize
Small Group discussion comments
shared_ptr
/unique_ptr
(presumably the array partial specializations)noexcept
(presumably relating to comparison operators?)std::get
, since it is likestd::array
(though then it would have to participate in structured binding?)mdspan
. If you really need this, just convert to aspan
Full group discussion
array_view
, now that the termview
does not imply immutable (presumably with some change tostring_view
?)unique_ptr
andshared_ptr
constructors: 6-8-0-0-0nullptr_t
constructor: 4-5-3-0-0span(pointer, pointer)
constructor: 0-0-2-10-0Other notes (not from
span
discussion, but encountered while working on it):One of the requirements is that "
V::static_extent(r) == U::static_extent(r)
orV::static_extent(r) == std::dynamic_extent
for0 < r < V::rank()
". This should probably also include the possibility thatU::static_extent(r) == std::dynamic_extent
.mdspan
defines the constraints here in terms ofstd::is_assignable<U::pointer, V::pointer>
, butspan
defines it in terms of accessing aU::value_type
through aV::pointer
meeting the rules for well-defined object access defined in [basic.lval]/8. Are these definitions exactly equivalent?The text was updated successfully, but these errors were encountered: