Skip to content

Commit 08a21dc

Browse files
author
Artem Gindinson
committed
[SYCL] Enable native FP atomics by default
Since Intel GPU and CPU support the target, pass the required macro by default during device FE compilation for SPIR non-FPGA targets. This alleviates the users of the native FP atomic functionality from passing the macro explicitly. Signed-off-by: Artem Gindinson <[email protected]>
1 parent e45408a commit 08a21dc

File tree

6 files changed

+37
-14
lines changed

6 files changed

+37
-14
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4669,12 +4669,21 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
46694669
if (HasFPGA)
46704670
CmdArgs.push_back("-fsycl-disable-range-rounding");
46714671

4672+
const auto &DeviceTriple = getToolChain().getTriple();
4673+
const auto &DeviceSubArch = DeviceTriple.getSubArch();
46724674
// Enable generation of USM address spaces for FPGA.
46734675
// __ENABLE_USM_ADDR_SPACE__ will be used during compilation of SYCL headers
4674-
if (getToolChain().getTriple().getSubArch() ==
4675-
llvm::Triple::SPIRSubArch_fpga)
4676+
if (DeviceSubArch == llvm::Triple::SPIRSubArch_fpga)
46764677
CmdArgs.push_back("-D__ENABLE_USM_ADDR_SPACE__");
46774678

4679+
// Use native FP atomics on supported targets by default.
4680+
// TODO: Currently, only OpenCL CPU and Intel GPU support the functions.
4681+
// Allow other targets through check once/if support for
4682+
// SPV_EXT_shader_atomic_float* extensions lands there.
4683+
if (DeviceTriple.isSPIR() &&
4684+
DeviceSubArch != llvm::Triple::SPIRSubArch_fpga)
4685+
CmdArgs.push_back("-DSYCL_USE_NATIVE_FP_ATOMICS");
4686+
46784687
// Add any options that are needed specific to SYCL offload while
46794688
// performing the host side compilation.
46804689
if (!IsSYCLOffloadDevice) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Check that the macro for enabling native SYCL FP atomics is only passed for
2+
/// targets that offer support for the corresponding SPIR-V extensions.
3+
// RUN: %clangxx -fsycl %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-POS
4+
// RUN: %clangxx -fsycl %s -fsycl-targets=spir64_gen-unknown-unknown-sycldevice -### 2>&1 \
5+
// RUN: | FileCheck %s --check-prefix=CHECK-POS
6+
// RUN: %clangxx -fsycl %s -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice -### 2>&1 \
7+
// RUN: | FileCheck %s --check-prefix=CHECK-POS
8+
// CHECK-POS: clang{{.*}} "-fsycl-is-device"{{.*}} "-DSYCL_USE_NATIVE_FP_ATOMICS"
9+
//
10+
// RUN: %clangxx -fsycl %s -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice -### 2>&1 \
11+
// RUN: | FileCheck %s --check-prefix=CHECK-NEG
12+
// RUN: %clangxx -fsycl %s -fsycl-targets=nvptx64-nvidia-nvcl-sycldevice -### 2>&1 \
13+
// RUN: | FileCheck %s --check-prefix=CHECK-NEG
14+
// CHECK-NEG-NOT: -DSYCL_USE_NATIVE_FP_ATOMICS

sycl/test/atomic_ref/add.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -DSYCL_USE_NATIVE_FP_ATOMICS \
2-
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM
31
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-device-only -S %s -o - \
4-
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM-EMU
2+
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM
3+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -USYCL_USE_NATIVE_FP_ATOMICS \
4+
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM-EMU
55
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out
66
// RUN: %RUN_ON_HOST %t.out
77

sycl/test/atomic_ref/max.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -DSYCL_USE_NATIVE_FP_ATOMICS \
2-
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM
31
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-device-only -S %s -o - \
4-
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM-EMU
2+
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM
3+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -USYCL_USE_NATIVE_FP_ATOMICS \
4+
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM-EMU
55
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out
66
// RUN: %RUN_ON_HOST %t.out
77

sycl/test/atomic_ref/min.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -DSYCL_USE_NATIVE_FP_ATOMICS \
2-
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM
31
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-device-only -S %s -o - \
4-
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM-EMU
2+
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM
3+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -USYCL_USE_NATIVE_FP_ATOMICS \
4+
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM-EMU
55
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out
66
// RUN: %RUN_ON_HOST %t.out
77

sycl/test/atomic_ref/sub.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -DSYCL_USE_NATIVE_FP_ATOMICS \
2-
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM
31
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-device-only -S %s -o - \
4-
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM-EMU
2+
// RUN: | FileCheck %s --check-prefix=CHECK-LLVM
3+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -USYCL_USE_NATIVE_FP_ATOMICS \
4+
// RUN: -fsycl-device-only -S %s -o - | FileCheck %s --check-prefix=CHECK-LLVM-EMU
55
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out
66
// RUN: %RUN_ON_HOST %t.out
77

0 commit comments

Comments
 (0)