Skip to content

Commit

Permalink
More CUDA fixes exposed during Kokkos integration
Browse files Browse the repository at this point in the history
  • Loading branch information
crtrott committed Jun 17, 2024
1 parent e01c4c6 commit 99d810b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/experimental/__p0009_bits/extents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace detail {
// Function used to check compatibility of extents in converting constructor
// can't be a private member function for some reason.
template <size_t... Extents, size_t... OtherExtents>
MDSPAN_INLINE_FUNCTION
static constexpr std::integral_constant<bool, false> __check_compatible_extents(
std::integral_constant<bool, false>,
std::integer_sequence<size_t, Extents...>,
Expand All @@ -49,6 +50,7 @@ struct __compare_extent_compatible : std::integral_constant<bool,
{};

template <size_t... Extents, size_t... OtherExtents>
MDSPAN_INLINE_FUNCTION
static constexpr std::integral_constant<
bool, _MDSPAN_FOLD_AND(__compare_extent_compatible<Extents, OtherExtents>::value)>
__check_compatible_extents(
Expand Down
6 changes: 6 additions & 0 deletions include/experimental/__p0009_bits/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ template <std::size_t N>
using with_rank = std::integral_constant<std::size_t, N>;

template <class I1, class I2>
MDSPAN_INLINE_FUNCTION
constexpr bool common_integral_compare(I1 x, I2 y)
{
static_assert(std::is_integral<I1>::value &&
Expand All @@ -24,11 +25,14 @@ constexpr bool common_integral_compare(I1 x, I2 y)
}

template <class T1, class T2, class F>
MDSPAN_INLINE_FUNCTION
constexpr bool rankwise_equal(with_rank<0>, const T1&, const T2&, F)
{
return true;
}

template <std::size_t N, class T1, class T2, class F>
MDSPAN_INLINE_FUNCTION
constexpr bool rankwise_equal(with_rank<N>, const T1& x, const T2& y, F func)
{
bool match = true;
Expand All @@ -43,6 +47,7 @@ constexpr bool rankwise_equal(with_rank<N>, const T1& x, const T2& y, F func)
constexpr struct
{
template <class T, class I>
MDSPAN_INLINE_FUNCTION
constexpr auto operator()(const T& x, I i) const
{
return x.extent(i);
Expand All @@ -52,6 +57,7 @@ constexpr struct
constexpr struct
{
template <class T, class I>
MDSPAN_INLINE_FUNCTION
constexpr auto operator()(const T& x, I i) const
{
return x.stride(i);
Expand Down
22 changes: 18 additions & 4 deletions include/experimental/__p2630_bits/submdspan_mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,19 @@ MDSPAN_IMPL_PROPOSED_NAMESPACE::layout_left_padded<PaddingValue>::mapping<Extent
out_of_bounds ? this->required_span_size()
: this->operator()(MDSPAN_IMPL_STANDARD_NAMESPACE::detail::first_of(slices)...));
if constexpr (dst_ext_t::rank() == 0) { // result rank-0
using dst_mapping_t = typename layout_left::template mapping<dst_ext_t>;
return submdspan_mapping_result<dst_mapping_t>{dst_mapping_t{dst_ext}, offset};
// The following for some reasons leads to compiler error later, while not using a typedef works:
// Compilers: CUDA 11.2 with GCC 9.1
//
// using dst_mapping_t = typename layout_left::template mapping<dst_ext_t>;
// return submdspan_mapping_result<dst_mapping_t>{dst_mapping_t{dst_ext}, offset};
//
// Error: submdspan_mapping.hpp:299:23: error: 'dst_mapping_t' does not name a type
// 299 | using dst_mapping_t = typename layout_left::template mapping<dst_ext_t>;
// The same error is given (about dst_mapping_t not naming type) when a different name is used in 299:
// using dst_mapping_t2 = typename layout_left::template mapping<dst_ext_t>;

return submdspan_mapping_result<typename layout_left::template mapping<dst_ext_t>>
{typename layout_left::template mapping<dst_ext_t>{dst_ext}, offset};
} else { // general case
// Figure out if any slice's lower bound equals the corresponding extent.
// If so, bypass evaluating the layout mapping. This fixes LWG Issue 4060.
Expand Down Expand Up @@ -509,8 +520,11 @@ MDSPAN_IMPL_PROPOSED_NAMESPACE::layout_right_padded<PaddingValue>::mapping<Exten
out_of_bounds ? this->required_span_size()
: this->operator()(MDSPAN_IMPL_STANDARD_NAMESPACE::detail::first_of(slices)...));
if constexpr (dst_ext_t::rank() == 0) { // result rank-0
using dst_mapping_t = typename layout_right::template mapping<dst_ext_t>;
return submdspan_mapping_result<dst_mapping_t>{dst_mapping_t{dst_ext}, offset};
// Same issue as in layout_left_padded: see comment there
// using dst_mapping_t = typename layout_right::template mapping<dst_ext_t>;
// return submdspan_mapping_result<dst_mapping_t>{dst_mapping_t{dst_ext}, offset};
return submdspan_mapping_result<typename layout_right::template mapping<dst_ext_t>>
{typename layout_right::template mapping<dst_ext_t>{dst_ext}, offset};
} else { // general case
using deduce_layout = MDSPAN_IMPL_STANDARD_NAMESPACE::detail::deduce_layout_right_submapping<
typename dst_ext_t::index_type, dst_ext_t::rank(),
Expand Down

0 comments on commit 99d810b

Please sign in to comment.