@@ -3900,10 +3900,30 @@ pi_result piProgramLink(pi_context Context, pi_uint32 NumDevices,
3900
3900
ZeModuleDesc.pNext = &ZeExtModuleDesc;
3901
3901
ZeModuleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
3902
3902
3903
+ // This works around a bug in the Level Zero driver. When "ZE_DEBUG=-1",
3904
+ // the driver does validation of the API calls, and it expects
3905
+ // "pInputModule" to be non-NULL and "inputSize" to be non-zero. This
3906
+ // validation is wrong when using the "ze_module_program_exp_desc_t"
3907
+ // extension because those fields are supposed to be ignored. As a
3908
+ // workaround, set both fields to 1.
3909
+ //
3910
+ // TODO: Remove this workaround when the driver is fixed.
3911
+ ZeModuleDesc.pInputModule = reinterpret_cast <const uint8_t *>(1 );
3912
+ ZeModuleDesc.inputSize = 1 ;
3913
+
3903
3914
// We need a Level Zero extension to compile multiple programs together into
3904
3915
// a single Level Zero module. However, we don't need that extension if
3905
3916
// there happens to be only one input program.
3906
- if (!PiDriverModuleProgramExtensionFound) {
3917
+ //
3918
+ // The "|| (NumInputPrograms == 1)" term is a workaround for a bug in the
3919
+ // Level Zero driver. The driver's "ze_module_program_exp_desc_t"
3920
+ // extension should work even in the case when there is just one input
3921
+ // module. However, there is currently a bug in the driver that leads to a
3922
+ // crash. As a workaround, do not use the extension when there is one
3923
+ // input module.
3924
+ //
3925
+ // TODO: Remove this workaround when the driver is fixed.
3926
+ if (!PiDriverModuleProgramExtensionFound || (NumInputPrograms == 1 )) {
3907
3927
if (NumInputPrograms == 1 ) {
3908
3928
ZeModuleDesc.pNext = nullptr ;
3909
3929
ZeModuleDesc.inputSize = ZeExtModuleDesc.inputSizes [0 ];
0 commit comments