Merged
feat(dfx): Runtime memory overlap check #5107
duanhaotianAdd on Jul 27
feat(dfx): Runtime memory overlap check #5107
Merged
Merged fromduanhaotian/pyptoduanhaotian7intocann/pyptomaster
Total: 28 files changed+1231-40
| @@ -527,8 +527,7 @@ void CodeGenNPU::BuildArchOptions(std::ostringstream& oss, const CompileInfo& co | |||
| 527 | if (ConfigManager::Instance().GetCodeGenConfig(KEY_CODEGEN_SUPPORT_TILE_TENSOR, false)) { | 527 | if (ConfigManager::Instance().GetCodeGenConfig(KEY_CODEGEN_SUPPORT_TILE_TENSOR, false)) { |
| 528 | compileOpts.emplace_back("-DSUPPORT_TILE_TENSOR"); | 528 | compileOpts.emplace_back("-DSUPPORT_TILE_TENSOR"); |
| 529 | } | 529 | } |
| 530 | - if (config::GetPlatformConfig(KEY_ENABLE_PROF_AICORE_TIME, false) || | 530 | + if (config::GetPlatformConfig(KEY_ENABLE_PROF_AICORE_TIME, false) || config::IsRuntimeDebugAllEnabled()) { |
| 531 | - config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_DEBUG_ALL) { | ||
| 532 | compileOpts.emplace_back("-DOPEN_MIX_PERF"); | 531 | compileOpts.emplace_back("-DOPEN_MIX_PERF"); |
| 533 | } | 532 | } |
| 534 | 533 | ||
| @@ -503,6 +503,8 @@ inline T GetDebugOption(const std::string& key) | |||
| 503 | return ConfigManagerNg::CurrentScope()->GetConfigAllType<T>("debug." + key); | 503 | return ConfigManagerNg::CurrentScope()->GetConfigAllType<T>("debug." + key); |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | +inline bool IsRuntimeDebugAllEnabled() { return GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_DEBUG_ALL; } | ||
| 507 | + | ||
| 506 | /** | 508 | /** |
| 507 | * @brief Get operation configuration option | 509 | * @brief Get operation configuration option |
| 508 | */ | 510 | */ |
| @@ -0,0 +1,497 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file dump_device_memory.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | +#include "machine/device/dump/dump_device_memory.h" | ||
| 16 | + | ||
| 17 | +#ifndef __DEVICE__ | ||
| 18 | +#include <algorithm> | ||
| 19 | +#include <fstream> | ||
| 20 | +#include <mutex> | ||
| 21 | +#include <set> | ||
| 22 | +#include <string> | ||
| 23 | +#include <utility> | ||
| 24 | +#include "interface/configs/config_manager.h" | ||
| 25 | +#include "interface/function/rebuildable_attribute.h" | ||
| 26 | +#include "machine/utils/dep_verify_dump_path.h" | ||
| 27 | +#include "machine/utils/dynamic/dev_callop_attribute.h" | ||
| 28 | +#include "machine/utils/dynamic/dev_encode_program.h" | ||
| 29 | +#endif | ||
| 30 | + | ||
| 31 | +namespace npu::tile_fwk::dynamic::mem_dump { | ||
| 32 | + | ||
| 33 | +#ifndef __DEVICE__ | ||
| 34 | +namespace { | ||
| 35 | + | ||
| 36 | +void OpenIfPathChanged(std::ofstream& ofs, std::string& lastPath, const std::string& path, const char* header) | ||
| 37 | +{ | ||
| 38 | + if (path == lastPath) { | ||
| 39 | + return; | ||
| 40 | + } | ||
| 41 | + if (ofs.is_open()) { | ||
| 42 | + ofs.close(); | ||
| 43 | + } | ||
| 44 | + lastPath = path; | ||
| 45 | + ofs.open(path); | ||
| 46 | + if (ofs.is_open()) { | ||
| 47 | + ofs << header << '\n'; | ||
| 48 | + } | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +inline bool DumpEnabled() | ||
| 52 | +{ | ||
| 53 | + static const bool cached = (config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_RUNTIME_DEBUG_VERIFY); | ||
| 54 | + return cached; | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +struct TensorSummary { | ||
| 58 | + bool valid{false}; | ||
| 59 | + uint32_t seqNo{0}; | ||
| 60 | + uint32_t funcIdx{0}; | ||
| 61 | + int rootIndex{0}; | ||
| 62 | + int rawMagic{0}; | ||
| 63 | + uint64_t base{0}; | ||
| 64 | + uint64_t end{0}; | ||
| 65 | + uint64_t size{0}; | ||
| 66 | + std::string location; | ||
| 67 | +}; | ||
| 68 | + | ||
| 69 | +struct LargestRootFunctionSummary { | ||
| 70 | + bool valid{false}; | ||
| 71 | + std::string name; | ||
| 72 | + uint64_t unroll{0}; | ||
| 73 | + uint64_t innerSpilledRaw{0}; | ||
| 74 | + uint64_t leafSpilled{0}; | ||
| 75 | + uint64_t totalOutcastRaw{0}; | ||
| 76 | + uint64_t staticOutcast{0}; | ||
| 77 | +}; | ||
| 78 | + | ||
| 79 | +struct TensorWorkspaceBreakdown { | ||
| 80 | + uint64_t totalBytes{0}; | ||
| 81 | + uint64_t bytesBeforeAlignmentAndParallelism{0}; | ||
| 82 | + uint64_t rootInnerSpilledBytes{0}; | ||
| 83 | + uint64_t devTaskInnerExclusiveOutcastBytes{0}; | ||
| 84 | + uint64_t outcastPoolBytes{0}; | ||
| 85 | + uint64_t maxOutcastBytes{0}; | ||
| 86 | + uint64_t maxStaticOutcastBytes{0}; | ||
| 87 | + uint64_t maxDynamicAssembleOutcastBytes{0}; | ||
| 88 | + uint64_t devTaskBoundaryOutcastCount{0}; | ||
| 89 | + uint64_t devTaskInnerTemporalOutcastCount{0}; | ||
| 90 | + uint64_t boundaryAndInnerTemporalOutcastCount{0}; | ||
| 91 | + uint32_t parallelism{0}; | ||
| 92 | + uint32_t slottableOutcastSlotSize{0}; | ||
| 93 | + uint32_t memoryDrivenWorkspace{0}; | ||
| 94 | +}; | ||
| 95 | + | ||
| 96 | +struct AiCoreSpilledBreakdown { | ||
| 97 | + uint64_t totalBytes{0}; | ||
| 98 | + uint64_t perCoreBytes{0}; | ||
| 99 | + uint64_t aicoreCount{0}; | ||
| 100 | +}; | ||
| 101 | + | ||
| 102 | +struct WorkspaceBreakdown { | ||
| 103 | + uint64_t totalBytes{0}; | ||
| 104 | + LargestRootFunctionSummary largestRootFunction; | ||
| 105 | + TensorWorkspaceBreakdown tensor; | ||
| 106 | + AiCoreSpilledBreakdown aicoreSpilled; | ||
| 107 | +}; | ||
| 108 | + | ||
| 109 | +struct MetadataBreakdown { | ||
| 110 | + uint64_t totalBytes{0}; | ||
| 111 | + uint64_t generalBytes{0}; | ||
| 112 | + uint64_t dynamicCellMatchBytes{0}; | ||
| 113 | + uint64_t stitchPoolBytes{0}; | ||
| 114 | + uint64_t maxDynamicCellMatchTableBytes{0}; | ||
| 115 | + uint64_t dynamicCellMatchSlotCount{0}; | ||
| 116 | + uint32_t generalSlabSize{0}; | ||
| 117 | + uint32_t stitchSlabSize{0}; | ||
| 118 | +}; | ||
| 119 | + | ||
| 120 | +struct MemoryOverviewState { | ||
| 121 | + bool started{false}; | ||
| 122 | + uint64_t workspaceSize{0}; | ||
| 123 | + uint64_t tensorWorkspaceSize{0}; | ||
| 124 | + uint64_t metadataSize{0}; | ||
| 125 | + uint64_t globalTensorBytes{0}; | ||
| 126 | + std::set<std::pair<uint64_t, uint64_t>> globalTensorRanges; | ||
| 127 | + TensorSummary largestGlobalTensor; | ||
| 128 | + TensorSummary largestWorkspaceTensor; | ||
| 129 | + WorkspaceBreakdown workspaceBreakdown; | ||
| 130 | + MetadataBreakdown metadataBreakdown; | ||
| 131 | +}; | ||
| 132 | + | ||
| 133 | +std::mutex& OverviewMutex() | ||
| 134 | +{ | ||
| 135 | + static std::mutex mu; | ||
| 136 | + return mu; | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +MemoryOverviewState& OverviewState() | ||
| 140 | +{ | ||
| 141 | + static MemoryOverviewState state; | ||
| 142 | + return state; | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +void WriteSectionHeader(std::ofstream& ofs, const char* section) { ofs << '\n' << '[' << section << "]\n"; } | ||
| 146 | + | ||
| 147 | +void WriteTensorSummary(std::ofstream& ofs, const char* section, const TensorSummary& tensor) | ||
| 148 | +{ | ||
| 149 | + WriteSectionHeader(ofs, section); | ||
| 150 | + ofs << "valid=" << (tensor.valid ? 1 : 0) << '\n'; | ||
| 151 | + if (!tensor.valid) { | ||
| 152 | + return; | ||
| 153 | + } | ||
| 154 | + ofs << "seqNo=" << tensor.seqNo << '\n' | ||
| 155 | + << "funcIdx=" << tensor.funcIdx << '\n' | ||
| 156 | + << "rootIndex=" << tensor.rootIndex << '\n' | ||
| 157 | + << "rawMagic=" << tensor.rawMagic << '\n' | ||
| 158 | + << "base=" << tensor.base << '\n' | ||
| 159 | + << "end=" << tensor.end << '\n' | ||
| 160 | + << "size=" << tensor.size << '\n' | ||
| 161 | + << "location=" << tensor.location << '\n'; | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +void WriteOverviewLocked() | ||
| 165 | +{ | ||
| 166 | + const MemoryOverviewState& state = OverviewState(); | ||
| 167 | + if (!state.started) { | ||
| 168 | + return; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + std::ofstream ofs(GetDepVerifyDumpDir() + "/mem_overview.txt", std::ios::out | std::ios::trunc); | ||
| 172 | + if (!ofs.is_open()) { | ||
| 173 | + return; | ||
| 174 | + } | ||
| 175 | + ofs << "schemaVersion=2\n"; | ||
| 176 | + | ||
| 177 | + WriteSectionHeader(ofs, "overall"); | ||
| 178 | + ofs << "globalTensorBytes=" << state.globalTensorBytes << '\n' | ||
| 179 | + << "workspaceBytes=" << state.workspaceSize << '\n' | ||
| 180 | + << "tensorWorkspaceBytes=" << state.tensorWorkspaceSize << '\n' | ||
| 181 | + << "metadataBytes=" << state.metadataSize << '\n' | ||
| 182 | + << "workspaceAndMetadataBytes=" << state.workspaceSize + state.metadataSize << '\n' | ||
| 183 | + << "trackedTotalBytes=" << state.globalTensorBytes + state.workspaceSize + state.metadataSize << '\n'; | ||
| 184 | + | ||
| 185 | + const WorkspaceBreakdown& workspace = state.workspaceBreakdown; | ||
| 186 | + WriteSectionHeader(ofs, "workspace"); | ||
| 187 | + ofs << "totalBytes=" << workspace.totalBytes << '\n'; | ||
| 188 | + | ||
| 189 | + const LargestRootFunctionSummary& largestRoot = workspace.largestRootFunction; | ||
| 190 | + WriteSectionHeader(ofs, "workspace.largestRootFunction"); | ||
| 191 | + ofs << "valid=" << (largestRoot.valid ? 1 : 0) << '\n'; | ||
| 192 | + if (largestRoot.valid) { | ||
| 193 | + ofs << "name=" << largestRoot.name << '\n' | ||
| 194 | + << "unroll=" << largestRoot.unroll << '\n' | ||
| 195 | + << "innerSpilledRaw=" << largestRoot.innerSpilledRaw << '\n' | ||
| 196 | + << "leafSpilled=" << largestRoot.leafSpilled << '\n' | ||
| 197 | + << "totalOutcastRaw=" << largestRoot.totalOutcastRaw << '\n' | ||
| 198 | + << "staticOutcast=" << largestRoot.staticOutcast << '\n'; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + const TensorWorkspaceBreakdown& tensor = workspace.tensor; | ||
| 202 | + WriteSectionHeader(ofs, "workspace.tensor"); | ||
| 203 | + ofs << "totalBytes=" << tensor.totalBytes << '\n' | ||
| 204 | + << "bytesBeforeAlignmentAndParallelism=" << tensor.bytesBeforeAlignmentAndParallelism << '\n' | ||
| 205 | + << "rootInnerSpilledBytes=" << tensor.rootInnerSpilledBytes << '\n' | ||
| 206 | + << "devTaskInnerExclusiveOutcastBytes=" << tensor.devTaskInnerExclusiveOutcastBytes << '\n' | ||
| 207 | + << "outcastPoolBytes=" << tensor.outcastPoolBytes << '\n' | ||
| 208 | + << "maxOutcastBytes=" << tensor.maxOutcastBytes << '\n' | ||
| 209 | + << "maxStaticOutcastBytes=" << tensor.maxStaticOutcastBytes << '\n' | ||
| 210 | + << "maxDynamicAssembleOutcastBytes=" << tensor.maxDynamicAssembleOutcastBytes << '\n' | ||
| 211 | + << "devTaskBoundaryOutcastCount=" << tensor.devTaskBoundaryOutcastCount << '\n' | ||
| 212 | + << "devTaskInnerTemporalOutcastCount=" << tensor.devTaskInnerTemporalOutcastCount << '\n' | ||
| 213 | + << "boundaryAndInnerTemporalOutcastCount=" << tensor.boundaryAndInnerTemporalOutcastCount << '\n' | ||
| 214 | + << "parallelism=" << tensor.parallelism << '\n' | ||
| 215 | + << "slottableOutcastSlotSize=" << tensor.slottableOutcastSlotSize << '\n' | ||
| 216 | + << "memoryDrivenWorkspace=" << tensor.memoryDrivenWorkspace << '\n'; | ||
| 217 | + | ||
| 218 | + const AiCoreSpilledBreakdown& aicoreSpilled = workspace.aicoreSpilled; | ||
| 219 | + WriteSectionHeader(ofs, "workspace.aicoreSpilled"); | ||
| 220 | + ofs << "totalBytes=" << aicoreSpilled.totalBytes << '\n' | ||
| 221 | + << "perCoreBytes=" << aicoreSpilled.perCoreBytes << '\n' | ||
| 222 | + << "aicoreCount=" << aicoreSpilled.aicoreCount << '\n'; | ||
| 223 | + | ||
| 224 | + const MetadataBreakdown& metadata = state.metadataBreakdown; | ||
| 225 | + WriteSectionHeader(ofs, "metadata"); | ||
| 226 | + ofs << "totalBytes=" << metadata.totalBytes << '\n' | ||
| 227 | + << "generalBytes=" << metadata.generalBytes << '\n' | ||
| 228 | + << "dynamicCellMatchBytes=" << metadata.dynamicCellMatchBytes << '\n' | ||
| 229 | + << "stitchPoolBytes=" << metadata.stitchPoolBytes << '\n' | ||
| 230 | + << "maxDynamicCellMatchTableBytes=" << metadata.maxDynamicCellMatchTableBytes << '\n' | ||
| 231 | + << "dynamicCellMatchSlotCount=" << metadata.dynamicCellMatchSlotCount << '\n' | ||
| 232 | + << "generalSlabSize=" << metadata.generalSlabSize << '\n' | ||
| 233 | + << "stitchSlabSize=" << metadata.stitchSlabSize << '\n'; | ||
| 234 | + | ||
| 235 | + WriteTensorSummary(ofs, "rawTensorStatistics.largestGlobalTensor", state.largestGlobalTensor); | ||
| 236 | + WriteTensorSummary(ofs, "rawTensorStatistics.largestWorkspaceTensor", state.largestWorkspaceTensor); | ||
| 237 | +} | ||
| 238 | + | ||
| 239 | +void RecordTensorOverview(uint32_t seqNo, uint32_t funcIdx, int rootIndex, const DevAscendRawTensor* rawTensor, | ||
| 240 | + uint64_t base, uint64_t end, const char* location) | ||
| 241 | +{ | ||
| 242 | + if (end <= base) { | ||
| 243 | + return; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + std::lock_guard<std::mutex> lock(OverviewMutex()); | ||
| 247 | + MemoryOverviewState& state = OverviewState(); | ||
| 248 | + if (!state.started) { | ||
| 249 | + return; | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + TensorSummary tensor{true, seqNo, funcIdx, rootIndex, rawTensor->rawMagic, base, end, end - base, location}; | ||
| 253 | + std::pair<uint64_t, uint64_t> range{base, end}; | ||
| 254 | + bool isWorkspace = rawTensor->ioProperty != DevIOProperty::ROOT_INCAST && | ||
| 255 | + rawTensor->ioProperty != DevIOProperty::ROOT_OUTCAST; | ||
| 256 | + if (isWorkspace) { | ||
| 257 | + if (!state.largestWorkspaceTensor.valid || tensor.size > state.largestWorkspaceTensor.size) { | ||
| 258 | + state.largestWorkspaceTensor = tensor; | ||
| 259 | + } | ||
| 260 | + return; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + if (base == 0) { | ||
| 264 | + return; | ||
| 265 | + } | ||
| 266 | + if (state.globalTensorRanges.insert(range).second) { | ||
| 267 | + state.globalTensorBytes += tensor.size; | ||
| 268 | + } | ||
| 269 | + if (!state.largestGlobalTensor.valid || tensor.size > state.largestGlobalTensor.size) { | ||
| 270 | + state.largestGlobalTensor = tensor; | ||
| 271 | + } | ||
| 272 | +} | ||
| 273 | + | ||
| 274 | +void FlushOverview() | ||
| 275 | +{ | ||
| 276 | + std::lock_guard<std::mutex> lock(OverviewMutex()); | ||
| 277 | + WriteOverviewLocked(); | ||
| 278 | +} | ||
| 279 | + | ||
| 280 | +const char* LocationName(DevIOProperty ioProperty) | ||
| 281 | +{ | ||
| 282 | + switch (ioProperty) { | ||
| 283 | + case DevIOProperty::ROOT_INCAST: | ||
| 284 | + return "INCAST"; | ||
| 285 | + case DevIOProperty::ROOT_OUTCAST: | ||
| 286 | + return "OUTCAST"; | ||
| 287 | + default: | ||
| 288 | + return "LOCAL"; | ||
| 289 | + } | ||
| 290 | +} | ||
| 291 | + | ||
| 292 | +void WriteU64List(std::ofstream& ofs, const uint64_t* values, int dims) | ||
| 293 | +{ | ||
| 294 | + ofs << '['; | ||
| 295 | + for (int i = 0; i < dims; ++i) { | ||
| 296 | + if (i != 0) { | ||
| 297 | + ofs << ';'; | ||
| 298 | + } | ||
| 299 | + ofs << values[i]; | ||
| 300 | + } | ||
| 301 | + ofs << ']'; | ||
| 302 | +} | ||
| 303 | + | ||
| 304 | +uint64_t TensorBaseAddr(const DevAscendFunctionDupped& dup, const DevAscendRawTensor* rawTensor) | ||
| 305 | +{ | ||
| 306 | + if (rawTensor->ioProperty == DevIOProperty::ROOT_INCAST) { | ||
| 307 | + AddressDescriptor desc = dup.GetIncastAddress(rawTensor->ioIndex); | ||
| 308 | + return desc.IsAddress() ? desc.GetAddressValue() : 0ULL; | ||
| 309 | + } | ||
| 310 | + if (rawTensor->ioProperty == DevIOProperty::ROOT_OUTCAST) { | ||
| 311 | + AddressDescriptor desc = dup.GetOutcastAddress(rawTensor->ioIndex); | ||
| 312 | + return desc.IsAddress() ? desc.GetAddressValue() : 0ULL; | ||
| 313 | + } | ||
| 314 | + return dup.RuntimeWorkspace() + rawTensor->addrOffset; | ||
| 315 | +} | ||
| 316 | + | ||
| 317 | +void AppendWorkspaceRow(uint32_t seqNo, uint32_t funcIdx, int rootIndex, uint64_t wsBegin, uint64_t wsEnd) | ||
| 318 | +{ | ||
| 319 | + static std::mutex mu; | ||
| 320 | + static std::ofstream ofs; | ||
| 321 | + static std::string lastPath; | ||
| 322 | + std::lock_guard<std::mutex> lock(mu); | ||
| 323 | + OpenIfPathChanged(ofs, lastPath, GetDepVerifyDumpDir() + "/mem_workspace_range.csv", | ||
| 324 | + "seqNo,funcIdx,rootIndex,wsBegin,wsEnd"); | ||
| 325 | + if (!ofs.is_open()) { | ||
| 326 | + return; | ||
| 327 | + } | ||
| 328 | + ofs << seqNo << ',' << funcIdx << ',' << rootIndex << ',' << wsBegin << ',' << wsEnd << '\n'; | ||
| 329 | +} | ||
| 330 | + | ||
| 331 | +void AppendAccessRow(uint32_t seqNo, uint32_t funcIdx, uint32_t opIdx, uint32_t taskId, int rootIndex, char accessType, | ||
| 332 | + uint64_t base, uint64_t end, const uint64_t* offset, const uint64_t* shape, | ||
| 333 | + const uint64_t* rawShape, int dims, const char* location, bool allConcrete, int rawMagic) | ||
| 334 | +{ | ||
| 335 | + static std::mutex mu; | ||
| 336 | + static std::ofstream ofs; | ||
| 337 | + static std::string lastPath; | ||
| 338 | + std::lock_guard<std::mutex> lock(mu); | ||
| 339 | + OpenIfPathChanged( | ||
| 340 | + ofs, lastPath, GetDepVerifyDumpDir() + "/mem_rawtensor_access.csv", | ||
| 341 | + "seqNo,funcIdx,opIdx,taskId,rootIndex,accessType,base,end,offset,shape,rawShape,location,allConcrete,rawMagic"); | ||
| 342 | + if (!ofs.is_open()) { | ||
| 343 | + return; | ||
| 344 | + } | ||
| 345 | + ofs << seqNo << ',' << funcIdx << ',' << opIdx << ',' << taskId << ',' << rootIndex << ',' << accessType << ',' | ||
| 346 | + << base << ',' << end << ','; | ||
| 347 | + WriteU64List(ofs, offset, dims); | ||
| 348 | + ofs << ','; | ||
| 349 | + WriteU64List(ofs, shape, dims); | ||
| 350 | + ofs << ','; | ||
| 351 | + WriteU64List(ofs, rawShape, dims); | ||
| 352 | + ofs << ',' << location << ',' << (allConcrete ? 1 : 0) << ',' << rawMagic << '\n'; | ||
| 353 | +} | ||
| 354 | + | ||
| 355 | +void DumpOperandAccess(uint32_t seqNo, uint32_t funcIdx, uint32_t opIdx, uint32_t taskId, int rootIndex, | ||
| 356 | + const DevAscendFunctionDupped& dup, DevAscendFunction* func, const uint64_t* exprList, | ||
| 357 | + int operandIndex, bool isIOperand, char accessType) | ||
| 358 | +{ | ||
| 359 | + const DevAscendOperationOperandInfo& info = func->GetOperationOperandInfo(opIdx, operandIndex, isIOperand); | ||
| 360 | + const DevAscendTensor* operand = isIOperand ? func->GetOperationIOperand(opIdx, operandIndex) : | ||
| 361 | + func->GetOperationOOperand(opIdx, operandIndex); | ||
| 362 | + int rawIndex = static_cast<int>(operand->rawIndex); | ||
| 363 | + const DevAscendRawTensor* rawTensor = func->GetRawTensor(rawIndex); | ||
| 364 | + int dims = info.GetDim(); | ||
| 365 | + | ||
| 366 | + uint64_t offset[DEV_SHAPE_DIM_MAX] = {0}; | ||
| 367 | + uint64_t shape[DEV_SHAPE_DIM_MAX] = {0}; | ||
| 368 | + uint64_t rawShape[DEV_SHAPE_DIM_MAX] = {0}; | ||
| 369 | + bool offsetShapeConcrete = GetTensorOffsetAndShape<false>(func, offset, shape, exprList, dims, opIdx, | ||
| 370 | + info.staticOffsetAttrBeginIndex, | ||
| 371 | + info.staticValidShapeAttrBeginIndex); | ||
| 372 | + bool rawShapeConcrete = GetTensorRawShape<false>(func, rawShape, exprList, dims, opIdx, | ||
| 373 | + info.staticRawShapeAttrBeginIndex); | ||
| 374 | + | ||
| 375 | + uint64_t base = TensorBaseAddr(dup, rawTensor); | ||
| 376 | + uint64_t size = rawTensor->GetMemoryRequirement(exprList); | ||
| 377 | + | ||
| 378 | + AppendAccessRow(seqNo, funcIdx, opIdx, taskId, rootIndex, accessType, base, base + size, offset, shape, rawShape, | ||
| 379 | + dims, LocationName(rawTensor->ioProperty), offsetShapeConcrete && rawShapeConcrete, | ||
| 380 | + rawTensor->rawMagic); | ||
| 381 | + RecordTensorOverview(seqNo, funcIdx, rootIndex, rawTensor, base, base + size, LocationName(rawTensor->ioProperty)); | ||
| 382 | +} | ||
| 383 | + | ||
| 384 | +} // namespace | ||
| 385 | + | ||
| 386 | +void DumpMemoryOverview(const DevAscendProgram& devProg, Function* func, uint64_t workspaceSize) | ||
| 387 | +{ | ||
| 388 | + if (!DumpEnabled()) { | ||
| 389 | + return; | ||
| 390 | + } | ||
| 391 | + | ||
| 392 | + const auto& tensor = devProg.memBudget.tensor; | ||
| 393 | + const auto& aicoreSpilled = devProg.memBudget.aicoreSpilled; | ||
| 394 | + const auto& metadata = devProg.memBudget.metadata; | ||
| 395 | + uint64_t outcastCount = tensor.BoundaryAndInnerTemporalOutcastSlotNum(); | ||
| 396 | + uint64_t maxOutcast = tensor.MaxOutcastMem(); | ||
| 397 | + uint64_t tensorBeforeAlignment = tensor.rootInnerSpilledMem + tensor.devTaskInnerExclusiveOutcasts + | ||
| 398 | + maxOutcast * outcastCount; | ||
| 399 | + | ||
| 400 | + LargestRootFunctionSummary largestRootFunction; | ||
| 401 | + if (func != nullptr) { | ||
| 402 | + auto* checker = RebuildableAttributeManager::GetInstance().GetAttr<RebuildableWorkspaceDesc>(func); | ||
| 403 | + const auto& rootList = checker->Get().rootFuncDescList; | ||
| 404 | + auto largestRoot = std::max_element(rootList.begin(), rootList.end(), [](const auto& lhs, const auto& rhs) { | ||
| 405 | + return lhs.rootInnerSpilledRawMem < rhs.rootInnerSpilledRawMem; | ||
| 406 | + }); | ||
| 407 | + if (largestRoot != rootList.end()) { | ||
| 408 | + largestRootFunction.valid = true; | ||
| 409 | + largestRootFunction.name = largestRoot->devFuncName; | ||
| 410 | + largestRootFunction.unroll = largestRoot->unroll; | ||
| 411 | + largestRootFunction.innerSpilledRaw = largestRoot->rootInnerSpilledRawMem; | ||
| 412 | + largestRootFunction.leafSpilled = largestRoot->leafPerCoreSpilledMem; | ||
| 413 | + largestRootFunction.totalOutcastRaw = largestRoot->rootTotalExclusiveOutcastRawMem; | ||
| 414 | + largestRootFunction.staticOutcast = largestRoot->rootMaxExclusiveOutcastMem; | ||
| 415 | + } | ||
| 416 | + } | ||
| 417 | + | ||
| 418 | + std::lock_guard<std::mutex> lock(OverviewMutex()); | ||
| 419 | + MemoryOverviewState& state = OverviewState(); | ||
| 420 | + state = MemoryOverviewState{}; | ||
| 421 | + state.started = true; | ||
| 422 | + state.workspaceSize = workspaceSize; | ||
| 423 | + state.tensorWorkspaceSize = tensor.Total(); | ||
| 424 | + state.metadataSize = metadata.Total(); | ||
| 425 | + | ||
| 426 | + WorkspaceBreakdown& workspace = state.workspaceBreakdown; | ||
| 427 | + workspace.totalBytes = workspaceSize; | ||
| 428 | + workspace.largestRootFunction = largestRootFunction; | ||
| 429 | + workspace.tensor.totalBytes = tensor.Total(); | ||
| 430 | + workspace.tensor.bytesBeforeAlignmentAndParallelism = tensorBeforeAlignment; | ||
| 431 | + workspace.tensor.rootInnerSpilledBytes = tensor.rootInnerSpilledMem; | ||
| 432 | + workspace.tensor.devTaskInnerExclusiveOutcastBytes = tensor.devTaskInnerExclusiveOutcasts; | ||
| 433 | + workspace.tensor.outcastPoolBytes = maxOutcast * outcastCount; | ||
| 434 | + workspace.tensor.maxOutcastBytes = maxOutcast; | ||
| 435 | + workspace.tensor.maxStaticOutcastBytes = tensor.maxStaticOutcastMem; | ||
| 436 | + workspace.tensor.maxDynamicAssembleOutcastBytes = tensor.maxDynamicAssembleOutcastMem; | ||
| 437 | + workspace.tensor.devTaskBoundaryOutcastCount = tensor.devTaskBoundaryOutcastNum; | ||
| 438 | + workspace.tensor.devTaskInnerTemporalOutcastCount = tensor.devTaskInnerTemporalOutcastNum; | ||
| 439 | + workspace.tensor.boundaryAndInnerTemporalOutcastCount = outcastCount; | ||
| 440 | + workspace.tensor.parallelism = tensor.parallelism; | ||
| 441 | + workspace.tensor.slottableOutcastSlotSize = tensor.slottableOutcastSlotSize; | ||
| 442 | + workspace.tensor.memoryDrivenWorkspace = tensor.memoryDrivenWorkspace; | ||
| 443 | + workspace.aicoreSpilled.totalBytes = aicoreSpilled.Total(); | ||
| 444 | + workspace.aicoreSpilled.perCoreBytes = aicoreSpilled.perCoreSpilledMem; | ||
| 445 | + workspace.aicoreSpilled.aicoreCount = aicoreSpilled.aicoreCount; | ||
| 446 | + | ||
| 447 | + MetadataBreakdown& metadataBreakdown = state.metadataBreakdown; | ||
| 448 | + metadataBreakdown.totalBytes = metadata.Total(); | ||
| 449 | + metadataBreakdown.generalBytes = metadata.general; | ||
| 450 | + metadataBreakdown.dynamicCellMatchBytes = metadata.dynamicCellMatch; | ||
| 451 | + metadataBreakdown.stitchPoolBytes = metadata.stitchPool; | ||
| 452 | + metadataBreakdown.maxDynamicCellMatchTableBytes = metadata.maxDynamicCellMatchTableMem; | ||
| 453 | + metadataBreakdown.dynamicCellMatchSlotCount = metadata.dynamicCellMatchSlotNum; | ||
| 454 | + metadataBreakdown.generalSlabSize = metadata.generalSlabSize; | ||
| 455 | + metadataBreakdown.stitchSlabSize = metadata.stitchSlabSize; | ||
| 456 | + WriteOverviewLocked(); | ||
| 457 | +} | ||
| 458 | + | ||
| 459 | +void DumpRootMemory(uint32_t seqNo, uint32_t funcIdx, const DevAscendFunctionDupped& dup) | ||
| 460 | +{ | ||
| 461 | + if (!DumpEnabled()) { | ||
| 462 | + return; | ||
| 463 | + } | ||
| 464 | + DevAscendFunction* func = const_cast<DevAscendFunction*>(dup.GetSource()); | ||
| 465 | + const uint64_t* exprList = dup.GetExpressionAddr(); | ||
| 466 | + int rootIndex = func->GetRootIndex(); | ||
| 467 | + | ||
| 468 | + uint64_t wsBegin = dup.RuntimeWorkspace(); | ||
| 469 | + uint64_t wsEnd = wsBegin + func->rootInnerTensorWsMemoryRequirement; | ||
| 470 | + AppendWorkspaceRow(seqNo, funcIdx, rootIndex, wsBegin, wsEnd); | ||
| 471 | + | ||
| 472 | + uint32_t operationSize = dup.GetOperationSize(); | ||
| 473 | + for (uint32_t opIdx = 0; opIdx < operationSize; ++opIdx) { | ||
| 474 | + uint32_t taskId = (funcIdx << 16) | (opIdx & 0xffffU); | ||
| 475 | + size_t iOperandSize = func->GetOperationIOperandSize(opIdx); | ||
| 476 | + for (size_t i = 0; i < iOperandSize; ++i) { | ||
| 477 | + DumpOperandAccess(seqNo, funcIdx, opIdx, taskId, rootIndex, dup, func, exprList, static_cast<int>(i), | ||
| 478 | + /*isIOperand=*/true, 'R'); | ||
| 479 | + } | ||
| 480 | + size_t oOperandSize = func->GetOperationOOperandSize(opIdx); | ||
| 481 | + for (size_t i = 0; i < oOperandSize; ++i) { | ||
| 482 | + DumpOperandAccess(seqNo, funcIdx, opIdx, taskId, rootIndex, dup, func, exprList, static_cast<int>(i), | ||
| 483 | + /*isIOperand=*/false, 'W'); | ||
| 484 | + } | ||
| 485 | + } | ||
| 486 | + FlushOverview(); | ||
| 487 | +} | ||
| 488 | + | ||
| 489 | +#else // __DEVICE__ | ||
| 490 | + | ||
| 491 | +void DumpMemoryOverview(const DevAscendProgram&, Function*, uint64_t) {} | ||
| 492 | + | ||
| 493 | +void DumpRootMemory(uint32_t, uint32_t, const DevAscendFunctionDupped&) {} | ||
| 494 | + | ||
| 495 | +#endif // __DEVICE__ | ||
| 496 | + | ||
| 497 | +} // namespace npu::tile_fwk::dynamic::mem_dump | ||
| @@ -0,0 +1,31 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#pragma once | ||
| 12 | + | ||
| 13 | +#include <cstdint> | ||
| 14 | + | ||
| 15 | +#include "machine/utils/dynamic/dev_encode_function_dupped_data.h" | ||
| 16 | + | ||
| 17 | +namespace npu::tile_fwk { | ||
| 18 | +class Function; | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +namespace npu::tile_fwk::dynamic { | ||
| 22 | +struct DevAscendProgram; | ||
| 23 | + | ||
| 24 | +namespace mem_dump { | ||
| 25 | + | ||
| 26 | +void DumpMemoryOverview(const DevAscendProgram& devProg, Function* func, uint64_t workspaceSize); | ||
| 27 | + | ||
| 28 | +void DumpRootMemory(uint32_t seqNo, uint32_t funcIdx, const DevAscendFunctionDupped& dup); | ||
| 29 | + | ||
| 30 | +} // namespace mem_dump | ||
| 31 | +} // namespace npu::tile_fwk::dynamic | ||
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | #include "machine/device/dynamic/context/device_task_context.h" | 16 | #include "machine/device/dynamic/context/device_task_context.h" |
| 17 | #include "machine/device/dynamic/eslmodel_aicore_hal.h" | 17 | #include "machine/device/dynamic/eslmodel_aicore_hal.h" |
| 18 | +#include "machine/device/dump/dump_device_memory.h" | ||
| 18 | #ifndef __DEVICE__ | 19 | #ifndef __DEVICE__ |
| 19 | #include "interface/configs/config_manager.h" | 20 | #include "interface/configs/config_manager.h" |
| 20 | #endif | 21 | #endif |
| @@ -318,6 +319,7 @@ int DeviceTaskContext::BuildDynFuncData(DynDeviceTask* dyntask, uint32_t taskId, | |||
| 318 | rootFuncNum += stitchedSize; | 319 | rootFuncNum += stitchedSize; |
| 319 | for (size_t funcIdx = 0; funcIdx < stitchedSize; ++funcIdx) { | 320 | for (size_t funcIdx = 0; funcIdx < stitchedSize; ++funcIdx) { |
| 320 | FillOneDynFuncData(dyndata, stitchedList[funcIdx], startArgs_, workspace_, leafFuncDataSize, leafFuncNum); | 321 | FillOneDynFuncData(dyndata, stitchedList[funcIdx], startArgs_, workspace_, leafFuncDataSize, leafFuncNum); |
| 322 | + DEV_IF_NONDEVICE { mem_dump::DumpRootMemory(taskId, static_cast<uint32_t>(funcIdx), stitchedList[funcIdx]); } | ||
| 321 | dyndata++; | 323 | dyndata++; |
| 322 | } | 324 | } |
| 323 | dynFuncDataSize += headerSize * sizeof(int64_t); | 325 | dynFuncDataSize += headerSize * sizeof(int64_t); |
| @@ -20,7 +20,7 @@ | |||
| 20 | #include <string> | 20 | #include <string> |
| 21 | #include <vector> | 21 | #include <vector> |
| 22 | #include "interface/configs/config_manager.h" | 22 | #include "interface/configs/config_manager.h" |
| 23 | -#include "utils/file_utils.h" | 23 | +#include "machine/utils/dep_verify_dump_path.h" |
| 24 | #include "machine/utils/dynamic/dev_encode_function_stitch.h" | 24 | #include "machine/utils/dynamic/dev_encode_function_stitch.h" |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| @@ -29,18 +29,6 @@ namespace npu::tile_fwk::dynamic::topo_dump { | |||
| 29 | #ifndef __DEVICE__ | 29 | #ifndef __DEVICE__ |
| 30 | namespace { | 30 | namespace { |
| 31 | 31 | ||
| 32 | -constexpr const char* DeviceVerifyDumpSubDir = "dep_verify_dump"; | ||
| 33 | - | ||
| 34 | -const std::string& DeviceDepVerifyDumpDir() | ||
| 35 | -{ | ||
| 36 | - static const std::string dir = []() { | ||
| 37 | - std::string d = config::LogTopFolder() + "/" + DeviceVerifyDumpSubDir; | ||
| 38 | - (void)CreateDir(d); | ||
| 39 | - return d; | ||
| 40 | - }(); | ||
| 41 | - return dir; | ||
| 42 | -} | ||
| 43 | - | ||
| 44 | void OpenIfPathChanged(std::ofstream& ofs, std::string& lastPath, const std::string& path, const char* header) | 32 | void OpenIfPathChanged(std::ofstream& ofs, std::string& lastPath, const std::string& path, const char* header) |
| 45 | { | 33 | { |
| 46 | if (path == lastPath) { | 34 | if (path == lastPath) { |
| @@ -92,7 +80,7 @@ void AppendSlotAccessRow(uint32_t seqNo, int slotIdx, uint32_t funcIdx, uint32_t | |||
| 92 | static std::ofstream ofs; | 80 | static std::ofstream ofs; |
| 93 | static std::string lastPath; | 81 | static std::string lastPath; |
| 94 | std::lock_guard<std::mutex> lock(mu); | 82 | std::lock_guard<std::mutex> lock(mu); |
| 95 | - OpenIfPathChanged(ofs, lastPath, DeviceDepVerifyDumpDir() + "/dyn_slot_access.csv", | 83 | + OpenIfPathChanged(ofs, lastPath, GetDepVerifyDumpDir() + "/dyn_slot_access.csv", |
| 96 | "seqNo,slotIdx,funcIdx,opIdx,taskId,accessType,cellIdxList,allConcrete"); | 84 | "seqNo,slotIdx,funcIdx,opIdx,taskId,accessType,cellIdxList,allConcrete"); |
| 97 | if (!ofs.is_open()) { | 85 | if (!ofs.is_open()) { |
| 98 | return; | 86 | return; |
| @@ -160,7 +148,7 @@ void DumpStitchEdge(const DevAscendFunctionDupped& producerDup, const DevAscendF | |||
| 160 | static std::ofstream ofs; | 148 | static std::ofstream ofs; |
| 161 | static std::string lastPath; | 149 | static std::string lastPath; |
| 162 | std::lock_guard<std::mutex> lock(mu); | 150 | std::lock_guard<std::mutex> lock(mu); |
| 163 | - OpenIfPathChanged(ofs, lastPath, DeviceDepVerifyDumpDir() + "/dyn_stitch_edges.csv", | 151 | + OpenIfPathChanged(ofs, lastPath, GetDepVerifyDumpDir() + "/dyn_stitch_edges.csv", |
| 164 | "stitchKind,slotIdx," | 152 | "stitchKind,slotIdx," |
| 165 | "producerFuncKey,producerFuncIdx,producerOpIdx,producerTaskId," | 153 | "producerFuncKey,producerFuncIdx,producerOpIdx,producerTaskId," |
| 166 | "consumerFuncKey,consumerFuncIdx,consumerOpIdx,consumerTaskId"); | 154 | "consumerFuncKey,consumerFuncIdx,consumerOpIdx,consumerTaskId"); |
| @@ -982,8 +982,7 @@ static void CompileDyndevFunction(Function* function, FunctionCache& cache, [[ma | |||
| 982 | { | 982 | { |
| 983 | ASSERT(HostBackEndErr::RUN_PASS_FAILED, | 983 | ASSERT(HostBackEndErr::RUN_PASS_FAILED, |
| 984 | (PassManager::Instance().RunPass(Program::GetInstance(), *function, "ExecuteGraph") == SUCCESS)); | 984 | (PassManager::Instance().RunPass(Program::GetInstance(), *function, "ExecuteGraph") == SUCCESS)); |
| 985 | - if (Platform::Instance().GetSoc().GetNPUArch() == NPUArch::DAV_3510 && | 985 | + if (Platform::Instance().GetSoc().GetNPUArch() == NPUArch::DAV_3510 && config::IsRuntimeDebugAllEnabled()) { |
| 986 | - config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_DEBUG_ALL) { | ||
| 987 | mix_info::DumpMixInfo(function); | 986 | mix_info::DumpMixInfo(function); |
| 988 | } | 987 | } |
| 989 | std::shared_ptr<DyndevFunctionAttribute> attr = function->GetDyndevAttribute(); | 988 | std::shared_ptr<DyndevFunctionAttribute> attr = function->GetDyndevAttribute(); |
| @@ -24,8 +24,8 @@ | |||
| 24 | #include "interface/configs/config_manager.h" | 24 | #include "interface/configs/config_manager.h" |
| 25 | #include "interface/function/function.h" | 25 | #include "interface/function/function.h" |
| 26 | #include "interface/tensor/tensor_slot.h" | 26 | #include "interface/tensor/tensor_slot.h" |
| 27 | -#include "utils/file_utils.h" | ||
| 28 | #include "interface/utils/string_utils.h" | 27 | #include "interface/utils/string_utils.h" |
| 28 | +#include "machine/utils/dep_verify_dump_path.h" | ||
| 29 | #include "machine/utils/dynamic/dev_encode_function.h" | 29 | #include "machine/utils/dynamic/dev_encode_function.h" |
| 30 | #include "machine/utils/dynamic/dev_encode_operation.h" | 30 | #include "machine/utils/dynamic/dev_encode_operation.h" |
| 31 | #include "machine/utils/dynamic/dev_encode_tensor.h" | 31 | #include "machine/utils/dynamic/dev_encode_tensor.h" |
| @@ -34,17 +34,6 @@ | |||
| 34 | namespace npu::tile_fwk::topo_dump { | 34 | namespace npu::tile_fwk::topo_dump { |
| 35 | namespace { | 35 | namespace { |
| 36 | 36 | ||
| 37 | -constexpr const char* kDepVerifyDumpSubDir = "dep_verify_dump"; | ||
| 38 | -const std::string& DepVerifyDumpDir() | ||
| 39 | -{ | ||
| 40 | - static const std::string dir = []() { | ||
| 41 | - std::string d = config::LogTopFolder() + "/" + kDepVerifyDumpSubDir; | ||
| 42 | - (void)CreateDir(d); | ||
| 43 | - return d; | ||
| 44 | - }(); | ||
| 45 | - return dir; | ||
| 46 | -} | ||
| 47 | - | ||
| 48 | inline bool DumpEnabled() | 37 | inline bool DumpEnabled() |
| 49 | { | 38 | { |
| 50 | static const bool cached = (config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_RUNTIME_DEBUG_VERIFY); | 39 | static const bool cached = (config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_RUNTIME_DEBUG_VERIFY); |
| @@ -74,7 +63,7 @@ std::ofstream OpenCsv(const std::string& fileName, std::initializer_list<const c | |||
| 74 | if (!enabled) { | 63 | if (!enabled) { |
| 75 | return ofs; | 64 | return ofs; |
| 76 | } | 65 | } |
| 77 | - outPath = DepVerifyDumpDir() + "/" + fileName; | 66 | + outPath = GetDepVerifyDumpDir() + "/" + fileName; |
| 78 | ofs.open(outPath); | 67 | ofs.open(outPath); |
| 79 | if (!ofs.is_open()) { | 68 | if (!ofs.is_open()) { |
| 80 | return ofs; | 69 | return ofs; |
| @@ -167,7 +156,7 @@ void DumpSlotMapping(const TensorSlotManager& slotManager, const std::unordered_ | |||
| 167 | << ',' << CsvQuote(feSlotToFuncName[slot.first]) << '\n'; | 156 | << ',' << CsvQuote(feSlotToFuncName[slot.first]) << '\n'; |
| 168 | } | 157 | } |
| 169 | 158 | ||
| 170 | - const std::string path = DepVerifyDumpDir() + "/slot_mapping.csv"; | 159 | + const std::string path = GetDepVerifyDumpDir() + "/slot_mapping.csv"; |
| 171 | std::ofstream ofs(path); | 160 | std::ofstream ofs(path); |
| 172 | if (!ofs.is_open()) { | 161 | if (!ofs.is_open()) { |
| 173 | return; | 162 | return; |
| @@ -70,7 +70,7 @@ int DeviceLauncher::SetCaptureStream(RtStream aicoreStream, RtStream aicpuStream | |||
| 70 | 70 | ||
| 71 | int DeviceLauncher::RunWithProfile(RtStream aicoreStream, RtStream aicpuStream, bool isCapture) | 71 | int DeviceLauncher::RunWithProfile(RtStream aicoreStream, RtStream aicpuStream, bool isCapture) |
| 72 | { | 72 | { |
| 73 | - if (config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_DEBUG_ALL) { | 73 | + if (config::IsRuntimeDebugAllEnabled()) { |
| 74 | if (isCapture) { | 74 | if (isCapture) { |
| 75 | MACHINE_LOGW("The swimlane function is not currently supported in CaptureMode. The contents of " | 75 | MACHINE_LOGW("The swimlane function is not currently supported in CaptureMode. The contents of " |
| 76 | "tilefwk_L1_prof_data may be empty."); | 76 | "tilefwk_L1_prof_data may be empty."); |
| @@ -254,8 +254,7 @@ public: | |||
| 254 | if (config::GetPlatformConfig(KEY_ENABLE_PROF_FUNC, false)) { | 254 | if (config::GetPlatformConfig(KEY_ENABLE_PROF_FUNC, false)) { |
| 255 | toSubMachineConfig.profConfig.Add(ProfConfig::AICPU_FUNC); | 255 | toSubMachineConfig.profConfig.Add(ProfConfig::AICPU_FUNC); |
| 256 | } | 256 | } |
| 257 | - if (config::GetPlatformConfig(KEY_ENABLE_PROF_AICORE_TIME, false) || | 257 | + if (config::GetPlatformConfig(KEY_ENABLE_PROF_AICORE_TIME, false) || config::IsRuntimeDebugAllEnabled()) { |
| 258 | - config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_DEBUG_ALL) { | ||
| 259 | toSubMachineConfig.profConfig.Add(ProfConfig::AICORE_TIME); | 258 | toSubMachineConfig.profConfig.Add(ProfConfig::AICORE_TIME); |
| 260 | } | 259 | } |
| 261 | if (config::GetPlatformConfig(KEY_ENABLE_PROF_AICORE_PMU, false)) { | 260 | if (config::GetPlatformConfig(KEY_ENABLE_PROF_AICORE_PMU, false)) { |
| @@ -129,7 +129,7 @@ DevMemoryPool& DevMemoryPool::Instance() | |||
| 129 | 129 | ||
| 130 | DevMemoryPool::DevMemoryPool() | 130 | DevMemoryPool::DevMemoryPool() |
| 131 | { | 131 | { |
| 132 | - needMemCheck_ = (config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_DEBUG_ALL); | 132 | + needMemCheck_ = config::IsRuntimeDebugAllEnabled(); |
| 133 | sentinelVec_ = std::vector<uint64_t>(SENTINEL_NUM, SENTINEL_VALUE); | 133 | sentinelVec_ = std::vector<uint64_t>(SENTINEL_NUM, SENTINEL_VALUE); |
| 134 | } | 134 | } |
| 135 | 135 | ||
| @@ -113,7 +113,7 @@ void DevicePerf::SetDebugEnable() | |||
| 113 | bool DevicePerf::RunPrepare() const | 113 | bool DevicePerf::RunPrepare() const |
| 114 | { | 114 | { |
| 115 | bool ret = true; | 115 | bool ret = true; |
| 116 | - if (config::GetDebugOption<int64_t>(CFG_RUNTIME_DBEUG_MODE) == CFG_DEBUG_ALL || ENABLE_PERF_TRACE) { | 116 | + if (config::IsRuntimeDebugAllEnabled() || ENABLE_PERF_TRACE) { |
| 117 | for (uint32_t i = 0; i < GetPerfDataSize(); i++) { | 117 | for (uint32_t i = 0; i < GetPerfDataSize(); i++) { |
| 118 | ret = RuntimeMemcpyDirect( | 118 | ret = RuntimeMemcpyDirect( |
| 119 | (reinterpret_cast<uint8_t*>(args_.sharedBuffer + sizeof(uint64_t) * SHAK_BUF_DFX_DATA_INDEX)) + | 119 | (reinterpret_cast<uint8_t*>(args_.sharedBuffer + sizeof(uint64_t) * SHAK_BUF_DFX_DATA_INDEX)) + |
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "tilefwk/pypto_fwk_log.h" | 21 | #include "tilefwk/pypto_fwk_log.h" |
| 22 | #include "tilefwk/error_code.h" | 22 | #include "tilefwk/error_code.h" |
| 23 | #include "interface/function/rebuildable_attribute.h" | 23 | #include "interface/function/rebuildable_attribute.h" |
| 24 | +#include "machine/device/dump/dump_device_memory.h" | ||
| 24 | #include "machine/runtime/launcher/cell_match_dynamic.h" | 25 | #include "machine/runtime/launcher/cell_match_dynamic.h" |
| 25 | #include "machine/runtime/launcher/device_launcher.h" | 26 | #include "machine/runtime/launcher/device_launcher.h" |
| 26 | #include "machine/runtime/launcher/device_launcher_binding.h" | 27 | #include "machine/runtime/launcher/device_launcher_binding.h" |
| @@ -171,6 +172,7 @@ int64_t KernelBinary::GetWorkspaceSize(const std::vector<DeviceTensorData>& tens | |||
| 171 | MACHINE_ASSERT(uint64_t(workspaceSize) == | 172 | MACHINE_ASSERT(uint64_t(workspaceSize) == |
| 172 | wsChecker->GetSizeForCheckOnly(devProg->memBudget.tensor.maxDynamicAssembleOutcastMem, | 173 | wsChecker->GetSizeForCheckOnly(devProg->memBudget.tensor.maxDynamicAssembleOutcastMem, |
| 173 | devProg->memBudget.debug.Total())); | 174 | devProg->memBudget.debug.Total())); |
| 175 | + mem_dump::DumpMemoryOverview(*devProg, dynFunc.get(), static_cast<uint64_t>(workspaceSize)); | ||
| 174 | } | 176 | } |
| 175 | return workspaceSize; | 177 | return workspaceSize; |
| 176 | } | 178 | } |
| @@ -0,0 +1,28 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#pragma once | ||
| 12 | + | ||
| 13 | +#include <string> | ||
| 14 | + | ||
| 15 | +#include "interface/configs/config_manager.h" | ||
| 16 | +#include "utils/file_utils.h" | ||
| 17 | + | ||
| 18 | +namespace npu::tile_fwk { | ||
| 19 | + | ||
| 20 | +inline std::string GetDepVerifyDumpDir() | ||
| 21 | +{ | ||
| 22 | + constexpr const char* kDepVerifyDumpSubDir = "dep_verify_dump"; | ||
| 23 | + std::string dir = config::LogTopFolder() + "/" + kDepVerifyDumpSubDir; | ||
| 24 | + (void)CreateDir(dir); | ||
Major: GetDepVerifyDumpDir() 每次调用都执行 CreateDir 系统调用,未缓存 原始代码(dump_device_topo.cpp / dump_host_topo.cpp)使用 该函数在 ![]() ![]() | |||
| 25 | + return dir; | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +} // namespace npu::tile_fwk | ||
| @@ -66,7 +66,7 @@ def test_getval_setval(): | |||
| 66 | torch.npu.synchronize() | 66 | torch.npu.synchronize() |
| 67 | # a[0,1] 应被写成原 a[0,0] | 67 | # a[0,1] 应被写成原 a[0,0] |
| 68 | assert abs(a[0, 1].item() - a_orig_00) < 1e-3, \ | 68 | assert abs(a[0, 1].item() - a_orig_00) < 1e-3, \ |
| 69 | - f"getval/setval failed: a[0,1]={a[0,1].item()}, expect {a_orig_00}" | 69 | + f"getval/setval failed: a[0,1]={a[0, 1].item()}, expect {a_orig_00}" |
| 70 | logging.info("tile getval/setval result equal!") | 70 | logging.info("tile getval/setval result equal!") |
| 71 | 71 | ||
| 72 | 72 | ||
| @@ -152,7 +152,7 @@ def test_tensor_getval_setval(): | |||
| 152 | torch.npu.synchronize() | 152 | torch.npu.synchronize() |
| 153 | 153 | ||
| 154 | assert abs(tensor5d[1, 1, 1, 1, 1].item() - val_5d) < 1e-6, \ | 154 | assert abs(tensor5d[1, 1, 1, 1, 1].item() - val_5d) < 1e-6, \ |
| 155 | - f"5D tensor setval failed: tensor5d[1,1,1,1,1]={tensor5d[1,1,1,1,1].item()}, expect {val_5d}" | 155 | + f"5D tensor setval failed: tensor5d[1,1,1,1,1]={tensor5d[1, 1, 1, 1, 1].item()}, expect {val_5d}" |
| 156 | logging.info("5D tensor getval/setval result equal!") | 156 | logging.info("5D tensor getval/setval result equal!") |
| 157 | 157 | ||
| 158 | 158 | ||
Rtools/dep_verifier/rules/rule_cell_write_conflict.py→tools/runtime_verifier/dep_verifier/rules/rule_cell_write_conflict.py+0-0
File renamed without changes.
Rtools/dep_verifier/rules/rule_static_integrity.py→tools/runtime_verifier/dep_verifier/rules/rule_static_integrity.py+0-0
File renamed without changes.
Rtools/dep_verifier/rules/rule_stitch_legality.py→tools/runtime_verifier/dep_verifier/rules/rule_stitch_legality.py+0-0
File renamed without changes.
| @@ -0,0 +1,655 @@ | |||
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# coding: utf-8 | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the LICENSE. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | +"""基于 controlflow 内存 dump 和 dyn_topo 的离线内存重叠检查。 | ||
| 12 | + | ||
| 13 | +只需要传入一次运行的 output 目录。脚本不依赖 profiling/swimlane 时间: | ||
| 14 | +同一 DeviceTask 内,dyn_topo 上互相不可达的两个 Op 视为可能并发,然后检查 | ||
| 15 | +Read-Write 和 Write-Write Operand 的物理地址及各维访问范围。 | ||
| 16 | +""" | ||
| 17 | + | ||
| 18 | +import argparse | ||
| 19 | +from collections import Counter, defaultdict | ||
| 20 | +import csv | ||
| 21 | +from dataclasses import dataclass | ||
| 22 | +import logging | ||
| 23 | +import os | ||
| 24 | +import sys | ||
| 25 | +from typing import Dict, List, Optional, Set, Tuple | ||
| 26 | + | ||
| 27 | +DYN_TOPO_NAME = "dyn_topo.txt" | ||
| 28 | +ACCESS_CSV_NAME = "mem_rawtensor_access.csv" | ||
| 29 | +TASK_OP_BITS = 16 | ||
| 30 | +SEPARATOR = "=" * 100 | ||
| 31 | + | ||
| 32 | + | ||
| 33 | +@dataclass(frozen=True, order=True) | ||
| 34 | +class TaskKey: | ||
| 35 | + seq_no: int | ||
| 36 | + task_id: int | ||
| 37 | + | ||
| 38 | + | ||
| 39 | +@dataclass | ||
| 40 | +class TopoTask: | ||
| 41 | + key: TaskKey | ||
| 42 | + root_index: int | ||
| 43 | + root_hash: str | ||
| 44 | + opmagic: int | ||
| 45 | + leaf_index: int | ||
| 46 | + leaf_hash: str | ||
| 47 | + core_type: int | ||
| 48 | + psg_id: int | ||
| 49 | + wrap_id: int | ||
| 50 | + successors: List[int] | ||
| 51 | + | ||
| 52 | + | ||
| 53 | +@dataclass | ||
| 54 | +class Access: | ||
| 55 | + row_number: int | ||
| 56 | + seq_no: int | ||
| 57 | + func_idx: int | ||
| 58 | + op_idx: int | ||
| 59 | + task_id: int | ||
| 60 | + root_index: int | ||
| 61 | + access_type: str | ||
| 62 | + operand_index: int | ||
| 63 | + base: int | ||
| 64 | + end: int | ||
| 65 | + offset: List[int] | ||
| 66 | + shape: List[int] | ||
| 67 | + raw_shape: Optional[List[int]] | ||
| 68 | + location: str | ||
| 69 | + all_concrete: bool | ||
| 70 | + raw_magic: Optional[int] | ||
| 71 | + | ||
| 72 | + @property | ||
| 73 | + def key(self) -> TaskKey: | ||
| 74 | + return TaskKey(self.seq_no, self.task_id) | ||
| 75 | + | ||
| 76 | + @property | ||
| 77 | + def is_write(self) -> bool: | ||
| 78 | + return self.access_type == "W" | ||
| 79 | + | ||
| 80 | + @property | ||
| 81 | + def operand_name(self) -> str: | ||
| 82 | + kind = "outputOperand" if self.is_write else "inputOperand" | ||
| 83 | + return f"{kind}[{self.operand_index}]" | ||
| 84 | + | ||
| 85 | + | ||
| 86 | +@dataclass | ||
| 87 | +class Conflict: | ||
| 88 | + race_kind: str | ||
| 89 | + overlap_kind: str | ||
| 90 | + src: Access | ||
| 91 | + dst: Access | ||
| 92 | + src_topo: TopoTask | ||
| 93 | + dst_topo: TopoTask | ||
| 94 | + | ||
| 95 | + | ||
| 96 | +def _parse_int_list(value: str) -> List[int]: | ||
| 97 | + text = (value or "").strip().strip('"') | ||
| 98 | + if text.startswith("[") and text.endswith("]"): | ||
| 99 | + text = text[1:-1] | ||
| 100 | + if not text: | ||


这个为什么不能用 WorkspaceDesc ?