thrust copy_if: incomplete type is not allowed

南笙酒味 提交于 2021-01-29 03:10:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!