2016-10-19 22 views
0

thrust:complex<float>のベクトルを操作するのにthrust::transformを使用しようとしています。次の例では、コンパイル時に数ページのエラーが発生します。thrust :: complex型で操作する:thrust :: transform

#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を使って打ち鳴らす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> >()); 
                      ^

本当の山車に取り組んで問題ありません

が、複雑なものでありませんように。私は欠けているタイプのエラーがあると思っていますが、私はまだ推力&テンプレートで学習曲線の急な部分にいます。

答えて

3

エラーメッセージは非常にわかりやすいです:

thrust::abs<thrust::complex<...>>正確に一つパラメータを期待機能で、thrust/detail/complex/arithmetic.h#L143次を参照してください。あなたのユースケースについては

template <typename ValueType> 
    __host__ __device__ 
    inline ValueType abs(const complex<ValueType>& z){ 
    return hypot(z.real(),z.imag()); 
} 

を、あなたはその機能をラップする必要がありますファンクタ

struct complex_abs_functor 
{ 
    template <typename ValueType> 
    __host__ __device__ 
    ValueType operator()(const thrust::complex<ValueType>& z) 
    { 
     return thrust::abs(z); 
    } 
}; 

最後に、ここでそのファンクタを採用:

thrust::transform(d_vec1.begin(), 
        d_vec1.end(), 
        d_vec2.begin(), 
        complex_abs_functor()); 
+0

これは、トリックを行いますが、なぜ '推力::否定<推力::複雑なは>()' '推力::変換()'の呼び出しに落ちません'thrust :: abs()'はファンクタでラップする必要がありますか?そして、1つのパラメータを期待することに対する苦情は、入力ベクトルに対して供給された単項演算のパラレル実行を設定し、出力ベクトルに結果を書き込む 'thrust :: transform()'ではありませんか? –

+1

@AndreasYankopolus negate **は既に**ファンクタなので、ラッピングは不要です。あなたがしたのは、 'thrust :: transform()'と呼ばれ、 'thrust :: transform'の中にパラメータを入れていないということですが、関数を提供する必要があります(= function ** object **、 'operator()'を提供します)。 –

+0

thrust/functional.hとthrust/complex.hの定義を見てみましょう。 –

関連する問題