Skip to content

[SYCL] Correct CFE behavior with named lambdas in unnamed-lambda mode #3990

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

Merged
merged 47 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4342e62
[SYCL] Limit 'kernel name marking' to ONLY unnamed lambda cases.
Jun 24, 2021
f1a3fea
Aaron's comments
Jun 24, 2021
d526878
Try not marking all kernels to see if this makes CI happy
Jun 25, 2021
0fb1f52
Remove wacky semicolon
Jun 25, 2021
d38c494
Update clang/lib/Sema/SemaSYCL.cpp
Jun 25, 2021
b9aeb56
[SYCL] Move use of __builtin_sycl_mark_kernel_name, for CI
Jun 22, 2021
dd361c9
clang-format
Jun 22, 2021
c168d35
Add missing typename I think?
Jun 22, 2021
a58ae67
Fix build for GCC hopefully
Jun 22, 2021
b68740b
Remove wrappers use of get-kernel-name to avoid auto-name in non-unna…
Jun 22, 2021
07ed76a
Another attempt to see if we can get the tests happy
Jun 22, 2021
a42df1f
Do not use get_kernel_name_t for the second time for wrapper
AlexeySachkov Jun 23, 2021
5e42e89
Hopefully, the proper fix
AlexeySachkov Jun 24, 2021
a5255fb
Revert 'type' removal, that shouldn't be necessary anymore
Jun 23, 2021
2fb8ca1
Proper fix
AlexeySachkov Jun 24, 2021
cd4b60f
Add test for error about the lack of kernel name
AlexeySachkov Jun 25, 2021
13e2303
Do not use get_kernel_name_t for the second time for wrapper
AlexeySachkov Jun 23, 2021
344362e
Fix up sycl-std and -f[no-]sycl-unnamed-lambdas command line args to …
Jun 28, 2021
c9ce737
Make sure the kernel-name generated by the CFE is correct in respect …
Jun 28, 2021
d13d009
Correct generation of kernel name, correct the command-line bad-value…
Jun 29, 2021
ab287e5
Fix all of the sema checking to work with unnamed kernels/named kerne…
Jun 29, 2021
ce4208f
Clang-format fix
Jun 29, 2021
f8f2285
Add unnamed-ness to the kerneldesc
Jun 29, 2021
5e705aa
Change KernelInfo to work with the soon-to-be-implemented int-header
Jun 29, 2021
f53cbc8
clang format for kernel_desc
Jun 29, 2021
76e5ba1
First run at int-header
Jun 29, 2021
774fbdb
Fix some tests, correct initialization of FreeFunctionCalls
Jun 29, 2021
505f54c
Fix last test failures in check-clang
Jun 29, 2021
611e064
Add missing 'return' statements in kernelInfo
Jun 29, 2021
d476db9
Fix build error in kernel_desc
Jun 29, 2021
7d0cd2f
Add triple to a test to make sure it works on widows
Jun 29, 2021
f1cf728
Correct behavior of the __pf_kernel_wrapper to maintain namedness.
Jun 30, 2021
9be624c
Remove use of is_same_v which is C++17, update test to use disable la…
Jun 30, 2021
284df41
Update test to ensure -fsycl is passed to the driver
Jun 30, 2021
b1df7ea
Change reduction to make sure auto_name is preserved
Jun 30, 2021
067ffda
Fix reduction.hpp clang-format issue
Jun 30, 2021
32b4bc8
Take MikeT's suggestion on Options.td implementation.
Jun 30, 2021
131ba1f
Apparently BothFlags needs to go last, so fixing MikeT's suggestion
Jun 30, 2021
6fa0d7c
Fix build issues in reduction.hpp
Jul 1, 2021
f61c5fe
Fix another reduction.hpp build error
Jul 1, 2021
32b6b10
make changes requested by Aaron
Jul 6, 2021
4fde7ba
clang-format
Jul 6, 2021
afa2ece
Remove fsycl-unnamed-lambda from tests, now that it is the default be…
Jul 6, 2021
97f2e03
Convert test to /dev/null as requested by aaron
Jul 6, 2021
5d370ee
Add whitespace back!
Jul 7, 2021
8f45577
Add test to differentiate between qualified/unqualified unnamed lambdas
Jul 7, 2021
db8c428
Merge remote-tracking branch 'SYCL_public/sycl' into correct_kernel_n…
Jul 7, 2021
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
15 changes: 9 additions & 6 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ defvar hip = LangOpts<"HIP">;
defvar gnu_mode = LangOpts<"GNUMode">;
defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
defvar cpp_modules = LangOpts<"CPlusPlusModules">;
defvar sycl_ver = LangOpts<"SYCLVersion">;

defvar std = !strconcat("LangStandard::getLangStandardForKind(", lang_std.KeyPath, ")");

Expand Down Expand Up @@ -2599,9 +2600,14 @@ def fsycl_link_EQ : Joined<["-"], "fsycl-link=">,
def fsycl_link : Flag<["-"], "fsycl-link">, Alias<fsycl_link_EQ>,
AliasArgs<["early"]>, Flags<[CC1Option, CoreOption]>,
HelpText<"Generate partially linked device object to be used with the host link">;
def fsycl_unnamed_lambda : Flag<["-"], "fsycl-unnamed-lambda">,
Flags<[CC1Option, CoreOption]>, HelpText<"Allow unnamed SYCL lambda kernels">,
MarshallingInfoFlag<LangOpts<"SYCLUnnamedLambda">>;
defm sycl_unnamed_lambda
: BoolFOption<
"sycl-unnamed-lambda", LangOpts<"SYCLUnnamedLambda">,
Default<!strconcat(
sycl_ver.KeyPath,
" >= clang::LangOptions::SYCLMajorVersion::SYCL_2020")>,
PosFlag<SetTrue, [], "Allow">, NegFlag<SetFalse, [], "Disallow">,
BothFlags<[CC1Option, CoreOption], " unnamed SYCL lambda kernels">>;
def fsycl_help_EQ : Joined<["-"], "fsycl-help=">,
Flags<[NoXarchOption, CoreOption]>, HelpText<"Emit help information from the "
"related offline compilation tool. Valid values: all, fpga, gen, x86_64.">,
Expand Down Expand Up @@ -5896,9 +5902,6 @@ def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>,
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
HelpText<"SYCL language standard to compile for.">,
Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>,
NormalizedValuesScope<"LangOptions">,
MarshallingInfoEnum<LangOpts<"SYCLVersion">, "SYCL_None">,
ShouldParseIf<!strconcat(fsycl_is_device.KeyPath, "||", fsycl_is_host.KeyPath)>;

def fsycl_default_sub_group_size
Expand Down
30 changes: 17 additions & 13 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class SYCLIntegrationHeader {
};

public:
SYCLIntegrationHeader(bool UnnamedLambdaSupport, Sema &S);
SYCLIntegrationHeader(Sema &S);

/// Emits contents of the header into given stream.
void emit(raw_ostream &Out);
Expand All @@ -334,8 +334,8 @@ class SYCLIntegrationHeader {
/// Signals that subsequent parameter descriptor additions will go to
/// the kernel with given name. Starts new kernel invocation descriptor.
void startKernel(StringRef KernelName, QualType KernelNameType,
StringRef KernelStableName, SourceLocation Loc,
bool IsESIMD);
StringRef KernelStableName, SourceLocation Loc, bool IsESIMD,
bool IsUnnamedKernel);

/// Adds a kernel parameter descriptor to current kernel invocation
/// descriptor.
Expand Down Expand Up @@ -375,10 +375,10 @@ class SYCLIntegrationHeader {
// there are four free functions the kernel may call (this_id, this_item,
// this_nd_item, this_group)
struct KernelCallsSYCLFreeFunction {
bool CallsThisId;
bool CallsThisItem;
bool CallsThisNDItem;
bool CallsThisGroup;
bool CallsThisId = false;
bool CallsThisItem = false;
bool CallsThisNDItem = false;
bool CallsThisGroup = false;
};

// Kernel invocation descriptor
Expand All @@ -404,7 +404,15 @@ class SYCLIntegrationHeader {
// this_id(), etc)
KernelCallsSYCLFreeFunction FreeFunctionCalls;

KernelDesc() = default;
// If we are in unnamed kernel/lambda mode AND this is one that the user
// hasn't provided an explicit name for.
bool IsUnnamedKernel;

KernelDesc(StringRef Name, QualType NameType, StringRef StableName,
SourceLocation KernelLoc, bool IsESIMD, bool IsUnnamedKernel)
: Name(Name), NameType(NameType), StableName(StableName),
KernelLocation(KernelLoc), IsESIMDKernel(IsESIMD),
IsUnnamedKernel(IsUnnamedKernel) {}
};

/// Returns the latest invocation descriptor started by
Expand All @@ -426,9 +434,6 @@ class SYCLIntegrationHeader {
/// integration header emission time.
llvm::SmallVector<SpecConstID, 4> SpecConsts;

/// Whether header is generated with unnamed lambda support
bool UnnamedLambdaSupport;

Sema &S;
};

Expand Down Expand Up @@ -13293,8 +13298,7 @@ class Sema final {
/// Lazily creates and returns SYCL integration header instance.
SYCLIntegrationHeader &getSyclIntegrationHeader() {
if (SyclIntHeader == nullptr)
SyclIntHeader = std::make_unique<SYCLIntegrationHeader>(
getLangOpts().SYCLUnnamedLambda, *this);
SyclIntHeader = std::make_unique<SYCLIntegrationHeader>(*this);
return *SyclIntHeader.get();
}

Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4675,8 +4675,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Ensure the default version in SYCL mode is 2020.
CmdArgs.push_back("-sycl-std=2020");
}
if (Args.hasArg(options::OPT_fsycl_unnamed_lambda))
CmdArgs.push_back("-fsycl-unnamed-lambda");

if (!Args.hasFlag(options::OPT_fsycl_unnamed_lambda,
options::OPT_fno_sycl_unnamed_lambda))
CmdArgs.push_back("-fno-sycl-unnamed-lambda");

// Add the Unique ID prefix
StringRef UniqueID = D.getSYCLUniqueID(Input.getBaseInput());
Expand Down
46 changes: 36 additions & 10 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3546,6 +3546,20 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
case LangOptions::SubGroupSizeType::None:
break;
}

if (Opts.isSYCL()) {
switch (Opts.SYCLVersion) {
case LangOptions::SYCL_2017:
GenerateArg(Args, OPT_sycl_std_EQ, "2017", SA);
break;
case LangOptions::SYCL_2020:
GenerateArg(Args, OPT_sycl_std_EQ, "2020", SA);
break;
case LangOptions::SYCL_None:
// Do nothing, case where we were given an invalid value.
break;
}
}
}

bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Expand Down Expand Up @@ -3637,6 +3651,28 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
LangStd = OpenCLLangStd;
}

// We have to parse this manually before the marshalling, otherwise we can't
// use the marshalling to set other flags based on the SYCL version.
if (Args.hasArg(OPT_fsycl_is_device) || Args.hasArg(OPT_fsycl_is_host)) {
if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
Opts.setSYCLVersion(
llvm::StringSwitch<LangOptions::SYCLMajorVersion>(A->getValue())
.Case("2020", LangOptions::SYCL_2020)
.Cases("2017", "121", "1.2.1", "sycl-1.2.1",
LangOptions::SYCL_2017)
.Default(LangOptions::SYCL_None));

if (Opts.SYCLVersion == LangOptions::SYCL_None)
Diags.Report(diag::err_drv_invalid_value)
<< A->getAsString(Args) << A->getValue();
} else {
// If the user supplied -fsycl-is-device or -fsycl-is-host, but failed to
// provide -sycl-std=, we want to default it to whatever the default SYCL
// version is.
Opts.setSYCLVersion(LangOptions::SYCL_Default);
}
}

// Parse SYCL Default Sub group size.
if (const Arg *A = Args.getLastArg(OPT_fsycl_default_sub_group_size)) {
StringRef Value = A->getValue();
Expand Down Expand Up @@ -3687,16 +3723,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}

if ((Args.hasArg(OPT_fsycl_is_device) || Args.hasArg(OPT_fsycl_is_host)) &&
!Args.hasArg(OPT_sycl_std_EQ)) {
// If the user supplied -fsycl-is-device or -fsycl-is-host, but failed to
// provide -sycl-std=, we want to default it to whatever the default SYCL
// version is. I could not find a way to express this with the options
// tablegen because we still want this value to be SYCL_None when the user
// is not in device or host mode.
Opts.setSYCLVersion(LangOptions::SYCL_Default);
}

if (Opts.ObjC) {
if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
StringRef value = arg->getValue();
Expand Down
Loading