Skip to content

Commit cb8c5b7

Browse files
committed
[SYCL][RTC] Rework handling of build_options
Signed-off-by: Julian Oppermann <[email protected]>
1 parent 17df762 commit cb8c5b7

File tree

2 files changed

+33
-73
lines changed

2 files changed

+33
-73
lines changed

sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,15 @@ static void adjustArgs(const InputArgList &UserArgList,
321321
DAL.AddJoinedArg(
322322
nullptr, OptTable.getOption(OPT_resource_dir_EQ),
323323
(DPCPPRoot + "/lib/clang/" + Twine(CLANG_VERSION_MAJOR)).str());
324-
for (auto *Arg : UserArgList) {
325-
DAL.append(Arg);
326-
}
327-
// Remove args that will trigger an unused command line argument warning for
328-
// the FrontendAction invocation, but are handled later (e.g. during device
329-
// linking).
330-
DAL.eraseArg(OPT_fsycl_device_lib_EQ);
331-
DAL.eraseArg(OPT_fno_sycl_device_lib_EQ);
332-
DAL.eraseArg(OPT_ftime_trace_EQ);
333-
DAL.eraseArg(OPT_ftime_trace_granularity_EQ);
334-
DAL.eraseArg(OPT_ftime_trace_verbose);
324+
// User args may contain options not intended for the frontend, but we can't
325+
// claim them here to tell the driver they're used later. Hence, suppress the
326+
// unused argument warning.
327+
DAL.AddFlagArg(nullptr, OptTable.getOption(OPT_Qunused_arguments));
335328

336329
ArgStringList ASL;
337330
for_each(DAL, [&DAL, &ASL](Arg *A) { A->render(DAL, ASL); });
331+
for_each(UserArgList,
332+
[&UserArgList, &ASL](Arg *A) { A->render(UserArgList, ASL); });
338333
transform(ASL, std::back_inserter(CommandLine),
339334
[](const char *AS) { return std::string{AS}; });
340335
}
@@ -751,51 +746,22 @@ jit_compiler::parseUserArgs(View<const char *> UserArgs) {
751746
UserArgsRef[MissingArgIndex], MissingArgIndex);
752747
}
753748

754-
// Check for unsupported options.
755-
// TODO: There are probably more, e.g. requesting non-SPIR-V targets.
756-
{
757-
// -fsanitize=address
758-
bool IsDeviceAsanEnabled = false;
759-
if (Arg *A = AL.getLastArg(OPT_fsanitize_EQ, OPT_fno_sanitize_EQ)) {
760-
if (A->getOption().matches(OPT_fsanitize_EQ) &&
761-
A->getValues().size() == 1) {
762-
std::string SanitizeVal = A->getValue();
763-
IsDeviceAsanEnabled = SanitizeVal == "address";
764-
}
765-
} else {
766-
// User can pass -fsanitize=address to device compiler via
767-
// -Xsycl-target-frontend.
768-
auto SyclFEArg = AL.getAllArgValues(OPT_Xsycl_frontend);
769-
IsDeviceAsanEnabled = (std::count(SyclFEArg.begin(), SyclFEArg.end(),
770-
"-fsanitize=address") > 0);
771-
if (!IsDeviceAsanEnabled) {
772-
auto SyclFEArgEq = AL.getAllArgValues(OPT_Xsycl_frontend_EQ);
773-
IsDeviceAsanEnabled =
774-
(std::count(SyclFEArgEq.begin(), SyclFEArgEq.end(),
775-
"-fsanitize=address") > 0);
776-
}
777-
778-
// User can also enable asan for SYCL device via -Xarch_device option.
779-
if (!IsDeviceAsanEnabled) {
780-
auto DeviceArchVals = AL.getAllArgValues(OPT_Xarch_device);
781-
for (auto DArchVal : DeviceArchVals) {
782-
if (DArchVal.find("-fsanitize=address") != std::string::npos) {
783-
IsDeviceAsanEnabled = true;
784-
break;
785-
}
786-
}
787-
}
788-
}
789-
790-
if (IsDeviceAsanEnabled) {
791-
return createStringError(
792-
"Device ASAN is not supported for runtime compilation");
793-
}
794-
}
795-
796-
if (!AL.hasFlag(OPT_fsycl_device_code_split_esimd,
797-
OPT_fno_sycl_device_code_split_esimd, true)) {
798-
return createStringError("ESIMD device code split cannot be deactivated");
749+
// Check for options that are unsupported because they would interfere with
750+
// the in-memory pipeline.
751+
Arg *UnsupportedArg =
752+
AL.getLastArg(OPT_Action_Group, // Actions like -c or -S
753+
OPT_Link_Group, // Linker flags
754+
OPT_DebugInfo_Group, // Debugging
755+
OPT_o, // Output file
756+
OPT_fsycl_targets_EQ, // AoT compilation
757+
OPT_fsycl_link_EQ, // SYCL linker
758+
OPT_fno_sycl_device_code_split_esimd, // invoke_simd
759+
OPT_fsanitize_EQ // Sanitizer
760+
);
761+
if (UnsupportedArg) {
762+
return createStringError(
763+
"Option '%s' is not supported for SYCL runtime compilation",
764+
UnsupportedArg->getAsString(AL).c_str());
799765
}
800766

801767
return std::move(AL);

sycl/test-e2e/KernelCompiler/kernel_compiler_sycl_jit.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -551,23 +551,17 @@ int test_unsupported_options() {
551551
ctx, syclex::source_language::sycl_jit, "");
552552
std::vector<sycl::device> devs = kbSrc.get_devices();
553553

554-
auto CheckUnsupported = [&](const std::vector<std::string> &flags) {
555-
try {
556-
syclex::build(kbSrc, devs,
557-
syclex::properties{syclex::build_options{flags}});
558-
assert(false && "unsupported option not detected");
559-
} catch (sycl::exception &e) {
560-
assert(e.code() == sycl::errc::build);
561-
assert(std::string(e.what()).find("Parsing of user arguments failed") !=
562-
std::string::npos);
563-
}
564-
};
565-
566-
CheckUnsupported({"-fsanitize=address"});
567-
CheckUnsupported({"-Xsycl-target-frontend", "-fsanitize=address"});
568-
CheckUnsupported({"-Xsycl-target-frontend=spir64", "-fsanitize=address"});
569-
CheckUnsupported({"-Xarch_device", "-fsanitize=address"});
570-
CheckUnsupported({"-fno-sycl-device-code-split-esimd"});
554+
try {
555+
// Don't attempt to test exhaustively here...
556+
syclex::build(kbSrc, devs,
557+
syclex::properties{
558+
syclex::build_options{"-fsycl-targets=intel_gpu_pvc"}});
559+
assert(false && "unsupported option not detected");
560+
} catch (sycl::exception &e) {
561+
assert(e.code() == sycl::errc::build);
562+
assert(std::string(e.what()).find("Parsing of user arguments failed") !=
563+
std::string::npos);
564+
}
571565

572566
return 0;
573567
}

0 commit comments

Comments
 (0)