When declare a static thrust::device_vector in a function, wrapped into dll, it cause cudaErrorCudartUnloading (error 29) during the end of the program. It seems that the cuda context is destroyed before the deconstructor of device_vector. When declared in a normal function, there is no error. Could someone explain the reason for this?
I tried creating a c++ class dll in project 1, then add reference of project 1 to porject 2, where the main.cpp is. Finally I instantiate the class in main.cpp and call the function, the function works fine but the program has trouble during termination while it's trying to release the static devive_vector defined in dll.
// Project 1: Foo.h
#include <thrust/device_vector.h>
class __declspec(dllexport) Foo {
public:
Foo() {};
~Foo() {};
void FooFcn();
};
// Project 1: Foo.cu
void Foo::FooFcn() {
static thrust::device_vector<int> a;
a.resize(500000);
}
// Project 2: main.cpp
#include "Foo.h"
int main()
{
Foo foo;
foo.FooFcn();
return 0;
}
cudaErrorCudartUnloading (error 29) is the asserted error if you tried to run this.