New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clang fails to compile cuda code in C++20 mode, works in C++17 #47572
Comments
assigned to @Artem-B |
Ouch. In c++20 mode one of the the standard C++ headers includes which ends up including cuda_wrappers/new before we've got the standard CUDA macros ready. Should be fixed by https://reviews.llvm.org/D91807 |
This would be a good low-risk fix to cherry-pick into 11.0.1 |
Hi, I applied the patch you posted, but now I am getting the following errors: /usr/lib/llvm-11/lib/clang/11.0.1/include/cuda_wrappers/new:50:12: error: reference to host function 'malloc' in device function /usr/lib/llvm-11/lib/clang/11.0.1/include/cuda_wrappers/new:67:7: error: reference to host function 'free' in device function |
I'm going to hold off on backporting this until the failure in comment #4 is addressed. |
Interesting. Can you tell me which OS and libstdc++ version you're using? Did the patched cuda_wrappers/new from the source tree make it into the /usr/lib/llvm-11/lib/clang/11.0.1/include/cuda_wrappers/new where your clang is looking for them? |
Ubuntu 18.04 I applied your phabricator patch to that file, yes. |
I have just tested it with libc++ and it works fine (but of course it would be nice to have it working with libstdc++). |
Interesting. My version of libstdc++ is 20200918 and I do not see this issue. Would you be able to capture the output of the following command and attach it to the bug? Adjust --cuda-path to point to the CUDA version you're using. $ bin/clang++ -v --cuda-path=$HOME/local/cuda-11.0 --cuda-gpu-arch=sm_70 --std=c++20 -x cuda --stdlib=libstdc++ --cuda-device-only /dev/null -o - -dD -E |
clang command log |
Thank you for the log. Indeed the device-side declarations for malloc/free are missing when cuda_wrappers/new has been includes. Clang in HEAD does not complain unless we must emit Looks like D91807 does not really fix the problem, just hides it sometimes. I'll need to find a better way to deal with this. |
Do I understand correctly that this patch does not cause a regression, it just fixes a bug in some cases but not others? Do we still want to try to backport this? |
Alas, the patch only hides the issue, and only in a rather useless toy cases. If I were to attempt fixing it for 11.0.1, how much time do I have? I should have a better idea what can be done by the end of the day tomorrow. |
https://reviews.llvm.org/D91807 has been updated with a better fix. |
I've enabled testing w/ c++17 and c++20 on CUDA test bots and the tests compile and pass. I think the patch is ready for cherry-picking into 11.0.1, if the train is not gone yet. |
Merged: 59012b6 |
This problem reappear in clangd. Now clang can compile cuda programs with c++20, but clangd raises error. |
Extended Description
Trying to compile the following cuda code:
Works in C++17 mode, fails in C++20 mode with a series of errors about
unknown type name '__device__'
from thecuda_wrappers
headers.The text was updated successfully, but these errors were encountered: