Cuda issues with Clang Compiler

Hello,

I require some help building a cuda application using clang as the host compiler and libc++.

It appears that the cuda version 10.2 or 11.2.2 does not support libc++ that is distributed with clang 10.0.1 or any version past 6.0. If I try to create a make project using cmake v3.20.2 I encounter these errors:

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9100): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9113): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9121): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9135): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9678): error: namespace "std" has no member "__lazy_enable_if"

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9678): error: expected a ";"

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9681): warning: parsing restarts here after previous syntax error

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(375): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(381): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(383): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-11.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(389): error: cannot overload functions distinguished by return type alone

As you can see math_functions.h expects a template function called __lazy_enable_if but if you inspect math.h of libc++ you will notice that the function does not exists anymore. It was renamed in clang rls 9.x to _EnableIf.

The other errors occur because the functions in math_functions.h have different return types and exception specifiers than the one in math.h of libc++.

Can you give me some advices on how make cuda projects build with the current versions of libc++?

The only clang version that is supported for use with CUDA 11.2.2 is clang 11.0. If you haven’t tried that version, I would try that. (CUDA 10.2 supports clang 8.0.0 only)

And I also wouldn’t rule out the possibility that cmake is causing an issue. If it were me, I would attempt to confirm the problem using ordinary command line compilation. If compilation works with the usual method nvcc ... etc.) then it would probably be necessary to understand what cmake is doing.

Hi,

thank you for the help.

I already tried to use cuda 10.2 with clang 8.0.1 and cuda 11.2 with clang 11.0. For the clang 8.0.1 case the __lazy_enable_if error does not appear anymore because in 8.0.1 the function is still inside math.h. The errors that remain just tell you this:

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(8983): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(8996): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9004): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.h(9018): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(375): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(381): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(383): error: cannot overload functions distinguished by return type alone

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/math_functions.hpp(389): error: cannot overload functions distinguished by return type alone

For the clang 11.0 case I get the errors which I mentioned in my first post.

The translation unit that produces the errors is called CMakeCUDACompilerId.cu. This is the basic cmake compiler test that is performed when generating a new “Unix Makefiles” project.

Replacing the libc++ includes of 11.0 or 8.0.1 with the libc++ includes of libc++ 6.0.2 resolves the errors but it’s obviously not a real fix for this issue.

I am trying to setup cuda + clang + libc++ on Ubuntu 18.04.

I am doing all this because we want to work with a “proper” integration of cuda in the Unreal Engine 4.26. UE brings its own clang and libc++ packages. It would be great if we could just use the toolchain of UE to build our cuda modules. But if this is not possible then we could replace clang and libc++ and rebuild the entire engine. The problem is that we need a clang/libc++ package that works with cuda 11.2/10.2.