Merged
fix(Interpreter):Add interface to tile_fwk_adapter #5390
dingbo929Add on Aug 11
fix(Interpreter):Add interface to tile_fwk_adapter #5390
Merged
Merged fromdingbo929/pyptomasterintocann/pyptomaster
Total: 10 files changed+84-27
| @@ -49,6 +49,30 @@ int32_t AdumpRegExceptionDumpCallBack(AdumpExceptionDumpCallback callback) | |||
| 49 | return 0; | 49 | return 0; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | +int32_t AdxDumpDataDumpServerInit() | ||
| 53 | +{ | ||
| 54 | +#ifdef BUILD_WITH_CANN | ||
| 55 | + void* func = AdapterManager::Instance().GetAdumpAdapter().GetFunction(AdumpFunc::DataDumpServerInit); | ||
| 56 | + if (func != nullptr) { | ||
| 57 | + int32_t (*adumpFunc)() = reinterpret_cast<int32_t (*)()>(func); | ||
| 58 | + return adumpFunc(); | ||
| 59 | + } | ||
| 60 | +#endif | ||
| 61 | + return StubDumpDataDumpServerInit(); | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +int32_t AdxDumpDataDumpServerUnInit() | ||
| 65 | +{ | ||
| 66 | +#ifdef BUILD_WITH_CANN | ||
| 67 | + void* func = AdapterManager::Instance().GetAdumpAdapter().GetFunction(AdumpFunc::DataDumpServerUnInit); | ||
| 68 | + if (func != nullptr) { | ||
| 69 | + int32_t (*adumpFunc)() = reinterpret_cast<int32_t (*)()>(func); | ||
| 70 | + return adumpFunc(); | ||
| 71 | + } | ||
| 72 | +#endif | ||
| 73 | + return StubDumpDataDumpServerUnInit(); | ||
| 74 | +} | ||
| 75 | + | ||
| 52 | #ifdef BUILD_WITH_CANN | 76 | #ifdef BUILD_WITH_CANN |
| 53 | void ConvertTensorInfos(const std::vector<AdxTensorInfoV2>& tensors, std::vector<Adx::TensorInfoV2>& adxTensors) | 77 | void ConvertTensorInfos(const std::vector<AdxTensorInfoV2>& tensors, std::vector<Adx::TensorInfoV2>& adxTensors) |
| 54 | { | 78 | { |
| @@ -25,4 +25,6 @@ int32_t AdxDumpDumpTensorV2(const std::string& opType, const std::string& opName | |||
| 25 | const std::vector<AdxTensorInfoV2>& tensors, AclRtStream stream); | 25 | const std::vector<AdxTensorInfoV2>& tensors, AclRtStream stream); |
| 26 | 26 | ||
| 27 | int32_t AdumpRegExceptionDumpCallBack(AdumpExceptionDumpCallback callback); | 27 | int32_t AdumpRegExceptionDumpCallBack(AdumpExceptionDumpCallback callback); |
| 28 | +int32_t AdxDumpDataDumpServerInit(); | ||
| 29 | +int32_t AdxDumpDataDumpServerUnInit(); | ||
| 28 | } // namespace npu::tile_fwk | 30 | } // namespace npu::tile_fwk |
| @@ -19,7 +19,14 @@ | |||
| 19 | #include <map> | 19 | #include <map> |
| 20 | 20 | ||
| 21 | namespace npu::tile_fwk { | 21 | namespace npu::tile_fwk { |
| 22 | -enum class AdumpFunc { GetDumpSwitch = 0, DumpTensorV2, DumpFailTaskExceptionCallBack, Bottom }; | 22 | +enum class AdumpFunc { |
| 23 | + GetDumpSwitch = 0, | ||
| 24 | + DumpTensorV2, | ||
| 25 | + DumpFailTaskExceptionCallBack, | ||
| 26 | + DataDumpServerInit, | ||
| 27 | + DataDumpServerUnInit, | ||
| 28 | + Bottom | ||
| 29 | +}; | ||
| 23 | 30 | ||
| 24 | const std::string kAdumpLibName = "libascend_dump.so"; | 31 | const std::string kAdumpLibName = "libascend_dump.so"; |
| 25 | const std::map<AdumpFunc, std::string> kAdumpFuncStrMap{ | 32 | const std::map<AdumpFunc, std::string> kAdumpFuncStrMap{ |
| @@ -27,5 +34,7 @@ const std::map<AdumpFunc, std::string> kAdumpFuncStrMap{ | |||
| 27 | {AdumpFunc::DumpTensorV2, "_ZN3Adx17AdumpDumpTensorV2ERKSsS1_RKSt6vectorINS_12TensorInfoV2ESaIS3_EEPv"}, | 34 | {AdumpFunc::DumpTensorV2, "_ZN3Adx17AdumpDumpTensorV2ERKSsS1_RKSt6vectorINS_12TensorInfoV2ESaIS3_EEPv"}, |
| 28 | {AdumpFunc::DumpFailTaskExceptionCallBack, | 35 | {AdumpFunc::DumpFailTaskExceptionCallBack, |
| 29 | "_ZN3Adx29AdumpRegExceptionDumpCallbackEPFjPvPNS_17ExceptionDumpInfoEjPjPNS_17ExceptionDumpModeEE"}, | 36 | "_ZN3Adx29AdumpRegExceptionDumpCallbackEPFjPvPNS_17ExceptionDumpInfoEjPjPNS_17ExceptionDumpModeEE"}, |
| 37 | + {AdumpFunc::DataDumpServerInit, "AdxDataDumpServerInit"}, | ||
| 38 | + {AdumpFunc::DataDumpServerUnInit, "AdxDataDumpServerUnInit"}, | ||
| 30 | }; | 39 | }; |
| 31 | } // namespace npu::tile_fwk | 40 | } // namespace npu::tile_fwk |
| @@ -34,4 +34,16 @@ int32_t StubDumpDumpTensorV2(const std::string& opType, const std::string& opNam | |||
| 34 | (void)stream; | 34 | (void)stream; |
| 35 | return 0; | 35 | return 0; |
| 36 | } | 36 | } |
| 37 | + | ||
| 38 | +int32_t StubDumpDataDumpServerInit() | ||
| 39 | +{ | ||
| 40 | + ADAPTER_LOGD("Enter stub function of AdxDataDumpServerInit."); | ||
| 41 | + return 0; | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +int32_t StubDumpDataDumpServerUnInit() | ||
| 45 | +{ | ||
| 46 | + ADAPTER_LOGD("Enter stub function of AdxDataDumpServerUnInit."); | ||
| 47 | + return 0; | ||
| 48 | +} | ||
| 37 | } // namespace npu::tile_fwk | 49 | } // namespace npu::tile_fwk |
| @@ -24,4 +24,6 @@ namespace npu::tile_fwk { | |||
| 24 | uint64_t StubDumpGetDumpSwitch(const AdxDumpType dumpType); | 24 | uint64_t StubDumpGetDumpSwitch(const AdxDumpType dumpType); |
| 25 | int32_t StubDumpDumpTensorV2(const std::string& opType, const std::string& opName, | 25 | int32_t StubDumpDumpTensorV2(const std::string& opType, const std::string& opName, |
| 26 | const std::vector<AdxTensorInfoV2>& tensors, AclRtStream stream); | 26 | const std::vector<AdxTensorInfoV2>& tensors, AclRtStream stream); |
| 27 | +int32_t StubDumpDataDumpServerInit(); | ||
| 28 | +int32_t StubDumpDataDumpServerUnInit(); | ||
| 27 | } // namespace npu::tile_fwk | 29 | } // namespace npu::tile_fwk |
| @@ -51,7 +51,6 @@ target_link_libraries(tile_fwk_runtime | |||
| 51 | tile_fwk_intf_pub | 51 | tile_fwk_intf_pub |
| 52 | dl | 52 | dl |
| 53 | c_sec | 53 | c_sec |
| 54 | - $<$<AND:$<BOOL:${BUILD_WITH_CANN}>,$<NOT:$<BOOL:${ENABLE_UTEST}>>>:ascend_dump> | ||
| 55 | ) | 54 | ) |
| 56 | 55 | ||
| 57 | PTO_Fwk_AnalysisTargetHeaderFiles(TARGET tile_fwk_runtime) | 56 | PTO_Fwk_AnalysisTargetHeaderFiles(TARGET tile_fwk_runtime) |
| @@ -36,9 +36,6 @@ | |||
| 36 | #include "machine/host/perf_analysis.h" | 36 | #include "machine/host/perf_analysis.h" |
| 37 | #include "interface/program/program.h" | 37 | #include "interface/program/program.h" |
| 38 | 38 | ||
| 39 | -extern "C" __attribute__((weak)) int AdxDataDumpServerUnInit(); | ||
| 40 | -extern "C" __attribute__((weak)) int AdxDataDumpServerInit(); | ||
| 41 | - | ||
| 42 | namespace npu::tile_fwk::dynamic { | 39 | namespace npu::tile_fwk::dynamic { |
| 43 | bool DeviceLauncher::inited_ = false; | 40 | bool DeviceLauncher::inited_ = false; |
| 44 | std::vector<uint8_t> DeviceLauncher::tensorInfo_(kDefaultTensorinfoSize); | 41 | std::vector<uint8_t> DeviceLauncher::tensorInfo_(kDefaultTensorinfoSize); |
| @@ -229,12 +226,8 @@ CachedOperator* DeviceLauncher::GetDevRunCacheOperator(Function* func) | |||
| 229 | void DeviceLauncher::DataDumpInit() | 226 | void DeviceLauncher::DataDumpInit() |
| 230 | { | 227 | { |
| 231 | if (IsPtoDataDumpEnabled()) { | 228 | if (IsPtoDataDumpEnabled()) { |
| 232 | - if (!AdxDataDumpServerInit) { | ||
| 233 | - MACHINE_LOGE(DevCommonErr::NULLPTR, "AdxDataDumpServerInit function not found (weak symbol is null)."); | ||
| 234 | - return; | ||
| 235 | - } | ||
| 236 | MACHINE_LOGD("DataDumpServerInit is called \n"); | 229 | MACHINE_LOGD("DataDumpServerInit is called \n"); |
| 237 | - int sf = AdxDataDumpServerInit(); | 230 | + int sf = AdxDumpDataDumpServerInit(); |
| 238 | if (sf != 0) { | 231 | if (sf != 0) { |
| 239 | MACHINE_LOGW("ERROR AdxDataDumpServerInit failed \n"); | 232 | MACHINE_LOGW("ERROR AdxDataDumpServerInit failed \n"); |
| 240 | } | 233 | } |
| @@ -244,12 +237,8 @@ void DeviceLauncher::DataDumpInit() | |||
| 244 | void DeviceLauncher::DataDumpUnInit() | 237 | void DeviceLauncher::DataDumpUnInit() |
| 245 | { | 238 | { |
| 246 | if (IsPtoDataDumpEnabled()) { | 239 | if (IsPtoDataDumpEnabled()) { |
| 247 | - if (!AdxDataDumpServerUnInit) { | ||
| 248 | - MACHINE_LOGE(DevCommonErr::NULLPTR, "AdxDataDumpServerUnInit function not found (weak symbol is null)."); | ||
| 249 | - return; | ||
| 250 | - } | ||
| 251 | MACHINE_LOGD("DataDumpServerUnInit is called \n"); | 240 | MACHINE_LOGD("DataDumpServerUnInit is called \n"); |
| 252 | - int sf = AdxDataDumpServerUnInit(); | 241 | + int sf = AdxDumpDataDumpServerUnInit(); |
| 253 | if (sf != 0) { | 242 | if (sf != 0) { |
| 254 | MACHINE_LOGW("AdxDataDumpServerUnInit is failed %d \n", sf); | 243 | MACHINE_LOGW("AdxDataDumpServerUnInit is failed %d \n", sf); |
| 255 | } | 244 | } |
| @@ -42,9 +42,6 @@ | |||
| 42 | #include "machine/utils/machine_ws_intf.h" | 42 | #include "machine/utils/machine_ws_intf.h" |
| 43 | #include "securec.h" | 43 | #include "securec.h" |
| 44 | 44 | ||
| 45 | -extern "C" { | ||
| 46 | -__attribute__((weak)) int AdxDataDumpServerUnInit(); | ||
| 47 | -} | ||
| 48 | namespace npu::tile_fwk { | 45 | namespace npu::tile_fwk { |
| 49 | namespace { | 46 | namespace { |
| 50 | constexpr uint32_t MIX_BLOCK_DIM = 2; | 47 | constexpr uint32_t MIX_BLOCK_DIM = 2; |
| @@ -199,12 +196,8 @@ int DeviceRunner::DynamicLaunchSynchronize(RtStream schedStream, RtStream ctrlSt | |||
| 199 | rcCtrl = RuntimeStreamSynchronize(ctrlStream); | 196 | rcCtrl = RuntimeStreamSynchronize(ctrlStream); |
| 200 | } | 197 | } |
| 201 | if (IsPtoDataDumpEnabled()) { | 198 | if (IsPtoDataDumpEnabled()) { |
| 202 | - if (!AdxDataDumpServerUnInit) { | 199 | + MACHINE_LOGD("DataDumpServerUnInit is called \n"); |
| 203 | - MACHINE_LOGE(DevCommonErr::NULLPTR, "AdxDataDumpServerUnInit function not found (weak symbol is null)."); | 200 | + (void)AdxDumpDataDumpServerUnInit(); |
| 204 | - } else { | ||
| 205 | - MACHINE_LOGD("DataDumpServerInit is called \n"); | ||
| 206 | - AdxDataDumpServerUnInit(); | ||
| 207 | - } | ||
| 208 | } | 201 | } |
| 209 | int retAicorePrint = 0; | 202 | int retAicorePrint = 0; |
| 210 | if (static_cast<bool>(ENABLE_AICORE_PRINT)) { | 203 | if (static_cast<bool>(ENABLE_AICORE_PRINT)) { |
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "adapter/api/runtime_api.h" | 21 | #include "adapter/api/runtime_api.h" |
| 22 | #include "adapter/api/runtime_capture_context.h" | 22 | #include "adapter/api/runtime_capture_context.h" |
| 23 | #include "adapter/manager/adapter_manager.h" | 23 | #include "adapter/manager/adapter_manager.h" |
| 24 | +#include "adapter/stubs/adump_stubs.h" | ||
| 24 | #include "tilefwk/error.h" | 25 | #include "tilefwk/error.h" |
| 25 | 26 | ||
| 26 | namespace npu::tile_fwk { | 27 | namespace npu::tile_fwk { |
| @@ -166,6 +167,16 @@ TEST_F(TestAdapterApi, test_adump_api) | |||
| 166 | tensorInfo.originShape = {1, 128}; | 167 | tensorInfo.originShape = {1, 128}; |
| 167 | std::vector<AdxTensorInfoV2> tensors = {tensorInfo}; | 168 | std::vector<AdxTensorInfoV2> tensors = {tensorInfo}; |
| 168 | CHECK_API_RET(AdxDumpDumpTensorV2("op_name", "op_type", tensors, nullptr), 0); | 169 | CHECK_API_RET(AdxDumpDumpTensorV2("op_name", "op_type", tensors, nullptr), 0); |
| 170 | + CHECK_API_RET(AdxDumpDataDumpServerInit(), 0); | ||
| 171 | + CHECK_API_RET(AdxDumpDataDumpServerUnInit(), 0); | ||
| 172 | +} | ||
| 173 | + | ||
| 174 | +TEST_F(TestAdapterApi, test_adump_stubs) | ||
| 175 | +{ | ||
| 176 | + EXPECT_EQ(StubDumpGetDumpSwitch(AdxDumpType::OPERATOR), 0); | ||
| 177 | + EXPECT_EQ(StubDumpDumpTensorV2("op_name", "op_type", {}, nullptr), 0); | ||
| 178 | + EXPECT_EQ(StubDumpDataDumpServerInit(), 0); | ||
| 179 | + EXPECT_EQ(StubDumpDataDumpServerUnInit(), 0); | ||
| 169 | } | 180 | } |
| 170 | 181 | ||
| 171 | TEST_F(TestAdapterApi, test_hal_api) | 182 | TEST_F(TestAdapterApi, test_hal_api) |
| @@ -297,6 +308,12 @@ TEST_F(TestAdapterApi, test_adump_api_with_valid_params) | |||
| 297 | std::vector<AdxTensorInfoV2> tensors = {tensorInfo}; | 308 | std::vector<AdxTensorInfoV2> tensors = {tensorInfo}; |
| 298 | auto dumpRet = AdxDumpDumpTensorV2("op_name", "op_type", tensors, nullptr); | 309 | auto dumpRet = AdxDumpDumpTensorV2("op_name", "op_type", tensors, nullptr); |
| 299 | EXPECT_EQ(dumpRet, 0); | 310 | EXPECT_EQ(dumpRet, 0); |
| 311 | + | ||
| 312 | + auto serverInitRet = AdxDumpDataDumpServerInit(); | ||
| 313 | + EXPECT_EQ(serverInitRet, 0); | ||
| 314 | + | ||
| 315 | + auto serverUnInitRet = AdxDumpDataDumpServerUnInit(); | ||
| 316 | + EXPECT_EQ(serverUnInitRet, 0); | ||
| 300 | } | 317 | } |
| 301 | 318 | ||
| 302 | TEST_F(TestAdapterApi, test_hal_api_with_valid_params) | 319 | TEST_F(TestAdapterApi, test_hal_api_with_valid_params) |
| @@ -410,6 +427,10 @@ TEST_F(TestAdapterApi, test_adump_adapter) | |||
| 410 | EXPECT_EQ( | 427 | EXPECT_EQ( |
| 411 | AdapterManager::Instance().GetAdumpAdapter().GetFunction(AdumpFunc::DumpFailTaskExceptionCallBack) != nullptr, | 428 | AdapterManager::Instance().GetAdumpAdapter().GetFunction(AdumpFunc::DumpFailTaskExceptionCallBack) != nullptr, |
| 412 | loaded); | 429 | loaded); |
| 430 | + EXPECT_EQ(AdapterManager::Instance().GetAdumpAdapter().GetFunction(AdumpFunc::DataDumpServerInit) != nullptr, | ||
| 431 | + loaded); | ||
| 432 | + EXPECT_EQ(AdapterManager::Instance().GetAdumpAdapter().GetFunction(AdumpFunc::DataDumpServerUnInit) != nullptr, | ||
| 433 | + loaded); | ||
| 413 | } | 434 | } |
| 414 | 435 | ||
| 415 | TEST_F(TestAdapterApi, test_hal_adapter) | 436 | TEST_F(TestAdapterApi, test_hal_adapter) |
| @@ -668,6 +689,9 @@ TEST_F(TestAdapterApi, test_adump_api_with_device) | |||
| 668 | tensorInfo.originShape = {1, 128}; | 689 | tensorInfo.originShape = {1, 128}; |
| 669 | std::vector<AdxTensorInfoV2> tensors = {tensorInfo}; | 690 | std::vector<AdxTensorInfoV2> tensors = {tensorInfo}; |
| 670 | EXPECT_EQ(AdxDumpDumpTensorV2("op_name", "op_type", tensors, nullptr), 0); | 691 | EXPECT_EQ(AdxDumpDumpTensorV2("op_name", "op_type", tensors, nullptr), 0); |
| 692 | + | ||
| 693 | + EXPECT_EQ(AdxDumpDataDumpServerInit(), 0); | ||
| 694 | + EXPECT_EQ(AdxDumpDataDumpServerUnInit(), 0); | ||
| 671 | } | 695 | } |
| 672 | 696 | ||
| 673 | TEST_F(TestAdapterApi, test_hal_api_with_device) | 697 | TEST_F(TestAdapterApi, test_hal_api_with_device) |
| @@ -501,9 +501,12 @@ class CompactDumpTensorInfoParser: | |||
| 501 | """ | 501 | """ |
| 502 | field_size = FIELD_SIZES[field_type] | 502 | field_size = FIELD_SIZES[field_type] |
| 503 | total_bytes = field_size * array_len | 503 | total_bytes = field_size * array_len |
| 504 | - # 校验数据长度 | 504 | + # verify data length |
| 505 | if offset + total_bytes > len(bin_data): | 505 | if offset + total_bytes > len(bin_data): |
| 506 | - raise ValueError(f"字段解析失败:偏移{offset},需要{total_bytes}字节,剩余{len(bin_data) - offset}字节") | 506 | + remaining = len(bin_data) - offset |
| 507 | + raise ValueError( | ||
| 508 | + f"Field parse failed: offset {offset}, need {total_bytes} bytes, remaining {remaining} bytes" | ||
| 509 | + ) | ||
| 507 | 510 | ||
| 508 | # 构建单个元素的格式符 | 511 | # 构建单个元素的格式符 |
| 509 | fmt_char = {"uint8_t": "B", "uint16_t": "H", "uint32_t": "I", "int32_t": "i", "int64_t": "q", "uint64_t": "Q"}[ | 512 | fmt_char = {"uint8_t": "B", "uint16_t": "H", "uint32_t": "I", "int32_t": "i", "int64_t": "q", "uint64_t": "Q"}[ |
| @@ -651,7 +654,7 @@ class CompactDumpTensorInfoParser: | |||
| 651 | def parse_file(self, file_path: str) -> list[dict]: | 654 | def parse_file(self, file_path: str) -> list[dict]: |
| 652 | """解析整个紧凑存储的bin文件""" | 655 | """解析整个紧凑存储的bin文件""" |
| 653 | if not os.path.exists(file_path): | 656 | if not os.path.exists(file_path): |
| 654 | - raise FileNotFoundError(f"文件不存在:{file_path}") | 657 | + raise FileNotFoundError(f"File not found: {file_path}") |
| 655 | 658 | ||
| 656 | with open(file_path, "rb") as f: | 659 | with open(file_path, "rb") as f: |
| 657 | bin_data = f.read() | 660 | bin_data = f.read() |