推力:不支持运算符“*”

Thrust: Operator '*' is not supported

我有以下函数来填充向量 t,步长从 -time/2 到 time/2 和步长 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

看起来像是 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);
}

无论哪种方式,内部实现都使用索引(thrust::sequence 中的 signed long 类型)通过表达式

计算所需的序列
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