Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在CUDA和x27中重新声明cmath函数;s math_函数_C++_Cuda - Fatal编程技术网

C++ 在CUDA和x27中重新声明cmath函数;s math_函数

C++ 在CUDA和x27中重新声明cmath函数;s math_函数,c++,cuda,C++,Cuda,我在项目中包括了“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,

我在项目中包括了“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)
这在Ubuntu和CentOS 7上都会发生,使用GCC4.8.5或5.3.1


我是否应该在“cuda_runtime.h”之前包含任何其他头文件或定义任何宏?

您永远不应该将
math_functions.h
导入到普通主机代码中,而对于g++4.8.5,如果我尝试这样做,我会在头文件中生成一个
错误。如果将
cuda_runtime.h
正确导入主机代码,它将永远不会错误导入
math_函数.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
  ^
$cat test\u math.cpp
#包括
#包括
#如果你打破了我__
#包括
#否则
#包括
#恩迪夫
int main()
{
常量浮点值=0.123456789f;

谢谢!我不应该在我的项目中定义CUDACC,这会导致“cuda_runtime.h”中包含“math_function.h”。