Skip to content

Commit 223f5e0

Browse files
committed
[SYCL][Driver] Select Native bfloat16 when all AOT targets specified support native bfloat16 conversion
1 parent becaba8 commit 223f5e0

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ static bool selectBfloatLibs(const llvm::Triple &Triple, const Compilation &C,
347347
Device.starts_with("dg2") || Device.starts_with("bmg");
348348
};
349349

350+
auto checkSpirvJIT = [](StringRef Target) {
351+
return Target.starts_with("spir64-") || Target.starts_with("spirv64-") ||
352+
(Target == "spir64") || (Target == "spirv64");
353+
};
354+
350355
size_t DevicesPos = Params.find("-device ");
351356
// "-device xxx" is used to specify AOT target device.
352357
if (DevicesPos != std::string::npos) {
@@ -361,9 +366,11 @@ static bool selectBfloatLibs(const llvm::Triple &Triple, const Compilation &C,
361366
// can be involved only when all GPU deivces specified support native
362367
// bfloat16 native conversion.
363368
UseNative = true;
369+
364370
if (Arg *SYCLTarget = Args.getLastArg(options::OPT_fsycl_targets_EQ)) {
365371
for (auto TargetsV : SYCLTarget->getValues()) {
366-
if (!GPUArchsWithNBF16.contains(StringRef(TargetsV))) {
372+
if (!checkSpirvJIT(StringRef(TargetsV)) &&
373+
!GPUArchsWithNBF16.contains(StringRef(TargetsV))) {
367374
UseNative = false;
368375
break;
369376
}

clang/test/Driver/sycl-device-lib-bfloat16.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,79 @@
6868
// RUN: --sysroot=%S/Inputs/SYCL -### 2>&1 \
6969
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-FALLBACK
7070

71+
72+
// Test test AOT-DG2 compilation uses native libs + native libs.
73+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_acm_g10 \
74+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
75+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE
76+
77+
// Test test AOT-PVC + AOT-DG2 compilation uses native libs + native libs.
78+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,intel_gpu_acm_g10 \
79+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
80+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NATIVE
81+
82+
// Test test AOT-PVC + AOT-DG1 compilation uses native libs + native libs.
83+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_dg1,intel_gpu_acm_g10 \
84+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
85+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-FALLBACK
86+
87+
88+
// Test test AOT-PVC + JIT compilation uses native libs + no libs
89+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spir64 \
90+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
91+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE
92+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spirv64 \
93+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
94+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE
95+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spir64-unknown-unknown \
96+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
97+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE
98+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spirv64-unknown-unknown \
99+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
100+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE
101+
102+
// Test test AOT-DG1 + JIT compilation uses native libs + no libs
103+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_dg1,spir64 \
104+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
105+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE
106+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_dg1,spirv64 \
107+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
108+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE
109+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_dg1,spir64-unknown-unknown \
110+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
111+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE
112+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_dg1,spirv64-unknown-unknown \
113+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
114+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE
115+
116+
// Test test AOT-PVC + JIT compilation + AOT-DG2 uses native libs + no libs + native libs
117+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spir64,intel_gpu_acm_g10 \
118+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
119+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE-NATIVE
120+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spirv64,intel_gpu_acm_g10 \
121+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
122+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE-NATIVE
123+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spir64-unknown-unknown,intel_gpu_acm_g10 \
124+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
125+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE-NATIVE
126+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spirv64-unknown-unknown,intel_gpu_acm_g10 \
127+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
128+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-NATIVE-NONE-NATIVE
129+
130+
// Test test AOT-PVC + JIT compilation + AOT-DG1 uses fallback libs + no libs + fallback libs
131+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spir64,intel_gpu_dg1 \
132+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
133+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE-FALLBACK
134+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spirv64,intel_gpu_dg1 \
135+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
136+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE-FALLBACK
137+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spir64-unknown-unknown,intel_gpu_dg1 \
138+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
139+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE-FALLBACK
140+
// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc,spirv64-unknown-unknown,intel_gpu_dg1 \
141+
// RUN: --sysroot=%S/Inputs/SYCL %s -### 2>&1 \
142+
// RUN: | FileCheck %s -check-prefix=BFLOAT16-FALLBACK-NONE-FALLBACK
143+
71144
// BFLOAT16-NOT: llvm-link{{.*}} "{{.*}}libsycl-{{fallback|native}}-bfloat16.bc"
72145

73146
// BFLOAT16-NATIVE: llvm-link{{.*}} "{{.*}}libsycl-native-bfloat16.bc"
@@ -85,3 +158,20 @@
85158

86159
// BFLOAT16-FALLBACK-FALLBACK: llvm-link{{.*}} "{{.*}}libsycl-fallback-bfloat16.bc"
87160
// BFLOAT16-FALLBACK-FALLBACK: "{{.*}}libsycl-fallback-bfloat16.bc"
161+
162+
// BFLOAT16-NATIVE-NATIVE: llvm-link{{.*}} "{{.*}}libsycl-native-bfloat16.bc"
163+
// BFLOAT16-NATIVE-NATIVE: llvm-link{{.*}} "{{.*}}libsycl-native-bfloat16.bc"
164+
165+
// BFLOAT16-NATIVE-NONE: llvm-link{{.*}} "{{.*}}libsycl-native-bfloat16.bc"
166+
// BFLOAT16-NATIVE-NONE-NOT: llvm-link{{.*}} "{{.*}}-bfloat16.bc"
167+
168+
// BFLOAT16-FALLBACK-NONE: llvm-link{{.*}} "{{.*}}libsycl-fallback-bfloat16.bc"
169+
// BFLOAT16-FALLBACK-NONE-NOT: llvm-link{{.*}} "{{.*}}-bfloat16.bc"
170+
171+
// BFLOAT16-NATIVE-NONE-NATIVE: llvm-link{{.*}} "{{.*}}libsycl-native-bfloat16.bc"
172+
// BFLOAT16-NATIVE-NONE-NATIVE-NOT: llvm-link{{.*}} "{{.*}}-bfloat16.bc"
173+
// BFLOAT16-NATIVE-NONE-NATIVE: llvm-link{{.*}} "{{.*}}libsycl-native-bfloat16.bc"
174+
175+
// BFLOAT16-FALLBACK-NONE-FALLBACK: llvm-link{{.*}} "{{.*}}libsycl-fallback-bfloat16.bc"
176+
// BFLOAT16-FALLBACK-NONE-FALLBACK-NOT: llvm-link{{.*}} "{{.*}}-bfloat16.bc"
177+
// BFLOAT16-FALLBACK-NONE-FALLBACK: llvm-link{{.*}} "{{.*}}libsycl-fallback-bfloat16.bc"

0 commit comments

Comments
 (0)