Skip to content

Commit

Permalink
update mdspan tpl to latest stable
Browse files Browse the repository at this point in the history
  • Loading branch information
nmm0 committed Jun 3, 2024
1 parent bb66390 commit ae3f664
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 125 deletions.
2 changes: 1 addition & 1 deletion tpls/mdspan/include/experimental/__p0009_bits/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static_assert(_MDSPAN_CPLUSPLUS >= MDSPAN_CXX_STD_14, "mdspan requires C++14 or
#endif

#ifndef _MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
# if (!defined(__NVCC__) || (__CUDACC_VER_MAJOR__ >= 11 && __CUDACC_VER_MINOR__ >= 7)) && \
# if (!defined(__NVCC__) || (__CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__ * 10 >= 1170)) && \
((defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201703) || \
(!defined(__cpp_deduction_guides) && MDSPAN_HAS_CXX_17))
# define _MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
Expand Down
93 changes: 83 additions & 10 deletions tpls/mdspan/include/experimental/__p0009_bits/extents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

#pragma once
#include "dynamic_extent.hpp"
#include "utility.hpp"

#ifdef __cpp_lib_span
#include <span>
#endif
#include <array>
#include <type_traits>

#include <cassert>
#include <cinttypes>

namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
Expand Down Expand Up @@ -59,8 +62,8 @@ template<class IndexType, class ... Arguments>
MDSPAN_INLINE_FUNCTION
static constexpr bool are_valid_indices() {
return
(std::is_convertible<Arguments, IndexType>::value && ... && true) &&
(std::is_nothrow_constructible<IndexType, Arguments>::value && ... && true);
_MDSPAN_FOLD_AND(std::is_convertible<Arguments, IndexType>::value) &&
_MDSPAN_FOLD_AND(std::is_nothrow_constructible<IndexType, Arguments>::value);
}

// ------------------------------------------------------------------
Expand Down Expand Up @@ -538,14 +541,9 @@ template <class IndexType, size_t... Extents> class extents {
MDSPAN_INLINE_FUNCTION friend constexpr bool
operator==(const extents &lhs,
const extents<OtherIndexType, OtherExtents...> &rhs) noexcept {
if constexpr (rank() != extents<OtherIndexType, OtherExtents...>::rank()) {
return false;
} else {
using common_t = std::common_type_t<index_type, OtherIndexType>;
for (size_type r = 0; r < m_rank; r++)
if(static_cast<common_t>(rhs.extent(r)) != static_cast<common_t>(lhs.extent(r))) return false;
}
return true;
return
rank() == extents<OtherIndexType, OtherExtents...>::rank() &&
detail::rankwise_equal(detail::with_rank<rank()>{}, rhs, lhs, detail::extent);
}

#if !(MDSPAN_HAS_CXX_20)
Expand Down Expand Up @@ -614,5 +612,80 @@ static
#endif
constexpr bool __is_extents_v = __is_extents<T>::value;

template<class InputIndexType, class ExtentsIndexType>
MDSPAN_INLINE_FUNCTION
constexpr void
check_lower_bound(InputIndexType user_index,
ExtentsIndexType /* current_extent */,
std::true_type /* is_signed */)
{
(void) user_index; // prevent unused variable warning
#ifdef _MDSPAN_DEBUG
assert(static_cast<ExtentsIndexType>(user_index) >= 0);
#endif
}

template<class InputIndexType, class ExtentsIndexType>
MDSPAN_INLINE_FUNCTION
constexpr void
check_lower_bound(InputIndexType /* user_index */,
ExtentsIndexType /* current_extent */,
std::false_type /* is_signed */)
{}

template<class InputIndexType, class ExtentsIndexType>
MDSPAN_INLINE_FUNCTION
constexpr void
check_upper_bound(InputIndexType user_index,
ExtentsIndexType current_extent)
{
(void) user_index; // prevent unused variable warnings
(void) current_extent;
#ifdef _MDSPAN_DEBUG
assert(static_cast<ExtentsIndexType>(user_index) < current_extent);
#endif
}

// Returning true to use AND fold instead of comma
// CPP14 mode doesn't like the use of void expressions
// with the way the _MDSPAN_FOLD_AND is set up
template<class InputIndex, class ExtentsIndexType>
MDSPAN_INLINE_FUNCTION
constexpr bool
check_one_index(InputIndex user_index,
ExtentsIndexType current_extent)
{
check_lower_bound(user_index, current_extent,
std::integral_constant<bool, std::is_signed<ExtentsIndexType>::value>{});
check_upper_bound(user_index, current_extent);
return true;
}

template<size_t ... RankIndices,
class ExtentsIndexType, size_t ... Exts,
class ... Indices>
MDSPAN_INLINE_FUNCTION
constexpr void
check_all_indices_helper(std::index_sequence<RankIndices...>,
const extents<ExtentsIndexType, Exts...>& exts,
Indices... indices)
{
// Suppress warning about statement has no effect
(void) _MDSPAN_FOLD_AND(
(check_one_index(indices, exts.extent(RankIndices)))
);
}

template<class ExtentsIndexType, size_t ... Exts,
class ... Indices>
MDSPAN_INLINE_FUNCTION
constexpr void
check_all_indices(const extents<ExtentsIndexType, Exts...>& exts,
Indices... indices)
{
check_all_indices_helper(std::make_index_sequence<sizeof...(Indices)>(),
exts, indices...);
}

} // namespace detail
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE
26 changes: 11 additions & 15 deletions tpls/mdspan/include/experimental/__p0009_bits/layout_left.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#include "macros.hpp"
#include "trait_backports.hpp"
#include "extents.hpp"
#include "layout_stride.hpp"
#include "utility.hpp"
#if MDSPAN_HAS_CXX_17
#include "../__p2642_bits/layout_padded_fwd.hpp"
#include <cassert>
#endif
#include <type_traits>

namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
Expand Down Expand Up @@ -133,11 +136,11 @@ class layout_left::mapping {
: __extents(__other.extents())
{
MDSPAN_IMPL_PROPOSED_NAMESPACE::detail::
check_padded_layout_converting_constructor_mandates<extents_type,
_Mapping>();
check_padded_layout_converting_constructor_mandates<
extents_type, _Mapping>(detail::with_rank<extents_type::rank()>{});
MDSPAN_IMPL_PROPOSED_NAMESPACE::detail::
check_padded_layout_converting_constructor_preconditions<
extents_type>(__other);
extents_type>(detail::with_rank<extents_type::rank()>{}, __other);
}
#endif

Expand All @@ -156,17 +159,7 @@ class layout_left::mapping {
* TODO: check precondition
* other.required_span_size() is a representable value of type index_type
*/
#if !defined(_MDSPAN_HAS_CUDA) && !defined(_MDSPAN_HAS_HIP) && !defined(NDEBUG)
if constexpr (extents_type::rank() > 0) {
index_type stride = 1;
using common_t = std::common_type_t<index_type, typename OtherExtents::index_type>;
for(rank_type r=0; r<__extents.rank(); r++) {
if(static_cast<common_t>(stride) != static_cast<common_t>(other.stride(r)))
std::abort(); // ("Assigning layout_stride to layout_left with invalid strides.");
stride *= __extents.extent(r);
}
}
#endif
detail::validate_strides(detail::with_rank<extents_type::rank()>{}, layout_left{}, __extents, other);
}

MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED mapping& operator=(mapping const&) noexcept = default;
Expand Down Expand Up @@ -194,6 +187,9 @@ class layout_left::mapping {
)
_MDSPAN_HOST_DEVICE
constexpr index_type operator()(Indices... idxs) const noexcept {
#if ! defined(NDEBUG)
detail::check_all_indices(this->extents(), idxs...);
#endif // ! NDEBUG
return __compute_offset(__rank_count<0, extents_type::rank()>(), static_cast<index_type>(idxs)...);
}

Expand Down
25 changes: 10 additions & 15 deletions tpls/mdspan/include/experimental/__p0009_bits/layout_right.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
#include "macros.hpp"
#include "trait_backports.hpp"
#include "extents.hpp"
#include <stdexcept>
#include "layout_stride.hpp"
#include "utility.hpp"
#if MDSPAN_HAS_CXX_17
#include "../__p2642_bits/layout_padded_fwd.hpp"
#endif

namespace MDSPAN_IMPL_STANDARD_NAMESPACE {

Expand Down Expand Up @@ -134,11 +136,11 @@ class layout_right::mapping {
: __extents(__other.extents())
{
MDSPAN_IMPL_PROPOSED_NAMESPACE::detail::
check_padded_layout_converting_constructor_mandates<extents_type,
_Mapping>();
check_padded_layout_converting_constructor_mandates<
extents_type, _Mapping>(detail::with_rank<extents_type::rank()>{});
MDSPAN_IMPL_PROPOSED_NAMESPACE::detail::
check_padded_layout_converting_constructor_preconditions<
extents_type>(__other);
extents_type>(detail::with_rank<extents_type::rank()>{}, __other);
}
#endif

Expand All @@ -157,17 +159,7 @@ class layout_right::mapping {
* TODO: check precondition
* other.required_span_size() is a representable value of type index_type
*/
#if !defined(_MDSPAN_HAS_CUDA) && !defined(_MDSPAN_HAS_HIP) && !defined(NDEBUG)
if constexpr (extents_type::rank() > 0) {
index_type stride = 1;
using common_t = std::common_type_t<index_type, typename OtherExtents::index_type>;
for(rank_type r=__extents.rank(); r>0; r--) {
if(static_cast<common_t>(stride) != static_cast<common_t>(other.stride(r-1)))
std::abort(); // ("Assigning layout_stride to layout_right with invalid strides.");
stride *= __extents.extent(r-1);
}
}
#endif
detail::validate_strides(detail::with_rank<extents_type::rank()>{}, layout_right{}, __extents, other);
}

MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED mapping& operator=(mapping const&) noexcept = default;
Expand Down Expand Up @@ -195,6 +187,9 @@ class layout_right::mapping {
)
_MDSPAN_HOST_DEVICE
constexpr index_type operator()(Indices... idxs) const noexcept {
#if ! defined(NDEBUG)
detail::check_all_indices(this->extents(), idxs...);
#endif // ! NDEBUG
return __compute_offset(__rank_count<0, extents_type::rank()>(), static_cast<index_type>(idxs)...);
}

Expand Down
Loading

0 comments on commit ae3f664

Please sign in to comment.