@@ -2231,16 +2231,22 @@ pi_result piProgramLink(pi_context Context, pi_uint32 NumDevices,
2231
2231
ZeHandles.push_back (Input->ZeModule );
2232
2232
}
2233
2233
2234
- // Link all the modules together. If this fails (or if we catch an
2235
- // exception below), we need to release the reference counts on the input
2236
- // modules, delete any copies, etc.
2234
+ // Link all the modules together.
2237
2235
ze_module_build_log_handle_t ZeBuildLog;
2238
- ZE_CALL (zeModuleDynamicLinkMock (ZeHandles. size (), ZeHandles. data (),
2239
- &ZeBuildLog));
2236
+ ze_result_t ZeResult = ZE_CALL_NOCHECK (zeModuleDynamicLinkMock (
2237
+ ZeHandles. size (), ZeHandles. data (), &ZeBuildLog));
2240
2238
2241
2239
// Construct a new program object to represent the linked executable. This
2242
- // new object holds a reference to all the input programs.
2243
- *RetProgram = new _pi_program (Context, std::move (Inputs), ZeBuildLog);
2240
+ // new object holds a reference to all the input programs. Note that we
2241
+ // create this program object even if the link fails with "link failure"
2242
+ // because we need the new program object to hold the buid log (which has
2243
+ // the description of the failure).
2244
+ if (ZeResult == ZE_RESULT_SUCCESS ||
2245
+ ZeResult == ZE_RESULT_ERROR_MODULE_LINK_FAILURE) {
2246
+ *RetProgram = new _pi_program (Context, std::move (Inputs), ZeBuildLog);
2247
+ }
2248
+ if (ZeResult != ZE_RESULT_SUCCESS)
2249
+ return mapError (ZeResult);
2244
2250
} catch (const std::bad_alloc &) {
2245
2251
return PI_OUT_OF_HOST_MEMORY;
2246
2252
} catch (...) {
@@ -2356,9 +2362,8 @@ static pi_result compileOrBuild(pi_program Program, pi_uint32 NumDevices,
2356
2362
ze_device_handle_t ZeDevice = DeviceList[0 ]->ZeDevice ;
2357
2363
ze_context_handle_t ZeContext = Program->Context ->ZeContext ;
2358
2364
ze_module_handle_t ZeModule;
2359
- ze_module_build_log_handle_t ZeBuildLog;
2360
2365
ZE_CALL (zeModuleCreate (ZeContext, ZeDevice, &ZeModuleDesc, &ZeModule,
2361
- &ZeBuildLog));
2366
+ &Program-> ZeBuildLog ));
2362
2367
2363
2368
// Check if this module imports any symbols, which we need to know if we
2364
2369
// end up linking this module later. See comments in piProgramLink() for
@@ -2371,7 +2376,6 @@ static pi_result compileOrBuild(pi_program Program, pi_uint32 NumDevices,
2371
2376
// The caller must set the State to Object or Exe as appropriate.
2372
2377
Program->Code .reset ();
2373
2378
Program->ZeModule = ZeModule;
2374
- Program->ZeBuildLog = ZeBuildLog;
2375
2379
return PI_SUCCESS;
2376
2380
}
2377
2381
0 commit comments