Simple CUDA Thrust Program Error

2019-01-29 12:15发布

问题:

I just write an simple CUDA Thrust program, but when I run it. I got this error: thrust::system::system_error at position 0x0037f99c .

Can someone help me to figure out why this happen?

#include<thrust\host_vector.h>
#include<thrust\device_vector.h>
#include<iostream>
using namespace std;
using namespace thrust;
int main()
{

    thrust::host_vector<int> h_vec(3);
    h_vec[0]=1;h_vec[1]=2;h_vec[2]=3;
    thrust::device_vector<int> d_vec(3) ;
    d_vec= h_vec;
    int h_sum = thrust::reduce(h_vec.begin(), h_vec.end());
    int d_sum = thrust::reduce(d_vec.begin(), d_vec.end());
return 0;
}

回答1:

A few suggestions with Thrust:

  • If you are compiling your code with -G and having trouble, try compiling without -G
  • You can catch the errors that thrust throws, to get more information.
  • It's always recommended to compile your code for the architecture of the GPU you are using. So if you are on a cc2.0 GPU, compile with -arch=sm_20. If you are on a cc3.0 GPU, compile with -arch=sm_30 etc.
  • Finally, it's recommended to build a 64-bit project. On windows you would select a release/x64 project.


标签: cuda thrust