-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Fix for OpenMP offloading compilation error with GNU++20 option when using complex header #115306
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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-x86 Author: None (chandraghale) ChangesThe change done is to fix this issue https://github.com/llvm/llvm-project/issues/113207 . Detail discussion available in link provided. When using the -std=c++20 flag with -fopenmp for OpenMP offloading results in the following compilation error. Reduced test Case :
Full diff: https://github.com/llvm/llvm-project/pull/115306.diff 1 Files Affected:
diff --git a/clang/lib/Headers/openmp_wrappers/complex_cmath.h b/clang/lib/Headers/openmp_wrappers/complex_cmath.h
index e3d9aebbbc2436..cee36bde3f522e 100644
--- a/clang/lib/Headers/openmp_wrappers/complex_cmath.h
+++ b/clang/lib/Headers/openmp_wrappers/complex_cmath.h
@@ -64,8 +64,13 @@ template <class _Tp> __DEVICE__ _Tp norm(const std::complex<_Tp> &__c) {
}
// conj
-
-template <class _Tp> std::complex<_Tp> conj(const std::complex<_Tp> &__c) {
+#ifdef _GLIBCXX20_CONSTEXPR
+#define CXX20_CONSTEXPR_DEVICE __DEVICE__
+#else
+#define CXX20_CONSTEXPR_DEVICE
+#endif
+template <class _Tp>
+CXX20_CONSTEXPR_DEVICE std::complex<_Tp> conj(const std::complex<_Tp> &__c) {
return std::complex<_Tp>(__c.real(), -__c.imag());
}
|
|
||
template <class _Tp> std::complex<_Tp> conj(const std::complex<_Tp> &__c) { | ||
#ifdef _GLIBCXX20_CONSTEXPR | ||
#define CXX20_CONSTEXPR_DEVICE __DEVICE__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this is not constexpr
in C++20 but __DEVICE__
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shiltian I followed the existing approach used to define constexpr for handling OpenMP offloading in this wrapper. The DEVICE macro indeed looks better suited with GPU offloading environments.
@chandraghale Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…using complex header (llvm#115306) The change done is to fix this issue. [[Issue](llvm#113207)] discussion available in link provided. When using the -std=c++20 flag with -fopenmp for OpenMP offloading results in the following compilation error. Reduced test Case : ``` > cat foo.cpp #include <complex> void foo(){ } > CC -fopenmp -std=gnu++20 -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx90a foo.cpp -c In file included from foo.cpp:1: In file included from /opt/cray/pe/cce/18.0.1/cce-clang/x86_64/lib/clang/18/include/openmp_wrappers/complex:51: /opt/cray/pe/cce/18.0.1/cce-clang/x86_64/lib/clang/18/include/openmp_wrappers/complex_cmath.h:68:40: error: non-constexpr declaration of 'conj' follows constexpr declaration 68 | template <class _Tp> std::complex<_Tp> conj(const std::complex<_Tp> &__c) { | ^ /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/complex:970:5: note: previous declaration is here 970 | conj(const complex<_Tp>& __z) | ^ 1 error generated. ``` Co-authored-by: Chandra Ghale <[email protected]>
The change done is to fix this issue. [Issue] discussion available in link provided.
When using the -std=c++20 flag with -fopenmp for OpenMP offloading results in the following compilation error.
Reduced test Case :