Skip to content

Commit

Permalink
Clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
crtrott committed Oct 9, 2024
1 parent e38efe4 commit b0b3431
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 130 deletions.
8 changes: 4 additions & 4 deletions containers/src/Kokkos_DynRankView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ class DynRankView : private View<DataType*******, Properties...> {

private:
#ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
using drdtraits = Impl::DynRankDimTraits<void>;
using drdtraits = Impl::DynRankDimTraits<void>;
#else
using drdtraits = Impl::DynRankDimTraits<typename view_type::specialize>;
using drdtraits = Impl::DynRankDimTraits<typename view_type::specialize>;
#endif
public:
// typedefs from ViewTraits, overriden
Expand Down Expand Up @@ -456,9 +456,9 @@ class DynRankView : private View<DataType*******, Properties...> {
using const_scalar_array_type = const_value_type;
using non_const_scalar_array_type = non_const_value_type;
#ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
using specialize = void;
using specialize = void;
#else
using specialize = typename view_type::specialize;
using specialize = typename view_type::specialize;
#endif

// typedefs in View for mdspan compatibility
Expand Down
138 changes: 55 additions & 83 deletions core/src/Kokkos_View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
using index_type = typename traits::memory_space::size_type;

// FIXME: Should be unsigned
using size_type = typename memory_space::size_type;
using size_type = typename memory_space::size_type;

using scalar_array_type = typename traits::scalar_array_type;
using const_scalar_array_type = typename traits::const_scalar_array_type;
Expand Down Expand Up @@ -333,7 +333,8 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
template <typename... Is>
static KOKKOS_FUNCTION void check_access_member_function_valid_args(Is...) {
// cast to int to work around pointless comparison of unsigned to 0 warning
static_assert(static_cast<int>(sizeof...(Is)) <= static_cast<int>(8 - rank));
static_assert(static_cast<int>(sizeof...(Is)) <=
static_cast<int>(8 - rank));
static_assert(Kokkos::Impl::are_integral<Is...>::value);
}
#endif
Expand Down Expand Up @@ -495,10 +496,14 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
// may assign unmanaged from managed.

template <class OtherT, class... OtherArgs>
// requires(std::is_constructible_v<
// mdspan_type, typename View<OtherT, OtherArgs...>::mdspan_type>)
KOKKOS_INLINE_FUNCTION View(const View<OtherT, OtherArgs...>& other, std::enable_if_t<std::is_constructible_v<
mdspan_type, typename View<OtherT, OtherArgs...>::mdspan_type>, void*> = nullptr)
// requires(std::is_constructible_v<
// mdspan_type, typename View<OtherT, OtherArgs...>::mdspan_type>)
KOKKOS_INLINE_FUNCTION View(
const View<OtherT, OtherArgs...>& other,
std::enable_if_t<
std::is_constructible_v<
mdspan_type, typename View<OtherT, OtherArgs...>::mdspan_type>,
void*> = nullptr)
: base_t(static_cast<typename mdspan_type::data_handle_type>(
other.data_handle()),
static_cast<typename mdspan_type::mapping_type>(other.mapping()),
Expand All @@ -521,18 +526,21 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
// Allocation according to allocation properties and array layout

template <class... P>
explicit inline View(
const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<!Impl::ViewCtorProp<P...>::has_pointer, const typename traits::array_layout&> arg_layout)
explicit inline View(const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<!Impl::ViewCtorProp<P...>::has_pointer,
const typename traits::array_layout&>
arg_layout)
: base_t(
arg_prop,
Impl::mapping_from_array_layout<typename mdspan_type::mapping_type>(
arg_layout)) {}

template <class... P>
KOKKOS_FUNCTION explicit inline View(
const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer, const typename traits::array_layout&> arg_layout)
std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer,
const typename traits::array_layout&>
arg_layout)
: base_t(
arg_prop,
Impl::mapping_from_array_layout<typename mdspan_type::mapping_type>(
Expand All @@ -548,21 +556,23 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
arg_layout)) {}

#ifdef KOKKOS_ENABLE_CXX17
template<class Layout>
KOKKOS_FUNCTION
explicit inline View(const typename base_t::data_handle_type& handle,
const Layout& arg_layout, std::enable_if_t<
(std::is_same_v<Layout, LayoutStride> &&
std::is_same_v<typename base_t::layout_type, layout_stride>) ||
(std::is_same_v<Layout, LayoutLeft> &&
std::is_same_v<typename base_t::layout_type, layout_left>) ||
(std::is_same_v<Layout, LayoutLeft> &&
std::is_same_v<typename base_t::layout_type, Experimental::layout_left_padded<>>) ||
(std::is_same_v<Layout, LayoutRight> &&
std::is_same_v<typename base_t::layout_type, layout_right>) ||
(std::is_same_v<Layout, LayoutRight> &&
std::is_same_v<typename base_t::layout_type, Experimental::layout_right_padded<>>)
, void*> = nullptr)
template <class Layout>
KOKKOS_FUNCTION explicit inline View(
const typename base_t::data_handle_type& handle, const Layout& arg_layout,
std::enable_if_t<
(std::is_same_v<Layout, LayoutStride> &&
std::is_same_v<typename base_t::layout_type, layout_stride>) ||
(std::is_same_v<Layout, LayoutLeft> &&
std::is_same_v<typename base_t::layout_type, layout_left>) ||
(std::is_same_v<Layout, LayoutLeft> &&
std::is_same_v<typename base_t::layout_type,
Experimental::layout_left_padded<> >) ||
(std::is_same_v<Layout, LayoutRight> &&
std::is_same_v<typename base_t::layout_type, layout_right>) ||
(std::is_same_v<Layout, LayoutRight> &&
std::is_same_v<typename base_t::layout_type,
Experimental::layout_right_padded<> >),
void*> = nullptr)
: base_t(
handle,
Impl::mapping_from_array_layout<typename mdspan_type::mapping_type>(
Expand Down Expand Up @@ -637,80 +647,37 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
// Special function to be preferred over the above for passing in 0, NULL or
// nullptr when pointer type is char*
template <class... Args>
// requires(std::is_same_v<pointer_type, char*>)
explicit View(decltype(nullptr), Args... args)
: View(Kokkos::view_wrap(pointer_type(nullptr)), args...) {}
#else
#if 1
template <class P, class... Args, std::enable_if_t<std::is_convertible_v<P, pointer_type>, size_t> = 0ul>
template <
class P, class... Args,
std::enable_if_t<std::is_convertible_v<P, pointer_type>, size_t> = 0ul>
KOKKOS_FUNCTION View(P ptr_, Args... args)
: View(Kokkos::view_wrap(static_cast<pointer_type>(ptr_)), args...) {}

// Special function to be preferred over the above for string literals
// when pointer type is char*
template <class L, class... Args, std::enable_if_t<(std::is_same_v<pointer_type, char*> &&
std::is_same_v<const char*, L>), size_t> = 0ul>
template <class L, class... Args,
std::enable_if_t<(std::is_same_v<pointer_type, char*> &&
std::is_same_v<const char*, L>),
size_t> = 0ul>
explicit View(L label, Args... args)
: View(Kokkos::view_alloc(std::string(label)), args...) {}

// Special function to be preferred over the above for passing in 0, NULL or
// nullptr when pointer type is char*
template <class... Args>
// requires(std::is_same_v<pointer_type, char*>)
explicit View(decltype(nullptr), Args... args)
: View(Kokkos::view_wrap(pointer_type(nullptr)), args...) {}
#else
private:
KOKKOS_FUNCTION
static constexpr std::true_type matches_nullptr(decltype(nullptr)) {
return std::true_type{};
}
template<class T>
KOKKOS_FUNCTION
static constexpr std::enable_if_t<std::is_integral_v<T>,std::true_type> matches_nullptr(T) {
return std::true_type{};
}
template<class T>
KOKKOS_FUNCTION
static constexpr std::enable_if_t<!std::is_integral_v<T>,std::false_type> matches_nullptr(T) {
return std::false_type{};
}
public:
template<class Arg1, class ... Args, std::enable_if_t<
std::is_same_v<pointer_type, char*> ||
std::is_convertible_v<Arg1, pointer_type>
, size_t> = 0ul>
KOKKOS_FUNCTION View(Arg1 arg1, Args... args) {
if constexpr (std::is_same_v<pointer_type, char*>) {
if constexpr(std::is_same_v<const char*, Arg1>) {
// Label
KOKKOS_IF_ON_HOST(View(Kokkos::view_alloc(std::string(arg1)), args...);)
KOKKOS_IF_ON_DEVICE(Kokkos::abort("Calling allocating View constructor on device");)
return;
} else if constexpr(decltype(matches_nullptr(arg1))::value) {
// Nullptr
View(Kokkos::view_wrap(pointer_type(nullptr)), args...);
if constexpr (std::is_integral_v<Arg1>) {
if(arg1 != Arg1(0)) Kokkos::abort("Passing non-zero integer as first View ctor argument");
}
return;
}
}
if constexpr(std::is_convertible_v<Arg1, pointer_type>) {
View(Kokkos::view_wrap(pointer_type(nullptr)), args...);
return;
}
Kokkos::abort("Unexpected View Ctor callpath");
}
#endif
#endif

// Constructor which allows always 8 sizes should be deprecated
template <class... P>
explicit inline View(
const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<!Impl::ViewCtorProp<P...>::has_pointer, const size_t> arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
std::enable_if_t<!Impl::ViewCtorProp<P...>::has_pointer, const size_t>
arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
Expand All @@ -731,7 +698,8 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
template <class... P>
KOKKOS_FUNCTION explicit inline View(
const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer, const size_t> arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer, const size_t>
arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
Expand Down Expand Up @@ -931,14 +899,18 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {

KOKKOS_FUNCTION
constexpr typename base_t::index_type extent(size_t r) const noexcept {
// casting to int to avoid warning for pointeless comparison of unsigned with 0
if (static_cast<int>(r) >= static_cast<int>(base_t::extents_type::rank())) return 1;
// casting to int to avoid warning for pointeless comparison of unsigned
// with 0
if (static_cast<int>(r) >= static_cast<int>(base_t::extents_type::rank()))
return 1;
return base_t::extent(r);
}
KOKKOS_FUNCTION
static constexpr size_t static_extent(size_t r) noexcept {
// casting to int to avoid warning for pointeless comparison of unsigned with 0
if (static_cast<int>(r) >= static_cast<int>(base_t::extents_type::rank())) return 1;
// casting to int to avoid warning for pointeless comparison of unsigned
// with 0
if (static_cast<int>(r) >= static_cast<int>(base_t::extents_type::rank()))
return 1;
size_t value = base_t::extents_type::static_extent(r);
return value == Kokkos::dynamic_extent ? 0 : value;
}
Expand Down
35 changes: 18 additions & 17 deletions core/src/View/Kokkos_BasicView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,25 +407,26 @@ class BasicView {
"execution space");
}
if constexpr (has_exec) {
using prop_exec_space_t = std::remove_cv_t<std::remove_reference_t<decltype(Impl::get_property<
Impl::ExecutionSpaceTag>(prop_copy))>>;
return data_handle_type(Impl::make_shared_allocation_record<ElementType>(
arg_mapping.required_span_size(),
Impl::get_property<Impl::LabelTag>(prop_copy),
Impl::get_property<Impl::MemorySpaceTag>(prop_copy),
std::optional<prop_exec_space_t>{Impl::get_property<Impl::ExecutionSpaceTag>(prop_copy)},
std::integral_constant<bool, alloc_prop::initialize>(),
std::integral_constant<bool, alloc_prop::sequential_host_init>()));
using prop_exec_space_t = std::remove_cv_t<std::remove_reference_t<
decltype(Impl::get_property<Impl::ExecutionSpaceTag>(prop_copy))>>;
return data_handle_type(Impl::make_shared_allocation_record<ElementType>(
arg_mapping.required_span_size(),
Impl::get_property<Impl::LabelTag>(prop_copy),
Impl::get_property<Impl::MemorySpaceTag>(prop_copy),
std::optional<prop_exec_space_t>{
Impl::get_property<Impl::ExecutionSpaceTag>(prop_copy)},
std::integral_constant<bool, alloc_prop::initialize>(),
std::integral_constant<bool, alloc_prop::sequential_host_init>()));
} else {
return data_handle_type(Impl::make_shared_allocation_record<ElementType>(
arg_mapping.required_span_size(),
Impl::get_property<Impl::LabelTag>(prop_copy),
Impl::get_property<Impl::MemorySpaceTag>(prop_copy),
std::optional<execution_space>{std::nullopt},
std::integral_constant<bool, alloc_prop::initialize>(),
std::integral_constant<bool, alloc_prop::sequential_host_init>()));
return data_handle_type(Impl::make_shared_allocation_record<ElementType>(
arg_mapping.required_span_size(),
Impl::get_property<Impl::LabelTag>(prop_copy),
Impl::get_property<Impl::MemorySpaceTag>(prop_copy),
std::optional<execution_space>{std::nullopt},
std::integral_constant<bool, alloc_prop::initialize>(),
std::integral_constant<bool, alloc_prop::sequential_host_init>()));
}
}
}

public:
template <class... P>
Expand Down
24 changes: 12 additions & 12 deletions core/src/View/MDSpan/Kokkos_MDSpan_Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,35 @@ using std::mdspan;
#else
// Opt in for Kokkos::pair to submdspan/subview
// submdspan does only take index_pair_like which is derived from tuple_like
// tuple_like is an enumerated list: tuple, pair, array, complex, ranges::subrange
// Needs to be defined before including mdspan header
// tuple_like is an enumerated list: tuple, pair, array, complex,
// ranges::subrange Needs to be defined before including mdspan header

#include <Kokkos_Pair.hpp>

namespace Kokkos {
namespace detail {
template<class IdxT1, class IdxT2>
KOKKOS_INLINE_FUNCTION
constexpr auto first_of(const pair<IdxT1, IdxT2> &slice) {
template <class IdxT1, class IdxT2>
KOKKOS_INLINE_FUNCTION constexpr auto first_of(
const pair<IdxT1, IdxT2> &slice) {
return slice.first;
}
template<class IdxT1, class IdxT2, class Extents, size_t k>
KOKKOS_INLINE_FUNCTION
constexpr auto last_of(std::integral_constant<size_t, k>, const Extents &,
const pair<IdxT1, IdxT2> &slice) {
template <class IdxT1, class IdxT2, class Extents, size_t k>
KOKKOS_INLINE_FUNCTION constexpr auto last_of(std::integral_constant<size_t, k>,
const Extents &,
const pair<IdxT1, IdxT2> &slice) {
return slice.second;
}

template<class T, class IndexType>
template <class T, class IndexType>
struct index_pair_like;

template <class IdxT1, class IdxT2, class IndexType>
struct index_pair_like<Kokkos::pair<IdxT1, IdxT2>, IndexType> {
static constexpr bool value = std::is_convertible_v<IdxT1, IndexType> &&
std::is_convertible_v<IdxT2, IndexType>;
};
}
}
} // namespace detail
} // namespace Kokkos
#include <mdspan/mdspan.hpp>

#endif
Expand Down
6 changes: 3 additions & 3 deletions core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ template <size_t Pad>
struct is_layout_left_padded<Kokkos::Experimental::layout_left_padded<Pad>>
: public std::true_type {};


template <class ArrayLayout>
struct LayoutFromArrayLayout;

Expand Down Expand Up @@ -258,9 +257,10 @@ struct Padding {
}
};

template <class MappingType, size_t ScalarSize, class ViewCtorProperties, class... Sizes>
template <class MappingType, size_t ScalarSize, class ViewCtorProperties,
class... Sizes>
KOKKOS_INLINE_FUNCTION auto mapping_from_ctor_and_sizes(
const ViewCtorProperties&, const Sizes... args) {
const ViewCtorProperties &, const Sizes... args) {
using layout_t = typename MappingType::layout_type;
using ext_t = typename MappingType::extents_type;
ext_t ext{args...};
Expand Down
10 changes: 5 additions & 5 deletions core/unit_test/TestMDSpanConversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ struct TestViewMDSpanConversion {
using mdspan_type =
Kokkos::mdspan<value_type, extents_type, mdspan_layout_type>;

//static_assert(std::is_constructible_v<natural_mdspan_type, mdspan_type>);
//static_assert(std::is_convertible_v<mdspan_type, natural_mdspan_type> ==
// std::is_convertible_v<mdspan_type, unmanaged_view_type>);
// Manually create an mdspan from ref so we have a valid pointer to play
// with
// static_assert(std::is_constructible_v<natural_mdspan_type, mdspan_type>);
// static_assert(std::is_convertible_v<mdspan_type, natural_mdspan_type> ==
// std::is_convertible_v<mdspan_type, unmanaged_view_type>);
// Manually create an mdspan from ref so we have a valid pointer to play
// with
const auto &exts = mapping.extents();
auto mds = mdspan_type{ref.data(), mapping};

Expand Down
8 changes: 5 additions & 3 deletions core/unit_test/TestViewIsAssignable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ struct TestAssignability {
Kokkos::Impl::ViewMapping<typename ViewTypeDst::traits,
typename ViewTypeSrc::traits
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
,typename ViewTypeDst::specialize
,
typename ViewTypeDst::specialize
#else
,void
,
void
#endif
>;
>;

template <class MappingType>
static void try_assign(
Expand Down
Loading

0 comments on commit b0b3431

Please sign in to comment.