@@ -2231,16 +2231,22 @@ pi_result piProgramLink(pi_context Context, pi_uint32 NumDevices,
22312231 ZeHandles.push_back (Input->ZeModule );
22322232 }
22332233
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.
22372235 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));
22402238
22412239 // 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);
22442250 } catch (const std::bad_alloc &) {
22452251 return PI_OUT_OF_HOST_MEMORY;
22462252 } catch (...) {
@@ -2356,9 +2362,8 @@ static pi_result compileOrBuild(pi_program Program, pi_uint32 NumDevices,
23562362 ze_device_handle_t ZeDevice = DeviceList[0 ]->ZeDevice ;
23572363 ze_context_handle_t ZeContext = Program->Context ->ZeContext ;
23582364 ze_module_handle_t ZeModule;
2359- ze_module_build_log_handle_t ZeBuildLog;
23602365 ZE_CALL (zeModuleCreate (ZeContext, ZeDevice, &ZeModuleDesc, &ZeModule,
2361- &ZeBuildLog));
2366+ &Program-> ZeBuildLog ));
23622367
23632368 // Check if this module imports any symbols, which we need to know if we
23642369 // 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,
23712376 // The caller must set the State to Object or Exe as appropriate.
23722377 Program->Code .reset ();
23732378 Program->ZeModule = ZeModule;
2374- Program->ZeBuildLog = ZeBuildLog;
23752379 return PI_SUCCESS;
23762380}
23772381
0 commit comments