mimre
mimre

Reputation: 92

thrust copy_if: incomplete type is not allowed

I'm trying to use thrust::copy_if to compact an array with a predicate checking for positive numbers:

header file: file.h:

struct is_positive
{
  __host__ __device__
  bool operator()(const int x)
  {
    return (x >= 0);
  }
};

and file.cu

#include "../headers/file.h"
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
#include <thrust/copy.h>


void compact(int* d_inputArray, int* d_outputArray, const int size)
{
  thrust::device_ptr<int> t_inputArray(d_inputArray);
  thrust::device_ptr<int> t_outputArray(d_outputArray);
  thrust::copy_if(t_inputArray, t_inputArray + size, d_outputArray, is_positive());
}

I'm getting error messages starting with:

/usr/local/cuda/include/thrust/system/detail/generic/memory.inl(40): error: incomplete type is not allowed

full errormsg here

If I just use copy instead of copy_if, the code compiles fine, so I ruled everything except the predicate is_positive() out.

Thank you in advance for any help or general tips on how to debug such thrust errors.

e: I'm using Cuda 7.5

Upvotes: 1

Views: 834

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 151799

To me it looks like you just have a typo. This:

thrust::copy_if(t_inputArray, t_inputArray + size, d_outputArray, is_positive());
                                                   ^

should be this:

thrust::copy_if(t_inputArray, t_inputArray + size, t_outputArray, is_positive());

You've mixed a raw pointer with proper thrust device pointers, and this is causing trouble.

Upvotes: 3

Related Questions