问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/40611810/thrust-copy-if-incomplete-type-is-not-allowed