推力:不支持运营商'*'

时间:2016-06-08 14:47:16

标签: c++ cuda thrust

我有以下函数用于从-time / 2到time / 2的步骤填充向量t并逐步调整dt:

#define THRUST_PREC thrust::complex<double>
__host__ void generate_time(thrust::device_vector<THRUST_PREC> *t, const double dt, const double time)
{
    THRUST_PREC start = -time / 2.0;
    THRUST_PREC step = dt;
    thrust::sequence((*t).begin(), (*t).end(), start, step);
}

编译时,我得到error : no operator "*" matches these operands。为什么?有没有办法像我一样填充矢量,或者我应该用旧的方式填充它(也就是循环)?

修改:完整错误:Error 1 error : no operator "*" matches these operands C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include\thrust\system\detail\generic\sequence.inl 48 1 FFT_test

1 个答案:

答案 0 :(得分:4)

它看起来像thrust::complex的错误。 const thrust:complex<double>signed long之间的乘法运算未定义。

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sequence.inl(48):
error: no operator "*" matches these operands
             operand types are: const thrust::complex<double> * signed long
           detected during:
           ....

但奇怪的是,您可以使用thrust::transform代替。以下代码有效。

#define THRUST_PREC thrust::complex<double>
__host__ void generate_time(thrust::device_vector<THRUST_PREC> *t, const double dt, const double time)
{
  THRUST_PREC start = -time / 2.0;
  THRUST_PREC step = dt;
  thrust::transform(thrust::make_counting_iterator(0),
                    thrust::make_counting_iterator(0) + t->size(),
                    t->begin(),
                    start + step * _1);
}

无论哪种方式,内部实现都使用索引(signed long中的thrust::sequence类型)来计算表达式所需的序列

start + step * index;

阻止thrust::sequence工作的因素是operator *(...)没有很好地重载。

thrust::complex<double> a(1,1);
double double_b = 4;
float float_b = 4;
int int_b = 4;
long long_b = 4;

a *= double_b; // ok
a *= float_b;  // ok
a *= int_b;    // ok
a *= long_b;   // ok

std::cout << a * double_b << std::endl; // ok
std::cout << a * float_b << std::endl;  // error
std::cout << a * int_b << std::endl;    // error
std::cout << a * long_b << std::endl;   // error
相关问题