Merged
fix(machine): Report queued errors on bundle launch failure #6171
W4termyAdd on Sep 11
fix(machine): Report queued errors on bundle launch failure #6171
Merged
W4termyAdd on Sep 11
Total: 4 files changed+35-23
@@ -32,6 +32,7 @@
32#include "machine/runtime/context/stream_context.h"32#include "machine/runtime/context/stream_context.h"
33#include "machine/runtime/context/device_launcher_context.h"33#include "machine/runtime/context/device_launcher_context.h"
34#include "machine/runtime/runner/runtime_utils.h"34#include "machine/runtime/runner/runtime_utils.h"
35+#include "machine/runtime/runner/load_aicpu_op.h"
35#include "machine/runtime/runner/host_prof.h"36#include "machine/runtime/runner/host_prof.h"
36#include "machine/runtime/launcher/device_launcher.h"37#include "machine/runtime/launcher/device_launcher.h"
37#include "machine/runtime/launcher/cell_match_dynamic.h"38#include "machine/runtime/launcher/cell_match_dynamic.h"
@@ -40,12 +41,12 @@ namespace npu::tile_fwk::dynamic {
40 41 
41namespace {42namespace {
42// aicpu launch primitive (topology from devProg), kept here so device_launcher stays free of bundle code.43// aicpu launch primitive (topology from devProg), kept here so device_launcher stays free of bundle code.
43-int BundleLaunchAicpu(RtAicpuArgsEx& rtArgs, DevAscendProgram* devProg)44+int BundleLaunchAicpu(AicpuLaunchDesc& launchDesc, DevAscendProgram* devProg)
44{45{
45 auto ctrlStream = GetStreamContext().GetCtrlStream();46 auto ctrlStream = GetStreamContext().GetCtrlStream();
46 auto schedStream = GetStreamContext().GetScheStream();47 auto schedStream = GetStreamContext().GetScheStream();
47 int ret = 0;48 int ret = 0;
48- auto args = (AiCpuArgs*)rtArgs.args;49+ auto args = launchDesc.args;
49 const int nrAicpu = static_cast<int>(devProg->devArgs.nrAicpu);50 const int nrAicpu = static_cast<int>(devProg->devArgs.nrAicpu);
50 const bool launchSchedSameCluster = static_cast<int>(devProg->devArgs.launchSchedSameCluster);51 const bool launchSchedSameCluster = static_cast<int>(devProg->devArgs.launchSchedSameCluster);
51 if (launchSchedSameCluster) {52 if (launchSchedSameCluster) {
@@ -55,9 +56,9 @@ int BundleLaunchAicpu(RtAicpuArgsEx& rtArgs, DevAscendProgram* devProg)
55 args->kArgs.parameter.ctrlBlockNum = static_cast<int>(devProg->ctrlBlockDim);56 args->kArgs.parameter.ctrlBlockNum = static_cast<int>(devProg->ctrlBlockDim);
56 auto startTime = MspfSysCycleTime();57 auto startTime = MspfSysCycleTime();
57 args->kArgs.parameter.runMode = RUN_SPLITTED_STREAM_CTRL;58 args->kArgs.parameter.runMode = RUN_SPLITTED_STREAM_CTRL;
58- ret = RuntimeAicpuKernelLaunchExWithArgs(static_cast<uint32_t>(npu::tile_fwk::RtKernelType::AICPU_KFC),59+ launchDesc.stream = ctrlStream;
59- "AST_DYN_AICPU", 1, &rtArgs, nullptr, ctrlStream,60+ launchDesc.blockDim = 1U;
60- RT_KERNEL_USE_SPECIAL_TIMEOUT);61+ ret = LaunchPyptoRunWithHostArgs(launchDesc);
61 HostProf::GetInstance().ReportHostProfInfo(ctrlStream, startTime, 1, MSPF_GE_TASK_TYPE_AI_CPU, false);62 HostProf::GetInstance().ReportHostProfInfo(ctrlStream, startTime, 1, MSPF_GE_TASK_TYPE_AI_CPU, false);
62 if (ret != RT_SUCCESS) {63 if (ret != RT_SUCCESS) {
63 return ret;64 return ret;
@@ -68,9 +69,9 @@ int BundleLaunchAicpu(RtAicpuArgsEx& rtArgs, DevAscendProgram* devProg)
68 args->kArgs.parameter.runMode = RUN_SPLITTED_STREAM_SCHE;69 args->kArgs.parameter.runMode = RUN_SPLITTED_STREAM_SCHE;
69 startTime = MspfSysCycleTime();70 startTime = MspfSysCycleTime();
70 const int scheCpuNum = static_cast<int>(devProg->devArgs.scheCpuNum);71 const int scheCpuNum = static_cast<int>(devProg->devArgs.scheCpuNum);
71- ret = RuntimeAicpuKernelLaunchExWithArgs(static_cast<uint32_t>(npu::tile_fwk::RtKernelType::AICPU_KFC),72+ launchDesc.stream = schedStream;
72- "AST_DYN_AICPU", nrAicpu, &rtArgs, nullptr, schedStream,73+ launchDesc.blockDim = static_cast<uint32_t>(nrAicpu);
73- RT_KERNEL_USE_SPECIAL_TIMEOUT);74+ ret = LaunchPyptoRunWithHostArgs(launchDesc);
74 HostProf::GetInstance().ReportHostProfInfo(schedStream, startTime, scheCpuNum, MSPF_GE_TASK_TYPE_AI_CPU, false);75 HostProf::GetInstance().ReportHostProfInfo(schedStream, startTime, scheCpuNum, MSPF_GE_TASK_TYPE_AI_CPU, false);
75 return ret;76 return ret;
76}77}
@@ -187,19 +188,16 @@ int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binH
187 aicpuArgs->kArgs.runtimeDynamicCellMatchAddr = reinterpret_cast<uint64_t>(cellMatchAddr);188 aicpuArgs->kArgs.runtimeDynamicCellMatchAddr = reinterpret_cast<uint64_t>(cellMatchAddr);
188 aicpuArgs->kArgs.runtimeDynamicCellMatchCapacity = cellMatchAddr != nullptr ? dynamicCellMatchBytes : 0;189 aicpuArgs->kArgs.runtimeDynamicCellMatchCapacity = cellMatchAddr != nullptr ? dynamicCellMatchBytes : 0;
189 190 
190- // rt args.191+ // Resolve the entry through PyptoRun; only the input tensor pointer needs host-args relocation.
191- RtAicpuArgsEx rtAicpuArgs;192+ AicpuLaunchDesc aicpuLaunchDesc{};
192- (void)memset_s(&rtAicpuArgs, sizeof(RtAicpuArgsEx), 0, sizeof(RtAicpuArgsEx));193+ AicpuHostInput hostInfo{};
193- rtAicpuArgs.kernelNameAddrOffset = offsetof(AiCpuArgs, kernelName);
194- rtAicpuArgs.soNameAddrOffset = offsetof(AiCpuArgs, soName);
195- rtAicpuArgs.hostInputInfoNum = 1;
196- RtHostInputInfo hostInfo;
197 hostInfo.addrOffset = offsetof(AiCpuArgs, kArgs.inputs);194 hostInfo.addrOffset = offsetof(AiCpuArgs, kArgs.inputs);
198 hostInfo.dataOffset = sizeof(AiCpuArgs);195 hostInfo.dataOffset = sizeof(AiCpuArgs);
199- rtAicpuArgs.hostInputInfoPtr = &hostInfo;196+ aicpuLaunchDesc.hostInputs = &hostInfo;
200- rtAicpuArgs.timeout = AICPU_EXECUTE_TIMEOUT;197+ aicpuLaunchDesc.hostInputNum = 1;
201- rtAicpuArgs.args = aicpuArgs;198+ aicpuLaunchDesc.timeout = AICPU_EXECUTE_TIMEOUT;
202- rtAicpuArgs.argsSize = static_cast<uint32_t>(aicpuArgBuf.size() * sizeof(int64_t));199+ aicpuLaunchDesc.args = aicpuArgs;
200+ aicpuLaunchDesc.argsSize = static_cast<uint32_t>(aicpuArgBuf.size() * sizeof(int64_t));
203 201 
204 std::vector<void*> kernelArgs(0x7, nullptr);202 std::vector<void*> kernelArgs(0x7, nullptr);
205 RtArgsEx rtAicoreArgs;203 RtArgsEx rtAicoreArgs;
@@ -224,7 +222,7 @@ int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binH
224 return rc;222 return rc;
225 }223 }
226 224 
227- rc = BundleLaunchAicpu(rtAicpuArgs, devProg);225+ rc = BundleLaunchAicpu(aicpuLaunchDesc, devProg);
228 if (rc != RT_SUCCESS) {226 if (rc != RT_SUCCESS) {
229 MACHINE_LOGE(HostLauncherErr::LAUNCH_BUILTIN_OP_NULL_FAILED, "[kernel-bundle] launch aicpu failed: %d", rc);227 MACHINE_LOGE(HostLauncherErr::LAUNCH_BUILTIN_OP_NULL_FAILED, "[kernel-bundle] launch aicpu failed: %d", rc);
230 return rc;228 return rc;
@@ -26,6 +26,7 @@
26#include "machine/runtime/runner/kernel_binary.h"26#include "machine/runtime/runner/kernel_binary.h"
27#include "tilefwk/data_type.h"27#include "tilefwk/data_type.h"
28#include "tilefwk/error_code.h"28#include "tilefwk/error_code.h"
29+#include "tilefwk/error_manager.h"
29#include "tilefwk/platform.h"30#include "tilefwk/platform.h"
30#include "tilefwk/pypto_fwk_log.h"31#include "tilefwk/pypto_fwk_log.h"
31 32 
@@ -134,9 +135,13 @@ int LaunchImpl(const std::shared_ptr<LoadedBundle>& bundle, const PyptoTensorDes
134 config.blockdim = head->ctrlBlockDim != 0 ? static_cast<int>(head->ctrlBlockDim) :135 config.blockdim = head->ctrlBlockDim != 0 ? static_cast<int>(head->ctrlBlockDim) :
135 static_cast<int>(head->devArgs.nrValidAic);136 static_cast<int>(head->devArgs.nrValidAic);
136 137 
137- return dynamic::LaunchBundleKernelOnce(bundle->devProgram, binHandle, bundle->bundleKey, inputs,138+ int rc = dynamic::LaunchBundleKernelOnce(bundle->devProgram, binHandle, bundle->bundleKey, inputs,
138- bundle->ctrlFlowCache, bundle->displayName, bundle->cellMatchStridePatches,139+ bundle->ctrlFlowCache, bundle->displayName, bundle->cellMatchStridePatches,
139- workspaceAddr, static_cast<RtStream>(stream), sync != 0, config);140+ workspaceAddr, static_cast<RtStream>(stream), sync != 0, config);
141+ if (rc != 0) {
142+ ErrorManager::Instance().OutputErrorMessage();
143+ }
144+ return rc;
140}145}
141} // namespace146} // namespace
142 147 
@@ -170,6 +170,11 @@ int LoadAicpuOp::GetBuiltInOpBinHandle(int64_t* devArgsAddr)
170 return LaunchAicpuServerInit(devArgsAddr);170 return LaunchAicpuServerInit(devArgsAddr);
171}171}
172 172 
173+int LaunchPyptoRunWithHostArgs(const AicpuLaunchDesc& desc)
174+{
175+ return LoadAicpuOp::GetInstance().LaunchBuiltInOpWithHostArgs(desc, "PyptoRun");
176+}
177+ 
173int LoadAicpuOp::LaunchBuiltInOpWithHostArgs(const AicpuLaunchDesc& desc, const std::string& funcName) const178int LoadAicpuOp::LaunchBuiltInOpWithHostArgs(const AicpuLaunchDesc& desc, const std::string& funcName) const
174{179{
175 RtFuncHandle funcHandle;180 RtFuncHandle funcHandle;
@@ -45,6 +45,10 @@ struct AicpuLaunchDesc {
45 uint32_t soNameOffset = 0;45 uint32_t soNameOffset = 0;
46};46};
47 47 
48+// Resolve the initialized built-in handle inside the runtime library. Bundle callers must not
49+// instantiate the header-inline LoadAicpuOp singleton in their own shared library.
50+int LaunchPyptoRunWithHostArgs(const AicpuLaunchDesc& desc);
51+ 
48class LoadAicpuOp {52class LoadAicpuOp {
49public:53public:
50 LoadAicpuOp() = default;54 LoadAicpuOp() = default;