[英]Redefinitions when compiling CUDA with clang on Windows
Despite an almost identical question already asked, the answer is for OSX and no longer holds true (and is really hacky anyways). 尽管已经提出了一个几乎完全相同的问题 ,但答案是针对OSX并且不再适用(反正真的是hacky)。
The problem is when compiling cuda with clang on windows, there is tonnes of redefinitions in math_functions.hpp
. 问题是在Windows上使用clang编译cuda时, math_functions.hpp
有大量重新定义。
With some investigations, apparently cuda decided to put its math_functions.hpp
and math_functions.h
functions in namespace std
(is this even legal?), and collided with all the libstdc++ functions in cmath
and clang's own headers for compiling cuda. 通过一些调查,显然cuda决定将其math_functions.hpp
和math_functions.h
函数放在namespace std
(这甚至是合法的吗?),并与cmath
和clang自己的头文件中的所有libstdc ++函数相冲突以编译cuda。
How do I deal with this? 我该如何处理? Preferably not with the hacky way shown in the previous question? 最好不要使用上一个问题中显示的hacky方式?
According to clang's documentation , clang can overload based on __global__
/ __device__
qualifiers, shouldn't the code just compile anyways? 根据clang的文档 ,clang可以基于__global__
/ __device__
限定符重载,代码不应该只编译吗?
Versions: 版本:
clang 4.0.0 (built like this ) 铛4.0.0(建立像这样 )
libstdc++ came from gcc 7.1.0 libstdc ++来自gcc 7.1.0
cuda 8.0 cuda 8.0
windows 10 窗户10
Full error output 完整的错误输出
clang++ hellocuda.cu --cuda-path=E:\cuda\development --cuda-gpu-arch=sm_20 -LE:\cuda\development\lib\x64 -lcudart_static -ldl -lrt -std=c++1y -O2 -pedantic -Wall -Wextra -fms-extensions -o program.exe
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:1684:14: error: redefinition of
'__isnan'
__func__(int __isnan(double a))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:525:28: note:
previous definition is here
__CRT_INLINE int __cdecl __isnan (double _x)
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:1764:14: error: redefinition of
'__signbit'
__func__(int __signbit(double a))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:611:28: note:
previous definition is here
__CRT_INLINE int __cdecl __signbit (double x) {
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:1776:17: error: redefinition of
'copysign'
__func__(double copysign(double a, double b))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:1069:31: note:
previous definition is here
__CRT_INLINE double __cdecl copysign (double x, double y)
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:3161:14: error: redefinition of
'__signbitl'
__func__(int __signbitl(long double a))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:636:28: note:
previous definition is here
__CRT_INLINE int __cdecl __signbitl (long double x) {
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:3166:14: error: redefinition of
'__signbitf'
__func__(int __signbitf(float a))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:624:28: note:
previous definition is here
__CRT_INLINE int __cdecl __signbitf (float x) {
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:3191:14: error: redefinition of
'__isnanl'
__func__(int __isnanl(long double a))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:565:28: note:
previous definition is here
__CRT_INLINE int __cdecl __isnanl (long double _x)
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:3196:14: error: redefinition of
'__isnanf'
__func__(int __isnanf(float a))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:546:28: note:
previous definition is here
__CRT_INLINE int __cdecl __isnanf (float _x)
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:191:
E:\cuda\development/include\math_functions.hpp:3360:16: error: redefinition of
'copysignf'
__func__(float copysignf(float a, float b))
^
E:\TDM-GCC\mingw64 7.1.0\mingw64\x86_64-w64-mingw32\include\math.h:1076:30: note:
previous definition is here
__CRT_INLINE float __cdecl copysignf (float x, float y)
^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:250:
E:\cuda\development/include\math_functions.hpp:365:43: error: functions that differ
only in their return type cannot be overloaded
static __inline__ __host__ __device__ int isinf(double a)
~~~ ^
E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_math_forward_declares.h:107:17: note:
previous declaration is here
__DEVICE__ bool isinf(double);
~~~~ ^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:250:
E:\cuda\development/include\math_functions.hpp:381:43: error: functions that differ
only in their return type cannot be overloaded
static __inline__ __host__ __device__ int isinf(float a)
~~~ ^
E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_math_forward_declares.h:108:17: note:
previous declaration is here
__DEVICE__ bool isinf(float);
~~~~ ^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:250:
E:\cuda\development/include\math_functions.hpp:413:43: error: functions that differ
only in their return type cannot be overloaded
static __inline__ __host__ __device__ int isnan(double a)
~~~ ^
E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_math_forward_declares.h:115:17: note:
previous declaration is here
__DEVICE__ bool isnan(double);
~~~~ ^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:250:
E:\cuda\development/include\math_functions.hpp:429:43: error: functions that differ
only in their return type cannot be overloaded
static __inline__ __host__ __device__ int isnan(float a)
~~~ ^
E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_math_forward_declares.h:116:17: note:
previous declaration is here
__DEVICE__ bool isnan(float);
~~~~ ^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:250:
E:\cuda\development/include\math_functions.hpp:461:43: error: functions that differ
only in their return type cannot be overloaded
static __inline__ __host__ __device__ int isfinite(double a)
~~~ ^
E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_math_forward_declares.h:101:17: note:
previous declaration is here
__DEVICE__ bool isfinite(double);
~~~~ ^
In file included from <built-in>:1:
In file included from E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_runtime_wrapper.h:250:
E:\cuda\development/include\math_functions.hpp:477:43: error: functions that differ
only in their return type cannot be overloaded
static __inline__ __host__ __device__ int isfinite(float a)
~~~ ^
E:\LLVM\bin\..\lib\clang\4.0.0\include\__clang_cuda_math_forward_declares.h:102:17: note:
previous declaration is here
__DEVICE__ bool isfinite(float);
~~~~ ^
14 errors generated.
makefile:15: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
I tried quite a bit of stuff. 我尝试了很多东西。 They failed. 他们失败了。 In the end I dug into the headers and literally macroed out anything that has a conflict, which are located in 最后,我挖掘了标题,并将字面上的任何有冲突的内容宏观化了
clang uses _MSC_VER
to detect Windows, which is defined only if -fms-compatibility flag is used, but this causes a ton of other errors elsewhere for unknown reasons. clang使用_MSC_VER
来检测Windows,只有在使用-fms-compatibility标志时才会定义Windows,但这会导致其他地方出现大量其他错误,原因不明。
cuda uses a mixture of _WIN32
and _MSC_VER
to detect Windows. cuda使用_WIN32
和_MSC_VER
的混合来检测Windows。 As far as I can tell, just macroing away everything that is a redefinition is simply the easiest way to do this. 据我所知,只需将重新定义的所有内容宏观化,这只是最简单的方法。
This seems to be working, as in no other header errors popped up. 这似乎有效,因为没有出现其他标题错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.