0

I am trying to compute in-place prefix sum on device_vector from Thrust library. The following snippet doesn't work:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

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

int main()
{
    thrust::device_vector<float> vector(4);
    vector[0] = 1.0;
    vector[1] = -3.0;
    vector[2] = 4.0;
    vector[3] = 5.0;

    thrust::inclusive_scan(vector.begin(), vector.end(), vector.begin());
    thrust::host_vector<float> h_vector(vector.begin(), vector.end());

    for (size_t i = 0; i < 4; ++i) {
        std::cout << h_vector[i] << std::endl;
    }
    return 0;
}

It throws some exception on a line with inclusive_scan call. What am I doing wrong?

  • I am going to guess than scan requires the vector length to be >2. What would happen if you added a couple of extra elements? (Presuming that you actually have a working CUDA installation...) – talonmies Jun 01 '14 at 10:47
  • @talonmies Nope. Added couple of elements, still doesn't work (changed my question to reflect that edit). As for working CUDA installation -- template project code that sums two vectors does work. – AndrewShulaev Jun 01 '14 at 10:57
  • The code you currently have in your question works as expected for me. I will repeat my question about being sure you have a working CUDA installation. If I can't reproduce your problem, I can't tell you what might be wrong, sorry. What host platform and CUDA version are you running this on and how are your compiling the code? – talonmies Jun 01 '14 at 11:28
  • @talonmies I have CUDA v5.5 running from Visual Studio 2012 Professional. If you will point how can I provide more useful diagnostic information, I would happily do that. – AndrewShulaev Jun 01 '14 at 12:27
  • 1
    are you compiling a release project or are you compiling a debug project under Visual Studio? Compiling a debug project adds the `-G` switch, and [thrust codes may not work well with that](https://github.com/thrust/thrust/wiki/Debugging). Related to this, it may help if you identify the cuda and thrust versions you are using, and whether or not other codes (such as cuda sample codes) can be compiled and run correctly on your platform. If compiling a debug project, try switching to a release project and see if the problem goes away. – Robert Crovella Jun 01 '14 at 13:49
  • @RobertCrovella Yep, I am compiling from debug project and according to "Build" tab output, it does compile with -G key. Thank you for suggestion, I'll investigate this further. – AndrewShulaev Jun 01 '14 at 14:57

0 Answers0