[PATCH] D93638: [hip] Enable HIP compilation with `<complex`> on MSVC.

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 02:28:40 PST 2021


hliao updated this revision to Diff 315073.
hliao added a comment.

Forget that C function could be overloaded on Clang with overloadable
extension. With that, we don't need to mark functions from `<ymath.h>` as HD.
Instead, we could provide their device-side implementation directly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93638

Files:
  clang/lib/Headers/__clang_hip_cmath.h


Index: clang/lib/Headers/__clang_hip_cmath.h
===================================================================
--- clang/lib/Headers/__clang_hip_cmath.h
+++ clang/lib/Headers/__clang_hip_cmath.h
@@ -624,6 +624,34 @@
 } // namespace std
 #endif
 
+// Define device-side math functions from <ymath.h> on MSVC.
+#if defined(_MSC_VER)
+#if defined(__cplusplus)
+extern "C" {
+#endif // defined(__cplusplus)
+__DEVICE__ __attribute__((overloadable)) double _Cosh(double x, double y) {
+  return cosh(x) * y;
+}
+__DEVICE__ __attribute__((overloadable)) float _FCosh(float x, float y) {
+  return coshf(x) * y;
+}
+__DEVICE__ __attribute__((overloadable)) short _Dtest(double *p) {
+  return fpclassify(*p);
+}
+__DEVICE__ __attribute__((overloadable)) short _FDtest(float *p) {
+  return fpclassify(*p);
+}
+__DEVICE__ __attribute__((overloadable)) double _Sinh(double x, double y) {
+  return sinh(x) * y;
+}
+__DEVICE__ __attribute__((overloadable)) float _FSinh(float x, float y) {
+  return sinhf(x) * y;
+}
+#if defined(__cplusplus)
+}
+#endif // defined(__cplusplus)
+#endif // defined(_MSC_VER)
+
 #pragma pop_macro("__DEVICE__")
 
 #endif // __CLANG_HIP_CMATH_H__


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93638.315073.patch
Type: text/x-patch
Size: 1169 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210107/d25cb36b/attachment.bin>


More information about the cfe-commits mailing list