Search code examples
debuggingreleasethrust

thrust inclusive scan completes in debug build but fails in release build


I am using a simple thrust::inclusive scan call on a device vector. In the debug build, this executes without error. However, when executed using the the release build an error is encountered.

Also, this seems to only affect thrust::device<> vectors?

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

I am using eclipse nsight to perform the debug and release builds.

#include <iostream>
using namespace std;

#include <thrust/scan.h>
#include <thrust/device_vector.h>

int main(void) {

    cout << "hello\n";

    int data[6] = {1, 0, 2, 2, 1, 3};

    thrust::inclusive_scan(data, data + 6, data); // in-place scan

    for(int i=0;i<6;i++) cout<< data[i] << "\n";

    cout << "inclusive scan on a device vector\n";

    thrust::device_vector<int> d_C_0(6);

    d_C_0[0] = 1;
    d_C_0[1] = 0;
    d_C_0[2] = 2;
    d_C_0[3] = 2;
    d_C_0[4] = 1;
    d_C_0[5] = 3;

    thrust::inclusive_scan(d_C_0.begin(), d_C_0.begin() + 6, d_C_0.begin()); // in-place scan

    for(int i=0;i<6;i++) cout<< d_C_0[i] << "\n";

    return 0;
}

Solution

  • My guess is that it is failing the debug case but passing in the release case.

    For debug build, Nsight EE normally includes the -G compiler switch.

    Thrust (device code) is often incompatible with the -G switch.

    If you remove the -G switch from the compile command, I believe your code will run normally -- it does for me.

    If that doesn't solve the issue, please provide the complete compile command line that Nsight EE is using for each case (debug and release) as well as which GPU you are running on, and CUDA version (5.0 or 5.5).