2
votes

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
Probably you're not generating the right kind of code for your gpu's architecture. Catch the system_error and print out its .what() message to find out what the error is.Jared Hoberock
I was able to successfully compile and run your code. Please check the suggestion given by JaredHoberock in above.Sagar Masuti
I use CUDA Wizard to generate the project. I think the generation of code have no problem. The system error is generate by "int d_sum = thrust::reduce(d_vec.begin(), d_vec.end());" The error information is:synchronize: launch_closure_by_values:unspecified launch failure. BTW, while compile the program, I receive a lot warning like: Cannot tell what pointer points to, assuming global memory space. I use memory-check to check the program. It crashed. My GPU is Quadro K2000,CPU is Xeon E5. What's wrong? When I use CUSP library. It also crash when generating sparse matrix. --@Jared Hoberockuser3072616
Oh the problem solved. As you suggested, I change the kind of device code generation mode to "compute_20,sm_20". It works. Thank you very much @Jared Hoberockuser3072616
Does someone want to add this as an answer so we can getbthis off the unanswered list?talonmies

1 Answers

3
votes

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.