Skip to content

Commit

Permalink
Address the reviewers' suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gojakuch committed Jul 23, 2024
1 parent c10d76a commit e8dadc3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
30 changes: 17 additions & 13 deletions include/clad/Differentiator/KokkosBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,28 @@ inline void deep_copy_pushforward(const View1& dst, const View2& src, T param,
}

template <class View>
inline void
resize_pushforward(View& v, const size_t n0, const size_t n1, const size_t n2,
const size_t n3, const size_t n4, const size_t n5,
const size_t n6, const size_t n7, View& d_v,
const size_t d_n0, const size_t d_n1, const size_t d_n2,
const size_t d_n3, const size_t d_n4, const size_t d_n5,
const size_t d_n6, const size_t d_n7) {
inline void resize_pushforward(View& v, const size_t n0, const size_t n1,
const size_t n2, const size_t n3,
const size_t n4, const size_t n5,
const size_t n6, const size_t n7, View& d_v,
const size_t /*d_n0*/, const size_t /*d_n1*/,
const size_t /*d_n2*/, const size_t /*d_n3*/,
const size_t /*d_n4*/, const size_t /*d_n5*/,
const size_t /*d_n6*/, const size_t /*d_n7*/) {
::Kokkos::resize(v, n0, n1, n2, n3, n4, n5, n6, n7);
::Kokkos::resize(d_v, n0, n1, n2, n3, n4, n5, n6, n7);
}

template <class I, class dI, class View>
inline void resize_pushforward(
const I& arg, View& v, const size_t n0, const size_t n1, const size_t n2,
const size_t n3, const size_t n4, const size_t n5, const size_t n6,
const size_t n7, const dI& d_arg, View& d_v, const size_t d_n0,
const size_t d_n1, const size_t d_n2, const size_t d_n3, const size_t d_n4,
const size_t d_n5, const size_t d_n6, const size_t d_n7) {
inline void resize_pushforward(const I& arg, View& v, const size_t n0,
const size_t n1, const size_t n2,
const size_t n3, const size_t n4,
const size_t n5, const size_t n6,
const size_t n7, const dI& d_arg, View& d_v,
const size_t /*d_n0*/, const size_t /*d_n1*/,
const size_t /*d_n2*/, const size_t /*d_n3*/,
const size_t /*d_n4*/, const size_t /*d_n5*/,
const size_t /*d_n6*/, const size_t /*d_n7*/) {
::Kokkos::resize(arg, v, n0, n1, n2, n3, n4, n5, n6, n7);
::Kokkos::resize(arg, d_v, n0, n1, n2, n3, n4, n5, n6, n7);
}
Expand Down
44 changes: 44 additions & 0 deletions unittests/Kokkos/ViewBasics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,48 @@ TEST(ViewBasics, TestResize2) {
for (double x = 3; x <= 5; x += 1)
for (double y = 3; y <= 5; y += 1)
EXPECT_NEAR(df.execute(x, y), df_true(x, y), eps);
}

double f_basics_resize_3(double x, double y) {
Kokkos::View<double** [3], Kokkos::LayoutLeft, Kokkos::HostSpace> a("a", 3,
2);
Kokkos::deep_copy(a, 3 * x + y);

Kokkos::resize(Kokkos::WithoutInitializing, a, 5, 5);

a(4, 4, 0) = x * y;

return a(4, 4, 0);
}

TEST(ViewBasics, TestResize3) {
const double eps = 1e-8;

auto df = clad::differentiate(f_basics_resize_3, 0);
auto df_true = [](double x, double y) { return y; };
for (double x = 3; x <= 5; x += 1)
for (double y = 3; y <= 5; y += 1)
EXPECT_NEAR(df.execute(x, y), df_true(x, y), eps);
}

double f_basics_resize_4(double x, double y) {
Kokkos::View<double** [3], Kokkos::LayoutLeft, Kokkos::HostSpace> a("a", 3,
2);
Kokkos::deep_copy(a, 3 * x + y);

Kokkos::resize(a, 5, 5);

a(4, 4, 0) = x * y;

return a(4, 4, 0);
}

TEST(ViewBasics, TestResize4) {
const double eps = 1e-8;

auto df = clad::differentiate(f_basics_resize_4, 0);
auto df_true = [](double x, double y) { return y; };
for (double x = 3; x <= 5; x += 1)
for (double y = 3; y <= 5; y += 1)
EXPECT_NEAR(df.execute(x, y), df_true(x, y), eps);
}

0 comments on commit e8dadc3

Please sign in to comment.