Skip to content

Commit 0442119

Browse files
committed
[SYCL] Add sycl-enable-bfloat16-conversion compilation flag
This flag defines __SYCL_ENABLE_BF16_CONVERSION__ macro that can be used to specify whether BF16 conversion feature is supported. This macro is being defined for both host and device compilation. Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 98ebbb7 commit 0442119

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ LANGOPT(
269269
"get/operator[], get_id/operator[] and get_global_id/get_global_linear_id "
270270
"in SYCL class id, iterm and nd_iterm")
271271
LANGOPT(SYCLDisableRangeRounding, 1, 0, "Disable parallel for range rounding")
272+
LANGOPT(
273+
SYCLEnableBF16Conversion, 1, 0,
274+
"Enable generation of BFloat16 conversion instructions")
272275

273276
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
274277

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,10 @@ def fno_sycl_link_spirv : Flag<["-"], "fno-sycl-link-spirv">,
26892689
"when discovered in user specified objects and archives.">;
26902690
def fsyntax_only : Flag<["-"], "fsyntax-only">,
26912691
Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group<Action_Group>;
2692+
defm sycl_enable_bfloat16_conversion: BoolFOption<"sycl-enable-bfloat16-conversion",
2693+
LangOpts<"SYCLEnableBF16Conversion">, DefaultFalse,
2694+
PosFlag<SetTrue, [], "Enable">, NegFlag<SetFalse, [], "Do not enable">,
2695+
BothFlags<[CC1Option, CoreOption], " BFloat16 conversion extension">>;
26922696
def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group<f_Group>;
26932697
def ftemplate_depth_EQ : Joined<["-"], "ftemplate-depth=">, Group<f_Group>;
26942698
def ftemplate_depth_ : Joined<["-"], "ftemplate-depth-">, Group<f_Group>;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4705,6 +4705,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
47054705
options::OPT_fno_sycl_id_queries_fit_in_int))
47064706
A->render(Args, CmdArgs);
47074707

4708+
// Set options for both host and device so we can manipulate host logic
4709+
// in case if bfloat16 conversion is supported
4710+
if (Arg *A = Args.getLastArg(options::OPT_fsycl_enable_bfloat16_conversion,
4711+
options::OPT_fsycl_enable_bfloat16_conversion))
4712+
A->render(Args, CmdArgs);
4713+
47084714
if (SYCLStdArg) {
47094715
SYCLStdArg->render(Args, CmdArgs);
47104716
CmdArgs.push_back("-fsycl-std-layout-kernel-params");

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
495495
// flag is used.
496496
if (LangOpts.SYCLDisableRangeRounding)
497497
Builder.defineMacro("__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__");
498+
499+
if (LangOpts.SYCLEnableBF16Conversion)
500+
Builder.defineMacro("__SYCL_ENABLE_BF16_CONVERSION__");
498501
}
499502

500503
if (LangOpts.DeclareSPIRVBuiltins) {

clang/test/Driver/sycl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// RUN: %clang_cl -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
4040
// RUN: %clangxx -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
4141
// RUN: %clang_cl -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
42+
// RUN: %clangxx -### -fsycl-device-only -fsycl-enable-bfloat16-conversion %s 2>&1 | FileCheck %s --check-prefix=CHECK-BFLOAT16-CONV
4243

4344
// DEFAULT: "-triple" "spir64-unknown-{{.*}}-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-sycl-std=2020"{{.*}} "-emit-llvm-bc"
4445
// DEFAULT: "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
@@ -53,6 +54,7 @@
5354
// COMBINED: "-triple" "spir64-unknown-{{.*}}-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
5455
// TEXTUAL: "-triple" "spir64-unknown-{{.*}}-sycldevice{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm"
5556
// CHECK-NOT-LAMBDA: "-fno-sycl-unnamed-lambda"
57+
// CHECK-BFLOAT16-CONV: "-fsycl-enable-bfloat16-conversion"
5658

5759
/// -fsycl-device-only triple checks
5860
// RUN: %clang -fsycl-device-only -target x86_64-unknown-linux-gnu -### %s 2>&1 \

clang/test/Preprocessor/sycl-macro.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
// RUN: %clang_cc1 -fno-sycl-id-queries-fit-in-int %s -E -dM | FileCheck \
1111
// RUN: --check-prefix=CHECK-NO-SYCL_FIT_IN_INT %s
1212

13+
// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck \
14+
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s
15+
// RUN: %clang_cc1 %s -fsycl-is-host -E -dM | FileCheck \
16+
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s
17+
// RUN: %clang_cc1 -fsycl-is-device -fsycl-enable-bfloat16-conversion -E -dM | FileCheck \
18+
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV %s
19+
// RUN: %clang_cc1 -fsycl-is-host -fsycl-enable-bfloat16-conversion -E -dM | FileCheck \
20+
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV %s
21+
// RUN: %clang_cc1 -fsycl-is-device -fno-sycl-enable-bfloat16-conversion -E -dM | FileCheck \
22+
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s
23+
// RUN: %clang_cc1 -fsycl-is-host -fno-sycl-enable-bfloat16-conversion -E -dM | FileCheck \
24+
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s
25+
1326
// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
1427
// CHECK-NOT:#define SYCL_EXTERNAL
1528
// CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
@@ -30,3 +43,6 @@
3043

3144
// CHECK-NO-SYCL_FIT_IN_INT-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
3245
// CHECK-SYCL-ID:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
46+
47+
// CHECK-SYCL-BFLOAT16-CONV:#define __SYCL_ENABLE_BF16_CONVERSION__ 1
48+
// CHECK-SYCL-BFLOAT16-CONV-DISABLED-NOT:#define __SYCL_ENABLE_BF16_CONVERSION__ 1

0 commit comments

Comments
 (0)