[PATCH] D61765: [OpenMP][Clang][BugFix] Split declares and math functions inclusion.

Gheorghe-Teodor Bercea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 10 14:29:07 PDT 2019


gtbercea marked an inline comment as done.
gtbercea added inline comments.


================
Comment at: lib/Headers/__clang_cuda_math_forward_declares.h:30-38
+#ifndef _OPENMP
+__DEVICE__ long abs(long);
+__DEVICE__ long long abs(long long);
+#else
+#ifndef __cplusplus
 __DEVICE__ long abs(long);
 __DEVICE__ long long abs(long long);
----------------
tra wrote:
> tra wrote:
> > gtbercea wrote:
> > > jdoerfert wrote:
> > > > gtbercea wrote:
> > > > > tra wrote:
> > > > > > I'm not quite sure what's the idea here. It may be worth adding a comment.
> > > > > > 
> > > > > > It could also be expressed somewhat simpler:
> > > > > > 
> > > > > > ```
> > > > > > #if !(defined(_OPENMP) && defined(__cplusplus))
> > > > > > ...
> > > > > > #endif
> > > > > > ```
> > > > > > 
> > > > > When these two functions definitions are here or in the __clang_cuda_cmath.h header then I get the following error (adapted for the __clang_cuda_cmath.h case):
> > > > > 
> > > > > 
> > > > > ```
> > > > > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:166:3: error: declaration conflicts with target of using declaration already in scope
> > > > >   abs(long __i) { return __builtin_labs(__i); }
> > > > >   ^
> > > > > /autofs/home/gbercea/patch-compiler/obj-release/lib/clang/9.0.0/include/__clang_cuda_cmath.h:40:17: note: target of using declaration
> > > > > __DEVICE__ long abs(long __n) { return ::labs(__n); }
> > > > >                 ^
> > > > > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:122:11: note: using declaration
> > > > >   using ::abs;
> > > > >           ^
> > > > > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:174:3: error: declaration conflicts with target of using declaration already in scope
> > > > >   abs(long long __x) { return __builtin_llabs (__x); }
> > > > >   ^
> > > > > /autofs/home/gbercea/patch-compiler/obj-release/lib/clang/9.0.0/include/__clang_cuda_cmath.h:39:22: note: target of using declaration
> > > > > __DEVICE__ long long abs(long long __n) { return ::llabs(__n); }
> > > > >                      ^
> > > > > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:122:11: note: using declaration
> > > > >   using ::abs;
> > > > > ```
> > > > > 
> > > > > 
> > > > Long story short, we currently cannot use the overload trick through `__device__` and therefore *replace* (not augment) host math headers with the cuda versions which unfortunately mix std math functions with other functions that we don't want/need.
> > > This doesn't seem to be happening in the CUDA case. My suspicion is it's because of the __device__ attribute.
> > It looks like until OpenMP supports some sort of target-based overloading this will not play nicely with libstdc++. 
> > Did you, by any chance, check if the header works with libc++ ? I wonder if we may encounter more conflicts like these.
> Correct. `__device__` functions overload whatever `(implicitly)__host__` functions declared by the standard library, so they coexist w/o problems. Usually. host/device implementation nuances are still observable.
> 
Just did a few quick tests with libstdc++ and it was all good. 


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61765/new/

https://reviews.llvm.org/D61765





More information about the cfe-commits mailing list