Skip to content

Commit

Permalink
Fix test for GCC-13
Browse files Browse the repository at this point in the history
It seems that the compiler was optimizing out the write. Adding printing
of the value variable at the end of the destructor also resulted in the
correct behavior. Thus, I changed it to the volatile write.

Drive-by change: do synchronous deep_copy
  • Loading branch information
aprokop committed May 9, 2024
1 parent d2f80a5 commit 476c239
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/tstDetailsKokkosExtUninitializedMemoryAlgorithms.cpp
Expand Up @@ -28,7 +28,11 @@ struct NoDefaultConstructor
KOKKOS_FUNCTION NoDefaultConstructor(int x)
: value(x)
{}
KOKKOS_FUNCTION ~NoDefaultConstructor() { value = -1; }
KOKKOS_FUNCTION ~NoDefaultConstructor()
{
// Make sure compiler does not optimize out the write
*((int volatile *)&value) = -1;
}
};

BOOST_AUTO_TEST_CASE_TEMPLATE(construct_destroy_at, DeviceType,
Expand All @@ -55,7 +59,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(construct_destroy_at, DeviceType,
Kokkos::parallel_for(
"Test::destroy", Kokkos::RangePolicy<ExecutionSpace>(exec, 0, n),
KOKKOS_LAMBDA(int i) { destroy_at(&view(i)); });
Kokkos::deep_copy(exec, view_host, view);
Kokkos::deep_copy(view_host, view);
BOOST_TEST(view_host(0).value == -1);
BOOST_TEST(view_host(1).value == -1);
}

0 comments on commit 476c239

Please sign in to comment.