Merged
fix(machine): export std::any<long> manager for bundle cross-DSO type identity #6079
W4termyAdd on Sep 9
fix(machine): export std::any<long> manager for bundle cross-DSO type identity #6079
Merged
W4termyAdd on Sep 9
Total: 9 files changed+204-27
@@ -17,6 +17,8 @@
17 17 
18#include <atomic>18#include <atomic>
19#include <cstddef>19#include <cstddef>
20+#include <cstdio>
21+#include <cstring>
20#include <string>22#include <string>
21#include <vector>23#include <vector>
22 24 
@@ -87,11 +89,23 @@ int BundleLaunchAicore(AclRtStream aicoreStream, void* kernel, RtArgsEx& rtArgs,
87 HostProf::GetInstance().ReportHostProfInfo(aicoreStream, startTime, blockDim, MSPF_GE_TASK_TYPE_MIX_AIC, true);89 HostProf::GetInstance().ReportHostProfInfo(aicoreStream, startTime, blockDim, MSPF_GE_TASK_TYPE_MIX_AIC, true);
88 return ret;90 return ret;
89}91}
92+ 
93+std::string MakeAicpuOpName(const std::string& displayName, uint64_t bundleKey)
94+{
95+ constexpr size_t maxNameSize = sizeof(AiCpuArgs::opName) - 1;
96+ if (displayName.size() <= maxNameSize) {
97+ return displayName;
98+ }
99+ char keySuffix[18] = {};
100+ (void)std::snprintf(keySuffix, sizeof(keySuffix), "_%016llx", static_cast<unsigned long long>(bundleKey));
101+ const size_t prefixSize = maxNameSize - std::strlen(keySuffix);
102+ return displayName.substr(0, prefixSize) + keySuffix;
103+}
90} // namespace104} // namespace
91 105 
92int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binHandle, uint64_t cacheKey,106int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binHandle, uint64_t cacheKey,
93 const std::vector<DeviceTensorData>& tensorList,107 const std::vector<DeviceTensorData>& tensorList,
94- const std::vector<uint8_t>& hostCtrlFlowCache,108+ const std::vector<uint8_t>& hostCtrlFlowCache, const std::string& displayName,
95 const std::vector<DevDynamicCellMatchStridePatch>& cellMatchStridePatches,109 const std::vector<DevDynamicCellMatchStridePatch>& cellMatchStridePatches,
96 void* workspaceAddr, RtStream aicoreStream, bool streamSynchronize,110 void* workspaceAddr, RtStream aicoreStream, bool streamSynchronize,
97 const DeviceLauncherConfig& config)111 const DeviceLauncherConfig& config)
@@ -125,6 +139,12 @@ int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binH
125 auto* aicpuArgs = new (aicpuArgBuf.data()) AiCpuArgs();139 auto* aicpuArgs = new (aicpuArgBuf.data()) AiCpuArgs();
126 aicpuArgs->kArgs.inputs = nullptr;140 aicpuArgs->kArgs.inputs = nullptr;
127 aicpuArgs->kArgs.outputs = nullptr;141 aicpuArgs->kArgs.outputs = nullptr;
142+ const std::string aicpuOpName = MakeAicpuOpName(displayName, cacheKey);
143+ if (strcpy_s(aicpuArgs->opName, sizeof(aicpuArgs->opName), aicpuOpName.c_str()) != 0) {
144+ MACHINE_LOGE(DevCommonErr::PARAM_CHECK_FAILED, "[kernel-bundle] invalid AICPU op name: %s",
145+ aicpuOpName.c_str());
146+ return -1;
147+ }
128 148 
129 // Fill device-side kArgs: cfgdata (base-0 devProg), metadata, distributed ctx. Topology is re-derived from149 // Fill device-side kArgs: cfgdata (base-0 devProg), metadata, distributed ctx. Topology is re-derived from
130 // the target platform in DeviceInitTilingData.150 // the target platform in DeviceInitTilingData.
@@ -210,8 +230,7 @@ int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binH
210 return rc;230 return rc;
211 }231 }
212 232 
213- static const char kBundleKernelName[] = "PyPTO_bundle_kernel";233+ kernelArgs[0] = const_cast<char*>(displayName.c_str());
214- kernelArgs[0] = const_cast<char*>(kBundleKernelName);
215 kernelArgs[4] = reinterpret_cast<int64_t*>(aicpuArgs + 1); // inputp234 kernelArgs[4] = reinterpret_cast<int64_t*>(aicpuArgs + 1); // inputp
216 kernelArgs[5] = aicpuArgs->kArgs.cfgdata; // 5 is cfgdata235 kernelArgs[5] = aicpuArgs->kArgs.cfgdata; // 5 is cfgdata
217 kernelArgs[6] = reinterpret_cast<DevTensorData*>(reinterpret_cast<int64_t*>(aicpuArgs + 1) + 2);236 kernelArgs[6] = reinterpret_cast<DevTensorData*>(reinterpret_cast<int64_t*>(aicpuArgs + 1) + 2);
@@ -19,6 +19,7 @@
19#pragma once19#pragma once
20 20 
21#include <cstdint>21#include <cstdint>
22+#include <string>
22#include <vector>23#include <vector>
23 24 
24#include "adapter/api/runtime_define.h" // RtStream25#include "adapter/api/runtime_define.h" // RtStream
@@ -35,7 +36,7 @@ namespace npu::tile_fwk::dynamic {
35// memBudget for the launch shape. Returns 0 on success.36// memBudget for the launch shape. Returns 0 on success.
36int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binHandle, uint64_t cacheKey,37int LaunchBundleKernelOnce(const std::vector<uint8_t>& devProgBinary, void* binHandle, uint64_t cacheKey,
37 const std::vector<DeviceTensorData>& tensorList,38 const std::vector<DeviceTensorData>& tensorList,
38- const std::vector<uint8_t>& hostCtrlFlowCache,39+ const std::vector<uint8_t>& hostCtrlFlowCache, const std::string& displayName,
39 const std::vector<DevDynamicCellMatchStridePatch>& cellMatchStridePatches,40 const std::vector<DevDynamicCellMatchStridePatch>& cellMatchStridePatches,
40 void* workspaceAddr, RtStream aicoreStream, bool streamSynchronize,41 void* workspaceAddr, RtStream aicoreStream, bool streamSynchronize,
41 const DeviceLauncherConfig& config = DeviceLauncherConfig());42 const DeviceLauncherConfig& config = DeviceLauncherConfig());
@@ -16,6 +16,8 @@
16#include "machine/runtime/bundle/kernel_bundle_loader.h"16#include "machine/runtime/bundle/kernel_bundle_loader.h"
17 17 
18#include <cstring>18#include <cstring>
19+#include <iomanip>
20+#include <sstream>
19 21 
20#include "machine/runtime/bundle/kernel_bundle_crc32.h"22#include "machine/runtime/bundle/kernel_bundle_crc32.h"
21#include "machine/runtime/bundle/kernel_bundle_format.h"23#include "machine/runtime/bundle/kernel_bundle_format.h"
@@ -54,6 +56,31 @@ void FoldTlvIntoBundleKey(uint64_t& key, uint32_t type, uint32_t crc, uint64_t l
54 }56 }
55 }57 }
56}58}
59+ 
60+std::string BundleKeyName(uint64_t bundleKey)
61+{
62+ std::ostringstream os;
63+ os << "PyPTO_bundle_" << std::hex << std::setw(16) << std::setfill('0') << bundleKey;
64+ return os.str();
65+}
66+ 
67+std::string BundlePathName(const std::string& path, uint64_t bundleKey)
68+{
69+ const size_t separator = path.find_last_of("/\\");
70+ std::string name = separator == std::string::npos ? path : path.substr(separator + 1);
71+ constexpr const char* suffix = ".pyptokb";
72+ constexpr size_t suffixSize = 8;
73+ if (name.size() >= suffixSize && name.compare(name.size() - suffixSize, suffixSize, suffix) == 0) {
74+ name.erase(name.size() - suffixSize);
75+ }
76+ if (name.empty()) {
77+ return BundleKeyName(bundleKey);
78+ }
79+ if (name.compare(0, 5, "PyPTO") != 0) {
80+ name = "PyPTO_bundle_" + name;
81+ }
82+ return name;
83+}
57} // namespace84} // namespace
58 85 
59std::shared_ptr<LoadedBundle> KernelBundleLoader::LoadFromMemory(const uint8_t* p, size_t n)86std::shared_ptr<LoadedBundle> KernelBundleLoader::LoadFromMemory(const uint8_t* p, size_t n)
@@ -129,6 +156,7 @@ std::shared_ptr<LoadedBundle> KernelBundleLoader::LoadFromMemory(const uint8_t*
129 return nullptr;156 return nullptr;
130 }157 }
131 b->bundleKey = bundleKey;158 b->bundleKey = bundleKey;
159+ b->displayName = BundleKeyName(bundleKey);
132 MACHINE_LOGI("[kernel-bundle] loaded: bundleKey=%#lx hashKey=%#lx workspaceSize=%lu archInfo=%u ctrlCache=%zuB "160 MACHINE_LOGI("[kernel-bundle] loaded: bundleKey=%#lx hashKey=%#lx workspaceSize=%lu archInfo=%u ctrlCache=%zuB "
133 "symbolMeta=%zuB",161 "symbolMeta=%zuB",
134 b->bundleKey, b->GetHashKey(), b->GetWorkspaceSize(), b->GetArchInfo(), b->ctrlFlowCache.size(),162 b->bundleKey, b->GetHashKey(), b->GetWorkspaceSize(), b->GetArchInfo(), b->ctrlFlowCache.size(),
@@ -144,7 +172,11 @@ std::shared_ptr<LoadedBundle> KernelBundleLoader::LoadFromFile(const std::string
144 MACHINE_LOGE(DevCommonErr::FILE_ERROR, "[kernel-bundle] failed to read %s", path.c_str());172 MACHINE_LOGE(DevCommonErr::FILE_ERROR, "[kernel-bundle] failed to read %s", path.c_str());
145 return nullptr;173 return nullptr;
146 }174 }
147- return LoadFromMemory(raw.data(), raw.size());175+ auto bundle = LoadFromMemory(raw.data(), raw.size());
176+ if (bundle != nullptr) {
177+ bundle->displayName = BundlePathName(path, bundle->bundleKey);
178+ }
179+ return bundle;
148}180}
149 181 
150} // namespace npu::tile_fwk::bundle182} // namespace npu::tile_fwk::bundle
@@ -40,6 +40,9 @@ struct LoadedBundle {
40 std::vector<uint8_t> ctrlFlowCache; // DevControlFlowCache blob (may be empty for old bundles)40 std::vector<uint8_t> ctrlFlowCache; // DevControlFlowCache blob (may be empty for old bundles)
41 std::vector<uint8_t> symbolMeta; // JSON dynamic-workspace symbols (empty -> static workspace fallback)41 std::vector<uint8_t> symbolMeta; // JSON dynamic-workspace symbols (empty -> static workspace fallback)
42 42 
43+ // Stable logical name used by asynchronous AICORE/AICPU exception callbacks.
44+ std::string displayName;
45+ 
43 // Per-shape dynamic cell-match stride patches, computed host-side by EvalWorkspaceForShapes and written into46 // Per-shape dynamic cell-match stride patches, computed host-side by EvalWorkspaceForShapes and written into
44 // the aicpu launch args. Empty for ops with no dynamic cell-match table.47 // the aicpu launch args. Empty for ops with no dynamic cell-match table.
45 std::vector<dynamic::DevDynamicCellMatchStridePatch> cellMatchStridePatches;48 std::vector<dynamic::DevDynamicCellMatchStridePatch> cellMatchStridePatches;
@@ -135,8 +135,8 @@ int LaunchImpl(const std::shared_ptr<LoadedBundle>& bundle, const PyptoTensorDes
135 static_cast<int>(head->devArgs.nrValidAic);135 static_cast<int>(head->devArgs.nrValidAic);
136 136 
137 return dynamic::LaunchBundleKernelOnce(bundle->devProgram, binHandle, bundle->bundleKey, inputs,137 return dynamic::LaunchBundleKernelOnce(bundle->devProgram, binHandle, bundle->bundleKey, inputs,
138- bundle->ctrlFlowCache, bundle->cellMatchStridePatches, workspaceAddr,138+ bundle->ctrlFlowCache, bundle->displayName, bundle->cellMatchStridePatches,
139- static_cast<RtStream>(stream), sync != 0, config);139+ workspaceAddr, static_cast<RtStream>(stream), sync != 0, config);
140}140}
141} // namespace141} // namespace
142 142 
@@ -8,6 +8,7 @@
8 PyptoLaunch;8 PyptoLaunch;
9 PyptoWorkspaceFromMemory;9 PyptoWorkspaceFromMemory;
10 PyptoLaunchFromMemory;10 PyptoLaunchFromMemory;
11+ _ZNSt3any17_Manager_internalIlE9_S_manage*;
11 local:12 local:
12 *;13 *;
13};14};
@@ -28,11 +28,15 @@
28#include "machine/runtime/bundle/pack/kernel_bundle_packer.h"28#include "machine/runtime/bundle/pack/kernel_bundle_packer.h"
29#include "machine/runtime/bundle/pack/kernel_bundle_pack.h"29#include "machine/runtime/bundle/pack/kernel_bundle_pack.h"
30#include "machine/utils/dynamic/dev_encode_function_param.h"30#include "machine/utils/dynamic/dev_encode_function_param.h"
31+#ifndef TILE_FWK_BUNDLE_STANDALONE
31#include "machine/compile/aicore_compiler.h"32#include "machine/compile/aicore_compiler.h"
33+#endif
32#include "interface/function/function.h"34#include "interface/function/function.h"
33 35 
34using namespace npu::tile_fwk;36using namespace npu::tile_fwk;
35namespace npu::tile_fwk::dynamic {37namespace npu::tile_fwk::dynamic {
38+void FillExceptionKernelDisplayName(const char* kernelName, AdxExceptionDumpInfo* exceptionDumpInfo);
39+ 
36constexpr int32_t MAX_AICPU_ARG_NUM = 7;40constexpr int32_t MAX_AICPU_ARG_NUM = 7;
37 41 
38static bool PackAndDumpBundle(const std::vector<uint8_t>& kernelBinary, const DyndevFunctionAttribute* dynAttr,42static bool PackAndDumpBundle(const std::vector<uint8_t>& kernelBinary, const DyndevFunctionAttribute* dynAttr,
@@ -74,6 +78,7 @@ void DumpBundledKernel(const DyndevFunctionAttribute* dynAttr, const char* kerne
74 PackAndDumpBundle(dynAttr->kernelBinary, dynAttr, kernelName, "");78 PackAndDumpBundle(dynAttr->kernelBinary, dynAttr, kernelName, "");
75}79}
76 80 
81+#ifndef TILE_FWK_BUNDLE_STANDALONE
77void DumpNoSubFuncBundledKernel(const DyndevFunctionAttribute* dynAttr, Function* func, const char* kernelName)82void DumpNoSubFuncBundledKernel(const DyndevFunctionAttribute* dynAttr, Function* func, const char* kernelName)
78{83{
79 if (dynAttr == nullptr || func == nullptr || kernelName == nullptr) {84 if (dynAttr == nullptr || func == nullptr || kernelName == nullptr) {
@@ -122,6 +127,7 @@ void DumpNoSubFuncBundledKernel(const DyndevFunctionAttribute* dynAttr, Function
122 // 3. 打包并 dump127 // 3. 打包并 dump
123 PackAndDumpBundle(noSubFuncKernel, dynAttr, kernelName, "_nosubfunc");128 PackAndDumpBundle(noSubFuncKernel, dynAttr, kernelName, "_nosubfunc");
124}129}
130+#endif
125 131 
126void GetTensorInfo(uint32_t inputSize, DevTensorData* tensorData, AdxExceptionDumpInfo* exceptionDumpInfo)132void GetTensorInfo(uint32_t inputSize, DevTensorData* tensorData, AdxExceptionDumpInfo* exceptionDumpInfo)
127{133{
@@ -161,21 +167,32 @@ void GetTensorInfo(uint32_t inputSize, DevTensorData* tensorData, AdxExceptionDu
161 }167 }
162 exceptionDumpInfo->extraTensorNum = inputSize;168 exceptionDumpInfo->extraTensorNum = inputSize;
163 DumpBundledKernel(dynAttr.get(), exceptionDumpInfo->kernelName);169 DumpBundledKernel(dynAttr.get(), exceptionDumpInfo->kernelName);
170+#ifndef TILE_FWK_BUNDLE_STANDALONE
164 // 触发 __HAS_SUB_FUNC__ 未定义的二进制编译并打包 dump(失败仅 WARNING 降级)171 // 触发 __HAS_SUB_FUNC__ 未定义的二进制编译并打包 dump(失败仅 WARNING 降级)
165 DumpNoSubFuncBundledKernel(dynAttr.get(), func, exceptionDumpInfo->kernelName);172 DumpNoSubFuncBundledKernel(dynAttr.get(), func, exceptionDumpInfo->kernelName);
173+#endif
166}174}
167 175 
168int32_t GetAicoreExceptionDumpInfo(std::vector<void*> kernelArg, AdxExceptionDumpInfo* exceptionDumpInfo)176int32_t GetAicoreExceptionDumpInfo(std::vector<void*> kernelArg, AdxExceptionDumpInfo* exceptionDumpInfo)
169{177{
178+ if (kernelArg.size() <= 6 || kernelArg[4] == nullptr || kernelArg[6] == nullptr) {
179+ MACHINE_LOGW("GetAicoreExceptionDumpInfo failed: incomplete kernel args");
180+ return static_cast<int32_t>(npu::tile_fwk::MachineError::DUMP_DFX);
181+ }
170 int64_t* tensor = static_cast<int64_t*>(kernelArg[4]);182 int64_t* tensor = static_cast<int64_t*>(kernelArg[4]);
171- uint32_t tensorSize = tensor[0] - tensor[1];183+ // Mixed operand list: ABI is still [nMixed, nOut=0], dump uses nMixed only (no in/out split).
172- MACHINE_LOGD("GetAicoreExceptionDumpInfo: tensorSize=%u, outputTensorSize:[%ld]", tensorSize, tensor[1]);184+ if (tensor[0] < 0) {
185+ MACHINE_LOGW("GetAicoreExceptionDumpInfo failed: negative mixed tensor count n=%ld", tensor[0]);
186+ return static_cast<int32_t>(npu::tile_fwk::MachineError::DUMP_DFX);
187+ }
188+ MACHINE_LOGD("GetAicoreExceptionDumpInfo: mixedCount=[%ld]", tensor[0]);
173 auto tensorData = (DevTensorData*)kernelArg[6];189 auto tensorData = (DevTensorData*)kernelArg[6];
174- GetTensorInfo(tensorSize, tensorData, exceptionDumpInfo);190+ GetTensorInfo(static_cast<uint32_t>(tensor[0]), tensorData, exceptionDumpInfo);
175 return 0;191 return 0;
176}192}
177 193 
178-int32_t GetDeviceExceptionDumpInfo(RtAicoreExDetailInfo& aicoreExceptionInfo, AdxExceptionDumpInfo* exceptionDumpInfo)194+int32_t GetDeviceExceptionDumpInfo(RtAicoreExDetailInfo& aicoreExceptionInfo, AdxExceptionDumpInfo* exceptionDumpInfo,
195+ uint32_t exceptionDumpSize)
179{196{
180 auto kernelArgAddr = aicoreExceptionInfo.exceptionArgs.argAddr;197 auto kernelArgAddr = aicoreExceptionInfo.exceptionArgs.argAddr;
181 auto argsSize = aicoreExceptionInfo.exceptionArgs.argsize;198 auto argsSize = aicoreExceptionInfo.exceptionArgs.argsize;
@@ -206,6 +223,9 @@ int32_t GetDeviceExceptionDumpInfo(RtAicoreExDetailInfo& aicoreExceptionInfo, Ad
206 MACHINE_LOGI("Current exception info not PyPTO, which kernelName is[%s]", kernelName);223 MACHINE_LOGI("Current exception info not PyPTO, which kernelName is[%s]", kernelName);
207 return 0;224 return 0;
208 }225 }
226+ for (uint32_t i = 0; i < exceptionDumpSize; ++i) {
227+ FillExceptionKernelDisplayName(kernelName, &exceptionDumpInfo[i]);
228+ }
209 exceptionDumpInfo->argAddr = kernelArgAddr;229 exceptionDumpInfo->argAddr = kernelArgAddr;
210 exceptionDumpInfo->argssize = argsSize;230 exceptionDumpInfo->argssize = argsSize;
211 auto exceptionKernelInfo = aicoreExceptionInfo.exceptionArgs.exceptionKernelInfo;231 auto exceptionKernelInfo = aicoreExceptionInfo.exceptionArgs.exceptionKernelInfo;
@@ -229,6 +249,17 @@ void FillExceptionKernelName(const char* kernelName, AdxExceptionDumpInfo* excep
229 }249 }
230}250}
231 251 
252+void FillExceptionKernelDisplayName(const char* kernelName, AdxExceptionDumpInfo* exceptionDumpInfo)
253+{
254+ if (kernelName == nullptr) {
255+ return;
256+ }
257+ const auto ret = strcpy_s(exceptionDumpInfo->kernelDisplayName, MAX_KERNEL_BUF_LEN, kernelName);
258+ if (ret != 0) {
259+ MACHINE_LOGW("Mem cpy kernelDisplayName failed");
260+ }
261+}
262+ 
232int32_t FillCoreExceptionInfo(RtExceptionInfo* exceptionInfo, AdxExceptionDumpInfo* exceptionDumpInfo,263int32_t FillCoreExceptionInfo(RtExceptionInfo* exceptionInfo, AdxExceptionDumpInfo* exceptionDumpInfo,
233 uint32_t exceptionDumpSize)264 uint32_t exceptionDumpSize)
234{265{
@@ -267,15 +298,13 @@ int32_t GetAicpuExceptionDumpInfo(RtAicpuExDetailInfo& aicpuExcepitionInfo, AdxE
267 MACHINE_LOGD("Aicpu kernelArgs is not suitable pypto");298 MACHINE_LOGD("Aicpu kernelArgs is not suitable pypto");
268 return 0;299 return 0;
269 }300 }
270- // aicpu Op whose functionName == kerneName301+ 
271 if (aicpuExcepitionInfo.functionName != nullptr &&302 if (aicpuExcepitionInfo.functionName != nullptr &&
272 strncmp(aicpuExcepitionInfo.functionName, "DynTileFwkKernelServer", strlen("DynTileFwkKernelServer")) != 0) {303 strncmp(aicpuExcepitionInfo.functionName, "DynTileFwkKernelServer", strlen("DynTileFwkKernelServer")) != 0) {
273 MACHINE_LOGI("Current exception info is not PyPTO");304 MACHINE_LOGI("Current exception info is not PyPTO");
274 return 0;305 return 0;
275 }306 }
276 307 
277- std::string aicpuPyptoName = "PyPTO_Aicpu_" + Program::GetInstance().GetLastFunction()->GetOriginalRawName();
278- FillExceptionKernelName(aicpuPyptoName.c_str(), exceptionDumpInfo);
279 MACHINE_LOGI("Current argAddr is %p, argSize: %u", kernelArgAddr, argSize);308 MACHINE_LOGI("Current argAddr is %p, argSize: %u", kernelArgAddr, argSize);
280 std::vector<uint8_t> kernelArg(argSize);309 std::vector<uint8_t> kernelArg(argSize);
281 int rc = RuntimeMemcpyDirect(kernelArg.data(), argSize, kernelArgAddr, argSize, RtMemcpyKind::DEVICE_TO_HOST);310 int rc = RuntimeMemcpyDirect(kernelArg.data(), argSize, kernelArgAddr, argSize, RtMemcpyKind::DEVICE_TO_HOST);
@@ -285,13 +314,31 @@ int32_t GetAicpuExceptionDumpInfo(RtAicpuExDetailInfo& aicpuExcepitionInfo, AdxE
285 }314 }
286 315 
287 npu::tile_fwk::AiCpuArgs* aicpuArgs = (AiCpuArgs*)kernelArg.data();316 npu::tile_fwk::AiCpuArgs* aicpuArgs = (AiCpuArgs*)kernelArg.data();
317+ const char* runtimeKernelName = nullptr;
318+ if (aicpuExcepitionInfo.kernelName != nullptr && aicpuExcepitionInfo.kernelName[0] != '\0') {
319+ runtimeKernelName = aicpuExcepitionInfo.kernelName;
320+ } else if (aicpuExcepitionInfo.functionName != nullptr && aicpuExcepitionInfo.functionName[0] != '\0') {
321+ runtimeKernelName = aicpuExcepitionInfo.functionName;
322+ }
323+ FillExceptionKernelName(runtimeKernelName, exceptionDumpInfo);
324+ 
325+ auto* lastFunc = Program::GetInstance().GetLastFunction();
326+ std::string displayName;
327+ const size_t opNameSize = strnlen(aicpuArgs->opName, sizeof(aicpuArgs->opName));
328+ if (opNameSize != 0) {
329+ displayName.assign(aicpuArgs->opName, opNameSize);
330+ } else if (lastFunc != nullptr) {
331+ displayName = "PyPTO_Aicpu_" + lastFunc->GetOriginalRawName();
332+ } else {
333+ displayName = "PyPTO_Aicpu_bundle_kernel";
334+ }
335+ FillExceptionKernelDisplayName(displayName.c_str(), exceptionDumpInfo);
288 // device kernelArgs336 // device kernelArgs
289 [[maybe_unused]] DeviceKernelArgs deviceKernelArgs = aicpuArgs->kArgs;337 [[maybe_unused]] DeviceKernelArgs deviceKernelArgs = aicpuArgs->kArgs;
290- // tensor info338+ // Mixed operand list: [nMixed, nOut=0] then DevTensorData[nMixed].
291 int64_t* tensorInfo = (int64_t*)(aicpuArgs + 1);339 int64_t* tensorInfo = (int64_t*)(aicpuArgs + 1);
292- int64_t inputSize = tensorInfo[0];
293 auto tensorData = (DevTensorData*)(tensorInfo + 2);340 auto tensorData = (DevTensorData*)(tensorInfo + 2);
294- GetTensorInfo(inputSize, tensorData, exceptionDumpInfo);341+ GetTensorInfo(static_cast<uint32_t>(tensorInfo[0]), tensorData, exceptionDumpInfo);
295 return 0;342 return 0;
296}343}
297 344 
@@ -305,7 +352,7 @@ int32_t DeviceExceptionDumpCallBack(RtExceptionInfo* exceptionInfo, AdxException
305 if (ret != 0) {352 if (ret != 0) {
306 return ret;353 return ret;
307 }354 }
308- return GetDeviceExceptionDumpInfo(expandInfo.u.aicoreInfo, &exceptionDumpInfo[0]);355+ return GetDeviceExceptionDumpInfo(expandInfo.u.aicoreInfo, &exceptionDumpInfo[0], exceptionDumpSize);
309 }356 }
310 if (expandInfo.type == RtExceptionExpandType::AICPU) {357 if (expandInfo.type == RtExceptionExpandType::AICPU) {
311 return GetAicpuExceptionDumpInfo(expandInfo.u.aicpuInfo, &exceptionDumpInfo[0]);358 return GetAicpuExceptionDumpInfo(expandInfo.u.aicpuInfo, &exceptionDumpInfo[0]);
@@ -105,7 +105,7 @@ struct AiCpuArgs {
105 DeviceKernelArgs kArgs;105 DeviceKernelArgs kArgs;
106 const char kernelName[32] = {"DynTileFwkKernelServer"};106 const char kernelName[32] = {"DynTileFwkKernelServer"};
107 const char soName[32] = {"libaicpu_extend_kernels.so"};107 const char soName[32] = {"libaicpu_extend_kernels.so"};
108- const char opName[32] = {""};108+ char opName[32] = {""};
109};109};
110 110 
111struct LogHead {111struct LogHead {
@@ -267,11 +267,13 @@ TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithMultipleTensors)
267 267 
268TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithOutputTensors)268TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithOutputTensors)
269{269{
270+ // Mixed operand list is counted in nIn; nOut is unused for dump.
270 char kernelName[] = "PyPTO_OutputTensorKernel";271 char kernelName[] = "PyPTO_OutputTensorKernel";
271 int64_t inputOutputInfo[2] = {2, 1};272 int64_t inputOutputInfo[2] = {2, 1};
272 std::vector<uint8_t> tensorBuf0(32, 0xAB);273 std::vector<uint8_t> tensorBuf0(32, 0xAB);
273 std::vector<uint8_t> tensorBuf1(16, 0xCD);274 std::vector<uint8_t> tensorBuf1(16, 0xCD);
274- DevTensorData tensorData[2] = {};275+ std::vector<uint8_t> tensorBuf2(8, 0xEF);
276+ DevTensorData tensorData[3] = {};
275 tensorData[0].address = reinterpret_cast<uint64_t>(tensorBuf0.data());277 tensorData[0].address = reinterpret_cast<uint64_t>(tensorBuf0.data());
276 tensorData[0].dataType = static_cast<int32_t>(DataType::DT_FP32);278 tensorData[0].dataType = static_cast<int32_t>(DataType::DT_FP32);
277 tensorData[0].shape.dim[0] = 4;279 tensorData[0].shape.dim[0] = 4;
@@ -282,6 +284,11 @@ TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithOutputTensors)
282 tensorData[1].shape.dim[0] = 4;284 tensorData[1].shape.dim[0] = 4;
283 tensorData[1].shape.dim[1] = 4;285 tensorData[1].shape.dim[1] = 4;
284 tensorData[1].shape.dimSize = 2;286 tensorData[1].shape.dimSize = 2;
287+ tensorData[2].address = reinterpret_cast<uint64_t>(tensorBuf2.data());
288+ tensorData[2].dataType = static_cast<int32_t>(DataType::DT_FP32);
289+ tensorData[2].shape.dim[0] = 2;
290+ tensorData[2].shape.dim[1] = 2;
291+ tensorData[2].shape.dimSize = 2;
285 std::vector<void*> kernelArg(MAX_AICPU_ARG_NUM, nullptr);292 std::vector<void*> kernelArg(MAX_AICPU_ARG_NUM, nullptr);
286 kernelArg[KERNEL_NAME_IDX] = kernelName;293 kernelArg[KERNEL_NAME_IDX] = kernelName;
287 kernelArg[INPUT_OUTPUT_IDX] = inputOutputInfo;294 kernelArg[INPUT_OUTPUT_IDX] = inputOutputInfo;
@@ -298,12 +305,13 @@ TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithOutputTensors)
298 EXPECT_EQ(ret, 0);305 EXPECT_EQ(ret, 0);
299 EXPECT_EQ(mode, AdxExceptionDumpMode::ADX_DUMP_MODE_OVERWRITE);306 EXPECT_EQ(mode, AdxExceptionDumpMode::ADX_DUMP_MODE_OVERWRITE);
300 EXPECT_EQ(realSize, 1);307 EXPECT_EQ(realSize, 1);
301- EXPECT_EQ(dumpInfo.extraTensorNum, 1);308+ EXPECT_EQ(dumpInfo.extraTensorNum, 2);
302}309}
303 310 
304TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithExceptionKernelInfoBin)311TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithExceptionKernelInfoBin)
305{312{
306 char exceptionKernelName[] = "PyPTO_BinTestKernel";313 char exceptionKernelName[] = "PyPTO_BinTestKernel";
314+ char bundleDisplayName[] = "PyPTO_bundle_bin_test";
307 int64_t inputOutputInfo[2] = {1, 0};315 int64_t inputOutputInfo[2] = {1, 0};
308 uint8_t binBuf[128] = {};316 uint8_t binBuf[128] = {};
309 std::vector<uint8_t> tensorBuf(32, 0xAB);317 std::vector<uint8_t> tensorBuf(32, 0xAB);
@@ -314,7 +322,7 @@ TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithExceptionKernelInfoBin)
314 tensorData[0].shape.dim[1] = 8;322 tensorData[0].shape.dim[1] = 8;
315 tensorData[0].shape.dimSize = 2;323 tensorData[0].shape.dimSize = 2;
316 std::vector<void*> kernelArg(MAX_AICPU_ARG_NUM, nullptr);324 std::vector<void*> kernelArg(MAX_AICPU_ARG_NUM, nullptr);
317- kernelArg[KERNEL_NAME_IDX] = exceptionKernelName;325+ kernelArg[KERNEL_NAME_IDX] = bundleDisplayName;
318 kernelArg[INPUT_OUTPUT_IDX] = inputOutputInfo;326 kernelArg[INPUT_OUTPUT_IDX] = inputOutputInfo;
319 kernelArg[TENSOR_DATA_IDX] = tensorData;327 kernelArg[TENSOR_DATA_IDX] = tensorData;
320 RtExceptionInfo exceptionInfo = {};328 RtExceptionInfo exceptionInfo = {};
@@ -334,7 +342,7 @@ TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithExceptionKernelInfoBin)
334 EXPECT_EQ(realSize, 1);342 EXPECT_EQ(realSize, 1);
335 EXPECT_EQ(dumpInfo.bin, exceptionInfo.expandInfo.u.aicoreInfo.exceptionArgs.exceptionKernelInfo.bin);343 EXPECT_EQ(dumpInfo.bin, exceptionInfo.expandInfo.u.aicoreInfo.exceptionArgs.exceptionKernelInfo.bin);
336 EXPECT_STREQ(dumpInfo.kernelName, exceptionKernelName);344 EXPECT_STREQ(dumpInfo.kernelName, exceptionKernelName);
337- EXPECT_STREQ(dumpInfo.kernelDisplayName, exceptionKernelName);345+ EXPECT_STREQ(dumpInfo.kernelDisplayName, bundleDisplayName);
338}346}
339 347 
340TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithNullExceptionKernelName)348TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithNullExceptionKernelName)
@@ -371,7 +379,7 @@ TEST_F(DeviceExceptionDumpTest, TestAicoreExceptionWithNullExceptionKernelName)
371 EXPECT_EQ(dumpInfo.bin, exceptionInfo.expandInfo.u.aicoreInfo.exceptionArgs.exceptionKernelInfo.bin);379 EXPECT_EQ(dumpInfo.bin, exceptionInfo.expandInfo.u.aicoreInfo.exceptionArgs.exceptionKernelInfo.bin);
372 // kernelName should remain empty when exceptionKernelInfo.kernelName is nullptr380 // kernelName should remain empty when exceptionKernelInfo.kernelName is nullptr
373 EXPECT_STREQ(dumpInfo.kernelName, "");381 EXPECT_STREQ(dumpInfo.kernelName, "");
374- EXPECT_STREQ(dumpInfo.kernelDisplayName, "");382+ EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_NullKernelName");
375}383}
376 384 
377TEST_F(DeviceExceptionDumpTest, TestNonAicoreExceptionTypeFFTSPlus)385TEST_F(DeviceExceptionDumpTest, TestNonAicoreExceptionTypeFFTSPlus)
@@ -391,13 +399,16 @@ TEST_F(DeviceExceptionDumpTest, TestNonAicoreExceptionTypeFFTSPlus)
391// ============================ AICPU exception dump tests ============================399// ============================ AICPU exception dump tests ============================
392 400 
393static void BuildAicpuArgBuffer(std::vector<uint8_t>& buffer, int64_t inputSize,401static void BuildAicpuArgBuffer(std::vector<uint8_t>& buffer, int64_t inputSize,
394- const std::vector<DevTensorData>& tensors)402+ const std::vector<DevTensorData>& tensors, const char* opName = nullptr)
395{403{
396 size_t totalSize = sizeof(AiCpuArgs) + DEV_TENSOR_DATA_OFFSET * sizeof(int64_t) +404 size_t totalSize = sizeof(AiCpuArgs) + DEV_TENSOR_DATA_OFFSET * sizeof(int64_t) +
397 tensors.size() * sizeof(DevTensorData);405 tensors.size() * sizeof(DevTensorData);
398 buffer.assign(totalSize, 0);406 buffer.assign(totalSize, 0);
399 auto* args = reinterpret_cast<AiCpuArgs*>(buffer.data());407 auto* args = reinterpret_cast<AiCpuArgs*>(buffer.data());
400 args->kArgs = DeviceKernelArgs{};408 args->kArgs = DeviceKernelArgs{};
409+ if (opName != nullptr) {
410+ ASSERT_EQ(strcpy_s(args->opName, sizeof(args->opName), opName), 0);
411+ }
401 int64_t* tensorInfo = reinterpret_cast<int64_t*>(buffer.data() + sizeof(AiCpuArgs));412 int64_t* tensorInfo = reinterpret_cast<int64_t*>(buffer.data() + sizeof(AiCpuArgs));
402 tensorInfo[0] = inputSize;413 tensorInfo[0] = inputSize;
403 tensorInfo[1] = 0;414 tensorInfo[1] = 0;
@@ -468,7 +479,7 @@ TEST_F(DeviceExceptionDumpTest, TestAicpuExceptionWithNullFunctionName)
468 exceptionInfo.expandInfo.u.aicpuInfo.functionName = nullptr;479 exceptionInfo.expandInfo.u.aicpuInfo.functionName = nullptr;
469 auto ret = ExceptionDumpCallBack(&exceptionInfo, &dumpInfo, dumpSize, &realSize, &mode);480 auto ret = ExceptionDumpCallBack(&exceptionInfo, &dumpInfo, dumpSize, &realSize, &mode);
470 EXPECT_EQ(ret, 0);481 EXPECT_EQ(ret, 0);
471- EXPECT_STREQ(dumpInfo.kernelName, "PyPTO_Aicpu_TestFunc");482+ EXPECT_STREQ(dumpInfo.kernelName, "");
472 EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_Aicpu_TestFunc");483 EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_Aicpu_TestFunc");
473}484}
474 485 
@@ -503,7 +514,7 @@ TEST_F(DeviceExceptionDumpTest, TestAicpuExceptionWithValidTensors)
503 EXPECT_EQ(ret, 0);514 EXPECT_EQ(ret, 0);
504 EXPECT_EQ(mode, AdxExceptionDumpMode::ADX_DUMP_MODE_OVERWRITE);515 EXPECT_EQ(mode, AdxExceptionDumpMode::ADX_DUMP_MODE_OVERWRITE);
505 EXPECT_EQ(realSize, 1);516 EXPECT_EQ(realSize, 1);
506- EXPECT_STREQ(dumpInfo.kernelName, "PyPTO_Aicpu_TestFunc");517+ EXPECT_STREQ(dumpInfo.kernelName, "DynTileFwkKernelServer");
507 EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_Aicpu_TestFunc");518 EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_Aicpu_TestFunc");
508 EXPECT_EQ(dumpInfo.extraTensorNum, 2);519 EXPECT_EQ(dumpInfo.extraTensorNum, 2);
509}520}
@@ -531,3 +542,66 @@ TEST_F(DeviceExceptionDumpTest, TestAicpuExceptionWithZeroAddressTensor)
531 EXPECT_EQ(ret, 0);542 EXPECT_EQ(ret, 0);
532 EXPECT_EQ(dumpInfo.extraTensorNum, 1);543 EXPECT_EQ(dumpInfo.extraTensorNum, 1);
533}544}
545+ 
546+TEST_F(DeviceExceptionDumpTest, TestAicpuExceptionOfflineUsesOpName)
547+{
548+ Program::GetInstance().SetLastFunction(nullptr);
549+ std::vector<uint8_t> buffer;
550+ BuildAicpuArgBuffer(buffer, 0, {}, "PyPTO_bundle_valuedep");
551+ RtExceptionInfo exceptionInfo = {};
552+ AdxExceptionDumpInfo dumpInfo = {};
553+ uint32_t dumpSize = 1;
554+ uint32_t realSize = 0;
555+ AdxExceptionDumpMode mode = AdxExceptionDumpMode::ADX_DUMP_MODE_NONE;
556+ exceptionInfo.expandInfo.type = RtExceptionExpandType::AICPU;
557+ exceptionInfo.expandInfo.u.aicpuInfo.argAddr = buffer.data();
558+ exceptionInfo.expandInfo.u.aicpuInfo.argsize = static_cast<uint32_t>(buffer.size());
559+ exceptionInfo.expandInfo.u.aicpuInfo.functionName = "DynTileFwkKernelServer";
560+ exceptionInfo.expandInfo.u.aicpuInfo.kernelName = "DynTileFwkKernelServer";
561+ auto ret = ExceptionDumpCallBack(&exceptionInfo, &dumpInfo, dumpSize, &realSize, &mode);
562+ EXPECT_EQ(ret, 0);
563+ EXPECT_STREQ(dumpInfo.kernelName, "DynTileFwkKernelServer");
564+ EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_bundle_valuedep");
565+}
566+ 
567+TEST_F(DeviceExceptionDumpTest, TestAicpuExceptionOfflineUsesFunctionNameFallback)
568+{
569+ Program::GetInstance().SetLastFunction(nullptr);
570+ std::vector<uint8_t> buffer;
571+ BuildAicpuArgBuffer(buffer, 0, {});
572+ RtExceptionInfo exceptionInfo = {};
573+ AdxExceptionDumpInfo dumpInfo = {};
574+ uint32_t dumpSize = 1;
575+ uint32_t realSize = 0;
576+ AdxExceptionDumpMode mode = AdxExceptionDumpMode::ADX_DUMP_MODE_NONE;
577+ exceptionInfo.expandInfo.type = RtExceptionExpandType::AICPU;
578+ exceptionInfo.expandInfo.u.aicpuInfo.argAddr = buffer.data();
579+ exceptionInfo.expandInfo.u.aicpuInfo.argsize = static_cast<uint32_t>(buffer.size());
580+ exceptionInfo.expandInfo.u.aicpuInfo.functionName = "DynTileFwkKernelServer";
581+ exceptionInfo.expandInfo.u.aicpuInfo.kernelName = nullptr;
582+ auto ret = ExceptionDumpCallBack(&exceptionInfo, &dumpInfo, dumpSize, &realSize, &mode);
583+ EXPECT_EQ(ret, 0);
584+ EXPECT_STREQ(dumpInfo.kernelName, "DynTileFwkKernelServer");
585+ EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_Aicpu_bundle_kernel");
586+}
587+ 
588+TEST_F(DeviceExceptionDumpTest, TestAicpuExceptionOfflineUsesBundleFallback)
589+{
590+ Program::GetInstance().SetLastFunction(nullptr);
591+ std::vector<uint8_t> buffer;
592+ BuildAicpuArgBuffer(buffer, 0, {});
593+ RtExceptionInfo exceptionInfo = {};
594+ AdxExceptionDumpInfo dumpInfo = {};
595+ uint32_t dumpSize = 1;
596+ uint32_t realSize = 0;
597+ AdxExceptionDumpMode mode = AdxExceptionDumpMode::ADX_DUMP_MODE_NONE;
598+ exceptionInfo.expandInfo.type = RtExceptionExpandType::AICPU;
599+ exceptionInfo.expandInfo.u.aicpuInfo.argAddr = buffer.data();
600+ exceptionInfo.expandInfo.u.aicpuInfo.argsize = static_cast<uint32_t>(buffer.size());
601+ exceptionInfo.expandInfo.u.aicpuInfo.functionName = nullptr;
602+ exceptionInfo.expandInfo.u.aicpuInfo.kernelName = nullptr;
603+ auto ret = ExceptionDumpCallBack(&exceptionInfo, &dumpInfo, dumpSize, &realSize, &mode);
604+ EXPECT_EQ(ret, 0);
605+ EXPECT_STREQ(dumpInfo.kernelName, "");
606+ EXPECT_STREQ(dumpInfo.kernelDisplayName, "PyPTO_Aicpu_bundle_kernel");
607+}