ManagedArrays copy constructed outside of a lambda capture are broken
EDIT: See my comment below for an even simpler test case.
Data movement is triggered by the copy constructor, right? I have a case where a ManagedArray is a member of a class. The copy constructor of the class is called, which calls the copy constructor of the ManagedArray. However, the following test case fails.
class TestClass {
public:
TestClass(chai::ManagedArray
CUDA_TEST(managed_ptr, cuda_inner_ManagedArray) { const int expectedValue = rand();
chai::ManagedArray
TestClass temp(array);
chai::ManagedArray
forall(cuda(), 0, 1, [=] device (int i) { results[i] = temp.getValue(i); });
results.move(chai::CPU); ASSERT_EQ(results[0], expectedValue); }
Here's an even simpler case.
CUDA_TEST(managed_ptr, cuda_inner_ManagedArray) { const int expectedValue = rand();
chai::ManagedArray
chai::ManagedArray
chai::ManagedArray
forall(cuda(), 0, 1, [=] device (int i) { results[i] = array2[i]; });
results.move(chai::CPU); ASSERT_EQ(results[0], expectedValue); }
Hey @adayton1 your interpretation of how the copy is triggered is correct. I wonder if the array is being "moved" rather than copied.
Does there need to be a call to cudaDeviceSynchronize? I thought the forall called it.
It does: https://github.com/LLNL/CHAI/blob/develop/src/util/forall.hpp#L114