2012-12-20 32 views
1

由於cutil.h頭從CUDA樣品取出,一些新的頭被引入像helper_cuda.h,helper_functions.h。CUDA 5.0:checkCudaErrors未能找到正確的「檢查」的方法,如果類有一個「檢查」方法

一所使用我的主關鍵字是CUDA_CHECK_ERROR,我認爲它會被替換checkCudaErrors。

在我的大部分代碼中,宏編譯並運行良好。但是,當我在一個名爲check(..)的函數的類中使用它時,checkCudaErrors函數會出現編譯錯誤。

下面是一個例子:

#include <stdio.h> 

#include <cuda_runtime.h> 
#include <helper_cuda.h> 
#include <helper_functions.h> 

template<typename T> 
class Trivial { 

public: 

    void check() 
    { 

    } 

    void initialize() 
    { 
     checkCudaErrors(cudaMalloc(NULL, 1)); 
    } 

    T val; 

}; 

int main(int argc, char **argv) 
{ 

    Trivial<int> tt; 

    tt.initialize(); 

    return 0; 
} 

和編譯的結果:(!當使用GCC 4.5還編是看到了同樣的錯誤)

1>------ Build started: Project: ZERO_CHECK, Configuration: Release x64 ------ 
2>------ Build started: Project: massivecc, Configuration: Release x64 ------ 
2> trivial_main.cpp 
2>..\src\trivial_main.cpp(19): error C2660: 'Trivial<T>::check' : function does not  take 4 arguments 
2>   with 
2>   [ 
2>    T=int 
2>   ] 
2>   ..\src\trivial_main.cpp(18) : while compiling class template member   function 'void Trivial<T>::initialize(void)' 
2>   with 
2>   [ 
2>    T=int 
2>   ] 
2>   ..\src\trivial_main.cpp(29) : see reference to class template   instantiation 'Trivial<T>' being compiled 
2>   with 
2>   [ 
2>    T=int 
2>   ] 
3>------ Skipped Build: Project: ALL_BUILD, Configuration: Release x64 ------ 
3>Project not selected to build for this solution configuration 
========== Build: 1 succeeded, 1 failed, 1 up-to-date, 1 skipped ========== 

同樣的誤差考慮,當我刪除了模板參數。

+0

我不得不復制檢查(..)函數定義到我的類的頭中,以便能夠編譯類(我的真實代碼,不是這個示例,但它是相似的)。 – phoad

+0

也許你可以添加你的解決方案作爲答案,並接受它,以便從未回答的問題列表中解決這個問題。 – talonmies

回答

0

我不得不將helper_functions.h中的check(..)函數的定義複製到我的類的頭文件中,以便能夠編譯這個類。

#include <stdio.h>  
#include <cuda_runtime.h> 
#include <helper_cuda.h> 
#include <helper_functions.h>  
class Trivial {  
public:  
    template< typename T > 
    bool check(T result, char const *const func, const char *const file, int const line) 
    { 
     if (result) { 
      fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", 
      file, line, static_cast<unsigned int>(result), _cudaGetErrorEnum(result), func); 
      return true; 
     } else { 
      return false; 
     } 
    } 

    void check() { } 

    void initialize() 
    { 
     checkCudaErrors(cudaMalloc(NULL, 1)); 
    } 
}; 

int main(int argc, char **argv) 
{ 
    Trivial tt; 
    tt.initialize();  
    return 0; 
} 

所以,這主要解決了我的問題和我的代碼編譯成功。

0

參照helper_cuda.h發現線680

https://github.com/pathscale/nvidia_sdk_samples/blob/master/vectorAdd/common/inc/helper_cuda.h

你找到checkCudaErrors源代碼聲明使用#define checkCudaErrors(VAL)檢查((VAL),#val,FILELINE),它接受一個參數,並調用基於config.Note其他3個參數,檢查它是否也符合680

而在你的情況下定義,你定義的支票,不採取任何argume NT。不同的聲明和定義的情況下,多種定義。

相關問題