Skip to content

Commit 91bd27c

Browse files
committed
[SYCL] Diagnose error in L0 for linker options
The Level Zero driver does not support any way to pass options that are specific to the online linker, so diagnose an error if the application attempts to pass any. Previously, any such options were silently ignored. Note that the Level Zero driver does support online _compiler_ options, and the plugin correctly handles these.
1 parent 1450d95 commit 91bd27c

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,15 +3785,26 @@ pi_result piProgramLink(pi_context Context, pi_uint32 NumDevices,
37853785
const pi_program *InputPrograms,
37863786
void (*PFnNotify)(pi_program Program, void *UserData),
37873787
void *UserData, pi_program *RetProgram) {
3788-
(void)Options;
3789-
37903788
// We only support one device with Level Zero currently.
37913789
pi_device Device = Context->Devices[0];
37923790
if (NumDevices != 1) {
37933791
zePrint("piProgramLink: level_zero supports only one device.");
37943792
return PI_INVALID_VALUE;
37953793
}
37963794

3795+
// We do not support any link flags at this time because the Level Zero API
3796+
// does not have any way to pass flags that are specific to linking.
3797+
if (Options && *Options != '\0') {
3798+
std::string ErrorMessage(
3799+
"Level Zero does not support kernel link flags: \"");
3800+
ErrorMessage.append(Options);
3801+
ErrorMessage.push_back('\"');
3802+
pi_program Program =
3803+
new _pi_program(_pi_program::Invalid, Context, ErrorMessage);
3804+
*RetProgram = Program;
3805+
return PI_LINK_PROGRAM_FAILURE;
3806+
}
3807+
37973808
// Validate input parameters.
37983809
PI_ASSERT(DeviceList && DeviceList[0] == Device, PI_INVALID_DEVICE);
37993810
PI_ASSERT(!PFnNotify && !UserData, PI_INVALID_VALUE);
@@ -4051,16 +4062,26 @@ pi_result piProgramGetBuildInfo(pi_program Program, pi_device Device,
40514062
// with piProgramRegister?
40524063
return ReturnValue("");
40534064
} else if (ParamName == CL_PROGRAM_BUILD_LOG) {
4054-
// The OpenCL spec says an empty string is returned if there was no
4055-
// previous Compile, Build, or Link.
4056-
if (!Program->ZeBuildLog)
4057-
return ReturnValue("");
4058-
size_t LogSize = ParamValueSize;
4059-
ZE_CALL(zeModuleBuildLogGetString,
4060-
(Program->ZeBuildLog, &LogSize, pi_cast<char *>(ParamValue)));
4061-
if (ParamValueSizeRet) {
4062-
*ParamValueSizeRet = LogSize;
4065+
// Check first to see if the plugin code recorded an error message.
4066+
if (!Program->ErrorMessage.empty()) {
4067+
return ReturnValue(Program->ErrorMessage.c_str());
40634068
}
4069+
4070+
// Next check if there is a Level Zero build log.
4071+
if (Program->ZeBuildLog) {
4072+
size_t LogSize = ParamValueSize;
4073+
ZE_CALL(zeModuleBuildLogGetString,
4074+
(Program->ZeBuildLog, &LogSize, pi_cast<char *>(ParamValue)));
4075+
if (ParamValueSizeRet) {
4076+
*ParamValueSizeRet = LogSize;
4077+
}
4078+
return PI_SUCCESS;
4079+
}
4080+
4081+
// Otherwise, there is no error. The OpenCL spec says to return an empty
4082+
// string if there ws no previous attempt to compile, build, or link the
4083+
// program.
4084+
return ReturnValue("");
40644085
} else {
40654086
zePrint("piProgramGetBuildInfo: unsupported ParamName\n");
40664087
return PI_INVALID_VALUE;

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,11 @@ struct _pi_program : _pi_object {
10751075
: Context{Context}, OwnZeModule{OwnZeModule}, State{St},
10761076
ZeModule{ZeModule}, ZeBuildLog{nullptr} {}
10771077

1078+
// Construct a program in Invalid state with a custom error message.
1079+
_pi_program(state St, pi_context Context, const std::string &ErrorMessage)
1080+
: Context{Context}, OwnZeModule{true}, ErrorMessage{ErrorMessage},
1081+
State{St}, ZeModule{nullptr}, ZeBuildLog{nullptr} {}
1082+
10781083
~_pi_program();
10791084

10801085
const pi_context Context; // Context of the program.
@@ -1083,6 +1088,10 @@ struct _pi_program : _pi_object {
10831088
// asked to not transfer the ownership to SYCL RT.
10841089
const bool OwnZeModule;
10851090

1091+
// This error message is used only in Invalid state to hold a custom error
1092+
// message from a call to piProgramLink.
1093+
const std::string ErrorMessage;
1094+
10861095
// Protects accesses to all the non-const member variables. Exclusive access
10871096
// is required to modify any of these members.
10881097
std::shared_mutex Mutex;

0 commit comments

Comments
 (0)