[PATCH] D16593: [CUDA] Implemented device-side support for functions in <cmath>.

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 26 14:42:48 PST 2016


tra added inline comments.

================
Comment at: lib/Headers/__clang_cuda_cmath.h:33
@@ +32,3 @@
+// builtins if CUDA does not provide a suitable function.
+// We also provide device-side std::abs() for integer types.
+
----------------
jlebar wrote:
> Why is std::abs a special case that needs to be called out here?
It's a bit of an oddball because it operated on integer parameters and came from <cstdlib>.
Which is indeed irrelevant here.
Deleted. 

================
Comment at: lib/Headers/__clang_cuda_cmath.h:93
@@ +92,3 @@
+  return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,
+                              FP_ZERO, x);
+}
----------------
jlebar wrote:
> Looking through bugzilla, it appears that this builtin may try to invoke library functions, which may or may not exist in our case (e.g. extern "C" fabs vs ::fabs).  It's probably worth checking this one in particular to make sure it works.
Checked -- as far as I can tell it generates valid PTX to test its arguments.

================
Comment at: lib/Headers/__clang_cuda_cmath.h:99
@@ +98,3 @@
+}
+__DEVICE__ float frexp(float arg, int *exp) { return frexpf(arg, exp); }
+__DEVICE__ double frexp(double arg, int *exp) { return frexp(arg, exp); }
----------------
jlebar wrote:
> Nit, ::
Fixed.

================
Comment at: lib/Headers/__clang_cuda_cmath.h:105
@@ +104,3 @@
+__DEVICE__ int ilogb(double arg) { return ::ilogb(arg); }
+__DEVICE__ bool isfinite(float x) { return __finitef(x); }
+__DEVICE__ bool isfinite(double x) { return __finite(x); }
----------------
jlebar wrote:
> jlebar wrote:
> > Where's __finitef coming from?  Same for the other __ functions used here.
> Nit: "::" in front of all the __ functions.
__finitef and other non-builtin __* functions come from CUDA headers. Added missing ::.

================
Comment at: lib/Headers/__clang_cuda_cmath.h:39
@@ +38,3 @@
+__DEVICE__ long abs(long n) { return ::labs(n); }
+__DEVICE__ int abs(int n) { return ::abs(n); }
+__DEVICE__ float abs(float x) { return ::fabsf(x); }
----------------
Both libc++ and libstdc++ provide these symbols in pre-c++11 mode, so should we.


http://reviews.llvm.org/D16593





More information about the cfe-commits mailing list