Skip to content

Commit c0ab9f8

Browse files
authored
[SYCL] Add native half type flag for NVPTX >= SM_53 (#8906)
LLVM will now error out if builtins operating on half types are used without explicitly passing `-fnative-half-type` (see: https://reviews.llvm.org/D146715). PTX supports half types since [SM_53](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html?highlight=half%20precision#half-precision-floating-point-instructions).
1 parent 1a283ac commit c0ab9f8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5051,6 +5051,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
50515051
Arg *SYCLStdArg = Args.getLastArg(options::OPT_sycl_std_EQ);
50525052

50535053
if (IsSYCLOffloadDevice) {
5054+
if (Triple.isNVPTX()) {
5055+
StringRef GPUArchName = JA.getOffloadingArch();
5056+
// TODO: Once default arch is moved to at least SM_53, empty arch should
5057+
// also result in the flag added.
5058+
if (!GPUArchName.empty() &&
5059+
StringToCudaArch(GPUArchName) >= CudaArch::SM_53)
5060+
CmdArgs.push_back("-fnative-half-type");
5061+
}
50545062
// Pass the triple of host when doing SYCL
50555063
llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
50565064
std::string NormalizedTriple = AuxT.normalize();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// Check that -fnative-half-type is added automatically for SM versions
2+
/// greater or equal to 53.
3+
// RUN: %clangxx -fsycl -fsycl-targets=nvidia_gpu_sm_53 %s -### 2>&1 | \
4+
// RUN: FileCheck --check-prefix=CHECK-53 %s
5+
// CHECK-53: clang{{.*}} "-triple" "nvptx64-nvidia-cuda"{{.*}}"-fnative-half-type"
6+
// RUN: %clangxx -fsycl -fsycl-targets=nvidia_gpu_sm_70 %s -### 2>&1 | \
7+
// RUN: FileCheck --check-prefix=CHECK-70 %s
8+
// CHECK-70: clang{{.*}} "-triple" "nvptx64-nvidia-cuda"{{.*}}"-fnative-half-type"
9+
10+
/// As the default is set to SM_50, make sure that the option is not added.
11+
// RUN: %clangxx -fsycl -fsycl -fsycl-targets=nvidia64-nvidia-cuda %s -### 2>&1 | \
12+
// RUN: FileCheck --check-prefix=CHECK-DEFAULT %s
13+
// CHECK-DEFAULT-NOT: {{.*}}"-fnative-half-type"
14+
15+
/// SM < 53
16+
// RUN: %clangxx -fsycl -fsycl-targets=nvidia_gpu_sm_50 %s -### 2>&1 | \
17+
// RUN: FileCheck --check-prefix=CHECK-50 %s
18+
// CHECK-50-NOT: {{.*}}"-fnative-half-type"

0 commit comments

Comments
 (0)