Skip to content

[SYCL] Add sycl-enable-bfloat16-conversion compilation flag #4343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/LangOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ LANGOPT(
"get/operator[], get_id/operator[] and get_global_id/get_global_linear_id "
"in SYCL class id, iterm and nd_iterm")
LANGOPT(SYCLDisableRangeRounding, 1, 0, "Disable parallel for range rounding")
LANGOPT(
SYCLEnableBF16Conversion, 1, 0,
"Enable generation of BFloat16 conversion instructions")

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

Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,11 @@ def fno_sycl_link_spirv : Flag<["-"], "fno-sycl-link-spirv">,
"when discovered in user specified objects and archives.">;
def fsyntax_only : Flag<["-"], "fsyntax-only">,
Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group<Action_Group>;
defm sycl_enable_bfloat16_conversion: BoolFOption<"sycl-enable-bfloat16-conversion",
LangOpts<"SYCLEnableBF16Conversion">, DefaultFalse,
PosFlag<SetTrue, [], "Define __SYCL_BF16_CONVERSION_IS_SUPPORTED__ macro and enable">,
NegFlag<SetFalse, [], "Do not enable">,
BothFlags<[CC1Option, CoreOption], " BFloat16 conversion extension">>;
def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group<f_Group>;
def ftemplate_depth_EQ : Joined<["-"], "ftemplate-depth=">, Group<f_Group>;
def ftemplate_depth_ : Joined<["-"], "ftemplate-depth-">, Group<f_Group>;
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4705,6 +4705,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fno_sycl_id_queries_fit_in_int))
A->render(Args, CmdArgs);

// Set options for both host and device so we can manipulate host logic
// in the case where bfloat16 conversion is supported
if (Arg *A =
Args.getLastArg(options::OPT_fsycl_enable_bfloat16_conversion,
options::OPT_fno_sycl_enable_bfloat16_conversion))
A->render(Args, CmdArgs);

if (SYCLStdArg) {
SYCLStdArg->render(Args, CmdArgs);
CmdArgs.push_back("-fsycl-std-layout-kernel-params");
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
// flag is used.
if (LangOpts.SYCLDisableRangeRounding)
Builder.defineMacro("__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__");

if (LangOpts.SYCLEnableBF16Conversion)
Builder.defineMacro("__SYCL_BF16_CONVERSION_IS_SUPPORTED__");
}

if (LangOpts.DeclareSPIRVBuiltins) {
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/sycl.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
// RUN: %clang_cl -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
// RUN: %clangxx -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
// RUN: %clang_cl -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
// RUN: %clangxx -### -fsycl -fsycl-enable-bfloat16-conversion %s 2>&1 | FileCheck %s --check-prefix=CHECK-BFLOAT16-CONV
// RUN: %clangxx -### -fsycl -fno-sycl-enable-bfloat16-conversion %s 2>&1 | FileCheck %s --check-prefix=CHECK-BFLOAT16-CONV-NEG

// DEFAULT: "-triple" "spir64-unknown-{{.*}}-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-sycl-std=2020"{{.*}} "-emit-llvm-bc"
// DEFAULT: "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
Expand All @@ -53,6 +55,8 @@
// COMBINED: "-triple" "spir64-unknown-{{.*}}-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
// TEXTUAL: "-triple" "spir64-unknown-{{.*}}-sycldevice{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm"
// CHECK-NOT-LAMBDA: "-fno-sycl-unnamed-lambda"
// CHECK-BFLOAT16-CONV: "-fsycl-enable-bfloat16-conversion"
// CHECK-BFLOAT16-CONV-NEG: "-fno-sycl-enable-bfloat16-conversion"

/// -fsycl-device-only triple checks
// RUN: %clang -fsycl-device-only -target x86_64-unknown-linux-gnu -### %s 2>&1 \
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Preprocessor/sycl-macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
// RUN: %clang_cc1 -fno-sycl-id-queries-fit-in-int %s -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-NO-SYCL_FIT_IN_INT %s

// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s
// RUN: %clang_cc1 %s -fsycl-is-host -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s
// RUN: %clang_cc1 -fsycl-is-device -fsycl-enable-bfloat16-conversion -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV %s
// RUN: %clang_cc1 -fsycl-is-host -fsycl-enable-bfloat16-conversion -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV %s
// RUN: %clang_cc1 -fsycl-is-device -fno-sycl-enable-bfloat16-conversion -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s
// RUN: %clang_cc1 -fsycl-is-host -fno-sycl-enable-bfloat16-conversion -E -dM | FileCheck \
// RUN: --check-prefix=CHECK-SYCL-BFLOAT16-CONV-DISABLED %s

// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
// CHECK-NOT:#define SYCL_EXTERNAL
// CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
Expand All @@ -30,3 +43,6 @@

// CHECK-NO-SYCL_FIT_IN_INT-NOT:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1
// CHECK-SYCL-ID:#define __SYCL_ID_QUERIES_FIT_IN_INT__ 1

// CHECK-SYCL-BFLOAT16-CONV:#define __SYCL_BF16_CONVERSION_IS_SUPPORTED__ 1
// CHECK-SYCL-BFLOAT16-CONV-DISABLED-NOT:#define __SYCL_BF16_CONVERSION_IS_SUPPORTED__ 1