[PATCH] D158778: [CUDA] Propagate __float128 support from the host.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 24 14:06:22 PDT 2023


tra created this revision.
Herald added subscribers: mattd, gchakrabarti, asavonic, kerbowa, bixia, tpr, yaxunl, jvesely.
Herald added a project: All.
tra edited the summary of this revision.
tra published this revision for review.
tra added reviewers: jlebar, yaxunl.
tra added a comment.
Herald added subscribers: cfe-commits, jholewinski.
Herald added a project: clang.

For some context about why it's needed see https://github.com/compiler-explorer/compiler-explorer/pull/5373#issuecomment-1687127788
The short version is that currently CUDA compilation is broken w/ clang with unpatched libstdc++. Ubuntu and Debian patch libstdc++ to avoid the problem, but this should be handled by clang.


GPUs do not have actual FP128 support, but we do need to be able to compile
host-side headers which use `__float128`. On the GPU side we'll downgrade `__float128`
to double, similarly to how we handle `long double`. Both types will have
different in-memory representation compared to their host counterparts and are
not expected to be interchangeable across host/device boundary.

Also see https://reviews.llvm.org/D78513 which applied equivalent change to
HIP/AMDGPU.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158778

Files:
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/test/SemaCUDA/amdgpu-f128.cu
  clang/test/SemaCUDA/f128.cu


Index: clang/test/SemaCUDA/f128.cu
===================================================================
--- clang/test/SemaCUDA/f128.cu
+++ clang/test/SemaCUDA/f128.cu
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -fsyntax-only -verify %s
 
 // expected-no-diagnostics
 typedef __float128 f128_t;
Index: clang/lib/Basic/Targets/NVPTX.cpp
===================================================================
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -142,6 +142,20 @@
   // we need all classes to be defined on both the host and device.
   MaxAtomicInlineWidth = HostTarget->getMaxAtomicInlineWidth();
 
+  // For certain builtin types support on the host target, claim they are
+  // support to pass the compilation of the host code during the device-side
+  // compilation.
+  //
+  // FIXME: As the side effect, we also accept `__float128` uses in the device
+  // code, but use 'double' as the underlying type, so host/device
+  // representation of the type is different. This is similar to what happens to
+  // long double.
+
+  if (HostTarget->hasFloat128Type()) {
+    HasFloat128 = true;
+    Float128Format = DoubleFormat;
+  }
+
   // Properties intentionally not copied from host:
   // - LargeArrayMinWidth, LargeArrayAlign: Not visible across the
   //   host/device boundary.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158778.553253.patch
Type: text/x-patch
Size: 1511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230824/91abda91/attachment-0001.bin>


More information about the cfe-commits mailing list