Skip to content

Commit

Permalink
Avoid variables from underscore under common and fft (#180)
Browse files Browse the repository at this point in the history
* avoid variables from underscore under fft

* Add reserved-identifier check in clang-tidy

* rename variables starting from underscore under common/src

* rename ariables starting from underscore under common/unit_test

* rename variables starting from underscore under fft/src

---------

Co-authored-by: Yuuichi Asahi <[email protected]>
  • Loading branch information
yasahi-hpc and Yuuichi Asahi authored Oct 28, 2024
1 parent aa6a94d commit 7c10f22
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 469 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception

Checks: '-*,modernize-type-traits,modernize-use-using,modernize-use-nullptr,cppcoreguidelines-pro-type-cstyle-cast'
Checks: '-*,modernize-type-traits,modernize-use-using,modernize-use-nullptr,cppcoreguidelines-pro-type-cstyle-cast,bugprone-reserved-identifier'
FormatStyle: file
HeaderFileExtensions: ['h','hh','hpp','hxx']
ImplementationFileExtensions: ['c','cc','cpp','cxx']
Expand Down
92 changes: 46 additions & 46 deletions common/src/KokkosFFT_transpose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ axis_type<ViewType::rank()> compute_transpose_extents(

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

using range_type = Kokkos::MDRangePolicy<
Expand All @@ -115,7 +115,7 @@ void transpose_impl(const ExecutionSpace& exec_space, const InViewType& in,

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

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

Kokkos::Array<int, rank> map = to_array(_map);
Kokkos::Array<int, rank> map_array = to_array(map);
Kokkos::parallel_for(
"KokkosFFT::transpose", range, KOKKOS_LAMBDA(int i0, int i1, int i2) {
int dst_indices[rank] = {i0, i1, i2};
int dst_i0 = dst_indices[map[0]];
int dst_i1 = dst_indices[map[1]];
int dst_i2 = dst_indices[map[2]];
int dst_i0 = dst_indices[map_array[0]];
int dst_i1 = dst_indices[map_array[1]];
int dst_i2 = dst_indices[map_array[2]];

out(dst_i0, dst_i1, dst_i2) = in(i0, i1, i2);
});
}

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

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

Kokkos::Array<int, rank> map = to_array(_map);
Kokkos::Array<int, rank> map_array = to_array(map);
Kokkos::parallel_for(
"KokkosFFT::transpose", range,
KOKKOS_LAMBDA(int i0, int i1, int i2, int i3) {
int dst_indices[rank] = {i0, i1, i2, i3};
int dst_i0 = dst_indices[map[0]];
int dst_i1 = dst_indices[map[1]];
int dst_i2 = dst_indices[map[2]];
int dst_i3 = dst_indices[map[3]];
int dst_i0 = dst_indices[map_array[0]];
int dst_i1 = dst_indices[map_array[1]];
int dst_i2 = dst_indices[map_array[2]];
int dst_i3 = dst_indices[map_array[3]];

out(dst_i0, dst_i1, dst_i2, dst_i3) = in(i0, i1, i2, i3);
});
}

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

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

Kokkos::Array<int, rank> map = to_array(_map);
Kokkos::Array<int, rank> map_array = to_array(map);
Kokkos::parallel_for(
"KokkosFFT::transpose", range,
KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4) {
int dst_indices[rank] = {i0, i1, i2, i3, i4};
int dst_i0 = dst_indices[map[0]];
int dst_i1 = dst_indices[map[1]];
int dst_i2 = dst_indices[map[2]];
int dst_i3 = dst_indices[map[3]];
int dst_i4 = dst_indices[map[4]];
int dst_i0 = dst_indices[map_array[0]];
int dst_i1 = dst_indices[map_array[1]];
int dst_i2 = dst_indices[map_array[2]];
int dst_i3 = dst_indices[map_array[3]];
int dst_i4 = dst_indices[map_array[4]];

out(dst_i0, dst_i1, dst_i2, dst_i3, dst_i4) = in(i0, i1, i2, i3, i4);
});
}

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

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

Kokkos::Array<int, rank> map = to_array(_map);
Kokkos::Array<int, rank> map_array = to_array(map);
Kokkos::parallel_for(
"KokkosFFT::transpose", range,
KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4, int i5) {
int dst_indices[rank] = {i0, i1, i2, i3, i4, i5};
int dst_i0 = dst_indices[map[0]];
int dst_i1 = dst_indices[map[1]];
int dst_i2 = dst_indices[map[2]];
int dst_i3 = dst_indices[map[3]];
int dst_i4 = dst_indices[map[4]];
int dst_i5 = dst_indices[map[5]];
int dst_i0 = dst_indices[map_array[0]];
int dst_i1 = dst_indices[map_array[1]];
int dst_i2 = dst_indices[map_array[2]];
int dst_i3 = dst_indices[map_array[3]];
int dst_i4 = dst_indices[map_array[4]];
int dst_i5 = dst_indices[map_array[5]];

out(dst_i0, dst_i1, dst_i2, dst_i3, dst_i4, dst_i5) =
in(i0, i1, i2, i3, i4, i5);
Expand All @@ -255,7 +255,7 @@ void transpose_impl(const ExecutionSpace& exec_space, const InViewType& in,

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

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

Kokkos::Array<int, rank> map = to_array(_map);
Kokkos::Array<int, rank> map_array = to_array(map);
Kokkos::parallel_for(
"KokkosFFT::transpose", range,
KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4, int i5) {
for (int i6 = 0; i6 < n6; i6++) {
int dst_indices[rank] = {i0, i1, i2, i3, i4, i5, i6};
int dst_i0 = dst_indices[map[0]];
int dst_i1 = dst_indices[map[1]];
int dst_i2 = dst_indices[map[2]];
int dst_i3 = dst_indices[map[3]];
int dst_i4 = dst_indices[map[4]];
int dst_i5 = dst_indices[map[5]];
int dst_i6 = dst_indices[map[6]];
int dst_i0 = dst_indices[map_array[0]];
int dst_i1 = dst_indices[map_array[1]];
int dst_i2 = dst_indices[map_array[2]];
int dst_i3 = dst_indices[map_array[3]];
int dst_i4 = dst_indices[map_array[4]];
int dst_i5 = dst_indices[map_array[5]];
int dst_i6 = dst_indices[map_array[6]];

out(dst_i0, dst_i1, dst_i2, dst_i3, dst_i4, dst_i5, dst_i6) =
in(i0, i1, i2, i3, i4, i5, i6);
Expand All @@ -297,7 +297,7 @@ void transpose_impl(const ExecutionSpace& exec_space, const InViewType& in,

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

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

Kokkos::Array<int, rank> map = to_array(_map);
Kokkos::Array<int, rank> map_array = to_array(map);
Kokkos::parallel_for(
"KokkosFFT::transpose", range,
KOKKOS_LAMBDA(int i0, int i1, int i2, int i3, int i4, int i5) {
for (int i6 = 0; i6 < n6; i6++) {
for (int i7 = 0; i7 < n7; i7++) {
int dst_indices[rank] = {i0, i1, i2, i3, i4, i5, i6, i7};
int dst_i0 = dst_indices[map[0]];
int dst_i1 = dst_indices[map[1]];
int dst_i2 = dst_indices[map[2]];
int dst_i3 = dst_indices[map[3]];
int dst_i4 = dst_indices[map[4]];
int dst_i5 = dst_indices[map[5]];
int dst_i6 = dst_indices[map[6]];
int dst_i7 = dst_indices[map[7]];
int dst_i0 = dst_indices[map_array[0]];
int dst_i1 = dst_indices[map_array[1]];
int dst_i2 = dst_indices[map_array[2]];
int dst_i3 = dst_indices[map_array[3]];
int dst_i4 = dst_indices[map_array[4]];
int dst_i5 = dst_indices[map_array[5]];
int dst_i6 = dst_indices[map_array[6]];
int dst_i7 = dst_indices[map_array[7]];

out(dst_i0, dst_i1, dst_i2, dst_i3, dst_i4, dst_i5, dst_i6,
dst_i7) = in(i0, i1, i2, i3, i4, i5, i6, i7);
Expand Down
101 changes: 52 additions & 49 deletions common/unit_test/Test_Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ void test_fft_freq(T atol = 1.0e-12) {
auto h_x_odd_ref = Kokkos::create_mirror_view(x_odd_ref);
auto h_x_even_ref = Kokkos::create_mirror_view(x_even_ref);

std::vector<int> _x_odd_ref = {0, 1, 2, 3, 4, -4, -3, -2, -1};
std::vector<int> _x_even_ref = {0, 1, 2, 3, 4, -5, -4, -3, -2, -1};
std::vector<int> tmp_x_odd_ref = {0, 1, 2, 3, 4, -4, -3, -2, -1};
std::vector<int> tmp_x_even_ref = {0, 1, 2, 3, 4, -5, -4, -3, -2, -1};

for (std::size_t i = 0; i < _x_odd_ref.size(); i++) {
h_x_odd_ref(i) = static_cast<T>(_x_odd_ref.at(i));
for (std::size_t i = 0; i < tmp_x_odd_ref.size(); i++) {
h_x_odd_ref(i) = static_cast<T>(tmp_x_odd_ref.at(i));
}

for (std::size_t i = 0; i < _x_even_ref.size(); i++) {
h_x_even_ref(i) = static_cast<T>(_x_even_ref.at(i));
for (std::size_t i = 0; i < tmp_x_even_ref.size(); i++) {
h_x_even_ref(i) = static_cast<T>(tmp_x_even_ref.at(i));
}

Kokkos::deep_copy(x_odd_ref, h_x_odd_ref);
Expand Down Expand Up @@ -82,15 +82,15 @@ void test_rfft_freq(T atol = 1.0e-12) {
auto h_x_odd_ref = Kokkos::create_mirror_view(x_odd_ref);
auto h_x_even_ref = Kokkos::create_mirror_view(x_even_ref);

std::vector<int> _x_odd_ref = {0, 1, 2, 3, 4};
std::vector<int> _x_even_ref = {0, 1, 2, 3, 4, 5};
std::vector<int> tmp_x_odd_ref = {0, 1, 2, 3, 4};
std::vector<int> tmp_x_even_ref = {0, 1, 2, 3, 4, 5};

for (std::size_t i = 0; i < _x_odd_ref.size(); i++) {
h_x_odd_ref(i) = static_cast<T>(_x_odd_ref.at(i));
for (std::size_t i = 0; i < tmp_x_odd_ref.size(); i++) {
h_x_odd_ref(i) = static_cast<T>(tmp_x_odd_ref.at(i));
}

for (std::size_t i = 0; i < _x_even_ref.size(); i++) {
h_x_even_ref(i) = static_cast<T>(_x_even_ref.at(i));
for (std::size_t i = 0; i < tmp_x_even_ref.size(); i++) {
h_x_even_ref(i) = static_cast<T>(tmp_x_even_ref.at(i));
}

Kokkos::deep_copy(x_odd_ref, h_x_odd_ref);
Expand Down Expand Up @@ -218,20 +218,20 @@ void test_fftshift1D_1DView(int n0) {
auto h_x_ref = Kokkos::create_mirror_view(x_ref);
auto h_y_ref = Kokkos::create_mirror_view(y_ref);

std::vector<int> _x_ref;
std::vector<int> _y_ref;
std::vector<int> tmp_x_ref;
std::vector<int> tmp_y_ref;

if (n0 % 2 == 0) {
_x_ref = {0, 1, 2, 3, 4, -5, -4, -3, -2, -1};
_y_ref = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4};
tmp_x_ref = {0, 1, 2, 3, 4, -5, -4, -3, -2, -1};
tmp_y_ref = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4};
} else {
_x_ref = {0, 1, 2, 3, 4, -4, -3, -2, -1};
_y_ref = {-4, -3, -2, -1, 0, 1, 2, 3, 4};
tmp_x_ref = {0, 1, 2, 3, 4, -4, -3, -2, -1};
tmp_y_ref = {-4, -3, -2, -1, 0, 1, 2, 3, 4};
}

for (int i = 0; i < n0; i++) {
h_x_ref(i) = static_cast<double>(_x_ref.at(i));
h_y_ref(i) = static_cast<double>(_y_ref.at(i));
h_x_ref(i) = static_cast<double>(tmp_x_ref.at(i));
h_y_ref(i) = static_cast<double>(tmp_y_ref.at(i));
}

Kokkos::deep_copy(x_ref, h_x_ref);
Expand Down Expand Up @@ -261,34 +261,35 @@ void test_fftshift1D_2DView(int n0) {
auto h_y_axis0_ref = Kokkos::create_mirror_view(y_axis0_ref);
auto h_y_axis1_ref = Kokkos::create_mirror_view(y_axis1_ref);

std::vector<int> _x_ref;
std::vector<int> _y0_ref, _y1_ref;
std::vector<int> tmp_x_ref;
std::vector<int> tmp_y0_ref, tmp_y1_ref;

if (n0 % 2 == 0) {
_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
-15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
_y0_ref = {
tmp_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, -15, -14, -13, -12, -11,
-10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
tmp_y0_ref = {
5, 6, 7, 8, 9, 0, 1, 2, 3, 4, -15, -14, -13, -12, -11,
10, 11, 12, 13, 14, -5, -4, -3, -2, -1, -10, -9, -8, -7, -6,
};
_y1_ref = {-10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, -15, -14, -13, -12, -11};
tmp_y1_ref = {-10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, -15, -14, -13, -12, -11};
} else {
_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
-13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
_y0_ref = {5, 6, 7, 8, 0, 1, 2, 3, 4, -13, -12, -11, -10, 9,
10, 11, 12, 13, -4, -3, -2, -1, -9, -8, -7, -6, -5};
_y1_ref = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, -13, -12, -11, -10};
tmp_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
-13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
tmp_y0_ref = {5, 6, 7, 8, 0, 1, 2, 3, 4, -13, -12, -11, -10, 9,
10, 11, 12, 13, -4, -3, -2, -1, -9, -8, -7, -6, -5};
tmp_y1_ref = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, -13, -12, -11, -10};
}

for (int i1 = 0; i1 < n1; i1++) {
for (int i0 = 0; i0 < n0; i0++) {
std::size_t i = i0 + i1 * n0;
h_x_ref(i0, i1) = static_cast<double>(_x_ref.at(i));
h_y_axis0_ref(i0, i1) = static_cast<double>(_y0_ref.at(i));
h_y_axis1_ref(i0, i1) = static_cast<double>(_y1_ref.at(i));
h_x_ref(i0, i1) = static_cast<double>(tmp_x_ref.at(i));
h_y_axis0_ref(i0, i1) = static_cast<double>(tmp_y0_ref.at(i));
h_y_axis1_ref(i0, i1) = static_cast<double>(tmp_y1_ref.at(i));
}
}

Expand Down Expand Up @@ -325,26 +326,28 @@ void test_fftshift2D_2DView(int n0) {
auto h_x_ref = Kokkos::create_mirror_view(x_ref);
auto h_y_ref = Kokkos::create_mirror_view(y_ref);

std::vector<int> _x_ref;
std::vector<int> _y_ref;
std::vector<int> tmp_x_ref;
std::vector<int> tmp_y_ref;

if (n0 % 2 == 0) {
_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
-15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
_y_ref = {-5, -4, -3, -2, -1, -10, -9, -8, -7, -6, 5, 6, 7, 8, 9,
0, 1, 2, 3, 4, -15, -14, -13, -12, -11, 10, 11, 12, 13, 14};
tmp_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, -15, -14, -13, -12, -11,
-10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
tmp_y_ref = {-5, -4, -3, -2, -1, -10, -9, -8, -7, -6,
5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
-15, -14, -13, -12, -11, 10, 11, 12, 13, 14};
} else {
_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
-13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
_y_ref = {-4, -3, -2, -1, -9, -8, -7, -6, -5, 5, 6, 7, 8, 0,
1, 2, 3, 4, -13, -12, -11, -10, 9, 10, 11, 12, 13};
tmp_x_ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
-13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
tmp_y_ref = {-4, -3, -2, -1, -9, -8, -7, -6, -5, 5, 6, 7, 8, 0,
1, 2, 3, 4, -13, -12, -11, -10, 9, 10, 11, 12, 13};
}

for (int i1 = 0; i1 < n1; i1++) {
for (int i0 = 0; i0 < n0; i0++) {
std::size_t i = i0 + i1 * n0;
h_x_ref(i0, i1) = static_cast<double>(_x_ref.at(i));
h_y_ref(i0, i1) = static_cast<double>(_y_ref.at(i));
h_x_ref(i0, i1) = static_cast<double>(tmp_x_ref.at(i));
h_y_ref(i0, i1) = static_cast<double>(tmp_y_ref.at(i));
}
}

Expand Down
Loading

0 comments on commit 7c10f22

Please sign in to comment.