【发布时间】:2017-03-01 18:03:07
【问题描述】:
我正在尝试使用thrust::transform 对thrust:complex<float> 类型的向量进行操作,但没有成功。以下示例在编译过程中出现了几页错误。
#include <cuda.h>
#include <cuda_runtime.h>
#include <cufft.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/transform.h>
#include <thrust/complex.h>
int main(int argc, char *argv[]) {
thrust::device_vector< thrust::complex<float> > d_vec1(4);
thrust::device_vector<float> d_vec2(4);
thrust::fill(d_vec1.begin(), d_vec1.end(), thrust::complex<float>(1,1));
thrust::transform(d_vec1.begin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
}
我在 Ubuntu Xenial 上使用 CUDA 8.0,并使用 nvcc --std=c++11 main.cpp -o main 使用 clang 3.8.0-2ubuntu4 进行编译。
主要错误似乎是:
main.cpp: In function ‘int main(int, char**)’:
main.cpp:17:105: error: no matching function for call to ‘abs()’
gin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
和
/usr/local/cuda-8.0/bin/../targets/x86_64-linux/include/thrust/detail/complex/arithmetic.h:143:20: note: template argument deduction/substitution failed:
main.cpp:17:105: note: candidate expects 1 argument, 0 provided
gin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
^
处理真正的花车没问题,但处理复杂的花车就没有问题。我认为我遗漏了一个类型错误,但我仍然处于 Thrust 和模板学习曲线的陡峭部分。
【问题讨论】: