Merged
fix(dfx): Add memory events and change moduleid to PyPTO. 9.2.0 #6225
meiqing2Add on Sep 12
fix(dfx): Add memory events and change moduleid to PyPTO. 9.2.0 #6225
Merged
Merged frommeiqing2/pypto_3306mtr9.2.0intocann/pypto9.2.0
Total: 7 files changed+12-14
| @@ -374,7 +374,7 @@ uint8_t* DeviceLauncher::CopyControlFlowCache(DevControlFlowCache* ctrlCache) | |||
| 374 | auto cacheSize = ctrlCache->usedCacheSize; | 374 | auto cacheSize = ctrlCache->usedCacheSize; |
| 375 | auto bufNum = DEFAULT_RUNTIME_DATA_RING_BUFFER_COUNT; | 375 | auto bufNum = DEFAULT_RUNTIME_DATA_RING_BUFFER_COUNT; |
| 376 | 376 | ||
| 377 | - int ret = RuntimeMalloc((void**)&devCache, cacheSize * bufNum, RT_MEMORY_HBM, 0); | 377 | + int ret = RuntimeMalloc((void**)&devCache, cacheSize * bufNum, RT_MEMORY_HBM, PYPTO); |
| 378 | if (devCache == nullptr) { | 378 | if (devCache == nullptr) { |
| 379 | MACHINE_LOGE(RtErr::RT_MALLOC_FAILED, "control flow cache malloc failed"); | 379 | MACHINE_LOGE(RtErr::RT_MALLOC_FAILED, "control flow cache malloc failed"); |
| 380 | return nullptr; | 380 | return nullptr; |
| @@ -31,13 +31,13 @@ struct DeviceMemoryUtils { | |||
| 31 | if (isUseHugePage_) { | 31 | if (isUseHugePage_) { |
| 32 | DevMemoryPool::Instance().AllocDevAddr(&devPtr, size); | 32 | DevMemoryPool::Instance().AllocDevAddr(&devPtr, size); |
| 33 | } else { | 33 | } else { |
| 34 | - RuntimeMalloc((void**)&devPtr, size, RT_MEMORY_HBM, 0); | 34 | + RuntimeMalloc((void**)&devPtr, size, RT_MEMORY_HBM, PYPTO); |
| 35 | } | 35 | } |
| 36 | } else if (*cachedDevAddrHolder == nullptr) { | 36 | } else if (*cachedDevAddrHolder == nullptr) { |
| 37 | if (isUseHugePage_) { | 37 | if (isUseHugePage_) { |
| 38 | DevMemoryPool::Instance().AllocDevAddr(&devPtr, size); | 38 | DevMemoryPool::Instance().AllocDevAddr(&devPtr, size); |
| 39 | } else { | 39 | } else { |
| 40 | - RuntimeMalloc((void**)&devPtr, size, RT_MEMORY_HBM, 0); | 40 | + RuntimeMalloc((void**)&devPtr, size, RT_MEMORY_HBM, PYPTO); |
| 41 | } | 41 | } |
| 42 | *cachedDevAddrHolder = devPtr; | 42 | *cachedDevAddrHolder = devPtr; |
| 43 | } else { | 43 | } else { |
| @@ -71,7 +71,7 @@ struct EslModelMemoryUtils { | |||
| 71 | if (isUseHugePage_) { | 71 | if (isUseHugePage_) { |
| 72 | DevMemoryPool::Instance().AllocDevAddr(&devPtr, size); | 72 | DevMemoryPool::Instance().AllocDevAddr(&devPtr, size); |
| 73 | } else { | 73 | } else { |
| 74 | - RuntimeMalloc((void**)&devPtr, size, RT_MEMORY_HBM, 0); | 74 | + RuntimeMalloc((void**)&devPtr, size, RT_MEMORY_HBM, PYPTO); |
| 75 | } | 75 | } |
| 76 | if (cachedDevAddrHolder != nullptr && *cachedDevAddrHolder == nullptr) { | 76 | if (cachedDevAddrHolder != nullptr && *cachedDevAddrHolder == nullptr) { |
| 77 | *cachedDevAddrHolder = devPtr; | 77 | *cachedDevAddrHolder = devPtr; |
| @@ -37,7 +37,7 @@ int AicorePrintHostManager::Init(const DeviceArgs& args) | |||
| 37 | } | 37 | } |
| 38 | for (uint32_t i = 0; i < numCores_; i++) { | 38 | for (uint32_t i = 0; i < numCores_; i++) { |
| 39 | void* devPtr = nullptr; | 39 | void* devPtr = nullptr; |
| 40 | - if (RuntimeMalloc(&devPtr, PRINT_BUFFER_SIZE, RT_MEMORY_HBM, 0) != RT_SUCCESS) { | 40 | + if (RuntimeMalloc(&devPtr, PRINT_BUFFER_SIZE, RT_MEMORY_HBM, PYPTO) != RT_SUCCESS) { |
| 41 | MACHINE_LOGE(DevCommonErr::ALLOC_FAILED, "Failed to alloc aicore print buffer, size=%lu bytes, coreId=%u", | 41 | MACHINE_LOGE(DevCommonErr::ALLOC_FAILED, "Failed to alloc aicore print buffer, size=%lu bytes, coreId=%u", |
| 42 | PRINT_BUFFER_SIZE, i); | 42 | PRINT_BUFFER_SIZE, i); |
| 43 | Release(); | 43 | Release(); |
| @@ -21,8 +21,6 @@ | |||
| 21 | #include "interface/utils/common.h" | 21 | #include "interface/utils/common.h" |
| 22 | #include "passes/pass_utils/pass_utils.h" | 22 | #include "passes/pass_utils/pass_utils.h" |
| 23 | 23 | ||
| 24 | -#define CCECPU 25 | ||
| 25 | - | ||
| 26 | namespace npu::tile_fwk { | 24 | namespace npu::tile_fwk { |
| 27 | namespace { | 25 | namespace { |
| 28 | const std::string kOpType = "PyPTO"; | 26 | const std::string kOpType = "PyPTO"; |
| @@ -91,7 +89,7 @@ int32_t HostProf::HostProfInit(uint32_t type, void* data, uint32_t len) | |||
| 91 | return 0; | 89 | return 0; |
| 92 | } | 90 | } |
| 93 | 91 | ||
| 94 | -void HostProf::RegHostProf() { MspfRegisterCallback(CCECPU, HostProfInit); } | 92 | +void HostProf::RegHostProf() { MspfRegisterCallback(PYPTO, HostProfInit); } |
| 95 | 93 | ||
| 96 | bool HostProf::HostProfReportApi(const uint64_t& startTime, const uint64_t& endTime) const | 94 | bool HostProf::HostProfReportApi(const uint64_t& startTime, const uint64_t& endTime) const |
| 97 | { | 95 | { |
| @@ -348,11 +348,6 @@ class JitCallableWrapper: | |||
| 348 | """ | 348 | """ |
| 349 | return self._handler | 349 | return self._handler |
| 350 | 350 | ||
| 351 | - @staticmethod | ||
| 352 | - def alloc(size): | ||
| 353 | - """Allocate NPU int8 memory and return its data pointer""" | ||
| 354 | - return torch.empty(size, dtype=torch.int8, device='npu').data_ptr() | ||
| 355 | - | ||
| 356 | @staticmethod | 351 | @staticmethod |
| 357 | def _validate_exact_torch_tensors(tensors: list) -> None: | 352 | def _validate_exact_torch_tensors(tensors: list) -> None: |
| 358 | dtensor_type = get_dtensor_type() | 353 | dtensor_type = get_dtensor_type() |
| @@ -1129,6 +1124,11 @@ class JitCallableWrapper: | |||
| 1129 | """ | 1124 | """ |
| 1130 | _cost_model_run_once_data_from_host(in_tensors, out_tensors) | 1125 | _cost_model_run_once_data_from_host(in_tensors, out_tensors) |
| 1131 | 1126 | ||
| 1127 | + def _alloc(self, size: int) -> int: | ||
| 1128 | + """Allocate NPU int8 memory and return its data pointer""" | ||
| 1129 | + with torch.autograd.profiler.record_function(f"PyPTO_{self._original_func.__name__}"): | ||
| 1130 | + return torch.empty(size, dtype=torch.int8, device='npu').data_ptr() | ||
| 1131 | + | ||
| 1132 | 1132 | ||
| 1133 | def function( | 1133 | def function( |
| 1134 | func: Optional[Callable] = None, | 1134 | func: Optional[Callable] = None, |
| @@ -694,7 +694,7 @@ private: | |||
| 694 | int64_t* wsAddr = nullptr; | 694 | int64_t* wsAddr = nullptr; |
| 695 | int64_t wsSize = kmodule->GetWorkspaceSize(kbinary, tensors); | 695 | int64_t wsSize = kmodule->GetWorkspaceSize(kbinary, tensors); |
| 696 | if (wsSize) { | 696 | if (wsSize) { |
| 697 | - auto pyalloc = py::getattr(module, "alloc"); | 697 | + auto pyalloc = py::getattr(module, "_alloc"); |
| 698 | wsAddr = (int64_t*)pyalloc(wsSize).cast<int64_t>(); | 698 | wsAddr = (int64_t*)pyalloc(wsSize).cast<int64_t>(); |
| 699 | } | 699 | } |
| 700 | COMPILER_LOGD("alloc workspace %ld bytes", wsSize); | 700 | COMPILER_LOGD("alloc workspace %ld bytes", wsSize); |