Skip to content

Commit

Permalink
Rename: unuse under score in util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuichi Asahi committed Jul 6, 2024
1 parent 714e563 commit a763274
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 65 deletions.
12 changes: 6 additions & 6 deletions common/src/KokkosFFT_normalization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace KokkosFFT {
namespace Impl {
template <typename ExecutionSpace, typename ViewType, typename T>
void _normalize(const ExecutionSpace& exec_space, ViewType& inout,
const T coef) {
void normalize_impl(const ExecutionSpace& exec_space, ViewType& inout,
const T coef) {
std::size_t size = inout.size();
auto* data = inout.data();

Expand All @@ -24,8 +24,8 @@ void _normalize(const ExecutionSpace& exec_space, ViewType& inout,
}

template <typename ViewType>
auto _coefficients(ViewType, Direction direction, Normalization normalization,
std::size_t fft_size) {
auto coefficients_impl(ViewType, Direction direction,
Normalization normalization, std::size_t fft_size) {
using value_type =
KokkosFFT::Impl::real_type_t<typename ViewType::non_const_value_type>;
value_type coef = 1;
Expand Down Expand Up @@ -63,8 +63,8 @@ void normalize(const ExecutionSpace& exec_space, ViewType& inout,
Direction direction, Normalization normalization,
std::size_t fft_size) {
auto [coef, to_normalize] =
_coefficients(inout, direction, normalization, fft_size);
if (to_normalize) _normalize(exec_space, inout, coef);
coefficients_impl(inout, direction, normalization, fft_size);
if (to_normalize) normalize_impl(exec_space, inout, coef);
}

inline auto swap_direction(Normalization normalization) {
Expand Down
38 changes: 18 additions & 20 deletions common/src/KokkosFFT_padding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ auto is_crop_or_pad_needed(const ViewType& view,
"is_crop_or_pad_needed: Rank of View must be equal to Rank "
"of extended shape.");

// [TO DO] Add a is_C2R arg. If is_C2R is true, then shape should be shape/2+1
constexpr int rank = static_cast<int>(ViewType::rank());

bool not_same = false;
bool not_same = false;
for (int i = 0; i < rank; i++) {
if (modified_shape.at(i) != view.extent(i)) {
not_same = true;
Expand All @@ -103,8 +101,8 @@ auto is_crop_or_pad_needed(const ViewType& view,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<1> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<1> s) {
auto _n0 = s.at(0);
out = OutViewType("out", _n0);

Expand All @@ -117,8 +115,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<2> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<2> s) {
constexpr std::size_t DIM = 2;

auto [_n0, _n1] = s;
Expand All @@ -143,8 +141,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<3> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<3> s) {
constexpr std::size_t DIM = 3;

auto [_n0, _n1, _n2] = s;
Expand Down Expand Up @@ -172,8 +170,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<4> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<4> s) {
constexpr std::size_t DIM = 4;

auto [_n0, _n1, _n2, _n3] = s;
Expand Down Expand Up @@ -202,8 +200,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<5> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<5> s) {
constexpr std::size_t DIM = 5;

auto [_n0, _n1, _n2, _n3, _n4] = s;
Expand Down Expand Up @@ -233,8 +231,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<6> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<6> s) {
constexpr std::size_t DIM = 6;

auto [_n0, _n1, _n2, _n3, _n4, _n5] = s;
Expand Down Expand Up @@ -266,8 +264,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<7> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<7> s) {
constexpr std::size_t DIM = 6;

auto [_n0, _n1, _n2, _n3, _n4, _n5, _n6] = s;
Expand Down Expand Up @@ -302,8 +300,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<8> s) {
void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, shape_type<8> s) {
constexpr std::size_t DIM = 6;

auto [_n0, _n1, _n2, _n3, _n4, _n5, _n6, _n7] = s;
Expand Down Expand Up @@ -351,7 +349,7 @@ void crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in,
static_assert(OutViewType::rank() == DIM,
"crop_or_pad: Rank of View must be equal to Rank "
"of extended shape.");
_crop_or_pad(exec_space, in, out, s);
crop_or_pad_impl(exec_space, in, out, s);
}
} // namespace Impl
} // namespace KokkosFFT
Expand Down
64 changes: 30 additions & 34 deletions common/src/KokkosFFT_transpose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ auto get_map_axes(const ViewType& view, int axis) {
}

template <class InViewType, class OutViewType, std::size_t DIMS>
void _prep_transpose_view(InViewType& in, OutViewType& out,
axis_type<DIMS> _map) {
void prep_transpose_view(InViewType& in, OutViewType& out,
axis_type<DIMS> map) {
constexpr int rank = OutViewType::rank();

// Assign a View if not a shallow copy
bool is_out_view_ready = true;
std::array<int, rank> out_extents;
for (int i = 0; i < rank; i++) {
out_extents.at(i) = in.extent(_map.at(i));
out_extents.at(i) = in.extent(map.at(i));
if (static_cast<std::size_t>(out_extents.at(i)) != out.extent(i)) {
is_out_view_ready = false;
}
Expand All @@ -111,16 +111,9 @@ void _prep_transpose_view(InViewType& in, OutViewType& out,
}
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType,
std::enable_if_t<InViewType::rank() == 1, std::nullptr_t> = nullptr>
void _transpose(const ExecutionSpace&, InViewType&, OutViewType&,
axis_type<1>) {
// FIXME: Comment why empty?
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<2> _map) {
void transpose_impl(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<2> _map) {
constexpr std::size_t DIM = 2;

using range_type = Kokkos::MDRangePolicy<
Expand All @@ -136,15 +129,15 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
// [TO DO] Choose optimal tile sizes for each device
);

_prep_transpose_view(in, out, _map);
prep_transpose_view(in, out, _map);

Kokkos::parallel_for(
range, KOKKOS_LAMBDA(int i0, int i1) { out(i1, i0) = in(i0, i1); });
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<3> _map) {
void transpose_impl(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<3> _map) {
constexpr std::size_t DIM = 3;
constexpr std::size_t rank = InViewType::rank();

Expand All @@ -161,7 +154,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
tile_type{{4, 4, 4}} // [TO DO] Choose optimal tile sizes for each device
);

_prep_transpose_view(in, out, _map);
prep_transpose_view(in, out, _map);

Kokkos::Array<int, 3> map = {_map[0], _map[1], _map[2]};
Kokkos::parallel_for(
Expand All @@ -176,8 +169,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<4> _map) {
void transpose_impl(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<4> _map) {
constexpr std::size_t DIM = 4;
constexpr std::size_t rank = InViewType::rank();

Expand All @@ -195,7 +188,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
// [TO DO] Choose optimal tile sizes for each device
);

_prep_transpose_view(in, out, _map);
prep_transpose_view(in, out, _map);

Kokkos::Array<int, rank> map = {_map[0], _map[1], _map[2], _map[3]};
Kokkos::parallel_for(
Expand All @@ -211,8 +204,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<5> _map) {
void transpose_impl(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<5> _map) {
constexpr std::size_t DIM = 5;
constexpr std::size_t rank = InViewType::rank();

Expand All @@ -231,7 +224,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
// [TO DO] Choose optimal tile sizes for each device
);

_prep_transpose_view(in, out, _map);
prep_transpose_view(in, out, _map);

Kokkos::Array<int, rank> map = {_map[0], _map[1], _map[2], _map[3], _map[4]};
Kokkos::parallel_for(
Expand All @@ -248,8 +241,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<6> _map) {
void transpose_impl(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<6> _map) {
constexpr std::size_t DIM = 6;
constexpr std::size_t rank = InViewType::rank();

Expand All @@ -269,7 +262,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
// [TO DO] Choose optimal tile sizes for each device
);

_prep_transpose_view(in, out, _map);
prep_transpose_view(in, out, _map);

Kokkos::Array<int, rank> map = {_map[0], _map[1], _map[2],
_map[3], _map[4], _map[5]};
Expand All @@ -288,8 +281,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<7> _map) {
void transpose_impl(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<7> _map) {
constexpr std::size_t DIM = 6;
constexpr std::size_t rank = InViewType::rank();

Expand All @@ -309,7 +302,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
// [TO DO] Choose optimal tile sizes for each device
);

_prep_transpose_view(in, out, _map);
prep_transpose_view(in, out, _map);

Kokkos::Array<int, rank> map = {_map[0], _map[1], _map[2], _map[3],
_map[4], _map[5], _map[6]};
Expand All @@ -332,8 +325,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
}

template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void _transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<8> _map) {
void transpose_impl(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<8> _map) {
constexpr std::size_t DIM = 6;

constexpr std::size_t rank = InViewType::rank();
Expand All @@ -355,7 +348,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
// [TO DO] Choose optimal tile sizes for each device
);

_prep_transpose_view(in, out, _map);
prep_transpose_view(in, out, _map);

Kokkos::Array<int, rank> map = {_map[0], _map[1], _map[2], _map[3],
_map[4], _map[5], _map[6], _map[7]};
Expand Down Expand Up @@ -402,7 +395,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in,
template <typename ExecutionSpace, typename InViewType, typename OutViewType,
std::size_t DIM = 1>
void transpose(const ExecutionSpace& exec_space, InViewType& in,
OutViewType& out, axis_type<DIM> _map) {
OutViewType& out, axis_type<DIM> map) {
static_assert(Kokkos::is_view<InViewType>::value,
"transpose: InViewType is not a Kokkos::View.");
static_assert(Kokkos::is_view<InViewType>::value,
Expand All @@ -416,11 +409,14 @@ void transpose(const ExecutionSpace& exec_space, InViewType& in,
"transpose: Rank of View must be equal to Rank of "
"transpose axes.");

if (!KokkosFFT::Impl::is_transpose_needed(_map)) {
if (!KokkosFFT::Impl::is_transpose_needed(map)) {
throw std::runtime_error("transpose: transpose not necessary");
}

_transpose(exec_space, in, out, _map);
// in order not to call transpose_impl for 1D case
if constexpr (DIM > 1) {
transpose_impl(exec_space, in, out, map);
}
}
} // namespace Impl
} // namespace KokkosFFT
Expand Down
10 changes: 5 additions & 5 deletions common/unit_test/Test_prep_transpose_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void test_managed_prep_transpose_view() {
InViewType in("in", layout);
OutViewType out("out", layout);
auto data_prev = out.data();
KokkosFFT::Impl::_prep_transpose_view(in, out, map);
KokkosFFT::Impl::prep_transpose_view(in, out, map);
// ensure no allocation
EXPECT_EQ(data_prev, out.data());
// check shape
Expand All @@ -60,7 +60,7 @@ void test_managed_prep_transpose_view() {
}
InViewType in("in", layout);
OutViewType out;
KokkosFFT::Impl::_prep_transpose_view(in, out, map);
KokkosFFT::Impl::prep_transpose_view(in, out, map);
// check shape
for (int i = 0; i < DIMS; ++i) {
EXPECT_EQ(out.extent(i), 5);
Expand Down Expand Up @@ -96,7 +96,7 @@ void test_unmanaged_prep_transpose_view() {
OutManagedViewType out("out", layout);
OutViewType u_out(out.data(), layout);
auto data_prev = out.data();
KokkosFFT::Impl::_prep_transpose_view(in, u_out, map);
KokkosFFT::Impl::prep_transpose_view(in, u_out, map);
EXPECT_EQ(data_prev, u_out.data());
// check shape
for (int i = 0; i < DIMS; ++i) {
Expand Down Expand Up @@ -126,7 +126,7 @@ void test_unmanaged_prep_transpose_view() {
InManagedViewType in("in", layout);
OutManagedViewType out("out", layout_orig);
OutViewType u_out(out.data(), layout_orig);
KokkosFFT::Impl::_prep_transpose_view(in, u_out, map);
KokkosFFT::Impl::prep_transpose_view(in, u_out, map);
// check shape
for (int i = 0; i < DIMS; ++i) {
EXPECT_EQ(u_out.extent(i), 5);
Expand All @@ -148,7 +148,7 @@ void test_unmanaged_prep_transpose_view() {
InManagedViewType in("in", layout);
OutManagedViewType out("out", layout_orig);
OutViewType u_out(out.data(), layout_orig);
EXPECT_THROW(KokkosFFT::Impl::_prep_transpose_view(in, u_out, map),
EXPECT_THROW(KokkosFFT::Impl::prep_transpose_view(in, u_out, map),
std::runtime_error);
}
}
Expand Down

0 comments on commit a763274

Please sign in to comment.