2013-10-06 49 views
-2

我想在我的CUDA應用程序中使用減推力。因此,我包括頭和調用函數:Cuda的推力 - xutility:名稱,後跟「::」必須是類或命名空間

#include <thrust\reduce.h> 

__host__ void reduction(){ 
    unsigned int t = 0; 
    thrust::reduce(t,t); 
} 

但是我得到的編譯錯誤(只有一種類型):「名字後面加上‘::’必須是類或命名空間」。問題在於一個名爲xutility的文件(我沒有碰過)。所有的錯誤都與下列類別定義有關:

// TEMPLATE CLASS iterator_traits 
template<class _Iter> 
    struct iterator_traits 
    { // get traits from iterator _Iter 
    typedef typename _Iter::iterator_category iterator_category; 
    typedef typename _Iter::value_type value_type; 
    typedef typename _Iter::difference_type difference_type; 
    typedef difference_type distance_type; // retained 
    typedef typename _Iter::pointer pointer; 
    typedef typename _Iter::reference reference; 
    }; 

我沒有真正進入模板編程。我究竟做錯了什麼?

+1

會是什麼'(無效)推力::減少(threadIdx.x,threadIdx.x);'連做,如果它編譯?如果你要問一個關於語法錯誤,以及如何解決這些問題,至少沒有禮貌表現出一些實際的代碼和一個實際的編譯器錯誤和行號,無些廢話僞代碼。 – talonmies

+0

我試圖提供一個最小的例子;因爲這個最小例子中的錯誤依然存在,所以我認爲最好不要包含整個源代碼。編譯器錯誤與前面所述完全相同。我決定提供導致錯誤的行而不是行號,以便您不必滾動瀏覽xutility文件。 – emher

回答

1

推力套路都設計爲從主機端,而不是在內核調用。

使用thrust::reduce的例子看到這一點。

https://github.com/thrust/thrust/blob/master/examples/sum.cu

+0

你的例子工作得很好。我的例子很愚蠢,當然我不能在內核中啓動thrust :: reduce。但是,如果我將它包裝爲__host__方法,我會得到samme錯誤。我不能使用main,因爲我通過dll從C#調用方法。 – emher

+0

如果你創建一個獨立的例子你可以用'main'。這就是你被要求去做的事情,事實上在SO上這樣的問題也是可以預料的。你說這個錯誤只是一個小例子。爲什麼不提供它,而不是一個「愚蠢」的例子(用你的話)? –

相關問題