The following code is from the answer of Converting thrust::iterators to and from raw pointers
It compiles ok, but when run under CUDA 6.0, it report thrust::system::system_error after exclusive_scan (the trace stack is full of exclusive_scan relavant information)
#include <cuda_runtime.h>
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
#include <thrust/scan.h>
#include <thrust/fill.h>
#include <thrust/copy.h>
#include <cstdio>
#pragma comment(lib,"cudart.lib")
int main()
{
const int N = 16;
int * a;
cudaMalloc((void**)&a, N*sizeof(int));
thrust::device_ptr<int> d = thrust::device_pointer_cast(a);
thrust::fill(d, d+N, 2);
thrust::device_vector<int> v(N);
thrust::exclusive_scan(d, d+N, v.begin());
int v_[N];
thrust::copy(v.begin(), v.end(), v_);
for(int i=0; i<N; i++)
printf("%d %d\n", i, v_[i]);
return 0;
}
what's wrong in that code?(the code is published 2 years ago, and the people who answer it says it runs ok. I think he's using CUDA 4.0 or lower. But the code fails to run after CUDA 5.0) I'm using VS 2012 and CUDA 6.0 (compute_13,sm_13)
You are compiling a debug project which is adding the -G
switch. This can be problematic with Thrust. Switch to a release project, which will remove the -G
switch.
I tried the following combinations:
-G -arch=sm_20
-arch=sm_20
-arch=sm_13
and all produced code that ran OK.
When I did this:
-G -arch=sm_13
I was able to reproduce the error you are seeing. (All tests on CUDA 6)