Skip to content

Commit

Permalink
Do not use Unmanaged traits explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuichi Asahi committed Oct 24, 2024
1 parent 715cc0d commit 1788f06
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
4 changes: 1 addition & 3 deletions common/unit_test/Test_Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,13 @@ template <typename ValueType1, typename ValueType2>
void test_are_pointers_aliasing() {
using View1 = Kokkos::View<ValueType1*, execution_space>;
using View2 = Kokkos::View<ValueType2*, execution_space>;
using UView2 = Kokkos::View<ValueType2*, execution_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;

const int n1 = 10;
// sizeof ValeuType2 is larger or equal to ValueType1
const int n2 = sizeof(ValueType1) == sizeof(ValueType2) ? n1 : n1 / 2 + 1;
View1 view1("view1", n1);
View2 view2("view2", n1);
UView2 uview2(reinterpret_cast<ValueType2*>(view1.data()), n2);
View2 uview2(reinterpret_cast<ValueType2*>(view1.data()), n2);

EXPECT_TRUE(KokkosFFT::Impl::are_aliasing(view1.data(), uview2.data()));
EXPECT_FALSE(KokkosFFT::Impl::are_aliasing(view1.data(), view2.data()));
Expand Down
5 changes: 1 addition & 4 deletions fft/src/KokkosFFT_Plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,7 @@ class Plan {
// For the in-place Complex to Real transform, the output must be
// reshaped to fit the original size (in.size() * 2) for correct
// normalization
using UnmanagedOutViewType =
Kokkos::View<out_value_type*, execSpace,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
UnmanagedOutViewType out_tmp(out.data(), in.size() * 2);
Kokkos::View<out_value_type*, execSpace> out_tmp(out.data(), in.size() * 2);
KokkosFFT::Impl::normalize(m_exec_space, out_tmp, m_direction, norm,
m_fft_size);
return;
Expand Down
39 changes: 17 additions & 22 deletions fft/unit_test/Test_Transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,18 @@ void test_fft1_identity(T atol = 1.0e-12) {

template <typename T, typename LayoutType>
void test_fft1_identity_inplace(T atol = 1.0e-12) {
const int maxlen = 32;
using RealView1DType = Kokkos::View<T*, LayoutType, execution_space>;
using RealUView1DType = Kokkos::View<T*, LayoutType, execution_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
const int maxlen = 32;
using RealView1DType = Kokkos::View<T*, LayoutType, execution_space>;
using ComplexView1DType =
Kokkos::View<Kokkos::complex<T>*, LayoutType, execution_space>;
using ComplexUView1DType =
Kokkos::View<Kokkos::complex<T>*, LayoutType, execution_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;

for (int i = 1; i < maxlen; i++) {
ComplexView1DType a("a", i), a_ref("a_ref", i);
ComplexUView1DType a_hat(a.data(), i), inv_a_hat(a.data(), i);
ComplexView1DType a_hat(a.data(), i), inv_a_hat(a.data(), i);

// Used for Real transforms
ComplexView1DType ar_hat("ar_hat", i / 2 + 1);
RealUView1DType ar(reinterpret_cast<T*>(ar_hat.data()), i),
RealView1DType ar(reinterpret_cast<T*>(ar_hat.data()), i),
inv_ar_hat(reinterpret_cast<T*>(ar_hat.data()), i);
RealView1DType ar_ref("ar_ref", i);

Expand Down Expand Up @@ -1675,17 +1670,12 @@ void test_fft2_2dfft_2dview_shape(T atol = 1.0e-12) {
template <typename T, typename LayoutType>
void test_fft2_2dfft_2dview_inplace([[maybe_unused]] T atol = 1.0e-12) {
const int n0 = 4, n1 = 6;
using RealView2DType = Kokkos::View<T**, LayoutType, execution_space>;
using RealUView2DType = Kokkos::View<T**, LayoutType, execution_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
using RealView2DType = Kokkos::View<T**, LayoutType, execution_space>;
using ComplexView2DType =
Kokkos::View<Kokkos::complex<T>**, LayoutType, execution_space>;
using ComplexUView2DType =
Kokkos::View<Kokkos::complex<T>**, LayoutType, execution_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;

ComplexView2DType x("x", n0, n1), x_ref("x_ref", n0, n1);
ComplexUView2DType x_hat(x.data(), n0, n1), inv_x_hat(x.data(), n0, n1);
ComplexView2DType x_hat(x.data(), n0, n1), inv_x_hat(x.data(), n0, n1);

// Used for real transforms
ComplexView2DType xr_hat("xr_hat", n0, n1 / 2 + 1),
Expand All @@ -1695,16 +1685,16 @@ void test_fft2_2dfft_2dview_inplace([[maybe_unused]] T atol = 1.0e-12) {
inv_xr_hat_ref("inv_xr_hat_ref", n0, n1);

// Unmanged views for in-place transforms
RealUView2DType xr(reinterpret_cast<T*>(xr_hat.data()), n0, n1),
RealView2DType xr(reinterpret_cast<T*>(xr_hat.data()), n0, n1),
inv_xr_hat(reinterpret_cast<T*>(xr_hat.data()), n0, n1);
RealUView2DType xr_padded(reinterpret_cast<T*>(xr_hat.data()), n0,
(n1 / 2 + 1) * 2),
RealView2DType xr_padded(reinterpret_cast<T*>(xr_hat.data()), n0,
(n1 / 2 + 1) * 2),
inv_xr_hat_padded(reinterpret_cast<T*>(xr_hat.data()), n0,
(n1 / 2 + 1) * 2);

// Initialize xr_hat through xr_padded
auto sub_xr_padded =
Kokkos::subview(xr_padded, Kokkos::ALL(), Kokkos::pair<int, int>(0, n1));
Kokkos::subview(xr_padded, Kokkos::ALL, Kokkos::pair<int, int>(0, n1));

const Kokkos::complex<T> z(1.0, 1.0);
Kokkos::Random_XorShift64_Pool<> random_pool(12345);
Expand Down Expand Up @@ -1736,6 +1726,8 @@ void test_fft2_2dfft_2dview_inplace([[maybe_unused]] T atol = 1.0e-12) {
KokkosFFT::Normalization::backward, axes);
KokkosFFT::ifft2(execution_space(), x_hat, inv_x_hat,
KokkosFFT::Normalization::backward, axes);

Kokkos::fence();
EXPECT_TRUE(allclose(inv_x_hat, x_ref, 1.e-5, atol));

// In-place transforms
Expand All @@ -1745,6 +1737,8 @@ void test_fft2_2dfft_2dview_inplace([[maybe_unused]] T atol = 1.0e-12) {
// Out-of-place transforms (reference)
KokkosFFT::rfft2(execution_space(), xr_ref, xr_hat_ref,
KokkosFFT::Normalization::backward, axes);

Kokkos::fence();
EXPECT_TRUE(allclose(xr_hat, xr_hat_ref, 1.e-5, atol));

// In-place transforms
Expand All @@ -1757,8 +1751,9 @@ void test_fft2_2dfft_2dview_inplace([[maybe_unused]] T atol = 1.0e-12) {
KokkosFFT::irfft2(execution_space(), xr_hat_ref, inv_xr_hat_ref,
KokkosFFT::Normalization::backward, axes);

auto sub_inv_xr_hat_padded = Kokkos::subview(
inv_xr_hat_padded, Kokkos::ALL(), Kokkos::pair<int, int>(0, n1));
Kokkos::fence();
auto sub_inv_xr_hat_padded = Kokkos::subview(inv_xr_hat_padded, Kokkos::ALL,
Kokkos::pair<int, int>(0, n1));
Kokkos::deep_copy(inv_xr_hat_unpadded, sub_inv_xr_hat_padded);

EXPECT_TRUE(allclose(inv_xr_hat_unpadded, inv_xr_hat_ref, 1.e-5, atol));
Expand Down

0 comments on commit 1788f06

Please sign in to comment.