-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MDSpan issues expose by Kokkos View refactor #358
Changes from 4 commits
e861e5c
3bd2ee8
192ffb2
4f551ba
d1af943
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#pragma once | ||
|
||
#include <tuple> | ||
#include <complex> | ||
|
||
#include "strided_slice.hpp" | ||
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { | ||
|
@@ -52,6 +53,33 @@ template <class OffsetType, class ExtentType, class StrideType> | |
struct is_strided_slice< | ||
strided_slice<OffsetType, ExtentType, StrideType>> : std::true_type {}; | ||
|
||
// Helper for identifying valid pair like things | ||
template <class T, class IndexType> struct index_pair_like : std::false_type {}; | ||
|
||
template <class IdxT1, class IdxT2, class IndexType> | ||
struct index_pair_like<std::pair<IdxT1, IdxT2>, IndexType> { | ||
static constexpr bool value = std::is_convertible_v<IdxT1, IndexType> && | ||
std::is_convertible_v<IdxT2, IndexType>; | ||
}; | ||
|
||
template <class IdxT1, class IdxT2, class IndexType> | ||
struct index_pair_like<std::tuple<IdxT1, IdxT2>, IndexType> { | ||
static constexpr bool value = std::is_convertible_v<IdxT1, IndexType> && | ||
std::is_convertible_v<IdxT2, IndexType>; | ||
}; | ||
|
||
template <class IdxT, class IndexType> | ||
struct index_pair_like<std::complex<IdxT>, IndexType> { | ||
static constexpr bool value = std::is_convertible_v<IdxT, IndexType>; | ||
}; | ||
dalg24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
template <class IdxT, class IndexType> | ||
struct index_pair_like<std::array<IdxT, 2>, IndexType> { | ||
static constexpr bool value = std::is_convertible_v<IdxT, IndexType>; | ||
}; | ||
|
||
// FIXME: we actually need to pass IndexType into all of these | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is left to do? |
||
|
||
// first_of(slice): getting begin of slice specifier range | ||
MDSPAN_TEMPLATE_REQUIRES( | ||
class Integral, | ||
|
@@ -70,13 +98,19 @@ first_of(const ::MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent_t &) { | |
|
||
MDSPAN_TEMPLATE_REQUIRES( | ||
class Slice, | ||
/* requires */(std::is_convertible_v<Slice, std::tuple<size_t, size_t>>) | ||
/* requires */(index_pair_like<Slice, size_t>::value) | ||
) | ||
MDSPAN_INLINE_FUNCTION | ||
constexpr auto first_of(const Slice &i) { | ||
return std::get<0>(i); | ||
} | ||
|
||
template<class T> | ||
MDSPAN_INLINE_FUNCTION | ||
constexpr auto first_of(const std::complex<T> &i) { | ||
return i.real(); | ||
} | ||
|
||
template <class OffsetType, class ExtentType, class StrideType> | ||
MDSPAN_INLINE_FUNCTION | ||
constexpr OffsetType | ||
|
@@ -100,14 +134,20 @@ constexpr Integral | |
|
||
MDSPAN_TEMPLATE_REQUIRES( | ||
size_t k, class Extents, class Slice, | ||
/* requires */(std::is_convertible_v<Slice, std::tuple<size_t, size_t>>) | ||
/* requires */(index_pair_like<Slice, size_t>::value) | ||
) | ||
MDSPAN_INLINE_FUNCTION | ||
constexpr auto last_of(std::integral_constant<size_t, k>, const Extents &, | ||
const Slice &i) { | ||
return std::get<1>(i); | ||
} | ||
|
||
template<size_t k, class Extents, class T> | ||
MDSPAN_INLINE_FUNCTION | ||
constexpr auto last_of(std::integral_constant<size_t, k>, const Extents &, const std::complex<T> &i) { | ||
return i.imag(); | ||
} | ||
|
||
// Suppress spurious warning with NVCC about no return statement. | ||
// This is a known issue in NVCC and NVC++ | ||
// Depending on the CUDA and GCC version we need both the builtin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,7 @@ struct padded_extent { | |
using static_array_type = typename static_array_type_for_padded_extent< | ||
padding_value, _Extents, _ExtentToPadIdx, _Extents::rank()>::type; | ||
|
||
MDSPAN_INLINE_FUNCTION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you actually need this or did you just add for consistency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
static constexpr auto static_value() { return static_array_type::static_value(0); } | ||
|
||
MDSPAN_INLINE_FUNCTION | ||
|
@@ -203,7 +204,7 @@ class layout_left_padded<PaddingValue>::mapping { | |
} | ||
|
||
public: | ||
#if !MDSPAN_HAS_CXX_20 | ||
#if !MDSPAN_HAS_CXX_20 || defined(__NVCC__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the problem here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NVCC does not like the requires stuff down there. Basically, it ends up saying that there is not default constructor on the device available in C++20 mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to narrow it down in a simple reproducer. |
||
MDSPAN_INLINE_FUNCTION_DEFAULTED | ||
constexpr mapping() | ||
: mapping(extents_type{}) | ||
|
@@ -347,7 +348,7 @@ class layout_left_padded<PaddingValue>::mapping { | |
MDSPAN_INLINE_FUNCTION | ||
constexpr mapping(const _Mapping &other_mapping) noexcept | ||
: padded_stride(padded_stride_type::init_padding( | ||
other_mapping.extents(), | ||
static_cast<extents_type>(other_mapping.extents()), | ||
other_mapping.extents().extent(extent_to_pad_idx))), | ||
exts(other_mapping.extents()) {} | ||
|
||
|
@@ -566,7 +567,7 @@ class layout_right_padded<PaddingValue>::mapping { | |
} | ||
|
||
public: | ||
#if !MDSPAN_HAS_CXX_20 | ||
#if !MDSPAN_HAS_CXX_20 || defined(__NVCC__) | ||
MDSPAN_INLINE_FUNCTION_DEFAULTED | ||
constexpr mapping() | ||
: mapping(extents_type{}) | ||
|
@@ -707,7 +708,7 @@ class layout_right_padded<PaddingValue>::mapping { | |
MDSPAN_INLINE_FUNCTION | ||
constexpr mapping(const _Mapping &other_mapping) noexcept | ||
: padded_stride(padded_stride_type::init_padding( | ||
other_mapping.extents(), | ||
static_cast<extents_type>(other_mapping.extents()), | ||
other_mapping.extents().extent(extent_to_pad_idx))), | ||
exts(other_mapping.extents()) {} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature macro for complex
get
support is called __cpp_lib_tuple_like so maybeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has nothing to do with get: https://eel.is/c++draft/views.multidim#mdspan.syn
We are using an exposition only concept called
index-pair-like
and if you follow all the stuff down to their roots, this thing here basically implements that concept in form of atype_trait
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I looked at
get
was that that's what is used infirst_of
which now uses this concept as requirement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed that by adding special versions for complex.