Skip to content

Commit

Permalink
Merge pull request #327 from nmm0/326-fix-padded-layout-annotations
Browse files Browse the repository at this point in the history
fix padded layout annotations and add tagged raw array constructor to `layout_stride`
  • Loading branch information
crtrott authored May 31, 2024
2 parents b885a2c + f08661a commit 59a70bb
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 230 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Features in Addition To C++ Standard
- C++14 backport (e.g., fold expressions not required)
- Compile times of this backport will be substantially slower than the C++17 version
- Macros to enable, e.g., `__device__` marking of all functions for CUDA compatibility
* Non-standard extensions for device code compatibility
* These extension methods can be invoked by passing `Kokkos::mdspan_non_standard` as the first argument.

Building and Installation
-------------------------
Expand Down
44 changes: 44 additions & 0 deletions include/experimental/__p0009_bits/layout_stride.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ struct layout_stride {
return __strides_storage_t{static_cast<index_type>(s[Idxs])...};
}

template<class IntegralType>
MDSPAN_INLINE_FUNCTION
static constexpr const __strides_storage_t fill_strides(mdspan_non_standard_tag, const IntegralType (&s)[extents_type::rank()]) {
return __strides_storage_t{static_cast<index_type>(s[Idxs])...};
}

#ifdef __cpp_lib_span
template<class IntegralType>
MDSPAN_INLINE_FUNCTION
Expand Down Expand Up @@ -313,6 +319,44 @@ struct layout_stride {
*/
}

MDSPAN_TEMPLATE_REQUIRES(
class IntegralTypes,
/* requires */ (
// MSVC 19.32 does not like using index_type here, requires the typename Extents::index_type
// error C2641: cannot deduce template arguments for 'MDSPAN_IMPL_STANDARD_NAMESPACE::layout_stride::mapping'
_MDSPAN_TRAIT(std::is_convertible, const std::remove_const_t<IntegralTypes>&, typename Extents::index_type) &&
_MDSPAN_TRAIT(std::is_nothrow_constructible, typename Extents::index_type, const std::remove_const_t<IntegralTypes>&)
)
)
MDSPAN_INLINE_FUNCTION
constexpr
mapping(
mdspan_non_standard_tag,
extents_type const& e,
IntegralTypes (&s)[extents_type::rank()]
) noexcept
#if defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS)
: __members{
#else
: __base_t(__base_t{__member_pair_t(
#endif
e, __strides_storage_t(__impl::fill_strides(mdspan_non_standard, s))
#if defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS)
}
#else
)})
#endif
{
/*
* TODO: check preconditions
* - s[i] > 0 is true for all i in the range [0, rank_ ).
* - REQUIRED-SPAN-SIZE(e, s) is a representable value of type index_type ([basic.fundamental]).
* - If rank_ is greater than 0, then there exists a permutation P of the integers in the
* range [0, rank_), such that s[ pi ] >= s[ pi − 1 ] * e.extent( pi − 1 ) is true for
* all i in the range [1, rank_ ), where pi is the ith element of P.
*/
}

#ifdef __cpp_lib_span
MDSPAN_TEMPLATE_REQUIRES(
class IntegralTypes,
Expand Down
4 changes: 4 additions & 0 deletions include/experimental/__p0009_bits/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ constexpr struct
} stride;

} // namespace detail

constexpr struct mdspan_non_standard_tag {
} mdspan_non_standard;

} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE
Loading

0 comments on commit 59a70bb

Please sign in to comment.