1

I have a struct which contains some Eigen::Vector3d values. I have a vector of that struct and I want to upload it to the GPU using thrust.

When I did that, I got an error saying that the copy was undefined. I've been trying to understand why it can't use default cudaMemcpy and it looks like Eigen::Vector3d is not trivially_copyable.

I'm trying to understand why its not, but I cant find any reason. AFAIK, Eigen::Vector3d is just 3 continuous double values. Why is that not trivially_copyable? What are the possible errors I can find if I cudaMemcpy that vector by hand directly?

Edit: The question has been marked as a duplicate of thrust device to host undefined cross_system_copy. I don't think its an exact duplicate, although its related. In that question I'm asking if I should do something special to make thrust work with Eigen. In this question I'm asking why a Eigen::Vector3d is not trivially_copyable and asking what can happen if I decide to cudaMemcpy by hand the content of a std::vector. I think they are different enough questions so I decided to ask it as a separate question.

talonmies
  • 70,661
  • 34
  • 192
  • 269
jjcasmar
  • 1,387
  • 1
  • 18
  • 30
  • It should be trivially copyable, since it only contains trivial types. But there is a copy-constructor implemented (which would be `= default`, if that was possible with C++03), which is required for some internal technicalities, I think. You can try to remove the copy constructor from `Matrix` (and maybe from all base classes as well) and see if everything still works. – chtz Mar 19 '19 at 10:03
  • "A trivially copyable class is a class that: has no non-trivial copy constructors, has no non-trivial move constructors, has no non-trivial copy assignment operators, has no non-trivial move assignment operators, and has a trivial destructor." – talonmies Mar 19 '19 at 11:18
  • @talonmies I know I should have been a bit more precise with my wording. What I intended to say was that "nothing should go wrong if you `std::memcpy` an `Eigen::Vector3d`". That is of course not equivalent to "trivially copyable" in the C++-sense. – chtz Mar 19 '19 at 12:19
  • You can't be certain that alignment of host and device structures (especially those over which you have no control of) will be identical . So a byte copy won't be guaranteed to work – talonmies Mar 19 '19 at 18:43
  • In that case, what would be the correct way of sending this to cuda? – jjcasmar Mar 19 '19 at 19:00

0 Answers0