Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ManagedArrays copy constructed outside of a lambda capture are broken #66

Open
adayton1 opened this issue Feb 15, 2019 · 4 comments
Open

Comments

@adayton1
Copy link
Member

adayton1 commented Feb 15, 2019

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 values) : m_values(values) {}
TestClass(const TestClass& other) : m_values(other.m_values) {}
CHAI_HOST_DEVICE int getValue(const int i) const { return m_values[i]; }
private:
chai::ManagedArray m_values;
};

CUDA_TEST(managed_ptr, cuda_inner_ManagedArray)
{
const int expectedValue = rand();

chai::ManagedArray array(1, chai::CPU);
array[0] = expectedValue;

TestClass temp(array);
chai::ManagedArray results(1, chai::GPU);

forall(cuda(), 0, 1, [=] device (int i) {
results[i] = temp.getValue(i);
});

results.move(chai::CPU);
ASSERT_EQ(results[0], expectedValue);
}

@adayton1
Copy link
Member Author

Here's an even simpler case.

CUDA_TEST(managed_ptr, cuda_inner_ManagedArray)
{
const int expectedValue = rand();

chai::ManagedArray array(1, chai::CPU);
array[0] = expectedValue;

chai::ManagedArray array2 = array;

chai::ManagedArray results(1, chai::GPU);

forall(cuda(), 0, 1, [=] device (int i) {
results[i] = array2[i];
});

results.move(chai::CPU);
ASSERT_EQ(results[0], expectedValue);
}

@adayton1 adayton1 changed the title ManagedArrays inside classes do not work ManagedArrays copy constructed outside of a lambda capture are broken Feb 15, 2019
@davidbeckingsale
Copy link
Member

Hey @adayton1 your interpretation of how the copy is triggered is correct. I wonder if the array is being "moved" rather than copied.

@adayton1
Copy link
Member Author

Does there need to be a call to cudaDeviceSynchronize? I thought the forall called it.

@davidbeckingsale
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants