Skip to content

Commit

Permalink
Reduce number of View constructor instantiations
Browse files Browse the repository at this point in the history
View constructors with templated label take std::string
and runtime unmanaged View constructors taking pointers now constrained.

This reduces the number of instantiation when passing C string arguments
to the View constructors.

Co-authored-by: Christian Trott <crtrott@sandia.gov>
  • Loading branch information
dalg24 and crtrott committed Oct 26, 2023
1 parent 0b59a1b commit 840d6b7
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions core/src/Kokkos_View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,26 +1489,20 @@ class View : public ViewTraits<DataType, Properties...> {
}

// Allocate with label and layout
template <typename Label>
explicit inline View(
const Label& arg_label,
std::enable_if_t<Kokkos::Impl::is_view_label<Label>::value,
typename traits::array_layout> const& arg_layout)
explicit inline View(std::string const& arg_label,
typename traits::array_layout const& arg_layout)
: View(Impl::ViewCtorProp<std::string>(arg_label), arg_layout) {}

// Allocate label and layout, must disambiguate from subview constructor.
template <typename Label>
explicit inline View(
const Label& arg_label,
std::enable_if_t<Kokkos::Impl::is_view_label<Label>::value, 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,
const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
explicit inline View(std::string const& arg_label,
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,
const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
: View(Impl::ViewCtorProp<std::string>(arg_label),
typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
arg_N4, arg_N5, arg_N6, arg_N7)) {
Expand Down Expand Up @@ -1565,8 +1559,10 @@ class View : public ViewTraits<DataType, Properties...> {
arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
}

template <class PointerType, class = std::enable_if_t<std::is_convertible_v<
PointerType, pointer_type>>>
explicit KOKKOS_INLINE_FUNCTION View(
pointer_type arg_ptr, const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
PointerType arg_ptr, 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 @@ -1582,8 +1578,10 @@ class View : public ViewTraits<DataType, Properties...> {
"overload taking a layout object instead.");
}

template <class PointerType, class = std::enable_if_t<std::is_convertible_v<
PointerType, pointer_type>>>
explicit KOKKOS_INLINE_FUNCTION View(
pointer_type arg_ptr, const typename traits::array_layout& arg_layout)
PointerType arg_ptr, const typename traits::array_layout& arg_layout)
: View(Impl::ViewCtorProp<pointer_type>(arg_ptr), arg_layout) {}

//----------------------------------------
Expand Down

0 comments on commit 840d6b7

Please sign in to comment.