Skip to content

Commit 4dbb34a

Browse files
authored
[SYCL][PI][L0] Skip modules without kernel inside when creating target kernel on L0 (#3614)
On L0 backend, we iterate all models in a pi_program, for each module, we call zeKernelCreate. If the call fails due to some error other than "ze invalid kernel name", the kernel creation will fail and current program will abort. However, this logic assume that all modules in the pi_program will have some kernel inside. If we enable SYCL device library "online" link based on piProgramLink, the assumption will be broken. At that time, the pi_program will include some modules from device library without any kernel inside(they are used to resolve undefined symbol in user's image), if we call zeKernelCreate for those module, the return value is "ze invalid argument" instead of "ze invalid kernel name". Suppose under such circumstance, the pi_program includes 2 modules, mod1 for device library without any kernel and mod2 for user's device image with target kernel, we will firstly try to zeKernelCreate for mod1 and the API returns with error "ze invalid argument", then the program will abort but in fact, we can create the target kernel with mod2. This change enables skipping all modules without any kernel inside before trying to call zeKernelCreate for them, this is done by using zeModuelGetKernelNames to query the number of kernel names in module, if kernel name num is 0, we skip it.
1 parent 870b840 commit 4dbb34a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,10 +3517,20 @@ pi_result piKernelCreate(pi_program Program, const char *KernelName,
35173517
ze_result_t ZeResult = ZE_RESULT_ERROR_INVALID_KERNEL_NAME;
35183518
_pi_program::ModuleIterator ModIt(Program);
35193519
while (!ModIt.Done()) {
3520-
ZeResult =
3521-
ZE_CALL_NOCHECK(zeKernelCreate, (*ModIt, &ZeKernelDesc, &ZeKernel));
3522-
if (ZeResult != ZE_RESULT_ERROR_INVALID_KERNEL_NAME)
3523-
break;
3520+
// For a module with valid sycl kernel inside, zeKernelCreate API
3521+
// should return ZE_RESULT_SUCCESS if target kernel is found and
3522+
// ZE_RESULT_ERROR_INVALID_KERNEL_NAME otherwise. However, some module
3523+
// may not include any sycl kernel such as device library modules. For such
3524+
// modules, zeKernelCreate will return ZE_RESULT_ERROR_INVALID_ARGUMENT and
3525+
// we should skip them.
3526+
uint32_t KernelNum = 0;
3527+
ZE_CALL(zeModuleGetKernelNames, (*ModIt, &KernelNum, nullptr));
3528+
if (KernelNum != 0) {
3529+
ZeResult =
3530+
ZE_CALL_NOCHECK(zeKernelCreate, (*ModIt, &ZeKernelDesc, &ZeKernel));
3531+
if (ZeResult != ZE_RESULT_ERROR_INVALID_KERNEL_NAME)
3532+
break;
3533+
}
35243534
ModIt++;
35253535
}
35263536
if (ZeResult != ZE_RESULT_SUCCESS)

0 commit comments

Comments
 (0)