由於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 ==========
同樣的誤差考慮,當我刪除了模板參數。
我不得不復制檢查(..)函數定義到我的類的頭中,以便能夠編譯類(我的真實代碼,不是這個示例,但它是相似的)。 – phoad
也許你可以添加你的解決方案作爲答案,並接受它,以便從未回答的問題列表中解決這個問題。 – talonmies