我正在尝试使用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 并使用 clang 3.8.0-2ubuntu4 进行编译nvcc --std=c++11 main.cpp -o main
.
主要错误似乎是:
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> >() );
and
/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 和模板学习曲线的陡峭部分。