Merged
aclnn手写框架支持按算子级上报profiling #934
ren-botaoAdd on Sep 24
aclnn手写框架支持按算子级上报profiling #934
Merged
Merged fromren-botao/opbasemsprof_optypeintocann/opbasemaster
Total: 20 files changed+670-132
| @@ -14,12 +14,14 @@ | |||
| 14 | #include <stdint.h> | 14 | #include <stdint.h> |
| 15 | #include <type_traits> | 15 | #include <type_traits> |
| 16 | #include <mutex> | 16 | #include <mutex> |
| 17 | +#include <vector> | ||
| 17 | 18 | ||
| 18 | #include "acl/acl_base_rt.h" | 19 | #include "acl/acl_base_rt.h" |
| 19 | #include "profiling/aprof_pub.h" | 20 | #include "profiling/aprof_pub.h" |
| 20 | 21 | ||
| 21 | #include "aclnn/acl_meta.h" | 22 | #include "aclnn/acl_meta.h" |
| 22 | #include "opdev/op_cache.h" | 23 | #include "opdev/op_cache.h" |
| 24 | +#include "opdev/op_log.h" | ||
| 23 | #include "thread_local_context.h" | 25 | #include "thread_local_context.h" |
| 24 | 26 | ||
| 25 | namespace op { | 27 | namespace op { |
| @@ -27,25 +29,63 @@ namespace internal { | |||
| 27 | 29 | ||
| 28 | struct TaskInfo { | 30 | struct TaskInfo { |
| 29 | uint64_t attrId{0}; | 31 | uint64_t attrId{0}; |
| 30 | - MsprofGeTaskType type; | 32 | + MsprofGeTaskType type{MSPROF_GE_TASK_TYPE_INVALID}; |
| 31 | - uint32_t ration; | 33 | + uint32_t ration{0}; |
| 32 | OpExecMode execMode{OpExecMode::OP_EXEC_MODE_DEFAULT}; | 34 | OpExecMode execMode{OpExecMode::OP_EXEC_MODE_DEFAULT}; |
| 33 | }; | 35 | }; |
| 34 | 36 | ||
| 35 | class OpExecCacheDfx { | 37 | class OpExecCacheDfx { |
| 36 | public: | 38 | public: |
| 37 | void SetExceptionDumpInfo(const ExceptionDumpInfo& info) { exceptionDumpInfo_.push_back(info); } | 39 | void SetExceptionDumpInfo(const ExceptionDumpInfo& info) { exceptionDumpInfo_.push_back(info); } |
| 38 | - ExceptionDumpInfo GetExceptionDumpInfo(int32_t index) const { return exceptionDumpInfo_[index]; } | 40 | + |
| 41 | + ExceptionDumpInfo GetExceptionDumpInfo(int32_t index) const | ||
| 42 | + { | ||
| 43 | + return IsValidIndex(index, exceptionDumpInfo_.size(), "exceptionDumpInfo") ? exceptionDumpInfo_[index] : | ||
| 44 | + ExceptionDumpInfo{}; | ||
| 45 | + } | ||
| 46 | + | ||
| 39 | void SetProfilingInfoId(const op::internal::ProfilingInfoId& id) { profilingInfoId_.push_back(id); } | 47 | void SetProfilingInfoId(const op::internal::ProfilingInfoId& id) { profilingInfoId_.push_back(id); } |
| 40 | - op::internal::ProfilingInfoId GetProfilingInfoId(int32_t index) const { return profilingInfoId_[index]; } | 48 | + |
| 41 | - void SetTaskInfo(const TaskInfo& taskInfo); | 49 | + op::internal::ProfilingInfoId GetProfilingInfoId(int32_t index) const |
| 42 | - MsprofGeTaskType GetTaskType(int32_t index) const { return taskInfo_[index].type; } | 50 | + { |
| 43 | - TaskInfo GetTaskInfo(int32_t index) const { return taskInfo_[index]; } | 51 | + return IsValidIndex(index, profilingInfoId_.size(), "profilingInfoId") ? profilingInfoId_[index] : |
| 52 | + op::internal::ProfilingInfoId{}; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + void SetTaskInfo(const TaskInfo& taskInfo) { taskInfo_.push_back(taskInfo); } | ||
| 56 | + | ||
| 57 | + TaskInfo GetTaskInfo(int32_t index) const | ||
| 58 | + { | ||
| 59 | + return IsValidIndex(index, taskInfo_.size(), "taskInfo") ? taskInfo_[index] : TaskInfo{}; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + MsprofGeTaskType GetTaskType(int32_t index) const | ||
| 63 | + { | ||
| 64 | + return IsValidIndex(index, taskInfo_.size(), "taskInfo") ? taskInfo_[index].type : MSPROF_GE_TASK_TYPE_INVALID; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + void SetOpType(uint32_t opType) { opTypes_.push_back(opType); } | ||
| 68 | + | ||
| 69 | + uint32_t GetOpType(int32_t index) const | ||
| 70 | + { | ||
| 71 | + return IsValidIndex(index, opTypes_.size(), "opTypes") ? opTypes_[index] : 0U; | ||
| 72 | + } | ||
| 44 | 73 | ||
| 45 | private: | 74 | private: |
| 75 | + static bool IsValidIndex(int32_t index, size_t size, const char* fieldName) | ||
| 76 | + { | ||
| 77 | + if (index >= 0 && static_cast<size_t>(index) < size) { | ||
| 78 | + return true; | ||
| 79 | + } | ||
| 80 | + OP_LOGW("OpExecCacheDfx field %s: index %d is out of range, current size is %zu, return the default value.", | ||
| 81 | + fieldName, static_cast<int32_t>(index), size); | ||
| 82 | + return false; | ||
| 83 | + } | ||
| 84 | + | ||
| 46 | std::vector<TaskInfo> taskInfo_; | 85 | std::vector<TaskInfo> taskInfo_; |
| 47 | std::vector<op::internal::ProfilingInfoId> profilingInfoId_; | 86 | std::vector<op::internal::ProfilingInfoId> profilingInfoId_; |
| 48 | std::vector<ExceptionDumpInfo> exceptionDumpInfo_; | 87 | std::vector<ExceptionDumpInfo> exceptionDumpInfo_; |
| 88 | + std::vector<uint32_t> opTypes_; | ||
| 49 | }; | 89 | }; |
| 50 | 90 | ||
| 51 | class OpExecCacheWrap { | 91 | class OpExecCacheWrap { |
| @@ -75,7 +75,8 @@ void DumpL2(const std::vector<const aclTensor*>& tensors, const OpLogInfo& opLog | |||
| 75 | 75 | ||
| 76 | void CacheTensorInfo(const FVector<const aclTensor*>& inTensors, const FVector<const aclTensor*>& outTensors); | 76 | void CacheTensorInfo(const FVector<const aclTensor*>& inTensors, const FVector<const aclTensor*>& outTensors); |
| 77 | 77 | ||
| 78 | -void CacheDfxInfo(uint32_t numBlocks, const ProfilingInfoId& id, const TaskInfo& taskInfo, bool isMemSet); | 78 | +void CacheDfxInfo(uint32_t numBlocks, const ProfilingInfoId& id, const TaskInfo& taskInfo, bool isMemSet, |
| 79 | + uint32_t opType); | ||
| 79 | 80 | ||
| 80 | int32_t RestoreTensorInfo(void* cacheTensorInfoLists, FVector<const aclTensor*>& inTensors, | 81 | int32_t RestoreTensorInfo(void* cacheTensorInfoLists, FVector<const aclTensor*>& inTensors, |
| 81 | FVector<const aclTensor*>& outTensors); | 82 | FVector<const aclTensor*>& outTensors); |
| @@ -168,6 +169,20 @@ void SetOpProfilingRecordArgFlag(bool value); | |||
| 168 | 169 | ||
| 169 | bool IsAclnnDebugEnabled(); | 170 | bool IsAclnnDebugEnabled(); |
| 170 | 171 | ||
| 172 | +bool IsSpecifiedOpProfilingEnabled(); | ||
| 173 | +bool CheckSpecifiedOpProfiling(uint32_t opType); | ||
| 174 | + | ||
| 175 | +inline bool IsTilingProfilingEnabled(uint32_t opType) | ||
| 176 | +{ | ||
| 177 | + return opProfilingSwitch.reportFlag && (!IsSpecifiedOpProfilingEnabled() || CheckSpecifiedOpProfiling(opType)); | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +inline bool IsL0ProfilingEnabled(uint32_t opType) | ||
| 181 | +{ | ||
| 182 | + return opProfilingSwitch.kernelLaunchFlag && | ||
| 183 | + (!IsSpecifiedOpProfilingEnabled() || CheckSpecifiedOpProfiling(opType)); | ||
| 184 | +} | ||
| 185 | + | ||
| 171 | #ifdef __cplusplus | 186 | #ifdef __cplusplus |
| 172 | extern "C" { | 187 | extern "C" { |
| 173 | #endif | 188 | #endif |
| @@ -11,8 +11,23 @@ | |||
| 11 | #ifndef OP_API_OP_API_COMMON_INC_OP_FEATURE_INTERNAL_H_ | 11 | #ifndef OP_API_OP_API_COMMON_INC_OP_FEATURE_INTERNAL_H_ |
| 12 | #define OP_API_OP_API_COMMON_INC_OP_FEATURE_INTERNAL_H_ | 12 | #define OP_API_OP_API_COMMON_INC_OP_FEATURE_INTERNAL_H_ |
| 13 | 13 | ||
| 14 | +#ifndef PRODUCT_SIDE_IS_DEVICE | ||
| 15 | +#include "version/runtime_version.h" | ||
| 16 | +#endif | ||
| 17 | + | ||
| 14 | #include "aclnn/acl_meta.h" | 18 | #include "aclnn/acl_meta.h" |
| 15 | 19 | ||
| 20 | +#define PKG_VERSION_NUM_9_2_0 90200000 | ||
| 21 | + | ||
| 22 | +#if !defined(PRODUCT_SIDE_IS_DEVICE) | ||
| 23 | +#if defined(RUNTIME_VERSION_NUM) | ||
| 24 | +#if (RUNTIME_VERSION_NUM >= PKG_VERSION_NUM_9_2_0) | ||
| 25 | +#define NNOPBASE_RUNTIME_VERSION_SUPPORT_PCIE_THROUGH 1 | ||
| 26 | +#define NNOPBASE_RUNTIME_VERSION_SUPPORT_OP_PROFILING 1 | ||
| 27 | +#endif | ||
| 28 | +#endif | ||
| 29 | +#endif | ||
| 30 | + | ||
| 16 | namespace op { | 31 | namespace op { |
| 17 | namespace internal { | 32 | namespace internal { |
| 18 | 33 | ||
| @@ -1013,10 +1013,7 @@ void* OpExecCache::AddLaunchAddress(const AddrRule& rule) | |||
| 1013 | return slot; | 1013 | return slot; |
| 1014 | } | 1014 | } |
| 1015 | 1015 | ||
| 1016 | -void OpExecCache::KeepResource(std::shared_ptr<void> resource) | 1016 | +void OpExecCache::KeepResource(std::shared_ptr<void> resource) { resources_.push_back(std::move(resource)); } |
| 1017 | -{ | ||
| 1018 | - resources_.push_back(std::move(resource)); | ||
| 1019 | -} | ||
| 1020 | 1017 | ||
| 1021 | void OpExecCache::SetCacheBuf(void* buf) { cacheBuf_ = buf; } | 1018 | void OpExecCache::SetCacheBuf(void* buf) { cacheBuf_ = buf; } |
| 1022 | 1019 | ||
| @@ -1095,8 +1092,6 @@ void OpExecCache::SetWorkspaceSize(uint64_t val) { workspaceSize_ = val; } | |||
| 1095 | 1092 | ||
| 1096 | uint64_t OpExecCache::GetWorkspaceSize() const { return workspaceSize_; } | 1093 | uint64_t OpExecCache::GetWorkspaceSize() const { return workspaceSize_; } |
| 1097 | 1094 | ||
| 1098 | -void OpExecCacheDfx::SetTaskInfo(const TaskInfo& taskInfo) { taskInfo_.push_back(taskInfo); } | ||
| 1099 | - | ||
| 1100 | uint64_t OpExecCache::GetHash() const { return hashKey_; } | 1095 | uint64_t OpExecCache::GetHash() const { return hashKey_; } |
| 1101 | 1096 | ||
| 1102 | OpCacheKey OpExecCache::GetOpCacheKey() const { return key_; } | 1097 | OpCacheKey OpExecCache::GetOpCacheKey() const { return key_; } |
| @@ -1118,8 +1113,8 @@ bool OpExecCache::IsOpCacheValid() | |||
| 1118 | 1113 | ||
| 1119 | aclnnStatus OpExecCache::DoSummaryProfiling(int index) | 1114 | aclnnStatus OpExecCache::DoSummaryProfiling(int index) |
| 1120 | { | 1115 | { |
| 1121 | - if (opExecCacheDfx_->GetTaskType(index) == MSPROF_GE_TASK_TYPE_MIX_AIV || | 1116 | + const MsprofGeTaskType taskType = opExecCacheDfx_->GetTaskType(index); |
| 1122 | - opExecCacheDfx_->GetTaskType(index) == MSPROF_GE_TASK_TYPE_MIX_AIC) { | 1117 | + if (taskType == MSPROF_GE_TASK_TYPE_MIX_AIV || taskType == MSPROF_GE_TASK_TYPE_MIX_AIC) { |
| 1123 | op::internal::ReportNodeContextIdInfo(opExecCacheDfx_->GetProfilingInfoId(index).summaryItemId_); | 1118 | op::internal::ReportNodeContextIdInfo(opExecCacheDfx_->GetProfilingInfoId(index).summaryItemId_); |
| 1124 | } | 1119 | } |
| 1125 | // only level2 profiling need to report addition info | 1120 | // only level2 profiling need to report addition info |
| @@ -1149,9 +1144,11 @@ aclnnStatus OpExecCache::Run(void* workspaceAddr, const aclrtStream stream, cons | |||
| 1149 | continue; | 1144 | continue; |
| 1150 | } | 1145 | } |
| 1151 | RestoreThreadLocal(index); | 1146 | RestoreThreadLocal(index); |
| 1147 | + bool isL0ProfilingEnabled = op::internal::IsL0ProfilingEnabled(opExecCacheDfx_->GetOpType(index)); | ||
| 1152 | { | 1148 | { |
| 1153 | - OpDfxGuard kernelLaunchGuard(opExecCacheDfx_->GetProfilingInfoId(index).summaryItemId_, | 1149 | + uint64_t summaryItemId = isL0ProfilingEnabled ? opExecCacheDfx_->GetProfilingInfoId(index).summaryItemId_ : |
| 1154 | - DfxProfilingType::DfxProfilingKernelLaunch); | 1150 | + kInvalidProfilingId; |
| 1151 | + OpDfxGuard kernelLaunchGuard(summaryItemId, DfxProfilingType::DfxProfilingKernelLaunch); | ||
| 1155 | aclnnStatus result = t.runner(stream, op::internal::PtrShift(cacheBuf_, t.cacheOffset)); | 1152 | aclnnStatus result = t.runner(stream, op::internal::PtrShift(cacheBuf_, t.cacheOffset)); |
| 1156 | OP_CHECK(result == ACLNN_SUCCESS, OP_LOGE(result, "OpExecCache run fail."), return result); | 1153 | OP_CHECK(result == ACLNN_SUCCESS, OP_LOGE(result, "OpExecCache run fail."), return result); |
| 1157 | } | 1154 | } |
| @@ -1159,7 +1156,7 @@ aclnnStatus OpExecCache::Run(void* workspaceAddr, const aclrtStream stream, cons | |||
| 1159 | DoExceptionDump(cacheTensorInfoLists_[index], workspaceAddr, tensors, | 1156 | DoExceptionDump(cacheTensorInfoLists_[index], workspaceAddr, tensors, |
| 1160 | opExecCacheDfx_->GetExceptionDumpInfo(index), stream); | 1157 | opExecCacheDfx_->GetExceptionDumpInfo(index), stream); |
| 1161 | } | 1158 | } |
| 1162 | - if (op::internal::opProfilingSwitch.kernelLaunchFlag) { | 1159 | + if (isL0ProfilingEnabled) { |
| 1163 | DoSummaryProfiling(index); | 1160 | DoSummaryProfiling(index); |
| 1164 | } | 1161 | } |
| 1165 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { | 1162 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { |
| @@ -29,13 +29,11 @@ | |||
| 29 | #include "opdev/op_errno.h" | 29 | #include "opdev/op_errno.h" |
| 30 | #include "op_common/op_host/util/op_const_def.h" | 30 | #include "op_common/op_host/util/op_const_def.h" |
| 31 | 31 | ||
| 32 | -#define PKG_VERSION_NUM_9_2_0 90200000 | ||
| 33 | - | ||
| 34 | namespace op { | 32 | namespace op { |
| 35 | namespace internal { | 33 | namespace internal { |
| 36 | 34 | ||
| 37 | namespace { | 35 | namespace { |
| 38 | -#if !defined(PRODUCT_SIDE_IS_DEVICE) && defined(RUNTIME_VERSION_NUM) && (RUNTIME_VERSION_NUM >= PKG_VERSION_NUM_9_2_0) | 36 | +#if defined(NNOPBASE_RUNTIME_VERSION_SUPPORT_PCIE_THROUGH) |
| 39 | using PcieAddrRange = aclrtAddrRange; | 37 | using PcieAddrRange = aclrtAddrRange; |
| 40 | #else | 38 | #else |
| 41 | struct PcieAddrRange { | 39 | struct PcieAddrRange { |
| @@ -63,7 +61,7 @@ bool IsPcieThroughEnvEnabled() | |||
| 63 | 61 | ||
| 64 | bool IsHostDeviceConnectWithPcie([[maybe_unused]] uint32_t deviceId) | 62 | bool IsHostDeviceConnectWithPcie([[maybe_unused]] uint32_t deviceId) |
| 65 | { | 63 | { |
| 66 | -#if !defined(PRODUCT_SIDE_IS_DEVICE) && defined(RUNTIME_VERSION_NUM) && (RUNTIME_VERSION_NUM >= PKG_VERSION_NUM_9_2_0) | 64 | +#if defined(NNOPBASE_RUNTIME_VERSION_SUPPORT_PCIE_THROUGH) |
| 67 | int64_t hdConnectType = ACL_HOST_DEVICE_CONNECT_TYPE_UB; | 65 | int64_t hdConnectType = ACL_HOST_DEVICE_CONNECT_TYPE_UB; |
| 68 | auto ret = aclrtGetDeviceInfo(deviceId, ACL_DEV_ATTR_HD_CONNECT_TYPE, &hdConnectType); | 66 | auto ret = aclrtGetDeviceInfo(deviceId, ACL_DEV_ATTR_HD_CONNECT_TYPE, &hdConnectType); |
| 69 | if (ret != ACL_SUCCESS) { | 67 | if (ret != ACL_SUCCESS) { |
| @@ -85,7 +83,7 @@ bool IsHostDeviceConnectWithPcie([[maybe_unused]] uint32_t deviceId) | |||
| 85 | 83 | ||
| 86 | aclnnStatus GetPcieAddrRange([[maybe_unused]] std::vector<PcieAddrRange>& addrRanges) | 84 | aclnnStatus GetPcieAddrRange([[maybe_unused]] std::vector<PcieAddrRange>& addrRanges) |
| 87 | { | 85 | { |
| 88 | -#if !defined(PRODUCT_SIDE_IS_DEVICE) && defined(RUNTIME_VERSION_NUM) && (RUNTIME_VERSION_NUM >= PKG_VERSION_NUM_9_2_0) | 86 | +#if defined(NNOPBASE_RUNTIME_VERSION_SUPPORT_PCIE_THROUGH) |
| 89 | addrRanges.clear(); | 87 | addrRanges.clear(); |
| 90 | if (aclrtHostGetDevicePointerAddrRange == nullptr) { | 88 | if (aclrtHostGetDevicePointerAddrRange == nullptr) { |
| 91 | OP_LOGW("aclrtHostGetDevicePointerAddrRange symbol is not found"); | 89 | OP_LOGW("aclrtHostGetDevicePointerAddrRange symbol is not found"); |
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | #include "acl/acl_rt.h" | 15 | #include "acl/acl_rt.h" |
| 16 | #include "kernel_launcher.h" | 16 | #include "kernel_launcher.h" |
| 17 | +#include "op_dfx_internal.h" | ||
| 17 | #include "opdev/op_arg_def.h" | 18 | #include "opdev/op_arg_def.h" |
| 18 | 19 | ||
| 19 | namespace op { | 20 | namespace op { |
| @@ -58,14 +59,18 @@ protected: | |||
| 58 | 59 | ||
| 59 | aclnnStatus ParamMemCpy(const aclrtStream stream) const; | 60 | aclnnStatus ParamMemCpy(const aclrtStream stream) const; |
| 60 | 61 | ||
| 61 | - aclnnStatus Distribute(const aclrtStream stream, OpArgList& inputList, OpArgList& outputList) | 62 | + aclnnStatus Distribute(const aclrtStream stream, uint32_t opType, OpArgList& inputList, OpArgList& outputList) |
| 62 | { | 63 | { |
| 64 | + auto& opThreadLocalCtx = op::internal::GetThreadLocalContext(); | ||
| 65 | + const bool isL0ProfilingEnabled = op::internal::IsL0ProfilingEnabled(opType); | ||
| 63 | { | 66 | { |
| 64 | - GetThreadLocalContext().profilingInfoId_.summaryItemId_ = GenSummaryItemId( | 67 | + opThreadLocalCtx.profilingInfoId_.summaryItemId_ = kInvalidProfilingId; |
| 65 | - GetThreadLocalContext().logInfo_.l2ApiName, GetThreadLocalContext().logInfo_.l0Name, | 68 | + if (isL0ProfilingEnabled) { |
| 66 | - GetThreadLocalContext().logInfo_.l0Name); | 69 | + opThreadLocalCtx.profilingInfoId_.summaryItemId_ = GenSummaryItemId(opThreadLocalCtx.logInfo_.l2ApiName, |
| 67 | - OpDfxGuard kernelLaunchGuard(GetThreadLocalContext().profilingInfoId_.summaryItemId_, | 70 | + opThreadLocalCtx.logInfo_.l0Name, |
| 68 | - DfxProfilingKernelLaunch); | 71 | + opThreadLocalCtx.logInfo_.l0Name); |
| 72 | + } | ||
| 73 | + OpDfxGuard kernelLaunchGuard(opThreadLocalCtx.profilingInfoId_.summaryItemId_, DfxProfilingKernelLaunch); | ||
| 69 | OP_LOGI("funcType is %d.", randomNumTaskInfo_.randomNumFuncParaInfo.funcType); | 74 | OP_LOGI("funcType is %d.", randomNumTaskInfo_.randomNumFuncParaInfo.funcType); |
| 70 | auto ret = aclrtRandomNumAsync(&randomNumTaskInfo_, stream, nullptr); | 75 | auto ret = aclrtRandomNumAsync(&randomNumTaskInfo_, stream, nullptr); |
| 71 | if (ret != ACL_SUCCESS) { | 76 | if (ret != ACL_SUCCESS) { |
| @@ -73,17 +78,16 @@ protected: | |||
| 73 | return ACLNN_ERR_RUNTIME_ERROR; | 78 | return ACLNN_ERR_RUNTIME_ERROR; |
| 74 | } | 79 | } |
| 75 | } | 80 | } |
| 76 | - if (op::internal::opProfilingSwitch.kernelLaunchFlag && op::internal::opProfilingSwitch.additionInfoFlag) { | 81 | + if (isL0ProfilingEnabled && op::internal::opProfilingSwitch.additionInfoFlag) { |
| 77 | - op::internal::GetThreadLocalContext().profilingInfoId_.kernelLauncherId_ = GenKernelLauncherId( | 82 | + opThreadLocalCtx.profilingInfoId_.kernelLauncherId_ = GenKernelLauncherId(opThreadLocalCtx.logInfo_.l0Name); |
| 78 | - op::internal::GetThreadLocalContext().logInfo_.l0Name); | 83 | + opThreadLocalCtx.profilingInfoId_.summaryItemId_ = GenSummaryItemId(opThreadLocalCtx.logInfo_.l2ApiName, |
| 79 | - GetThreadLocalContext().profilingInfoId_.summaryItemId_ = GenSummaryItemId( | 84 | + opThreadLocalCtx.logInfo_.l0Name, |
| 80 | - GetThreadLocalContext().logInfo_.l2ApiName, GetThreadLocalContext().logInfo_.l0Name, | 85 | + opThreadLocalCtx.logInfo_.l0Name); |
| 81 | - GetThreadLocalContext().logInfo_.l0Name); | ||
| 82 | op::internal::ReportAdditionInfo(inputList, outputList, MSPROF_GE_TASK_TYPE_DSA, | 86 | op::internal::ReportAdditionInfo(inputList, outputList, MSPROF_GE_TASK_TYPE_DSA, |
| 83 | - GetThreadLocalContext().profilingInfoId_.summaryItemId_); | 87 | + opThreadLocalCtx.profilingInfoId_.summaryItemId_); |
| 84 | } | 88 | } |
| 85 | GetCacheOpInfoSwitch(stream); | 89 | GetCacheOpInfoSwitch(stream); |
| 86 | - if (GetThreadLocalContext().cacheOpInfoSwitch_) { | 90 | + if (opThreadLocalCtx.cacheOpInfoSwitch_) { |
| 87 | ReportCacheOpInfoDSA(inputList, outputList, MSPROF_GE_TASK_TYPE_DSA); | 91 | ReportCacheOpInfoDSA(inputList, outputList, MSPROF_GE_TASK_TYPE_DSA); |
| 88 | } | 92 | } |
| 89 | return ACLNN_SUCCESS; | 93 | return ACLNN_SUCCESS; |
| @@ -101,14 +105,14 @@ public: | |||
| 101 | randomNumTaskInfo_.randomNumFuncParaInfo.funcType = ACL_RT_RANDOM_NUM_FUNC_TYPE_NORMAL_DIS; | 105 | randomNumTaskInfo_.randomNumFuncParaInfo.funcType = ACL_RT_RANDOM_NUM_FUNC_TYPE_NORMAL_DIS; |
| 102 | } | 106 | } |
| 103 | 107 | ||
| 104 | - aclnnStatus Run(aclrtStream stream, OpArgContext* opArgCtx) | 108 | + aclnnStatus Run(aclrtStream stream, uint32_t opType, OpArgContext* opArgCtx) |
| 105 | { | 109 | { |
| 106 | VisitWorkspaceArg(*opArgCtx->GetOpArg(op::OP_WORKSPACE_ARG)); | 110 | VisitWorkspaceArg(*opArgCtx->GetOpArg(op::OP_WORKSPACE_ARG)); |
| 107 | CHECK_RET_CODE(VisitOutputArgs(*opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), "VisitOutputArgs failed"); | 111 | CHECK_RET_CODE(VisitOutputArgs(*opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), "VisitOutputArgs failed"); |
| 108 | CHECK_RET_CODE(VisitInputArgs(*opArgCtx->GetOpArg(op::OP_INPUT_ARG)), "VisitInputArgs failed"); | 112 | CHECK_RET_CODE(VisitInputArgs(*opArgCtx->GetOpArg(op::OP_INPUT_ARG)), "VisitInputArgs failed"); |
| 109 | CHECK_RET_CODE(ParamMemCpy(stream), "ParamMemCpy failed"); | 113 | CHECK_RET_CODE(ParamMemCpy(stream), "ParamMemCpy failed"); |
| 110 | CHECK_RET_CODE( | 114 | CHECK_RET_CODE( |
| 111 | - Distribute(stream, *opArgCtx->GetOpArg(op::OP_INPUT_ARG), *opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), | 115 | + Distribute(stream, opType, *opArgCtx->GetOpArg(op::OP_INPUT_ARG), *opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), |
| 112 | "Distribute failed"); | 116 | "Distribute failed"); |
| 113 | 117 | ||
| 114 | return ACLNN_SUCCESS; | 118 | return ACLNN_SUCCESS; |
| @@ -238,14 +242,14 @@ public: | |||
| 238 | randomNumTaskInfo_.randomNumFuncParaInfo.funcType = ACL_RT_RANDOM_NUM_FUNC_TYPE_UNIFORM_DIS; | 242 | randomNumTaskInfo_.randomNumFuncParaInfo.funcType = ACL_RT_RANDOM_NUM_FUNC_TYPE_UNIFORM_DIS; |
| 239 | } | 243 | } |
| 240 | 244 | ||
| 241 | - aclnnStatus Run(aclrtStream stream, OpArgContext* opArgCtx) | 245 | + aclnnStatus Run(aclrtStream stream, uint32_t opType, OpArgContext* opArgCtx) |
| 242 | { | 246 | { |
| 243 | VisitWorkspaceArg(*opArgCtx->GetOpArg(op::OP_WORKSPACE_ARG)); | 247 | VisitWorkspaceArg(*opArgCtx->GetOpArg(op::OP_WORKSPACE_ARG)); |
| 244 | CHECK_RET_CODE(VisitOutputArgs(*opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), "VisitOutputArgs failed"); | 248 | CHECK_RET_CODE(VisitOutputArgs(*opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), "VisitOutputArgs failed"); |
| 245 | CHECK_RET_CODE(VisitInputArgs(*opArgCtx->GetOpArg(op::OP_INPUT_ARG)), "VisitInputArgs failed"); | 249 | CHECK_RET_CODE(VisitInputArgs(*opArgCtx->GetOpArg(op::OP_INPUT_ARG)), "VisitInputArgs failed"); |
| 246 | CHECK_RET_CODE(ParamMemCpy(stream), "ParamMemCpy failed"); | 250 | CHECK_RET_CODE(ParamMemCpy(stream), "ParamMemCpy failed"); |
| 247 | CHECK_RET_CODE( | 251 | CHECK_RET_CODE( |
| 248 | - Distribute(stream, *opArgCtx->GetOpArg(op::OP_INPUT_ARG), *opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), | 252 | + Distribute(stream, opType, *opArgCtx->GetOpArg(op::OP_INPUT_ARG), *opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), |
| 249 | "Distribute failed"); | 253 | "Distribute failed"); |
| 250 | 254 | ||
| 251 | return ACLNN_SUCCESS; | 255 | return ACLNN_SUCCESS; |
| @@ -368,14 +372,14 @@ public: | |||
| 368 | randomNumTaskInfo_.randomNumFuncParaInfo.funcType = ACL_RT_RANDOM_NUM_FUNC_TYPE_DROPOUT_BITMASK; | 372 | randomNumTaskInfo_.randomNumFuncParaInfo.funcType = ACL_RT_RANDOM_NUM_FUNC_TYPE_DROPOUT_BITMASK; |
| 369 | } | 373 | } |
| 370 | 374 | ||
| 371 | - aclnnStatus Run(aclrtStream stream, OpArgContext* opArgCtx) | 375 | + aclnnStatus Run(aclrtStream stream, uint32_t opType, OpArgContext* opArgCtx) |
| 372 | { | 376 | { |
| 373 | VisitWorkspaceArg(*opArgCtx->GetOpArg(op::OP_WORKSPACE_ARG)); | 377 | VisitWorkspaceArg(*opArgCtx->GetOpArg(op::OP_WORKSPACE_ARG)); |
| 374 | CHECK_RET_CODE(VisitOutputArgs(*opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), "VisitOutputArgs failed"); | 378 | CHECK_RET_CODE(VisitOutputArgs(*opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), "VisitOutputArgs failed"); |
| 375 | CHECK_RET_CODE(VisitInputArgs(*opArgCtx->GetOpArg(op::OP_INPUT_ARG)), "VisitInputArgs failed"); | 379 | CHECK_RET_CODE(VisitInputArgs(*opArgCtx->GetOpArg(op::OP_INPUT_ARG)), "VisitInputArgs failed"); |
| 376 | CHECK_RET_CODE(ParamMemCpy(stream), "ParamMemCpy failed"); | 380 | CHECK_RET_CODE(ParamMemCpy(stream), "ParamMemCpy failed"); |
| 377 | CHECK_RET_CODE( | 381 | CHECK_RET_CODE( |
| 378 | - Distribute(stream, *opArgCtx->GetOpArg(op::OP_INPUT_ARG), *opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), | 382 | + Distribute(stream, opType, *opArgCtx->GetOpArg(op::OP_INPUT_ARG), *opArgCtx->GetOpArg(op::OP_OUTPUT_ARG)), |
| 379 | "Distribute failed"); | 383 | "Distribute failed"); |
| 380 | 384 | ||
| 381 | return ACLNN_SUCCESS; | 385 | return ACLNN_SUCCESS; |
| @@ -508,7 +512,7 @@ public: | |||
| 508 | op::internal::GetThreadLocalContext().logInfo_.l0Name = opLogInfo_.l0Name; | 512 | op::internal::GetThreadLocalContext().logInfo_.l0Name = opLogInfo_.l0Name; |
| 509 | op::internal::GetThreadLocalContext().profilingInfoId_ = profilingInfoId_; | 513 | op::internal::GetThreadLocalContext().profilingInfoId_ = profilingInfoId_; |
| 510 | 514 | ||
| 511 | - const auto ret = task_.Run(executor_->GetStream(), args_); | 515 | + const auto ret = task_.Run(executor_->GetStream(), opType_, args_); |
| 512 | if (ret != ACLNN_SUCCESS) { | 516 | if (ret != ACLNN_SUCCESS) { |
| 513 | OP_LOGE(ACLNN_ERR_INNER, "DSA task distribute error."); | 517 | OP_LOGE(ACLNN_ERR_INNER, "DSA task distribute error."); |
| 514 | return ACLNN_ERR_INNER; | 518 | return ACLNN_ERR_INNER; |
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "kernel_arg.h" | 22 | #include "kernel_arg.h" |
| 23 | #include "kernel_mgr.h" | 23 | #include "kernel_mgr.h" |
| 24 | #include "op_kernel.h" | 24 | #include "op_kernel.h" |
| 25 | +#include "op_dfx_internal.h" | ||
| 25 | #include "bridge_pool.h" | 26 | #include "bridge_pool.h" |
| 26 | #include "opdev/op_def.h" | 27 | #include "opdev/op_def.h" |
| 27 | #include "opdev/op_dfx.h" | 28 | #include "opdev/op_dfx.h" |
| @@ -108,9 +109,11 @@ public: | |||
| 108 | const TilingCtxOutput* res = nullptr; | 109 | const TilingCtxOutput* res = nullptr; |
| 109 | ret = InitTilingParseCtx(); | 110 | ret = InitTilingParseCtx(); |
| 110 | OP_CHECK(ret == ACLNN_SUCCESS, OP_LOGW("InitTilingParseCtx failed, return %d", ret), return ret); | 111 | OP_CHECK(ret == ACLNN_SUCCESS, OP_LOGW("InitTilingParseCtx failed, return %d", ret), return ret); |
| 112 | + const bool isTilingProfilingEnabled = op::internal::IsTilingProfilingEnabled(opType_); | ||
| 113 | + const bool isL0ProfilingEnabled = op::internal::IsL0ProfilingEnabled(opType_); | ||
| 111 | { | 114 | { |
| 112 | - uint32_t tilingProfilingId = 0; | 115 | + uint32_t tilingProfilingId = kInvalidProfilingId; |
| 113 | - if (op::internal::opProfilingSwitch.reportFlag) { | 116 | + if (isTilingProfilingEnabled) { |
| 114 | std::string tilingFuncName = std::string(op::OpTypeDict::ToString(opType_).GetString()) + "_Tiling"; | 117 | std::string tilingFuncName = std::string(op::OpTypeDict::ToString(opType_).GetString()) + "_Tiling"; |
| 115 | tilingProfilingId = CollectProfilingStr(tilingFuncName.c_str()); | 118 | tilingProfilingId = CollectProfilingStr(tilingFuncName.c_str()); |
| 116 | } | 119 | } |
| @@ -131,8 +134,8 @@ public: | |||
| 131 | OP_CHECK(res != nullptr, OP_LOGW("Tiling Failed."), return ACLNN_ERR_INNER_NULLPTR); | 134 | OP_CHECK(res != nullptr, OP_LOGW("Tiling Failed."), return ACLNN_ERR_INNER_NULLPTR); |
| 132 | } | 135 | } |
| 133 | 136 | ||
| 134 | - uint64_t summaryId = 0; | 137 | + uint64_t summaryId = kInvalidProfilingId; |
| 135 | - if (opProfilingSwitch.kernelLaunchFlag) { | 138 | + if (isL0ProfilingEnabled) { |
| 136 | summaryId = GenSummaryItemId(GetThreadLocalContext().logInfo_.l2ApiName, | 139 | summaryId = GenSummaryItemId(GetThreadLocalContext().logInfo_.l2ApiName, |
| 137 | GetThreadLocalContext().logInfo_.l0Name, | 140 | GetThreadLocalContext().logInfo_.l0Name, |
| 138 | op::OpTypeDict::ToString(opType_).GetString()); | 141 | op::OpTypeDict::ToString(opType_).GetString()); |
| @@ -147,7 +150,7 @@ public: | |||
| 147 | DumpWorkspaceData(stream, args); | 150 | DumpWorkspaceData(stream, args); |
| 148 | } | 151 | } |
| 149 | static uint64_t kernelLaunchId = GenKernelLauncherId("NonFiniteCheck"); | 152 | static uint64_t kernelLaunchId = GenKernelLauncherId("NonFiniteCheck"); |
| 150 | - if (opProfilingSwitch.kernelLaunchFlag && opProfilingSwitch.additionInfoFlag) { | 153 | + if (isL0ProfilingEnabled && opProfilingSwitch.additionInfoFlag) { |
| 151 | ReportAdditionInfo(GetTaskInfo(*(res->tilingKey_)), kernelLaunchId, summaryId); | 154 | ReportAdditionInfo(GetTaskInfo(*(res->tilingKey_)), kernelLaunchId, summaryId); |
| 152 | } | 155 | } |
| 153 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { | 156 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { |
| @@ -135,10 +135,45 @@ __attribute__((constructor)) void InitAclnnDebugSwitch() | |||
| 135 | OP_LOGI("Aclnn debug mode is enabled by log level."); | 135 | OP_LOGI("Aclnn debug mode is enabled by log level."); |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | + | ||
| 139 | +// 算子级 profiling 开关,由 ProfilingCallBack 依据 PROF_OP_MASK 更新 | ||
| 140 | +std::atomic<bool> g_enableSpecifiedOpProfiling{false}; | ||
| 141 | + | ||
| 142 | +// 与 MsprofOpSwitchType::MSPROF_OPTYPE 对齐,本地定义以避免依赖旧版本头文件的枚举 | ||
| 143 | +constexpr uint32_t NNOPBASE_MSPROF_OPTYPE_QUERY = 0; | ||
| 144 | + | ||
| 145 | +// 弱符号:新版本 msprof 才导出该接口,旧版本下解析为 nullptr | ||
| 146 | +extern "C" { | ||
| 147 | +__attribute__((weak)) bool MsprofCheckOpSwitch(uint32_t type, const char* op, size_t len); | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | +void SetSpecifiedOpProfilingSwitch(uint64_t profSwitch) | ||
| 151 | +{ | ||
| 152 | +#if defined(PROF_OP_MASK) | ||
| 153 | + g_enableSpecifiedOpProfiling.store((profSwitch & PROF_OP_MASK) != 0, std::memory_order_relaxed); | ||
| 154 | +#else | ||
| 155 | + // 编译时头文件未定义 PROF_OP_MASK,不支持算子级 profiling,保持默认关闭 | ||
| 156 | + OP_LOGI("Op profiling is not supported when compiling nnopbase, so this feature is disabled."); | ||
| 157 | +#endif | ||
| 158 | +} | ||
| 138 | } // namespace | 159 | } // namespace |
| 139 | 160 | ||
| 140 | bool IsAclnnDebugEnabled() { return g_aclnnDebugEnabled.load(std::memory_order_relaxed); } | 161 | bool IsAclnnDebugEnabled() { return g_aclnnDebugEnabled.load(std::memory_order_relaxed); } |
| 141 | 162 | ||
| 163 | +bool IsSpecifiedOpProfilingEnabled() { return g_enableSpecifiedOpProfiling.load(std::memory_order_relaxed); } | ||
| 164 | + | ||
| 165 | +bool CheckSpecifiedOpProfiling(uint32_t opType) | ||
| 166 | +{ | ||
| 167 | + if (MsprofCheckOpSwitch == nullptr) { | ||
| 168 | + OP_LOGI("MsprofCheckOpSwitch symbol is not found, specified op profiling is disabled."); | ||
| 169 | + return false; | ||
| 170 | + } | ||
| 171 | + ge::AscendString opName = op::OpTypeDict::ToString(opType); | ||
| 172 | + bool enabled = MsprofCheckOpSwitch(NNOPBASE_MSPROF_OPTYPE_QUERY, opName.GetString(), opName.GetLength()); | ||
| 173 | + OP_LOGI("opType = %u, opName = %s, enabled = %d", opType, opName.GetString(), static_cast<int32_t>(enabled)); | ||
| 174 | + return enabled; | ||
| 175 | +} | ||
| 176 | + | ||
| 142 | OpThreadLocalContext& GetThreadLocalContext() | 177 | OpThreadLocalContext& GetThreadLocalContext() |
| 143 | { | 178 | { |
| 144 | thread_local static OpThreadLocalContext oPThreadLocalContext; | 179 | thread_local static OpThreadLocalContext oPThreadLocalContext; |
| @@ -295,18 +330,20 @@ int32_t ProfilingCallBack(uint32_t type, VOID_PTR data, uint32_t len) | |||
| 295 | opProfilingSwitch.additionInfoFlag = false; | 330 | opProfilingSwitch.additionInfoFlag = false; |
| 296 | opProfilingSwitch.level2ProfilingFlag = false; | 331 | opProfilingSwitch.level2ProfilingFlag = false; |
| 297 | opProfilingSwitch.timeStampFlag = false; | 332 | opProfilingSwitch.timeStampFlag = false; |
| 333 | + g_enableSpecifiedOpProfiling.store(false, std::memory_order_relaxed); | ||
| 298 | OP_LOGI("After ProfilingCallBack Stop, reportFlag=%d, kernelLaunchFlag=%d, additionInfoFlag=%d, " | 334 | OP_LOGI("After ProfilingCallBack Stop, reportFlag=%d, kernelLaunchFlag=%d, additionInfoFlag=%d, " |
| 299 | - "level2ProfilingFlag=%d, timeStampFlag=%d", | 335 | + "level2ProfilingFlag=%d, timeStampFlag=%d, specifiedOpProfilingEnabled=%d", |
| 300 | opProfilingSwitch.reportFlag, opProfilingSwitch.kernelLaunchFlag, opProfilingSwitch.additionInfoFlag, | 336 | opProfilingSwitch.reportFlag, opProfilingSwitch.kernelLaunchFlag, opProfilingSwitch.additionInfoFlag, |
| 301 | - opProfilingSwitch.level2ProfilingFlag, opProfilingSwitch.timeStampFlag); | 337 | + opProfilingSwitch.level2ProfilingFlag, opProfilingSwitch.timeStampFlag, |
| 338 | + IsSpecifiedOpProfilingEnabled()); | ||
| 302 | return 0; | 339 | return 0; |
| 303 | } | 340 | } |
| 304 | OP_LOGI("ProfilingCallBack, profSwitch = %lu", handle->profSwitch); | 341 | OP_LOGI("ProfilingCallBack, profSwitch = %lu", handle->profSwitch); |
| 305 | 342 | ||
| 306 | OP_LOGI("Before ProfilingCallBack Update, reportFlag=%d, kernelLaunchFlag=%d, additionInfoFlag=%d, " | 343 | OP_LOGI("Before ProfilingCallBack Update, reportFlag=%d, kernelLaunchFlag=%d, additionInfoFlag=%d, " |
| 307 | - "level2ProfilingFlag=%d", | 344 | + "level2ProfilingFlag=%d, specifiedOpProfilingEnabled=%d", |
| 308 | opProfilingSwitch.reportFlag, opProfilingSwitch.kernelLaunchFlag, opProfilingSwitch.additionInfoFlag, | 345 | opProfilingSwitch.reportFlag, opProfilingSwitch.kernelLaunchFlag, opProfilingSwitch.additionInfoFlag, |
| 309 | - opProfilingSwitch.level2ProfilingFlag); | 346 | + opProfilingSwitch.level2ProfilingFlag, IsSpecifiedOpProfilingEnabled()); |
| 310 | 347 | ||
| 311 | opProfilingSwitch.reportFlag = (handle->profSwitch & PROF_ACL_API_MASK) != 0; | 348 | opProfilingSwitch.reportFlag = (handle->profSwitch & PROF_ACL_API_MASK) != 0; |
| 312 | opProfilingSwitch.kernelLaunchFlag = (handle->profSwitch & PROF_TASK_TIME_MASK) != 0; | 349 | opProfilingSwitch.kernelLaunchFlag = (handle->profSwitch & PROF_TASK_TIME_MASK) != 0; |
| @@ -314,11 +351,12 @@ int32_t ProfilingCallBack(uint32_t type, VOID_PTR data, uint32_t len) | |||
| 314 | opProfilingSwitch.level2ProfilingFlag = ((handle->profSwitch & PROF_TASK_TIME_L2_MASK) != 0 || | 351 | opProfilingSwitch.level2ProfilingFlag = ((handle->profSwitch & PROF_TASK_TIME_L2_MASK) != 0 || |
| 315 | (handle->profSwitch & PROF_OP_ATTR_MASK) != 0); | 352 | (handle->profSwitch & PROF_OP_ATTR_MASK) != 0); |
| 316 | opProfilingSwitch.timeStampFlag = handle->profSwitch & PROF_OP_TIMESTAMP_MASK; | 353 | opProfilingSwitch.timeStampFlag = handle->profSwitch & PROF_OP_TIMESTAMP_MASK; |
| 354 | + SetSpecifiedOpProfilingSwitch(handle->profSwitch); | ||
| 317 | 355 | ||
| 318 | OP_LOGI("After ProfilingCallBack Update, reportFlag=%d, kernelLaunchFlag=%d, additionInfoFlag=%d, " | 356 | OP_LOGI("After ProfilingCallBack Update, reportFlag=%d, kernelLaunchFlag=%d, additionInfoFlag=%d, " |
| 319 | - "level2ProfilingFlag=%d, timeStampFlag=%d", | 357 | + "level2ProfilingFlag=%d, timeStampFlag=%d, specifiedOpProfilingEnabled=%d", |
| 320 | opProfilingSwitch.reportFlag, opProfilingSwitch.kernelLaunchFlag, opProfilingSwitch.additionInfoFlag, | 358 | opProfilingSwitch.reportFlag, opProfilingSwitch.kernelLaunchFlag, opProfilingSwitch.additionInfoFlag, |
| 321 | - opProfilingSwitch.level2ProfilingFlag, opProfilingSwitch.timeStampFlag); | 359 | + opProfilingSwitch.level2ProfilingFlag, opProfilingSwitch.timeStampFlag, IsSpecifiedOpProfilingEnabled()); |
| 322 | 360 | ||
| 323 | if ((opProfilingSwitch.reportFlag || opProfilingSwitch.kernelLaunchFlag || opProfilingSwitch.timeStampFlag) && | 361 | if ((opProfilingSwitch.reportFlag || opProfilingSwitch.kernelLaunchFlag || opProfilingSwitch.timeStampFlag) && |
| 324 | opProfilingSwitch.additionInfoFlag) { | 362 | opProfilingSwitch.additionInfoFlag) { |
| @@ -235,6 +235,7 @@ public: | |||
| 235 | launchCfg.blockDimOffset = 0; | 235 | launchCfg.blockDimOffset = 0; |
| 236 | launchCfg.engineType = isVectorCoreEnableScenario_ ? LaunchKernelEngineType::VECTOR_CORE_ENGINE_AIC : | 236 | launchCfg.engineType = isVectorCoreEnableScenario_ ? LaunchKernelEngineType::VECTOR_CORE_ENGINE_AIC : |
| 237 | LaunchKernelEngineType::NO_VECTOR_CORE; | 237 | LaunchKernelEngineType::NO_VECTOR_CORE; |
| 238 | + launchCfg.opType = opType_; | ||
| 238 | 239 | ||
| 239 | rtsArg.ReportExceptionDumpInfo(); | 240 | rtsArg.ReportExceptionDumpInfo(); |
| 240 | aclnnStatus ret = DoLaunchKernel(rtsArg, stream, launchCfg); | 241 | aclnnStatus ret = DoLaunchKernel(rtsArg, stream, launchCfg); |
| @@ -266,13 +267,13 @@ public: | |||
| 266 | op::OpTypeDict::ToString(opType_).GetString()); | 267 | op::OpTypeDict::ToString(opType_).GetString()); |
| 267 | TaskInfo tskInfo = GetTaskInfo(tilingkey, args); | 268 | TaskInfo tskInfo = GetTaskInfo(tilingkey, args); |
| 268 | tskInfo.attrId = GetAttrId(args); | 269 | tskInfo.attrId = GetAttrId(args); |
| 269 | - CacheDfxInfo(numBlocks, GetThreadLocalContext().profilingInfoId_, tskInfo, false); | 270 | + CacheDfxInfo(numBlocks, GetThreadLocalContext().profilingInfoId_, tskInfo, false, opType_); |
| 270 | } else { | 271 | } else { |
| 271 | GetThreadLocalContext().memSetProfilingInfoId_.summaryItemId_ = GenSummaryItemId( | 272 | GetThreadLocalContext().memSetProfilingInfoId_.summaryItemId_ = GenSummaryItemId( |
| 272 | GetThreadLocalContext().logInfo_.l2ApiName, GetThreadLocalContext().logInfo_.l0Name, | 273 | GetThreadLocalContext().logInfo_.l2ApiName, GetThreadLocalContext().logInfo_.l0Name, |
| 273 | op::OpTypeDict::ToString(opType_).GetString()); | 274 | op::OpTypeDict::ToString(opType_).GetString()); |
| 274 | CacheDfxInfo(numBlocks, GetThreadLocalContext().memSetProfilingInfoId_, | 275 | CacheDfxInfo(numBlocks, GetThreadLocalContext().memSetProfilingInfoId_, |
| 275 | - GetTaskInfo(tilingkey, args), true); | 276 | + GetTaskInfo(tilingkey, args), true, opType_); |
| 276 | } | 277 | } |
| 277 | } | 278 | } |
| 278 | 279 | ||
| @@ -291,9 +292,12 @@ public: | |||
| 291 | aclnnStatus DoLaunchWithDfx(const TilingCtxOutput* res, aclrtStream stream, OpArgContext* args) | 292 | aclnnStatus DoLaunchWithDfx(const TilingCtxOutput* res, aclrtStream stream, OpArgContext* args) |
| 292 | { | 293 | { |
| 293 | aclnnStatus rc = ACLNN_ERR_INNER; | 294 | aclnnStatus rc = ACLNN_ERR_INNER; |
| 294 | - if (op::internal::opProfilingSwitch.kernelLaunchFlag) { | 295 | + auto& opThreadLocalCtx = op::internal::GetThreadLocalContext(); |
| 295 | - GetThreadLocalContext().profilingInfoId_.summaryItemId_ = GenSummaryItemId( | 296 | + const bool isL0ProfilingEnabled = op::internal::IsL0ProfilingEnabled(opType_); |
| 296 | - GetThreadLocalContext().logInfo_.l2ApiName, GetThreadLocalContext().logInfo_.l0Name, | 297 | + opThreadLocalCtx.profilingInfoId_.summaryItemId_ = kInvalidProfilingId; |
| 298 | + if (isL0ProfilingEnabled) { | ||
| 299 | + opThreadLocalCtx.profilingInfoId_.summaryItemId_ = GenSummaryItemId( | ||
| 300 | + opThreadLocalCtx.logInfo_.l2ApiName, opThreadLocalCtx.logInfo_.l0Name, | ||
| 297 | op::OpTypeDict::ToString(opType_).GetString()); | 301 | op::OpTypeDict::ToString(opType_).GetString()); |
| 298 | } | 302 | } |
| 299 | // disabling the Cache | 303 | // disabling the Cache |
| @@ -303,32 +307,31 @@ public: | |||
| 303 | } | 307 | } |
| 304 | std::vector<int32_t> tensorOffset; | 308 | std::vector<int32_t> tensorOffset; |
| 305 | { | 309 | { |
| 306 | - OpDfxGuard kernelLaunchGuard(GetThreadLocalContext().profilingInfoId_.summaryItemId_, | 310 | + OpDfxGuard kernelLaunchGuard(opThreadLocalCtx.profilingInfoId_.summaryItemId_, DfxProfilingKernelLaunch); |
| 307 | - DfxProfilingKernelLaunch); | ||
| 308 | rc = DoLaunch(res, stream, false, args, tensorOffset); | 311 | rc = DoLaunch(res, stream, false, args, tensorOffset); |
| 309 | } | 312 | } |
| 310 | if (IsPrintFEnable()) { | 313 | if (IsPrintFEnable()) { |
| 311 | DumpWorkspaceData(stream, args); | 314 | DumpWorkspaceData(stream, args); |
| 312 | } | 315 | } |
| 313 | if (op::internal::IsExceptionDumpEnable()) { | 316 | if (op::internal::IsExceptionDumpEnable()) { |
| 314 | - op::internal::PrepareExceptionDumpInfo(args, GetThreadLocalContext().logInfo_, genPlaceholder_, | 317 | + op::internal::PrepareExceptionDumpInfo(args, opThreadLocalCtx.logInfo_, genPlaceholder_, hasDevPtrArg_, |
| 315 | - hasDevPtrArg_, interCoreSync_, tensorOffset, stream); | 318 | + interCoreSync_, tensorOffset, stream); |
| 316 | } | 319 | } |
| 317 | - if (op::internal::opProfilingSwitch.kernelLaunchFlag) { | 320 | + if (isL0ProfilingEnabled) { |
| 318 | auto taskInfo = GetTaskInfo(*(res->tilingKey_), args); | 321 | auto taskInfo = GetTaskInfo(*(res->tilingKey_), args); |
| 319 | if (taskInfo.type == MSPROF_GE_TASK_TYPE_MIX_AIV || taskInfo.type == MSPROF_GE_TASK_TYPE_MIX_AIC) { | 322 | if (taskInfo.type == MSPROF_GE_TASK_TYPE_MIX_AIV || taskInfo.type == MSPROF_GE_TASK_TYPE_MIX_AIC) { |
| 320 | - op::internal::ReportNodeContextIdInfo(GetThreadLocalContext().profilingInfoId_.summaryItemId_); | 323 | + op::internal::ReportNodeContextIdInfo(opThreadLocalCtx.profilingInfoId_.summaryItemId_); |
| 321 | } | 324 | } |
| 322 | // only level1 profiling need to report addition info | 325 | // only level1 profiling need to report addition info |
| 323 | - op::internal::GetThreadLocalContext().profilingInfoId_.kernelLauncherId_ = GenKernelLauncherId( | 326 | + opThreadLocalCtx.profilingInfoId_.kernelLauncherId_ = GenKernelLauncherId( |
| 324 | op::OpTypeDict::ToString(opType_).GetString()); | 327 | op::OpTypeDict::ToString(opType_).GetString()); |
| 325 | if (op::internal::opProfilingSwitch.additionInfoFlag) { | 328 | if (op::internal::opProfilingSwitch.additionInfoFlag) { |
| 326 | op::internal::ReportAdditionInfo(*args->GetOpArg(op::OP_INPUT_ARG), *args->GetOpArg(op::OP_OUTPUT_ARG), | 329 | op::internal::ReportAdditionInfo(*args->GetOpArg(op::OP_INPUT_ARG), *args->GetOpArg(op::OP_OUTPUT_ARG), |
| 327 | - taskInfo, GetThreadLocalContext().profilingInfoId_.summaryItemId_); | 330 | + taskInfo, opThreadLocalCtx.profilingInfoId_.summaryItemId_); |
| 328 | } | 331 | } |
| 329 | - ReportOpAttrInfo(args, GetThreadLocalContext().profilingInfoId_.summaryItemId_); | 332 | + ReportOpAttrInfo(args, opThreadLocalCtx.profilingInfoId_.summaryItemId_); |
| 330 | } | 333 | } |
| 331 | - if (GetThreadLocalContext().cacheOpInfoSwitch_) { | 334 | + if (opThreadLocalCtx.cacheOpInfoSwitch_) { |
| 332 | TaskInfo taskInfo = GetTaskInfo(*(res->tilingKey_), args); | 335 | TaskInfo taskInfo = GetTaskInfo(*(res->tilingKey_), args); |
| 333 | uint64_t attrId = GetAttrId(args); | 336 | uint64_t attrId = GetAttrId(args); |
| 334 | ReportCacheOpInfo(taskInfo, args, opType_, attrId); | 337 | ReportCacheOpInfo(taskInfo, args, opType_, attrId); |
| @@ -521,6 +524,7 @@ public: | |||
| 521 | launchCfg.blockDimOffset = 0; | 524 | launchCfg.blockDimOffset = 0; |
| 522 | launchCfg.dynUBufSize = 0; | 525 | launchCfg.dynUBufSize = 0; |
| 523 | launchCfg.engineType = LaunchKernelEngineType::VECTOR_CORE_ENGINE_AIC; | 526 | launchCfg.engineType = LaunchKernelEngineType::VECTOR_CORE_ENGINE_AIC; |
| 527 | + launchCfg.opType = opType_; | ||
| 524 | 528 | ||
| 525 | rtsArg.ReportExceptionDumpInfo(); | 529 | rtsArg.ReportExceptionDumpInfo(); |
| 526 | ret = DoLaunchKernel(rtsArg, stream, launchCfg); | 530 | ret = DoLaunchKernel(rtsArg, stream, launchCfg); |
| @@ -569,6 +573,7 @@ public: | |||
| 569 | launchCfg.blockDimOffset = blockdimAic; | 573 | launchCfg.blockDimOffset = blockdimAic; |
| 570 | launchCfg.dynUBufSize = 0; | 574 | launchCfg.dynUBufSize = 0; |
| 571 | launchCfg.engineType = LaunchKernelEngineType::VECTOR_CORE_ENGINE_AIV; | 575 | launchCfg.engineType = LaunchKernelEngineType::VECTOR_CORE_ENGINE_AIV; |
| 576 | + launchCfg.opType = opType_; | ||
| 572 | 577 | ||
| 573 | rtsArg.ReportExceptionDumpInfo(); | 578 | rtsArg.ReportExceptionDumpInfo(); |
| 574 | ret = DoLaunchKernel(rtsArg, secondStream, launchCfg); | 579 | ret = DoLaunchKernel(rtsArg, secondStream, launchCfg); |
| @@ -625,7 +630,8 @@ public: | |||
| 625 | if (binType_ == BinType::DYNAMIC_BIN) { | 630 | if (binType_ == BinType::DYNAMIC_BIN) { |
| 626 | CHECK_RET_CODE(InitTilingParseCtx(), "InitTilingParseCtx failed"); | 631 | CHECK_RET_CODE(InitTilingParseCtx(), "InitTilingParseCtx failed"); |
| 627 | { | 632 | { |
| 628 | - if (op::internal::opProfilingSwitch.reportFlag) { | 633 | + GetThreadLocalContext().profilingInfoId_.tilingProfilingId_ = kInvalidProfilingId; |
| 634 | + if (op::internal::IsTilingProfilingEnabled(opType_)) { | ||
| 629 | std::string tilingFuncName = op::OpTypeDict::ToString(opType_).GetString() + std::string("_Tiling"); | 635 | std::string tilingFuncName = op::OpTypeDict::ToString(opType_).GetString() + std::string("_Tiling"); |
| 630 | GetThreadLocalContext().profilingInfoId_.tilingProfilingId_ = CollectProfilingStr( | 636 | GetThreadLocalContext().profilingInfoId_.tilingProfilingId_ = CollectProfilingStr( |
| 631 | tilingFuncName.c_str()); | 637 | tilingFuncName.c_str()); |
| @@ -717,8 +723,9 @@ public: | |||
| 717 | auto workspace = OP_WORKSPACE(std::move(tensor)); | 723 | auto workspace = OP_WORKSPACE(std::move(tensor)); |
| 718 | static uint64_t kernelLaunchId = GenKernelLauncherId("MemSet"); | 724 | static uint64_t kernelLaunchId = GenKernelLauncherId("MemSet"); |
| 719 | GetThreadLocalContext().memSetProfilingInfoId_.kernelLauncherId_ = kernelLaunchId; | 725 | GetThreadLocalContext().memSetProfilingInfoId_.kernelLauncherId_ = kernelLaunchId; |
| 720 | - uint64_t summaryId = 0; | 726 | + const bool isL0ProfilingEnabled = op::internal::IsL0ProfilingEnabled(opType_); |
| 721 | - if (opProfilingSwitch.kernelLaunchFlag) { | 727 | + uint64_t summaryId = kInvalidProfilingId; |
| 728 | + if (isL0ProfilingEnabled) { | ||
| 722 | summaryId = GenSummaryItemId(GetThreadLocalContext().logInfo_.l2ApiName, | 729 | summaryId = GenSummaryItemId(GetThreadLocalContext().logInfo_.l2ApiName, |
| 723 | GetThreadLocalContext().logInfo_.l0Name, "MemSet"); | 730 | GetThreadLocalContext().logInfo_.l0Name, "MemSet"); |
| 724 | } | 731 | } |
| @@ -732,7 +739,7 @@ public: | |||
| 732 | OpDfxGuard kernelLaunchGuard(summaryId, DfxProfilingKernelLaunch); | 739 | OpDfxGuard kernelLaunchGuard(summaryId, DfxProfilingKernelLaunch); |
| 733 | rc = DoLaunch(res, stream, true, &tempCtx, tensorOffset); | 740 | rc = DoLaunch(res, stream, true, &tempCtx, tensorOffset); |
| 734 | } | 741 | } |
| 735 | - if (opProfilingSwitch.kernelLaunchFlag && opProfilingSwitch.additionInfoFlag) { | 742 | + if (isL0ProfilingEnabled && opProfilingSwitch.additionInfoFlag) { |
| 736 | ReportAdditionInfo(GetTaskInfo(*(res->tilingKey_)), kernelLaunchId, summaryId); | 743 | ReportAdditionInfo(GetTaskInfo(*(res->tilingKey_)), kernelLaunchId, summaryId); |
| 737 | } | 744 | } |
| 738 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { | 745 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { |
| @@ -753,8 +760,11 @@ public: | |||
| 753 | OP_CHECK(!(rc == ACLNN_SUCCESS && memsetV2OpArgCtx == nullptr), OP_LOGW("There is no tensor to memset"), | 760 | OP_CHECK(!(rc == ACLNN_SUCCESS && memsetV2OpArgCtx == nullptr), OP_LOGW("There is no tensor to memset"), |
| 754 | return ACLNN_SUCCESS); | 761 | return ACLNN_SUCCESS); |
| 755 | auto& opTlsCtx = GetThreadLocalContext(); | 762 | auto& opTlsCtx = GetThreadLocalContext(); |
| 763 | + const bool isTilingProfilingEnabled = op::internal::IsTilingProfilingEnabled(opType_); | ||
| 764 | + const bool isL0ProfilingEnabled = op::internal::IsL0ProfilingEnabled(opType_); | ||
| 756 | // tiling | 765 | // tiling |
| 757 | - if (op::internal::opProfilingSwitch.reportFlag) { | 766 | + opTlsCtx.profilingInfoId_.tilingProfilingId_ = kInvalidProfilingId; |
| 767 | + if (isTilingProfilingEnabled) { | ||
| 758 | std::string tilingFuncName = op::OpTypeDict::ToString(opType_).GetString() + std::string("_Tiling"); | 768 | std::string tilingFuncName = op::OpTypeDict::ToString(opType_).GetString() + std::string("_Tiling"); |
| 759 | opTlsCtx.profilingInfoId_.tilingProfilingId_ = CollectProfilingStr(tilingFuncName.c_str()); | 769 | opTlsCtx.profilingInfoId_.tilingProfilingId_ = CollectProfilingStr(tilingFuncName.c_str()); |
| 760 | } | 770 | } |
| @@ -775,8 +785,8 @@ public: | |||
| 775 | // kernel launch | 785 | // kernel launch |
| 776 | static uint64_t kernelLaunchId = GenKernelLauncherId(MEMSET_V2_NAME.c_str()); | 786 | static uint64_t kernelLaunchId = GenKernelLauncherId(MEMSET_V2_NAME.c_str()); |
| 777 | opTlsCtx.memSetProfilingInfoId_.kernelLauncherId_ = kernelLaunchId; | 787 | opTlsCtx.memSetProfilingInfoId_.kernelLauncherId_ = kernelLaunchId; |
| 778 | - uint64_t summaryId = 0; | 788 | + uint64_t summaryId = kInvalidProfilingId; |
| 779 | - if (opProfilingSwitch.kernelLaunchFlag) { | 789 | + if (isL0ProfilingEnabled) { |
| 780 | summaryId = GenSummaryItemId(opTlsCtx.logInfo_.l2ApiName, opTlsCtx.logInfo_.l0Name, MEMSET_V2_NAME.c_str()); | 790 | summaryId = GenSummaryItemId(opTlsCtx.logInfo_.l2ApiName, opTlsCtx.logInfo_.l0Name, MEMSET_V2_NAME.c_str()); |
| 781 | } | 791 | } |
| 782 | std::vector<int32_t> tensorOffset; | 792 | std::vector<int32_t> tensorOffset; |
| @@ -784,7 +794,7 @@ public: | |||
| 784 | OpDfxGuard kernelLaunchGuard(summaryId, DfxProfilingKernelLaunch); | 794 | OpDfxGuard kernelLaunchGuard(summaryId, DfxProfilingKernelLaunch); |
| 785 | rc = DoLaunch(res, stream, true, memsetV2OpArgCtx, tensorOffset); | 795 | rc = DoLaunch(res, stream, true, memsetV2OpArgCtx, tensorOffset); |
| 786 | } | 796 | } |
| 787 | - if (opProfilingSwitch.kernelLaunchFlag && opProfilingSwitch.additionInfoFlag) { | 797 | + if (isL0ProfilingEnabled && opProfilingSwitch.additionInfoFlag) { |
| 788 | ReportAdditionInfo(GetTaskInfo(*(res->tilingKey_)), kernelLaunchId, summaryId); | 798 | ReportAdditionInfo(GetTaskInfo(*(res->tilingKey_)), kernelLaunchId, summaryId); |
| 789 | } | 799 | } |
| 790 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { | 800 | if (GetThreadLocalContext().cacheOpInfoSwitch_) { |
| @@ -807,7 +817,8 @@ public: | |||
| 807 | return ACLNN_SUCCESS; | 817 | return ACLNN_SUCCESS; |
| 808 | } | 818 | } |
| 809 | CHECK_RET_CODE(InitTilingParseCtx(), "InitTilingParseCtx failed"); | 819 | CHECK_RET_CODE(InitTilingParseCtx(), "InitTilingParseCtx failed"); |
| 810 | - if (op::internal::opProfilingSwitch.reportFlag) { | 820 | + GetThreadLocalContext().profilingInfoId_.tilingProfilingId_ = kInvalidProfilingId; |
| 821 | + if (op::internal::IsTilingProfilingEnabled(opType_)) { | ||
| 811 | std::string tilingFuncName = op::OpTypeDict::ToString(opType_).GetString() + std::string("_Tiling"); | 822 | std::string tilingFuncName = op::OpTypeDict::ToString(opType_).GetString() + std::string("_Tiling"); |
| 812 | GetThreadLocalContext().profilingInfoId_.tilingProfilingId_ = CollectProfilingStr(tilingFuncName.c_str()); | 823 | GetThreadLocalContext().profilingInfoId_.tilingProfilingId_ = CollectProfilingStr(tilingFuncName.c_str()); |
| 813 | } | 824 | } |
| @@ -24,6 +24,7 @@ | |||
| 24 | #include "opdev/op_log.h" | 24 | #include "opdev/op_log.h" |
| 25 | #include "opdev/op_cache.h" | 25 | #include "opdev/op_cache.h" |
| 26 | #include "op_dfx_internal.h" | 26 | #include "op_dfx_internal.h" |
| 27 | +#include "op_feature_internal.h" | ||
| 27 | #include "op_cache_internal.h" | 28 | #include "op_cache_internal.h" |
| 28 | #include "kernel_utils.h" | 29 | #include "kernel_utils.h" |
| 29 | #include "bridge_dfx.h" | 30 | #include "bridge_dfx.h" |
| @@ -142,7 +143,7 @@ int PrintRtArg(const rtArgs_t& rtArg) | |||
| 142 | } | 143 | } |
| 143 | uint32_t hostDataNum = (rtArg.hasTiling != 0 && rtArg.placeHolderInfoNum > 0) ? rtArg.placeHolderInfoNum - 1 : | 144 | uint32_t hostDataNum = (rtArg.hasTiling != 0 && rtArg.placeHolderInfoNum > 0) ? rtArg.placeHolderInfoNum - 1 : |
| 144 | rtArg.placeHolderInfoNum; | 145 | rtArg.placeHolderInfoNum; |
| 145 | - OP_LOGD("opType: %s, argsSize: %u, placeHolderInfoNum: %u, hostDataNum: %u, hasTiling %d, tilingAddrOffset: %u, " | 146 | + OP_LOGD("l0Name: %s, argsSize: %u, placeHolderInfoNum: %u, hostDataNum: %u, hasTiling %d, tilingAddrOffset: %u, " |
| 146 | "tilingDataOffset: %u", | 147 | "tilingDataOffset: %u", |
| 147 | op::internal::GetThreadLocalContext().logInfo_.l0Name, rtArg.argsSize, rtArg.placeHolderInfoNum, | 148 | op::internal::GetThreadLocalContext().logInfo_.l0Name, rtArg.argsSize, rtArg.placeHolderInfoNum, |
| 148 | hostDataNum, rtArg.hasTiling, rtArg.tilingAddrOffset, rtArg.tilingDataOffset); | 149 | hostDataNum, rtArg.hasTiling, rtArg.tilingAddrOffset, rtArg.tilingDataOffset); |
| @@ -214,6 +215,38 @@ int PrintAICErrorDFXInfo(const void* dfxInfoAddr, const size_t argNum, const siz | |||
| 214 | return 0; | 215 | return 0; |
| 215 | } | 216 | } |
| 216 | 217 | ||
| 218 | +namespace { | ||
| 219 | +void AddOpProfilingLaunchKernelAttr(uint32_t opType, [[maybe_unused]] std::vector<aclrtLaunchKernelAttr>& kernelAttrs) | ||
| 220 | +{ | ||
| 221 | + // 任一 profiling 上报类型开启时才需要该 attr | ||
| 222 | + if (!(op::internal::opProfilingSwitch.kernelLaunchFlag || op::internal::opProfilingSwitch.additionInfoFlag || | ||
| 223 | + op::internal::opProfilingSwitch.level2ProfilingFlag)) { | ||
| 224 | + return; | ||
| 225 | + } | ||
| 226 | + // 算子级开关未使能、或该算子未在配置中时,不下发 | ||
| 227 | + if (!op::internal::IsSpecifiedOpProfilingEnabled() || !op::internal::CheckSpecifiedOpProfiling(opType)) { | ||
| 228 | + return; | ||
| 229 | + } | ||
| 230 | +#if defined(NNOPBASE_RUNTIME_VERSION_SUPPORT_OP_PROFILING) | ||
| 231 | + static int32_t runtimeVerNum = -1; | ||
| 232 | + static const aclError runtimeVerRet = aclsysGetVersionNum("runtime", &runtimeVerNum); | ||
| 233 | + if (runtimeVerRet != ACL_SUCCESS || runtimeVerNum < PKG_VERSION_NUM_9_2_0) { | ||
| 234 | + OP_LOGW("[AddOpProfilingLaunchKernelAttr] ACL_RT_LAUNCH_KERNEL_ATTR_ENABLE_PROFILING attr is not " | ||
| 235 | + "supported, get runtime version return %d, runtime version num is %d, required is %d, " | ||
| 236 | + "skip adding attr.", | ||
| 237 | + runtimeVerRet, runtimeVerNum, PKG_VERSION_NUM_9_2_0); | ||
| 238 | + return; | ||
| 239 | + } | ||
| 240 | + kernelAttrs.emplace_back(); | ||
| 241 | + kernelAttrs.back().id = ACL_RT_LAUNCH_KERNEL_ATTR_ENABLE_PROFILING; | ||
| 242 | + kernelAttrs.back().value.enableProfiling = 1; | ||
| 243 | +#else | ||
| 244 | + OP_LOGW("[AddOpProfilingLaunchKernelAttr] ACL_RT_LAUNCH_KERNEL_ATTR_ENABLE_PROFILING attr is not supported, " | ||
| 245 | + "because the runtime package version is lower than 9.2.0 when compiling nnopbase, skip adding attr."); | ||
| 246 | +#endif | ||
| 247 | +} | ||
| 248 | +} // namespace | ||
| 249 | + | ||
| 217 | constexpr size_t TILING_AND_OVERFLOW = 2; | 250 | constexpr size_t TILING_AND_OVERFLOW = 2; |
| 218 | constexpr size_t ONLY_OVERFLOW = 1; | 251 | constexpr size_t ONLY_OVERFLOW = 1; |
| 219 | thread_local std::vector<aclrtPlaceHolderInfo> RtsArg::placeHolderInfo_{MAX_HOST_INFO_NUM}; | 252 | thread_local std::vector<aclrtPlaceHolderInfo> RtsArg::placeHolderInfo_{MAX_HOST_INFO_NUM}; |
| @@ -313,6 +346,8 @@ aclnnStatus RtsArg::LaunchKernel(aclrtStream stream, const KernelLaunchConfig& l | |||
| 313 | ACL_RT_ENGINE_TYPE_AIV; | 346 | ACL_RT_ENGINE_TYPE_AIV; |
| 314 | } | 347 | } |
| 315 | 348 | ||
| 349 | + AddOpProfilingLaunchKernelAttr(launchCfg.opType, kernelAttrs); | ||
| 350 | + | ||
| 316 | aclrtLaunchKernelCfg aclrtLaunchCfg; | 351 | aclrtLaunchKernelCfg aclrtLaunchCfg; |
| 317 | aclrtLaunchCfg.attrs = kernelAttrs.data(); | 352 | aclrtLaunchCfg.attrs = kernelAttrs.data(); |
| 318 | aclrtLaunchCfg.numAttrs = kernelAttrs.size(); | 353 | aclrtLaunchCfg.numAttrs = kernelAttrs.size(); |
| @@ -777,7 +812,7 @@ LaunchArgCache* RtsArg::DumpToCache() | |||
| 777 | launchCache->SetExceptionArgNum(0); | 812 | launchCache->SetExceptionArgNum(0); |
| 778 | launchCache->SetDFXInfoCacheElemCount(0); | 813 | launchCache->SetDFXInfoCacheElemCount(0); |
| 779 | launchCache->SetRtsApiType(LaunchArgCache::RTS_OLD); | 814 | launchCache->SetRtsApiType(LaunchArgCache::RTS_OLD); |
| 780 | - launchCache->SetOpType(op::internal::GetThreadLocalContext().logInfo_.l0Name); | 815 | + launchCache->SetL0Name(op::internal::GetThreadLocalContext().logInfo_.l0Name); |
| 781 | LaunchArgCache::ArgInfo* argInfo = launchCache->GetArgInfo(); | 816 | LaunchArgCache::ArgInfo* argInfo = launchCache->GetArgInfo(); |
| 782 | AddArgInfoToCache(cache, argInfo, argInfo_, hasFftsAddr_, rtsArgBuffer_); | 817 | AddArgInfoToCache(cache, argInfo, argInfo_, hasFftsAddr_, rtsArgBuffer_); |
| 783 | AddExceptionDumpDataToCache(argInfo_, cache, launchCache); | 818 | AddExceptionDumpDataToCache(argInfo_, cache, launchCache); |
| @@ -878,6 +913,8 @@ aclnnStatus LaunchArgCache::LaunchKernelFromCache(aclrtStream stream, rtArgs_t& | |||
| 878 | kernelAttrs.back().value.engineType = ACL_RT_ENGINE_TYPE_AIC; | 913 | kernelAttrs.back().value.engineType = ACL_RT_ENGINE_TYPE_AIC; |
| 879 | } | 914 | } |
| 880 | 915 | ||
| 916 | + AddOpProfilingLaunchKernelAttr(launchCfg.opType, kernelAttrs); | ||
| 917 | + | ||
| 881 | aclrtLaunchKernelCfg aclrtLaunchCfg; | 918 | aclrtLaunchKernelCfg aclrtLaunchCfg; |
| 882 | aclrtLaunchCfg.attrs = kernelAttrs.data(); | 919 | aclrtLaunchCfg.attrs = kernelAttrs.data(); |
| 883 | aclrtLaunchCfg.numAttrs = kernelAttrs.size(); | 920 | aclrtLaunchCfg.numAttrs = kernelAttrs.size(); |
| @@ -906,7 +943,8 @@ aclnnStatus LaunchArgCache::RunFromCache(aclrtStream stream, void* cache) | |||
| 906 | } | 943 | } |
| 907 | 944 | ||
| 908 | LaunchArgCache* launchCache = PtrCastTo<LaunchArgCache>(cache); | 945 | LaunchArgCache* launchCache = PtrCastTo<LaunchArgCache>(cache); |
| 909 | - op::internal::GetThreadLocalContext().logInfo_.l0Name = launchCache->GetOpType(); | 946 | + auto& opThreadLocalCtx = op::internal::GetThreadLocalContext(); |
| 947 | + opThreadLocalCtx.logInfo_.l0Name = launchCache->GetL0Name(); | ||
| 910 | 948 | ||
| 911 | LaunchArgCache::ArgInfo* argInfo = launchCache->GetArgInfo(); | 949 | LaunchArgCache::ArgInfo* argInfo = launchCache->GetArgInfo(); |
| 912 | void* rawArg = launchCache->GetRawRtsArg(); | 950 | void* rawArg = launchCache->GetRawRtsArg(); |
| @@ -925,8 +963,8 @@ aclnnStatus LaunchArgCache::RunFromCache(aclrtStream stream, void* cache) | |||
| 925 | rtArg.argsSize = launchCache->GetRawArgSize(); | 963 | rtArg.argsSize = launchCache->GetRawArgSize(); |
| 926 | 964 | ||
| 927 | if (IsExceptionDumpEnable()) { | 965 | if (IsExceptionDumpEnable()) { |
| 928 | - op::internal::GetThreadLocalContext().exceptionDumpInfo_.rtsArgs_ = rtArg.args; | 966 | + opThreadLocalCtx.exceptionDumpInfo_.rtsArgs_ = rtArg.args; |
| 929 | - op::internal::GetThreadLocalContext().exceptionDumpInfo_.rtsArgsSize_ = rtArg.argsSize; | 967 | + opThreadLocalCtx.exceptionDumpInfo_.rtsArgsSize_ = rtArg.argsSize; |
| 930 | } | 968 | } |
| 931 | 969 | ||
| 932 | for (size_t i = 0; i < argNum; i++) { | 970 | for (size_t i = 0; i < argNum; i++) { |
| @@ -28,6 +28,7 @@ | |||
| 28 | namespace op::internal { | 28 | namespace op::internal { |
| 29 | 29 | ||
| 30 | constexpr size_t KERNEL_NAME_MAX_SIZE = 160; | 30 | constexpr size_t KERNEL_NAME_MAX_SIZE = 160; |
| 31 | +constexpr size_t L0_NAME_MAX_SIZE = 48; | ||
| 31 | constexpr int32_t LAUNCH_KERNEL_ATTR_DYN_UBUF_SIZE = 2; | 32 | constexpr int32_t LAUNCH_KERNEL_ATTR_DYN_UBUF_SIZE = 2; |
| 32 | 33 | ||
| 33 | enum class LaunchKernelEngineType : uint8_t { NO_VECTOR_CORE = 0, VECTOR_CORE_ENGINE_AIC, VECTOR_CORE_ENGINE_AIV }; | 34 | enum class LaunchKernelEngineType : uint8_t { NO_VECTOR_CORE = 0, VECTOR_CORE_ENGINE_AIC, VECTOR_CORE_ENGINE_AIV }; |
| @@ -43,6 +44,7 @@ struct KernelLaunchConfig { | |||
| 43 | uint32_t dynUBufSize; | 44 | uint32_t dynUBufSize; |
| 44 | uint32_t blockDimOffset; | 45 | uint32_t blockDimOffset; |
| 45 | LaunchKernelEngineType engineType; | 46 | LaunchKernelEngineType engineType; |
| 47 | + uint32_t opType{0}; | ||
| 46 | }; | 48 | }; |
| 47 | 49 | ||
| 48 | // rts args struct | 50 | // rts args struct |
| @@ -154,6 +156,8 @@ public: | |||
| 154 | 156 | ||
| 155 | uint64_t GetTilingKey() const { return tilingKey_; } | 157 | uint64_t GetTilingKey() const { return tilingKey_; } |
| 156 | 158 | ||
| 159 | + uint32_t GetOpType() const { return launchCfg_.opType; } | ||
| 160 | + | ||
| 157 | KernelLaunchConfig& GetKernelLaunchConfig() | 161 | KernelLaunchConfig& GetKernelLaunchConfig() |
| 158 | { | 162 | { |
| 159 | launchCfg_.kernelNameOfNoFatBin = kernelNameOfNoFatBin_; | 163 | launchCfg_.kernelNameOfNoFatBin = kernelNameOfNoFatBin_; |
| @@ -173,9 +177,16 @@ public: | |||
| 173 | return sizeof(void*) * argNum_ + hostLen; | 177 | return sizeof(void*) * argNum_ + hostLen; |
| 174 | } | 178 | } |
| 175 | 179 | ||
| 176 | - void SetOpType(const char* opType) { strcpy_s(opType_, sizeof(opType_), opType); } | 180 | + void SetL0Name(const char* l0Name) |
| 181 | + { | ||
| 182 | + auto rc = strcpy_s(l0Name_, sizeof(l0Name_), l0Name); | ||
| 183 | + OP_CHECK(rc == EOK, | ||
| 184 | + OP_LOGW("Copy l0Name failed, return %d, the maximum length is %zu, l0Name: %s.", rc, | ||
| 185 | + sizeof(l0Name_) - 1, l0Name == nullptr ? "(null)" : l0Name), | ||
| 186 | + return); | ||
| 187 | + } | ||
| 177 | 188 | ||
| 178 | - const char* GetOpType() { return opType_; } | 189 | + const char* GetL0Name() const { return l0Name_; } |
| 179 | 190 | ||
| 180 | void SetHostArgInfo(size_t size, size_t num) | 191 | void SetHostArgInfo(size_t size, size_t num) |
| 181 | { | 192 | { |
| @@ -192,7 +203,7 @@ public: | |||
| 192 | static aclnnStatus RunFromCache(aclrtStream stream, void* cache); | 203 | static aclnnStatus RunFromCache(aclrtStream stream, void* cache); |
| 193 | 204 | ||
| 194 | private: | 205 | private: |
| 195 | - char opType_[16] = {0}; | 206 | + char l0Name_[L0_NAME_MAX_SIZE] = {0}; |
| 196 | char kernelNameOfNoFatBin_[KERNEL_NAME_MAX_SIZE] = {0}; | 207 | char kernelNameOfNoFatBin_[KERNEL_NAME_MAX_SIZE] = {0}; |
| 197 | void* handle_{nullptr}; | 208 | void* handle_{nullptr}; |
| 198 | KernelLaunchConfig launchCfg_; | 209 | KernelLaunchConfig launchCfg_; |
| @@ -130,7 +130,8 @@ void CacheTensorInfo(const FVector<const aclTensor*>& inTensors, const FVector<c | |||
| 130 | cache->SetCacheTensorInfo(cacheTensorInfoLists); | 130 | cache->SetCacheTensorInfo(cacheTensorInfoLists); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | -void CacheDfxInfo(uint32_t numBlocks, const ProfilingInfoId& id, const TaskInfo& taskInfo, bool isMemSet) | 133 | +void CacheDfxInfo(uint32_t numBlocks, const ProfilingInfoId& id, const TaskInfo& taskInfo, bool isMemSet, |
| 134 | + uint32_t opType) | ||
| 134 | { | 135 | { |
| 135 | OP_LOGD("CacheDfxInfo numBlocks = %u", numBlocks); | 136 | OP_LOGD("CacheDfxInfo numBlocks = %u", numBlocks); |
| 136 | OpExecCache* cache = GetOpCacheContext().GetOpCache(); | 137 | OpExecCache* cache = GetOpCacheContext().GetOpCache(); |
| @@ -139,6 +140,7 @@ void CacheDfxInfo(uint32_t numBlocks, const ProfilingInfoId& id, const TaskInfo& | |||
| 139 | } | 140 | } |
| 140 | cache->SetBlockDim(numBlocks); | 141 | cache->SetBlockDim(numBlocks); |
| 141 | cache->opExecCacheDfx_->SetProfilingInfoId(id); | 142 | cache->opExecCacheDfx_->SetProfilingInfoId(id); |
| 143 | + cache->opExecCacheDfx_->SetOpType(opType); | ||
| 142 | 144 | ||
| 143 | cache->opExecCacheDfx_->SetTaskInfo(taskInfo); | 145 | cache->opExecCacheDfx_->SetTaskInfo(taskInfo); |
| 144 | if (!IsExceptionDumpEnable()) { | 146 | if (!IsExceptionDumpEnable()) { |
| @@ -87,6 +87,7 @@ target_link_libraries(stub_nnopbase | |||
| 87 | PRIVATE | 87 | PRIVATE |
| 88 | $<BUILD_INTERFACE:intf_pub> | 88 | $<BUILD_INTERFACE:intf_pub> |
| 89 | $<BUILD_INTERFACE:error_manager_headers> | 89 | $<BUILD_INTERFACE:error_manager_headers> |
| 90 | + $<BUILD_INTERFACE:cann_version_headers> | ||
| 90 | metadef_headers | 91 | metadef_headers |
| 91 | runtime_headers | 92 | runtime_headers |
| 92 | opbase_headers | 93 | opbase_headers |
| @@ -31,3 +31,8 @@ int32_t MsprofRegTypeInfo(uint16_t level, uint32_t typeId, const char* typeName) | |||
| 31 | { | 31 | { |
| 32 | return ProfilerStub::GetInstance()->MsprofRegTypeInfo(level, typeId, typeName); | 32 | return ProfilerStub::GetInstance()->MsprofRegTypeInfo(level, typeId, typeName); |
| 33 | } | 33 | } |
| 34 | + | ||
| 35 | +bool MsprofCheckOpSwitch(uint32_t type, const char* op, size_t len) | ||
| 36 | +{ | ||
| 37 | + return ProfilerStub::GetInstance()->MsprofCheckOpSwitch(type, op, len); | ||
| 38 | +} | ||
| @@ -36,6 +36,9 @@ public: | |||
| 36 | 36 | ||
| 37 | virtual int32_t MsprofRegTypeInfo(uint16_t level, uint32_t typeId, const char* typeName) { return 0; } | 37 | virtual int32_t MsprofRegTypeInfo(uint16_t level, uint32_t typeId, const char* typeName) { return 0; } |
| 38 | 38 | ||
| 39 | + // 算子级 profiling:是否对指定算子使能(默认不使能) | ||
| 40 | + virtual bool MsprofCheckOpSwitch(uint32_t type, const char* op, size_t len) { return false; } | ||
| 41 | + | ||
| 39 | void Install(ProfilerStub* instance) { fake_instance_ = instance; } | 42 | void Install(ProfilerStub* instance) { fake_instance_ = instance; } |
| 40 | 43 | ||
| 41 | void UnInstall() { fake_instance_ = nullptr; } | 44 | void UnInstall() { fake_instance_ = nullptr; } |
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "opdev/make_op_executor.h" | 17 | #include "opdev/make_op_executor.h" |
| 18 | #include "opdev/op_dfx.h" | 18 | #include "opdev/op_dfx.h" |
| 19 | #include "op_cache_internal.h" | 19 | #include "op_cache_internal.h" |
| 20 | +#include "op_dfx_internal.h" | ||
| 20 | #include "depends/profiler/profiler_stub.h" | 21 | #include "depends/profiler/profiler_stub.h" |
| 21 | #include "thread_local_context.h" | 22 | #include "thread_local_context.h" |
| 22 | 23 | ||
| @@ -38,7 +39,6 @@ static ProfilingCacheUtProfiler prof; | |||
| 38 | namespace op { | 39 | namespace op { |
| 39 | namespace internal { | 40 | namespace internal { |
| 40 | void CacheTensorInfo(const FVector<const aclTensor*>& inTensors, const FVector<const aclTensor*>& outTensors); | 41 | void CacheTensorInfo(const FVector<const aclTensor*>& inTensors, const FVector<const aclTensor*>& outTensors); |
| 41 | -void CacheDfxInfo(uint32_t blockDim, const ProfilingInfoId& id, const TaskInfo& taskInfo, bool isMemSet); | ||
| 42 | aclnnStatus DoReportAdditionInfo(void* infoLists, const TaskInfo& taskInfo, | 42 | aclnnStatus DoReportAdditionInfo(void* infoLists, const TaskInfo& taskInfo, |
| 43 | const op::internal::ProfilingInfoId& profilingInfoId); | 43 | const op::internal::ProfilingInfoId& profilingInfoId); |
| 44 | } // namespace internal | 44 | } // namespace internal |
| @@ -118,7 +118,7 @@ TEST_F(ProfilingCacheUt, test_cache_tensor_has_op_cache) | |||
| 118 | TaskInfo info; | 118 | TaskInfo info; |
| 119 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; | 119 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; |
| 120 | info.ration = 0; | 120 | info.ration = 0; |
| 121 | - CacheDfxInfo(32, id, info, false); | 121 | + CacheDfxInfo(32, id, info, false, 0); |
| 122 | 122 | ||
| 123 | // release resource | 123 | // release resource |
| 124 | aclDestroyTensor(tensorIn); | 124 | aclDestroyTensor(tensorIn); |
| @@ -158,7 +158,7 @@ TEST_F(ProfilingCacheUt, test_cache_tensor_restore_and_report) | |||
| 158 | TaskInfo info; | 158 | TaskInfo info; |
| 159 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; | 159 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; |
| 160 | info.ration = 0; | 160 | info.ration = 0; |
| 161 | - CacheDfxInfo(32, id, info, false); | 161 | + CacheDfxInfo(32, id, info, false, 0); |
| 162 | 162 | ||
| 163 | // test restore/report | 163 | // test restore/report |
| 164 | EXPECT_EQ(DoReportAdditionInfo(opExecCache->GetCacheTensorInfo(0), info, id), OK); | 164 | EXPECT_EQ(DoReportAdditionInfo(opExecCache->GetCacheTensorInfo(0), info, id), OK); |
| @@ -877,7 +877,9 @@ TEST(DirectInvokeTaskTest, StatelessCallbacksRequireNoDestroy) | |||
| 877 | 877 | ||
| 878 | TEST(DirectInvokeTaskTest, RepeatReusesPreparationAndAlwaysLaunchesWithCurrentAddresses) | 878 | TEST(DirectInvokeTaskTest, RepeatReusesPreparationAndAlwaysLaunchesWithCurrentAddresses) |
| 879 | { | 879 | { |
| 880 | - struct ResetMocks { ~ResetMocks() { GlobalMockObject::verify(); } } resetMocks; | 880 | + struct ResetMocks { |
| 881 | + ~ResetMocks() { GlobalMockObject::verify(); } | ||
| 882 | + } resetMocks; | ||
| 881 | MOCKER(op::internal::CheckCacheable).stubs().will(returnValue(true)); | 883 | MOCKER(op::internal::CheckCacheable).stubs().will(returnValue(true)); |
| 882 | auto& tls = op::internal::GetThreadLocalContext(); | 884 | auto& tls = op::internal::GetThreadLocalContext(); |
| 883 | struct Restore { | 885 | struct Restore { |
| @@ -886,7 +888,8 @@ TEST(DirectInvokeTaskTest, RepeatReusesPreparationAndAlwaysLaunchesWithCurrentAd | |||
| 886 | uint64_t hash; | 888 | uint64_t hash; |
| 887 | std::vector<const aclStorage*> storages; | 889 | std::vector<const aclStorage*> storages; |
| 888 | size_t storageCount; | 890 | size_t storageCount; |
| 889 | - ~Restore() { | 891 | + ~Restore() |
| 892 | + { | ||
| 890 | tls.cacheHasFull_ = cacheHasFull; | 893 | tls.cacheHasFull_ = cacheHasFull; |
| 891 | tls.hashKey_ = hash; | 894 | tls.hashKey_ = hash; |
| 892 | tls.cachedStorageList_ = std::move(storages); | 895 | tls.cachedStorageList_ = std::move(storages); |
| @@ -909,8 +912,8 @@ TEST(DirectInvokeTaskTest, RepeatReusesPreparationAndAlwaysLaunchesWithCurrentAd | |||
| 909 | ASSERT_TRUE(executor->GetOpExecCache()->IsOpCacheValid()); | 912 | ASSERT_TRUE(executor->GetOpExecCache()->IsOpCacheValid()); |
| 910 | auto* args = op::GetOpArgContext(OP_INPUT(tensors.input.get()), OP_OUTPUT(tensors.output.get()), | 913 | auto* args = op::GetOpArgContext(OP_INPUT(tensors.input.get()), OP_OUTPUT(tensors.output.get()), |
| 911 | FIXTURE_ATTR(config), OP_WORKSPACE()); | 914 | FIXTURE_ATTR(config), OP_WORKSPACE()); |
| 912 | - ASSERT_EQ(op::AddDirectInvokeTask("DirectInvokeFixture", DirectInvokeFixtureOpTypeId(), | 915 | + ASSERT_EQ(op::AddDirectInvokeTask("DirectInvokeFixture", DirectInvokeFixtureOpTypeId(), PrepareFixture, |
| 913 | - PrepareFixture, LaunchFixture, DestroyFixture, executor.get(), args), | 916 | + LaunchFixture, DestroyFixture, executor.get(), args), |
| 914 | ACLNN_SUCCESS); | 917 | ACLNN_SUCCESS); |
| 915 | // This must hold independently of DFX switches that can also reject cache. | 918 | // This must hold independently of DFX switches that can also reject cache. |
| 916 | EXPECT_TRUE(executor->GetOpExecCache()->IsOpCacheValid()); | 919 | EXPECT_TRUE(executor->GetOpExecCache()->IsOpCacheValid()); |
| @@ -953,7 +956,10 @@ TEST(DirectInvokeTaskTest, CacheSnapshotOwnsArgumentsAndRebindsOffsetsAndWorkspa | |||
| 953 | using namespace op; | 956 | using namespace op; |
| 954 | using namespace op::internal; | 957 | using namespace op::internal; |
| 955 | int destroyed = 0; | 958 | int destroyed = 0; |
| 956 | - struct State { int* destroyed; int calls{0}; }; | 959 | + struct State { |
| 960 | + int* destroyed; | ||
| 961 | + int calls{0}; | ||
| 962 | + }; | ||
| 957 | auto state = std::shared_ptr<void>(new State{&destroyed}, [](void* p) { | 963 | auto state = std::shared_ptr<void>(new State{&destroyed}, [](void* p) { |
| 958 | auto* s = static_cast<State*>(p); | 964 | auto* s = static_cast<State*>(p); |
| 959 | ++*s->destroyed; | 965 | ++*s->destroyed; |
| @@ -989,7 +995,8 @@ TEST(DirectInvokeTaskTest, CacheSnapshotOwnsArgumentsAndRebindsOffsetsAndWorkspa | |||
| 989 | DestroyOpArgContext(args); | 995 | DestroyOpArgContext(args); |
| 990 | aclDestroyIntArray(array); | 996 | aclDestroyIntArray(array); |
| 991 | aclDestroyScalar(scalar); | 997 | aclDestroyScalar(scalar); |
| 992 | - for (size_t i = 0; i < list->Size(); ++i) (*list)[i] = nullptr; | 998 | + for (size_t i = 0; i < list->Size(); ++i) |
| 999 | + (*list)[i] = nullptr; | ||
| 993 | aclDestroyTensorList(list); | 1000 | aclDestroyTensorList(list); |
| 994 | aclDestroyTensorList(workspaceList); | 1001 | aclDestroyTensorList(workspaceList); |
| 995 | aclDestroyTensor(input); | 1002 | aclDestroyTensor(input); |
| @@ -997,15 +1004,19 @@ TEST(DirectInvokeTaskTest, CacheSnapshotOwnsArgumentsAndRebindsOffsetsAndWorkspa | |||
| 997 | DirectInvokeLaunchFn launch = [](void* p, const OpArgContext* current, aclrtStream stream) noexcept { | 1004 | DirectInvokeLaunchFn launch = [](void* p, const OpArgContext* current, aclrtStream stream) noexcept { |
| 998 | auto* s = static_cast<State*>(p); | 1005 | auto* s = static_cast<State*>(p); |
| 999 | ++s->calls; | 1006 | ++s->calls; |
| 1000 | - const auto* list = static_cast<const aclTensorList*>(current->GetOpArg(OP_INPUT_ARG)->args[0].value.data.pointer); | 1007 | + const auto* list = static_cast<const aclTensorList*>( |
| 1008 | + current->GetOpArg(OP_INPUT_ARG)->args[0].value.data.pointer); | ||
| 1001 | EXPECT_EQ((*list)[0], nullptr); | 1009 | EXPECT_EQ((*list)[0], nullptr); |
| 1002 | EXPECT_EQ((*list)[1], (*list)[2]); | 1010 | EXPECT_EQ((*list)[1], (*list)[2]); |
| 1003 | EXPECT_EQ((*list)[1]->GetData(), static_cast<char*>(reinterpret_cast<void*>(stream)) + 5 * sizeof(float)); | 1011 | EXPECT_EQ((*list)[1]->GetData(), static_cast<char*>(reinterpret_cast<void*>(stream)) + 5 * sizeof(float)); |
| 1004 | const auto* attrs = current->GetOpArg(OP_ATTR_ARG); | 1012 | const auto* attrs = current->GetOpArg(OP_ATTR_ARG); |
| 1005 | EXPECT_EQ((*static_cast<const aclIntArray*>(attrs->args[0].value.data.pointer))[1], 9); | 1013 | EXPECT_EQ((*static_cast<const aclIntArray*>(attrs->args[0].value.data.pointer))[1], 9); |
| 1006 | - EXPECT_FLOAT_EQ(*static_cast<const float*>(static_cast<const aclScalar*>(attrs->args[1].value.data.pointer)->GetData()), 0.5F); | 1014 | + EXPECT_FLOAT_EQ( |
| 1015 | + *static_cast<const float*>(static_cast<const aclScalar*>(attrs->args[1].value.data.pointer)->GetData()), | ||
| 1016 | + 0.5F); | ||
| 1007 | EXPECT_STREQ(static_cast<const char*>(attrs->args[2].value.data.pointer), "snapshot"); | 1017 | EXPECT_STREQ(static_cast<const char*>(attrs->args[2].value.data.pointer), "snapshot"); |
| 1008 | - const auto* work = static_cast<const aclTensorList*>(current->GetOpArg(OP_WORKSPACE_ARG)->args[0].value.data.pointer); | 1018 | + const auto* work = static_cast<const aclTensorList*>( |
| 1019 | + current->GetOpArg(OP_WORKSPACE_ARG)->args[0].value.data.pointer); | ||
| 1009 | EXPECT_EQ(static_cast<char*>((*work)[0]->GetData()) - static_cast<char*>((*work)[0]->GetStorageAddr()), 18); | 1020 | EXPECT_EQ(static_cast<char*>((*work)[0]->GetData()) - static_cast<char*>((*work)[0]->GetStorageAddr()), 18); |
| 1010 | return ACLNN_SUCCESS; | 1021 | return ACLNN_SUCCESS; |
| 1011 | }; | 1022 | }; |
| @@ -1027,7 +1038,9 @@ TEST(DirectInvokeTaskTest, CacheSnapshotOwnsArgumentsAndRebindsOffsetsAndWorkspa | |||
| 1027 | 1038 | ||
| 1028 | TEST(DirectInvokeTaskTest, CacheAssociatesDfxWithMixedTasksAndStopsOnError) | 1039 | TEST(DirectInvokeTaskTest, CacheAssociatesDfxWithMixedTasksAndStopsOnError) |
| 1029 | { | 1040 | { |
| 1030 | - struct ResetMocks { ~ResetMocks() { GlobalMockObject::verify(); } } resetMocks; | 1041 | + struct ResetMocks { |
| 1042 | + ~ResetMocks() { GlobalMockObject::verify(); } | ||
| 1043 | + } resetMocks; | ||
| 1031 | using namespace op::internal; | 1044 | using namespace op::internal; |
| 1032 | MOCKER(IsExceptionDumpEnable).stubs().will(returnValue(true)); | 1045 | MOCKER(IsExceptionDumpEnable).stubs().will(returnValue(true)); |
| 1033 | MOCKER(DoExceptionDump).expects(exactly(2)); | 1046 | MOCKER(DoExceptionDump).expects(exactly(2)); |
| @@ -1038,7 +1051,11 @@ TEST(DirectInvokeTaskTest, CacheAssociatesDfxWithMixedTasksAndStopsOnError) | |||
| 1038 | struct RestoreDfx { | 1051 | struct RestoreDfx { |
| 1039 | decltype(opProfilingSwitch) profiling; | 1052 | decltype(opProfilingSwitch) profiling; |
| 1040 | decltype(oldTls) tls; | 1053 | decltype(oldTls) tls; |
| 1041 | - ~RestoreDfx() { opProfilingSwitch = profiling; GetThreadLocalContext() = tls; } | 1054 | + ~RestoreDfx() |
| 1055 | + { | ||
| 1056 | + opProfilingSwitch = profiling; | ||
| 1057 | + GetThreadLocalContext() = tls; | ||
| 1058 | + } | ||
| 1042 | } restore{oldProfiling, oldTls}; | 1059 | } restore{oldProfiling, oldTls}; |
| 1043 | opProfilingSwitch = {}; | 1060 | opProfilingSwitch = {}; |
| 1044 | opProfilingSwitch.kernelLaunchFlag = true; | 1061 | opProfilingSwitch.kernelLaunchFlag = true; |
| @@ -1048,7 +1065,12 @@ TEST(DirectInvokeTaskTest, CacheAssociatesDfxWithMixedTasksAndStopsOnError) | |||
| 1048 | alignas(64) char buffer[512]{}; | 1065 | alignas(64) char buffer[512]{}; |
| 1049 | cache.SetCacheBuf(buffer); | 1066 | cache.SetCacheBuf(buffer); |
| 1050 | std::vector<int> order; | 1067 | std::vector<int> order; |
| 1051 | - struct Record { std::vector<int>* order; int id; uint32_t blocks; aclnnStatus result; }; | 1068 | + struct Record { |
| 1069 | + std::vector<int>* order; | ||
| 1070 | + int id; | ||
| 1071 | + uint32_t blocks; | ||
| 1072 | + aclnnStatus result; | ||
| 1073 | + }; | ||
| 1052 | auto runner = [](aclrtStream, void* data) -> aclnnStatus { | 1074 | auto runner = [](aclrtStream, void* data) -> aclnnStatus { |
| 1053 | Record record; | 1075 | Record record; |
| 1054 | std::memcpy(&record, data, sizeof(record)); | 1076 | std::memcpy(&record, data, sizeof(record)); |
| @@ -1061,13 +1083,13 @@ TEST(DirectInvokeTaskTest, CacheAssociatesDfxWithMixedTasksAndStopsOnError) | |||
| 1061 | }; | 1083 | }; |
| 1062 | auto add = [&](int id, bool hasDfx, aclnnStatus result) { | 1084 | auto add = [&](int id, bool hasDfx, aclnnStatus result) { |
| 1063 | size_t offset = 0, capacity = 0; | 1085 | size_t offset = 0, capacity = 0; |
| 1064 | - cache.NewLaunchCache(&offset, &capacity, runner, | 1086 | + cache.NewLaunchCache(&offset, &capacity, runner, hasDfx ? op::AI_CORE : op::DIRECT_INVOKE); |
| 1065 | - hasDfx ? op::AI_CORE : op::DIRECT_INVOKE); | ||
| 1066 | const Record record{&order, id, hasDfx ? static_cast<uint32_t>(id * 10) : 0U, result}; | 1087 | const Record record{&order, id, hasDfx ? static_cast<uint32_t>(id * 10) : 0U, result}; |
| 1067 | std::memcpy(cache.AddLaunchData(sizeof(record)), &record, sizeof(record)); | 1088 | std::memcpy(cache.AddLaunchData(sizeof(record)), &record, sizeof(record)); |
| 1068 | if (hasDfx) { | 1089 | if (hasDfx) { |
| 1069 | cache.SetBlockDim(record.blocks); | 1090 | cache.SetBlockDim(record.blocks); |
| 1070 | cache.opExecCacheDfx_->SetProfilingInfoId(ProfilingInfoId(0, 0, id)); | 1091 | cache.opExecCacheDfx_->SetProfilingInfoId(ProfilingInfoId(0, 0, id)); |
| 1092 | + cache.opExecCacheDfx_->SetOpType(static_cast<uint32_t>(id)); | ||
| 1071 | TaskInfo info{}; | 1093 | TaskInfo info{}; |
| 1072 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; | 1094 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; |
| 1073 | cache.opExecCacheDfx_->SetTaskInfo(info); | 1095 | cache.opExecCacheDfx_->SetTaskInfo(info); |
| @@ -1116,17 +1138,19 @@ TEST(DirectInvokeTaskTest, FrameworkDfxClosesProfilingOnRunnerFailure) | |||
| 1116 | char buffer[32]{}; | 1138 | char buffer[32]{}; |
| 1117 | cache.SetCacheBuf(buffer); | 1139 | cache.SetCacheBuf(buffer); |
| 1118 | size_t offset = 0, capacity = 0; | 1140 | size_t offset = 0, capacity = 0; |
| 1119 | - cache.NewLaunchCache(&offset, &capacity, | 1141 | + cache.NewLaunchCache(&offset, &capacity, [](aclrtStream, void*) -> aclnnStatus { return ACLNN_ERR_INNER; }); |
| 1120 | - [](aclrtStream, void*) -> aclnnStatus { return ACLNN_ERR_INNER; }); | ||
| 1121 | cache.SetBlockDim(32); | 1142 | cache.SetBlockDim(32); |
| 1122 | cache.opExecCacheDfx_->SetProfilingInfoId(ProfilingInfoId(0, 0, 42)); | 1143 | cache.opExecCacheDfx_->SetProfilingInfoId(ProfilingInfoId(0, 0, 42)); |
| 1123 | bool submitted = false; | 1144 | bool submitted = false; |
| 1124 | - cache.NewLaunchCache(&offset, &capacity, [](aclrtStream, void* data) -> aclnnStatus { | 1145 | + cache.NewLaunchCache( |
| 1125 | - bool* flag = nullptr; | 1146 | + &offset, &capacity, |
| 1126 | - std::memcpy(&flag, data, sizeof(flag)); | 1147 | + [](aclrtStream, void* data) -> aclnnStatus { |
| 1127 | - *flag = true; | 1148 | + bool* flag = nullptr; |
| 1128 | - return ACLNN_SUCCESS; | 1149 | + std::memcpy(&flag, data, sizeof(flag)); |
| 1129 | - }, op::DIRECT_INVOKE); | 1150 | + *flag = true; |
| 1151 | + return ACLNN_SUCCESS; | ||
| 1152 | + }, | ||
| 1153 | + op::DIRECT_INVOKE); | ||
| 1130 | bool* flag = &submitted; | 1154 | bool* flag = &submitted; |
| 1131 | std::memcpy(cache.AddLaunchData(sizeof(flag)), &flag, sizeof(flag)); | 1155 | std::memcpy(cache.AddLaunchData(sizeof(flag)), &flag, sizeof(flag)); |
| 1132 | EXPECT_EQ(cache.Run(nullptr, nullptr, {}), ACLNN_ERR_INNER); | 1156 | EXPECT_EQ(cache.Run(nullptr, nullptr, {}), ACLNN_ERR_INNER); |
| @@ -1147,7 +1171,10 @@ TEST(DirectInvokeTaskTest, CacheRecordCapacityFailureReleasesPreparedState) | |||
| 1147 | cache.SetCacheBuf(buffer); | 1171 | cache.SetCacheBuf(buffer); |
| 1148 | cache.cacheCap_ = capacity; | 1172 | cache.cacheCap_ = capacity; |
| 1149 | cache.hashKey_ = 1; | 1173 | cache.hashKey_ = 1; |
| 1150 | - auto state = std::shared_ptr<void>(new int(1), [&](void* p) { ++destroyed; delete static_cast<int*>(p); }); | 1174 | + auto state = std::shared_ptr<void>(new int(1), [&](void* p) { |
| 1175 | + ++destroyed; | ||
| 1176 | + delete static_cast<int*>(p); | ||
| 1177 | + }); | ||
| 1151 | auto replay = std::make_shared<DirectInvokeReplay>(state); | 1178 | auto replay = std::make_shared<DirectInvokeReplay>(state); |
| 1152 | const int64_t dims[] = {4}, strides[] = {1}; | 1179 | const int64_t dims[] = {4}, strides[] = {1}; |
| 1153 | auto* scratch = aclCreateTensor(dims, 1, ACL_UINT8, strides, 0, ACL_FORMAT_ND, dims, 1, nullptr); | 1180 | auto* scratch = aclCreateTensor(dims, 1, ACL_UINT8, strides, 0, ACL_FORMAT_ND, dims, 1, nullptr); |
| @@ -1158,8 +1185,8 @@ TEST(DirectInvokeTaskTest, CacheRecordCapacityFailureReleasesPreparedState) | |||
| 1158 | ASSERT_TRUE(replay->Init(*args, cache)); | 1185 | ASSERT_TRUE(replay->Init(*args, cache)); |
| 1159 | DestroyOpArgContext(args); | 1186 | DestroyOpArgContext(args); |
| 1160 | aclDestroyTensorList(workspace); | 1187 | aclDestroyTensorList(workspace); |
| 1161 | - EXPECT_FALSE(DirectInvokeReplay::SaveToCache(cache, replay, | 1188 | + EXPECT_FALSE(DirectInvokeReplay::SaveToCache( |
| 1162 | - [](void*, const OpArgContext*, aclrtStream) noexcept { return ACLNN_SUCCESS; })); | 1189 | + cache, replay, [](void*, const OpArgContext*, aclrtStream) noexcept { return ACLNN_SUCCESS; })); |
| 1163 | EXPECT_FALSE(cache.IsOpCacheValid()); | 1190 | EXPECT_FALSE(cache.IsOpCacheValid()); |
| 1164 | } | 1191 | } |
| 1165 | EXPECT_EQ(destroyed, 2); | 1192 | EXPECT_EQ(destroyed, 2); |
| @@ -1195,8 +1222,10 @@ protected: | |||
| 1195 | tensors.input->SetFromWorkspace(false); | 1222 | tensors.input->SetFromWorkspace(false); |
| 1196 | tensors.output->SetFromWorkspace(false); | 1223 | tensors.output->SetFromWorkspace(false); |
| 1197 | // Include every prepare input, just as an L2 API does for AI Core. | 1224 | // Include every prepare input, just as an L2 API does for AI Core. |
| 1198 | - return op::internal::GetFromCache(executor, bytes, api_, | 1225 | + return op::internal::GetFromCache( |
| 1199 | - std::make_tuple(tensors.input.get(), static_cast<uint64_t>(config_.prepareStatus), | 1226 | + executor, bytes, api_, |
| 1227 | + std::make_tuple( | ||
| 1228 | + tensors.input.get(), static_cast<uint64_t>(config_.prepareStatus), | ||
| 1200 | static_cast<uint64_t>(config_.launchStatus), static_cast<uint64_t>(config_.workspaceSizes.size()), | 1229 | static_cast<uint64_t>(config_.launchStatus), static_cast<uint64_t>(config_.workspaceSizes.size()), |
| 1201 | config_.workspaceSizes.empty() ? uint64_t{0} : config_.workspaceSizes[0], | 1230 | config_.workspaceSizes.empty() ? uint64_t{0} : config_.workspaceSizes[0], |
| 1202 | config_.workspaceSizes.size() < 2 ? uint64_t{0} : config_.workspaceSizes[1], config_.requestNullSizes), | 1231 | config_.workspaceSizes.size() < 2 ? uint64_t{0} : config_.workspaceSizes[1], config_.requestNullSizes), |
| @@ -1208,9 +1237,10 @@ protected: | |||
| 1208 | auto owner = CREATE_EXECUTOR(); | 1237 | auto owner = CREATE_EXECUTOR(); |
| 1209 | auto* args = op::GetOpArgContext(OP_INPUT(tensors.input.get()), OP_OUTPUT(tensors.output.get()), | 1238 | auto* args = op::GetOpArgContext(OP_INPUT(tensors.input.get()), OP_OUTPUT(tensors.output.get()), |
| 1210 | FIXTURE_ATTR(config_), OP_WORKSPACE()); | 1239 | FIXTURE_ATTR(config_), OP_WORKSPACE()); |
| 1211 | - auto status = op::AddDirectInvokeTask("DirectInvokeFixture", DirectInvokeFixtureOpTypeId(), | 1240 | + auto status = op::AddDirectInvokeTask("DirectInvokeFixture", DirectInvokeFixtureOpTypeId(), PrepareFixture, |
| 1212 | - PrepareFixture, LaunchFixture, DestroyFixture, owner.get(), args); | 1241 | + LaunchFixture, DestroyFixture, owner.get(), args); |
| 1213 | - if (status != ACLNN_SUCCESS) return status; | 1242 | + if (status != ACLNN_SUCCESS) |
| 1243 | + return status; | ||
| 1214 | *bytes = owner->GetWorkspaceSize(); | 1244 | *bytes = owner->GetWorkspaceSize(); |
| 1215 | owner.ReleaseTo(executor); | 1245 | owner.ReleaseTo(executor); |
| 1216 | return ACLNN_SUCCESS; | 1246 | return ACLNN_SUCCESS; |
| @@ -1234,8 +1264,8 @@ TEST_F(DirectInvokeL2CacheTest, HitAfterExecutorDestructionReusesStateAndCurrent | |||
| 1234 | ASSERT_FALSE(Lookup(first, &executor, &bytes)); | 1264 | ASSERT_FALSE(Lookup(first, &executor, &bytes)); |
| 1235 | ASSERT_EQ(Register(first, &executor, &bytes), ACLNN_SUCCESS); | 1265 | ASSERT_EQ(Register(first, &executor, &bytes), ACLNN_SUCCESS); |
| 1236 | firstWorkspace.resize(bytes); | 1266 | firstWorkspace.resize(bytes); |
| 1237 | - ASSERT_EQ(CommonOpExecutorRun(firstWorkspace.data(), bytes, executor, | 1267 | + ASSERT_EQ(CommonOpExecutorRun(firstWorkspace.data(), bytes, executor, reinterpret_cast<aclrtStream>(0x2468)), |
| 1238 | - reinterpret_cast<aclrtStream>(0x2468)), ACLNN_SUCCESS); | 1268 | + ACLNN_SUCCESS); |
| 1239 | preparedState = config_.observedState; | 1269 | preparedState = config_.observedState; |
| 1240 | EXPECT_EQ(config_.prepareCount, 1U); | 1270 | EXPECT_EQ(config_.prepareCount, 1U); |
| 1241 | EXPECT_EQ(config_.destroyCount, 0U); | 1271 | EXPECT_EQ(config_.destroyCount, 0U); |
| @@ -37,6 +37,8 @@ | |||
| 37 | #include "depends/platform/platform_stub.h" | 37 | #include "depends/platform/platform_stub.h" |
| 38 | #include "kernel_launcher.h" | 38 | #include "kernel_launcher.h" |
| 39 | #include "depends/acl/aclrt_stub.h" | 39 | #include "depends/acl/aclrt_stub.h" |
| 40 | +#include "op_dfx_internal.h" | ||
| 41 | +#include "depends/profiler/profiler_stub.h" | ||
| 40 | #include "test_comp_op_common.h" | 42 | #include "test_comp_op_common.h" |
| 41 | 43 | ||
| 42 | using namespace op; | 44 | using namespace op; |
| @@ -927,3 +929,184 @@ TEST_F(KernelLaunchUT, KernelLaunch_CaptureGetInfoFail_NormalOverflow) | |||
| 927 | CaptureGetInfoFailStub failStub; | 929 | CaptureGetInfoFailStub failStub; |
| 928 | TestLaunchWithCaptureStub(&failStub); | 930 | TestLaunchWithCaptureStub(&failStub); |
| 929 | } | 931 | } |
| 932 | + | ||
| 933 | +// ---- 算子级 profiling attr 测试用 stub ---- | ||
| 934 | + | ||
| 935 | +// 捕获 aclrtLaunchKernelWithHostArgs 收到的 kernel attrs | ||
| 936 | +class CaptureLaunchAttrStub : public AclrtStub { | ||
| 937 | +public: | ||
| 938 | + aclError aclrtLaunchKernelWithHostArgs(aclrtFuncHandle funcHandle, uint32_t blockDim, aclrtStream stream, | ||
| 939 | + aclrtLaunchKernelCfg* cfg, void* hostArgs, size_t argsSize, | ||
| 940 | + aclrtPlaceHolderInfo* placeHolderArray, size_t placeHolderNum) override | ||
| 941 | + { | ||
| 942 | + capturedAttrs_.assign(cfg->attrs, cfg->attrs + cfg->numAttrs); | ||
| 943 | + return ACL_SUCCESS; | ||
| 944 | + } | ||
| 945 | + | ||
| 946 | + bool HasEnableProfilingAttr() const | ||
| 947 | + { | ||
| 948 | + for (const auto& attr : capturedAttrs_) { | ||
| 949 | + if (attr.id == ACL_RT_LAUNCH_KERNEL_ATTR_ENABLE_PROFILING && attr.value.enableProfiling == 1) { | ||
[Major] 测试代码直接引用新版本 runtime/msprof 符号,缺少产品代码同款的编译期版本保护 产品代码对 ACL_RT_LAUNCH_KERNEL_ATTR_ENABLE_PROFILING 用 RUNTIME_VERSION_SUPPORT_OP_PROFILING 保护(rts_arg.cpp:230)、对 PROF_OP_MASK 用 #if defined 保护(op_dfx.cpp:151),而测试代码未做同等保护:本行及同文件对 value.enableProfiling 的引用、test_profiling.cpp:321 的 MSPROF_OPTYPE 与多处 PROF_OP_MASK 均直接使用。在 runtime/msprof 头文件低于 9.2.0 的配套环境编译 UT 会直接失败。建议为测试中这些引用增加与产品代码一致的宏保护或 stub 定义,保证低版本环境 UT 可编译。 (来自自动检视代理,以 gubaocheng 身份提交) ![]() ![]() | |||
| 950 | + return true; | ||
| 951 | + } | ||
| 952 | + } | ||
| 953 | + return false; | ||
| 954 | + } | ||
| 955 | + | ||
| 956 | + std::vector<aclrtLaunchKernelAttr> capturedAttrs_; | ||
| 957 | +}; | ||
| 958 | + | ||
| 959 | +// 可控制算子级查询返回值的 profiler 桩 | ||
| 960 | +class OpProfilingUtProfiler : public ProfilerStub { | ||
| 961 | +public: | ||
| 962 | + bool MsprofCheckOpSwitch(uint32_t type, const char* op, size_t len) override { return checkOpSwitchRet_; } | ||
| 963 | + | ||
| 964 | + bool checkOpSwitchRet_ = false; | ||
| 965 | +}; | ||
| 966 | + | ||
| 967 | +// 构造一个最小可用的 launch 配置;opType 决定算子级 profiling 是否命中该算子 | ||
| 968 | +static op::internal::KernelLaunchConfig MakeLaunchCfg(uint32_t opType) | ||
| 969 | +{ | ||
| 970 | + op::internal::KernelLaunchConfig launchCfg{}; | ||
| 971 | + launchCfg.funcHandle = (void*)0x12345678; | ||
| 972 | + launchCfg.numBlocks = 32; | ||
| 973 | + launchCfg.schemMode = 1; | ||
| 974 | + launchCfg.engineType = op::internal::LaunchKernelEngineType::NO_VECTOR_CORE; | ||
| 975 | + launchCfg.opType = opType; | ||
| 976 | + return launchCfg; | ||
| 977 | +} | ||
| 978 | + | ||
| 979 | +// 成对安装/卸载两个 fake,避免用例中途 return 导致泄漏 | ||
| 980 | +class OpProfilingAttrGuard { | ||
| 981 | +public: | ||
| 982 | + OpProfilingAttrGuard(CaptureLaunchAttrStub& aclrtStub, OpProfilingUtProfiler& profilerStub) | ||
| 983 | + : aclrtStub_(aclrtStub), profilerStub_(profilerStub) | ||
| 984 | + { | ||
| 985 | + AclrtStub::GetInstance()->Install(&aclrtStub_); | ||
| 986 | + ProfilerStub::GetInstance()->Install(&profilerStub_); | ||
| 987 | + } | ||
| 988 | + | ||
| 989 | + ~OpProfilingAttrGuard() | ||
| 990 | + { | ||
| 991 | + ProfilerStub::GetInstance()->UnInstall(); | ||
| 992 | + AclrtStub::GetInstance()->UnInstall(); | ||
| 993 | + } | ||
| 994 | + | ||
| 995 | + // 按 profSwitch 位启动 profiling(START 分支会重设四个上报旗标与算子级总闸) | ||
| 996 | + static int32_t StartProfiling(uint64_t profSwitch) | ||
| 997 | + { | ||
| 998 | + MsprofCommandHandle handle; | ||
| 999 | + handle.profSwitch = profSwitch; | ||
| 1000 | + handle.type = PROF_COMMANDHANDLE_TYPE_START; | ||
| 1001 | + return op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)); | ||
| 1002 | + } | ||
| 1003 | + | ||
| 1004 | + // 关闭总闸并复位全部上报旗标 | ||
| 1005 | + static int32_t StopProfiling() | ||
| 1006 | + { | ||
| 1007 | + MsprofCommandHandle handle; | ||
| 1008 | + handle.type = PROF_COMMANDHANDLE_TYPE_STOP; | ||
| 1009 | + return op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)); | ||
| 1010 | + } | ||
| 1011 | + | ||
| 1012 | + // 开启算子级总闸与 L0 上报旗标 | ||
| 1013 | + static int32_t EnableSpecifiedOpProfiling() { return StartProfiling(PROF_TASK_TIME_MASK | PROF_OP_MASK); } | ||
| 1014 | + | ||
| 1015 | +private: | ||
| 1016 | + CaptureLaunchAttrStub& aclrtStub_; | ||
| 1017 | + OpProfilingUtProfiler& profilerStub_; | ||
| 1018 | +}; | ||
| 1019 | + | ||
| 1020 | +TEST_F(KernelLaunchUT, op_profiling_attr_non_cache) | ||
| 1021 | +{ | ||
| 1022 | + const uint32_t opType = op::GenOpTypeId("Axpy"); | ||
| 1023 | + ASSERT_NE(opType, 0U); | ||
| 1024 | + | ||
| 1025 | + CaptureLaunchAttrStub aclrtStub; | ||
| 1026 | + OpProfilingUtProfiler profilerStub; | ||
| 1027 | + OpProfilingAttrGuard guard(aclrtStub, profilerStub); | ||
| 1028 | + profilerStub.checkOpSwitchRet_ = true; | ||
| 1029 | + OpProfilingAttrGuard::EnableSpecifiedOpProfiling(); | ||
| 1030 | + | ||
| 1031 | + op::Shape selfShape{100}; | ||
| 1032 | + op::Shape outShape{100}; | ||
| 1033 | + aclOpExecutor exe; | ||
| 1034 | + int64_t inputData[100]; | ||
| 1035 | + auto self = exe.AllocIntArray(inputData, 100); | ||
| 1036 | + auto out = exe.AllocTensor(outShape, op::DataType::DT_INT32); | ||
| 1037 | + auto inputTensor = exe.ConvertToTensor(self, op::DataType::DT_INT32); | ||
| 1038 | + auto ctx = op::MakeOpArgContext(OP_INPUT(inputTensor), OP_OUTPUT(out)); | ||
| 1039 | + | ||
| 1040 | + op::internal::ExpandableRtsArgBuffer buffer; | ||
| 1041 | + buffer.Init(TEST_LAUNCH_ARG_INIT_CAP, TEST_TILING_HOST_DATA_INIT_CAP); | ||
| 1042 | + op::internal::TilingData* tilingData = buffer.GetTilingDataPtr(); | ||
| 1043 | + tilingData->data_size_ = 60; | ||
| 1044 | + | ||
| 1045 | + op::internal::LaunchArgInfo argInfo(false, false, ctx); | ||
| 1046 | + op::internal::RtsArg arg(true, argInfo, &buffer); | ||
| 1047 | + arg.FillArgs(); | ||
| 1048 | + | ||
| 1049 | + op::internal::KernelLaunchConfig launchCfg = MakeLaunchCfg(opType); | ||
| 1050 | + | ||
| 1051 | + EXPECT_EQ(arg.LaunchKernel(nullptr, launchCfg), ACLNN_SUCCESS); | ||
| 1052 | + EXPECT_TRUE(aclrtStub.HasEnableProfilingAttr()); | ||
| 1053 | + | ||
| 1054 | + OpProfilingAttrGuard::StopProfiling(); | ||
| 1055 | +} | ||
| 1056 | + | ||
| 1057 | +TEST_F(KernelLaunchUT, op_profiling_attr_from_cache) | ||
| 1058 | +{ | ||
| 1059 | + const uint32_t opType = op::GenOpTypeId("Axpy"); | ||
| 1060 | + ASSERT_NE(opType, 0U); | ||
| 1061 | + | ||
| 1062 | + CaptureLaunchAttrStub aclrtStub; | ||
| 1063 | + OpProfilingUtProfiler profilerStub; | ||
| 1064 | + OpProfilingAttrGuard guard(aclrtStub, profilerStub); | ||
| 1065 | + profilerStub.checkOpSwitchRet_ = true; | ||
| 1066 | + OpProfilingAttrGuard::EnableSpecifiedOpProfiling(); | ||
| 1067 | + | ||
| 1068 | + op::internal::rtArgs_t rtArg{}; | ||
| 1069 | + op::internal::KernelLaunchConfig launchCfg = MakeLaunchCfg(opType); | ||
| 1070 | + | ||
| 1071 | + EXPECT_EQ(op::internal::LaunchArgCache::LaunchKernelFromCache(nullptr, rtArg, launchCfg), ACLNN_SUCCESS); | ||
| 1072 | + EXPECT_TRUE(aclrtStub.HasEnableProfilingAttr()); | ||
| 1073 | + | ||
| 1074 | + OpProfilingAttrGuard::StopProfiling(); | ||
| 1075 | +} | ||
| 1076 | + | ||
| 1077 | +TEST_F(KernelLaunchUT, op_profiling_attr_skip_when_switch_off) | ||
| 1078 | +{ | ||
| 1079 | + const uint32_t opType = op::GenOpTypeId("Axpy"); | ||
| 1080 | + ASSERT_NE(opType, 0U); | ||
| 1081 | + | ||
| 1082 | + CaptureLaunchAttrStub aclrtStub; | ||
| 1083 | + OpProfilingUtProfiler profilerStub; | ||
| 1084 | + OpProfilingAttrGuard guard(aclrtStub, profilerStub); | ||
| 1085 | + | ||
| 1086 | + op::internal::rtArgs_t rtArg{}; | ||
| 1087 | + op::internal::KernelLaunchConfig launchCfg = MakeLaunchCfg(opType); | ||
| 1088 | + | ||
| 1089 | + // 场景一:算子级总闸开启,但三个上报旗标全关 -> 不下发 | ||
| 1090 | + // (仅带 PROF_OP_MASK 的 START 只会点亮总闸,四个上报旗标均为 false) | ||
| 1091 | + profilerStub.checkOpSwitchRet_ = true; | ||
| 1092 | + EXPECT_EQ(OpProfilingAttrGuard::StartProfiling(PROF_OP_MASK), 0); | ||
| 1093 | + EXPECT_TRUE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 1094 | + EXPECT_EQ(op::internal::LaunchArgCache::LaunchKernelFromCache(nullptr, rtArg, launchCfg), ACLNN_SUCCESS); | ||
| 1095 | + EXPECT_FALSE(aclrtStub.HasEnableProfilingAttr()); | ||
| 1096 | + | ||
| 1097 | + // 场景二:L0 上报旗标开启,但算子级总闸关闭 -> 不下发 | ||
| 1098 | + // (只带 PROF_TASK_TIME_MASK 的 START 点亮 kernelLaunchFlag 而不点亮总闸) | ||
| 1099 | + EXPECT_EQ(OpProfilingAttrGuard::StartProfiling(PROF_TASK_TIME_MASK), 0); | ||
| 1100 | + EXPECT_FALSE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 1101 | + profilerStub.checkOpSwitchRet_ = true; | ||
| 1102 | + EXPECT_EQ(op::internal::LaunchArgCache::LaunchKernelFromCache(nullptr, rtArg, launchCfg), ACLNN_SUCCESS); | ||
| 1103 | + EXPECT_FALSE(aclrtStub.HasEnableProfilingAttr()); | ||
| 1104 | + | ||
| 1105 | + // 场景三:总闸开启、旗标开启,但该算子未命中配置 -> 不下发 | ||
| 1106 | + OpProfilingAttrGuard::EnableSpecifiedOpProfiling(); | ||
| 1107 | + profilerStub.checkOpSwitchRet_ = false; | ||
| 1108 | + EXPECT_EQ(op::internal::LaunchArgCache::LaunchKernelFromCache(nullptr, rtArg, launchCfg), ACLNN_SUCCESS); | ||
| 1109 | + EXPECT_FALSE(aclrtStub.HasEnableProfilingAttr()); | ||
| 1110 | + | ||
| 1111 | + OpProfilingAttrGuard::StopProfiling(); | ||
| 1112 | +} | ||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "gtest/gtest.h" | 11 | #include "gtest/gtest.h" |
| 12 | #include <array> | 12 | #include <array> |
| 13 | #include <memory> | 13 | #include <memory> |
| 14 | +#include <string> | ||
| 14 | 15 | ||
| 15 | #include "acl/acl.h" | 16 | #include "acl/acl.h" |
| 16 | #include "opdev/make_op_executor.h" | 17 | #include "opdev/make_op_executor.h" |
| @@ -30,6 +31,19 @@ public: | |||
| 30 | profiling_called = true; | 31 | profiling_called = true; |
| 31 | return 0; | 32 | return 0; |
| 32 | } | 33 | } |
| 34 | + | ||
| 35 | + bool MsprofCheckOpSwitch(uint32_t type, const char* op, size_t len) override | ||
| 36 | + { | ||
| 37 | + checkOpSwitchCalled_ = true; | ||
| 38 | + queriedType_ = type; | ||
| 39 | + queriedOpName_.assign(op, len); | ||
| 40 | + return checkOpSwitchRet_; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + bool checkOpSwitchRet_ = false; | ||
| 44 | + bool checkOpSwitchCalled_ = false; | ||
| 45 | + uint32_t queriedType_ = 0; | ||
| 46 | + std::string queriedOpName_; | ||
| 33 | }; | 47 | }; |
| 34 | static ProfilingUtProfiler prof; | 48 | static ProfilingUtProfiler prof; |
| 35 | 49 | ||
| @@ -145,7 +159,7 @@ TEST_F(ProfilingUt, l0_api_profiling) | |||
| 145 | 159 | ||
| 146 | TEST_F(ProfilingUt, kernel_launch_profiling) | 160 | TEST_F(ProfilingUt, kernel_launch_profiling) |
| 147 | { | 161 | { |
| 148 | - MsprofCommandHandle handle; | 162 | + MsprofCommandHandle handle{}; |
| 149 | 163 | ||
| 150 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_INVALID, nullptr, 0), -1); | 164 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_INVALID, nullptr, 0), -1); |
| 151 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, 0), -1); | 165 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, 0), -1); |
| @@ -154,10 +168,13 @@ TEST_F(ProfilingUt, kernel_launch_profiling) | |||
| 154 | op::internal::CollectProfilingStr("aaaaa"); | 168 | op::internal::CollectProfilingStr("aaaaa"); |
| 155 | 169 | ||
| 156 | profiling_called = false; | 170 | profiling_called = false; |
| 157 | - op::internal::opProfilingSwitch.reportFlag = true; | 171 | + // 以真实 START 回调点亮四个上报旗标与算子级总闸,供随后验证 STOP 会把它们一并复位 |
| 158 | - op::internal::opProfilingSwitch.kernelLaunchFlag = true; | 172 | + MsprofCommandHandle handleStart; |
| 159 | - op::internal::opProfilingSwitch.additionInfoFlag = true; | 173 | + handleStart.profSwitch = PROF_ACL_API_MASK | PROF_TASK_TIME_MASK | PROF_TASK_TIME_L1_MASK | PROF_TASK_TIME_L2_MASK | |
| 160 | - op::internal::opProfilingSwitch.level2ProfilingFlag = true; | 174 | + PROF_OP_MASK; |
| 175 | + handleStart.type = PROF_COMMANDHANDLE_TYPE_START; | ||
| 176 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handleStart, sizeof(MsprofCommandHandle)), 0); | ||
| 177 | + EXPECT_TRUE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 161 | 178 | ||
| 162 | vector<int64_t> shapeA = {2, 1, 32, 16}; | 179 | vector<int64_t> shapeA = {2, 1, 32, 16}; |
| 163 | aclDataType dtype1 = aclDataType::ACL_FLOAT16; | 180 | aclDataType dtype1 = aclDataType::ACL_FLOAT16; |
| @@ -193,6 +210,7 @@ TEST_F(ProfilingUt, kernel_launch_profiling) | |||
| 193 | EXPECT_EQ(op::internal::opProfilingSwitch.kernelLaunchFlag, false); | 210 | EXPECT_EQ(op::internal::opProfilingSwitch.kernelLaunchFlag, false); |
| 194 | EXPECT_EQ(op::internal::opProfilingSwitch.additionInfoFlag, false); | 211 | EXPECT_EQ(op::internal::opProfilingSwitch.additionInfoFlag, false); |
| 195 | EXPECT_EQ(op::internal::opProfilingSwitch.level2ProfilingFlag, false); | 212 | EXPECT_EQ(op::internal::opProfilingSwitch.level2ProfilingFlag, false); |
| 213 | + EXPECT_FALSE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 196 | handleStop.type = PROF_COMMANDHANDLE_TYPE_INIT; | 214 | handleStop.type = PROF_COMMANDHANDLE_TYPE_INIT; |
| 197 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handleStop, sizeof(MsprofCommandHandle)), 0); | 215 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handleStop, sizeof(MsprofCommandHandle)), 0); |
| 198 | EXPECT_EQ(op::internal::opProfilingSwitch.reportFlag, false); | 216 | EXPECT_EQ(op::internal::opProfilingSwitch.reportFlag, false); |
| @@ -262,3 +280,95 @@ TEST_F(ProfilingUt, GetTimeStampFlag) | |||
| 262 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | 280 | EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); |
| 263 | EXPECT_EQ(op::internal::opProfilingSwitch.timeStampFlag, false); | 281 | EXPECT_EQ(op::internal::opProfilingSwitch.timeStampFlag, false); |
| 264 | } | 282 | } |
| 283 | + | ||
| 284 | +TEST_F(ProfilingUt, specified_op_profiling_switch) | ||
| 285 | +{ | ||
| 286 | + // STOP 复位后为关闭 | ||
| 287 | + MsprofCommandHandle handleStop; | ||
| 288 | + handleStop.type = PROF_COMMANDHANDLE_TYPE_STOP; | ||
| 289 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handleStop, sizeof(MsprofCommandHandle)), 0); | ||
| 290 | + EXPECT_FALSE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 291 | + | ||
| 292 | + // START 携带 PROF_OP_MASK 位时使能 | ||
| 293 | + MsprofCommandHandle handle; | ||
| 294 | + handle.profSwitch = PROF_OP_MASK; | ||
| 295 | + handle.type = PROF_COMMANDHANDLE_TYPE_START; | ||
| 296 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | ||
| 297 | + EXPECT_TRUE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 298 | + | ||
| 299 | + // START 不带 PROF_OP_MASK 位时保持关闭 | ||
| 300 | + handle.profSwitch = PROF_ACL_API_MASK; | ||
| 301 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | ||
| 302 | + EXPECT_FALSE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 303 | + | ||
| 304 | + // STOP 再次复位 | ||
| 305 | + handle.type = PROF_COMMANDHANDLE_TYPE_STOP; | ||
| 306 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | ||
| 307 | + EXPECT_FALSE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 308 | +} | ||
| 309 | + | ||
| 310 | +TEST_F(ProfilingUt, check_specified_op_profiling) | ||
| 311 | +{ | ||
| 312 | + const uint32_t opType = op::GenOpTypeId("Axpy"); | ||
| 313 | + ASSERT_NE(opType, 0U); | ||
| 314 | + | ||
| 315 | + // 桩返回 true:查询结果透传为 true,且查询参数正确 | ||
| 316 | + prof.checkOpSwitchRet_ = true; | ||
| 317 | + prof.checkOpSwitchCalled_ = false; | ||
| 318 | + prof.queriedOpName_.clear(); | ||
| 319 | + EXPECT_TRUE(op::internal::CheckSpecifiedOpProfiling(opType)); | ||
| 320 | + EXPECT_TRUE(prof.checkOpSwitchCalled_); | ||
| 321 | + EXPECT_EQ(prof.queriedType_, static_cast<uint32_t>(MSPROF_OPTYPE)); | ||
| 322 | + EXPECT_EQ(prof.queriedOpName_, "Axpy"); | ||
| 323 | + | ||
| 324 | + // 桩返回 false:查询结果透传为 false | ||
| 325 | + prof.checkOpSwitchRet_ = false; | ||
| 326 | + EXPECT_FALSE(op::internal::CheckSpecifiedOpProfiling(opType)); | ||
| 327 | + EXPECT_EQ(prof.queriedOpName_, "Axpy"); | ||
| 328 | +} | ||
| 329 | + | ||
| 330 | +TEST_F(ProfilingUt, is_l0_and_tiling_profiling_enabled) | ||
| 331 | +{ | ||
| 332 | + const uint32_t opType = op::GenOpTypeId("Axpy"); | ||
| 333 | + ASSERT_NE(opType, 0U); | ||
| 334 | + MsprofCommandHandle handle; | ||
| 335 | + | ||
| 336 | + // 总闸关闭:保持原有上报行为,与桩返回值无关 | ||
| 337 | + handle.profSwitch = PROF_ACL_API_MASK | PROF_TASK_TIME_MASK; | ||
| 338 | + handle.type = PROF_COMMANDHANDLE_TYPE_START; | ||
| 339 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | ||
| 340 | + EXPECT_FALSE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 341 | + prof.checkOpSwitchRet_ = true; | ||
| 342 | + EXPECT_TRUE(op::internal::IsTilingProfilingEnabled(opType)); | ||
| 343 | + EXPECT_TRUE(op::internal::IsL0ProfilingEnabled(opType)); | ||
| 344 | + prof.checkOpSwitchRet_ = false; | ||
| 345 | + EXPECT_TRUE(op::internal::IsTilingProfilingEnabled(opType)); | ||
| 346 | + EXPECT_TRUE(op::internal::IsL0ProfilingEnabled(opType)); | ||
| 347 | + | ||
| 348 | + // 总闸开启且算子命中:上报 | ||
| 349 | + handle.profSwitch = PROF_ACL_API_MASK | PROF_TASK_TIME_MASK | PROF_OP_MASK; | ||
| 350 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | ||
| 351 | + EXPECT_TRUE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 352 | + prof.checkOpSwitchRet_ = true; | ||
| 353 | + EXPECT_TRUE(op::internal::IsTilingProfilingEnabled(opType)); | ||
| 354 | + EXPECT_TRUE(op::internal::IsL0ProfilingEnabled(opType)); | ||
| 355 | + | ||
| 356 | + // 总闸开启但算子未命中:不上报 | ||
| 357 | + prof.checkOpSwitchRet_ = false; | ||
| 358 | + EXPECT_FALSE(op::internal::IsTilingProfilingEnabled(opType)); | ||
| 359 | + EXPECT_FALSE(op::internal::IsL0ProfilingEnabled(opType)); | ||
| 360 | + | ||
| 361 | + // 上报旗标关闭:即使总闸开启且算子命中也不上报 | ||
| 362 | + handle.profSwitch = PROF_OP_MASK; | ||
| 363 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | ||
| 364 | + EXPECT_TRUE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 365 | + prof.checkOpSwitchRet_ = true; | ||
| 366 | + EXPECT_FALSE(op::internal::IsTilingProfilingEnabled(opType)); | ||
| 367 | + EXPECT_FALSE(op::internal::IsL0ProfilingEnabled(opType)); | ||
| 368 | + | ||
| 369 | + // 复位全局状态与桩状态,避免污染同一 fixture 内的后续用例 | ||
| 370 | + prof.checkOpSwitchRet_ = false; | ||
| 371 | + handle.type = PROF_COMMANDHANDLE_TYPE_STOP; | ||
| 372 | + EXPECT_EQ(op::internal::ProfilingCallBack(PROF_CTRL_SWITCH, &handle, sizeof(MsprofCommandHandle)), 0); | ||
| 373 | + EXPECT_FALSE(op::internal::IsSpecifiedOpProfilingEnabled()); | ||
| 374 | +} | ||
| @@ -40,7 +40,6 @@ static ProfilingCacheUtProfiler prof; | |||
| 40 | namespace op { | 40 | namespace op { |
| 41 | namespace internal { | 41 | namespace internal { |
| 42 | void CacheTensorInfo(const FVector<const aclTensor*>& inTensors, const FVector<const aclTensor*>& outTensors); | 42 | void CacheTensorInfo(const FVector<const aclTensor*>& inTensors, const FVector<const aclTensor*>& outTensors); |
| 43 | -void CacheDfxInfo(uint32_t numBlocks, const op::internal::ProfilingInfoId& id, const TaskInfo& taskInfo, bool isMemSet); | ||
| 44 | aclnnStatus DoReportAdditionInfo(void* infoLists, const TaskInfo& taskInfo, | 43 | aclnnStatus DoReportAdditionInfo(void* infoLists, const TaskInfo& taskInfo, |
| 45 | const op::internal::ProfilingInfoId& profilingInfoId); | 44 | const op::internal::ProfilingInfoId& profilingInfoId); |
| 46 | } // namespace internal | 45 | } // namespace internal |
| @@ -120,7 +119,12 @@ TEST_F(ProfilingCacheUt, test_cache_tensor_has_op_cache) | |||
| 120 | TaskInfo info; | 119 | TaskInfo info; |
| 121 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; | 120 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; |
| 122 | info.ration = 0; | 121 | info.ration = 0; |
| 123 | - CacheDfxInfo(32, id, info, false); | 122 | + const uint32_t opType = op::GenOpTypeId("Axpy"); |
| 123 | + ASSERT_NE(opType, 0U); | ||
| 124 | + CacheDfxInfo(32, id, info, false, opType); | ||
| 125 | + | ||
| 126 | + // opType 应被写入缓存 dfx,供缓存回放路径取用 | ||
| 127 | + EXPECT_EQ(opExecCache->opExecCacheDfx_->GetOpType(0), opType); | ||
| 124 | 128 | ||
| 125 | // release resource | 129 | // release resource |
| 126 | aclDestroyTensor(tensorIn); | 130 | aclDestroyTensor(tensorIn); |
| @@ -162,7 +166,12 @@ TEST_F(ProfilingCacheUt, test_cache_tensor_restore_and_report) | |||
| 162 | TaskInfo info; | 166 | TaskInfo info; |
| 163 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; | 167 | info.type = MSPROF_GE_TASK_TYPE_AI_CORE; |
| 164 | info.ration = 0; | 168 | info.ration = 0; |
| 165 | - CacheDfxInfo(32, id, info, false); | 169 | + const uint32_t opType = op::GenOpTypeId("Axpy"); |
| 170 | + ASSERT_NE(opType, 0U); | ||
| 171 | + CacheDfxInfo(32, id, info, false, opType); | ||
| 172 | + | ||
| 173 | + // opType 应被写入缓存 dfx,供缓存回放路径取用 | ||
| 174 | + EXPECT_EQ(opExecCache->opExecCacheDfx_->GetOpType(0), opType); | ||
| 166 | 175 | ||
| 167 | // test restore/report | 176 | // test restore/report |
| 168 | EXPECT_EQ(DoReportAdditionInfo(opExecCache->GetCacheTensorInfo(0), info, id), OK); | 177 | EXPECT_EQ(DoReportAdditionInfo(opExecCache->GetCacheTensorInfo(0), info, id), OK); |
| @@ -173,3 +182,28 @@ TEST_F(ProfilingCacheUt, test_cache_tensor_restore_and_report) | |||
| 173 | aclDestroyTensor(tensorOut); | 182 | aclDestroyTensor(tensorOut); |
| 174 | delete opExecCache; | 183 | delete opExecCache; |
| 175 | } | 184 | } |
| 185 | + | ||
| 186 | +TEST_F(ProfilingCacheUt, dfx_getters_out_of_range_return_default) | ||
| 187 | +{ | ||
| 188 | + // 未写入任何 DFX 数据时,各 getter 应返回确定的默认值,而不是越界访问 | ||
| 189 | + OpExecCacheDfx dfx; | ||
| 190 | + EXPECT_EQ(dfx.GetOpType(0), 0U); | ||
| 191 | + EXPECT_EQ(dfx.GetTaskType(0), MSPROF_GE_TASK_TYPE_INVALID); | ||
| 192 | + EXPECT_EQ(dfx.GetTaskInfo(0).type, MSPROF_GE_TASK_TYPE_INVALID); | ||
| 193 | + EXPECT_EQ(dfx.GetTaskInfo(0).ration, 0U); | ||
| 194 | + EXPECT_EQ(dfx.GetProfilingInfoId(0).summaryItemId_, 0U); | ||
| 195 | + EXPECT_EQ(dfx.GetExceptionDumpInfo(0).rtsArgsSize_, 0U); | ||
| 196 | + | ||
| 197 | + // 负下标同样按越界处理 | ||
| 198 | + EXPECT_EQ(dfx.GetOpType(-1), 0U); | ||
| 199 | + EXPECT_EQ(dfx.GetTaskType(-1), MSPROF_GE_TASK_TYPE_INVALID); | ||
| 200 | + | ||
| 201 | + // 写入后按 index 正常返回,越界下标仍返回默认值 | ||
| 202 | + TaskInfo validTaskInfo{}; | ||
| 203 | + validTaskInfo.type = MSPROF_GE_TASK_TYPE_AI_CORE; | ||
| 204 | + dfx.SetOpType(42U); | ||
| 205 | + dfx.SetTaskInfo(validTaskInfo); | ||
| 206 | + EXPECT_EQ(dfx.GetOpType(0), 42U); | ||
| 207 | + EXPECT_EQ(dfx.GetTaskType(0), MSPROF_GE_TASK_TYPE_AI_CORE); | ||
| 208 | + EXPECT_EQ(dfx.GetOpType(1), 0U); | ||
| 209 | +} | ||


[Major] 同一次 launch 重复执行算子级开关查询(全局互斥锁+跨符号调用)
本行 AddOpProfilingLaunchKernelAttr 内的 CheckSpecifiedOpProfiling 与上游 DoLaunchWithDfx(op_kernel.h)中 IsL0ProfilingEnabled 的判定会在同一次 launch 中各执行一次:每次都调用 OpTypeDict::ToString(内部持有 opTypeMutex 全局互斥锁,见 op_def.cpp:176-183)和 MsprofCheckOpSwitch 弱符号跨符号调用,且各自再打一条 OP_LOGI。多线程并发 launch 场景该全局锁成为热点,判定结果又完全重复。建议一次判定后随 KernelLaunchConfig 传递结果,或按 opType 缓存命中结果,避免每次 launch 的重复加锁与查询。
(来自自动检视代理,以 gubaocheng 身份提交)