Skip to content

[CUDA] work around more __noinline__ conflicts with libc++ #74123

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

Closed
wants to merge 3 commits into from

Conversation

Artem-B
Copy link
Member

@Artem-B Artem-B commented Dec 1, 2023

@Artem-B Artem-B requested review from ldionne and gribozavr December 1, 2023 18:41
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Dec 1, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2023

@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: Artem Belevich (Artem-B)

Changes

#73838


Full diff: https://github.com/llvm/llvm-project/pull/74123.diff

3 Files Affected:

  • (modified) clang/lib/Headers/CMakeLists.txt (+2)
  • (added) clang/lib/Headers/cuda_wrappers/__config (+10)
  • (added) clang/lib/Headers/cuda_wrappers/string (+10)
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index fdd54c05eedf825..f562c354327f2fb 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -283,10 +283,12 @@ set(files
   )
 
 set(cuda_wrapper_files
+  cuda_wrappers/__config
   cuda_wrappers/algorithm
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+  cuda_wrappers/string
 )
 
 set(cuda_wrapper_bits_files
diff --git a/clang/lib/Headers/cuda_wrappers/__config b/clang/lib/Headers/cuda_wrappers/__config
new file mode 100644
index 000000000000000..04038b0fa3437ee
--- /dev/null
+++ b/clang/lib/Headers/cuda_wrappers/__config
@@ -0,0 +1,10 @@
+// CUDA headers define __noinline__ which interferes with libc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#define __noinline__ __noinline__
+#include_next "__config"
+
+#pragma pop_macro("__noinline__")
diff --git a/clang/lib/Headers/cuda_wrappers/string b/clang/lib/Headers/cuda_wrappers/string
new file mode 100644
index 000000000000000..d612710393623b5
--- /dev/null
+++ b/clang/lib/Headers/cuda_wrappers/string
@@ -0,0 +1,10 @@
+// CUDA headers define __noinline__ which interferes with libc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#define __noinline__ __noinline__
+#include_next "string"
+
+#pragma pop_macro("__noinline__")

@gribozavr
Copy link
Collaborator

gribozavr commented Dec 1, 2023

I don't mind this, but should libc++ start using _LIBCPP_NOINLINE more, we would be playing a catch-up game here - we would need to add more and more similar wrapper headers.

@gribozavr gribozavr requested a review from EricWF December 1, 2023 19:16
@Artem-B
Copy link
Member Author

Artem-B commented Dec 1, 2023

Yes, I've mentioned that in #73838. However, we need something to fix the issue right now while we're figuring out a better solution.

In any case __noinline__ is unlikely to be widely used, so the wrappers may be manageable, at least for the short-to-medium term.

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can find a solution to work around this in libc++ within a reasonable timeframe, but I won't block this, since I don't really care about this part of the code base.

@Artem-B
Copy link
Member Author

Artem-B commented Dec 1, 2023

I think we can find a solution to work around this in libc++ within a reasonable timeframe

OK. I'll hold off on landing the patch. I believe we're not blocked on it at the moment.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some review comments if we end up merging this.

FWIW I am not thrilled about using __config here. That header is an implementation detail of libc++ and defining it and relying on it is somewhat brittle.

@Artem-B
Copy link
Member Author

Artem-B commented Dec 1, 2023

FWIW I am not thrilled about using __config here. That header is an implementation detail of libc++ and defining it and relying on it is somewhat brittle.

I'm all for having it fixed in libc++ or in CUDA SDK. Barring that, working around the specific implementation details is all I can do here. I'm open to other ideas on how this conflict can be worked around or solved in a better way.

@gribozavr
Copy link
Collaborator

#73838 has landed, we can close this PR now.

@ldionne ldionne closed this Jan 23, 2024
@Artem-B Artem-B deleted the libcxx-noinline branch February 12, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants