Using device_vector traction as a global variable

Why does the following code break at the end of the main one?

#include <thrust/device_vector.h>

thrust::device_vector<float4> v;

int main(){
    v.resize(1000);
    return 0;
}

      

Mistake:

terminate called after throwing an instance of 'thrust::system::system_error'
what():  unspecified driver error

      

If I use host_vector

instead device_vector

, the code works fine.

Do you think this is a Thrust bug, or am I doing something wrong here?

I tried this on ubuntu 10.10 with cuda 4.0 and on Windows 7 with cuda 6.5. In both cases, the Thrust version is 1.7.

thank

+3


source to share


1 answer


The problem is not a bug in Thrust, and you are not doing something wrong. Rather, it is a design limitation of the CUDA runtime API.

The main reason for the failure is that the destructor for thrust::vector

is called when a variable is out of scope, which happens after the CUDA runtime API context has been demolished. This will throw a runtime error (possibly cudaErrorCudartUnloading

) because the process is trying to call cudaFree

after it has already been disconnected from the CUDA driver.



I am not aware of a workaround other than not using the traction device containers declared in the unit translation scope main()

.

+4


source







All Articles