Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cuda 没有重载函数的实例“;推力:取下“如果”;匹配参数列表_Cuda_Thrust - Fatal编程技术网

Cuda 没有重载函数的实例“;推力:取下“如果”;匹配参数列表

Cuda 没有重载函数的实例“;推力:取下“如果”;匹配参数列表,cuda,thrust,Cuda,Thrust,我已经用remove_if编写了程序。它使用cudaMalloc分配的数组,并由程序的前一部分(在设备中)填充。移除后,阵列将由下一个部件使用(在设备中;无推力)。我想避免任何复制设备主机,主机设备。我用这个例子: Nvcc写道: **remove_if.cu(19):错误:重载函数“推力::remove_if”的实例与参数列表不匹配 参数类型为:(推力::设备_ptr,推力::设备_ptr,is_zero)”** 我编写了一个简单的程序示例,但出现了相同的错误: #include <s

我已经用remove_if编写了程序。它使用cudaMalloc分配的数组,并由程序的前一部分(在设备中)填充。移除后,阵列将由下一个部件使用(在设备中;无推力)。我想避免任何复制设备主机,主机设备。我用这个例子:

Nvcc写道: **remove_if.cu(19):错误:重载函数“推力::remove_if”的实例与参数列表不匹配 参数类型为:(推力::设备_ptr,推力::设备_ptr,is_zero)”**

我编写了一个简单的程序示例,但出现了相同的错误:

#include <stdio.h>
#include "book.h"
#include <thrust/remove.h>
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
int main(void)
{
  int *dev_lsubpix;
  struct is_zero
  {
    __host__ __device__
    bool operator()(int x)
    {
      return (x<1);
    }
  };
HANDLE_ERROR( cudaMalloc((void**)&dev_lsubpix, 10*sizeof(int)));
thrust::device_ptr<int> dev_ptr = thrust::device_pointer_cast(dev_lsubpix);
  int new_length=     thrust::remove_if(dev_ptr, dev_ptr+10, is_zero())-dev_ptr;
  cudaFree(dev_lsubpix);
}
#包括
#包括“book.h”
#包括
#包括
#包括
内部主(空)
{
int*dev_lsubpix;
结构是零
{
__主机设备__
布尔运算符()(int x)
{

return(x虽然错误原因不太明显,但问题在于您尝试使用的谓词函子的范围。因为您已在
main
范围声明了该函子,因此它不是
main
之外的有效类型,编译器不知道如何处理匿名类型

如果您像这样重构代码:

#include <stdio.h>
#include <thrust/remove.h>
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
struct is_zero
{
    __host__ __device__
        bool operator()(int x)
        {
            return (x<1);
        }
};

int main(void)
{
    int *dev_lsubpix;
    cudaMalloc((void**)&dev_lsubpix, 10*sizeof(int));
    thrust::device_ptr<int> dev_ptr = thrust::device_pointer_cast(dev_lsubpix);
    int new_length = thrust::remove_if(dev_ptr, dev_ptr+10, is_zero())-dev_ptr;
    cudaFree(dev_lsubpix);
}
#包括
#包括
#包括
#包括
结构是零
{
__主机设备__
布尔运算符()(int x)
{

return(x虽然错误原因不太明显,但问题在于您尝试使用的谓词函子的范围。因为您已在
main
范围声明了该函子,因此它不是
main
之外的有效类型,编译器不知道如何处理匿名类型

如果您像这样重构代码:

#include <stdio.h>
#include <thrust/remove.h>
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
struct is_zero
{
    __host__ __device__
        bool operator()(int x)
        {
            return (x<1);
        }
};

int main(void)
{
    int *dev_lsubpix;
    cudaMalloc((void**)&dev_lsubpix, 10*sizeof(int));
    thrust::device_ptr<int> dev_ptr = thrust::device_pointer_cast(dev_lsubpix);
    int new_length = thrust::remove_if(dev_ptr, dev_ptr+10, is_zero())-dev_ptr;
    cudaFree(dev_lsubpix);
}
#包括
#包括
#包括
#包括
结构是零
{
__主机设备__
布尔运算符()(int x)
{
返回(x