[英]Re-declaration of cmath functions in CUDA's math_functions.h
我在項目中包含了“ cuda_runtime.h”。 然后,它引發編譯錯誤:
In file included from /usr/local/cuda/include/common_functions.h:235:0,
from /usr/local/cuda/include/cuda_runtime.h:116,
from /usr/local/include/caffe2/core/common_gpu.h:7,
from /home/vpe.cripac/projects/LaS-VPE-Platform/src/native/DeepMAR_deploy/src/DeepMARCaffe2Utils.cpp:8:
/usr/local/cuda/include/math_functions.h:9421:99: error: redeclaration ‘float std::tanh(float)’ differs in ‘constexpr’
extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ __CUDA_CONSTEXPR__ float __cdecl tanh(float);
In file included from /usr/local/cuda/include/math_functions.h:8809:0,
from /usr/local/cuda/include/common_functions.h:235,
from /usr/local/cuda/include/cuda_runtime.h:116,
from /usr/local/include/caffe2/core/common_gpu.h:7,
from /home/vpe.cripac/projects/LaS-VPE-Platform/src/native/DeepMAR_deploy/src/DeepMARCaffe2Utils.cpp:8:
/usr/include/c++/4.8.2/cmath:520:3: error: from previous declaration ‘constexpr float std::tanh(float)’
tanh(float __x)
在使用GCC 4.8.5或5.3.1的Ubuntu和CentOS 7上均會發生這種情況。
我是否應該在“ cuda_runtime.h”之前包含任何其他標頭或定義任何宏?
永遠不要將math_functions.h
導入純宿主代碼,並且在g ++ 4.8.5中,如果嘗試這樣做,我會在頭文件中收到#error
。 如果將cuda_runtime.h
正確導入到您的主機代碼中,它將永遠不會錯誤地導入math_functions.h
:
$ cat test_math.cpp
#include <iostream>
#include <cmath>
#ifdef __BREAK_ME__
#include <math_functions.h>
#else
#include <cuda_runtime.h>
#endif
int main()
{
const float val = 0.123456789f;
std::cout << "tanh(" << val << ")=" << std::tanh(val) << std::endl;
return 0;
}
$ g++ -I/opt/cuda-8.0/include test_math.cpp
$ g++ -I/opt/cuda-8.0/include -D__BREAK_ME__ test_math.cpp
In file included from /opt/cuda-8.0/include/math_functions.h:10055:0,
from test_math.cpp:5:
/opt/cuda-8.0/include/crt/func_macro.h:50:2: error: #error -- incorrect inclusion of a cudart header file
#error -- incorrect inclusion of a cudart header file
^
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.