Skip to content

Commit 9500875

Browse files
authored
[SYCL] Handle nullptr arguments in level_zero (#6464)
* [SYCL] Handle nullptr arguments in level_zero If specialization constant is not used on device, then the buffer for it is not created on device side. In this case the host part passes nullptr for the corresponding kernel operand holding the reference to the buffer with constants. This patch fixes the level_zero arguments handling to avoid SegFault in the plugin. Signed-off-by: Vyacheslav N Klochkov <vyacheslav.n.klochkov@intel.com>
1 parent a0bfab1 commit 9500875

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4976,8 +4976,11 @@ pi_result piextKernelSetArgMemObj(pi_kernel Kernel, pi_uint32 ArgIndex,
49764976
// piextKernelSetArgMemObj.
49774977
//
49784978
std::scoped_lock Guard(Kernel->Mutex);
4979+
// The ArgValue may be a NULL pointer in which case a NULL value is used for
4980+
// the kernel argument declared as a pointer to global or constant memory.
4981+
auto Arg = ArgValue ? *ArgValue : nullptr;
49794982
Kernel->PendingArguments.push_back(
4980-
{ArgIndex, sizeof(void *), *ArgValue, _pi_mem::read_write});
4983+
{ArgIndex, sizeof(void *), Arg, _pi_mem::read_write});
49814984

49824985
return PI_SUCCESS;
49834986
}
@@ -5201,9 +5204,13 @@ piEnqueueKernelLaunch(pi_queue Queue, pi_kernel Kernel, pi_uint32 WorkDim,
52015204

52025205
// If there are any pending arguments set them now.
52035206
for (auto &Arg : Kernel->PendingArguments) {
5204-
char **ZeHandlePtr;
5205-
PI_CALL(
5206-
Arg.Value->getZeHandlePtr(ZeHandlePtr, Arg.AccessMode, Queue->Device));
5207+
// The ArgValue may be a NULL pointer in which case a NULL value is used for
5208+
// the kernel argument declared as a pointer to global or constant memory.
5209+
char **ZeHandlePtr = nullptr;
5210+
if (Arg.Value) {
5211+
PI_CALL(Arg.Value->getZeHandlePtr(ZeHandlePtr, Arg.AccessMode,
5212+
Queue->Device));
5213+
}
52075214
ZE_CALL(zeKernelSetArgumentValue,
52085215
(Kernel->ZeKernel, Arg.Index, Arg.Size, ZeHandlePtr));
52095216
}

0 commit comments

Comments
 (0)