Skip to content

Commit 04f23ec

Browse files
author
Jakub Chlanda
authored
[Driver][SYCL] Support 64bit long double for SYCL GPU compilation (#16441)
Make sure that `-mlong-double-64` option is supported on HIP/Cuda.
1 parent 7af800e commit 04f23ec

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ class ToolChain {
377377
return nullptr;
378378
}
379379

380-
/// TranslateOffloadTargetArgs - Create a new derived argument list for
381-
/// that contains the Offload target specific flags passed via
382-
/// -Xopenmp-target -opt=val OR -Xopenmp-target=<triple> -opt=val
380+
/// TranslateOffloadTargetArgs - Create a new derived argument list that
381+
/// contains the Offload target specific flags passed via -Xopenmp-target
382+
/// -opt=val OR -Xopenmp-target=<triple> -opt=val
383383
/// Also handles -Xsycl-target OR -Xsycl-target=<triple>
384384
virtual llvm::opt::DerivedArgList *TranslateOffloadTargetArgs(
385385
const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,

clang/lib/Driver/ToolChain.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,8 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
16401640
DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
16411641
const OptTable &Opts = getDriver().getOpts();
16421642
bool Modified = false;
1643+
auto &Triple = getTriple();
1644+
const bool IsSYCL = DeviceOffloadKind == Action::OFK_SYCL;
16431645

16441646
// Handle -Xopenmp-target and -Xsycl-target-frontend flags
16451647
for (auto *A : Args) {
@@ -1654,13 +1656,15 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
16541656
// to correctly set metadata in intermediate files.
16551657
if (SameTripleAsHost ||
16561658
A->getOption().matches(options::OPT_mcode_object_version_EQ) ||
1657-
(getTriple().getArch() == llvm::Triple::amdgcn &&
1658-
DeviceOffloadKind != Action::OFK_SYCL)) {
1659+
(Triple.getArch() == llvm::Triple::amdgcn && !IsSYCL)) {
16591660
DAL->append(A);
16601661
continue;
16611662
}
1662-
// SPIR/SPIR-V special case for -mlong-double
1663-
if (getTriple().isSPIROrSPIRV() &&
1663+
// SPIR/SPIR-V and SYCL GPU special case for -mlong-double. We have to
1664+
// make sure that if user requested 64bit long double it is honored on
1665+
// both host and device.
1666+
if ((Triple.isSPIROrSPIRV() ||
1667+
(IsSYCL && (Triple.isAMDGCN() || Triple.isNVPTX()))) &&
16641668
A->getOption().matches(options::OPT_LongDouble_Group)) {
16651669
DAL->append(A);
16661670
continue;
@@ -1683,7 +1687,7 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
16831687
// is similar, can be improved
16841688
if (DeviceOffloadKind == Action::OFK_OpenMP) {
16851689
XOffloadTargetNoTriple =
1686-
A->getOption().matches(options::OPT_Xopenmp_target);
1690+
A->getOption().matches(options::OPT_Xopenmp_target);
16871691
if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
16881692
llvm::Triple TT(getOpenMPTriple(A->getValue(0)));
16891693

@@ -1699,12 +1703,12 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
16991703
DAL->append(A);
17001704
continue;
17011705
}
1702-
} else if (DeviceOffloadKind == Action::OFK_SYCL) {
1706+
} else if (IsSYCL) {
17031707
XOffloadTargetNoTriple =
1704-
A->getOption().matches(options::OPT_Xsycl_frontend);
1708+
A->getOption().matches(options::OPT_Xsycl_frontend);
17051709
if (A->getOption().matches(options::OPT_Xsycl_frontend_EQ)) {
17061710
// Passing device args: -Xsycl-target-frontend=<triple> -opt=val.
1707-
if (getDriver().getSYCLDeviceTriple(A->getValue(0)) == getTriple())
1711+
if (getDriver().getSYCLDeviceTriple(A->getValue(0)) == Triple)
17081712
Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
17091713
else
17101714
continue;
@@ -1744,8 +1748,7 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
17441748
getDriver().Diag(diag::err_drv_Xopenmp_target_missing_triple);
17451749
continue;
17461750
}
1747-
if (DeviceOffloadKind == Action::OFK_SYCL &&
1748-
!SingleTargetTripleCount(options::OPT_fsycl_targets_EQ)) {
1751+
if (IsSYCL && !SingleTargetTripleCount(options::OPT_fsycl_targets_EQ)) {
17491752
getDriver().Diag(diag::err_drv_Xsycl_target_missing_triple)
17501753
<< A->getSpelling();
17511754
continue;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6751,6 +6751,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
67516751
(A->getOption().getID() == options::OPT_mlong_double_64))
67526752
// Only allow for -mlong-double-64 for SPIR/SPIR-V
67536753
A->render(Args, CmdArgs);
6754+
else if ((IsSYCL &&
6755+
(TC.getTriple().isAMDGCN() || TC.getTriple().isNVPTX())) &&
6756+
(A->getOption().getID() == options::OPT_mlong_double_64))
6757+
// similarly, allow 64bit long double for SYCL GPU targets
6758+
A->render(Args, CmdArgs);
67546759
else if (TC.getTriple().isPPC() &&
67556760
(A->getOption().getID() != options::OPT_mlong_double_80))
67566761
A->render(Args, CmdArgs);

clang/test/Driver/mlong-double-128.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@
1212
// RUN: not %clang --target=powerpc -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR2 %s
1313
// RUN: not %clang --target=spir64-unknown-unknown -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR3 %s
1414
// RUN: not %clang --target=spir64-unknown-unknown -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR4 %s
15+
// RUN: not %clang --target=nvptx64-nvidia-cuda -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR5 %s
16+
// RUN: not %clang --target=nvptx64-nvidia-cuda -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR6 %s
17+
// RUN: not %clang --target=amd_gpu_gfx1031 -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR7 %s
18+
// RUN: not %clang --target=amd_gpu_gfx1031 -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR8 %s
1519

1620
// ERR: error: unsupported option '-mlong-double-128' for target 'aarch64'
1721
// ERR2: error: unsupported option '-mlong-double-80' for target 'powerpc'
1822
// ERR3: error: unsupported option '-mlong-double-128' for target 'spir64-unknown-unknown'
1923
// ERR4: error: unsupported option '-mlong-double-80' for target 'spir64-unknown-unknown'
24+
// ERR5: error: unsupported option '-mlong-double-128' for target 'nvptx64-nvidia-cuda'
25+
// ERR6: error: unsupported option '-mlong-double-80' for target 'nvptx64-nvidia-cuda'
26+
// ERR7: error: unsupported option '-mlong-double-128' for target 'amd_gpu_gfx1031'
27+
// ERR8: error: unsupported option '-mlong-double-80' for target 'amd_gpu_gfx1031'

clang/test/Driver/sycl-mlong-double.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@
55
// CHECK: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu"
66
// CHECK-SAME: "-mlong-double-64"
77

8-
/// -mlong-double-128 and -mlong-double-80 are not supported for spir64.
8+
/// -mlong-double-128 and -mlong-double-80 are not supported for spir64, or SYCL GPU targets.
99
// RUN: not %clangxx -c -fsycl -mlong-double-128 -target x86_64-unknown-linux-gnu %s -### 2>&1 | FileCheck --check-prefix=CHECK-128 %s
1010
// CHECK-128: error: unsupported option '-mlong-double-128' for target 'spir64-unknown-unknown'
1111
// CHECK-128-NOT: clang{{.*}} "-triple" "-spir64-unknown-unknown" {{.*}} "-mlong-double-128"
1212

1313
// RUN: not %clangxx -c -fsycl -mlong-double-80 -target x86_64-unknown-linux-gnu %s -### 2>&1 | FileCheck --check-prefix=CHECK-80 %s
1414
// CHECK-80: error: unsupported option '-mlong-double-80' for target 'spir64-unknown-unknown'
1515
// CHECK-80-NOT: clang{{.*}} "-triple" "-spir64-unknown-unknown" {{.*}} "-mlong-double-80"
16+
17+
// RUN: not %clangxx -c -fsycl -mlong-double-128 --target=x86_64-unknown-linux-gnu -fsycl-targets=amd_gpu_gfx1031 %s -### 2>&1 | FileCheck --check-prefix=CHECK-128-AMD %s
18+
// CHECK-128-AMD: error: unsupported option '-mlong-double-128' for target 'amdgcn-amd-amdhsa'
19+
// CHECK-128-AMD-NOT: clang{{.*}} "-triple" "-amd_gpu_gfx1031" {{.*}} "-mlong-double-128"
20+
21+
// RUN: not %clangxx -c -fsycl -mlong-double-80 --target=x86_64-unknown-linux-gnu -fsycl-targets=amd_gpu_gfx1031 %s -### 2>&1 | FileCheck --check-prefix=CHECK-80-AMD %s
22+
// CHECK-80-AMD: error: unsupported option '-mlong-double-80' for target 'amdgcn-amd-amdhsa'
23+
// CHECK-80-AMD-NOT: clang{{.*}} "-triple" "-amd_gpu_gfx1031" {{.*}} "-mlong-double-80"
24+
25+
// RUN: not %clangxx -c -fsycl -mlong-double-128 --target=x86_64-unknown-linux-gnu -fsycl-targets=nvptx64-nvidia-cuda %s -### 2>&1 | FileCheck --check-prefix=CHECK-128-NVPTX %s
26+
// CHECK-128-NVPTX: error: unsupported option '-mlong-double-128' for target 'nvptx64-nvidia-cuda'
27+
// CHECK-128-NVPTX-NOT: clang{{.*}} "-triple" "-nvptx64-nvidia-cuda" {{.*}} "-mlong-double-128"
28+
29+
// RUN: not %clangxx -c -fsycl -mlong-double-80 --target=x86_64-unknown-linux-gnu -fsycl-targets=nvptx64-nvidia-cuda %s -### 2>&1 | FileCheck --check-prefix=CHECK-80-NVPTX %s
30+
// CHECK-80-NVPTX: error: unsupported option '-mlong-double-80' for target 'nvptx64-nvidia-cuda'
31+
// CHECK-80-NVPTX-NOT: clang{{.*}} "-triple" "-nvptx64-nvidia-cuda" {{.*}} "-mlong-double-80"

0 commit comments

Comments
 (0)