Version Information
cuda : 10.2
g++ : 8
eigen : 3.3.7
Hello
We defined a structure in a .h file with a member variable of type from the eigen library (specifically, we used version 3.3.7), and then we used this structure in a .cc file and a .cu file respectively, and found that the sizes of the two did not match. Further, when we passed the structure as a variable in a function in .cc to a function in a .cu file, a segment fault occurred in the assignment of the member variables in it.
Could you tell me why this is happening and how we can solve this problem?
The definition of the structure and the test code snippet are as follows.
struct test_struct
{
std::vector<float> vec1;
Eigen::Affine3d eigen_test;
std::vector<float> vec2;
};
void test_cuda_class::test_for_nvcc(test_struct t1)
{
std::cout << "=========== in cu ===========" << std::endl;
std::cout << "sizeof t1: " << sizeof(t1) << std::endl;
t1.vec2.assign(10,0); //here we got segment fault
std::cout << "==========^ in cu ^==========" << std::endl;
}
void test_cc_class::test_in_cc()
{
std::cout << "=========== in cc ===========" << std::endl;
test_struct t1;
std::cout << "sizeof t1: " << sizeof(t1) << std::endl;
std::cout << "==========^ in cc ^==========" << std::endl;
test_cuda_class test1_obj;
test1_obj.test_for_nvcc(t1);
}
The printout is as follows.
=========== in cc ===========
sizeof t1: 192
==========^ in cc ^==========
=========== in cu ===========
sizeof t1: 176
Segmentation fault
The complete test code and CMakeLists are shown in the attachment, please note that if you need to run the complete test, please change the address of the eigen library.
CMakeLists.txt (663 Bytes)
main.cc (92 Bytes)
test.cc (321 Bytes)
test.h (160 Bytes)
test_cuda.cu (300 Bytes)
test_cuda.h (378 Bytes)