thrust copy_if: 不允许不完整的类型

thrust copy_if: incomplete type is not allowed

我正在尝试使用 thrust::copy_if 来压缩一个带有谓词检查正数的数组:

头文件:file.h:

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

和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());
}

我收到以下开头的错误消息:

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

full errormsg here

如果我只是使用 copy 而不是 copy_if,代码编译正常,所以我排除了除谓词 is_positive() 之外的所有内容。

提前感谢您提供有关如何调试此类推力错误的任何帮助或一般提示。

e: 我正在使用 Cuda 7.5

在我看来,您只是打错了字。这个:

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

应该是这样的:

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

您将原始指针与正确的推力设备指针混合在一起,这造成了麻烦。