@@ -4305,28 +4305,37 @@ pi_result piProgramBuild(pi_program Program, pi_uint32 NumDevices,
4305
4305
ze_device_handle_t ZeDevice = DeviceList[0 ]->ZeDevice ;
4306
4306
ze_context_handle_t ZeContext = Program->Context ->ZeContext ;
4307
4307
ze_module_handle_t ZeModule = nullptr ;
4308
- ZE_CALL (zeModuleCreate, (ZeContext, ZeDevice, &ZeModuleDesc, &ZeModule,
4309
- &Program->ZeBuildLog ));
4310
-
4311
- // The call to zeModuleCreate does not report an error if there are
4312
- // unresolved symbols because it thinks these could be resolved later via a
4313
- // call to zeModuleDynamicLink. However, modules created with piProgramBuild
4314
- // are supposed to be fully linked and ready to use. Therefore, do an extra
4315
- // check now for unresolved symbols.
4316
- ze_result_t ZeResult = checkUnresolvedSymbols (ZeModule, &Program->ZeBuildLog );
4317
- if (ZeResult == ZE_RESULT_ERROR_MODULE_LINK_FAILURE) {
4318
- return PI_BUILD_PROGRAM_FAILURE;
4319
- } else if (ZeResult != ZE_RESULT_SUCCESS) {
4320
- return mapError (ZeResult);
4308
+
4309
+ pi_result Result = PI_SUCCESS;
4310
+ Program->State = _pi_program::Exe;
4311
+ ze_result_t ZeResult =
4312
+ ZE_CALL_NOCHECK (zeModuleCreate, (ZeContext, ZeDevice, &ZeModuleDesc,
4313
+ &ZeModule, &Program->ZeBuildLog ));
4314
+ if (ZeResult != ZE_RESULT_SUCCESS) {
4315
+ // We adjust pi_program below to avoid attempting to release zeModule when
4316
+ // RT calls piProgramRelease().
4317
+ ZeModule = nullptr ;
4318
+ Program->State = _pi_program::Invalid;
4319
+ Result = mapError (ZeResult);
4320
+ } else {
4321
+ // The call to zeModuleCreate does not report an error if there are
4322
+ // unresolved symbols because it thinks these could be resolved later via a
4323
+ // call to zeModuleDynamicLink. However, modules created with
4324
+ // piProgramBuild are supposed to be fully linked and ready to use.
4325
+ // Therefore, do an extra check now for unresolved symbols.
4326
+ ZeResult = checkUnresolvedSymbols (ZeModule, &Program->ZeBuildLog );
4327
+ if (ZeResult != ZE_RESULT_SUCCESS) {
4328
+ Program->State = _pi_program::Invalid;
4329
+ Result = (ZeResult == ZE_RESULT_ERROR_MODULE_LINK_FAILURE)
4330
+ ? PI_BUILD_PROGRAM_FAILURE
4331
+ : mapError (ZeResult);
4332
+ }
4321
4333
}
4322
4334
4323
4335
// We no longer need the IL / native code.
4324
4336
Program->Code .reset ();
4325
-
4326
4337
Program->ZeModule = ZeModule;
4327
- Program->State = _pi_program::Exe;
4328
-
4329
- return PI_SUCCESS;
4338
+ return Result;
4330
4339
}
4331
4340
4332
4341
pi_result piProgramGetBuildInfo (pi_program Program, pi_device Device,
0 commit comments