Skip to content

Commit 96b0af3

Browse files
committed
[SYCL][ESIMD] Add driver option to enable SYCL Explicit SIMD extension.
Options name: -fsycl-explicit-simd. This option is temporary until ESIMD and normal SYCL kernels can co-exist in the same source. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 0681a36 commit 96b0af3

File tree

7 files changed

+29
-0
lines changed

7 files changed

+29
-0
lines changed

clang/include/clang/Basic/Attr.td

+1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def CUDA : LangOpt<"CUDA">;
327327
def SYCLIsDevice : LangOpt<"SYCLIsDevice">;
328328
def SYCL : LangOpt<"SYCLIsDevice">;
329329
def SYCLIsHost : LangOpt<"SYCLIsHost">;
330+
def SYCLExplicitSIMD : LangOpt<"SYCLExplicitSIMD">;
330331
def HIP : LangOpt<"HIP">;
331332
def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
332333
def CPlusPlus : LangOpt<"CPlusPlus">;

clang/include/clang/Basic/LangOptions.def

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ LANGOPT(SYCLStdLayoutKernelParams, 1, 0, "Enable standard layout requirement for
248248
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
249249
LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used")
250250
LANGOPT(DeclareSPIRVBuiltins, 1, 0, "Declare SPIR-V builtin functions")
251+
LANGOPT(SYCLExplicitSIMD , 1, 0, "SYCL compilation with explicit SIMD extension")
251252

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

clang/include/clang/Driver/Options.td

+4
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,10 @@ def fno_sycl : Flag<["-"], "fno-sycl">, Group<sycl_Group>, Flags<[CoreOption]>,
35503550
HelpText<"Disable SYCL kernels compilation for device">;
35513551
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
35523552
HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 1.2.1, sycl-1.2.1">;
3553+
def fsycl_esimd : Flag<["-"], "fsycl-explicit-simd">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
3554+
HelpText<"Enable SYCL explicit SIMD extension">;
3555+
def fno_sycl_esimd : Flag<["-"], "fno-sycl-explicit-simd">, Group<sycl_Group>,
3556+
HelpText<"Disable SYCL explicit SIMD extension">, Flags<[NoArgumentUnused, CoreOption]>;
35533557

35543558
include "CC1Options.td"
35553559

clang/lib/Driver/ToolChains/Clang.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -4124,6 +4124,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41244124
CmdArgs.push_back("-fsycl");
41254125
CmdArgs.push_back("-fsycl-is-device");
41264126
CmdArgs.push_back("-fdeclare-spirv-builtins");
4127+
4128+
if (Args.hasFlag(options::OPT_fsycl_esimd, options::OPT_fno_sycl_esimd,
4129+
false))
4130+
CmdArgs.push_back("-fsycl-explicit-simd");
41274131
// Pass the triple of host when doing SYCL
41284132
auto AuxT = llvm::Triple(llvm::sys::getProcessTriple());
41294133
std::string NormalizedTriple = AuxT.normalize();
@@ -6145,6 +6149,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
61456149
// doing the host pass.
61466150
CmdArgs.push_back("-fsycl");
61476151
CmdArgs.push_back("-fsycl-is-host");
6152+
6153+
// TODO add support to specify options shared between host and device
6154+
// compilation only once.
6155+
if (Args.hasFlag(options::OPT_fsycl_esimd, options::OPT_fno_sycl_esimd,
6156+
false))
6157+
CmdArgs.push_back("-fsycl-explicit-simd");
61486158
}
61496159
if (IsSYCLOffloadDevice && JA.getType() == types::TY_SYCL_Header) {
61506160
// Generating a SYCL Header

clang/lib/Frontend/CompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
25562556
<< A->getAsString(Args) << A->getValue();
25572557
}
25582558
}
2559+
Opts.SYCLExplicitSIMD = Args.hasArg(options::OPT_fsycl_esimd);
25592560
}
25602561

25612562
Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);

clang/lib/Frontend/InitPreprocessor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11131113
Builder.defineMacro("__SYCL_NVPTX__", "1");
11141114
}
11151115
}
1116+
if (LangOpts.SYCLExplicitSIMD)
1117+
Builder.defineMacro("__SYCL_EXPLICIT_SIMD__", "1");
11161118
if (LangOpts.SYCLUnnamedLambda)
11171119
Builder.defineMacro("__SYCL_UNNAMED_LAMBDA__", "1");
11181120

clang/test/Driver/sycl-esimd.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// Check that explicit SIMD extension is disabled by default:
2+
// RUN: %clang -### %s 2>&1 \
3+
// RUN: | FileCheck -check-prefix=CHECK-DEFAULT %s
4+
// CHECK-DEFAULT-NOT: "-fsycl-explicit-simd"
5+
6+
/// Check "-fsycl-explicit-simd" is passed when compiling for device and host:
7+
// RUN: %clang -### -fsycl -fsycl-explicit-simd %s 2>&1 \
8+
// RUN: | FileCheck -check-prefix=CHECK-SYCL-ESIMD %s
9+
// CHECK-SYCL-ESIMD: "-cc1"{{.*}} "-fsycl-explicit-simd"{{.*}}
10+
// CHECK-SYCL-ESIMD: "-cc1"{{.*}} "-fsycl-explicit-simd"{{.*}}

0 commit comments

Comments
 (0)