Merged
增加deterministicLevel强一致性配置 #643
pengjiahao96Add on Jul 14
增加deterministicLevel强一致性配置 #643
Merged
Merged frompengjiahao96/opbasemasterintocann/opbasemaster
Total: 44 files changed+1444-670
| @@ -15,14 +15,14 @@ | |||
| 15 | 15 | ||
| 16 | namespace aclnnOpInfoRecord { | 16 | namespace aclnnOpInfoRecord { |
| 17 | struct OpCompilerOption { | 17 | struct OpCompilerOption { |
| 18 | - explicit OpCompilerOption(const std::string& impl_mode_v, bool deterministic_v = true) | 18 | + explicit OpCompilerOption(const std::string& impl_mode_v, uint8_t deterministic_v = true) |
| 19 | : impl_mode(impl_mode_v), deterministic(deterministic_v) | 19 | : impl_mode(impl_mode_v), deterministic(deterministic_v) |
| 20 | {} | 20 | {} |
| 21 | - explicit OpCompilerOption(const char* impl_mode_v, bool deterministic_v = true) | 21 | + explicit OpCompilerOption(const char* impl_mode_v, uint8_t deterministic_v = true) |
| 22 | : impl_mode(impl_mode_v), deterministic(deterministic_v) | 22 | : impl_mode(impl_mode_v), deterministic(deterministic_v) |
| 23 | {} | 23 | {} |
| 24 | std::string impl_mode; | 24 | std::string impl_mode; |
| 25 | - bool deterministic; | 25 | + uint8_t deterministic; |
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | struct OpKernelInfo { | 28 | struct OpKernelInfo { |
| @@ -259,7 +259,8 @@ int32_t OpInfoSerialize(const gert::TilingContext* ctx, const aclnnOpInfoRecord: | |||
| 259 | } | 259 | } |
| 260 | AddPlatformInfoToJson(jsonDebug, ctx); | 260 | AddPlatformInfoToJson(jsonDebug, ctx); |
| 261 | jsonDebug["impl_mode"] = opt.impl_mode; | 261 | jsonDebug["impl_mode"] = opt.impl_mode; |
| 262 | - jsonDebug["deterministic"] = opt.deterministic ? "true" : "false"; | 262 | + jsonDebug["deterministic"] = (opt.deterministic == 0U) ? "true" : "false"; |
| 263 | + jsonDebug["deterministic_level"] = opt.deterministic; | ||
| 263 | std::lock_guard<std::mutex> lck(g_opInfoStatisticsLck); | 264 | std::lock_guard<std::mutex> lck(g_opInfoStatisticsLck); |
| 264 | AddJsonToOpInfoCompile(jsonDebug); // dump json for compile, not needed "bin_type" and "bin_info" | 265 | AddJsonToOpInfoCompile(jsonDebug); // dump json for compile, not needed "bin_type" and "bin_info" |
| 265 | jsonDebug["bin_type"] = kernelInfo->bin_type; | 266 | jsonDebug["bin_type"] = kernelInfo->bin_type; |
| @@ -562,10 +562,9 @@ aclnnStatus OpKernelBin::InitTilingParseCtx() | |||
| 562 | ThreadCoreNum key(GetThreadLocalContext().opConfigInfo_.aicNum_, GetThreadLocalContext().opConfigInfo_.aivNum_); | 562 | ThreadCoreNum key(GetThreadLocalContext().opConfigInfo_.aicNum_, GetThreadLocalContext().opConfigInfo_.aivNum_); |
| 563 | auto f = [&ret, &key, this]() { | 563 | auto f = [&ret, &key, this]() { |
| 564 | auto p = std::make_unique<TilingParseCtxHolder>(); | 564 | auto p = std::make_unique<TilingParseCtxHolder>(); |
| 565 | - if (p->BuildTilingParseCtx( | 565 | + if (p->BuildTilingParseCtx(opType_, OpRunContextMgr::GetOpTilingFuncs(opType_), binJson_.GetVar(), |
| 566 | - opType_, OpRunContextMgr::GetOpTilingFuncs(opType_), binJson_.GetVar(), SocContext::GetPlatformInfo(), | 566 | + SocContext::GetPlatformInfo(), keyAndDetail_.implMode, |
| 567 | - aclnnOpInfoRecord::OpCompilerOption(keyAndDetail_.implMode, keyAndDetail_.deterministicFlag), | 567 | + aclnnOpInfoRecord::OpKernelInfo(binPath_, static_cast<int8_t>(binType_))) != OK) { |
| 568 | - aclnnOpInfoRecord::OpKernelInfo(binPath_, static_cast<int8_t>(binType_))) != OK) { | ||
| 569 | ret = ACLNN_ERR_RUNTIME_ERROR; | 568 | ret = ACLNN_ERR_RUNTIME_ERROR; |
| 570 | return; | 569 | return; |
| 571 | } | 570 | } |
| @@ -245,11 +245,13 @@ public: | |||
| 245 | { | 245 | { |
| 246 | if (op::internal::GetOpProfilingRecordArgFlag()) { | 246 | if (op::internal::GetOpProfilingRecordArgFlag()) { |
| 247 | gert::TilingContext* ctx = opRunCtx_.UpdateTilingCtx(opType, opJson, inputs, outputs, attrs); | 247 | gert::TilingContext* ctx = opRunCtx_.UpdateTilingCtx(opType, opJson, inputs, outputs, attrs); |
| 248 | - bool isDeterministicOn = GetThreadLocalContext().opConfigInfo_.isDeterministicOn_; | 248 | + auto opCompilerOpt = aclnnOpInfoRecord::OpCompilerOption( |
| 249 | - auto opts = aclnnOpInfoRecord::OpCompilerOption(implMode, isDeterministicOn); | 249 | + implMode, GetThreadLocalContext().opConfigInfo_.deterministicLevel_); |
| 250 | - OP_LOGI("Call ExeOptInfoStat, option %d %s. kernel info %d %s, deterministic is %d.", opts.deterministic, | 250 | + OP_LOGI("Call OpInfoSerialize, deterministic level %d, impl mode %s. kernel info %d %s.", |
| 251 | - opts.impl_mode.c_str(), kernelInfo.bin_type, kernelInfo.bin_info.c_str(), isDeterministicOn); | 251 | + opCompilerOpt.deterministic, opCompilerOpt.impl_mode.c_str(), kernelInfo.bin_type, |
| 252 | - aclnnOpInfoRecord::OpInfoSerialize(ctx, opts, &kernelInfo); | 252 | + kernelInfo.bin_info.c_str()); |
| 253 | + OP_CHECK_NO_RETURN(aclnnOpInfoRecord::OpInfoSerialize(ctx, opCompilerOpt, &kernelInfo) == 0, | ||
| 254 | + OP_LOGW("OpInfoSerialize return failed!")); | ||
| 253 | } | 255 | } |
| 254 | } | 256 | } |
| 255 | 257 | ||
| @@ -142,7 +142,7 @@ void SetCoreNum(const Json& opJson, fe::PlatFormInfos* platformInfo, uint32_t& c | |||
| 142 | aclnnStatus TilingParseCtxHolder::BuildTilingParseCtx(uint32_t opType, | 142 | aclnnStatus TilingParseCtxHolder::BuildTilingParseCtx(uint32_t opType, |
| 143 | const gert::OpImplKernelRegistry::OpImplFunctions* tilingFuncs, | 143 | const gert::OpImplKernelRegistry::OpImplFunctions* tilingFuncs, |
| 144 | const Json& opJson, fe::PlatFormInfos* platformInfo, | 144 | const Json& opJson, fe::PlatFormInfos* platformInfo, |
| 145 | - const aclnnOpInfoRecord::OpCompilerOption& compileOptions, | 145 | + const std::string& opImplModeStr, |
| 146 | const aclnnOpInfoRecord::OpKernelInfo& opKernelInfo) | 146 | const aclnnOpInfoRecord::OpKernelInfo& opKernelInfo) |
| 147 | { | 147 | { |
| 148 | if (tilingFuncs == nullptr) { | 148 | if (tilingFuncs == nullptr) { |
| @@ -161,7 +161,7 @@ aclnnStatus TilingParseCtxHolder::BuildTilingParseCtx(uint32_t opType, | |||
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | opTypeStr_ = OpTypeDict::ToString(opType).GetString(); | 163 | opTypeStr_ = OpTypeDict::ToString(opType).GetString(); |
| 164 | - compileOptions_ = compileOptions; | 164 | + opImplModeStr_ = opImplModeStr; |
| 165 | opKernelInfo_ = opKernelInfo; | 165 | opKernelInfo_ = opKernelInfo; |
| 166 | SetCoreNum(opJson, platformInfo, coreNum_); | 166 | SetCoreNum(opJson, platformInfo, coreNum_); |
| 167 | tilingParseInfo_.platformInfo_ = platformInfo; | 167 | tilingParseInfo_.platformInfo_ = platformInfo; |
| @@ -228,7 +228,7 @@ aclnnStatus TilingParseCtxHolder::BuildTilingParseCtx(uint32_t opType, | |||
| 228 | return ACLNN_SUCCESS; | 228 | return ACLNN_SUCCESS; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | -const aclnnOpInfoRecord::OpCompilerOption& TilingParseCtxHolder::GetCompileOptions() const { return compileOptions_; } | 231 | +const std::string& TilingParseCtxHolder::GetOpImplModeStr() const { return opImplModeStr_; } |
| 232 | 232 | ||
| 233 | const aclnnOpInfoRecord::OpKernelInfo* TilingParseCtxHolder::GetOpKernelInfo() const { return &opKernelInfo_; } | 233 | const aclnnOpInfoRecord::OpKernelInfo* TilingParseCtxHolder::GetOpKernelInfo() const { return &opKernelInfo_; } |
| 234 | 234 | ||
| @@ -42,10 +42,10 @@ public: | |||
| 42 | 42 | ||
| 43 | aclnnStatus BuildTilingParseCtx(uint32_t opType, const gert::OpImplKernelRegistry::OpImplFunctions* tilingFuncs, | 43 | aclnnStatus BuildTilingParseCtx(uint32_t opType, const gert::OpImplKernelRegistry::OpImplFunctions* tilingFuncs, |
| 44 | const nlohmann::json& opJson, fe::PlatFormInfos* platformInfo, | 44 | const nlohmann::json& opJson, fe::PlatFormInfos* platformInfo, |
| 45 | - const aclnnOpInfoRecord::OpCompilerOption& compileOptions, | 45 | + const std::string& opImplModeStr, |
| 46 | const aclnnOpInfoRecord::OpKernelInfo& opKernelInfo); | 46 | const aclnnOpInfoRecord::OpKernelInfo& opKernelInfo); |
| 47 | 47 | ||
| 48 | - const aclnnOpInfoRecord::OpCompilerOption& GetCompileOptions() const; | 48 | + const std::string& GetOpImplModeStr() const; |
| 49 | 49 | ||
| 50 | const aclnnOpInfoRecord::OpKernelInfo* GetOpKernelInfo() const; | 50 | const aclnnOpInfoRecord::OpKernelInfo* GetOpKernelInfo() const; |
| 51 | 51 | ||
| @@ -84,7 +84,7 @@ private: | |||
| 84 | 84 | ||
| 85 | std::string kernelName_; | 85 | std::string kernelName_; |
| 86 | std::string opTypeStr_; | 86 | std::string opTypeStr_; |
| 87 | - aclnnOpInfoRecord::OpCompilerOption compileOptions_{"", false}; | 87 | + std::string opImplModeStr_; |
| 88 | ComputeNodeInfo dummyComputeNodeInfo_; | 88 | ComputeNodeInfo dummyComputeNodeInfo_; |
| 89 | KernelExtendInfo dummyKernelInfo_; | 89 | KernelExtendInfo dummyKernelInfo_; |
| 90 | static constexpr size_t MAX_COMPILE_INFO_STRUCT_SIZE = 32 * 1024; | 90 | static constexpr size_t MAX_COMPILE_INFO_STRUCT_SIZE = 32 * 1024; |
| @@ -25,6 +25,7 @@ | |||
| 25 | #include "opdev/op_dfx.h" | 25 | #include "opdev/op_dfx.h" |
| 26 | #include "kernel_context_holder.h" | 26 | #include "kernel_context_holder.h" |
| 27 | #include "tiling_parse_ctx_holder.h" | 27 | #include "tiling_parse_ctx_holder.h" |
| 28 | +#include "thread_local_context.h" | ||
| 28 | #include "op_dfx_internal.h" | 29 | #include "op_dfx_internal.h" |
| 29 | 30 | ||
| 30 | namespace op { | 31 | namespace op { |
| @@ -133,12 +134,14 @@ public: | |||
| 133 | { | 134 | { |
| 134 | gert::TilingContext* ctx = PtrCastTo<gert::TilingContext>(tilingCtx_); | 135 | gert::TilingContext* ctx = PtrCastTo<gert::TilingContext>(tilingCtx_); |
| 135 | if (op::internal::GetOpProfilingRecordArgFlag()) { | 136 | if (op::internal::GetOpProfilingRecordArgFlag()) { |
| 136 | - OP_LOGI("Call ExeOptInfoStat, option %d %s. kernel info %d %s.", | 137 | + auto opCompilerOpt = aclnnOpInfoRecord::OpCompilerOption( |
| 137 | - tilingParseCtx->GetCompileOptions().deterministic, | 138 | + tilingParseCtx->GetOpImplModeStr(), GetThreadLocalContext().opConfigInfo_.deterministicLevel_); |
| 138 | - tilingParseCtx->GetCompileOptions().impl_mode.c_str(), tilingParseCtx->GetOpKernelInfo()->bin_type, | 139 | + OP_LOGI("Call OpInfoSerialize, deterministic level %d, impl mode %s. kernel info %d %s.", |
| 139 | - tilingParseCtx->GetOpKernelInfo()->bin_info.c_str()); | 140 | + opCompilerOpt.deterministic, opCompilerOpt.impl_mode.c_str(), |
| 140 | - aclnnOpInfoRecord::OpInfoSerialize(ctx, tilingParseCtx->GetCompileOptions(), | 141 | + tilingParseCtx->GetOpKernelInfo()->bin_type, tilingParseCtx->GetOpKernelInfo()->bin_info.c_str()); |
| 141 | - tilingParseCtx->GetOpKernelInfo()); | 142 | + OP_CHECK_NO_RETURN( |
| 143 | + aclnnOpInfoRecord::OpInfoSerialize(ctx, opCompilerOpt, tilingParseCtx->GetOpKernelInfo()) == 0, | ||
| 144 | + OP_LOGW("OpInfoSerialize return failed!")); | ||
| 142 | } | 145 | } |
| 143 | return ctx; | 146 | return ctx; |
| 144 | }; | 147 | }; |
| @@ -918,7 +918,8 @@ aclnnStatus NnopbaseAddSupportList(void* executor, OpSupportList* list, uint32_t | |||
| 918 | { | 918 | { |
| 919 | NNOPBASE_ASSERT_NOTNULL_RETVAL(executor); | 919 | NNOPBASE_ASSERT_NOTNULL_RETVAL(executor); |
| 920 | NNOPBASE_ASSERT_NOTNULL_RETVAL(list); | 920 | NNOPBASE_ASSERT_NOTNULL_RETVAL(list); |
| 921 | - NnopbaseExecutorAddSupportList((NnopbaseExecutor*)executor, list, socSupportList, socSupportListLen); | 921 | + NnopbaseExecutorAddSupportList(PtrCastTo<NnopbaseExecutor>(executor)->opCompatibility, list, socSupportList, |
| 922 | + socSupportListLen); | ||
| 922 | return OK; | 923 | return OK; |
| 923 | } | 924 | } |
| 924 | 925 | ||
| @@ -974,9 +975,11 @@ aclnnStatus NnopbaseAddSocNameList(void* executor, OpSupportList* list, const ch | |||
| 974 | } | 975 | } |
| 975 | NNOPBASE_ASSERT_RTOK_RETVAL(NnopbaseCheckCurrentSocMatch(socNameList, socNameListLen)); | 976 | NNOPBASE_ASSERT_RTOK_RETVAL(NnopbaseCheckCurrentSocMatch(socNameList, socNameListLen)); |
| 976 | NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor); | 977 | NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor); |
| 977 | - if (nnopExecutor->socSupportList != nullptr && | 978 | + auto& opCompatibility = nnopExecutor->opCompatibility; |
| 978 | - nnopExecutor->socSupportListLen == static_cast<uint32_t>(socNameListLen) && nnopExecutor->socSupportListOwned) { | 979 | + if (opCompatibility.supportedSocList != nullptr && |
| 979 | - NnopbaseExecutorAddSupportList(nnopExecutor, list, nnopExecutor->socSupportList, socNameListLen); | 980 | + opCompatibility.supportedSocCount == static_cast<uint32_t>(socNameListLen) && |
| 981 | + opCompatibility.ownsSupportedSocList) { | ||
| 982 | + NnopbaseExecutorAddSupportList(opCompatibility, list, opCompatibility.supportedSocList, socNameListLen, true); | ||
| 980 | return OK; | 983 | return OK; |
| 981 | } | 984 | } |
| 982 | const auto& indvSoc = nnopbase::IndvSoc::GetInstance(); | 985 | const auto& indvSoc = nnopbase::IndvSoc::GetInstance(); |
| @@ -985,11 +988,11 @@ aclnnStatus NnopbaseAddSocNameList(void* executor, OpSupportList* list, const ch | |||
| 985 | MAX_SOC_NAME_LIST_LEN); | 988 | MAX_SOC_NAME_LIST_LEN); |
| 986 | return ACLNN_ERR_PARAM_INVALID; | 989 | return ACLNN_ERR_PARAM_INVALID; |
| 987 | } | 990 | } |
| 988 | - if (nnopExecutor->socSupportListOwned) { | 991 | + if (opCompatibility.ownsSupportedSocList) { |
| 989 | - delete[] nnopExecutor->socSupportList; | 992 | + delete[] opCompatibility.supportedSocList; |
| 990 | } | 993 | } |
| 991 | - nnopExecutor->socSupportList = nullptr; | 994 | + opCompatibility.supportedSocList = nullptr; |
| 992 | - nnopExecutor->socSupportListOwned = false; | 995 | + opCompatibility.ownsSupportedSocList = false; |
| 993 | auto* enumList = new (std::nothrow) uint32_t[socNameListLen]; | 996 | auto* enumList = new (std::nothrow) uint32_t[socNameListLen]; |
| 994 | NNOPBASE_ASSERT_NOTNULL_RETVAL(enumList); | 997 | NNOPBASE_ASSERT_NOTNULL_RETVAL(enumList); |
| 995 | for (size_t i = 0U; i < socNameListLen; i++) { | 998 | for (size_t i = 0U; i < socNameListLen; i++) { |
| @@ -1000,10 +1003,7 @@ aclnnStatus NnopbaseAddSocNameList(void* executor, OpSupportList* list, const ch | |||
| 1000 | } | 1003 | } |
| 1001 | } | 1004 | } |
| 1002 | NnopbaseConvertSocNamesToEnums(indvSoc, socNameList, socNameListLen, enumList); | 1005 | NnopbaseConvertSocNamesToEnums(indvSoc, socNameList, socNameListLen, enumList); |
| 1003 | - nnopExecutor->socSupportList = enumList; | 1006 | + NnopbaseExecutorAddSupportList(opCompatibility, list, enumList, socNameListLen, true); |
| 1004 | - nnopExecutor->socSupportListLen = static_cast<uint32_t>(socNameListLen); | ||
| 1005 | - nnopExecutor->socSupportListOwned = true; | ||
| 1006 | - NnopbaseExecutorAddSupportList(nnopExecutor, list, enumList, socNameListLen); | ||
| 1007 | return OK; | 1007 | return OK; |
| 1008 | } | 1008 | } |
| 1009 | 1009 | ||
| @@ -1134,9 +1134,10 @@ const NnopbaseChar* NnopbaseFindStaticKernel(const aclTensor* tensors[], const N | |||
| 1134 | staticRuntimeInfo->implMode, staticRuntimeInfo->deterMode, valueDepend, | 1134 | staticRuntimeInfo->implMode, staticRuntimeInfo->deterMode, valueDepend, |
| 1135 | true); | 1135 | true); |
| 1136 | 1136 | ||
| 1137 | - NnopbaseCoreNum coreNum{staticRuntimeInfo->aicNum, staticRuntimeInfo->aivNum}; | 1137 | + StaticKernelPlatformInfo platformInfo{{staticRuntimeInfo->aicNum, staticRuntimeInfo->aivNum}, |
| 1138 | + static_cast<int8_t>(staticRuntimeInfo->deterMode)}; | ||
| 1138 | auto simplifiedKey = NnopbaseCollectorGetStaticKernelBin(regInfoKey.opType.c_str(), regInfoKey.hashKey, verbose, | 1139 | auto simplifiedKey = NnopbaseCollectorGetStaticKernelBin(regInfoKey.opType.c_str(), regInfoKey.hashKey, verbose, |
| 1139 | - uint32_t(verKey1 - verbose), &coreNum); | 1140 | + uint32_t(verKey1 - verbose), &platformInfo); |
| 1140 | if (simplifiedKey != nullptr) { | 1141 | if (simplifiedKey != nullptr) { |
| 1141 | return simplifiedKey; | 1142 | return simplifiedKey; |
| 1142 | } else { | 1143 | } else { |
| @@ -1146,7 +1147,7 @@ const NnopbaseChar* NnopbaseFindStaticKernel(const aclTensor* tensors[], const N | |||
| 1146 | staticRuntimeInfo->implMode, staticRuntimeInfo->deterMode, valueDepend, | 1147 | staticRuntimeInfo->implMode, staticRuntimeInfo->deterMode, valueDepend, |
| 1147 | false); | 1148 | false); |
| 1148 | return NnopbaseCollectorGetStaticKernelBin(regInfoKey.opType.c_str(), regInfoKey.hashKey, verbose, | 1149 | return NnopbaseCollectorGetStaticKernelBin(regInfoKey.opType.c_str(), regInfoKey.hashKey, verbose, |
| 1149 | - uint32_t(verKey2 - verbose), &coreNum); | 1150 | + uint32_t(verKey2 - verbose), &platformInfo); |
| 1150 | } | 1151 | } |
| 1151 | } | 1152 | } |
| 1152 | 1153 | ||
| @@ -1163,7 +1164,7 @@ aclnnStatus NnopbaseGetStreamAndEvent(const aclrtStream stream, aclrtStream* sub | |||
| 1163 | aclnnStatus NnopbaseSetMc2(void* const executor) | 1164 | aclnnStatus NnopbaseSetMc2(void* const executor) |
| 1164 | { | 1165 | { |
| 1165 | NNOPBASE_ASSERT_NOTNULL_RETVAL(executor); | 1166 | NNOPBASE_ASSERT_NOTNULL_RETVAL(executor); |
| 1166 | - ((NnopbaseExecutor*)executor)->mc2OpCfg.isMc2 = true; | 1167 | + ((NnopbaseExecutor*)executor)->mc2.enabled = true; |
| 1167 | bool needLoadDavidHcclApi = nnopbase::IndvSoc::GetInstance().SupportMc2FusionLaunch(); | 1168 | bool needLoadDavidHcclApi = nnopbase::IndvSoc::GetInstance().SupportMc2FusionLaunch(); |
| 1168 | if (needLoadDavidHcclApi) { | 1169 | if (needLoadDavidHcclApi) { |
| 1169 | const static aclnnStatus retVal = nnopbase::IndvMc2ClientWrapper::GetInstance().IndvMc2ClientWrapperInit( | 1170 | const static aclnnStatus retVal = nnopbase::IndvMc2ClientWrapper::GetInstance().IndvMc2ClientWrapperInit( |
| @@ -1181,10 +1182,10 @@ aclnnStatus NnopbaseSetMc2(void* const executor) | |||
| 1181 | aclnnStatus NnopbaseSetHcomGroup(void* const executor, char* const group) | 1182 | aclnnStatus NnopbaseSetHcomGroup(void* const executor, char* const group) |
| 1182 | { | 1183 | { |
| 1183 | NNOPBASE_ASSERT_NOTNULL_RETVAL(executor); | 1184 | NNOPBASE_ASSERT_NOTNULL_RETVAL(executor); |
| 1184 | - CHECK_COND(((NnopbaseExecutor*)executor)->mc2OpCfg.isMc2, ACLNN_ERR_PARAM_INVALID, | 1185 | + CHECK_COND(((NnopbaseExecutor*)executor)->mc2.enabled, ACLNN_ERR_PARAM_INVALID, |
| 1185 | "Failed to set Hcom group for %s, group is %p.", ((NnopbaseExecutor*)executor)->opType, group); | 1186 | "Failed to set Hcom group for %s, group is %p.", ((NnopbaseExecutor*)executor)->opType, group); |
| 1186 | if ((group == nullptr) || strcmp(group, "") == 0) { | 1187 | if ((group == nullptr) || strcmp(group, "") == 0) { |
| 1187 | - ((NnopbaseExecutor*)executor)->mc2OpCfg.hcomHandle.push_back(nullptr); | 1188 | + ((NnopbaseExecutor*)executor)->mc2.commHandles.push_back(nullptr); |
| 1188 | } else { | 1189 | } else { |
| 1189 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseSetMc2Tiling(((NnopbaseExecutor*)executor), group)); | 1190 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseSetMc2Tiling(((NnopbaseExecutor*)executor), group)); |
| 1190 | } | 1191 | } |
| @@ -1283,7 +1284,7 @@ bool NnopbaseMatchArgs(void* executor, uint64_t* workspaceLen) | |||
| 1283 | NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor); | 1284 | NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor); |
| 1284 | RecordNnopbaseTime(nnopExecutor, NnopbaseTimeIdx::kGetWsStart); | 1285 | RecordNnopbaseTime(nnopExecutor, NnopbaseTimeIdx::kGetWsStart); |
| 1285 | nnopbase::NnopbaseGetCoreNum(&nnopExecutor->coreNum.aicNum, &nnopExecutor->coreNum.aivNum); | 1286 | nnopbase::NnopbaseGetCoreNum(&nnopExecutor->coreNum.aicNum, &nnopExecutor->coreNum.aivNum); |
| 1286 | - nnopExecutor->deterministic = nnopbase::GetGlobalDeterministic(); | 1287 | + nnopExecutor->deterministicLevel = static_cast<uint8_t>(nnopbase::GetGlobalDeterministic()); |
| 1287 | NnopbaseUpdatePlatformInfo(nnopExecutor); | 1288 | NnopbaseUpdatePlatformInfo(nnopExecutor); |
| 1288 | if ((!g_nnopbaseSysCfgParams.enableArgsCache) || op::internal::GetOpProfilingRecordArgFlag()) { | 1289 | if ((!g_nnopbaseSysCfgParams.enableArgsCache) || op::internal::GetOpProfilingRecordArgFlag()) { |
| 1289 | nnopExecutor->ownArgs.enableCache = false; | 1290 | nnopExecutor->ownArgs.enableCache = false; |
| @@ -1298,7 +1299,7 @@ bool NnopbaseMatchArgs(void* executor, uint64_t* workspaceLen) | |||
| 1298 | key = Indv::CacheKeyBuilder::AppendCoreNum(&nnopExecutor->ownArgs, &nnopExecutor->coreNum); | 1299 | key = Indv::CacheKeyBuilder::AppendCoreNum(&nnopExecutor->ownArgs, &nnopExecutor->coreNum); |
| 1299 | uint32_t mc2RankId = nnopbase::utils::ThreadVarContainer::GetCurMc2RankIdInThread(); | 1300 | uint32_t mc2RankId = nnopbase::utils::ThreadVarContainer::GetCurMc2RankIdInThread(); |
| 1300 | key = Indv::CacheKeyBuilder::AppendMc2RankId(&nnopExecutor->ownArgs, &mc2RankId); | 1301 | key = Indv::CacheKeyBuilder::AppendMc2RankId(&nnopExecutor->ownArgs, &mc2RankId); |
| 1301 | - key = Indv::CacheKeyBuilder::AppendDeterministic(&nnopExecutor->ownArgs, &(nnopExecutor->deterministic)); | 1302 | + key = Indv::CacheKeyBuilder::AppendDeterministicLevel(&nnopExecutor->ownArgs, &(nnopExecutor->deterministicLevel)); |
| 1302 | nnopExecutor->ownArgs.seed = NnopbaseHashBinary(PtrCastTo<NnopbaseUChar>(nnopExecutor->ownArgs.inputKey.data()), | 1303 | nnopExecutor->ownArgs.seed = NnopbaseHashBinary(PtrCastTo<NnopbaseUChar>(nnopExecutor->ownArgs.inputKey.data()), |
| 1303 | nnopExecutor->ownArgs.keyLen); | 1304 | nnopExecutor->ownArgs.keyLen); |
| 1304 | if (nnopbase::ArgsPool::GetInstance().MatchArgs(nnopExecutor)) { | 1305 | if (nnopbase::ArgsPool::GetInstance().MatchArgs(nnopExecutor)) { |
| @@ -15,7 +15,7 @@ | |||
| 15 | static inline NnopbaseUChar* NnopbasePrepareDimInfo(NnopbaseUChar* addr, const GertShape& shape) | 15 | static inline NnopbaseUChar* NnopbasePrepareDimInfo(NnopbaseUChar* addr, const GertShape& shape) |
| 16 | { | 16 | { |
| 17 | const int64_t shapeSize = shape.GetShapeSize(); | 17 | const int64_t shapeSize = shape.GetShapeSize(); |
| 18 | - if (shapeSize > 0) { // 非空tensor场景 | 18 | + if (shapeSize > 0) { // 非空tensor场景 |
| 19 | const size_t dimNum = shape.GetDimNum(); | 19 | const size_t dimNum = shape.GetDimNum(); |
| 20 | if (dimNum == 0U) { // Scalar场景相当于shape={1}的tensor | 20 | if (dimNum == 0U) { // Scalar场景相当于shape={1}的tensor |
| 21 | addr = nnopbase::NnopbaseAppendByte<uint64_t>(addr, 1ULL); | 21 | addr = nnopbase::NnopbaseAppendByte<uint64_t>(addr, 1ULL); |
| @@ -73,13 +73,13 @@ static void NnopbaseExecutorPrepareIOSize(const NnopbaseExecutor* const executor | |||
| 73 | 73 | ||
| 74 | static void NnopbaseExecutorSetDfxInfo(const NnopbaseExecutor* const executor) | 74 | static void NnopbaseExecutorSetDfxInfo(const NnopbaseExecutor* const executor) |
| 75 | { | 75 | { |
| 76 | - size_t startIndex = executor->mc2OpCfg.hcomHandle.size(); | 76 | + size_t startIndex = executor->mc2.commHandles.size(); |
| 77 | NnopbaseUChar* addr = op::internal::PtrCastTo<NnopbaseUChar>(&(executor->args->dfxInfo[startIndex])); | 77 | NnopbaseUChar* addr = op::internal::PtrCastTo<NnopbaseUChar>(&(executor->args->dfxInfo[startIndex])); |
| 78 | const auto workspacesSizes = NnopbaseGetWorkspacesSizesFromArgs(executor->args); | 78 | const auto workspacesSizes = NnopbaseGetWorkspacesSizesFromArgs(executor->args); |
| 79 | const uint32_t workspaceNum = workspacesSizes->GetSize() == 0UL ? 1U : | 79 | const uint32_t workspaceNum = workspacesSizes->GetSize() == 0UL ? 1U : |
| 80 | static_cast<uint32_t>(workspacesSizes->GetSize()); | 80 | static_cast<uint32_t>(workspacesSizes->GetSize()); |
| 81 | uint32_t oomNum = executor->args->inputs.paramDescs.count + executor->args->outputs.paramDescs.count + | 81 | uint32_t oomNum = executor->args->inputs.paramDescs.count + executor->args->outputs.paramDescs.count + |
| 82 | - workspaceNum + executor->mc2OpCfg.hcomHandle.size(); | 82 | + workspaceNum + executor->mc2.commHandles.size(); |
| 83 | if (executor->args->outputs.outPutShapeSize != 0U) { | 83 | if (executor->args->outputs.outPutShapeSize != 0U) { |
| 84 | oomNum += 1U; | 84 | oomNum += 1U; |
| 85 | } | 85 | } |
| @@ -142,7 +142,7 @@ static void NnopbaseExecutorGetOutputShapeInfoSize(const NnopbaseTensors& tensor | |||
| 142 | } | 142 | } |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | -void NnopbaseExecutorPrepareDfxInfo(NnopbaseExecutor* executor) | 145 | +void NnopbaseExecutorPrepareDfxInfo(NnopbaseExecutor* const executor) |
| 146 | { | 146 | { |
| 147 | // workspace num为0时,args中需要占位 | 147 | // workspace num为0时,args中需要占位 |
| 148 | const auto workspacesSizes = NnopbaseGetWorkspacesSizesFromArgs(executor->args); | 148 | const auto workspacesSizes = NnopbaseGetWorkspacesSizesFromArgs(executor->args); |
| @@ -152,7 +152,7 @@ void NnopbaseExecutorPrepareDfxInfo(NnopbaseExecutor* executor) | |||
| 152 | NnopbaseExecutorGetInputShapeInfoSize(executor->args->inputs, space); | 152 | NnopbaseExecutorGetInputShapeInfoSize(executor->args->inputs, space); |
| 153 | NnopbaseExecutorGetOutputShapeInfoSize(executor->args->outputs, executor->args->outputs.outPutShapeMap, space); | 153 | NnopbaseExecutorGetOutputShapeInfoSize(executor->args->outputs, executor->args->outputs.outPutShapeMap, space); |
| 154 | space += (executor->args->inputs.paramDescs.count + executor->args->outputs.paramDescs.count + workspaceNum + | 154 | space += (executor->args->inputs.paramDescs.count + executor->args->outputs.paramDescs.count + workspaceNum + |
| 155 | - executor->mc2OpCfg.hcomHandle.size()); | 155 | + executor->mc2.commHandles.size()); |
| 156 | if (executor->args->outputs.outPutShapeSize != 0U) { | 156 | if (executor->args->outputs.outPutShapeSize != 0U) { |
| 157 | space += 1U; | 157 | space += 1U; |
| 158 | } | 158 | } |
| @@ -161,18 +161,18 @@ void NnopbaseExecutorPrepareDfxInfo(NnopbaseExecutor* executor) | |||
| 161 | NnopbaseExecutorSetDfxInfo(executor); | 161 | NnopbaseExecutorSetDfxInfo(executor); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | -aclnnStatus NnopbaseExecutorArgsGetDfxInfo(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr, | 164 | +aclnnStatus NnopbaseExecutorArgsGetDfxInfo(NnopbaseExecutor* const executor, NnopbaseExecutorArgsAddr* const argsAddr, |
| 165 | const uint32_t workspaceNum) | 165 | const uint32_t workspaceNum) |
| 166 | { | 166 | { |
| 167 | if (executor->args->dfxInfo.empty()) { | 167 | if (executor->args->dfxInfo.empty()) { |
| 168 | NnopbaseExecutorPrepareDfxInfo(executor); | 168 | NnopbaseExecutorPrepareDfxInfo(executor); |
| 169 | } | 169 | } |
| 170 | - for (size_t i = 0U; i < executor->contextAddr.size(); i++) { | 170 | + for (size_t i = 0U; i < executor->mc2.contextAddrs.size(); i++) { |
| 171 | executor->args->dfxInfo[i] = 32U; | 171 | executor->args->dfxInfo[i] = 32U; |
| 172 | } | 172 | } |
| 173 | if (executor->args->binInfo->oomFlag) { | 173 | if (executor->args->binInfo->oomFlag) { |
| 174 | uint32_t oomSize = (executor->args->inputs.paramDescs.count + executor->args->outputs.paramDescs.count + | 174 | uint32_t oomSize = (executor->args->inputs.paramDescs.count + executor->args->outputs.paramDescs.count + |
| 175 | - workspaceNum + executor->contextAddr.size()) * | 175 | + workspaceNum + executor->mc2.contextAddrs.size()) * |
| 176 | sizeof(void*); | 176 | sizeof(void*); |
| 177 | if (executor->args->outputs.outPutShapeSize != 0U) { | 177 | if (executor->args->outputs.outPutShapeSize != 0U) { |
| 178 | oomSize += sizeof(void*); | 178 | oomSize += sizeof(void*); |
| @@ -221,12 +221,12 @@ static void NnopbaseExecutorGetDynamicTensorSize(NnopbaseTensors& tensors) | |||
| 221 | } | 221 | } |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | -size_t NnopbaseCalcArgsSize(NnopbaseExecutor* executor, const size_t tilingDataSize) | 224 | +size_t NnopbaseCalcArgsSize(NnopbaseExecutor* const executor, const size_t tilingDataSize) |
| 225 | { | 225 | { |
| 226 | // mc2算子多了个NnopbaseHcclCommParamDesc、hcomHandle.size()个context addr | 226 | // mc2算子多了个NnopbaseHcclCommParamDesc、hcomHandle.size()个context addr |
| 227 | - const size_t mc2Size = executor->mc2OpCfg.isMc2 ? executor->mc2OpCfg.hcomHandle.size() * sizeof(void*) + | 227 | + const size_t mc2Size = executor->mc2.enabled ? |
| 228 | - sizeof(NnopbaseHcclCommParamDesc) : | 228 | + executor->mc2.commHandles.size() * sizeof(void*) + sizeof(NnopbaseHcclCommParamDesc) : |
| 229 | - 0U; | 229 | + 0U; |
| 230 | const size_t irNum = static_cast<size_t>(executor->args->inputs.paramDescs.count + | 230 | const size_t irNum = static_cast<size_t>(executor->args->inputs.paramDescs.count + |
| 231 | executor->args->outputs.paramDescs.count); | 231 | executor->args->outputs.paramDescs.count); |
| 232 | // tiling前workspace先按最大申请,input, output, workspaces, 3 for tiling, overflow, ctrlAddr | 232 | // tiling前workspace先按最大申请,input, output, workspaces, 3 for tiling, overflow, ctrlAddr |
| @@ -234,7 +234,7 @@ size_t NnopbaseCalcArgsSize(NnopbaseExecutor* executor, const size_t tilingDataS | |||
| 234 | executor->args->tilingDataOffset = argsLen; | 234 | executor->args->tilingDataOffset = argsLen; |
| 235 | if (executor->args->outputs.outPutShapeSize != 0U) { | 235 | if (executor->args->outputs.outPutShapeSize != 0U) { |
| 236 | executor->args->tilingDataOffset += sizeof(void*); | 236 | executor->args->tilingDataOffset += sizeof(void*); |
| 237 | - argsLen += sizeof(void*) * 2; // 2 is outputshape and oom | 237 | + argsLen += sizeof(void*) * 2; // 2 is outputshape and oom |
| 238 | } | 238 | } |
| 239 | argsLen += (irNum + NNOPBASE_NORM_MAX_WORKSPACE_NUMS + 1) * sizeof(void*); // oom, 1 is for automicIndex | 239 | argsLen += (irNum + NNOPBASE_NORM_MAX_WORKSPACE_NUMS + 1) * sizeof(void*); // oom, 1 is for automicIndex |
| 240 | if (executor->hasTiling) { | 240 | if (executor->hasTiling) { |
| @@ -243,24 +243,24 @@ size_t NnopbaseCalcArgsSize(NnopbaseExecutor* executor, const size_t tilingDataS | |||
| 243 | argsLen += (tilingDataSize + executor->args->inputs.dynamicSize + executor->args->outputs.dynamicSize); | 243 | argsLen += (tilingDataSize + executor->args->inputs.dynamicSize + executor->args->outputs.dynamicSize); |
| 244 | } | 244 | } |
| 245 | if ((executor->args->inputs.hostInputNum > 0) || executor->args->inputs.hasDynamic || | 245 | if ((executor->args->inputs.hostInputNum > 0) || executor->args->inputs.hasDynamic || |
| 246 | - executor->args->outputs.hasDynamic || (executor->mc2OpCfg.isMc2 && executor->hasTiling)) { | 246 | + executor->args->outputs.hasDynamic || (executor->mc2.enabled && executor->hasTiling)) { |
| 247 | executor->argsExt.hostInputInfoNum = executor->args->inputs.hostInputNum + | 247 | executor->argsExt.hostInputInfoNum = executor->args->inputs.hostInputNum + |
| 248 | static_cast<uint16_t>(executor->args->inputs.dynamicNum + | 248 | static_cast<uint16_t>(executor->args->inputs.dynamicNum + |
| 249 | executor->args->outputs.dynamicNum); | 249 | executor->args->outputs.dynamicNum); |
| 250 | // MC2算子aicore和aicpu各一份hostInfo | 250 | // MC2算子aicore和aicpu各一份hostInfo |
| 251 | - const size_t hostInfoNum = executor->mc2OpCfg.isMc2 ? 2U : 1U; | 251 | + const size_t hostInfoNum = executor->mc2.enabled ? 2U : 1U; |
| 252 | const size_t alignHostInputSize = ((executor->args->inputs.hostInputSize + NNOPBASE_SEVENS_BYTES) / | 252 | const size_t alignHostInputSize = ((executor->args->inputs.hostInputSize + NNOPBASE_SEVENS_BYTES) / |
| 253 | NNOPBASE_EIGHT_BYTES) * | 253 | NNOPBASE_EIGHT_BYTES) * |
| 254 | NNOPBASE_EIGHT_BYTES; | 254 | NNOPBASE_EIGHT_BYTES; |
| 255 | argsLen += (executor->argsExt.hostInputInfoNum * sizeof(rtHostInputInfo_t) * hostInfoNum) + alignHostInputSize; | 255 | argsLen += (executor->argsExt.hostInputInfoNum * sizeof(rtHostInputInfo_t) * hostInfoNum) + alignHostInputSize; |
| 256 | - if (executor->mc2OpCfg.isMc2 && executor->hasTiling) { | 256 | + if (executor->mc2.enabled && executor->hasTiling) { |
| 257 | argsLen += sizeof(rtHostInputInfo_t); // aicpuArgs需要存tilingdata hostinfo | 257 | argsLen += sizeof(rtHostInputInfo_t); // aicpuArgs需要存tilingdata hostinfo |
| 258 | } | 258 | } |
| 259 | } | 259 | } |
| 260 | - if (executor->mc2OpCfg.isMc2) { | 260 | + if (executor->mc2.enabled) { |
| 261 | argsLen += NNOPBASE_AICPU_PARAM_LEN * 2; // 2 is soname/kernelname | 261 | argsLen += NNOPBASE_AICPU_PARAM_LEN * 2; // 2 is soname/kernelname |
| 262 | argsLen += (strlen(executor->opType) + NNOPBASE_MC2_AICPU_SUFFIX.length()); | 262 | argsLen += (strlen(executor->opType) + NNOPBASE_MC2_AICPU_SUFFIX.length()); |
| 263 | - if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType)) { | 263 | + if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { |
| 264 | argsLen += sizeof(NnopbaseHcclCommParamDesc); // 82上parsmdesc组在args最后 | 264 | argsLen += sizeof(NnopbaseHcclCommParamDesc); // 82上parsmdesc组在args最后 |
| 265 | } | 265 | } |
| 266 | } | 266 | } |
| @@ -268,8 +268,9 @@ size_t NnopbaseCalcArgsSize(NnopbaseExecutor* executor, const size_t tilingDataS | |||
| 268 | return argsLen; | 268 | return argsLen; |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | -static void NnopbaseExecutorEncodeDynamicTensors(NnopbaseExecutorArgsAddr* argsAddr, NnopbaseExecutor* const executor, | 271 | +static void NnopbaseExecutorEncodeDynamicTensors(NnopbaseExecutorArgsAddr* const argsAddr, |
| 272 | - void** dynamicIOAddr, const NnopbaseParamInstance* paramInstance) | 272 | + NnopbaseExecutor* const executor, void** const dynamicIOAddr, |
| 273 | + const NnopbaseParamInstance* const paramInstance) | ||
| 273 | { | 274 | { |
| 274 | NnopbaseUChar** dynamicIOData = &argsAddr->hostInputData; | 275 | NnopbaseUChar** dynamicIOData = &argsAddr->hostInputData; |
| 275 | aclrtPlaceHolderInfo** dynamicIOInfo = &argsAddr->hostInputInfo; | 276 | aclrtPlaceHolderInfo** dynamicIOInfo = &argsAddr->hostInputInfo; |
| @@ -309,10 +310,10 @@ static void NnopbaseExecutorEncodeDynamicTensors(NnopbaseExecutorArgsAddr* argsA | |||
| 309 | (*dynamicIOInfo)->addrOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(dynamicIOAddr) - args); | 310 | (*dynamicIOInfo)->addrOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(dynamicIOAddr) - args); |
| 310 | (*dynamicIOInfo)->dataOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(*dynamicIOAddr) - args); | 311 | (*dynamicIOInfo)->dataOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(*dynamicIOAddr) - args); |
| 311 | (*dynamicIOInfo)++; | 312 | (*dynamicIOInfo)++; |
| 312 | - if ((executor->mc2OpCfg.isMc2) && | 313 | + if ((executor->mc2.enabled) && |
| 313 | - (!nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType))) { | 314 | + (!nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType))) { |
| 314 | aclrtPlaceHolderInfo** aicpuHostInputInfo = &argsAddr->aicpuHostInputInfo; | 315 | aclrtPlaceHolderInfo** aicpuHostInputInfo = &argsAddr->aicpuHostInputInfo; |
| 315 | - const NnopbaseUChar* const aicpuArgs = (NnopbaseUChar*)executor->aicpuArgs.args; | 316 | + const NnopbaseUChar* const aicpuArgs = (NnopbaseUChar*)executor->mc2.aicpuArgs.args; |
| 316 | (*aicpuHostInputInfo)->addrOffset = static_cast<uint32_t>( | 317 | (*aicpuHostInputInfo)->addrOffset = static_cast<uint32_t>( |
| 317 | op::internal::PtrCastTo<NnopbaseUChar>(dynamicIOAddr) - aicpuArgs); | 318 | op::internal::PtrCastTo<NnopbaseUChar>(dynamicIOAddr) - aicpuArgs); |
| 318 | (*aicpuHostInputInfo)->dataOffset = static_cast<uint32_t>( | 319 | (*aicpuHostInputInfo)->dataOffset = static_cast<uint32_t>( |
| @@ -349,10 +350,10 @@ static inline void NnopbaseExecutorEncodeHostInput(const NnopbaseExecutor* const | |||
| 349 | *inputAddr = *hostInputData; | 350 | *inputAddr = *hostInputData; |
| 350 | (*hostInputInfo)->addrOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(inputAddr) - args); | 351 | (*hostInputInfo)->addrOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(inputAddr) - args); |
| 351 | (*hostInputInfo)->dataOffset = static_cast<uint32_t>((*hostInputData) - args); | 352 | (*hostInputInfo)->dataOffset = static_cast<uint32_t>((*hostInputData) - args); |
| 352 | - if ((executor->mc2OpCfg.isMc2) && | 353 | + if ((executor->mc2.enabled) && |
| 353 | - (!nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType))) { | 354 | + (!nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType))) { |
| 354 | aclrtPlaceHolderInfo** aicpuHostInputInfo = &argsAddr->aicpuHostInputInfo; | 355 | aclrtPlaceHolderInfo** aicpuHostInputInfo = &argsAddr->aicpuHostInputInfo; |
| 355 | - const NnopbaseUChar* const aicpuArgs = (NnopbaseUChar*)executor->aicpuArgs.args; | 356 | + const NnopbaseUChar* const aicpuArgs = (NnopbaseUChar*)executor->mc2.aicpuArgs.args; |
| 356 | (*aicpuHostInputInfo)->addrOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(inputAddr) - | 357 | (*aicpuHostInputInfo)->addrOffset = static_cast<uint32_t>(op::internal::PtrCastTo<NnopbaseUChar>(inputAddr) - |
| 357 | aicpuArgs); | 358 | aicpuArgs); |
| 358 | (*aicpuHostInputInfo)->dataOffset = static_cast<uint32_t>((*hostInputData) - aicpuArgs); | 359 | (*aicpuHostInputInfo)->dataOffset = static_cast<uint32_t>((*hostInputData) - aicpuArgs); |
| @@ -363,8 +364,8 @@ static inline void NnopbaseExecutorEncodeHostInput(const NnopbaseExecutor* const | |||
| 363 | (*hostInputData) += size; | 364 | (*hostInputData) += size; |
| 364 | } | 365 | } |
| 365 | 366 | ||
| 366 | -void** NnopbaseExecutorPrepareInputsParamsExt(NnopbaseExecutor* executor, void** addr, | 367 | +void** NnopbaseExecutorPrepareInputsParamsExt(NnopbaseExecutor* const executor, void** addr, |
| 367 | - NnopbaseExecutorArgsAddr* argsAddr) | 368 | + NnopbaseExecutorArgsAddr* const argsAddr) |
| 368 | { | 369 | { |
| 369 | const NnopbaseUChar* const args = (NnopbaseUChar*)executor->argsExt.args; | 370 | const NnopbaseUChar* const args = (NnopbaseUChar*)executor->argsExt.args; |
| 370 | NnopbaseUChar** hostInputData = &argsAddr->hostInputData; | 371 | NnopbaseUChar** hostInputData = &argsAddr->hostInputData; |
| @@ -399,8 +400,8 @@ void** NnopbaseExecutorPrepareInputsParamsExt(NnopbaseExecutor* executor, void** | |||
| 399 | return addr; | 400 | return addr; |
| 400 | } | 401 | } |
| 401 | 402 | ||
| 402 | -void** NnopbaseExecutorPrepareOutputsParamsExt(NnopbaseExecutor* executor, void** addr, | 403 | +void** NnopbaseExecutorPrepareOutputsParamsExt(NnopbaseExecutor* const executor, void** addr, |
| 403 | - NnopbaseExecutorArgsAddr* argsAddr) | 404 | + NnopbaseExecutorArgsAddr* const argsAddr) |
| 404 | { | 405 | { |
| 405 | const NnopbaseUChar* const args = (NnopbaseUChar*)executor->argsExt.args; | 406 | const NnopbaseUChar* const args = (NnopbaseUChar*)executor->argsExt.args; |
| 406 | NnopbaseUChar** hostInputData = &argsAddr->hostInputData; | 407 | NnopbaseUChar** hostInputData = &argsAddr->hostInputData; |
| @@ -429,7 +430,7 @@ void** NnopbaseExecutorPrepareOutputsParamsExt(NnopbaseExecutor* executor, void* | |||
| 429 | return addr; | 430 | return addr; |
| 430 | } | 431 | } |
| 431 | 432 | ||
| 432 | -std::vector<aclrtPlaceHolderInfo> NnopbaseGetRTSPlaceHolder(NnopbaseRTArgsExt* argsExt) | 433 | +std::vector<aclrtPlaceHolderInfo> NnopbaseGetRTSPlaceHolder(NnopbaseRTArgsExt* const argsExt) |
| 433 | { | 434 | { |
| 434 | std::vector<aclrtPlaceHolderInfo> hostInputInfoPtr; | 435 | std::vector<aclrtPlaceHolderInfo> hostInputInfoPtr; |
| 435 | if (argsExt->hasTiling != 0) { | 436 | if (argsExt->hasTiling != 0) { |
| @@ -25,8 +25,8 @@ struct NnopbaseRTArgsExt { | |||
| 25 | uint16_t hostInputInfoNum; // hostInputInfo num | 25 | uint16_t hostInputInfoNum; // hostInputInfo num |
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | -std::vector<aclrtPlaceHolderInfo> NnopbaseGetRTSPlaceHolder(NnopbaseRTArgsExt* argsExt); | 28 | +std::vector<aclrtPlaceHolderInfo> NnopbaseGetRTSPlaceHolder(NnopbaseRTArgsExt* const argsExt); |
| 29 | 29 | ||
| 30 | void NnopbaseGetIrIndex(const NnopbaseParamDesc& paramDesc, const size_t index, size_t& irIndex, size_t& relativeIndex); | 30 | void NnopbaseGetIrIndex(const NnopbaseParamDesc& paramDesc, const size_t index, size_t& irIndex, size_t& relativeIndex); |
| 31 | 31 | ||
| 32 | -#endif | 32 | +#endif |
| @@ -67,7 +67,7 @@ void ArgsPool::Finalize() | |||
| 67 | 67 | ||
| 68 | bool ArgsPool::IsArgsMatch(NnopbaseExecutorArgs* const args, NnopbaseExecutor* executor) | 68 | bool ArgsPool::IsArgsMatch(NnopbaseExecutorArgs* const args, NnopbaseExecutor* executor) |
| 69 | { | 69 | { |
| 70 | - if (args->isVist) { | 70 | + if (args->isVisit) { |
| 71 | OP_LOGI("Op %s seed %zu args %p is visited.", executor->opType, args->seed, args); | 71 | OP_LOGI("Op %s seed %zu args %p is visited.", executor->opType, args->seed, args); |
| 72 | return false; | 72 | return false; |
| 73 | } | 73 | } |
| @@ -80,7 +80,7 @@ bool ArgsPool::IsArgsMatch(NnopbaseExecutorArgs* const args, NnopbaseExecutor* e | |||
| 80 | executor->args = args; | 80 | executor->args = args; |
| 81 | executor->hasTiling = (!args->binInfo->isStaticShape); | 81 | executor->hasTiling = (!args->binInfo->isStaticShape); |
| 82 | executor->isCachedArgs = true; | 82 | executor->isCachedArgs = true; |
| 83 | - args->isVist = true; | 83 | + args->isVisit = true; |
| 84 | Get(executor->args); | 84 | Get(executor->args); |
| 85 | OP_LOGI("Op %s match args cache successfully, seed is %zu, key len is %zu.", executor->opType, args->seed, | 85 | OP_LOGI("Op %s match args cache successfully, seed is %zu, key len is %zu.", executor->opType, args->seed, |
| 86 | args->keyLen); | 86 | args->keyLen); |
| @@ -128,7 +128,7 @@ aclnnStatus ArgsPool::CreateArgs(NnopbaseExecutor* executor) | |||
| 128 | const std::lock_guard<std::mutex> lk(mutex); | 128 | const std::lock_guard<std::mutex> lk(mutex); |
| 129 | (void)argsMap[executor->ownArgs.seed].emplace_back(args.release()); | 129 | (void)argsMap[executor->ownArgs.seed].emplace_back(args.release()); |
| 130 | executor->args = argsMap[executor->ownArgs.seed].back(); | 130 | executor->args = argsMap[executor->ownArgs.seed].back(); |
| 131 | - executor->args->isVist = true; | 131 | + executor->args->isVisit = true; |
| 132 | RecordNnopbaseTime(executor, NnopbaseTimeIdx::kCreateCacheEnd); | 132 | RecordNnopbaseTime(executor, NnopbaseTimeIdx::kCreateCacheEnd); |
| 133 | Put(executor->args); | 133 | Put(executor->args); |
| 134 | } | 134 | } |
| @@ -175,7 +175,7 @@ void ArgsPool::Put(NnopbaseExecutorArgs* const args) | |||
| 175 | { | 175 | { |
| 176 | while ((argsCache.size() >= maxCacheNum) && (!cacheList.empty())) { | 176 | while ((argsCache.size() >= maxCacheNum) && (!cacheList.empty())) { |
| 177 | const auto& tmp = cacheList.back(); | 177 | const auto& tmp = cacheList.back(); |
| 178 | - if (tmp->isVist) { | 178 | + if (tmp->isVisit) { |
| 179 | OP_LOGW("The number of args cached has reached %zu, but the oldest args %p seed %zu is in use! " | 179 | OP_LOGW("The number of args cached has reached %zu, but the oldest args %p seed %zu is in use! " |
| 180 | "Can't delete args!", | 180 | "Can't delete args!", |
| 181 | maxCacheNum, tmp, tmp->seed); | 181 | maxCacheNum, tmp, tmp->seed); |
| @@ -31,7 +31,7 @@ public: | |||
| 31 | } | 31 | } |
| 32 | const std::lock_guard<std::mutex> lk(mutex); | 32 | const std::lock_guard<std::mutex> lk(mutex); |
| 33 | ReleaseFixedCache(args); | 33 | ReleaseFixedCache(args); |
| 34 | - args->isVist = false; | 34 | + args->isVisit = false; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | void FixCache(NnopbaseExecutorArgs* const args); | 37 | void FixCache(NnopbaseExecutorArgs* const args); |
| @@ -38,7 +38,7 @@ static const std::string NNOPBASE_MEMSET_OP_NAME = "MemSet"; | |||
| 38 | 38 | ||
| 39 | typedef struct { | 39 | typedef struct { |
| 40 | DList head; | 40 | DList head; |
| 41 | - bool isVist; | 41 | + bool isVisit; |
| 42 | } BinInfoBucket; | 42 | } BinInfoBucket; |
| 43 | 43 | ||
| 44 | typedef struct { | 44 | typedef struct { |
| @@ -94,6 +94,11 @@ struct NnopbaseCoreNum { | |||
| 94 | uint32_t aivNum = 0U; | 94 | uint32_t aivNum = 0U; |
| 95 | }; | 95 | }; |
| 96 | 96 | ||
| 97 | +struct StaticKernelPlatformInfo { | ||
| 98 | + NnopbaseCoreNum coreNum; | ||
| 99 | + int8_t deterministicLevel = -1; | ||
| 100 | +}; | ||
| 101 | + | ||
| 97 | struct StaticKernelJsonRunInfo { | 102 | struct StaticKernelJsonRunInfo { |
| 98 | uint32_t aicpuNumBlocks = 0U; | 103 | uint32_t aicpuNumBlocks = 0U; |
| 99 | uint32_t numBlocks = 0U; | 104 | uint32_t numBlocks = 0U; |
| @@ -108,8 +113,8 @@ struct StaticKernelJsonRunInfo { | |||
| 108 | }; | 113 | }; |
| 109 | 114 | ||
| 110 | struct ExtraKernelDesc { | 115 | struct ExtraKernelDesc { |
| 111 | - std::unique_ptr<NnopbaseCoreNum> coreNum = nullptr; | 116 | + std::unique_ptr<StaticKernelPlatformInfo> platformInfo = nullptr; // 编译静态kernel时的平台描述 |
| 112 | - std::unique_ptr<StaticKernelJsonRunInfo> runInfo = nullptr; | 117 | + std::unique_ptr<StaticKernelJsonRunInfo> runInfo = nullptr; // 静态kernel的运行数据描述 |
| 113 | }; | 118 | }; |
| 114 | 119 | ||
| 115 | typedef struct { | 120 | typedef struct { |
| @@ -80,7 +80,7 @@ size_t CacheKeyBuilder::CalculateCacheKeyLenV1(NnopbaseExecutor* executor) | |||
| 80 | ++keyLen; // append '/' | 80 | ++keyLen; // append '/' |
| 81 | keyLen += sizeof(uint32_t); | 81 | keyLen += sizeof(uint32_t); |
| 82 | ++keyLen; // append '/' | 82 | ++keyLen; // append '/' |
| 83 | - keyLen += sizeof(bool); | 83 | + keyLen += sizeof(uint8_t); |
| 84 | return keyLen; | 84 | return keyLen; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| @@ -136,7 +136,7 @@ void CacheKeyBuilder::GenerateCacheArgsKeyV1(NnopbaseExecutor* executor) | |||
| 136 | NnopbaseAppendBinary(key, sizeof(uint32_t), &mc2RankId, sizeof(uint32_t))); | 136 | NnopbaseAppendBinary(key, sizeof(uint32_t), &mc2RankId, sizeof(uint32_t))); |
| 137 | key = NnopbaseAppend1Byte(key, '/'); | 137 | key = NnopbaseAppend1Byte(key, '/'); |
| 138 | key = op::internal::PtrCastTo<NnopbaseUChar>( | 138 | key = op::internal::PtrCastTo<NnopbaseUChar>( |
| 139 | - NnopbaseAppendBinary(key, sizeof(bool), &(executor->deterministic), sizeof(bool))); | 139 | + NnopbaseAppendBinary(key, sizeof(uint8_t), &(executor->deterministicLevel), sizeof(uint8_t))); |
| 140 | executor->ownArgs.seed = NnopbaseHashBinary(executor->ownArgs.inputKey.data(), executor->ownArgs.keyLen); | 140 | executor->ownArgs.seed = NnopbaseHashBinary(executor->ownArgs.inputKey.data(), executor->ownArgs.keyLen); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| @@ -196,16 +196,16 @@ NnopbaseUChar* CacheKeyBuilder::AppendCoreNum(NnopbaseExecutorArgs* args, const | |||
| 196 | return key; | 196 | return key; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | -NnopbaseUChar* CacheKeyBuilder::AppendDeterministic(NnopbaseExecutorArgs* args, const bool* deterministic) | 199 | +NnopbaseUChar* CacheKeyBuilder::AppendDeterministicLevel(NnopbaseExecutorArgs* args, const uint8_t* deterministicLevel) |
| 200 | { | 200 | { |
| 201 | NnopbaseUChar* key = op::internal::PtrCastTo<NnopbaseUChar>(args->inputKey.data() + args->keyLen); | 201 | NnopbaseUChar* key = op::internal::PtrCastTo<NnopbaseUChar>(args->inputKey.data() + args->keyLen); |
| 202 | key = AppendPlaceHolder(args, key); | 202 | key = AppendPlaceHolder(args, key); |
| 203 | - EnsureCapacity(args, sizeof(bool)); | 203 | + EnsureCapacity(args, sizeof(uint8_t)); |
| 204 | key = op::internal::PtrCastTo<NnopbaseUChar>(args->inputKey.data() + args->keyLen); | 204 | key = op::internal::PtrCastTo<NnopbaseUChar>(args->inputKey.data() + args->keyLen); |
| 205 | key = op::internal::PtrCastTo<NnopbaseUChar>( | 205 | key = op::internal::PtrCastTo<NnopbaseUChar>( |
| 206 | - NnopbaseAppendBinary(key, args->remainKeyLen, deterministic, sizeof(bool))); | 206 | + NnopbaseAppendBinary(key, args->remainKeyLen, deterministicLevel, sizeof(uint8_t))); |
| 207 | - args->keyLen += sizeof(bool); | 207 | + args->keyLen += sizeof(uint8_t); |
| 208 | - args->remainKeyLen -= sizeof(bool); | 208 | + args->remainKeyLen -= sizeof(uint8_t); |
| 209 | return key; | 209 | return key; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| @@ -366,4 +366,4 @@ void CacheKeyBuilder::AppendScalarList(NnopbaseExecutorArgs* args, const aclScal | |||
| 366 | (void)AppendScalarListInfo(args, dataType, scalarList->Size()); | 366 | (void)AppendScalarListInfo(args, dataType, scalarList->Size()); |
| 367 | } | 367 | } |
| 368 | } | 368 | } |
| 369 | -} // namespace Indv | 369 | +} // namespace Indv |
| @@ -21,7 +21,7 @@ public: | |||
| 21 | static NnopbaseUChar* AppendPlaceHolder(NnopbaseExecutorArgs* args, NnopbaseUChar* key); | 21 | static NnopbaseUChar* AppendPlaceHolder(NnopbaseExecutorArgs* args, NnopbaseUChar* key); |
| 22 | static NnopbaseUChar* AppendCoreNum(NnopbaseExecutorArgs* args, const NnopbaseCoreNum* coreNum); | 22 | static NnopbaseUChar* AppendCoreNum(NnopbaseExecutorArgs* args, const NnopbaseCoreNum* coreNum); |
| 23 | static NnopbaseUChar* AppendMc2RankId(NnopbaseExecutorArgs* args, const uint32_t* rankId); | 23 | static NnopbaseUChar* AppendMc2RankId(NnopbaseExecutorArgs* args, const uint32_t* rankId); |
| 24 | - static NnopbaseUChar* AppendDeterministic(NnopbaseExecutorArgs* args, const bool* deterministic); | 24 | + static NnopbaseUChar* AppendDeterministicLevel(NnopbaseExecutorArgs* args, const uint8_t* deterministicLevel); |
| 25 | static void AppendValueDependTensor(NnopbaseExecutorArgs* args, const void* addr, const uint64_t dim, | 25 | static void AppendValueDependTensor(NnopbaseExecutorArgs* args, const void* addr, const uint64_t dim, |
| 26 | const uint64_t dataLen, ge::DataType dType); | 26 | const uint64_t dataLen, ge::DataType dType); |
| 27 | static void AppendScalar(NnopbaseExecutorArgs* args, const aclScalar* scalar, const uint32_t index, | 27 | static void AppendScalar(NnopbaseExecutorArgs* args, const aclScalar* scalar, const uint32_t index, |
| @@ -168,17 +168,26 @@ std::string GetOpSoPackageName(const std::string& path) | |||
| 168 | return "built-in"; | 168 | return "built-in"; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | -bool MatchBinWithCoreNum(const NnopbaseBinInfo* const binInfo, const NnopbaseCoreNum* const coreNum) | 171 | +bool MatchBinWithPlatformInfo(const NnopbaseBinInfo* const binInfo, const StaticKernelPlatformInfo* const platformInfo) |
| 172 | { | 172 | { |
| 173 | // 不具备校验的条件或未开启校验,直接返回匹配成功 | 173 | // 不具备校验的条件或未开启校验,直接返回匹配成功 |
| 174 | - if (coreNum == nullptr || binInfo->extraKernelDesc == nullptr || binInfo->extraKernelDesc->coreNum == nullptr) { | 174 | + if (platformInfo == nullptr || binInfo->extraKernelDesc == nullptr || |
| 175 | + binInfo->extraKernelDesc->platformInfo == nullptr) { | ||
| 175 | return true; | 176 | return true; |
| 176 | } | 177 | } |
| 177 | - const auto& binCoreNum = binInfo->extraKernelDesc->coreNum; | 178 | + const auto& binPlatformInfo = binInfo->extraKernelDesc->platformInfo; |
| 179 | + const auto& binCoreNum = binInfo->extraKernelDesc->platformInfo->coreNum; | ||
| 180 | + const auto& coreNum = platformInfo->coreNum; | ||
| 178 | OP_LOGD("Match static bin with runtime coreNum[%u, %u], while coreNum of candidate static kernel is [%u, %u].", | 181 | OP_LOGD("Match static bin with runtime coreNum[%u, %u], while coreNum of candidate static kernel is [%u, %u].", |
| 179 | - coreNum->aicNum, coreNum->aivNum, binCoreNum->aicNum, binCoreNum->aivNum); | 182 | + coreNum.aicNum, coreNum.aivNum, binCoreNum.aicNum, binCoreNum.aivNum); |
| 180 | // 控核场景必须保证aic/aiv核数与当前核数相等 | 183 | // 控核场景必须保证aic/aiv核数与当前核数相等 |
| 181 | - return (binCoreNum->aivNum == coreNum->aivNum) && ((binCoreNum->aicNum == coreNum->aicNum)); | 184 | + bool coreEqual = (binCoreNum.aivNum == coreNum.aivNum) && ((binCoreNum.aicNum == coreNum.aicNum)); |
| 185 | + // 如果静态kernel描述符里包含了deterministicLevel,做强校验 | ||
| 186 | + if (binPlatformInfo->deterministicLevel != -1) { | ||
| 187 | + return (binPlatformInfo->deterministicLevel == platformInfo->deterministicLevel) && coreEqual; | ||
| 188 | + } else { | ||
| 189 | + return coreEqual; | ||
| 190 | + } | ||
| 182 | } | 191 | } |
| 183 | } // namespace | 192 | } // namespace |
| 184 | 193 | ||
| @@ -202,7 +211,8 @@ NnopbaseUChar* NnopbaseCollectorGenStaticKey(NnopbaseUChar* verKey, const Nnopba | |||
| 202 | { | 211 | { |
| 203 | verKey = NnopbaseAppendBinary(verKey, NNOPBASE_MAX_STATICKEY_LEN, &(regInfoKey->opType[0U]), | 212 | verKey = NnopbaseAppendBinary(verKey, NNOPBASE_MAX_STATICKEY_LEN, &(regInfoKey->opType[0U]), |
| 204 | regInfoKey->opType.size()); | 213 | regInfoKey->opType.size()); |
| 205 | - verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(deterMin)); | 214 | + uint64_t determinLevel = (deterMin == 0U) ? 0U : 1U; |
| 215 | + verKey = NnopbaseAppend8Byte(verKey, determinLevel); | ||
| 206 | verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(implMode)); | 216 | verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(implMode)); |
| 207 | OP_LOGI("Get deterministic is %ld, high precision is %ld", deterMin, implMode); | 217 | OP_LOGI("Get deterministic is %ld, high precision is %ld", deterMin, implMode); |
| 208 | 218 | ||
| @@ -291,14 +301,14 @@ NnopbaseUChar* NnopbaseCollectorGenStaticKey(NnopbaseUChar* verKey, const Nnopba | |||
| 291 | 301 | ||
| 292 | const NnopbaseChar* NnopbaseCollectorGetStaticKernelBin(const NnopbaseChar* const opType, const uint64_t key, | 302 | const NnopbaseChar* NnopbaseCollectorGetStaticKernelBin(const NnopbaseChar* const opType, const uint64_t key, |
| 293 | const NnopbaseUChar* verbose, const uint32_t verbLen, | 303 | const NnopbaseUChar* verbose, const uint32_t verbLen, |
| 294 | - const NnopbaseCoreNum* const coreNum) | 304 | + const StaticKernelPlatformInfo* const platformInfo) |
| 295 | { | 305 | { |
| 296 | NnopbaseRegInfo* regInfo = NnopbaseCollectorFindRegInfoInTbl(gBinCollector, opType, key); | 306 | NnopbaseRegInfo* regInfo = NnopbaseCollectorFindRegInfoInTbl(gBinCollector, opType, key); |
| 297 | if (regInfo == nullptr) { | 307 | if (regInfo == nullptr) { |
| 298 | return nullptr; | 308 | return nullptr; |
| 299 | } | 309 | } |
| 300 | const size_t hashKey = NnopbaseHashBinary(verbose, static_cast<size_t>(verbLen)) % NNOPBASE_NORM_MAX_BIN_BUCKETS; | 310 | const size_t hashKey = NnopbaseHashBinary(verbose, static_cast<size_t>(verbLen)) % NNOPBASE_NORM_MAX_BIN_BUCKETS; |
| 301 | - const NnopbaseBinInfo* binInfo = NnopbaseCollectorFindBinInfo(regInfo, hashKey, verbose, verbLen, coreNum); | 311 | + const NnopbaseBinInfo* binInfo = NnopbaseCollectorFindBinInfo(regInfo, hashKey, verbose, verbLen, platformInfo); |
| 302 | if (binInfo == nullptr) { | 312 | if (binInfo == nullptr) { |
| 303 | return nullptr; | 313 | return nullptr; |
| 304 | } | 314 | } |
| @@ -659,7 +669,7 @@ aclnnStatus NnopbaseCollectorGcRegInfo(void* data) | |||
| 659 | NnopbaseRegInfo* regInfo = op::internal::PtrCastTo<NnopbaseRegInfo>(data); | 669 | NnopbaseRegInfo* regInfo = op::internal::PtrCastTo<NnopbaseRegInfo>(data); |
| 660 | for (size_t i = 0U; i < NNOPBASE_NORM_MAX_BIN_BUCKETS; i++) { | 670 | for (size_t i = 0U; i < NNOPBASE_NORM_MAX_BIN_BUCKETS; i++) { |
| 661 | BinInfoBucket* bucket = ®Info->binTbl.buckets[i]; | 671 | BinInfoBucket* bucket = ®Info->binTbl.buckets[i]; |
| 662 | - if (bucket->isVist) { | 672 | + if (bucket->isVisit) { |
| 663 | return ACLNN_SUCCESS; | 673 | return ACLNN_SUCCESS; |
| 664 | } | 674 | } |
| 665 | DList* const head = &bucket->head; | 675 | DList* const head = &bucket->head; |
| @@ -683,7 +693,7 @@ aclnnStatus NnopbaseCollectorGcRegInfo(void* data) | |||
| 683 | void SetExtraKernelInfoToBin(const NnopbaseJsonInfo& jsonInfo, std::unique_ptr<NnopbaseBinInfo>& binInfo) | 693 | void SetExtraKernelInfoToBin(const NnopbaseJsonInfo& jsonInfo, std::unique_ptr<NnopbaseBinInfo>& binInfo) |
| 684 | { | 694 | { |
| 685 | auto& runInfo = jsonInfo.extraKernelDesc.runInfo; | 695 | auto& runInfo = jsonInfo.extraKernelDesc.runInfo; |
| 686 | - auto& coreNum = jsonInfo.extraKernelDesc.coreNum; | 696 | + auto& platformInfo = jsonInfo.extraKernelDesc.platformInfo; |
| 687 | if (runInfo != nullptr) { | 697 | if (runInfo != nullptr) { |
| 688 | if (binInfo->extraKernelDesc == nullptr) { | 698 | if (binInfo->extraKernelDesc == nullptr) { |
| 689 | binInfo->extraKernelDesc = std::make_shared<ExtraKernelDesc>(); | 699 | binInfo->extraKernelDesc = std::make_shared<ExtraKernelDesc>(); |
| @@ -700,16 +710,16 @@ void SetExtraKernelInfoToBin(const NnopbaseJsonInfo& jsonInfo, std::unique_ptr<N | |||
| 700 | binInfo->extraKernelDesc->runInfo->tilingKey, binInfo->extraKernelDesc->runInfo->clearAtomic, | 710 | binInfo->extraKernelDesc->runInfo->tilingKey, binInfo->extraKernelDesc->runInfo->clearAtomic, |
| 701 | binInfo->extraKernelDesc->runInfo->workspaceSizesNum); | 711 | binInfo->extraKernelDesc->runInfo->workspaceSizesNum); |
| 702 | } | 712 | } |
| 703 | - if (coreNum != nullptr) { | 713 | + if (platformInfo != nullptr) { |
| 704 | if (binInfo->extraKernelDesc == nullptr) { | 714 | if (binInfo->extraKernelDesc == nullptr) { |
| 705 | binInfo->extraKernelDesc = std::make_shared<ExtraKernelDesc>(); | 715 | binInfo->extraKernelDesc = std::make_shared<ExtraKernelDesc>(); |
| 706 | NNOPBASE_ASSERT_NOTNULL(binInfo->extraKernelDesc); | 716 | NNOPBASE_ASSERT_NOTNULL(binInfo->extraKernelDesc); |
| 707 | } | 717 | } |
| 708 | - binInfo->extraKernelDesc->coreNum = std::make_unique<NnopbaseCoreNum>(*coreNum); | 718 | + binInfo->extraKernelDesc->platformInfo = std::make_unique<StaticKernelPlatformInfo>(*platformInfo); |
| 709 | - NNOPBASE_ASSERT_NOTNULL(binInfo->extraKernelDesc->coreNum); | 719 | + NNOPBASE_ASSERT_NOTNULL(binInfo->extraKernelDesc->platformInfo); |
| 710 | OP_LOGI("Update platformInfo of %s json to binInfo, number of aic blocks is %u, number of aiv blocks is %u", | 720 | OP_LOGI("Update platformInfo of %s json to binInfo, number of aic blocks is %u, number of aiv blocks is %u", |
| 711 | - jsonInfo.opType.c_str(), binInfo->extraKernelDesc->coreNum->aicNum, | 721 | + jsonInfo.opType.c_str(), binInfo->extraKernelDesc->platformInfo->coreNum.aicNum, |
| 712 | - binInfo->extraKernelDesc->coreNum->aivNum); | 722 | + binInfo->extraKernelDesc->platformInfo->coreNum.aivNum); |
| 713 | } | 723 | } |
| 714 | } | 724 | } |
| 715 | 725 | ||
| @@ -723,7 +733,7 @@ aclnnStatus NnopbaseCollectorAddBinInfo(const string& key, NnopbaseRegInfo* cons | |||
| 723 | if (jsonInfo.isStaticShape) { | 733 | if (jsonInfo.isStaticShape) { |
| 724 | size_t hashKey = NnopbaseHashBinary(verbose, len) % NNOPBASE_NORM_MAX_BIN_BUCKETS; | 734 | size_t hashKey = NnopbaseHashBinary(verbose, len) % NNOPBASE_NORM_MAX_BIN_BUCKETS; |
| 725 | NnopbaseBinInfo* findBin = NnopbaseCollectorFindBinInfo(regInfo, hashKey, verbose, len, | 735 | NnopbaseBinInfo* findBin = NnopbaseCollectorFindBinInfo(regInfo, hashKey, verbose, len, |
| 726 | - jsonInfo.extraKernelDesc.coreNum.get()); | 736 | + jsonInfo.extraKernelDesc.platformInfo.get()); |
| 727 | if (findBin != nullptr) { | 737 | if (findBin != nullptr) { |
| 728 | OP_LOGI("%s binInfo already exists, no need to add.", regInfo->key.opType.c_str()); | 738 | OP_LOGI("%s binInfo already exists, no need to add.", regInfo->key.opType.c_str()); |
| 729 | return OK; | 739 | return OK; |
| @@ -811,17 +821,22 @@ void UpdatePlatformInfoForStaticJson(ExtraKernelDesc& kernelDesc, nlohmann::json | |||
| 811 | try { | 821 | try { |
| 812 | if (staticKernelJsonConfig.contains("platformInfo")) { | 822 | if (staticKernelJsonConfig.contains("platformInfo")) { |
| 813 | auto& platformInfo = staticKernelJsonConfig["platformInfo"]; | 823 | auto& platformInfo = staticKernelJsonConfig["platformInfo"]; |
| 814 | - kernelDesc.coreNum = std::make_unique<NnopbaseCoreNum>(); | 824 | + kernelDesc.platformInfo = std::make_unique<StaticKernelPlatformInfo>(); |
| 815 | - if (kernelDesc.coreNum == nullptr) { | 825 | + if (kernelDesc.platformInfo == nullptr) { |
| 816 | return; | 826 | return; |
| 817 | } | 827 | } |
| 818 | - kernelDesc.coreNum->aicNum = platformInfo["cubeCoreCnt"].get<uint32_t>(); | 828 | + auto& coreNum = kernelDesc.platformInfo->coreNum; |
| 819 | - kernelDesc.coreNum->aivNum = platformInfo["vectorCoreCnt"].get<uint32_t>(); | 829 | + coreNum.aicNum = platformInfo["cubeCoreCnt"].get<uint32_t>(); |
| 820 | - OP_LOGI("Parse platformInfo successfully, aicNum is %u, aivNum is %u", kernelDesc.coreNum->aicNum, | 830 | + coreNum.aivNum = platformInfo["vectorCoreCnt"].get<uint32_t>(); |
| 821 | - kernelDesc.coreNum->aivNum); | 831 | + if (platformInfo.contains("deterministicLevel")) { |
| 832 | + kernelDesc.platformInfo->deterministicLevel = platformInfo["deterministicLevel"].get<int8_t>(); | ||
| 833 | + } | ||
| 834 | + OP_LOGI("Parse platformInfo successfully, aicNum is %u, aivNum is %u, determinisitic level is %d.", | ||
| 835 | + kernelDesc.platformInfo->coreNum.aicNum, kernelDesc.platformInfo->coreNum.aivNum, | ||
| 836 | + kernelDesc.platformInfo->deterministicLevel); | ||
| 822 | } | 837 | } |
| 823 | } catch (const nlohmann::json::exception& e) { | 838 | } catch (const nlohmann::json::exception& e) { |
| 824 | - kernelDesc.coreNum = nullptr; | 839 | + kernelDesc.platformInfo = nullptr; |
| 825 | OP_LOGW("Failed to read static kernel json file of platformInfo, reason: %s", e.what()); | 840 | OP_LOGW("Failed to read static kernel json file of platformInfo, reason: %s", e.what()); |
| 826 | } | 841 | } |
| 827 | return; | 842 | return; |
| @@ -854,20 +869,20 @@ void NnopbaseCollectorInsertBinInfo(NnopbaseRegInfo* const regInfo, NnopbaseBinI | |||
| 854 | const size_t key = binInfo->binInfoKey.hashKey; | 869 | const size_t key = binInfo->binInfoKey.hashKey; |
| 855 | const uint32_t keyLen = binInfo->binInfoKey.len; | 870 | const uint32_t keyLen = binInfo->binInfoKey.len; |
| 856 | OP_LOGI("%s insert bin key is %zu, key len is %u", regInfo->key.opType.c_str(), key, keyLen); | 871 | OP_LOGI("%s insert bin key is %zu, key len is %u", regInfo->key.opType.c_str(), key, keyLen); |
| 857 | - while (!__sync_bool_compare_and_swap(®Info->binTbl.buckets[key].isVist, false, true)) { | 872 | + while (!__sync_bool_compare_and_swap(®Info->binTbl.buckets[key].isVisit, false, true)) { |
| 858 | /* nothing to do */ | 873 | /* nothing to do */ |
| 859 | }; | 874 | }; |
| 860 | DList* const head = ®Info->binTbl.buckets[key].head; | 875 | DList* const head = ®Info->binTbl.buckets[key].head; |
| 861 | DoubleListNodeInit(&binInfo->dllNode); | 876 | DoubleListNodeInit(&binInfo->dllNode); |
| 862 | DoubleListAppend(&binInfo->dllNode, head); | 877 | DoubleListAppend(&binInfo->dllNode, head); |
| 863 | binInfo->regInfo = regInfo; | 878 | binInfo->regInfo = regInfo; |
| 864 | - regInfo->binTbl.buckets[key].isVist = false; | 879 | + regInfo->binTbl.buckets[key].isVisit = false; |
| 865 | } | 880 | } |
| 866 | 881 | ||
| 867 | // 一样的key,会优先选择先放入hash表的 | 882 | // 一样的key,会优先选择先放入hash表的 |
| 868 | NnopbaseBinInfo* NnopbaseCollectorFindBinInfo(NnopbaseRegInfo* const regInfo, const size_t hashKey, | 883 | NnopbaseBinInfo* NnopbaseCollectorFindBinInfo(NnopbaseRegInfo* const regInfo, const size_t hashKey, |
| 869 | const NnopbaseUChar* const verbose, const uint32_t verbLen, | 884 | const NnopbaseUChar* const verbose, const uint32_t verbLen, |
| 870 | - const NnopbaseCoreNum* const coreNum) | 885 | + const StaticKernelPlatformInfo* const platformInfo) |
| 871 | { | 886 | { |
| 872 | OP_LOGI("Start find binInfo, opType is %s, hashKey is %zu, verbLen is %u.", regInfo->key.opType.c_str(), hashKey, | 887 | OP_LOGI("Start find binInfo, opType is %s, hashKey is %zu, verbLen is %u.", regInfo->key.opType.c_str(), hashKey, |
| 873 | verbLen); | 888 | verbLen); |
| @@ -875,7 +890,7 @@ NnopbaseBinInfo* NnopbaseCollectorFindBinInfo(NnopbaseRegInfo* const regInfo, co | |||
| 875 | OP_LOGE(ACLNN_ERR_INNER, "HashKey[%zu] is too large, please check.", hashKey); | 890 | OP_LOGE(ACLNN_ERR_INNER, "HashKey[%zu] is too large, please check.", hashKey); |
| 876 | return nullptr; | 891 | return nullptr; |
| 877 | } | 892 | } |
| 878 | - while (!__sync_bool_compare_and_swap(®Info->binTbl.buckets[hashKey].isVist, false, true)) { | 893 | + while (!__sync_bool_compare_and_swap(®Info->binTbl.buckets[hashKey].isVisit, false, true)) { |
| 879 | /* nothing to do */ | 894 | /* nothing to do */ |
| 880 | }; | 895 | }; |
| 881 | const DList* const head = ®Info->binTbl.buckets[hashKey].head; | 896 | const DList* const head = ®Info->binTbl.buckets[hashKey].head; |
| @@ -896,13 +911,13 @@ NnopbaseBinInfo* NnopbaseCollectorFindBinInfo(NnopbaseRegInfo* const regInfo, co | |||
| 896 | break; | 911 | break; |
| 897 | } | 912 | } |
| 898 | } | 913 | } |
| 899 | - if (i == verbLen && MatchBinWithCoreNum(binInfo, coreNum)) { | 914 | + if (i == verbLen && MatchBinWithPlatformInfo(binInfo, platformInfo)) { |
| 900 | - regInfo->binTbl.buckets[hashKey].isVist = false; | 915 | + regInfo->binTbl.buckets[hashKey].isVisit = false; |
| 901 | OP_LOGI("Found %s binInfo, hashKey is %zu.", regInfo->key.opType.c_str(), hashKey); | 916 | OP_LOGI("Found %s binInfo, hashKey is %zu.", regInfo->key.opType.c_str(), hashKey); |
| 902 | return binInfo; | 917 | return binInfo; |
| 903 | } | 918 | } |
| 904 | } | 919 | } |
| 905 | - regInfo->binTbl.buckets[hashKey].isVist = false; | 920 | + regInfo->binTbl.buckets[hashKey].isVisit = false; |
| 906 | OP_LOGI("There is no available %s binInfo for hashKey %zu.", regInfo->key.opType.c_str(), hashKey); | 921 | OP_LOGI("There is no available %s binInfo for hashKey %zu.", regInfo->key.opType.c_str(), hashKey); |
| 907 | return nullptr; | 922 | return nullptr; |
| 908 | } | 923 | } |
| @@ -1399,13 +1414,13 @@ aclnnStatus NnopbaseCollectorDeleteStaticBins(NnopbaseRegInfo* regInfo) | |||
| 1399 | OP_LOGD("Start find static binInfo, opType is %s, hashKey is %zu.", regInfo->key.opType.c_str(), | 1414 | OP_LOGD("Start find static binInfo, opType is %s, hashKey is %zu.", regInfo->key.opType.c_str(), |
| 1400 | regInfo->key.hashKey); | 1415 | regInfo->key.hashKey); |
| 1401 | for (size_t i = 0U; i < NNOPBASE_NORM_MAX_BIN_BUCKETS; i++) { | 1416 | for (size_t i = 0U; i < NNOPBASE_NORM_MAX_BIN_BUCKETS; i++) { |
| 1402 | - while (!__sync_bool_compare_and_swap(®Info->binTbl.buckets[i].isVist, false, true)) { | 1417 | + while (!__sync_bool_compare_and_swap(®Info->binTbl.buckets[i].isVisit, false, true)) { |
| 1403 | /* nothing to do */ | 1418 | /* nothing to do */ |
| 1404 | }; | 1419 | }; |
| 1405 | BinInfoBucket* bucket = ®Info->binTbl.buckets[i]; | 1420 | BinInfoBucket* bucket = ®Info->binTbl.buckets[i]; |
| 1406 | DList* const head = &bucket->head; | 1421 | DList* const head = &bucket->head; |
| 1407 | if (head->count == 0U) { | 1422 | if (head->count == 0U) { |
| 1408 | - regInfo->binTbl.buckets[i].isVist = false; | 1423 | + regInfo->binTbl.buckets[i].isVisit = false; |
| 1409 | continue; | 1424 | continue; |
| 1410 | } | 1425 | } |
| 1411 | OP_LOGD("Start to delete OpType %s binTable [%zu], cur Number is %u.", opType.c_str(), i, head->count); | 1426 | OP_LOGD("Start to delete OpType %s binTable [%zu], cur Number is %u.", opType.c_str(), i, head->count); |
| @@ -1418,7 +1433,7 @@ aclnnStatus NnopbaseCollectorDeleteStaticBins(NnopbaseRegInfo* regInfo) | |||
| 1418 | NnopbaseBinInfoDestroy(&binInfo); | 1433 | NnopbaseBinInfoDestroy(&binInfo); |
| 1419 | } | 1434 | } |
| 1420 | } | 1435 | } |
| 1421 | - regInfo->binTbl.buckets[i].isVist = false; | 1436 | + regInfo->binTbl.buckets[i].isVisit = false; |
| 1422 | } | 1437 | } |
| 1423 | return OK; | 1438 | return OK; |
| 1424 | } | 1439 | } |
| @@ -52,7 +52,7 @@ extern NnopbaseBinCollector* gBinCollector; | |||
| 52 | aclnnStatus NnopbaseCollectorWork(NnopbaseBinCollector* const collector); | 52 | aclnnStatus NnopbaseCollectorWork(NnopbaseBinCollector* const collector); |
| 53 | NnopbaseBinInfo* NnopbaseCollectorFindBinInfo(NnopbaseRegInfo* const regInfo, const size_t hashKey, | 53 | NnopbaseBinInfo* NnopbaseCollectorFindBinInfo(NnopbaseRegInfo* const regInfo, const size_t hashKey, |
| 54 | const NnopbaseUChar* const verbose, const uint32_t verbLen, | 54 | const NnopbaseUChar* const verbose, const uint32_t verbLen, |
| 55 | - const NnopbaseCoreNum* const coreNum = nullptr); | 55 | + const StaticKernelPlatformInfo* const platformInfo = nullptr); |
| 56 | void NnopbaseCollectorInsertBinInfo(NnopbaseRegInfo* const regInfo, NnopbaseBinInfo* binInfo); | 56 | void NnopbaseCollectorInsertBinInfo(NnopbaseRegInfo* const regInfo, NnopbaseBinInfo* binInfo); |
| 57 | aclnnStatus NnopbaseCollectorAddBinInfo(const string& key, NnopbaseRegInfo* const regInfo, | 57 | aclnnStatus NnopbaseCollectorAddBinInfo(const string& key, NnopbaseRegInfo* const regInfo, |
| 58 | const NnopbaseJsonInfo& jsonInfo, const NnopbaseUChar* const verbose, | 58 | const NnopbaseJsonInfo& jsonInfo, const NnopbaseUChar* const verbose, |
| @@ -96,7 +96,7 @@ NnopbaseUChar* NnopbaseCollectorGenStaticKey(NnopbaseUChar* verKey, const Nnopba | |||
| 96 | const int64_t* const vDepend, const bool usingStride); | 96 | const int64_t* const vDepend, const bool usingStride); |
| 97 | const char* NnopbaseCollectorGetStaticKernelBin(const NnopbaseChar* const opType, const uint64_t key, | 97 | const char* NnopbaseCollectorGetStaticKernelBin(const NnopbaseChar* const opType, const uint64_t key, |
| 98 | const NnopbaseUChar* verbose, const uint32_t verbLen, | 98 | const NnopbaseUChar* verbose, const uint32_t verbLen, |
| 99 | - const NnopbaseCoreNum* const coreNum = nullptr); | 99 | + const StaticKernelPlatformInfo* const platformInfo = nullptr); |
| 100 | aclnnStatus NnopbaseCollectorGetStaticKernelPathAndReadConfig(NnopbaseBinCollector* const collector, | 100 | aclnnStatus NnopbaseCollectorGetStaticKernelPathAndReadConfig(NnopbaseBinCollector* const collector, |
| 101 | const std::string& basePath = ""); | 101 | const std::string& basePath = ""); |
| 102 | aclnnStatus NnopbaseCollectorDeleteStaticBins(NnopbaseRegInfo* regInfo); | 102 | aclnnStatus NnopbaseCollectorDeleteStaticBins(NnopbaseRegInfo* regInfo); |
| @@ -133,7 +133,7 @@ static inline void NnopbaseCollectorInitBinTbl(BinTbl* binTbl) | |||
| 133 | { | 133 | { |
| 134 | for (size_t i = 0U; i < NNOPBASE_NORM_MAX_BIN_BUCKETS; i++) { | 134 | for (size_t i = 0U; i < NNOPBASE_NORM_MAX_BIN_BUCKETS; i++) { |
| 135 | DoubleListInit(&binTbl->buckets[i].head); | 135 | DoubleListInit(&binTbl->buckets[i].head); |
| 136 | - binTbl->buckets[i].isVist = false; | 136 | + binTbl->buckets[i].isVisit = false; |
| 137 | } | 137 | } |
| 138 | } | 138 | } |
| 139 | 139 | ||
| @@ -52,12 +52,12 @@ aclnnStatus NnopbaseComputeNodeAttrsUpdt(NnopbaseComputeNodeInfoExt* nodeExt, Nn | |||
| 52 | 52 | ||
| 53 | aclnnStatus NnopbaseComputeNodeInfoUpdt(NnopbaseExecutor* executor) | 53 | aclnnStatus NnopbaseComputeNodeInfoUpdt(NnopbaseExecutor* executor) |
| 54 | { | 54 | { |
| 55 | - NnopbaseComputeNodeInfoExt* nodeExt = &executor->contextExt.nodeExt; | 55 | + NnopbaseComputeNodeInfoExt* nodeExt = &executor->tiling.contextExt.nodeExt; |
| 56 | NnopbaseComputeNodeInfo* node = nodeExt->node; | 56 | NnopbaseComputeNodeInfo* node = nodeExt->node; |
| 57 | const size_t count = static_cast<size_t>(executor->args->inputs.paramDescs.count); | 57 | const size_t count = static_cast<size_t>(executor->args->inputs.paramDescs.count); |
| 58 | const size_t outputIrNum = static_cast<size_t>(executor->args->outputs.paramDescs.count); | 58 | const size_t outputIrNum = static_cast<size_t>(executor->args->outputs.paramDescs.count); |
| 59 | 59 | ||
| 60 | - if (!executor->contextExt.hasPrepared) { | 60 | + if (!executor->tiling.contextExt.hasPrepared) { |
| 61 | node->nodeType = executor->opType; | 61 | node->nodeType = executor->opType; |
| 62 | node->nodeName = executor->opType; | 62 | node->nodeName = executor->opType; |
| 63 | node->irInputsNum = count; | 63 | node->irInputsNum = count; |
| @@ -129,13 +129,13 @@ aclnnStatus NnopbaseComputeNodeInfoInit(NnopbaseComputeNodeInfoExt* nodeExt) | |||
| 129 | 129 | ||
| 130 | aclnnStatus NnopbaseTilingContextUpdtPrepare(NnopbaseExecutor* executor) | 130 | aclnnStatus NnopbaseTilingContextUpdtPrepare(NnopbaseExecutor* executor) |
| 131 | { | 131 | { |
| 132 | - NnopbaseKernelRunContext* const context = executor->contextExt.context; | 132 | + NnopbaseKernelRunContext* const context = executor->tiling.contextExt.context; |
| 133 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseComputeNodeInfoUpdt(executor)); | 133 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseComputeNodeInfoUpdt(executor)); |
| 134 | context->input_size = static_cast<size_t>(executor->args->inputs.num + executor->args->outputs.num + | 134 | context->input_size = static_cast<size_t>(executor->args->inputs.num + executor->args->outputs.num + |
| 135 | static_cast<uint32_t>(kInputsAppendEnd)); | 135 | static_cast<uint32_t>(kInputsAppendEnd)); |
| 136 | context->output_size = gert::TilingContext::kOutputNum; | 136 | context->output_size = gert::TilingContext::kOutputNum; |
| 137 | context->output_start = &context->values[context->input_size]; | 137 | context->output_start = &context->values[context->input_size]; |
| 138 | - context->compute_node_info = executor->contextExt.nodeExt.node; | 138 | + context->compute_node_info = executor->tiling.contextExt.nodeExt.node; |
| 139 | return OK; | 139 | return OK; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| @@ -37,7 +37,7 @@ static inline void NnopbaseComputeNodeInfoDeInit(NnopbaseComputeNodeInfoExt* nod | |||
| 37 | 37 | ||
| 38 | static inline size_t NnopbaseComputeNodeCalcLen(NnopbaseExecutor* executor) | 38 | static inline size_t NnopbaseComputeNodeCalcLen(NnopbaseExecutor* executor) |
| 39 | { | 39 | { |
| 40 | - NnopbaseComputeNodeInfo* node = executor->contextExt.nodeExt.node; | 40 | + NnopbaseComputeNodeInfo* node = executor->tiling.contextExt.nodeExt.node; |
| 41 | size_t size = node->irInputsNum * sizeof(NnopbaseAnchorInstanceInfo) + | 41 | size_t size = node->irInputsNum * sizeof(NnopbaseAnchorInstanceInfo) + |
| 42 | node->irOutputsNum * sizeof(NnopbaseAnchorInstanceInfo) + | 42 | node->irOutputsNum * sizeof(NnopbaseAnchorInstanceInfo) + |
| 43 | (node->outputsNum + node->inputsNum) * sizeof(NnopbaseCompileTimeTensorDesc) + | 43 | (node->outputsNum + node->inputsNum) * sizeof(NnopbaseCompileTimeTensorDesc) + |
| @@ -62,7 +62,7 @@ aclnnStatus NnopbaseTilingContextUpdtPrepare(NnopbaseExecutor* executor); | |||
| 62 | 62 | ||
| 63 | static inline aclnnStatus NnopbaseTilingBuildOpAttrs(NnopbaseExecutor* executor) | 63 | static inline aclnnStatus NnopbaseTilingBuildOpAttrs(NnopbaseExecutor* executor) |
| 64 | { | 64 | { |
| 65 | - return NnopbaseComputeNodeAttrsUpdt(&executor->contextExt.nodeExt, &executor->attrs); | 65 | + return NnopbaseComputeNodeAttrsUpdt(&executor->tiling.contextExt.nodeExt, &executor->attrs); |
| 66 | } | 66 | } |
| 67 | #ifdef __cplusplus | 67 | #ifdef __cplusplus |
| 68 | } | 68 | } |
| @@ -420,8 +420,8 @@ aclnnStatus NnopbaseArgsExceptionDumpAddr(NnopbaseExecutor* const executor) | |||
| 420 | OP_LOGI("ArgExceptionDump is enabled."); | 420 | OP_LOGI("ArgExceptionDump is enabled."); |
| 421 | uint32_t atomicIndex = 0U; | 421 | uint32_t atomicIndex = 0U; |
| 422 | size_t mc2ContextNum = 0U; | 422 | size_t mc2ContextNum = 0U; |
| 423 | - if (executor->mc2OpCfg.isMc2) { | 423 | + if (executor->mc2.enabled) { |
| 424 | - mc2ContextNum = executor->contextAddr.size(); | 424 | + mc2ContextNum = executor->mc2.contextAddrs.size(); |
| 425 | } | 425 | } |
| 426 | const uint32_t addrNum = executor->args->inputs.num + executor->args->inputs.dynamicNum + | 426 | const uint32_t addrNum = executor->args->inputs.num + executor->args->inputs.dynamicNum + |
| 427 | executor->args->outputs.num + executor->args->outputs.dynamicNum + | 427 | executor->args->outputs.num + executor->args->outputs.dynamicNum + |
| @@ -447,8 +447,8 @@ aclnnStatus NnopbaseArgsExceptionDumpAddr(NnopbaseExecutor* const executor) | |||
| 447 | *sizeInfoAddr |= inputOffset; | 447 | *sizeInfoAddr |= inputOffset; |
| 448 | } | 448 | } |
| 449 | sizeInfoAddr++; | 449 | sizeInfoAddr++; |
| 450 | - if (executor->mc2OpCfg.isMc2) { | 450 | + if (executor->mc2.enabled) { |
| 451 | - for (size_t i = 0U; i < executor->contextAddr.size(); i++) { | 451 | + for (size_t i = 0U; i < executor->mc2.contextAddrs.size(); i++) { |
| 452 | *sizeInfoAddr = 32ULL; // 只打印context结构体的前32字节 | 452 | *sizeInfoAddr = 32ULL; // 只打印context结构体的前32字节 |
| 453 | sizeInfoAddr++; | 453 | sizeInfoAddr++; |
| 454 | } | 454 | } |
| @@ -71,6 +71,38 @@ std::vector<aclrtLaunchKernelAttr> CreateRtsLaunchCfgAttrs(uint8_t scheMode, uin | |||
| 71 | return attrs; | 71 | return attrs; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | +aclnnStatus RegisterCustomizedCallback(NnopbaseExecutor* const executor, NnopbaseBinInfo* const binInfo) | ||
| 75 | +{ | ||
| 76 | +#ifndef PRODUCT_SIDE_IS_DEVICE | ||
| 77 | +#if defined(RUNTIME_VERSION_NUM) && defined(METADEF_VERSION_NUM) && \ | ||
| 78 | + (RUNTIME_VERSION_NUM >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER) && \ | ||
| 79 | + (METADEF_VERSION_NUM >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER) | ||
| 80 | + int32_t metadefVerNum = -1; | ||
| 81 | + int32_t runtimeVerNum = -1; | ||
| 82 | + auto aclRetForMetadef = aclsysGetVersionNum("metadef", &metadefVerNum); | ||
| 83 | + auto aclRetForRts = aclsysGetVersionNum("runtime", &runtimeVerNum); | ||
| 84 | + if (aclRetForMetadef == ACL_SUCCESS && aclRetForRts == ACL_SUCCESS && | ||
| 85 | + metadefVerNum >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER && | ||
| 86 | + runtimeVerNum >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER) { | ||
| 87 | + auto& registry = gert::DefaultOpImplSpaceRegistryV2::GetInstance().GetSpaceRegistry(); | ||
| 88 | + NNOPBASE_ASSERT_NOTNULL_RETVAL(registry); | ||
| 89 | + auto opImpl = registry->GetOpImpl(executor->opType); | ||
| 90 | + if (opImpl != nullptr && opImpl->exception_func != nullptr) { | ||
| 91 | + OP_LOGI("Start to register customized exception dump parse function for op: %s.", executor->opType); | ||
| 92 | + auto inst = nnopbase::IndvRtsWrapper::GetInstance(); | ||
| 93 | + if (inst == nullptr) { | ||
| 94 | + return ACLNN_ERR_INNER; | ||
| 95 | + } | ||
| 96 | + NNOPBASE_ASSERT_OK_RETVAL(inst->AclrtBinarySetExceptionCallback( | ||
| 97 | + binInfo->binHandle, op::internal::PtrCastTo<void>(opImpl->exception_func), nullptr)); | ||
| 98 | + OP_LOGI("Register customized exception dump parse function for op: %s successfully.", executor->opType); | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | +#endif | ||
| 102 | +#endif | ||
| 103 | + return OK; | ||
| 104 | +} | ||
| 105 | + | ||
| 74 | void ResizeExecutorArgsBuf(NnopbaseExecutor* executor) | 106 | void ResizeExecutorArgsBuf(NnopbaseExecutor* executor) |
| 75 | { | 107 | { |
| 76 | OP_LOGI("Start resizing %s args buffer.", executor->opType); | 108 | OP_LOGI("Start resizing %s args buffer.", executor->opType); |
| @@ -65,7 +65,7 @@ struct NnopbaseExecutorArgs { | |||
| 65 | size_t keyLen = 0U; | 65 | size_t keyLen = 0U; |
| 66 | size_t seed = 0U; | 66 | size_t seed = 0U; |
| 67 | size_t tilingDataOffset = NNOPBASE_TILING_DATA_OFFSET; | 67 | size_t tilingDataOffset = NNOPBASE_TILING_DATA_OFFSET; |
| 68 | - bool isVist = false; | 68 | + bool isVisit = false; |
| 69 | bool enableCache = true; // 缓存是否启用的开关 | 69 | bool enableCache = true; // 缓存是否启用的开关 |
| 70 | std::vector<uint8_t> memsetArgs; | 70 | std::vector<uint8_t> memsetArgs; |
| 71 | std::vector<uint64_t> dfxInfo; | 71 | std::vector<uint64_t> dfxInfo; |
| @@ -81,22 +81,94 @@ struct NnopbaseExecutorArgs { | |||
| 81 | size_t remainKeyLen = NNOPBASE_MAX_ARGS_KEY_LEN; | 81 | size_t remainKeyLen = NNOPBASE_MAX_ARGS_KEY_LEN; |
| 82 | }; | 82 | }; |
| 83 | 83 | ||
| 84 | -typedef struct { | 84 | +struct NnopbaseMc2Execution { |
| 85 | - bool isMc2 = false; | 85 | + bool enabled = false; |
| 86 | - NnopbaseHcclServerType sType; | 86 | + NnopbaseHcclServerType serverType = NNOPBASE_HCCL_SERVER_TYPE_END; |
| 87 | - std::vector<HcclComm> hcomHandle; | 87 | + std::vector<HcclComm> commHandles; |
| 88 | -} NnopbaseMc2OpCfg; | 88 | + std::vector<void*> contextAddrs; |
| 89 | + rtAicpuArgsEx_t aicpuArgs{}; | ||
| 90 | + rtFusionArgsEx_t fusionArgs{}; | ||
| 91 | + std::vector<aclrtStream> aicpuStreams; | ||
| 92 | + std::vector<uint64_t> aicpuThreads; | ||
| 93 | + std::vector<std::pair<aclrtStream, aclrtStream>> aicpuNotifies; | ||
| 94 | + | ||
| 95 | + void ClearRuntimeState() | ||
| 96 | + { | ||
| 97 | + enabled = false; | ||
| 98 | + serverType = NNOPBASE_HCCL_SERVER_TYPE_END; | ||
| 99 | + commHandles.clear(); | ||
| 100 | + contextAddrs.clear(); | ||
| 101 | + aicpuStreams.clear(); | ||
| 102 | + aicpuThreads.clear(); | ||
| 103 | + aicpuNotifies.clear(); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + void Reset() | ||
| 107 | + { | ||
| 108 | + ClearRuntimeState(); | ||
| 109 | + aicpuArgs = {}; | ||
| 110 | + fusionArgs = {}; | ||
| 111 | + } | ||
| 112 | +}; | ||
| 113 | + | ||
| 114 | +struct NnopbaseTilingState { | ||
| 115 | + uint64_t* tilingKey = nullptr; | ||
| 116 | + uint32_t* numBlocks = nullptr; | ||
| 117 | + bool* needAtomic = nullptr; | ||
| 118 | + uint32_t* scheMode = nullptr; | ||
| 119 | + uint32_t* dynUbufSize = nullptr; | ||
| 120 | + uint32_t* aicpuNumBlocks = nullptr; | ||
| 121 | + NnopbaseKernelRunContextExt contextExt{}; | ||
| 122 | + | ||
| 123 | + void Init() | ||
| 124 | + { | ||
| 125 | + tilingKey = nullptr; | ||
| 126 | + numBlocks = nullptr; | ||
| 127 | + needAtomic = nullptr; | ||
| 128 | + scheMode = nullptr; | ||
| 129 | + dynUbufSize = nullptr; | ||
| 130 | + aicpuNumBlocks = nullptr; | ||
| 131 | + contextExt = {}; | ||
| 132 | + } | ||
| 133 | +}; | ||
| 134 | + | ||
| 135 | +struct NnopbaseDfxState { | ||
| 136 | + NnopbaseDfxId* tilingId = nullptr; | ||
| 137 | + uint64_t itemId = 0U; | ||
| 138 | + uint64_t aicpuItemId = 0U; | ||
| 139 | + uint64_t memsetItemId = 0U; | ||
| 140 | + aclnnOpInfoRecord::OpKernelInfo opKernelInfo{"", 0}; | ||
| 141 | + NnopbaseTimeStamp timeStamp{}; | ||
| 142 | + | ||
| 143 | + void Init() | ||
| 144 | + { | ||
| 145 | + tilingId = nullptr; | ||
| 146 | + itemId = 0U; | ||
| 147 | + aicpuItemId = 0U; | ||
| 148 | + memsetItemId = 0U; | ||
| 149 | + opKernelInfo = aclnnOpInfoRecord::OpKernelInfo("", 0); | ||
| 150 | + timeStamp = {}; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + void Reset() | ||
| 154 | + { | ||
| 155 | + tilingId = nullptr; | ||
| 156 | + opKernelInfo = aclnnOpInfoRecord::OpKernelInfo("", 0); | ||
| 157 | + } | ||
| 158 | +}; | ||
| 159 | + | ||
| 160 | +struct NnopbaseOpCompatibility { | ||
| 161 | + OpSupportList* paramSupportList = nullptr; | ||
| 162 | + uint32_t* supportedSocList = nullptr; | ||
| 163 | + uint32_t supportedSocCount = 0U; | ||
| 164 | + bool ownsSupportedSocList = false; | ||
| 165 | +}; | ||
| 89 | 166 | ||
| 90 | typedef struct { | 167 | typedef struct { |
| 91 | uint64_t magicNum = NNOPBASE_EXECUTOR_MAGIC_NUMBER; // 首8字节标识该executor类型属于nnopbase不可更改顺序 | 168 | uint64_t magicNum = NNOPBASE_EXECUTOR_MAGIC_NUMBER; // 首8字节标识该executor类型属于nnopbase不可更改顺序 |
| 92 | bool repeatFlag; | 169 | bool repeatFlag; |
| 93 | NnopbaseAttrs attrs; | 170 | NnopbaseAttrs attrs; |
| 94 | - uint64_t* tilingKey; | 171 | + NnopbaseTilingState tiling; |
| 95 | - uint32_t* numBlocks; | ||
| 96 | - bool* needAtomic; | ||
| 97 | - uint32_t* scheMode; | ||
| 98 | - uint32_t* dynUbufSize; | ||
| 99 | - uint32_t* aicpuNumBlocks; | ||
| 100 | NnopbaseExecutorArgs* args; | 172 | NnopbaseExecutorArgs* args; |
| 101 | NnopbaseExecutorArgs ownArgs; | 173 | NnopbaseExecutorArgs ownArgs; |
| 102 | NnopbaseBinCollector* collector; | 174 | NnopbaseBinCollector* collector; |
| @@ -107,42 +179,27 @@ typedef struct { | |||
| 107 | uint64_t opTypeHash; | 179 | uint64_t opTypeHash; |
| 108 | BinInfoKey binInfoKey; | 180 | BinInfoKey binInfoKey; |
| 109 | NnopbaseRTArgsExt argsExt; | 181 | NnopbaseRTArgsExt argsExt; |
| 110 | - NnopbaseKernelRunContextExt contextExt; | ||
| 111 | aclrtStream stream; | 182 | aclrtStream stream; |
| 112 | bool hasTiling; | 183 | bool hasTiling; |
| 113 | bool isWork; | 184 | bool isWork; |
| 114 | - NnopbaseDfxId* tilingId; | 185 | + NnopbaseDfxState dfx; |
| 115 | - OpSupportList* supportList; | 186 | + NnopbaseOpCompatibility opCompatibility; |
| 116 | - uint32_t* socSupportList; | ||
| 117 | - uint32_t socSupportListLen; | ||
| 118 | - bool socSupportListOwned = false; | ||
| 119 | uint32_t opTypeId; | 187 | uint32_t opTypeId; |
| 120 | int32_t poolIndex; | 188 | int32_t poolIndex; |
| 121 | void* userHandle; | 189 | void* userHandle; |
| 122 | bool isOutEmpty; | 190 | bool isOutEmpty; |
| 123 | bool isZeroEleOutputLaunch = false; | 191 | bool isZeroEleOutputLaunch = false; |
| 124 | - std::vector<void*> contextAddr; | 192 | + NnopbaseMc2Execution mc2; |
| 125 | - rtAicpuArgsEx_t aicpuArgs; | ||
| 126 | - rtFusionArgsEx_t fusionArgs; | ||
| 127 | - std::vector<aclrtStream> aicpuStream; | ||
| 128 | - std::vector<uint64_t> aicpuThread; | ||
| 129 | - std::vector<std::pair<aclrtStream, aclrtStream>> aicpuNotify; | ||
| 130 | aclOpExecutor* inUnContExe; | 193 | aclOpExecutor* inUnContExe; |
| 131 | aclOpExecutor* viewCopyExe; | 194 | aclOpExecutor* viewCopyExe; |
| 132 | size_t inUncontWsSize; | 195 | size_t inUncontWsSize; |
| 133 | - uint64_t itemId; | ||
| 134 | - uint64_t aicpuItemId; | ||
| 135 | - uint64_t memsetItemId; | ||
| 136 | - aclnnOpInfoRecord::OpKernelInfo opKernelInfo{"", 0}; | ||
| 137 | - NnopbaseTimeStamp timeStamp{}; | ||
| 138 | std::vector<uint8_t> outputShapeData; | 196 | std::vector<uint8_t> outputShapeData; |
| 139 | bool hasMemset; | 197 | bool hasMemset; |
| 140 | NnopbaseFormatCheckOption formatCheckOption; | 198 | NnopbaseFormatCheckOption formatCheckOption; |
| 141 | - NnopbaseMc2OpCfg mc2OpCfg; | ||
| 142 | bool matchArgsV2 = false; // 兼容之前的缓存匹配流程,true表示走的新流程,匹配的时候不用再重新生成key | 199 | bool matchArgsV2 = false; // 兼容之前的缓存匹配流程,true表示走的新流程,匹配的时候不用再重新生成key |
| 143 | bool isCachedArgs = false; | 200 | bool isCachedArgs = false; |
| 144 | NnopbaseCoreNum coreNum{0, 0}; | 201 | NnopbaseCoreNum coreNum{0, 0}; |
| 145 | - bool deterministic = false; | 202 | + uint8_t deterministicLevel = 0U; |
| 146 | NnopbaseParamCheckMode paramCheckMode = NnopbaseParamCheckMode::kCheckEnd; | 203 | NnopbaseParamCheckMode paramCheckMode = NnopbaseParamCheckMode::kCheckEnd; |
| 147 | } NnopbaseExecutor; | 204 | } NnopbaseExecutor; |
| 148 | 205 | ||
| @@ -169,7 +226,7 @@ struct NnopbaseExecutorSpace { | |||
| 169 | 226 | ||
| 170 | typedef struct { | 227 | typedef struct { |
| 171 | std::vector<NnopbaseExecutorSpace*> spaces; | 228 | std::vector<NnopbaseExecutorSpace*> spaces; |
| 172 | - bool isVist; | 229 | + bool isVisit; |
| 173 | } NnopbaseExecutorSpaceSet; | 230 | } NnopbaseExecutorSpaceSet; |
| 174 | 231 | ||
| 175 | typedef struct { | 232 | typedef struct { |
| @@ -204,30 +261,30 @@ void NnopbaseExecutorDeInit(NnopbaseExecutor* executor); | |||
| 204 | void StreamMapClear(aclrtStream stream); | 261 | void StreamMapClear(aclrtStream stream); |
| 205 | aclnnStatus CheckSocVersionAndParam(NnopbaseExecutor* executor, | 262 | aclnnStatus CheckSocVersionAndParam(NnopbaseExecutor* executor, |
| 206 | NnopbaseParamCheckMode mode = NnopbaseParamCheckMode::kCheckRequiredIo); | 263 | NnopbaseParamCheckMode mode = NnopbaseParamCheckMode::kCheckRequiredIo); |
| 207 | -aclnnStatus NnopbaseExecutorGenStaticKey(NnopbaseExecutor* executor, bool usingStride = false); | 264 | +aclnnStatus NnopbaseExecutorGenStaticKey(NnopbaseExecutor* const executor, const bool usingStride = false); |
| 208 | -void NnopbaseExecutorGenDynamicKey(NnopbaseExecutor* executor); | 265 | +void NnopbaseExecutorGenDynamicKey(NnopbaseExecutor* const executor); |
| 209 | size_t NnopbaseExecutorComputeGenKeySize(const NnopbaseExecutor* const executor, bool usingStride = false); | 266 | size_t NnopbaseExecutorComputeGenKeySize(const NnopbaseExecutor* const executor, bool usingStride = false); |
| 210 | -NnopbaseUChar* NnopbaseExecutorGenAttrsKey(NnopbaseAttrs* attrs, NnopbaseUChar* verKey); | 267 | +NnopbaseUChar* NnopbaseExecutorGenAttrsKey(const NnopbaseAttrs* const attrs, NnopbaseUChar* verKey); |
| 211 | -NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, NnopbaseTensors* tensors, size_t tensorNum, | 268 | +NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, const NnopbaseTensors* const tensors, |
| 212 | - bool usingStride = false); | 269 | + const size_t tensorNum, const bool usingStride = false); |
| 213 | -bool NnopbaseExecutorGetStaticBinInfo(NnopbaseExecutor* executor); | 270 | +bool NnopbaseExecutorGetStaticBinInfo(NnopbaseExecutor* const executor); |
| 214 | -NnopbaseUChar* NnopbaseExecutor8ByteCopy(size_t totalSize, NnopbaseUChar* verKey, const NnopbaseUChar* addr); | 271 | +NnopbaseUChar* NnopbaseExecutor8ByteCopy(const size_t totalSize, NnopbaseUChar* verKey, const NnopbaseUChar* addr); |
| 215 | aclnnStatus SetTensorDataSizeToInitValue(NnopbaseExecutor* executor); | 272 | aclnnStatus SetTensorDataSizeToInitValue(NnopbaseExecutor* executor); |
| 216 | 273 | ||
| 217 | // prepare args for launch | 274 | // prepare args for launch |
| 218 | void** NnopbaseExecutorPrepareNullTensors(const NnopbaseExecutor* const executor, void** addr, size_t* tensorIndex); | 275 | void** NnopbaseExecutorPrepareNullTensors(const NnopbaseExecutor* const executor, void** addr, size_t* tensorIndex); |
| 219 | -aclnnStatus NnopbaseExecutorPrepareParamsExt(NnopbaseExecutor* executor, aclrtStream const stream); | 276 | +aclnnStatus NnopbaseExecutorPrepareParamsExt(NnopbaseExecutor* const executor, aclrtStream const stream); |
| 220 | -void** NnopbaseExecutorPrepareInputsParamsExt(NnopbaseExecutor* executor, void** addr, | 277 | +void** NnopbaseExecutorPrepareInputsParamsExt(NnopbaseExecutor* const executor, void** addr, |
| 221 | - NnopbaseExecutorArgsAddr* argsAddr); | 278 | + NnopbaseExecutorArgsAddr* const argsAddr); |
| 222 | -void** NnopbaseExecutorPrepareOutputsParamsExt(NnopbaseExecutor* executor, void** addr, | 279 | +void** NnopbaseExecutorPrepareOutputsParamsExt(NnopbaseExecutor* const executor, void** addr, |
| 223 | - NnopbaseExecutorArgsAddr* argsAddr); | 280 | + NnopbaseExecutorArgsAddr* const argsAddr); |
| 224 | 281 | ||
| 225 | aclnnStatus NnopbaseExecutorTilingAndUpdateBinInfo(NnopbaseExecutor* executor); | 282 | aclnnStatus NnopbaseExecutorTilingAndUpdateBinInfo(NnopbaseExecutor* executor); |
| 226 | aclnnStatus NnopbaseExecutorGcSpace(void* data); | 283 | aclnnStatus NnopbaseExecutorGcSpace(void* data); |
| 227 | aclnnStatus NnopbaseExecutorClearSpace(NnopbaseExecutorSpace* space); | 284 | aclnnStatus NnopbaseExecutorClearSpace(NnopbaseExecutorSpace* space); |
| 228 | aclnnStatus NnopbaseExecutorSetRegInfo(NnopbaseExecutor* executor, const NnopbaseChar* opType); | 285 | aclnnStatus NnopbaseExecutorSetRegInfo(NnopbaseExecutor* executor, const NnopbaseChar* opType); |
| 229 | 286 | ||
| 230 | -bool NnopbaseExecutorGetDynamicBinInfo(NnopbaseExecutor* executor); | 287 | +bool NnopbaseExecutorGetDynamicBinInfo(NnopbaseExecutor* const executor); |
| 231 | 288 | ||
| 232 | // add io | 289 | // add io |
| 233 | struct NnopbaseTensorIoOptions { | 290 | struct NnopbaseTensorIoOptions { |
| @@ -255,9 +312,9 @@ aclnnStatus NnopbaseExecutorRunWithWorkspace(NnopbaseExecutor* executor, aclrtSt | |||
| 255 | aclnnStatus NnopbaseExecutorRunForWorkspace(NnopbaseExecutor* executor, uint64_t* workspaceLen); | 312 | aclnnStatus NnopbaseExecutorRunForWorkspace(NnopbaseExecutor* executor, uint64_t* workspaceLen); |
| 256 | void NnopbaseExecutorClear(NnopbaseExecutor* executor); | 313 | void NnopbaseExecutorClear(NnopbaseExecutor* executor); |
| 257 | 314 | ||
| 258 | -size_t NnopbaseCalcArgsSize(NnopbaseExecutor* executor, const size_t tilingDataSize); | 315 | +size_t NnopbaseCalcArgsSize(NnopbaseExecutor* const executor, const size_t tilingDataSize); |
| 259 | -void NnopbaseExecutorPrepareDfxInfo(NnopbaseExecutor* executor); | 316 | +void NnopbaseExecutorPrepareDfxInfo(NnopbaseExecutor* const executor); |
| 260 | -aclnnStatus NnopbaseExecutorArgsGetDfxInfo(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr, | 317 | +aclnnStatus NnopbaseExecutorArgsGetDfxInfo(NnopbaseExecutor* const executor, NnopbaseExecutorArgsAddr* const argsAddr, |
| 261 | const uint32_t workspaceNum); | 318 | const uint32_t workspaceNum); |
| 262 | bool NnopbaseMatchArgsCache(NnopbaseExecutor* executor, size_t& seed); | 319 | bool NnopbaseMatchArgsCache(NnopbaseExecutor* executor, size_t& seed); |
| 263 | aclnnStatus NnopbaseCreateExecutorArgs(NnopbaseExecutor* executor, const size_t seed); | 320 | aclnnStatus NnopbaseCreateExecutorArgs(NnopbaseExecutor* executor, const size_t seed); |
| @@ -307,7 +364,7 @@ aclnnStatus NnopbaseExecutorGetCoreTypeAndTaskRation(NnopbaseExecutor* executor, | |||
| 307 | aclnnStatus NnopbaseSetMc2Tiling(NnopbaseExecutor* executor, const char* const group); | 364 | aclnnStatus NnopbaseSetMc2Tiling(NnopbaseExecutor* executor, const char* const group); |
| 308 | static inline void NnopbaseExecutorSetHcclServerType(NnopbaseExecutor* executor, NnopbaseHcclServerType sType) | 365 | static inline void NnopbaseExecutorSetHcclServerType(NnopbaseExecutor* executor, NnopbaseHcclServerType sType) |
| 309 | { | 366 | { |
| 310 | - executor->mc2OpCfg.sType = sType; | 367 | + executor->mc2.serverType = sType; |
| 311 | } | 368 | } |
| 312 | 369 | ||
| 313 | aclnnStatus NnopbaseSetRefTensorAddr(NnopbaseExecutor* executor, const size_t index, const void* const addr, | 370 | aclnnStatus NnopbaseSetRefTensorAddr(NnopbaseExecutor* executor, const size_t index, const void* const addr, |
| @@ -348,7 +405,7 @@ inline bool NnopbaseSkipKernelLaunch(const NnopbaseExecutor* executor) | |||
| 348 | inline void RecordNnopbaseTime(NnopbaseExecutor* const executor, const size_t index) | 405 | inline void RecordNnopbaseTime(NnopbaseExecutor* const executor, const size_t index) |
| 349 | { | 406 | { |
| 350 | if (g_nnopbaseSysCfgParams.enableTimeStamp) { | 407 | if (g_nnopbaseSysCfgParams.enableTimeStamp) { |
| 351 | - clock_gettime(CLOCK_MONOTONIC, &(executor->timeStamp.tp[index])); | 408 | + clock_gettime(CLOCK_MONOTONIC, &(executor->dfx.timeStamp.tp[index])); |
| 352 | } | 409 | } |
| 353 | } | 410 | } |
| 354 | 411 | ||
| @@ -377,15 +434,17 @@ inline const NnopbaseWorkspaceSizes* NnopbaseGetWorkspacesSizesFromArgs(const Nn | |||
| 377 | 434 | ||
| 378 | static inline void NnopbaseExecutorAddTilingId(NnopbaseExecutor* executor, NnopbaseDfxId* tilingId) | 435 | static inline void NnopbaseExecutorAddTilingId(NnopbaseExecutor* executor, NnopbaseDfxId* tilingId) |
| 379 | { | 436 | { |
| 380 | - executor->tilingId = tilingId; | 437 | + executor->dfx.tilingId = tilingId; |
| 381 | } | 438 | } |
| 382 | 439 | ||
| 383 | -static inline void NnopbaseExecutorAddSupportList(NnopbaseExecutor* executor, OpSupportList* supportList, | 440 | +static inline void NnopbaseExecutorAddSupportList(NnopbaseOpCompatibility& opCompatibility, OpSupportList* supportList, |
| 384 | - uint32_t* socSupportList, size_t socSupportListLen) | 441 | + uint32_t* socSupportList, size_t socSupportListLen, |
| 442 | + bool ownsSupportedSocList = false) | ||
| 385 | { | 443 | { |
| 386 | - executor->supportList = supportList; | 444 | + opCompatibility.paramSupportList = supportList; |
| 387 | - executor->socSupportList = socSupportList; | 445 | + opCompatibility.supportedSocList = socSupportList; |
| 388 | - executor->socSupportListLen = socSupportListLen; | 446 | + opCompatibility.supportedSocCount = static_cast<uint32_t>(socSupportListLen); |
| 447 | + opCompatibility.ownsSupportedSocList = ownsSupportedSocList; | ||
| 389 | } | 448 | } |
| 390 | 449 | ||
| 391 | static inline void NnopbaseExecutorAddOpTypeId(NnopbaseExecutor* executor, const uint32_t opTypeId) | 450 | static inline void NnopbaseExecutorAddOpTypeId(NnopbaseExecutor* executor, const uint32_t opTypeId) |
| @@ -437,13 +496,13 @@ static inline void NnopbaseExecutorReleaseRefContiguousTensors(NnopbaseExecutor* | |||
| 437 | executor->args->inputs.unContiguousTensors.refContTensorList = nullptr; | 496 | executor->args->inputs.unContiguousTensors.refContTensorList = nullptr; |
| 438 | } | 497 | } |
| 439 | 498 | ||
| 440 | -static inline void NnopbaseExecutorSpaceSetInit(NnopbaseExecutorSpaceSet* set) { set->isVist = false; } | 499 | +static inline void NnopbaseExecutorSpaceSetInit(NnopbaseExecutorSpaceSet* set) { set->isVisit = false; } |
| 441 | static inline void NnopbaseExecutorAddSpaceToSet(NnopbaseExecutorSpaceSet* set, NnopbaseExecutorSpace* space) | 500 | static inline void NnopbaseExecutorAddSpaceToSet(NnopbaseExecutorSpaceSet* set, NnopbaseExecutorSpace* space) |
| 442 | { | 501 | { |
| 443 | - while (!__sync_bool_compare_and_swap(&set->isVist, false, true)) | 502 | + while (!__sync_bool_compare_and_swap(&set->isVisit, false, true)) |
| 444 | ; | 503 | ; |
| 445 | set->spaces.push_back(space); | 504 | set->spaces.push_back(space); |
| 446 | - set->isVist = false; | 505 | + set->isVisit = false; |
| 447 | } | 506 | } |
| 448 | 507 | ||
| 449 | void NnopbaseExecutorClearSet(NnopbaseExecutorSpaceSet* set); | 508 | void NnopbaseExecutorClearSet(NnopbaseExecutorSpaceSet* set); |
| @@ -36,12 +36,13 @@ void PrintTime(const NnopbaseExecutor* const executor, const char* const info, c | |||
| 36 | { | 36 | { |
| 37 | unsigned long time = 0U; | 37 | unsigned long time = 0U; |
| 38 | if (startIndex < NnopbaseTimeIdx::kNum && endIndex < NnopbaseTimeIdx::kNum && | 38 | if (startIndex < NnopbaseTimeIdx::kNum && endIndex < NnopbaseTimeIdx::kNum && |
| 39 | - executor->timeStamp.tp[endIndex].tv_nsec != 0) { | 39 | + executor->dfx.timeStamp.tp[endIndex].tv_nsec != 0) { |
| 40 | - if (executor->timeStamp.tp[startIndex].tv_sec != executor->timeStamp.tp[endIndex].tv_sec) { | 40 | + if (executor->dfx.timeStamp.tp[startIndex].tv_sec != executor->dfx.timeStamp.tp[endIndex].tv_sec) { |
| 41 | // 1000000000 for time stamp | 41 | // 1000000000 for time stamp |
| 42 | - time = executor->timeStamp.tp[endIndex].tv_nsec + 1000000000 - executor->timeStamp.tp[startIndex].tv_nsec; | 42 | + time = executor->dfx.timeStamp.tp[endIndex].tv_nsec + 1000000000 - |
| 43 | + executor->dfx.timeStamp.tp[startIndex].tv_nsec; | ||
| 43 | } else { | 44 | } else { |
| 44 | - time = executor->timeStamp.tp[endIndex].tv_nsec - executor->timeStamp.tp[startIndex].tv_nsec; | 45 | + time = executor->dfx.timeStamp.tp[endIndex].tv_nsec - executor->dfx.timeStamp.tp[startIndex].tv_nsec; |
| 45 | } | 46 | } |
| 46 | } | 47 | } |
| 47 | OP_EVENT("Nnopbase time %s : %f us", info, time / 1000.0); // 1000.0 for time us | 48 | OP_EVENT("Nnopbase time %s : %f us", info, time / 1000.0); // 1000.0 for time us |
| @@ -75,26 +76,22 @@ void NnopbaseExecutorClearAttrs(NnopbaseAttrs* attrs) | |||
| 75 | 76 | ||
| 76 | void NnopbaseExecutorReset(NnopbaseExecutor* executor) | 77 | void NnopbaseExecutorReset(NnopbaseExecutor* executor) |
| 77 | { | 78 | { |
| 79 | + executor->dfx.Reset(); | ||
| 78 | executor->isOutEmpty = false; | 80 | executor->isOutEmpty = false; |
| 79 | executor->workspaces.num = 0U; | 81 | executor->workspaces.num = 0U; |
| 80 | executor->hasTiling = true; | 82 | executor->hasTiling = true; |
| 81 | executor->ownArgs.enableCache = true; | 83 | executor->ownArgs.enableCache = true; |
| 82 | executor->userHandle = nullptr; | 84 | executor->userHandle = nullptr; |
| 83 | - executor->mc2OpCfg.isMc2 = false; | 85 | + executor->mc2.ClearRuntimeState(); |
| 84 | - executor->contextAddr.clear(); | ||
| 85 | - executor->mc2OpCfg.hcomHandle.clear(); | ||
| 86 | executor->inUnContExe = nullptr; | 86 | executor->inUnContExe = nullptr; |
| 87 | executor->viewCopyExe = nullptr; | 87 | executor->viewCopyExe = nullptr; |
| 88 | executor->inUncontWsSize = 0U; | 88 | executor->inUncontWsSize = 0U; |
| 89 | - executor->aicpuStream.clear(); | ||
| 90 | - executor->aicpuNotify.clear(); | ||
| 91 | executor->repeatFlag = false; | 89 | executor->repeatFlag = false; |
| 92 | executor->hasMemset = false; | 90 | executor->hasMemset = false; |
| 93 | executor->formatCheckOption = kNnopbaseDefault; | 91 | executor->formatCheckOption = kNnopbaseDefault; |
| 94 | - executor->mc2OpCfg.sType = NNOPBASE_HCCL_SERVER_TYPE_END; | ||
| 95 | executor->isCachedArgs = false; | 92 | executor->isCachedArgs = false; |
| 96 | executor->matchArgsV2 = false; | 93 | executor->matchArgsV2 = false; |
| 97 | - executor->deterministic = false; | 94 | + executor->deterministicLevel = 0U; |
| 98 | } | 95 | } |
| 99 | } // namespace | 96 | } // namespace |
| 100 | 97 | ||
| @@ -280,11 +277,7 @@ aclnnStatus NnopbaseExecutorInit(NnopbaseExecutor* executor, const NnopbaseOpInf | |||
| 280 | 277 | ||
| 281 | executor->hasMemset = false; | 278 | executor->hasMemset = false; |
| 282 | executor->args = nullptr; | 279 | executor->args = nullptr; |
| 283 | - executor->tilingKey = nullptr; | 280 | + executor->tiling.Init(); |
| 284 | - executor->numBlocks = nullptr; | ||
| 285 | - executor->needAtomic = nullptr; | ||
| 286 | - executor->scheMode = nullptr; | ||
| 287 | - executor->dynUbufSize = nullptr; | ||
| 288 | executor->collector = nullptr; | 281 | executor->collector = nullptr; |
| 289 | executor->workspaces.num = 0U; | 282 | executor->workspaces.num = 0U; |
| 290 | executor->workspaces.length = 0U; | 283 | executor->workspaces.length = 0U; |
| @@ -294,26 +287,18 @@ aclnnStatus NnopbaseExecutorInit(NnopbaseExecutor* executor, const NnopbaseOpInf | |||
| 294 | executor->binInfoKey.bufLen = 0U; | 287 | executor->binInfoKey.bufLen = 0U; |
| 295 | executor->hasTiling = true; | 288 | executor->hasTiling = true; |
| 296 | executor->isWork = false; | 289 | executor->isWork = false; |
| 297 | - executor->tilingId = nullptr; | 290 | + executor->dfx.Init(); |
| 298 | - executor->supportList = nullptr; | 291 | + executor->opCompatibility = {}; |
| 299 | - executor->socSupportList = nullptr; | ||
| 300 | - executor->socSupportListLen = 0U; | ||
| 301 | executor->opTypeId = 0U; | 292 | executor->opTypeId = 0U; |
| 302 | executor->poolIndex = -1; | 293 | executor->poolIndex = -1; |
| 303 | executor->userHandle = nullptr; | 294 | executor->userHandle = nullptr; |
| 304 | executor->isOutEmpty = false; | 295 | executor->isOutEmpty = false; |
| 305 | - executor->mc2OpCfg.isMc2 = false; | 296 | + executor->mc2.Reset(); |
| 306 | executor->inUnContExe = nullptr; | 297 | executor->inUnContExe = nullptr; |
| 307 | executor->viewCopyExe = nullptr; | 298 | executor->viewCopyExe = nullptr; |
| 308 | executor->inUncontWsSize = 0U; | 299 | executor->inUncontWsSize = 0U; |
| 309 | - executor->itemId = 0U; | ||
| 310 | - executor->aicpuItemId = 0U; | ||
| 311 | - executor->memsetItemId = 0U; | ||
| 312 | - executor->aicpuStream.clear(); | ||
| 313 | - executor->aicpuNotify.clear(); | ||
| 314 | executor->repeatFlag = false; | 300 | executor->repeatFlag = false; |
| 315 | executor->formatCheckOption = kNnopbaseDefault; | 301 | executor->formatCheckOption = kNnopbaseDefault; |
| 316 | - executor->mc2OpCfg.sType = NNOPBASE_HCCL_SERVER_TYPE_END; | ||
| 317 | (void)NnopbaseTilingContextInit(executor); | 302 | (void)NnopbaseTilingContextInit(executor); |
| 318 | return OK; | 303 | return OK; |
| 319 | } | 304 | } |
| @@ -350,12 +335,10 @@ void NnopbaseExecutorDeInit(NnopbaseExecutor* executor) | |||
| 350 | { | 335 | { |
| 351 | NnopbaseExecutorDeInitAttrsCaches(executor); | 336 | NnopbaseExecutorDeInitAttrsCaches(executor); |
| 352 | NnopbaseTilingContextDeInit(executor); | 337 | NnopbaseTilingContextDeInit(executor); |
| 353 | - if (executor->socSupportListOwned) { | 338 | + if (executor->opCompatibility.ownsSupportedSocList) { |
| 354 | - delete[] executor->socSupportList; | 339 | + delete[] executor->opCompatibility.supportedSocList; |
| 355 | } | 340 | } |
| 356 | - executor->socSupportList = nullptr; | 341 | + executor->opCompatibility = {}; |
| 357 | - executor->socSupportListLen = 0U; | ||
| 358 | - executor->socSupportListOwned = false; | ||
| 359 | FREE(executor->opType); | 342 | FREE(executor->opType); |
| 360 | } | 343 | } |
| 361 | 344 | ||
| @@ -393,20 +376,20 @@ void NnopbaseExecutorFixCache(NnopbaseExecutor* executor) | |||
| 393 | // NnopbaseInit内部调用,调用前已保证设置锁 | 376 | // NnopbaseInit内部调用,调用前已保证设置锁 |
| 394 | aclnnStatus NnopbaseExecutorSetGlobalConfig() | 377 | aclnnStatus NnopbaseExecutorSetGlobalConfig() |
| 395 | { | 378 | { |
| 396 | - g_nnopbaseSysCfgParams.enableTimeStamp = nnopbase::EnableNnopbaseTimeStamp(); // 是否开启性能打点 | 379 | + g_nnopbaseSysCfgParams.enableTimeStamp = nnopbase::EnableNnopbaseTimeStamp(); // 是否开启性能打点 |
| 397 | - g_nnopbaseSysCfgParams.enableArgsCache = nnopbase::EnableNnopbaseArgsCache(); // 是否开启args(tiling)缓存 | 380 | + g_nnopbaseSysCfgParams.enableArgsCache = nnopbase::EnableNnopbaseArgsCache(); // 是否开启args(tiling)缓存 |
| 398 | - g_nnopbaseSysCfgParams.deterministic = nnopbase::GetGlobalDeterministic(); // 确定性设置 | 381 | + g_nnopbaseSysCfgParams.deterministicLevel = nnopbase::GetGlobalDeterministic(); // 确定性设置 |
| 399 | g_nnopbaseSysCfgParams.implMode = nnopbase::NnopbaseGetImplMode( | 382 | g_nnopbaseSysCfgParams.implMode = nnopbase::NnopbaseGetImplMode( |
| 400 | - g_nnopbaseSysCfgParams.precision); // 高性能/高精度模式设置 | 383 | + g_nnopbaseSysCfgParams.precision); // 高性能/高精度模式设置 |
| 401 | NNOPBASE_ASSERT_OK_RETVAL( | 384 | NNOPBASE_ASSERT_OK_RETVAL( |
| 402 | - nnopbase::NnopbaseSetOverFlowAddr(g_nnopbaseSysCfgParams.overflowAddr)); // 设置溢出检测地址 | 385 | + nnopbase::NnopbaseSetOverFlowAddr(g_nnopbaseSysCfgParams.overflowAddr)); // 设置溢出检测地址 |
| 403 | g_nnopbaseSysCfgParams.enableDebugKernel = nnopbase::GetDebugKernel(); | 386 | g_nnopbaseSysCfgParams.enableDebugKernel = nnopbase::GetDebugKernel(); |
| 404 | 387 | ||
| 405 | - OP_LOGD("Set global config timeStamp enable = %d, argsCache enable = %d, deterministic = %d," | 388 | + OP_LOGD("Set global config timeStamp enable = %d, argsCache enable = %d, deterministicLevel = %d," |
| 406 | "precision = %d, overflowAddr = %p, debugKernel = %d.", | 389 | "precision = %d, overflowAddr = %p, debugKernel = %d.", |
| 407 | g_nnopbaseSysCfgParams.enableTimeStamp, g_nnopbaseSysCfgParams.enableArgsCache, | 390 | g_nnopbaseSysCfgParams.enableTimeStamp, g_nnopbaseSysCfgParams.enableArgsCache, |
| 408 | - g_nnopbaseSysCfgParams.deterministic, g_nnopbaseSysCfgParams.precision, g_nnopbaseSysCfgParams.overflowAddr, | 391 | + g_nnopbaseSysCfgParams.deterministicLevel, g_nnopbaseSysCfgParams.precision, |
| 409 | - g_nnopbaseSysCfgParams.enableDebugKernel); | 392 | + g_nnopbaseSysCfgParams.overflowAddr, g_nnopbaseSysCfgParams.enableDebugKernel); |
| 410 | return OK; | 393 | return OK; |
| 411 | } | 394 | } |
| 412 | 395 | ||
| @@ -499,7 +482,7 @@ aclnnStatus NnopbaseExecutorInsertMemsetOp(NnopbaseExecutor* executor) | |||
| 499 | { | 482 | { |
| 500 | executor->hasMemset = executor->args->binInfo->isStaticShape ? true : executor->args->tilingInfo.needAtomic; | 483 | executor->hasMemset = executor->args->binInfo->isStaticShape ? true : executor->args->tilingInfo.needAtomic; |
| 501 | if (executor->hasMemset) { | 484 | if (executor->hasMemset) { |
| 502 | - // 构造tilingContext | 485 | + // 构造 memset tiling 上下文 |
| 503 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseBuildMemsetTilingContext(executor)); | 486 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseBuildMemsetTilingContext(executor)); |
| 504 | NNOPBASE_ASSERT_OK_RETVAL(NnopnbaseMemsetTiling(executor)); | 487 | NNOPBASE_ASSERT_OK_RETVAL(NnopnbaseMemsetTiling(executor)); |
| 505 | } | 488 | } |
| @@ -509,7 +492,7 @@ aclnnStatus NnopbaseExecutorInsertMemsetOp(NnopbaseExecutor* executor) | |||
| 509 | static inline void NnopbaseExecutorPreportMemsetProfiling(const NnopbaseExecutor* const executor, uint32_t numBlocks, | 492 | static inline void NnopbaseExecutorPreportMemsetProfiling(const NnopbaseExecutor* const executor, uint32_t numBlocks, |
| 510 | const uint32_t taskType, const uint64_t launchBeginTime) | 493 | const uint32_t taskType, const uint64_t launchBeginTime) |
| 511 | { | 494 | { |
| 512 | - NnopbaseInnerReportLaunchInfo(launchBeginTime, executor->memsetItemId); | 495 | + NnopbaseInnerReportLaunchInfo(launchBeginTime, executor->dfx.memsetItemId); |
| 513 | NnopbaseReportMemsetAdditionInfo(executor, numBlocks, taskType, launchBeginTime + 1U); | 496 | NnopbaseReportMemsetAdditionInfo(executor, numBlocks, taskType, launchBeginTime + 1U); |
| 514 | return; | 497 | return; |
| 515 | } | 498 | } |
| @@ -620,7 +603,7 @@ aclnnStatus NnopbaseLaunchMemsetTask(NnopbaseExecutor* executor, aclrtStream str | |||
| 620 | void NnopbaseExecutorReportProfiling(NnopbaseExecutor* const executor, uint32_t numBlocks, const uint32_t taskType, | 603 | void NnopbaseExecutorReportProfiling(NnopbaseExecutor* const executor, uint32_t numBlocks, const uint32_t taskType, |
| 621 | const uint64_t launchBeginTime, aclrtStream stream) | 604 | const uint64_t launchBeginTime, aclrtStream stream) |
| 622 | { | 605 | { |
| 623 | - NnopbaseInnerReportLaunchInfo(launchBeginTime, executor->itemId); | 606 | + NnopbaseInnerReportLaunchInfo(launchBeginTime, executor->dfx.itemId); |
| 624 | NnopbaseReportAdditionInfo(executor, numBlocks, taskType, launchBeginTime + 1U); | 607 | NnopbaseReportAdditionInfo(executor, numBlocks, taskType, launchBeginTime + 1U); |
| 625 | NnopbaseReportAttrAndHostInfo(executor, launchBeginTime + 1U); | 608 | NnopbaseReportAttrAndHostInfo(executor, launchBeginTime + 1U); |
| 626 | NnopbaseReportCacheOpInfo(executor, numBlocks, taskType, stream); | 609 | NnopbaseReportCacheOpInfo(executor, numBlocks, taskType, stream); |
| @@ -663,7 +646,8 @@ void PrintNnopbaseAllTimeStampInfo(NnopbaseExecutor* const executor) | |||
| 663 | PrintTime(executor, "before launch", NnopbaseTimeIdx::kRunWithWsStart, NnopbaseTimeIdx::kBeforeLaunch); | 646 | PrintTime(executor, "before launch", NnopbaseTimeIdx::kRunWithWsStart, NnopbaseTimeIdx::kBeforeLaunch); |
| 664 | PrintTime(executor, "launch", NnopbaseTimeIdx::kBeforeLaunch, NnopbaseTimeIdx::kAfterLaunch); | 647 | PrintTime(executor, "launch", NnopbaseTimeIdx::kBeforeLaunch, NnopbaseTimeIdx::kAfterLaunch); |
| 665 | PrintTime(executor, "after launch", NnopbaseTimeIdx::kAfterLaunch, NnopbaseTimeIdx::kRunWithWsEnd); | 648 | PrintTime(executor, "after launch", NnopbaseTimeIdx::kAfterLaunch, NnopbaseTimeIdx::kRunWithWsEnd); |
| 666 | - (void)memset_s(executor->timeStamp.tp, sizeof(executor->timeStamp.tp), 0, sizeof(executor->timeStamp.tp)); | 649 | + (void)memset_s(executor->dfx.timeStamp.tp, sizeof(executor->dfx.timeStamp.tp), 0, |
| 650 | + sizeof(executor->dfx.timeStamp.tp)); | ||
| 667 | } | 651 | } |
| 668 | } | 652 | } |
| 669 | 653 | ||
| @@ -702,8 +686,10 @@ aclnnStatus NnopbaseExecutorSetRegInfo(NnopbaseExecutor* executor, const Nnopbas | |||
| 702 | std::string | 686 | std::string |
| 703 | errMsg = "1.SoC version " + socVersion + | 687 | errMsg = "1.SoC version " + socVersion + |
| 704 | " verification failed. This SoC is not configured through the AddConfig API of the OpDef class. "; | 688 | " verification failed. This SoC is not configured through the AddConfig API of the OpDef class. "; |
| 705 | - errMsg += "2.The binary_info_config.json file to which the " + std::string(opType) + " operator belongs fails to " | 689 | + errMsg += "2.The binary_info_config.json file to which the " + std::string(opType) + |
| 706 | - "be loaded because the file is damaged or does not exist or the user does not have sufficient permissions. "; | 690 | + " operator belongs fails to " |
| 691 | + "be loaded because the file is damaged or does not exist or the user does not have sufficient " | ||
| 692 | + "permissions. "; | ||
| 707 | errMsg += "3.The operator package to which the " + std::string(opType) + " operator belongs is not installed"; | 693 | errMsg += "3.The operator package to which the " + std::string(opType) + " operator belongs is not installed"; |
| 708 | OP_LOGE_FOR_EXECUTION_ERROR_WITHOUT_SOLUTION(errMsg.c_str()); | 694 | OP_LOGE_FOR_EXECUTION_ERROR_WITHOUT_SOLUTION(errMsg.c_str()); |
| 709 | return ACLNN_ERR_PARAM_NULLPTR; | 695 | return ACLNN_ERR_PARAM_NULLPTR; |
| @@ -714,16 +700,16 @@ aclnnStatus NnopbaseExecutorSetRegInfo(NnopbaseExecutor* executor, const Nnopbas | |||
| 714 | NNOPBASE_ASSERT_TRUE_RETVAL(strcpy_s(executor->opType, len + 1U, opType) == EOK); | 700 | NNOPBASE_ASSERT_TRUE_RETVAL(strcpy_s(executor->opType, len + 1U, opType) == EOK); |
| 715 | executor->opTypeHash = hashKey; | 701 | executor->opTypeHash = hashKey; |
| 716 | } | 702 | } |
| 717 | - executor->itemId = MsprofGetHashId(opType, len); | 703 | + executor->dfx.itemId = MsprofGetHashId(opType, len); |
| 718 | const std::string aicpuOpType = std::string(opType) + NNOPBASE_MC2_AICPU_SUFFIX; | 704 | const std::string aicpuOpType = std::string(opType) + NNOPBASE_MC2_AICPU_SUFFIX; |
| 719 | - executor->aicpuItemId = MsprofGetHashId(&aicpuOpType[0], aicpuOpType.length()); | 705 | + executor->dfx.aicpuItemId = MsprofGetHashId(&aicpuOpType[0], aicpuOpType.length()); |
| 720 | - executor->memsetItemId = MsprofGetHashId(&NNOPBASE_MEMSET_OP_NAME[0], NNOPBASE_MEMSET_OP_NAME.length()); | 706 | + executor->dfx.memsetItemId = MsprofGetHashId(&NNOPBASE_MEMSET_OP_NAME[0], NNOPBASE_MEMSET_OP_NAME.length()); |
| 721 | OP_LOGI("OpType is %s, hashKey is %lu, item id is %lu, aicpu item id is %lu, memset item id is %lu.", opType, | 707 | OP_LOGI("OpType is %s, hashKey is %lu, item id is %lu, aicpu item id is %lu, memset item id is %lu.", opType, |
| 722 | - hashKey, executor->itemId, executor->aicpuItemId, executor->memsetItemId); | 708 | + hashKey, executor->dfx.itemId, executor->dfx.aicpuItemId, executor->dfx.memsetItemId); |
| 723 | return OK; | 709 | return OK; |
| 724 | } | 710 | } |
| 725 | 711 | ||
| 726 | -NnopbaseUChar* NnopbaseExecutor8ByteCopy(size_t totalSize, NnopbaseUChar* verKey, const NnopbaseUChar* addr) | 712 | +NnopbaseUChar* NnopbaseExecutor8ByteCopy(const size_t totalSize, NnopbaseUChar* verKey, const NnopbaseUChar* addr) |
| 727 | { | 713 | { |
| 728 | const size_t length = totalSize / 8U; | 714 | const size_t length = totalSize / 8U; |
| 729 | if (length != 0) { | 715 | if (length != 0) { |
| @@ -925,17 +911,16 @@ aclnnStatus NnopbaseSetMc2Tiling(NnopbaseExecutor* executor, const char* const g | |||
| 925 | { | 911 | { |
| 926 | HcclComm commHandle = nullptr; | 912 | HcclComm commHandle = nullptr; |
| 927 | NNOPBASE_ASSERT_RTOK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcomGetCommHandleByGroup(group, &commHandle)); | 913 | NNOPBASE_ASSERT_RTOK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcomGetCommHandleByGroup(group, &commHandle)); |
| 928 | - executor->mc2OpCfg.hcomHandle.push_back(commHandle); | 914 | + executor->mc2.commHandles.push_back(commHandle); |
| 929 | NNOPBASE_ASSERT_RTOK_RETVAL(nnopbase::utils::ThreadVarContainer::SetCurMc2RankIdInThread(commHandle)); | 915 | NNOPBASE_ASSERT_RTOK_RETVAL(nnopbase::utils::ThreadVarContainer::SetCurMc2RankIdInThread(commHandle)); |
| 930 | return OK; | 916 | return OK; |
| 931 | } | 917 | } |
| 932 | 918 | ||
| 933 | -void NnopbaseExecutorGenDynamicKey(NnopbaseExecutor* executor) | 919 | +static NnopbaseUChar* NnopbaseInitDynamicKeyBuffer(NnopbaseExecutor* const executor, |
| 920 | + const NnopbaseTensors* const inputs, | ||
| 921 | + const NnopbaseTensors* const outputs) | ||
| 934 | { | 922 | { |
| 935 | NnopbaseUChar* verKey = nullptr; | 923 | NnopbaseUChar* verKey = nullptr; |
| 936 | - NnopbaseTensors* inputs = &executor->ownArgs.inputs; | ||
| 937 | - NnopbaseTensors* outputs = &executor->ownArgs.outputs; | ||
| 938 | - // verb key format: op_type/Deterministic,Precision/input num/output num/tensor desc... | ||
| 939 | if (executor->binInfoKey.verbose.empty()) { | 924 | if (executor->binInfoKey.verbose.empty()) { |
| 940 | const uint32_t len = inputs->requiredCnt * NNOPBASE_VERKEY_TENSOR_DESC_NUM + | 925 | const uint32_t len = inputs->requiredCnt * NNOPBASE_VERKEY_TENSOR_DESC_NUM + |
| 941 | inputs->dynamicNum * NNOPBASE_VERKEY_TENSOR_DESC_NUM + | 926 | inputs->dynamicNum * NNOPBASE_VERKEY_TENSOR_DESC_NUM + |
| @@ -951,45 +936,55 @@ void NnopbaseExecutorGenDynamicKey(NnopbaseExecutor* executor) | |||
| 951 | } else { | 936 | } else { |
| 952 | verKey = &(executor->binInfoKey.verbose[0U]) + executor->regInfo->key.opType.size(); | 937 | verKey = &(executor->binInfoKey.verbose[0U]) + executor->regInfo->key.opType.size(); |
| 953 | } | 938 | } |
| 954 | - verKey = NnopbaseAppend1Byte(verKey, static_cast<NnopbaseUChar>(executor->deterministic)); | 939 | + return verKey; |
| 955 | - verKey = NnopbaseAppend1Byte(verKey, g_nnopbaseSysCfgParams.precision); | 940 | +} |
| 956 | - OP_LOGI("Verbose opType is %s, deterministic value is %d, highPrecision value is %d, verboseLen is %u", | ||
| 957 | - executor->regInfo->key.opType.c_str(), executor->deterministic, g_nnopbaseSysCfgParams.precision, | ||
| 958 | - executor->binInfoKey.len); | ||
| 959 | 941 | ||
| 960 | - for (uint32_t i = 0U; i < inputs->paramDescs.count; i++) { | 942 | +static NnopbaseUChar* NnopbaseAppendDynamicKeyHead(const NnopbaseExecutor* const executor, NnopbaseUChar* verKey) |
| 961 | - if (inputs->paramDescs.instances[i].cfgNum == 0) { | 943 | +{ |
| 944 | + uint8_t determinLevel = (executor->deterministicLevel == 0U) ? 0U : 1U; | ||
| 945 | + verKey = NnopbaseAppend1Byte(verKey, static_cast<NnopbaseUChar>(determinLevel)); | ||
| 946 | + verKey = NnopbaseAppend1Byte(verKey, g_nnopbaseSysCfgParams.precision); | ||
| 947 | + OP_LOGI("Verbose opType is %s, determinLevel is %d, highPrecision is %d, verboseLen is %u", | ||
| 948 | + executor->regInfo->key.opType.c_str(), executor->deterministicLevel, g_nnopbaseSysCfgParams.precision, | ||
| 949 | + executor->binInfoKey.len); | ||
| 950 | + return verKey; | ||
| 951 | +} | ||
| 952 | + | ||
| 953 | +static NnopbaseUChar* NnopbaseAppendDynamicTensorsKey(const NnopbaseExecutor* const executor, NnopbaseUChar* verKey, | ||
| 954 | + const NnopbaseTensors* const tensors, const char* const ioType) | ||
| 955 | +{ | ||
| 956 | + for (uint32_t i = 0U; i < tensors->paramDescs.count; i++) { | ||
| 957 | + if (tensors->paramDescs.instances[i].cfgNum == 0) { | ||
| 962 | continue; | 958 | continue; |
| 963 | } | 959 | } |
| 964 | - const uint32_t startIndex = inputs->paramDescs.instances[i].startIndex; | 960 | + const uint32_t startIndex = tensors->paramDescs.instances[i].startIndex; |
| 965 | verKey = NnopbaseAppend1Byte( | 961 | verKey = NnopbaseAppend1Byte( |
| 966 | - verKey, static_cast<NnopbaseUChar>(inputs->extTensors[startIndex].rt2Tensor.GetDataType())); | 962 | + verKey, static_cast<NnopbaseUChar>(tensors->extTensors[startIndex].rt2Tensor.GetDataType())); |
| 967 | verKey = NnopbaseAppend1Byte( | 963 | verKey = NnopbaseAppend1Byte( |
| 968 | - verKey, static_cast<NnopbaseUChar>(inputs->extTensors[startIndex].rt2Tensor.GetStorageFormat())); | 964 | + verKey, static_cast<NnopbaseUChar>(tensors->extTensors[startIndex].rt2Tensor.GetStorageFormat())); |
| 969 | - OP_LOGI("Op %s input[%u] datatype is %s, format is %s.", executor->opType, startIndex, | 965 | + OP_LOGI("Op %s %s[%u] datatype is %s, format is %s.", executor->opType, ioType, startIndex, |
| 970 | - op::ToString(inputs->extTensors[startIndex].rt2Tensor.GetDataType()).GetString(), | 966 | + op::ToString(tensors->extTensors[startIndex].rt2Tensor.GetDataType()).GetString(), |
| 971 | - op::ToString(inputs->extTensors[startIndex].rt2Tensor.GetStorageFormat()).GetString()); | 967 | + op::ToString(tensors->extTensors[startIndex].rt2Tensor.GetStorageFormat()).GetString()); |
| 972 | - } | ||
| 973 | - for (uint32_t i = 0U; i < outputs->paramDescs.count; i++) { | ||
| 974 | - if (outputs->paramDescs.instances[i].cfgNum == 0) { | ||
| 975 | - continue; | ||
| 976 | - } | ||
| 977 | - const uint32_t startIndex = outputs->paramDescs.instances[i].startIndex; | ||
| 978 | - verKey = NnopbaseAppend1Byte( | ||
| 979 | - verKey, static_cast<NnopbaseUChar>(outputs->extTensors[startIndex].rt2Tensor.GetDataType())); | ||
| 980 | - verKey = NnopbaseAppend1Byte( | ||
| 981 | - verKey, static_cast<NnopbaseUChar>(outputs->extTensors[startIndex].rt2Tensor.GetStorageFormat())); | ||
| 982 | - OP_LOGI("Op %s output[%u] datatype is %s, format is %s.", executor->opType, startIndex, | ||
| 983 | - op::ToString(outputs->extTensors[startIndex].rt2Tensor.GetDataType()).GetString(), | ||
| 984 | - op::ToString(outputs->extTensors[startIndex].rt2Tensor.GetStorageFormat()).GetString()); | ||
| 985 | } | 968 | } |
| 969 | + return verKey; | ||
| 970 | +} | ||
| 971 | + | ||
| 972 | +void NnopbaseExecutorGenDynamicKey(NnopbaseExecutor* const executor) | ||
| 973 | +{ | ||
| 974 | + const NnopbaseTensors* const inputs = &executor->ownArgs.inputs; | ||
| 975 | + const NnopbaseTensors* const outputs = &executor->ownArgs.outputs; | ||
| 976 | + // verb key format: op_type/Deterministic,Precision/input num/output num/tensor desc... | ||
| 977 | + NnopbaseUChar* verKey = NnopbaseInitDynamicKeyBuffer(executor, inputs, outputs); | ||
| 978 | + verKey = NnopbaseAppendDynamicKeyHead(executor, verKey); | ||
| 979 | + verKey = NnopbaseAppendDynamicTensorsKey(executor, verKey, inputs, "input"); | ||
| 980 | + verKey = NnopbaseAppendDynamicTensorsKey(executor, verKey, outputs, "output"); | ||
| 986 | executor->binInfoKey.len = static_cast<uint32_t>(verKey - &(executor->binInfoKey.verbose[0U])); | 981 | executor->binInfoKey.len = static_cast<uint32_t>(verKey - &(executor->binInfoKey.verbose[0U])); |
| 987 | OP_LOGI("Op %s binInfoKey size %u", executor->opType, executor->binInfoKey.len); | 982 | OP_LOGI("Op %s binInfoKey size %u", executor->opType, executor->binInfoKey.len); |
| 988 | executor->binInfoKey.hashKey = NnopbaseHashBinary(&(executor->binInfoKey.verbose[0U]), executor->binInfoKey.len) % | 983 | executor->binInfoKey.hashKey = NnopbaseHashBinary(&(executor->binInfoKey.verbose[0U]), executor->binInfoKey.len) % |
| 989 | NNOPBASE_NORM_MAX_BIN_BUCKETS; | 984 | NNOPBASE_NORM_MAX_BIN_BUCKETS; |
| 990 | } | 985 | } |
| 991 | 986 | ||
| 992 | -bool NnopbaseExecutorGetDynamicBinInfo(NnopbaseExecutor* executor) | 987 | +bool NnopbaseExecutorGetDynamicBinInfo(NnopbaseExecutor* const executor) |
| 993 | { | 988 | { |
| 994 | NnopbaseExecutorGenDynamicKey(executor); | 989 | NnopbaseExecutorGenDynamicKey(executor); |
| 995 | executor->args->binInfo = NnopbaseCollectorFindBinInfo( | 990 | executor->args->binInfo = NnopbaseCollectorFindBinInfo( |
| @@ -997,10 +992,10 @@ bool NnopbaseExecutorGetDynamicBinInfo(NnopbaseExecutor* executor) | |||
| 997 | return executor->args->binInfo != nullptr; | 992 | return executor->args->binInfo != nullptr; |
| 998 | } | 993 | } |
| 999 | 994 | ||
| 1000 | -NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, NnopbaseTensors* tensors, size_t tensorNum, | 995 | +NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, const NnopbaseTensors* const tensors, |
| 1001 | - bool usingStride) | 996 | + const size_t tensorNum, const bool usingStride) |
| 1002 | { | 997 | { |
| 1003 | - NnopbaseUChar* addr; | 998 | + const NnopbaseUChar* addr; |
| 1004 | size_t length; | 999 | size_t length; |
| 1005 | for (size_t i = 0U; i < tensorNum; i++) { | 1000 | for (size_t i = 0U; i < tensorNum; i++) { |
| 1006 | if (tensors->extTensors[i].isNull) { | 1001 | if (tensors->extTensors[i].isNull) { |
| @@ -1032,7 +1027,7 @@ NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, NnopbaseTens | |||
| 1032 | verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(tensors->extTensors[i].rt2Tensor.GetOffset())); | 1027 | verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(tensors->extTensors[i].rt2Tensor.GetOffset())); |
| 1033 | } | 1028 | } |
| 1034 | if (tensors->extTensors[i].valueDepend) { | 1029 | if (tensors->extTensors[i].valueDepend) { |
| 1035 | - addr = op::internal::PtrCastTo<NnopbaseUChar>(tensors->extTensors[i].rt2Tensor.GetAddr()); | 1030 | + addr = op::internal::PtrCastTo<const NnopbaseUChar>(tensors->extTensors[i].rt2Tensor.GetAddr()); |
| 1036 | const auto dtype = tensors->extTensors[i].rt2Tensor.GetDataType(); | 1031 | const auto dtype = tensors->extTensors[i].rt2Tensor.GetDataType(); |
| 1037 | length = tensors->extTensors[i].rt2Tensor.GetSize(); | 1032 | length = tensors->extTensors[i].rt2Tensor.GetSize(); |
| 1038 | const size_t typeSize = op::TypeSize(dtype); | 1033 | const size_t typeSize = op::TypeSize(dtype); |
| @@ -1045,7 +1040,7 @@ NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, NnopbaseTens | |||
| 1045 | return verKey; | 1040 | return verKey; |
| 1046 | } | 1041 | } |
| 1047 | 1042 | ||
| 1048 | -NnopbaseUChar* NnopbaseExecutorGenAttrsKey(NnopbaseAttrs* attrs, NnopbaseUChar* verKey) | 1043 | +NnopbaseUChar* NnopbaseExecutorGenAttrsKey(const NnopbaseAttrs* const attrs, NnopbaseUChar* verKey) |
| 1049 | { | 1044 | { |
| 1050 | const NnopbaseUChar* addr = nullptr; | 1045 | const NnopbaseUChar* addr = nullptr; |
| 1051 | size_t length = 0; | 1046 | size_t length = 0; |
| @@ -1073,6 +1068,45 @@ NnopbaseUChar* NnopbaseExecutorGenAttrsKey(NnopbaseAttrs* attrs, NnopbaseUChar* | |||
| 1073 | return verKey; | 1068 | return verKey; |
| 1074 | } | 1069 | } |
| 1075 | 1070 | ||
| 1071 | +static size_t NnopbaseComputeStaticTensorsKeySize(const NnopbaseTensors* const tensors, const size_t tensorNum, | ||
| 1072 | + const bool usingStride, const bool withValueDepend) | ||
| 1073 | +{ | ||
| 1074 | + size_t len = 0U; | ||
| 1075 | + for (size_t i = 0U; i < tensorNum; i++) { | ||
| 1076 | + if (tensors->extTensors[i].isNull) { | ||
| 1077 | + len += sizeof(uint64_t); // '_' 占位 | ||
| 1078 | + continue; | ||
| 1079 | + } | ||
| 1080 | + if (tensors->extTensors[i].isRequired || tensors->extTensors[i].isOptional) { | ||
| 1081 | + len += NNOPBASE_DTYPE_AND_FORMAT_SIZE; | ||
| 1082 | + } | ||
| 1083 | + const GertShape& shape = tensors->extTensors[i].rt2Tensor.GetStorageShape(); | ||
| 1084 | + len += shape.GetDimNum() * sizeof(uint64_t); | ||
| 1085 | + if (usingStride) { | ||
| 1086 | + len += tensors->extTensors[i].rt2Tensor.GetStride().GetDimNum() * sizeof(uint64_t) + sizeof(uint64_t); | ||
| 1087 | + } | ||
| 1088 | + if (withValueDepend && tensors->extTensors[i].valueDepend) { | ||
| 1089 | + len += (tensors->extTensors[i].rt2Tensor.GetSize() / | ||
| 1090 | + (op::TypeSize(tensors->extTensors[i].rt2Tensor.GetDataType()))) * | ||
| 1091 | + sizeof(uint64_t); | ||
| 1092 | + } | ||
| 1093 | + } | ||
| 1094 | + return len; | ||
| 1095 | +} | ||
| 1096 | + | ||
| 1097 | +static size_t NnopbaseComputeStaticAttrsKeySize(const NnopbaseAttrs* const attrs) | ||
| 1098 | +{ | ||
| 1099 | + size_t len = 0U; | ||
| 1100 | + for (size_t i = 0U; i < attrs->num; i++) { | ||
| 1101 | + if (!attrs->attrs[i].addr.isVector) { | ||
| 1102 | + NnopbaseExecutorGet8ByteSize(attrs->attrs[i].addr.size, op::internal::PtrCastTo<uint32_t>(&len)); | ||
| 1103 | + } else { | ||
| 1104 | + len += (attrs->attrs[i].addr.size / attrs->attrs[i].addr.elementSize) * sizeof(uint64_t); | ||
| 1105 | + } | ||
| 1106 | + } | ||
| 1107 | + return len; | ||
| 1108 | +} | ||
| 1109 | + | ||
| 1076 | size_t NnopbaseExecutorComputeGenKeySize(const NnopbaseExecutor* const executor, bool usingStride) | 1110 | size_t NnopbaseExecutorComputeGenKeySize(const NnopbaseExecutor* const executor, bool usingStride) |
| 1077 | { | 1111 | { |
| 1078 | const NnopbaseTensors* const inputs = &executor->ownArgs.inputs; | 1112 | const NnopbaseTensors* const inputs = &executor->ownArgs.inputs; |
| @@ -1082,58 +1116,46 @@ size_t NnopbaseExecutorComputeGenKeySize(const NnopbaseExecutor* const executor, | |||
| 1082 | OP_LOGD("Op %s after add [optype, deterministic and precision or performance], length is %zu.", executor->opType, | 1116 | OP_LOGD("Op %s after add [optype, deterministic and precision or performance], length is %zu.", executor->opType, |
| 1083 | len); | 1117 | len); |
| 1084 | const size_t inputTensorNum = static_cast<size_t>(inputs->nonDynamicCnt + inputs->dynamicCnt); | 1118 | const size_t inputTensorNum = static_cast<size_t>(inputs->nonDynamicCnt + inputs->dynamicCnt); |
| 1085 | - for (size_t i = 0U; i < inputTensorNum; i++) { | 1119 | + len += NnopbaseComputeStaticTensorsKeySize(inputs, inputTensorNum, usingStride, true); |
| 1086 | - if (inputs->extTensors[i].isNull) { | ||
| 1087 | - len += sizeof(uint64_t); // '_' 占位 | ||
| 1088 | - continue; | ||
| 1089 | - } | ||
| 1090 | - if (inputs->extTensors[i].isRequired || inputs->extTensors[i].isOptional) { | ||
| 1091 | - len += NNOPBASE_DTYPE_AND_FORMAT_SIZE; | ||
| 1092 | - } | ||
| 1093 | - const GertShape& shape = inputs->extTensors[i].rt2Tensor.GetStorageShape(); | ||
| 1094 | - len += shape.GetDimNum() * sizeof(uint64_t); | ||
| 1095 | - if (usingStride) { | ||
| 1096 | - len += inputs->extTensors[i].rt2Tensor.GetStride().GetDimNum() * sizeof(uint64_t) + sizeof(uint64_t); | ||
| 1097 | - } | ||
| 1098 | - if (inputs->extTensors[i].valueDepend) { | ||
| 1099 | - len += (inputs->extTensors[i].rt2Tensor.GetSize() / | ||
| 1100 | - (op::TypeSize(inputs->extTensors[i].rt2Tensor.GetDataType()))) * | ||
| 1101 | - sizeof(uint64_t); | ||
| 1102 | - } | ||
| 1103 | - } | ||
| 1104 | OP_LOGD("Op %s after add input, length is %zu.", executor->opType, len); | 1120 | OP_LOGD("Op %s after add input, length is %zu.", executor->opType, len); |
| 1105 | const size_t outputTensorNum = outputs->nonDynamicCnt + outputs->dynamicCnt; | 1121 | const size_t outputTensorNum = outputs->nonDynamicCnt + outputs->dynamicCnt; |
| 1106 | - for (size_t i = 0U; i < outputTensorNum; i++) { | 1122 | + len += NnopbaseComputeStaticTensorsKeySize(outputs, outputTensorNum, usingStride, false); |
| 1107 | - if (outputs->extTensors[i].isNull) { | ||
| 1108 | - len += sizeof(uint64_t); | ||
| 1109 | - continue; | ||
| 1110 | - } | ||
| 1111 | - if (outputs->extTensors[i].isRequired || outputs->extTensors[i].isOptional) { | ||
| 1112 | - len += sizeof(uint64_t) * 2U; // 2 = dtype&format | ||
| 1113 | - } | ||
| 1114 | - const GertShape& shape = outputs->extTensors[i].rt2Tensor.GetStorageShape(); | ||
| 1115 | - len += shape.GetDimNum() * sizeof(uint64_t); | ||
| 1116 | - if (usingStride) { | ||
| 1117 | - len += outputs->extTensors[i].rt2Tensor.GetStride().GetDimNum() * sizeof(uint64_t) + sizeof(uint64_t); | ||
| 1118 | - } | ||
| 1119 | - } | ||
| 1120 | OP_LOGD("Op %s after add output, length is %zu.", executor->opType, len); | 1123 | OP_LOGD("Op %s after add output, length is %zu.", executor->opType, len); |
| 1121 | - for (size_t i = 0U; i < attrs->num; i++) { | 1124 | + len += NnopbaseComputeStaticAttrsKeySize(attrs); |
| 1122 | - if (!attrs->attrs[i].addr.isVector) { | ||
| 1123 | - NnopbaseExecutorGet8ByteSize(attrs->attrs[i].addr.size, op::internal::PtrCastTo<uint32_t>(&len)); | ||
| 1124 | - } else { | ||
| 1125 | - len += (attrs->attrs[i].addr.size / attrs->attrs[i].addr.elementSize) * sizeof(uint64_t); | ||
| 1126 | - } | ||
| 1127 | - } | ||
| 1128 | OP_LOGD("Op %s after add attr, length is %zu.", executor->opType, len); | 1125 | OP_LOGD("Op %s after add attr, length is %zu.", executor->opType, len); |
| 1129 | return len; | 1126 | return len; |
| 1130 | } | 1127 | } |
| 1131 | 1128 | ||
| 1132 | -aclnnStatus NnopbaseExecutorGenStaticKey(NnopbaseExecutor* executor, bool usingStride) | 1129 | +static NnopbaseUChar* NnopbaseInitStaticKeyBuffer(NnopbaseExecutor* const executor, const size_t len) |
| 1133 | { | 1130 | { |
| 1134 | - NnopbaseTensors* inputs = &executor->ownArgs.inputs; | 1131 | + NnopbaseUChar* verKey = nullptr; |
| 1135 | - NnopbaseAttrs* attrs = &executor->attrs; | 1132 | + if (len > executor->binInfoKey.bufLen) { |
| 1136 | - NnopbaseTensors* outputs = &executor->ownArgs.outputs; | 1133 | + executor->binInfoKey.verbose = std::vector<NnopbaseUChar>(len + NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN, '\0'); |
| 1134 | + verKey = &(executor->binInfoKey.verbose[0U]); | ||
| 1135 | + executor->binInfoKey.bufLen = static_cast<uint32_t>(len) + NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN; | ||
| 1136 | + verKey = NnopbaseAppendBinary(verKey, static_cast<size_t>(executor->binInfoKey.bufLen), | ||
| 1137 | + &(executor->regInfo->key.opType[0U]), executor->regInfo->key.opType.size()); | ||
| 1138 | + } else { | ||
| 1139 | + verKey = &(executor->binInfoKey.verbose[0U]) + executor->regInfo->key.opType.size(); | ||
| 1140 | + } | ||
| 1141 | + return verKey; | ||
| 1142 | +} | ||
| 1143 | + | ||
| 1144 | +static NnopbaseUChar* NnopbaseAppendStaticKeyHead(const NnopbaseExecutor* const executor, NnopbaseUChar* verKey) | ||
| 1145 | +{ | ||
| 1146 | + uint64_t deterministicLevel = (executor->deterministicLevel == 0U) ? 0U : 1U; | ||
| 1147 | + verKey = NnopbaseAppend8Byte(verKey, deterministicLevel); | ||
| 1148 | + verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(g_nnopbaseSysCfgParams.precision)); | ||
| 1149 | + OP_LOGI("Op %s HighPrecision is %d, Deterministic is %d, binInfoKey length is %u.", executor->opType, | ||
| 1150 | + g_nnopbaseSysCfgParams.precision, deterministicLevel, executor->binInfoKey.bufLen); | ||
| 1151 | + return verKey; | ||
| 1152 | +} | ||
| 1153 | + | ||
| 1154 | +aclnnStatus NnopbaseExecutorGenStaticKey(NnopbaseExecutor* const executor, const bool usingStride) | ||
| 1155 | +{ | ||
| 1156 | + const NnopbaseTensors* const inputs = &executor->ownArgs.inputs; | ||
| 1157 | + const NnopbaseAttrs* const attrs = &executor->attrs; | ||
| 1158 | + const NnopbaseTensors* const outputs = &executor->ownArgs.outputs; | ||
| 1137 | /* | 1159 | /* |
| 1138 | when usingStride = false: | 1160 | when usingStride = false: |
| 1139 | verb key format = op_type/Deterministic/Precision/{dtype, format, (shape)}/.../attr binary | 1161 | verb key format = op_type/Deterministic/Precision/{dtype, format, (shape)}/.../attr binary |
| @@ -1147,21 +1169,8 @@ aclnnStatus NnopbaseExecutorGenStaticKey(NnopbaseExecutor* executor, bool usingS | |||
| 1147 | return ACLNN_ERR_PARAM_INVALID; | 1169 | return ACLNN_ERR_PARAM_INVALID; |
| 1148 | } | 1170 | } |
| 1149 | 1171 | ||
| 1150 | - NnopbaseUChar* verKey = nullptr; | 1172 | + NnopbaseUChar* verKey = NnopbaseInitStaticKeyBuffer(executor, len); |
| 1151 | - if (len > executor->binInfoKey.bufLen) { | 1173 | + verKey = NnopbaseAppendStaticKeyHead(executor, verKey); |
| 1152 | - executor->binInfoKey.verbose = std::vector<NnopbaseUChar>(len + NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN, '\0'); | ||
| 1153 | - verKey = &(executor->binInfoKey.verbose[0U]); | ||
| 1154 | - executor->binInfoKey.bufLen = static_cast<uint32_t>(len) + NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN; | ||
| 1155 | - verKey = NnopbaseAppendBinary(verKey, static_cast<size_t>(executor->binInfoKey.bufLen), | ||
| 1156 | - &(executor->regInfo->key.opType[0U]), executor->regInfo->key.opType.size()); | ||
| 1157 | - } else { | ||
| 1158 | - verKey = &(executor->binInfoKey.verbose[0U]) + executor->regInfo->key.opType.size(); | ||
| 1159 | - } | ||
| 1160 | - verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(executor->deterministic)); | ||
| 1161 | - verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(g_nnopbaseSysCfgParams.precision)); | ||
| 1162 | - OP_LOGI("Op %s HighPrecision value is %d, Deterministic value is %d, binInfoKey length is %u.", executor->opType, | ||
| 1163 | - g_nnopbaseSysCfgParams.precision, executor->deterministic, executor->binInfoKey.bufLen); | ||
| 1164 | - | ||
| 1165 | const size_t inputTensorNum = inputs->nonDynamicCnt + inputs->dynamicCnt; | 1174 | const size_t inputTensorNum = inputs->nonDynamicCnt + inputs->dynamicCnt; |
| 1166 | verKey = NnopbaseExecutorGenTensorsKey(verKey, inputs, inputTensorNum, usingStride); | 1175 | verKey = NnopbaseExecutorGenTensorsKey(verKey, inputs, inputTensorNum, usingStride); |
| 1167 | const size_t outputTensorNum = static_cast<size_t>(outputs->nonDynamicCnt + outputs->dynamicCnt); | 1176 | const size_t outputTensorNum = static_cast<size_t>(outputs->nonDynamicCnt + outputs->dynamicCnt); |
| @@ -46,12 +46,23 @@ inline bool EnableNnopbaseArgsCache() | |||
| 46 | return disAbleArgsCache == nullptr ? true : strcmp(disAbleArgsCache, "1") != 0; // 1表示开启 | 46 | return disAbleArgsCache == nullptr ? true : strcmp(disAbleArgsCache, "1") != 0; // 1表示开启 |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | -inline bool GetGlobalDeterministic() | 49 | +inline int64_t GetGlobalDeterministic() |
| 50 | { | 50 | { |
| 51 | - int64_t value = 0; // 0表示非确定性 | 51 | + int64_t deterministicLevel = 0; // 0表示非确定性 |
| 52 | - const aclError ret = aclrtCtxGetSysParamOpt(ACL_OPT_DETERMINISTIC, &value); // SYS_OPT_DETERMINISTIC | 52 | + const aclError ret = aclrtGetSysParamOpt(ACL_OPT_DETERMINISTIC, &deterministicLevel); // SYS_OPT_DETERMINISTIC |
| 53 | - OP_LOGD("Get system param deterministic ret = %d.", ret); | 53 | + OP_CHECK_NO_RETURN(ret == ACL_SUCCESS, deterministicLevel = 0; |
| 54 | - return (value == 1); // 1表示确定性 | 54 | + OP_LOGW("Failed to get deterministic from system, ret= %d.", ret)); |
| 55 | + if (deterministicLevel == 1) { | ||
| 56 | + int64_t consistency = 0; | ||
| 57 | + aclError consistencyRet = aclrtGetSysParamOpt(ACL_OPT_STRONG_CONSISTENCY, &consistency); | ||
| 58 | + OP_CHECK_NO_RETURN(consistencyRet == ACL_SUCCESS, consistency = 0; | ||
| 59 | + OP_LOGW("Failed to get consistency from system, ret= %d.", consistencyRet)); | ||
| 60 | + if (consistency == 1) { | ||
| 61 | + deterministicLevel = 2; // 2表示强一致性 | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + OP_LOGI("determinisic level of system is %lld", deterministicLevel); | ||
| 65 | + return deterministicLevel; | ||
| 55 | } | 66 | } |
| 56 | 67 | ||
| 57 | inline void NnopbaseGetCoreNum(uint32_t* const aicNum, uint32_t* const aivNum) | 68 | inline void NnopbaseGetCoreNum(uint32_t* const aicNum, uint32_t* const aivNum) |
| @@ -96,7 +107,7 @@ inline bool GetDebugKernel() | |||
| 96 | int64_t value = 0; // 0表示不开启debug kernel | 107 | int64_t value = 0; // 0表示不开启debug kernel |
| 97 | const aclError ret = aclrtCtxGetSysParamOpt(ACL_OPT_ENABLE_DEBUG_KERNEL, &value); // SYS_OPT_ENABLE_DEBUG_KERNEL = 1 | 108 | const aclError ret = aclrtCtxGetSysParamOpt(ACL_OPT_ENABLE_DEBUG_KERNEL, &value); // SYS_OPT_ENABLE_DEBUG_KERNEL = 1 |
| 98 | OP_LOGD("Get system param debug kernel ret = %d.", ret); | 109 | OP_LOGD("Get system param debug kernel ret = %d.", ret); |
| 99 | - return (value == 1); // 1表示开启debug kernel | 110 | + return (value == 1); // 1表示开启debug kernel |
| 100 | } | 111 | } |
| 101 | 112 | ||
| 102 | static inline void NnopbaseSetDtypeAndSize(const aclIntArray* array, GertTensor* rt2Tensor) | 113 | static inline void NnopbaseSetDtypeAndSize(const aclIntArray* array, GertTensor* rt2Tensor) |
| @@ -271,4 +282,4 @@ static inline uint32_t NnopbaseExecutorGetTaskType(const CoreType coreType, Nnop | |||
| 271 | } | 282 | } |
| 272 | #endif | 283 | #endif |
| 273 | 284 | ||
| 274 | -#endif | 285 | +#endif |
| @@ -28,8 +28,8 @@ namespace { | |||
| 28 | aclnnStatus DoHcclAllocComResourceByTiling(NnopbaseExecutor* executor, HcclComm comm, void* stream, void* tilingData, | 28 | aclnnStatus DoHcclAllocComResourceByTiling(NnopbaseExecutor* executor, HcclComm comm, void* stream, void* tilingData, |
| 29 | void** commCtx) | 29 | void** commCtx) |
| 30 | { | 30 | { |
| 31 | - const bool supportA5AiCpu = nnopbase::IndvSoc::GetInstance().NnopbaseSupportA5AiCpu(executor->mc2OpCfg.sType); | 31 | + const bool supportA5AiCpu = nnopbase::IndvSoc::GetInstance().NnopbaseSupportA5AiCpu(executor->mc2.serverType); |
| 32 | - OP_LOGI("Nnopbase MC2 alloc resource route, sType[%d], supportA5AiCpu[%d].", executor->mc2OpCfg.sType, | 32 | + OP_LOGI("Nnopbase MC2 alloc resource route, sType[%d], supportA5AiCpu[%d].", executor->mc2.serverType, |
| 33 | supportA5AiCpu); | 33 | supportA5AiCpu); |
| 34 | if (supportA5AiCpu) { | 34 | if (supportA5AiCpu) { |
| 35 | return nnopbase::IndvMc2ClientWrapper::GetInstance().HcclAllocComResourceByTiling(comm, stream, tilingData, | 35 | return nnopbase::IndvMc2ClientWrapper::GetInstance().HcclAllocComResourceByTiling(comm, stream, tilingData, |
| @@ -42,17 +42,17 @@ aclnnStatus DoHcclAllocComResourceByTiling(NnopbaseExecutor* executor, HcclComm | |||
| 42 | 42 | ||
| 43 | aclnnStatus NnopbaseGetHcomResource(NnopbaseExecutor* executor, aclrtStream const stream) | 43 | aclnnStatus NnopbaseGetHcomResource(NnopbaseExecutor* executor, aclrtStream const stream) |
| 44 | { | 44 | { |
| 45 | - executor->contextAddr.clear(); | 45 | + executor->mc2.contextAddrs.clear(); |
| 46 | - executor->aicpuStream.clear(); | 46 | + executor->mc2.aicpuStreams.clear(); |
| 47 | - executor->aicpuThread.clear(); | 47 | + executor->mc2.aicpuThreads.clear(); |
| 48 | - executor->aicpuNotify.clear(); | 48 | + executor->mc2.aicpuNotifies.clear(); |
| 49 | - for (HcclComm commHandle : executor->mc2OpCfg.hcomHandle) { | 49 | + for (HcclComm commHandle : executor->mc2.commHandles) { |
| 50 | void* contextAddr = nullptr; | 50 | void* contextAddr = nullptr; |
| 51 | if (commHandle == nullptr) { | 51 | if (commHandle == nullptr) { |
| 52 | - executor->contextAddr.push_back(contextAddr); | 52 | + executor->mc2.contextAddrs.push_back(contextAddr); |
| 53 | - executor->aicpuStream.push_back(nullptr); | 53 | + executor->mc2.aicpuStreams.push_back(nullptr); |
| 54 | - executor->aicpuThread.push_back(0U); | 54 | + executor->mc2.aicpuThreads.push_back(0U); |
| 55 | - executor->aicpuNotify.push_back(std::make_pair(nullptr, nullptr)); | 55 | + executor->mc2.aicpuNotifies.push_back(std::make_pair(nullptr, nullptr)); |
| 56 | continue; | 56 | continue; |
| 57 | } | 57 | } |
| 58 | if (!executor->hasTiling) { | 58 | if (!executor->hasTiling) { |
| @@ -65,23 +65,23 @@ aclnnStatus NnopbaseGetHcomResource(NnopbaseExecutor* executor, aclrtStream cons | |||
| 65 | (op::internal::PtrCastTo<NnopbaseTilingData>(executor->args->tilingInfo.tilingData))->GetData(), | 65 | (op::internal::PtrCastTo<NnopbaseTilingData>(executor->args->tilingInfo.tilingData))->GetData(), |
| 66 | &contextAddr)); | 66 | &contextAddr)); |
| 67 | } | 67 | } |
| 68 | - executor->contextAddr.push_back(contextAddr); | 68 | + executor->mc2.contextAddrs.push_back(contextAddr); |
| 69 | aclrtStream aicpuStream = nullptr; | 69 | aclrtStream aicpuStream = nullptr; |
| 70 | aclrtStream notify[NNOPBASE_MC2_NOTIFY_COUNT] = {}; | 70 | aclrtStream notify[NNOPBASE_MC2_NOTIFY_COUNT] = {}; |
| 71 | - if (!nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType)) { | 71 | + if (!nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { |
| 72 | if (nnopbase::IndvSoc::GetInstance().SupportMc2FusionLaunch()) { | 72 | if (nnopbase::IndvSoc::GetInstance().SupportMc2FusionLaunch()) { |
| 73 | uint64_t threadHandle = 0U; | 73 | uint64_t threadHandle = 0U; |
| 74 | NNOPBASE_ASSERT_OK_RETVAL( | 74 | NNOPBASE_ASSERT_OK_RETVAL( |
| 75 | nnopbase::IndvHcclWrapper::GetInstance().HcclGetUnfoldThread(commHandle, &threadHandle)); | 75 | nnopbase::IndvHcclWrapper::GetInstance().HcclGetUnfoldThread(commHandle, &threadHandle)); |
| 76 | - executor->aicpuThread.push_back(threadHandle); | 76 | + executor->mc2.aicpuThreads.push_back(threadHandle); |
| 77 | NNOPBASE_ASSERT_OK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcclStreamAcquireWithThread( | 77 | NNOPBASE_ASSERT_OK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcclStreamAcquireWithThread( |
| 78 | commHandle, threadHandle, &aicpuStream)); | 78 | commHandle, threadHandle, &aicpuStream)); |
| 79 | } else { | 79 | } else { |
| 80 | NNOPBASE_ASSERT_OK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcclGetAicpuOpStreamAndNotify( | 80 | NNOPBASE_ASSERT_OK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcclGetAicpuOpStreamAndNotify( |
| 81 | commHandle, &aicpuStream, NNOPBASE_MC2_NOTIFY_COUNT, notify)); | 81 | commHandle, &aicpuStream, NNOPBASE_MC2_NOTIFY_COUNT, notify)); |
| 82 | - executor->aicpuNotify.push_back(std::make_pair(notify[0], notify[1])); | 82 | + executor->mc2.aicpuNotifies.push_back(std::make_pair(notify[0], notify[1])); |
| 83 | } | 83 | } |
| 84 | - executor->aicpuStream.push_back(aicpuStream); | 84 | + executor->mc2.aicpuStreams.push_back(aicpuStream); |
| 85 | } | 85 | } |
| 86 | OP_LOGI( | 86 | OP_LOGI( |
| 87 | "Executor is %p, stream is %p, commHandle is %p, get contextAddr is %p, get aicpuStream is %p, notify[0] " | 87 | "Executor is %p, stream is %p, commHandle is %p, get contextAddr is %p, get aicpuStream is %p, notify[0] " |
| @@ -91,36 +91,36 @@ aclnnStatus NnopbaseGetHcomResource(NnopbaseExecutor* executor, aclrtStream cons | |||
| 91 | return OK; | 91 | return OK; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | -aclnnStatus NnopbaseExecutorGetMc2Num(NnopbaseExecutor* executor, aclrtStream const stream, | 94 | +aclnnStatus NnopbaseExecutorGetMc2Num(NnopbaseExecutor* const executor, aclrtStream const stream, |
| 95 | NnopbaseExecutorArgsAddr* argsAddr, uint32_t* mc2Num) | 95 | NnopbaseExecutorArgsAddr* argsAddr, uint32_t* mc2Num) |
| 96 | { | 96 | { |
| 97 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseGetHcomResource(executor, stream)); | 97 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseGetHcomResource(executor, stream)); |
| 98 | argsAddr->hcclDesc->version = 1U; | 98 | argsAddr->hcclDesc->version = 1U; |
| 99 | - argsAddr->hcclDesc->groupNum = static_cast<uint64_t>(executor->contextAddr.size()); | 99 | + argsAddr->hcclDesc->groupNum = static_cast<uint64_t>(executor->mc2.contextAddrs.size()); |
| 100 | - if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType)) { | 100 | + if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { |
| 101 | *mc2Num = argsAddr->hcclDesc->groupNum; | 101 | *mc2Num = argsAddr->hcclDesc->groupNum; |
| 102 | - executor->fusionArgs.isNoNeedH2DCopy = 0U; | 102 | + executor->mc2.fusionArgs.isNoNeedH2DCopy = 0U; |
| 103 | - executor->fusionArgs.hostInputInfoPtr = nullptr; | 103 | + executor->mc2.fusionArgs.hostInputInfoPtr = nullptr; |
| 104 | - executor->fusionArgs.hostInputInfoNum = 0U; | 104 | + executor->mc2.fusionArgs.hostInputInfoNum = 0U; |
| 105 | - executor->fusionArgs.aicpuNum = 0U; | 105 | + executor->mc2.fusionArgs.aicpuNum = 0U; |
| 106 | } else { | 106 | } else { |
| 107 | *mc2Num = argsAddr->hcclDesc->groupNum + 1U; // 1 is NnopbaseHcclCommParamDesc | 107 | *mc2Num = argsAddr->hcclDesc->groupNum + 1U; // 1 is NnopbaseHcclCommParamDesc |
| 108 | - executor->aicpuArgs.kernelOffsetInfoPtr = nullptr; | 108 | + executor->mc2.aicpuArgs.kernelOffsetInfoPtr = nullptr; |
| 109 | - executor->aicpuArgs.kernelOffsetInfoNum = 0; | 109 | + executor->mc2.aicpuArgs.kernelOffsetInfoNum = 0; |
| 110 | - executor->aicpuArgs.isNoNeedH2DCopy = false; | 110 | + executor->mc2.aicpuArgs.isNoNeedH2DCopy = false; |
| 111 | - executor->aicpuArgs.hostInputInfoPtr = nullptr; | 111 | + executor->mc2.aicpuArgs.hostInputInfoPtr = nullptr; |
| 112 | - executor->aicpuArgs.hostInputInfoNum = 0U; | 112 | + executor->mc2.aicpuArgs.hostInputInfoNum = 0U; |
| 113 | } | 113 | } |
| 114 | return OK; | 114 | return OK; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | -aclnnStatus NnopbaseAddCapture(aclrtStream stream, std::vector<aclrtStream> aicpuStream) | 117 | +aclnnStatus NnopbaseAddCapture(aclrtStream stream, std::vector<aclrtStream> aicpuStreams) |
| 118 | { | 118 | { |
| 119 | aclmdlRICaptureStatus status; | 119 | aclmdlRICaptureStatus status; |
| 120 | aclmdlRI captureMdl; | 120 | aclmdlRI captureMdl; |
| 121 | if ((aclmdlRICaptureGetInfo(stream, &status, &captureMdl) == ACL_SUCCESS) && | 121 | if ((aclmdlRICaptureGetInfo(stream, &status, &captureMdl) == ACL_SUCCESS) && |
| 122 | (status == ACL_MODEL_RI_CAPTURE_STATUS_ACTIVE)) { | 122 | (status == ACL_MODEL_RI_CAPTURE_STATUS_ACTIVE)) { |
| 123 | - for (auto& stm : aicpuStream) { | 123 | + for (auto& stm : aicpuStreams) { |
| 124 | if (stm != nullptr) { | 124 | if (stm != nullptr) { |
| 125 | NNOPBASE_ASSERT_RTOK_RETVAL(rtStreamAddToModel(stm, captureMdl)); | 125 | NNOPBASE_ASSERT_RTOK_RETVAL(rtStreamAddToModel(stm, captureMdl)); |
| 126 | } | 126 | } |
| @@ -132,34 +132,36 @@ aclnnStatus NnopbaseAddCapture(aclrtStream stream, std::vector<aclrtStream> aicp | |||
| 132 | aclnnStatus NnopbaseLaunchKFCTask(NnopbaseExecutor* const executor, aclrtStream stream) | 132 | aclnnStatus NnopbaseLaunchKFCTask(NnopbaseExecutor* const executor, aclrtStream stream) |
| 133 | { | 133 | { |
| 134 | OP_LOGI("Launch kernel by KFC mode."); | 134 | OP_LOGI("Launch kernel by KFC mode."); |
| 135 | - NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddCapture(stream, executor->aicpuStream)); | 135 | + NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddCapture(stream, executor->mc2.aicpuStreams)); |
| 136 | - if (executor->aicpuStream[0] != nullptr) { | 136 | + if (executor->mc2.aicpuStreams[0] != nullptr) { |
| 137 | CHECK_COND( | 137 | CHECK_COND( |
| 138 | - aclrtWaitAndResetNotify(executor->aicpuNotify[0].first, executor->aicpuStream[0], UINT32_MAX) == | 138 | + aclrtWaitAndResetNotify(executor->mc2.aicpuNotifies[0].first, executor->mc2.aicpuStreams[0], UINT32_MAX) == |
| 139 | ACL_SUCCESS, | 139 | ACL_SUCCESS, |
| 140 | ACLNN_ERR_RUNTIME_ERROR, | 140 | ACLNN_ERR_RUNTIME_ERROR, |
| 141 | "Failed to call aclrtWaitAndResetNotify, executor is %p, aicpuStream is %p, stream is %p, Notify is %p.", | 141 | "Failed to call aclrtWaitAndResetNotify, executor is %p, aicpuStream is %p, stream is %p, Notify is %p.", |
| 142 | - executor, executor->aicpuStream[0], stream, executor->aicpuNotify[0].first); | 142 | + executor, executor->mc2.aicpuStreams[0], stream, executor->mc2.aicpuNotifies[0].first); |
| 143 | - NNOPBASE_ASSERT_RTOK_RETVAL(aclrtRecordNotify(executor->aicpuNotify[0].first, stream)); | 143 | + NNOPBASE_ASSERT_RTOK_RETVAL(aclrtRecordNotify(executor->mc2.aicpuNotifies[0].first, stream)); |
| 144 | } | 144 | } |
| 145 | - for (size_t i = 1U; i < executor->aicpuStream.size(); i++) { | 145 | + for (size_t i = 1U; i < executor->mc2.aicpuStreams.size(); i++) { |
| 146 | - if ((executor->aicpuStream[0] != nullptr) && (executor->aicpuNotify[i].first != nullptr)) { | 146 | + if ((executor->mc2.aicpuStreams[0] != nullptr) && (executor->mc2.aicpuNotifies[i].first != nullptr)) { |
| 147 | - NNOPBASE_ASSERT_RTOK_RETVAL( | 147 | + NNOPBASE_ASSERT_RTOK_RETVAL(aclrtWaitAndResetNotify(executor->mc2.aicpuNotifies[i].first, |
| 148 | - aclrtWaitAndResetNotify(executor->aicpuNotify[i].first, executor->aicpuStream[0], UINT32_MAX)); | 148 | + executor->mc2.aicpuStreams[0], UINT32_MAX)); |
| 149 | } | 149 | } |
| 150 | // aicpuStream和aicpuNotify是hccl同时创建的,aicpuStream不是null,aicpuNotify也不应该是null | 150 | // aicpuStream和aicpuNotify是hccl同时创建的,aicpuStream不是null,aicpuNotify也不应该是null |
| 151 | - if (executor->aicpuStream[i] != nullptr) { | 151 | + if (executor->mc2.aicpuStreams[i] != nullptr) { |
| 152 | - NNOPBASE_ASSERT_RTOK_RETVAL(aclrtRecordNotify(executor->aicpuNotify[i].first, executor->aicpuStream[i])); | 152 | + NNOPBASE_ASSERT_RTOK_RETVAL( |
| 153 | + aclrtRecordNotify(executor->mc2.aicpuNotifies[i].first, executor->mc2.aicpuStreams[i])); | ||
| 153 | } | 154 | } |
| 154 | } | 155 | } |
| 155 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAicpuKernelLaunch(executor)); | 156 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAicpuKernelLaunch(executor)); |
| 156 | - for (size_t i = 1U; i < executor->aicpuStream.size(); i++) { | 157 | + for (size_t i = 1U; i < executor->mc2.aicpuStreams.size(); i++) { |
| 157 | - if (executor->aicpuStream[i] != nullptr) { | 158 | + if (executor->mc2.aicpuStreams[i] != nullptr) { |
| 158 | - NNOPBASE_ASSERT_RTOK_RETVAL( | 159 | + NNOPBASE_ASSERT_RTOK_RETVAL(aclrtWaitAndResetNotify(executor->mc2.aicpuNotifies[i].second, |
| 159 | - aclrtWaitAndResetNotify(executor->aicpuNotify[i].second, executor->aicpuStream[i], UINT32_MAX)); | 160 | + executor->mc2.aicpuStreams[i], UINT32_MAX)); |
| 160 | } | 161 | } |
| 161 | - if ((executor->aicpuStream[0] != nullptr) && (executor->aicpuNotify[i].second != nullptr)) { | 162 | + if ((executor->mc2.aicpuStreams[0] != nullptr) && (executor->mc2.aicpuNotifies[i].second != nullptr)) { |
| 162 | - NNOPBASE_ASSERT_RTOK_RETVAL(aclrtRecordNotify(executor->aicpuNotify[i].second, executor->aicpuStream[0])); | 163 | + NNOPBASE_ASSERT_RTOK_RETVAL( |
| 164 | + aclrtRecordNotify(executor->mc2.aicpuNotifies[i].second, executor->mc2.aicpuStreams[0])); | ||
| 163 | } | 165 | } |
| 164 | } | 166 | } |
| 165 | OP_LOGI("Launch kernel by KFC mode successfully."); | 167 | OP_LOGI("Launch kernel by KFC mode successfully."); |
| @@ -170,10 +172,10 @@ aclnnStatus NnopbaseLaunchKFCTaskA5(NnopbaseExecutor* const executor, aclrtStrea | |||
| 170 | { | 172 | { |
| 171 | OP_LOGI("Launch kernel by A5 KFC mode."); | 173 | OP_LOGI("Launch kernel by A5 KFC mode."); |
| 172 | 174 | ||
| 173 | - NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddCapture(stream, executor->aicpuStream)); | 175 | + NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddCapture(stream, executor->mc2.aicpuStreams)); |
| 174 | - if (executor->aicpuStream[0] != nullptr) { | 176 | + if (executor->mc2.aicpuStreams[0] != nullptr) { |
| 175 | - const uint64_t unfoldThread = executor->aicpuThread[0]; | 177 | + const uint64_t unfoldThread = executor->mc2.aicpuThreads[0]; |
| 176 | - HcclComm comm = executor->mc2OpCfg.hcomHandle[0]; | 178 | + HcclComm comm = executor->mc2.commHandles[0]; |
| 177 | auto& wrapper = nnopbase::IndvHcclWrapper::GetInstance(); | 179 | auto& wrapper = nnopbase::IndvHcclWrapper::GetInstance(); |
| 178 | 180 | ||
| 179 | // unfold线程在获取展开流时已保存,主流线程由stream现取 | 181 | // unfold线程在获取展开流时已保存,主流线程由stream现取 |
| @@ -192,9 +194,9 @@ aclnnStatus NnopbaseLaunchKFCTaskA5(NnopbaseExecutor* const executor, aclrtStrea | |||
| 192 | 194 | ||
| 193 | void NnopbaseCopyDavidMC2ParamDesc(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr) | 195 | void NnopbaseCopyDavidMC2ParamDesc(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr) |
| 194 | { | 196 | { |
| 195 | - const NnopbaseUChar* const args = op::internal::PtrCastTo<NnopbaseUChar>(executor->fusionArgs.args); | 197 | + const NnopbaseUChar* const args = op::internal::PtrCastTo<NnopbaseUChar>(executor->mc2.fusionArgs.args); |
| 196 | const uint16_t kfcArgsFmtOffset = static_cast<uint16_t>(argsAddr->hostInputData - args); | 198 | const uint16_t kfcArgsFmtOffset = static_cast<uint16_t>(argsAddr->hostInputData - args); |
| 197 | - executor->fusionArgs.aicpuArgs[0].kfcArgsFmtOffset = kfcArgsFmtOffset / sizeof(void*); | 199 | + executor->mc2.fusionArgs.aicpuArgs[0].kfcArgsFmtOffset = kfcArgsFmtOffset / sizeof(void*); |
| 198 | OP_LOGI("KfcArgsFmtOffset is %u.", kfcArgsFmtOffset); | 200 | OP_LOGI("KfcArgsFmtOffset is %u.", kfcArgsFmtOffset); |
| 199 | for (size_t i = 0U; i < sizeof(NnopbaseHcclCommParamDesc); i++) { | 201 | for (size_t i = 0U; i < sizeof(NnopbaseHcclCommParamDesc); i++) { |
| 200 | argsAddr->hostInputData = NnopbaseAppend1Byte(argsAddr->hostInputData, | 202 | argsAddr->hostInputData = NnopbaseAppend1Byte(argsAddr->hostInputData, |
| @@ -203,13 +205,13 @@ void NnopbaseCopyDavidMC2ParamDesc(NnopbaseExecutor* executor, NnopbaseExecutorA | |||
| 203 | OP_LOGI("GroupNum is %u, hasffts is %u, tilingOff is %u, isDyn is %lu.", argsAddr->hcclDesc->groupNum, | 205 | OP_LOGI("GroupNum is %u, hasffts is %u, tilingOff is %u, isDyn is %lu.", argsAddr->hcclDesc->groupNum, |
| 204 | argsAddr->hcclDesc->hasFfts, argsAddr->hcclDesc->tilingOff, argsAddr->hcclDesc->isDyn); | 206 | argsAddr->hcclDesc->hasFfts, argsAddr->hcclDesc->tilingOff, argsAddr->hcclDesc->isDyn); |
| 205 | // 3 is soname/kernelname/opname | 207 | // 3 is soname/kernelname/opname |
| 206 | - executor->fusionArgs.argsSize = kfcArgsFmtOffset + sizeof(NnopbaseHcclCommParamDesc) + NNOPBASE_PARAM_EXT_LEN + | 208 | + executor->mc2.fusionArgs.argsSize = kfcArgsFmtOffset + sizeof(NnopbaseHcclCommParamDesc) + NNOPBASE_PARAM_EXT_LEN + |
| 207 | - static_cast<uint32_t>(sizeof(rtHostInputInfo_t)); | 209 | + static_cast<uint32_t>(sizeof(rtHostInputInfo_t)); |
| 208 | } | 210 | } |
| 209 | 211 | ||
| 210 | void NnopbaseCopyMC2ParamDesc(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr) | 212 | void NnopbaseCopyMC2ParamDesc(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr) |
| 211 | { | 213 | { |
| 212 | - NnopbaseUChar* descAddr = op::internal::PtrCastTo<NnopbaseUChar>(executor->aicpuArgs.args); | 214 | + NnopbaseUChar* descAddr = op::internal::PtrCastTo<NnopbaseUChar>(executor->mc2.aicpuArgs.args); |
| 213 | for (size_t i = 0U; i < sizeof(NnopbaseHcclCommParamDesc); i++) { | 215 | for (size_t i = 0U; i < sizeof(NnopbaseHcclCommParamDesc); i++) { |
| 214 | descAddr = NnopbaseAppend1Byte(descAddr, (op::internal::PtrCastTo<NnopbaseUChar>(argsAddr->hcclDesc))[i]); | 216 | descAddr = NnopbaseAppend1Byte(descAddr, (op::internal::PtrCastTo<NnopbaseUChar>(argsAddr->hcclDesc))[i]); |
| 215 | } | 217 | } |
| @@ -218,22 +220,22 @@ void NnopbaseCopyMC2ParamDesc(NnopbaseExecutor* executor, NnopbaseExecutorArgsAd | |||
| 218 | argsAddr->hcclDesc->hasFfts, argsAddr->hcclDesc->tilingOff, argsAddr->hcclDesc->isDyn); | 220 | argsAddr->hcclDesc->hasFfts, argsAddr->hcclDesc->tilingOff, argsAddr->hcclDesc->isDyn); |
| 219 | 221 | ||
| 220 | // 3 is soname/kernelname/opname | 222 | // 3 is soname/kernelname/opname |
| 221 | - executor->aicpuArgs.argsSize = executor->argsExt.argsSize + sizeof(NnopbaseHcclCommParamDesc) + | 223 | + executor->mc2.aicpuArgs.argsSize = executor->argsExt.argsSize + sizeof(NnopbaseHcclCommParamDesc) + |
| 222 | - NNOPBASE_AICPU_PARAM_LEN * 3U; | 224 | + NNOPBASE_AICPU_PARAM_LEN * 3U; |
| 223 | } | 225 | } |
| 224 | 226 | ||
| 225 | void NnopbasePrepareMC2Params(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr) | 227 | void NnopbasePrepareMC2Params(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr) |
| 226 | { | 228 | { |
| 227 | NnopbaseUChar* args = nullptr; | 229 | NnopbaseUChar* args = nullptr; |
| 228 | - if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType)) { | 230 | + if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { |
| 229 | - args = (NnopbaseUChar*)executor->fusionArgs.args; | 231 | + args = (NnopbaseUChar*)executor->mc2.fusionArgs.args; |
| 230 | - executor->fusionArgs.aicpuArgs[0].soNameAddrOffset = static_cast<uint16_t>(argsAddr->hostInputData - args); | 232 | + executor->mc2.fusionArgs.aicpuArgs[0].soNameAddrOffset = static_cast<uint16_t>(argsAddr->hostInputData - args); |
| 231 | } else { | 233 | } else { |
| 232 | - args = (NnopbaseUChar*)executor->aicpuArgs.args; | 234 | + args = (NnopbaseUChar*)executor->mc2.aicpuArgs.args; |
| 233 | - executor->aicpuArgs.soNameAddrOffset = static_cast<uint32_t>(argsAddr->hostInputData - args); | 235 | + executor->mc2.aicpuArgs.soNameAddrOffset = static_cast<uint32_t>(argsAddr->hostInputData - args); |
| 234 | } | 236 | } |
| 235 | 237 | ||
| 236 | - bool isA5AiCpu = nnopbase::IndvSoc::GetInstance().NnopbaseSupportA5AiCpu(executor->mc2OpCfg.sType); | 238 | + bool isA5AiCpu = nnopbase::IndvSoc::GetInstance().NnopbaseSupportA5AiCpu(executor->mc2.serverType); |
| 237 | const NnopbaseUChar* pSoName = isA5AiCpu ? NNOPBASE_MC2_SERVER_SO_NAME : NNOPBASE_MC2_AICPU_SO_NAME; | 239 | const NnopbaseUChar* pSoName = isA5AiCpu ? NNOPBASE_MC2_SERVER_SO_NAME : NNOPBASE_MC2_AICPU_SO_NAME; |
| 238 | const NnopbaseUChar* pKernelName = isA5AiCpu ? NNOPBASE_MC2_SERVER_KERNEL_NAME : NNOPBASE_MC2_AICPU_KERNEL_NAME; | 240 | const NnopbaseUChar* pKernelName = isA5AiCpu ? NNOPBASE_MC2_SERVER_KERNEL_NAME : NNOPBASE_MC2_AICPU_KERNEL_NAME; |
| 239 | 241 | ||
| @@ -241,10 +243,11 @@ void NnopbasePrepareMC2Params(NnopbaseExecutor* executor, NnopbaseExecutorArgsAd | |||
| 241 | argsAddr->hostInputData = NnopbaseAppend1Byte(argsAddr->hostInputData, pSoName[i]); | 243 | argsAddr->hostInputData = NnopbaseAppend1Byte(argsAddr->hostInputData, pSoName[i]); |
| 242 | } | 244 | } |
| 243 | 245 | ||
| 244 | - if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType)) { | 246 | + if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { |
| 245 | - executor->fusionArgs.aicpuArgs[0].kernelNameAddrOffset = static_cast<uint16_t>(argsAddr->hostInputData - args); | 247 | + executor->mc2.fusionArgs.aicpuArgs[0].kernelNameAddrOffset = static_cast<uint16_t>(argsAddr->hostInputData - |
| 248 | + args); | ||
| 246 | } else { | 249 | } else { |
| 247 | - executor->aicpuArgs.kernelNameAddrOffset = static_cast<uint16_t>(argsAddr->hostInputData - args); | 250 | + executor->mc2.aicpuArgs.kernelNameAddrOffset = static_cast<uint16_t>(argsAddr->hostInputData - args); |
| 248 | } | 251 | } |
| 249 | 252 | ||
| 250 | for (size_t i = 0U; i < NNOPBASE_AICPU_PARAM_LEN; i++) { | 253 | for (size_t i = 0U; i < NNOPBASE_AICPU_PARAM_LEN; i++) { |
| @@ -257,7 +260,7 @@ void NnopbasePrepareMC2Params(NnopbaseExecutor* executor, NnopbaseExecutorArgsAd | |||
| 257 | opName.length()), | 260 | opName.length()), |
| 258 | return); | 261 | return); |
| 259 | 262 | ||
| 260 | - if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType)) { | 263 | + if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { |
| 261 | const size_t opLen = ((opName.length() + 7) / 8) * 8; | 264 | const size_t opLen = ((opName.length() + 7) / 8) * 8; |
| 262 | argsAddr->hostInputData += opLen; | 265 | argsAddr->hostInputData += opLen; |
| 263 | return NnopbaseCopyDavidMC2ParamDesc(executor, argsAddr); | 266 | return NnopbaseCopyDavidMC2ParamDesc(executor, argsAddr); |
| @@ -286,20 +289,20 @@ aclnnStatus NnopbaseAicpuKernelLaunch(NnopbaseExecutor* const executor) | |||
| 286 | { | 289 | { |
| 287 | uint32_t time = 0; | 290 | uint32_t time = 0; |
| 288 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseGetAicpuTimeout(&time)); | 291 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseGetAicpuTimeout(&time)); |
| 289 | - executor->aicpuArgs.timeout = time; | 292 | + executor->mc2.aicpuArgs.timeout = time; |
| 290 | const uint64_t launchBeginTime = NnopbaseMsprofSysTime(); | 293 | const uint64_t launchBeginTime = NnopbaseMsprofSysTime(); |
| 291 | const std::string opType = std::string(executor->opType) + NNOPBASE_MC2_AICPU_SUFFIX; | 294 | const std::string opType = std::string(executor->opType) + NNOPBASE_MC2_AICPU_SUFFIX; |
| 292 | const uint32_t numBlocks = executor->args->tilingInfo.aicpuNumBlocks == 0U ? | 295 | const uint32_t numBlocks = executor->args->tilingInfo.aicpuNumBlocks == 0U ? |
| 293 | 1U : | 296 | 1U : |
| 294 | executor->args->tilingInfo.aicpuNumBlocks; | 297 | executor->args->tilingInfo.aicpuNumBlocks; |
| 295 | - NNOPBASE_ASSERT_RTOK_RETVAL(rtAicpuKernelLaunchExWithArgs(KERNEL_TYPE_AICPU_KFC, &opType[0], numBlocks, | 298 | + NNOPBASE_ASSERT_RTOK_RETVAL( |
| 296 | - &executor->aicpuArgs, nullptr, executor->aicpuStream[0], | 299 | + rtAicpuKernelLaunchExWithArgs(KERNEL_TYPE_AICPU_KFC, &opType[0], numBlocks, &executor->mc2.aicpuArgs, nullptr, |
| 297 | - RT_KERNEL_USE_SPECIAL_TIMEOUT)); | 300 | + executor->mc2.aicpuStreams[0], RT_KERNEL_USE_SPECIAL_TIMEOUT)); |
| 298 | OP_LOGI("%s launch successfully, numBlocks is %u.", opType.c_str(), numBlocks); | 301 | OP_LOGI("%s launch successfully, numBlocks is %u.", opType.c_str(), numBlocks); |
| 299 | 302 | ||
| 300 | - NnopbaseInnerReportLaunchInfo(launchBeginTime, executor->aicpuItemId); | 303 | + NnopbaseInnerReportLaunchInfo(launchBeginTime, executor->dfx.aicpuItemId); |
| 301 | NnopbaseReportAicpuAdditionInfo(launchBeginTime + 1, &opType[0]); | 304 | NnopbaseReportAicpuAdditionInfo(launchBeginTime + 1, &opType[0]); |
| 302 | - NnopbaseReportCacheOpInfo(executor, 0U, MSPROF_GE_TASK_TYPE_AI_CPU, executor->aicpuStream[0]); | 305 | + NnopbaseReportCacheOpInfo(executor, 0U, MSPROF_GE_TASK_TYPE_AI_CPU, executor->mc2.aicpuStreams[0]); |
| 303 | return OK; | 306 | return OK; |
| 304 | } | 307 | } |
| 305 | 308 | ||
| @@ -318,7 +321,7 @@ aclnnStatus NnopbaseFusionKernelLaunch(NnopbaseExecutor* const executor, aclrtSt | |||
| 318 | rtFunsionTaskInfo_t fusionTaskInfo = {}; | 321 | rtFunsionTaskInfo_t fusionTaskInfo = {}; |
| 319 | rtCcuTaskGroup_t ccuTaskGroup = {}; | 322 | rtCcuTaskGroup_t ccuTaskGroup = {}; |
| 320 | NNOPBASE_ASSERT_RTOK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcclGetCcuTaskInfo( | 323 | NNOPBASE_ASSERT_RTOK_RETVAL(nnopbase::IndvHcclWrapper::GetInstance().HcclGetCcuTaskInfo( |
| 321 | - executor->mc2OpCfg.hcomHandle[0], | 324 | + executor->mc2.commHandles[0], |
| 322 | (op::internal::PtrCastTo<NnopbaseTilingData>(executor->args->tilingInfo.tilingData))->GetData(), | 325 | (op::internal::PtrCastTo<NnopbaseTilingData>(executor->args->tilingInfo.tilingData))->GetData(), |
| 323 | &ccuTaskGroup)); | 326 | &ccuTaskGroup)); |
| 324 | fusionTaskInfo.subTask[0].type = RT_FUSION_CCU; | 327 | fusionTaskInfo.subTask[0].type = RT_FUSION_CCU; |
| @@ -330,7 +333,7 @@ aclnnStatus NnopbaseFusionKernelLaunch(NnopbaseExecutor* const executor, aclrtSt | |||
| 330 | fusionTaskInfo.subTask[0].type, fusionTaskInfo.subTask[1].type); | 333 | fusionTaskInfo.subTask[0].type, fusionTaskInfo.subTask[1].type); |
| 331 | 334 | ||
| 332 | const uint64_t launchBeginTime = NnopbaseMsprofSysTime(); | 335 | const uint64_t launchBeginTime = NnopbaseMsprofSysTime(); |
| 333 | - NNOPBASE_ASSERT_RTOK_RETVAL(rtFusionLaunch(&fusionTaskInfo, stream, &executor->fusionArgs)); | 336 | + NNOPBASE_ASSERT_RTOK_RETVAL(rtFusionLaunch(&fusionTaskInfo, stream, &executor->mc2.fusionArgs)); |
| 334 | NnopbaseExecutorReportProfiling(executor, numBlocks, MSPROF_GE_TASK_TYPE_FUSION, launchBeginTime, stream); | 337 | NnopbaseExecutorReportProfiling(executor, numBlocks, MSPROF_GE_TASK_TYPE_FUSION, launchBeginTime, stream); |
| 335 | OP_LOGI("Op %s fusion launch successfully.", executor->opType); | 338 | OP_LOGI("Op %s fusion launch successfully.", executor->opType); |
| 336 | return OK; | 339 | return OK; |
| @@ -358,19 +361,19 @@ static aclnnStatus NnopbaseMC2KernelAicpu(NnopbaseExecutor* executor, aclrtStrea | |||
| 358 | 361 | ||
| 359 | aclnnStatus NnopbaseMC2KernelLaunch(NnopbaseExecutor* executor, aclrtStream stream) | 362 | aclnnStatus NnopbaseMC2KernelLaunch(NnopbaseExecutor* executor, aclrtStream stream) |
| 360 | { | 363 | { |
| 361 | - OP_LOGI("HcclServerType is %d.", executor->mc2OpCfg.sType); | 364 | + OP_LOGI("HcclServerType is %d.", executor->mc2.serverType); |
| 362 | if (NnopbaseSkipKernelLaunch(executor)) { | 365 | if (NnopbaseSkipKernelLaunch(executor)) { |
| 363 | OP_LOGI("Output of MC2 operator is empty and ZeroEleOutputLaunch is not enabled, skipping launch."); | 366 | OP_LOGI("Output of MC2 operator is empty and ZeroEleOutputLaunch is not enabled, skipping launch."); |
| 364 | return OK; | 367 | return OK; |
| 365 | } | 368 | } |
| 366 | - if (executor->mc2OpCfg.sType == NNOPBASE_HCCL_SERVER_TYPE_END) { // default | 369 | + if (executor->mc2.serverType == NNOPBASE_HCCL_SERVER_TYPE_END) { // default |
| 367 | - if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2OpCfg.sType)) { | 370 | + if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { |
| 368 | return NnopbaseMC2KernelCCU(executor, stream); | 371 | return NnopbaseMC2KernelCCU(executor, stream); |
| 369 | } else { | 372 | } else { |
| 370 | return NnopbaseMC2KernelAicpu(executor, stream); | 373 | return NnopbaseMC2KernelAicpu(executor, stream); |
| 371 | } | 374 | } |
| 372 | } else { | 375 | } else { |
| 373 | - switch (executor->mc2OpCfg.sType) { | 376 | + switch (executor->mc2.serverType) { |
| 374 | case NNOPBASE_HCCL_SERVER_TYPE_MTE: | 377 | case NNOPBASE_HCCL_SERVER_TYPE_MTE: |
| 375 | return NnopbaseMC2KernelMTE(executor, stream); | 378 | return NnopbaseMC2KernelMTE(executor, stream); |
| 376 | case NNOPBASE_HCCL_SERVER_TYPE_CCU: | 379 | case NNOPBASE_HCCL_SERVER_TYPE_CCU: |
| @@ -20,7 +20,7 @@ aclnnStatus NnopbaseAicpuKernelLaunch(NnopbaseExecutor* const executor); | |||
| 20 | void NnopbasePrepareMC2Params(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr); | 20 | void NnopbasePrepareMC2Params(NnopbaseExecutor* executor, NnopbaseExecutorArgsAddr* argsAddr); |
| 21 | aclnnStatus NnopbaseLaunchKFCTask(NnopbaseExecutor* const executor, aclrtStream stream); | 21 | aclnnStatus NnopbaseLaunchKFCTask(NnopbaseExecutor* const executor, aclrtStream stream); |
| 22 | aclnnStatus NnopbaseLaunchKFCTaskA5(NnopbaseExecutor* const executor, aclrtStream stream); | 22 | aclnnStatus NnopbaseLaunchKFCTaskA5(NnopbaseExecutor* const executor, aclrtStream stream); |
| 23 | -aclnnStatus NnopbaseExecutorGetMc2Num(NnopbaseExecutor* executor, aclrtStream const stream, | 23 | +aclnnStatus NnopbaseExecutorGetMc2Num(NnopbaseExecutor* const executor, aclrtStream const stream, |
| 24 | NnopbaseExecutorArgsAddr* argsAddr, uint32_t* mc2Num); | 24 | NnopbaseExecutorArgsAddr* argsAddr, uint32_t* mc2Num); |
| 25 | aclnnStatus NnopbaseFusionKernelLaunch(NnopbaseExecutor* const executor, aclrtStream const stream); | 25 | aclnnStatus NnopbaseFusionKernelLaunch(NnopbaseExecutor* const executor, aclrtStream const stream); |
| 26 | aclnnStatus NnopbaseMC2KernelLaunch(NnopbaseExecutor* executor, aclrtStream stream); | 26 | aclnnStatus NnopbaseMC2KernelLaunch(NnopbaseExecutor* executor, aclrtStream stream); |
| @@ -127,7 +127,7 @@ aclnnStatus NnopbaseNonFiniteCheckRunForWorkspaceSize(const std::vector<const Ge | |||
| 127 | 127 | ||
| 128 | // 添加维测信息 | 128 | // 添加维测信息 |
| 129 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddTilingId(*executor, &tilingId)); | 129 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddTilingId(*executor, &tilingId)); |
| 130 | - NnopbaseExecutorAddSupportList(*executor, &supportList, socSupportList, socSupportListLen); | 130 | + NnopbaseExecutorAddSupportList((*executor)->opCompatibility, &supportList, socSupportList, socSupportListLen); |
| 131 | 131 | ||
| 132 | // 执行一阶段流程 | 132 | // 执行一阶段流程 |
| 133 | const aclnnStatus ret = NnopbaseExecutorRunForWorkspace(*executor, workspaceSize); | 133 | const aclnnStatus ret = NnopbaseExecutorRunForWorkspace(*executor, workspaceSize); |
| @@ -167,10 +167,10 @@ void NnopbaseReportCacheOpInfo(NnopbaseExecutor* const executor, uint32_t numBlo | |||
| 167 | NnopbaseEncodeMixOpNumBlocks(executor, numBlocks); | 167 | NnopbaseEncodeMixOpNumBlocks(executor, numBlocks); |
| 168 | 168 | ||
| 169 | uint32_t totalNum = executor->args->inputs.num + executor->args->outputs.num; | 169 | uint32_t totalNum = executor->args->inputs.num + executor->args->outputs.num; |
| 170 | - uint64_t itemId = executor->itemId; | 170 | + uint64_t itemId = executor->dfx.itemId; |
| 171 | if (taskType == MSPROF_GE_TASK_TYPE_AI_CPU) { | 171 | if (taskType == MSPROF_GE_TASK_TYPE_AI_CPU) { |
| 172 | totalNum = 0U; | 172 | totalNum = 0U; |
| 173 | - itemId = executor->aicpuItemId; | 173 | + itemId = executor->dfx.aicpuItemId; |
| 174 | } | 174 | } |
| 175 | size_t totalSize = sizeof(op::internal::CacheOpInfoBasic) + sizeof(MsrofTensorData) * totalNum; | 175 | size_t totalSize = sizeof(op::internal::CacheOpInfoBasic) + sizeof(MsrofTensorData) * totalNum; |
| 176 | void* buffer = malloc(totalSize); | 176 | void* buffer = malloc(totalSize); |
| @@ -213,7 +213,7 @@ static void NnopbaseBuildSingleProfTensorInfo(NnopbaseExecutor* const executor, | |||
| 213 | tensorInfo.dataLen = static_cast<uint32_t>(sizeof(MsprofTensorInfo)); | 213 | tensorInfo.dataLen = static_cast<uint32_t>(sizeof(MsprofTensorInfo)); |
| 214 | auto profTensorData = op::internal::PtrCastTo<MsprofTensorInfo>(tensorInfo.data); | 214 | auto profTensorData = op::internal::PtrCastTo<MsprofTensorInfo>(tensorInfo.data); |
| 215 | 215 | ||
| 216 | - profTensorData->opName = executor->itemId; | 216 | + profTensorData->opName = executor->dfx.itemId; |
| 217 | profTensorData->tensorNum = tensorNum; | 217 | profTensorData->tensorNum = tensorNum; |
| 218 | for (size_t k = 0UL; k < static_cast<size_t>(tensorNum); ++k) { | 218 | for (size_t k = 0UL; k < static_cast<size_t>(tensorNum); ++k) { |
| 219 | const size_t tensorIndex = (index * static_cast<size_t>(MSPROF_GE_TENSOR_DATA_NUM)) + k; | 219 | const size_t tensorIndex = (index * static_cast<size_t>(MSPROF_GE_TENSOR_DATA_NUM)) + k; |
| @@ -257,7 +257,7 @@ void NnopbaseReportContextIdInfo(const NnopbaseExecutor* const executor, const u | |||
| 257 | auto contextIdInfo = op::internal::PtrCastTo<MsprofContextIdInfo>(info.data); | 257 | auto contextIdInfo = op::internal::PtrCastTo<MsprofContextIdInfo>(info.data); |
| 258 | contextIdInfo->ctxIdNum = 1U; | 258 | contextIdInfo->ctxIdNum = 1U; |
| 259 | contextIdInfo->ctxIds[0] = 0U; | 259 | contextIdInfo->ctxIds[0] = 0U; |
| 260 | - contextIdInfo->opName = executor->itemId; | 260 | + contextIdInfo->opName = executor->dfx.itemId; |
| 261 | (void)MsprofReportAdditionalInfo(static_cast<uint32_t>(true), &info, | 261 | (void)MsprofReportAdditionalInfo(static_cast<uint32_t>(true), &info, |
| 262 | static_cast<uint32_t>(sizeof(MsprofAdditionalInfo))); | 262 | static_cast<uint32_t>(sizeof(MsprofAdditionalInfo))); |
| 263 | OP_LOGD("OP [%s] has reported contextid info.", executor->opType); | 263 | OP_LOGD("OP [%s] has reported contextid info.", executor->opType); |
| @@ -308,7 +308,7 @@ void NnopbaseReportAdditionInfo(void* const executor, uint32_t numBlocks, uint32 | |||
| 308 | } | 308 | } |
| 309 | OP_LOGI("[Cann Profiling] node type is %s, taskType is %u", opExecutor->opType, taskType); | 309 | OP_LOGI("[Cann Profiling] node type is %s, taskType is %u", opExecutor->opType, taskType); |
| 310 | if (op::internal::opProfilingSwitch.additionInfoFlag) { | 310 | if (op::internal::opProfilingSwitch.additionInfoFlag) { |
| 311 | - const uint64_t typeHash = opExecutor->itemId; | 311 | + const uint64_t typeHash = opExecutor->dfx.itemId; |
| 312 | MsprofCompactInfo nodeBasicInfo{}; | 312 | MsprofCompactInfo nodeBasicInfo{}; |
| 313 | NnopbaseBuildNodeBasicInfo(numBlocks, {typeHash, typeHash}, taskType, nodeBasicInfo, timeStamp); | 313 | NnopbaseBuildNodeBasicInfo(numBlocks, {typeHash, typeHash}, taskType, nodeBasicInfo, timeStamp); |
| 314 | (void)MsprofReportCompactInfo(static_cast<uint32_t>(true), &nodeBasicInfo, | 314 | (void)MsprofReportCompactInfo(static_cast<uint32_t>(true), &nodeBasicInfo, |
| @@ -325,7 +325,7 @@ void NnopbaseReportMemsetAdditionInfo(const NnopbaseExecutor* const executor, ui | |||
| 325 | if (op::internal::opProfilingSwitch.reportFlag || op::internal::opProfilingSwitch.kernelLaunchFlag) { | 325 | if (op::internal::opProfilingSwitch.reportFlag || op::internal::opProfilingSwitch.kernelLaunchFlag) { |
| 326 | OP_LOGI("[Cann Profiling] node type is MemSet, taskType is %u", taskType); | 326 | OP_LOGI("[Cann Profiling] node type is MemSet, taskType is %u", taskType); |
| 327 | if (op::internal::opProfilingSwitch.additionInfoFlag) { | 327 | if (op::internal::opProfilingSwitch.additionInfoFlag) { |
| 328 | - const uint64_t typeHash = executor->memsetItemId; | 328 | + const uint64_t typeHash = executor->dfx.memsetItemId; |
| 329 | MsprofCompactInfo nodeBasicInfo{}; | 329 | MsprofCompactInfo nodeBasicInfo{}; |
| 330 | NnopbaseBuildNodeBasicInfo(numBlocks, {typeHash, typeHash}, taskType, nodeBasicInfo, timeStamp); | 330 | NnopbaseBuildNodeBasicInfo(numBlocks, {typeHash, typeHash}, taskType, nodeBasicInfo, timeStamp); |
| 331 | (void)MsprofReportCompactInfo(static_cast<uint32_t>(true), &nodeBasicInfo, | 331 | (void)MsprofReportCompactInfo(static_cast<uint32_t>(true), &nodeBasicInfo, |
| @@ -480,7 +480,7 @@ static void NnopbaseReportAttrInfo(const NnopbaseExecutor* const executor, const | |||
| 480 | { | 480 | { |
| 481 | std::string attrStr = NnopbaseGetAttrVal(executor->attrs); | 481 | std::string attrStr = NnopbaseGetAttrVal(executor->attrs); |
| 482 | if (!attrStr.empty()) { | 482 | if (!attrStr.empty()) { |
| 483 | - NnopbaseReportInfo(attrStr, executor->itemId, timeStamp); | 483 | + NnopbaseReportInfo(attrStr, executor->dfx.itemId, timeStamp); |
| 484 | } | 484 | } |
| 485 | } | 485 | } |
| 486 | 486 | ||
| @@ -541,7 +541,7 @@ static void NnopbaseReportHostInfo(const NnopbaseExecutor* const executor, const | |||
| 541 | { | 541 | { |
| 542 | std::string inputStr = NnopbaseGetHostInfoStr(executor->args->inputs); | 542 | std::string inputStr = NnopbaseGetHostInfoStr(executor->args->inputs); |
| 543 | if (!inputStr.empty()) { | 543 | if (!inputStr.empty()) { |
| 544 | - NnopbaseReportInfo(inputStr, executor->itemId, timeStamp); | 544 | + NnopbaseReportInfo(inputStr, executor->dfx.itemId, timeStamp); |
| 545 | } | 545 | } |
| 546 | } | 546 | } |
| 547 | 547 | ||
| @@ -119,8 +119,8 @@ static inline size_t NnopbaseKernelRunContextLen(const uint32_t num) | |||
| 119 | 119 | ||
| 120 | void NnopbaseTilingBuildOpInputs(NnopbaseExecutor* executor) | 120 | void NnopbaseTilingBuildOpInputs(NnopbaseExecutor* executor) |
| 121 | { | 121 | { |
| 122 | - NnopbaseAsyncAnyValue** values = executor->contextExt.context->values; | 122 | + NnopbaseAsyncAnyValue** values = executor->tiling.contextExt.context->values; |
| 123 | - NnopbaseCompileTimeTensorDesc* inputTd = executor->contextExt.nodeExt.inputTdStart; | 123 | + NnopbaseCompileTimeTensorDesc* inputTd = executor->tiling.contextExt.nodeExt.inputTdStart; |
| 124 | for (uint32_t i = 0; i < executor->args->inputs.num; i++) { | 124 | for (uint32_t i = 0; i < executor->args->inputs.num; i++) { |
| 125 | if (!executor->args->inputs.extTensors[i].isNull) { | 125 | if (!executor->args->inputs.extTensors[i].isNull) { |
| 126 | NnopbaseCompileTimeTensorDesc* td = inputTd + i; | 126 | NnopbaseCompileTimeTensorDesc* td = inputTd + i; |
| @@ -140,8 +140,8 @@ void NnopbaseTilingBuildOpInputs(NnopbaseExecutor* executor) | |||
| 140 | 140 | ||
| 141 | void NnopbaseTilingBuildOpOutputs(NnopbaseExecutor* executor) | 141 | void NnopbaseTilingBuildOpOutputs(NnopbaseExecutor* executor) |
| 142 | { | 142 | { |
| 143 | - NnopbaseCompileTimeTensorDesc* outputTd = executor->contextExt.nodeExt.outputTdStart; | 143 | + NnopbaseCompileTimeTensorDesc* outputTd = executor->tiling.contextExt.nodeExt.outputTdStart; |
| 144 | - NnopbaseAsyncAnyValue** values = &executor->contextExt.context->values[executor->args->inputs.num]; | 144 | + NnopbaseAsyncAnyValue** values = &executor->tiling.contextExt.context->values[executor->args->inputs.num]; |
| 145 | const uint32_t count = executor->args->outputs.num; | 145 | const uint32_t count = executor->args->outputs.num; |
| 146 | for (uint32_t i = 0; i < count; i++) { | 146 | for (uint32_t i = 0; i < count; i++) { |
| 147 | if (!executor->args->outputs.extTensors[i].isNull) { | 147 | if (!executor->args->outputs.extTensors[i].isNull) { |
| @@ -164,40 +164,40 @@ void NnopbaseTilingBuildOpOutputs(NnopbaseExecutor* executor) | |||
| 164 | // 若无动态输入,在不需要重新刷新,有动态输入场景需要重新刷新 | 164 | // 若无动态输入,在不需要重新刷新,有动态输入场景需要重新刷新 |
| 165 | static void NnopbaseTilingSetContextOutputStep1(NnopbaseExecutor* const executor) | 165 | static void NnopbaseTilingSetContextOutputStep1(NnopbaseExecutor* const executor) |
| 166 | { | 166 | { |
| 167 | - NnopbaseAsyncAnyValue** values = executor->contextExt.context->values; | 167 | + NnopbaseAsyncAnyValue** values = executor->tiling.contextExt.context->values; |
| 168 | - size_t index = executor->contextExt.context->input_size; | 168 | + size_t index = executor->tiling.contextExt.context->input_size; |
| 169 | /* kOutputTilingKey. */ | 169 | /* kOutputTilingKey. */ |
| 170 | - executor->tilingKey = op::internal::PtrCastTo<uint64_t>(values[index]->data.inplace); | 170 | + executor->tiling.tilingKey = op::internal::PtrCastTo<uint64_t>(values[index]->data.inplace); |
| 171 | values[index]->deleter = nullptr; | 171 | values[index]->deleter = nullptr; |
| 172 | index++; | 172 | index++; |
| 173 | /* kOutputBlockDim. */ | 173 | /* kOutputBlockDim. */ |
| 174 | - executor->numBlocks = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); | 174 | + executor->tiling.numBlocks = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); |
| 175 | values[index]->deleter = nullptr; | 175 | values[index]->deleter = nullptr; |
| 176 | index++; | 176 | index++; |
| 177 | /* kOutputAtomicCleanFlag. */ | 177 | /* kOutputAtomicCleanFlag. */ |
| 178 | - executor->needAtomic = op::internal::PtrCastTo<bool>(values[index]->data.inplace); | 178 | + executor->tiling.needAtomic = op::internal::PtrCastTo<bool>(values[index]->data.inplace); |
| 179 | values[index]->deleter = nullptr; | 179 | values[index]->deleter = nullptr; |
| 180 | /* 4 for OutputTilingData, OutputWorkspace, OutputTilingCond, OutputScheduleMode. */ | 180 | /* 4 for OutputTilingData, OutputWorkspace, OutputTilingCond, OutputScheduleMode. */ |
| 181 | index += 4U; | 181 | index += 4U; |
| 182 | /* kOutputScheduleMode. */ | 182 | /* kOutputScheduleMode. */ |
| 183 | - executor->scheMode = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); | 183 | + executor->tiling.scheMode = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); |
| 184 | values[index]->deleter = nullptr; | 184 | values[index]->deleter = nullptr; |
| 185 | index++; | 185 | index++; |
| 186 | /* kOutputLocalMemorySize. */ | 186 | /* kOutputLocalMemorySize. */ |
| 187 | - executor->dynUbufSize = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); | 187 | + executor->tiling.dynUbufSize = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); |
| 188 | values[index]->deleter = nullptr; | 188 | values[index]->deleter = nullptr; |
| 189 | index++; | 189 | index++; |
| 190 | - executor->aicpuNumBlocks = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); | 190 | + executor->tiling.aicpuNumBlocks = op::internal::PtrCastTo<uint32_t>(values[index]->data.inplace); |
| 191 | values[index]->deleter = nullptr; | 191 | values[index]->deleter = nullptr; |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | // 设置TilingData和Workspace,实际内存放在tilingInfo里,value里的addr保存 | 194 | // 设置TilingData和Workspace,实际内存放在tilingInfo里,value里的addr保存 |
| 195 | static void NnopbaseTilingSetContextOutputStep2(NnopbaseExecutor* const executor) | 195 | static void NnopbaseTilingSetContextOutputStep2(NnopbaseExecutor* const executor) |
| 196 | { | 196 | { |
| 197 | - NnopbaseAsyncAnyValue** values = executor->contextExt.context->values; | 197 | + NnopbaseAsyncAnyValue** values = executor->tiling.contextExt.context->values; |
| 198 | auto& tilingInfo = executor->args->tilingInfo; | 198 | auto& tilingInfo = executor->args->tilingInfo; |
| 199 | // 3 for tilingkey, numBlocks, atomic | 199 | // 3 for tilingkey, numBlocks, atomic |
| 200 | - size_t index = executor->contextExt.context->input_size + 3U; | 200 | + size_t index = executor->tiling.contextExt.context->input_size + 3U; |
| 201 | /* kOutputTilingData. */ | 201 | /* kOutputTilingData. */ |
| 202 | values[index]->data.pointer = op::internal::PtrCastTo<void>(tilingInfo.tilingData); | 202 | values[index]->data.pointer = op::internal::PtrCastTo<void>(tilingInfo.tilingData); |
| 203 | values[index]->deleter = nullptr; | 203 | values[index]->deleter = nullptr; |
| @@ -212,9 +212,9 @@ aclnnStatus NnopbaseTilingContextBuild(NnopbaseExecutor* executor) | |||
| 212 | if (!g_nnopbasePlatformMgr.isInit) { | 212 | if (!g_nnopbasePlatformMgr.isInit) { |
| 213 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseExecutorPlatFormInfosInit()); | 213 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseExecutorPlatFormInfosInit()); |
| 214 | } | 214 | } |
| 215 | - NnopbaseAsyncAnyValue** values = executor->contextExt.context->values; | 215 | + NnopbaseAsyncAnyValue** values = executor->tiling.contextExt.context->values; |
| 216 | // executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt for option input | 216 | // executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt for option input |
| 217 | - if ((!executor->contextExt.hasPrepared) || executor->args->inputs.hasDynamic || | 217 | + if ((!executor->tiling.contextExt.hasPrepared) || executor->args->inputs.hasDynamic || |
| 218 | executor->args->outputs.hasDynamic || | 218 | executor->args->outputs.hasDynamic || |
| 219 | (executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt)) { | 219 | (executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt)) { |
| 220 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseTilingContextUpdtPrepare(executor)); | 220 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseTilingContextUpdtPrepare(executor)); |
| @@ -230,22 +230,22 @@ aclnnStatus NnopbaseTilingContextBuild(NnopbaseExecutor* executor) | |||
| 230 | values[index]->deleter = nullptr; | 230 | values[index]->deleter = nullptr; |
| 231 | index++; | 231 | index++; |
| 232 | /* kInputsDeterministic. */ | 232 | /* kInputsDeterministic. */ |
| 233 | - values[index]->data.pointer = reinterpret_cast<void*>(executor->deterministic); | 233 | + values[index]->data.pointer = reinterpret_cast<void*>(executor->deterministicLevel); |
| 234 | values[index]->deleter = nullptr; | 234 | values[index]->deleter = nullptr; |
| 235 | NnopbaseTilingSetContextOutputStep1(executor); | 235 | NnopbaseTilingSetContextOutputStep1(executor); |
| 236 | - executor->contextExt.hasPrepared = true; | 236 | + executor->tiling.contextExt.hasPrepared = true; |
| 237 | } | 237 | } |
| 238 | /* kInputsPlatformInfo. */ | 238 | /* kInputsPlatformInfo. */ |
| 239 | uint32_t platformInfIndex = executor->args->inputs.num + executor->args->outputs.num + 1U; | 239 | uint32_t platformInfIndex = executor->args->inputs.num + executor->args->outputs.num + 1U; |
| 240 | values[platformInfIndex]->data.pointer = static_cast<void*>(g_nnopbasePlatformMgr.infos.get()); | 240 | values[platformInfIndex]->data.pointer = static_cast<void*>(g_nnopbasePlatformMgr.infos.get()); |
| 241 | values[platformInfIndex]->deleter = nullptr; | 241 | values[platformInfIndex]->deleter = nullptr; |
| 242 | 242 | ||
| 243 | - *(executor->tilingKey) = 0U; | 243 | + *(executor->tiling.tilingKey) = 0U; |
| 244 | - *(executor->numBlocks) = 0U; | 244 | + *(executor->tiling.numBlocks) = 0U; |
| 245 | - *(executor->scheMode) = 0U; | 245 | + *(executor->tiling.scheMode) = 0U; |
| 246 | - *(executor->needAtomic) = false; | 246 | + *(executor->tiling.needAtomic) = false; |
| 247 | - *(executor->aicpuNumBlocks) = 0U; | 247 | + *(executor->tiling.aicpuNumBlocks) = 0U; |
| 248 | - *(executor->dynUbufSize) = 0U; | 248 | + *(executor->tiling.dynUbufSize) = 0U; |
| 249 | NnopbaseTilingSetContextOutputStep2(executor); | 249 | NnopbaseTilingSetContextOutputStep2(executor); |
| 250 | NnopbaseTilingBuildOpInputs(executor); | 250 | NnopbaseTilingBuildOpInputs(executor); |
| 251 | NnopbaseTilingBuildOpOutputs(executor); | 251 | NnopbaseTilingBuildOpOutputs(executor); |
| @@ -280,7 +280,7 @@ aclnnStatus NnopbaseInitContext(NnopbaseKernelRunContextExt* contextExt, const u | |||
| 280 | 280 | ||
| 281 | aclnnStatus NnopbaseTilingContextInit(NnopbaseExecutor* executor) | 281 | aclnnStatus NnopbaseTilingContextInit(NnopbaseExecutor* executor) |
| 282 | { | 282 | { |
| 283 | - NnopbaseKernelRunContextExt* contextExt = &executor->contextExt; | 283 | + NnopbaseKernelRunContextExt* contextExt = &executor->tiling.contextExt; |
| 284 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseComputeNodeInfoInit(&contextExt->nodeExt)); | 284 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseComputeNodeInfoInit(&contextExt->nodeExt)); |
| 285 | const uint32_t num = NnopbaseGetKernelRunContextValuesInitNum(executor); | 285 | const uint32_t num = NnopbaseGetKernelRunContextValuesInitNum(executor); |
| 286 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseInitContext(contextExt, num)); | 286 | NNOPBASE_ASSERT_OK_RETVAL(NnopbaseInitContext(contextExt, num)); |
| @@ -290,8 +290,8 @@ aclnnStatus NnopbaseTilingContextInit(NnopbaseExecutor* executor) | |||
| 290 | 290 | ||
| 291 | void NnopbaseTilingContextDeInit(NnopbaseExecutor* executor) | 291 | void NnopbaseTilingContextDeInit(NnopbaseExecutor* executor) |
| 292 | { | 292 | { |
| 293 | - FREE(executor->contextExt.context); | 293 | + FREE(executor->tiling.contextExt.context); |
| 294 | - NnopbaseComputeNodeInfoDeInit(&executor->contextExt.nodeExt); | 294 | + NnopbaseComputeNodeInfoDeInit(&executor->tiling.contextExt.nodeExt); |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | aclnnStatus NnopbaseMemsetTilingContextInit(const std::vector<NnopbaseInitValueInfo>& initValues, | 297 | aclnnStatus NnopbaseMemsetTilingContextInit(const std::vector<NnopbaseInitValueInfo>& initValues, |
| @@ -455,7 +455,7 @@ aclnnStatus NnopbaseBuildMemsetTilingContext(NnopbaseExecutor* executor) | |||
| 455 | values[index]->deleter = nullptr; | 455 | values[index]->deleter = nullptr; |
| 456 | index++; | 456 | index++; |
| 457 | /* kInputsDeterministic. */ | 457 | /* kInputsDeterministic. */ |
| 458 | - values[index]->data.pointer = reinterpret_cast<void*>(executor->deterministic); | 458 | + values[index]->data.pointer = reinterpret_cast<void*>(executor->deterministicLevel); |
| 459 | values[index]->deleter = nullptr; | 459 | values[index]->deleter = nullptr; |
| 460 | 460 | ||
| 461 | NnopbaseSetMemsetTilingKeyAndNumBlocks(executor); | 461 | NnopbaseSetMemsetTilingKeyAndNumBlocks(executor); |
| @@ -551,7 +551,7 @@ aclnnStatus NnopbaseBuildAndRunMemsetTilingParse(std::shared_ptr<MemsetOpInfo>& | |||
| 551 | NNOPBASE_ASSERT_NOTNULL_RETVAL(opImpl->tiling_parse); | 551 | NNOPBASE_ASSERT_NOTNULL_RETVAL(opImpl->tiling_parse); |
| 552 | NNOPBASE_ASSERT_NOTNULL_RETVAL(opImpl->tiling); | 552 | NNOPBASE_ASSERT_NOTNULL_RETVAL(opImpl->tiling); |
| 553 | CHECK_COND(NnopbaseSetMemsetTilingContext(memsetInfo, opImpl->compile_info_creator()) == OK, ACLNN_ERR_INNER, | 553 | CHECK_COND(NnopbaseSetMemsetTilingContext(memsetInfo, opImpl->compile_info_creator()) == OK, ACLNN_ERR_INNER, |
| 554 | - "Failed to set tilingContext for MemSet operator."); | 554 | + "Failed to set tiling for MemSet operator."); |
| 555 | 555 | ||
| 556 | memsetInfo->tilingFunc = reinterpret_cast<TilingFun>(opImpl->tiling); | 556 | memsetInfo->tilingFunc = reinterpret_cast<TilingFun>(opImpl->tiling); |
| 557 | auto ret = opImpl->tiling_parse(op::internal::PtrCastTo<gert::KernelContext>(memsetInfo->tilingParseContext)); | 557 | auto ret = opImpl->tiling_parse(op::internal::PtrCastTo<gert::KernelContext>(memsetInfo->tilingParseContext)); |
| @@ -79,7 +79,7 @@ struct NnopbaseTimeStamp { | |||
| 79 | 79 | ||
| 80 | typedef struct { | 80 | typedef struct { |
| 81 | void* overflowAddr; | 81 | void* overflowAddr; |
| 82 | - bool deterministic; | 82 | + uint8_t deterministicLevel; |
| 83 | NnopbaseUChar precision; | 83 | NnopbaseUChar precision; |
| 84 | bool enableArgsCache; | 84 | bool enableArgsCache; |
| 85 | bool enableTimeStamp; | 85 | bool enableTimeStamp; |
| @@ -70,9 +70,9 @@ static inline void DoubleListRemove(DoubleListNode* node, DList* list) | |||
| 70 | list->count--; | 70 | list->count--; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | -static inline int DoubleListIsEmpty(DList* list) { return list->node.next == &(list->node); } | 73 | +static inline int DoubleListIsEmpty(const DList* const list) { return list->node.next == &(list->node); } |
| 74 | 74 | ||
| 75 | -static inline unsigned int DoubleListCount(DList* list) { return list->count; } | 75 | +static inline unsigned int DoubleListCount(const DList* const list) { return list->count; } |
| 76 | 76 | ||
| 77 | #ifdef __cplusplus | 77 | #ifdef __cplusplus |
| 78 | } | 78 | } |
| @@ -19,7 +19,7 @@ class ThreadVarContainer { | |||
| 19 | public: | 19 | public: |
| 20 | static aclnnStatus SetCurMc2RankIdInThread(HcclComm commHandle); | 20 | static aclnnStatus SetCurMc2RankIdInThread(HcclComm commHandle); |
| 21 | static uint32_t GetCurMc2RankIdInThread(); | 21 | static uint32_t GetCurMc2RankIdInThread(); |
| 22 | - static void SetStaticKernelBasePathInThread(const std::string& staticKernelBasePath); | 22 | + static void SetStaticKernelBasePathInThread(const std::string& staticKernelBasePathValue); |
| 23 | static std::string GetStaticKernelBasePathInThread(); | 23 | static std::string GetStaticKernelBasePathInThread(); |
| 24 | }; | 24 | }; |
| 25 | } // namespace utils | 25 | } // namespace utils |
| @@ -261,7 +261,7 @@ aclError aclrtCacheLastTaskOpInfo(const void* const infoPtr, size_t infoSize) | |||
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | int64_t gDeterministicNew = 0; | 263 | int64_t gDeterministicNew = 0; |
| 264 | -int64_t gStrongConsistencyNew = 0; | 264 | +int64_t gStrongConsistency = 0; |
| 265 | 265 | ||
| 266 | EXTERN_C | 266 | EXTERN_C |
| 267 | aclError aclrtSetSysParamOpt(aclSysParamOpt opt, int64_t value) | 267 | aclError aclrtSetSysParamOpt(aclSysParamOpt opt, int64_t value) |
| @@ -269,7 +269,7 @@ aclError aclrtSetSysParamOpt(aclSysParamOpt opt, int64_t value) | |||
| 269 | if (opt == ACL_OPT_DETERMINISTIC) { | 269 | if (opt == ACL_OPT_DETERMINISTIC) { |
| 270 | gDeterministicNew = value; | 270 | gDeterministicNew = value; |
| 271 | } else if (opt == ACL_OPT_STRONG_CONSISTENCY) { | 271 | } else if (opt == ACL_OPT_STRONG_CONSISTENCY) { |
| 272 | - gStrongConsistencyNew = value; | 272 | + gStrongConsistency = value; |
| 273 | } | 273 | } |
| 274 | return ACL_SUCCESS; | 274 | return ACL_SUCCESS; |
| 275 | } | 275 | } |
| @@ -280,7 +280,7 @@ aclError aclrtGetSysParamOpt(aclSysParamOpt opt, int64_t* value) | |||
| 280 | if (opt == ACL_OPT_DETERMINISTIC) { | 280 | if (opt == ACL_OPT_DETERMINISTIC) { |
| 281 | *value = gDeterministicNew; | 281 | *value = gDeterministicNew; |
| 282 | } else if (opt == ACL_OPT_STRONG_CONSISTENCY) { | 282 | } else if (opt == ACL_OPT_STRONG_CONSISTENCY) { |
| 283 | - *value = gStrongConsistencyNew; | 283 | + *value = gStrongConsistency; |
| 284 | } | 284 | } |
| 285 | return ACL_SUCCESS; | 285 | return ACL_SUCCESS; |
| 286 | } | 286 | } |
| @@ -24,7 +24,16 @@ using namespace op; | |||
| 24 | using namespace std; | 24 | using namespace std; |
| 25 | using namespace op::internal; | 25 | using namespace op::internal; |
| 26 | 26 | ||
| 27 | -class OpExecutorTest : public testing::Test {}; | 27 | +class OpExecutorTest : public testing::Test { |
| 28 | +protected: | ||
| 29 | + void TearDown() override | ||
| 30 | + { | ||
| 31 | + aclrtSetSysParamOpt(ACL_OPT_DETERMINISTIC, 0); | ||
| 32 | + aclrtSetSysParamOpt(ACL_OPT_STRONG_CONSISTENCY, 0); | ||
| 33 | + op::internal::GetThreadLocalContext().opConfigInfo_.deterministicLevel_ = 0; | ||
| 34 | + op::internal::GetThreadLocalContext().opConfigInfo_.isDeterministicOn_ = false; | ||
| 35 | + } | ||
| 36 | +}; | ||
| 28 | 37 | ||
| 29 | TEST_F(OpExecutorTest, TestOpExecutor) | 38 | TEST_F(OpExecutorTest, TestOpExecutor) |
| 30 | { | 39 | { |
| @@ -899,4 +908,4 @@ TEST_F(OpExecutorTest, ConvertDoubleScalarOverflowToFloat4E2M1) | |||
| 899 | result.value = *data; | 908 | result.value = *data; |
| 900 | // OCP规范: FP4无Infinity, 溢出应钳制到最大值6.0 | 909 | // OCP规范: FP4无Infinity, 溢出应钳制到最大值6.0 |
| 901 | EXPECT_FLOAT_EQ(static_cast<float>(result), 6.0f); | 910 | EXPECT_FLOAT_EQ(static_cast<float>(result), 6.0f); |
| 902 | -} | 911 | +} |
| @@ -487,6 +487,8 @@ TEST_F(OpKernelUT, LaunchArgCacheTest) | |||
| 487 | } | 487 | } |
| 488 | } | 488 | } |
| 489 | op::DestroyOpArgContext(ctx2); | 489 | op::DestroyOpArgContext(ctx2); |
| 490 | + // 恢复全局开关,避免污染后续用例 | ||
| 491 | + opProfilingSwitch.recordOpArgFlag = false; | ||
| 490 | } | 492 | } |
| 491 | 493 | ||
| 492 | TEST_F(OpKernelUT, ReportOpAttrInfoTest) | 494 | TEST_F(OpKernelUT, ReportOpAttrInfoTest) |
| @@ -852,6 +854,8 @@ TEST_F(OpKernelUT, TestDoLaunchWithSplitAicAndAiv) | |||
| 852 | } | 854 | } |
| 853 | } | 855 | } |
| 854 | op::DestroyOpArgContext(ctx2); | 856 | op::DestroyOpArgContext(ctx2); |
| 857 | + // 恢复全局开关,避免污染后续用例 | ||
| 858 | + opProfilingSwitch.recordOpArgFlag = false; | ||
| 855 | } | 859 | } |
| 856 | 860 | ||
| 857 | TEST_F(OpKernelUT, NoKernelBinTest) | 861 | TEST_F(OpKernelUT, NoKernelBinTest) |
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | #include "gtest/gtest.h" | 11 | #include "gtest/gtest.h" |
| 12 | #include <array> | 12 | #include <array> |
| 13 | +#include <chrono> | ||
| 13 | #include <iostream> | 14 | #include <iostream> |
| 14 | #include <memory> | 15 | #include <memory> |
| 15 | #include <stdlib.h> | 16 | #include <stdlib.h> |
| @@ -98,8 +99,8 @@ static void TilingCtxBuildUTCase1() | |||
| 98 | 99 | ||
| 99 | const char* p = std::getenv("ASCEND_OPP_PATH"); | 100 | const char* p = std::getenv("ASCEND_OPP_PATH"); |
| 100 | EXPECT_NE(p, nullptr); | 101 | EXPECT_NE(p, nullptr); |
| 101 | - op::internal::KeyAndDetail key; | 102 | + op::internal::KeyAndDetail keyDetail; |
| 102 | - key.key = "hahaha"; | 103 | + keyDetail.key = "hahaha"; |
| 103 | size_t hashKey = 125; | 104 | size_t hashKey = 125; |
| 104 | char jsonPath[1024]; | 105 | char jsonPath[1024]; |
| 105 | char binPath[1024]; | 106 | char binPath[1024]; |
| @@ -112,7 +113,7 @@ static void TilingCtxBuildUTCase1() | |||
| 112 | "Axpy_233851a3505389e43928a8bba133a74d_high_performance.o", | 113 | "Axpy_233851a3505389e43928a8bba133a74d_high_performance.o", |
| 113 | p); | 114 | p); |
| 114 | 115 | ||
| 115 | - op::internal::OpKernelBin kernelBin(opType, jsonPath, jsonPath, binPath, key, hashKey, | 116 | + op::internal::OpKernelBin kernelBin(opType, jsonPath, jsonPath, binPath, keyDetail, hashKey, |
| 116 | op::internal::BinType::DYNAMIC_BIN, false, false); | 117 | op::internal::BinType::DYNAMIC_BIN, false, false); |
| 117 | EXPECT_EQ(kernelBin.InitTilingParseCtx(), ACLNN_SUCCESS); | 118 | EXPECT_EQ(kernelBin.InitTilingParseCtx(), ACLNN_SUCCESS); |
| 118 | 119 | ||
| @@ -365,57 +366,135 @@ static void SetCoreNumTestAiCore() | |||
| 365 | { | 366 | { |
| 366 | nlohmann::json mixAiCore = {{"coreType", "AiCore"}}; | 367 | nlohmann::json mixAiCore = {{"coreType", "AiCore"}}; |
| 367 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; | 368 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; |
| 369 | + auto& cfg = op::internal::GetThreadLocalContext().opConfigInfo_; | ||
| 370 | + // 保存主线程 thread_local 旧值,用例结束后恢复,避免污染后续主线程用例 | ||
| 371 | + uint32_t oldAic = cfg.aicNum_; | ||
| 372 | + uint32_t oldAiv = cfg.aivNum_; | ||
| 373 | + uint32_t oldPlatCoreNum = plat->GetCoreNum(); | ||
| 374 | + | ||
| 375 | + // 设置可控的 aic/aiv,按 SetCoreNum 分支语义独立推导期望值;随机值用 1 + 余数,避免 0 引入额外分支 | ||
| 376 | + auto tidVal = static_cast<uint32_t>(std::hash<std::thread::id>{}(std::this_thread::get_id())); | ||
| 377 | + uint32_t testAic = 1U + (tidVal % 19U); | ||
| 378 | + uint32_t testAiv = 1U + ((tidVal + 1U) % 19U); | ||
| 379 | + OP_LOGI("SetCoreNumTestAiCore testAic: %u, testAiv: %u", testAic, testAiv); | ||
| 380 | + cfg.aicNum_ = testAic; | ||
| 381 | + cfg.aivNum_ = testAiv; | ||
| 382 | + | ||
| 383 | + // coreType="AiCore" 走 SetCoreNum 的 else 分支:coreNum = cubeCoreNum = aicNum_ | ||
| 368 | uint32_t coreNum = 0; | 384 | uint32_t coreNum = 0; |
| 369 | op::internal::SetCoreNum(mixAiCore, plat, coreNum); | 385 | op::internal::SetCoreNum(mixAiCore, plat, coreNum); |
| 370 | - sleep(1); | 386 | + EXPECT_EQ(coreNum, testAic); |
| 371 | - uint32_t currCoreNum = plat->GetCoreNum(); | 387 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 372 | - EXPECT_EQ(currCoreNum, 0); | 388 | + EXPECT_EQ(plat->GetCoreNum(), testAic); |
| 389 | + | ||
| 390 | + cfg.aicNum_ = oldAic; | ||
| 391 | + cfg.aivNum_ = oldAiv; | ||
| 392 | + plat->SetCoreNum(oldPlatCoreNum); | ||
| 373 | } | 393 | } |
| 374 | 394 | ||
| 375 | static void SetCoreNumTestMIX() | 395 | static void SetCoreNumTestMIX() |
| 376 | { | 396 | { |
| 377 | nlohmann::json mixMIX = {{"coreType", "MIX"}}; | 397 | nlohmann::json mixMIX = {{"coreType", "MIX"}}; |
| 378 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; | 398 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; |
| 399 | + auto& cfg = op::internal::GetThreadLocalContext().opConfigInfo_; | ||
| 400 | + uint32_t oldAic = cfg.aicNum_; | ||
| 401 | + uint32_t oldAiv = cfg.aivNum_; | ||
| 402 | + uint32_t oldPlatCoreNum = plat->GetCoreNum(); | ||
| 403 | + | ||
| 404 | + auto tidVal = static_cast<uint32_t>(std::hash<std::thread::id>{}(std::this_thread::get_id())); | ||
| 405 | + uint32_t testAic = 1U + (tidVal % 19U); | ||
| 406 | + uint32_t testAiv = 1U + ((tidVal + 1U) % 19U); | ||
| 407 | + OP_LOGI("SetCoreNumTestMIX testAic: %u, testAiv: %u", testAic, testAiv); | ||
| 408 | + cfg.aicNum_ = testAic; | ||
| 409 | + cfg.aivNum_ = testAiv; | ||
| 410 | + | ||
| 411 | + // coreType="MIX" 且 json 无 taskRation:CalcMixCoreNum 返回 vectorCoreNum = aivNum_ | ||
| 379 | uint32_t coreNum = 0; | 412 | uint32_t coreNum = 0; |
| 380 | op::internal::SetCoreNum(mixMIX, plat, coreNum); | 413 | op::internal::SetCoreNum(mixMIX, plat, coreNum); |
| 381 | - sleep(1); | 414 | + EXPECT_EQ(coreNum, testAiv); |
| 382 | - uint32_t currCoreNum = plat->GetCoreNum(); | 415 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 383 | - EXPECT_EQ(currCoreNum, 0); | 416 | + EXPECT_EQ(plat->GetCoreNum(), testAiv); |
| 417 | + | ||
| 418 | + cfg.aicNum_ = oldAic; | ||
| 419 | + cfg.aivNum_ = oldAiv; | ||
| 420 | + plat->SetCoreNum(oldPlatCoreNum); | ||
| 384 | } | 421 | } |
| 385 | 422 | ||
| 386 | static void SetCoreNumTestVectorCore() | 423 | static void SetCoreNumTestVectorCore() |
| 387 | { | 424 | { |
| 388 | nlohmann::json mixVector = {{"coreType", "VectorCore"}}; | 425 | nlohmann::json mixVector = {{"coreType", "VectorCore"}}; |
| 389 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; | 426 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; |
| 427 | + auto& cfg = op::internal::GetThreadLocalContext().opConfigInfo_; | ||
| 428 | + uint32_t oldAic = cfg.aicNum_; | ||
| 429 | + uint32_t oldAiv = cfg.aivNum_; | ||
| 430 | + uint32_t oldPlatCoreNum = plat->GetCoreNum(); | ||
| 431 | + | ||
| 432 | + auto tidVal = static_cast<uint32_t>(std::hash<std::thread::id>{}(std::this_thread::get_id())); | ||
| 433 | + uint32_t testAic = 1U + (tidVal % 19U); | ||
| 434 | + uint32_t testAiv = 1U + ((tidVal + 1U) % 19U); | ||
| 435 | + OP_LOGI("SetCoreNumTestVectorCore testAic: %u, testAiv: %u", testAic, testAiv); | ||
| 436 | + cfg.aicNum_ = testAic; | ||
| 437 | + cfg.aivNum_ = testAiv; | ||
| 438 | + | ||
| 439 | + // coreType="VectorCore":coreNum = vectorCoreNum = aivNum_ | ||
| 390 | uint32_t coreNum = 0; | 440 | uint32_t coreNum = 0; |
| 391 | op::internal::SetCoreNum(mixVector, plat, coreNum); | 441 | op::internal::SetCoreNum(mixVector, plat, coreNum); |
| 392 | - sleep(1); | 442 | + EXPECT_EQ(coreNum, testAiv); |
| 393 | - uint32_t currCoreNum = plat->GetCoreNum(); | 443 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 394 | - EXPECT_EQ(currCoreNum, 0); | 444 | + EXPECT_EQ(plat->GetCoreNum(), testAiv); |
| 445 | + | ||
| 446 | + cfg.aicNum_ = oldAic; | ||
| 447 | + cfg.aivNum_ = oldAiv; | ||
| 448 | + plat->SetCoreNum(oldPlatCoreNum); | ||
| 395 | } | 449 | } |
| 396 | 450 | ||
| 397 | static void SetCoreNumTestAIV() | 451 | static void SetCoreNumTestAIV() |
| 398 | { | 452 | { |
| 399 | nlohmann::json mixAIV = {{"coreType", "MIX_AIV"}}; | 453 | nlohmann::json mixAIV = {{"coreType", "MIX_AIV"}}; |
| 400 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; | 454 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; |
| 455 | + auto& cfg = op::internal::GetThreadLocalContext().opConfigInfo_; | ||
| 456 | + uint32_t oldAic = cfg.aicNum_; | ||
| 457 | + uint32_t oldAiv = cfg.aivNum_; | ||
| 458 | + uint32_t oldPlatCoreNum = plat->GetCoreNum(); | ||
| 459 | + | ||
| 460 | + auto tidVal = static_cast<uint32_t>(std::hash<std::thread::id>{}(std::this_thread::get_id())); | ||
| 461 | + uint32_t testAic = 1U + (tidVal % 19U); | ||
| 462 | + uint32_t testAiv = 1U + ((tidVal + 1U) % 19U); | ||
| 463 | + OP_LOGI("SetCoreNumTestAIV testAic: %u, testAiv: %u", testAic, testAiv); | ||
| 464 | + cfg.aicNum_ = testAic; | ||
| 465 | + cfg.aivNum_ = testAiv; | ||
| 466 | + | ||
| 467 | + // 主线程 npuArch 已首次定型为 DAV_RESV(!= DAV_2002),coreType="MIX_AIV" 走 else 分支:coreNum = aicNum_ | ||
| 401 | uint32_t coreNum = 0; | 468 | uint32_t coreNum = 0; |
| 402 | op::internal::SetCoreNum(mixAIV, plat, coreNum); | 469 | op::internal::SetCoreNum(mixAIV, plat, coreNum); |
| 403 | - sleep(1); | 470 | + EXPECT_EQ(coreNum, testAic); |
| 404 | - uint32_t currCoreNum = plat->GetCoreNum(); | 471 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 405 | - EXPECT_EQ(currCoreNum, 0); | 472 | + EXPECT_EQ(plat->GetCoreNum(), testAic); |
| 473 | + | ||
| 474 | + cfg.aicNum_ = oldAic; | ||
| 475 | + cfg.aivNum_ = oldAiv; | ||
| 476 | + plat->SetCoreNum(oldPlatCoreNum); | ||
| 406 | } | 477 | } |
| 407 | 478 | ||
| 408 | -static void SetCoreNumTest310PMIXAIV() | 479 | +// 310P 场景的纯线程内逻辑:假定调用线程的 npuArch 已由调用方保证为 DAV_2002 |
| 480 | +static void SetCoreNumTest310PMIXAIVImpl() | ||
| 409 | { | 481 | { |
| 410 | nlohmann::json mixAIV = {{"coreType", "MIX_AIV"}}; | 482 | nlohmann::json mixAIV = {{"coreType", "MIX_AIV"}}; |
| 411 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; | 483 | fe::PlatFormInfos* plat = &op::internal::SocContext::platformInfo_; |
| 412 | - PlatformInfoStub::GetInstance()->SetSoCVersion("Ascend310P", "Ascend310P3"); | 484 | + auto& cfg = op::internal::GetThreadLocalContext().opConfigInfo_; |
| 485 | + auto tidVal = static_cast<uint32_t>(std::hash<std::thread::id>{}(std::this_thread::get_id())); | ||
| 486 | + uint32_t testAic = 1U + (tidVal % 19U); | ||
| 487 | + uint32_t testAiv = 1U + ((tidVal + 1U) % 19U); | ||
| 488 | + OP_LOGI("SetCoreNumTest310PMIXAIV testAic: %u, testAiv: %u", testAic, testAiv); | ||
| 489 | + cfg.aicNum_ = testAic; | ||
| 490 | + cfg.aivNum_ = testAiv; | ||
| 491 | + | ||
| 492 | + // DAV_2002 + MIX_AIV 分支:coreNum = vectorCoreNum + cubeCoreNum = aivNum_ + aicNum_ | ||
| 413 | uint32_t coreNum = 0; | 493 | uint32_t coreNum = 0; |
| 414 | op::internal::SetCoreNum(mixAIV, plat, coreNum); | 494 | op::internal::SetCoreNum(mixAIV, plat, coreNum); |
| 415 | - sleep(1); | 495 | + EXPECT_EQ(coreNum, testAic + testAiv); |
| 416 | - uint32_t currCoreNum = plat->GetCoreNum(); | 496 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 417 | - EXPECT_EQ(currCoreNum, 0); | 497 | + EXPECT_EQ(plat->GetCoreNum(), testAic + testAiv); |
| 418 | - PlatformInfoStub::GetInstance()->Reset(); | ||
| 419 | } | 498 | } |
| 420 | 499 | ||
| 421 | TEST_F(TilingCtxBuildUT, TilingCtxBuildUT_AttrTypes) | 500 | TEST_F(TilingCtxBuildUT, TilingCtxBuildUT_AttrTypes) |
| @@ -481,12 +560,31 @@ TEST_F(TilingCtxBuildUT, TilingCtxBuildUT_AttrTypes) | |||
| 481 | op::DestroyOpArgContext(ctx); | 560 | op::DestroyOpArgContext(ctx); |
| 482 | } | 561 | } |
| 483 | 562 | ||
| 563 | +TEST_F(TilingCtxBuildUT, TilingCtxBuildUTCase1) { TilingCtxBuildUTCase1(); } | ||
| 564 | +TEST_F(TilingCtxBuildUT, TilingCtxBuildUTCase2) { TilingCtxBuildUTCase2(); } | ||
| 565 | +TEST_F(TilingCtxBuildUT, TilingCtxBuildUTCase3) { TilingCtxBuildUTCase3(); } | ||
| 566 | +TEST_F(TilingCtxBuildUT, GetTilingResFromCacheCase) { GetTilingResFromCacheCase(); } | ||
| 567 | +TEST_F(TilingCtxBuildUT, TilingParseCtxHolderFreeTest) { TilingParseCtxHolderFreeTest(); } | ||
| 568 | +TEST_F(TilingCtxBuildUT, SetCoreNumTestAiCore) { SetCoreNumTestAiCore(); } | ||
| 569 | +TEST_F(TilingCtxBuildUT, SetCoreNumTestMIX) { SetCoreNumTestMIX(); } | ||
| 570 | +TEST_F(TilingCtxBuildUT, SetCoreNumTestVectorCore) { SetCoreNumTestVectorCore(); } | ||
| 571 | +TEST_F(TilingCtxBuildUT, SetCoreNumTestAIV) { SetCoreNumTestAIV(); } | ||
| 572 | +TEST_F(TilingCtxBuildUT, SetCoreNumTest310PMIXAIV) | ||
| 573 | +{ | ||
| 574 | + // 主线程 npuArch 已首次定型为 DAV_RESV,必须新起线程让其首次定型时读到 ASCEND_NPU_ARCH=2002 | ||
| 575 | + setenv("ASCEND_NPU_ARCH", "2002", 1); | ||
| 576 | + std::thread t(&SetCoreNumTest310PMIXAIVImpl); | ||
| 577 | + t.join(); | ||
| 578 | + // 环境变量是进程级,必须清理,避免污染后续新线程的 npuArch 定型 | ||
| 579 | + unsetenv("ASCEND_NPU_ARCH"); | ||
| 580 | +} | ||
| 581 | + | ||
| 484 | TEST_F(TilingCtxBuildUT, TilingCtxMultiThreadTest) | 582 | TEST_F(TilingCtxBuildUT, TilingCtxMultiThreadTest) |
| 485 | { | 583 | { |
| 584 | + // 移除 SetCoreNumTest310PMIXAIV:该用例依赖 setenv 控制环境变量,不适合作为多线程并发对象 | ||
| 486 | vector<Functional> funVec = {TilingCtxBuildUTCase1, TilingCtxBuildUTCase2, TilingCtxBuildUTCase3, | 585 | vector<Functional> funVec = {TilingCtxBuildUTCase1, TilingCtxBuildUTCase2, TilingCtxBuildUTCase3, |
| 487 | GetTilingResFromCacheCase, TilingParseCtxHolderFreeTest, SetCoreNumTestAiCore, | 586 | GetTilingResFromCacheCase, TilingParseCtxHolderFreeTest, SetCoreNumTestAiCore, |
| 488 | - SetCoreNumTestMIX, SetCoreNumTestVectorCore, SetCoreNumTestAIV, | 587 | + SetCoreNumTestMIX, SetCoreNumTestVectorCore, SetCoreNumTestAIV}; |
| 489 | - SetCoreNumTest310PMIXAIV}; | ||
| 490 | std::random_device rd; | 588 | std::random_device rd; |
| 491 | std::mt19937 gen(rd()); | 589 | std::mt19937 gen(rd()); |
| 492 | std::uniform_int_distribution<> distrib(0, funVec.size() - 1); | 590 | std::uniform_int_distribution<> distrib(0, funVec.size() - 1); |
| @@ -500,6 +598,22 @@ TEST_F(TilingCtxBuildUT, TilingCtxMultiThreadTest) | |||
| 500 | } | 598 | } |
| 501 | } | 599 | } |
| 502 | 600 | ||
| 601 | +TEST_F(TilingCtxBuildUT, SetCoreNumTest310PMIXAIVMultiThread) | ||
| 602 | +{ | ||
| 603 | + // 主线程派生工作线程前设置环境变量,所有工作线程首次 GetCurrentPlatformInfo 时定型为 DAV_2002 | ||
| 604 | + setenv("ASCEND_NPU_ARCH", "2002", 1); | ||
| 605 | + constexpr uint64_t threadCount = 100; | ||
| 606 | + vector<std::thread> threadVec; | ||
| 607 | + for (uint64_t i = 0; i < threadCount; i++) { | ||
| 608 | + threadVec.emplace_back(std::thread(&SetCoreNumTest310PMIXAIVImpl)); | ||
| 609 | + } | ||
| 610 | + for (uint64_t i = 0; i < threadCount; i++) { | ||
| 611 | + threadVec[i].join(); | ||
| 612 | + } | ||
| 613 | + // 全部 join 后清理,避免污染后续新线程的 npuArch 定型 | ||
| 614 | + unsetenv("ASCEND_NPU_ARCH"); | ||
| 615 | +} | ||
| 616 | + | ||
| 503 | static void TilingCtxBuildLaunchOneThread(op::internal::OpKernelBin* opKernelBin, pthread_barrier_t* barrier) | 617 | static void TilingCtxBuildLaunchOneThread(op::internal::OpKernelBin* opKernelBin, pthread_barrier_t* barrier) |
| 504 | { | 618 | { |
| 505 | if (barrier) { | 619 | if (barrier) { |
| @@ -578,11 +692,11 @@ TEST_F(TilingCtxBuildUT, TilingCtxMultiThreadTest2) | |||
| 578 | std::cout << "pthread_barrier_init failed, error code: " << ret << std::endl; | 692 | std::cout << "pthread_barrier_init failed, error code: " << ret << std::endl; |
| 579 | } | 693 | } |
| 580 | vector<std::thread> threadVec; | 694 | vector<std::thread> threadVec; |
| 581 | - for (int i = 0; i < BARRIER_THREAD_COUNT; i++) { | 695 | + for (int j = 0; j < BARRIER_THREAD_COUNT; j++) { |
| 582 | threadVec.emplace_back(std::thread(TilingCtxBuildLaunchOneThread, fakeBin, &barrier)); | 696 | threadVec.emplace_back(std::thread(TilingCtxBuildLaunchOneThread, fakeBin, &barrier)); |
| 583 | } | 697 | } |
| 584 | - for (int i = 0; i < BARRIER_THREAD_COUNT; i++) { | 698 | + for (int k = 0; k < BARRIER_THREAD_COUNT; k++) { |
| 585 | - threadVec[i].join(); | 699 | + threadVec[k].join(); |
| 586 | } | 700 | } |
| 587 | ret = pthread_barrier_destroy(&barrier); // 销毁屏障 | 701 | ret = pthread_barrier_destroy(&barrier); // 销毁屏障 |
| 588 | if (ret != 0) { | 702 | if (ret != 0) { |
| @@ -47,6 +47,19 @@ void SetSocVersion(const std::string& version) | |||
| 47 | soc.socVersion = version; | 47 | soc.socVersion = version; |
| 48 | soc.isInit = true; | 48 | soc.isInit = true; |
| 49 | } | 49 | } |
| 50 | + | ||
| 51 | +const NnopbaseHcclCommParamDesc* GetMc2ParamDesc(const NnopbaseExecutor* const executor) | ||
| 52 | +{ | ||
| 53 | + if (nnopbase::IndvSoc::GetInstance().NnopbaseEnableCcuLaunch(executor->mc2.serverType)) { | ||
| 54 | + if (executor->mc2.fusionArgs.args == nullptr) { | ||
| 55 | + return nullptr; | ||
| 56 | + } | ||
| 57 | + const size_t kfcArgsFmtOffset = executor->mc2.fusionArgs.aicpuArgs[0].kfcArgsFmtOffset * sizeof(void*); | ||
| 58 | + return reinterpret_cast<const NnopbaseHcclCommParamDesc*>( | ||
| 59 | + static_cast<const NnopbaseUChar*>(executor->mc2.fusionArgs.args) + kfcArgsFmtOffset); | ||
| 60 | + } | ||
| 61 | + return reinterpret_cast<const NnopbaseHcclCommParamDesc*>(executor->mc2.aicpuArgs.args); | ||
| 62 | +} | ||
| 50 | } // namespace | 63 | } // namespace |
| 51 | 64 | ||
| 52 | class NnopbaseExtUnitTest : public testing::Test { | 65 | class NnopbaseExtUnitTest : public testing::Test { |
| @@ -932,7 +945,7 @@ TEST_F(NnopbaseExtUnitTest, NnopBaseMc2SetSuccess) | |||
| 932 | ASSERT_EQ(NnopbaseSetHcomGroup(executor, group), ACLNN_ERR_PARAM_INVALID); | 945 | ASSERT_EQ(NnopbaseSetHcomGroup(executor, group), ACLNN_ERR_PARAM_INVALID); |
| 933 | 946 | ||
| 934 | ASSERT_EQ(NnopbaseSetMc2(executor), OK); | 947 | ASSERT_EQ(NnopbaseSetMc2(executor), OK); |
| 935 | - ASSERT_EQ(((NnopbaseExecutor*)executor)->mc2OpCfg.isMc2, true); | 948 | + ASSERT_EQ(((NnopbaseExecutor*)executor)->mc2.enabled, true); |
| 936 | 949 | ||
| 937 | ASSERT_EQ(NnopbaseSetHcomGroup(nullptr, group), ACLNN_ERR_PARAM_NULLPTR); | 950 | ASSERT_EQ(NnopbaseSetHcomGroup(nullptr, group), ACLNN_ERR_PARAM_NULLPTR); |
| 938 | ASSERT_EQ(NnopbaseSetHcomGroup(executor, nullptr), OK); | 951 | ASSERT_EQ(NnopbaseSetHcomGroup(executor, nullptr), OK); |
| @@ -2455,9 +2468,8 @@ TEST_F(NnopbaseExtUnitTest, NnopBaseMC2RunSuccessForDavidWithHostInput) | |||
| 2455 | // SOC version will be restored by SocVersionGuard destructor | 2468 | // SOC version will be restored by SocVersionGuard destructor |
| 2456 | ((NnopbaseExecutor*)executor)->collector->isMc2FusionLaunch = oriMc2FusionLaunchFlag; | 2469 | ((NnopbaseExecutor*)executor)->collector->isMc2FusionLaunch = oriMc2FusionLaunchFlag; |
| 2457 | 2470 | ||
| 2458 | - // END类型默认走A5 AICPU路径,hcclDesc写在aicpuArgs.args起始处(见NnopbaseCopyMC2ParamDesc) | 2471 | + const auto* desc = GetMc2ParamDesc(static_cast<NnopbaseExecutor*>(executor)); |
| 2459 | - NnopbaseHcclCommParamDesc* desc = reinterpret_cast<NnopbaseHcclCommParamDesc*>( | 2472 | + ASSERT_NE(desc, nullptr); |
| 2460 | - ((NnopbaseExecutor*)executor)->aicpuArgs.args); | ||
| 2461 | ASSERT_EQ(desc->groupNum, 1U); | 2473 | ASSERT_EQ(desc->groupNum, 1U); |
| 2462 | ASSERT_EQ(desc->version, 1U); | 2474 | ASSERT_EQ(desc->version, 1U); |
| 2463 | ASSERT_EQ(desc->hasFfts, 0U); | 2475 | ASSERT_EQ(desc->hasFfts, 0U); |
| @@ -2560,9 +2572,8 @@ TEST_F(NnopbaseExtUnitTest, NnopBaseMC2RunSuccessForDavidWithDynamicInput) | |||
| 2560 | // SOC version will be restored by SocVersionGuard destructor | 2572 | // SOC version will be restored by SocVersionGuard destructor |
| 2561 | ((NnopbaseExecutor*)executor)->collector->isMc2FusionLaunch = oriMc2FusionLaunchFlag; | 2573 | ((NnopbaseExecutor*)executor)->collector->isMc2FusionLaunch = oriMc2FusionLaunchFlag; |
| 2562 | 2574 | ||
| 2563 | - // END类型默认走A5 AICPU路径,hcclDesc写在aicpuArgs.args起始处(见NnopbaseCopyMC2ParamDesc) | 2575 | + const auto* desc = GetMc2ParamDesc(static_cast<NnopbaseExecutor*>(executor)); |
| 2564 | - NnopbaseHcclCommParamDesc* desc = reinterpret_cast<NnopbaseHcclCommParamDesc*>( | 2576 | + ASSERT_NE(desc, nullptr); |
| 2565 | - ((NnopbaseExecutor*)executor)->aicpuArgs.args); | ||
| 2566 | ASSERT_EQ(desc->groupNum, 1U); | 2577 | ASSERT_EQ(desc->groupNum, 1U); |
| 2567 | ASSERT_EQ(desc->version, 1U); | 2578 | ASSERT_EQ(desc->version, 1U); |
| 2568 | ASSERT_EQ(desc->hasFfts, 0U); | 2579 | ASSERT_EQ(desc->hasFfts, 0U); |
| @@ -2884,7 +2884,7 @@ TEST_F(NnopbaseUnitTest, NnopbaseSetMc2SuccessWithAiCPU) | |||
| 2884 | ASSERT_NE(executor, nullptr); | 2884 | ASSERT_NE(executor, nullptr); |
| 2885 | 2885 | ||
| 2886 | NnopbaseSetHcclServerType(executor, NNOPBASE_HCCL_SERVER_TYPE_AICPU); | 2886 | NnopbaseSetHcclServerType(executor, NNOPBASE_HCCL_SERVER_TYPE_AICPU); |
| 2887 | - ASSERT_EQ(((NnopbaseExecutor*)executor)->mc2OpCfg.sType, NNOPBASE_HCCL_SERVER_TYPE_AICPU); | 2887 | + ASSERT_EQ(((NnopbaseExecutor*)executor)->mc2.serverType, NNOPBASE_HCCL_SERVER_TYPE_AICPU); |
| 2888 | ASSERT_EQ(NnopbaseSetMc2(executor), OK); | 2888 | ASSERT_EQ(NnopbaseSetMc2(executor), OK); |
| 2889 | NnopbaseExecutorGcSpace(executorSpace); | 2889 | NnopbaseExecutorGcSpace(executorSpace); |
| 2890 | NnopbaseUnsetEnvAndClearFolder(); | 2890 | NnopbaseUnsetEnvAndClearFolder(); |
| @@ -2914,7 +2914,7 @@ TEST_F(NnopbaseUnitTest, NnopbaseSetMc2SuccessForascend950WithAiCPU) | |||
| 2914 | } socGuard{oriSocVersion}; | 2914 | } socGuard{oriSocVersion}; |
| 2915 | SetSocVersion(nnopbase::OPS_SUBPATH_ASCEND950); | 2915 | SetSocVersion(nnopbase::OPS_SUBPATH_ASCEND950); |
| 2916 | ASSERT_EQ(nnopbase::IndvSoc::GetInstance().GetCurSocVersion(), nnopbase::OPS_SUBPATH_ASCEND950); | 2916 | ASSERT_EQ(nnopbase::IndvSoc::GetInstance().GetCurSocVersion(), nnopbase::OPS_SUBPATH_ASCEND950); |
| 2917 | - ASSERT_EQ(((NnopbaseExecutor*)executor)->mc2OpCfg.sType, NNOPBASE_HCCL_SERVER_TYPE_AICPU); | 2917 | + ASSERT_EQ(((NnopbaseExecutor*)executor)->mc2.serverType, NNOPBASE_HCCL_SERVER_TYPE_AICPU); |
| 2918 | ASSERT_EQ(NnopbaseSetMc2(executor), OK); | 2918 | ASSERT_EQ(NnopbaseSetMc2(executor), OK); |
| 2919 | 2919 | ||
| 2920 | // SOC version will be restored by SocVersionGuard destructor | 2920 | // SOC version will be restored by SocVersionGuard destructor |
| @@ -513,6 +513,20 @@ TEST_F(NnopbaseCacheKeyUnitTest, NnopbaseV2CacheKeyNullTensor) | |||
| 513 | NnopbaseUnsetEnvAndClearFolder(); | 513 | NnopbaseUnsetEnvAndClearFolder(); |
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | +TEST_F(NnopbaseCacheKeyUnitTest, NnopbaseV2CacheKeyAppendsRawDeterministicLevel) | ||
| 517 | +{ | ||
| 518 | + NnopbaseExecutorArgs args; | ||
| 519 | + args.keyLen = 0U; | ||
| 520 | + args.remainKeyLen = 1U; | ||
| 521 | + const uint8_t deterministicLevel = 2U; | ||
| 522 | + | ||
| 523 | + (void)Indv::CacheKeyBuilder::AppendDeterministicLevel(&args, &deterministicLevel); | ||
| 524 | + | ||
| 525 | + ASSERT_EQ(args.keyLen, sizeof(uint8_t) + 1U); | ||
| 526 | + ASSERT_EQ(args.inputKey[0], kSeparator); | ||
| 527 | + ASSERT_EQ(args.inputKey[1], deterministicLevel); | ||
| 528 | +} | ||
| 529 | + | ||
| 516 | // ===== V2 path: IntArray input is value-dependent; raw bytes are appended ===== | 530 | // ===== V2 path: IntArray input is value-dependent; raw bytes are appended ===== |
| 517 | TEST_F(NnopbaseCacheKeyUnitTest, NnopbaseV2CacheKeyIntArray) | 531 | TEST_F(NnopbaseCacheKeyUnitTest, NnopbaseV2CacheKeyIntArray) |
| 518 | { | 532 | { |
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "executor/indv_executor.h" | 13 | #include "executor/indv_executor.h" |
| 14 | #include "executor/indv_bininfo.h" | 14 | #include "executor/indv_bininfo.h" |
| 15 | #include <gtest/gtest.h> | 15 | #include <gtest/gtest.h> |
| 16 | +#include <memory> | ||
| 16 | #include <string.h> | 17 | #include <string.h> |
| 17 | #include <sys/stat.h> | 18 | #include <sys/stat.h> |
| 18 | #include <sys/types.h> | 19 | #include <sys/types.h> |
| @@ -70,6 +71,43 @@ TEST_F(NnopbaseCollectorUnitTest, test_thread_static_kernel_base_path) | |||
| 70 | ASSERT_EQ(nnopbase::utils::ThreadVarContainer::GetStaticKernelBasePathInThread(), ""); | 71 | ASSERT_EQ(nnopbase::utils::ThreadVarContainer::GetStaticKernelBasePathInThread(), ""); |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 74 | +TEST_F(NnopbaseCollectorUnitTest, StaticKernelMatchChecksDeterministicLevelAfterSameKey) | ||
| 75 | +{ | ||
| 76 | + NnopbaseRegInfo regInfo; | ||
| 77 | + regInfo.key.opType = "StaticDeterministicTest"; | ||
| 78 | + NnopbaseCollectorInitBinTbl(®Info.binTbl); | ||
| 79 | + | ||
| 80 | + const NnopbaseUChar verbose[] = {'s', 'a', 'm', 'e', '_', 's', 'i', 'm', 'p', 'l', 'i', 'f', 'i', 'e', 'd'}; | ||
| 81 | + const uint32_t verboseLen = sizeof(verbose); | ||
| 82 | + | ||
| 83 | + NnopbaseBinInfo binLevel1; | ||
| 84 | + NnopbaseBinInfoInit(&binLevel1); | ||
| 85 | + ASSERT_EQ(NnopbaseBinInfoSetOpBinInfoKey(&binLevel1, verbose, verboseLen), OK); | ||
| 86 | + binLevel1.extraKernelDesc = std::make_shared<ExtraKernelDesc>(); | ||
| 87 | + binLevel1.extraKernelDesc->platformInfo = std::make_unique<StaticKernelPlatformInfo>(); | ||
| 88 | + binLevel1.extraKernelDesc->platformInfo->coreNum = {24U, 48U}; | ||
| 89 | + binLevel1.extraKernelDesc->platformInfo->deterministicLevel = 1; | ||
| 90 | + | ||
| 91 | + NnopbaseBinInfo binLevel2; | ||
| 92 | + NnopbaseBinInfoInit(&binLevel2); | ||
| 93 | + ASSERT_EQ(NnopbaseBinInfoSetOpBinInfoKey(&binLevel2, verbose, verboseLen), OK); | ||
| 94 | + binLevel2.extraKernelDesc = std::make_shared<ExtraKernelDesc>(); | ||
| 95 | + binLevel2.extraKernelDesc->platformInfo = std::make_unique<StaticKernelPlatformInfo>(); | ||
| 96 | + binLevel2.extraKernelDesc->platformInfo->coreNum = {24U, 48U}; | ||
| 97 | + binLevel2.extraKernelDesc->platformInfo->deterministicLevel = 2; // 2表示强一致性 | ||
| 98 | + | ||
| 99 | + NnopbaseCollectorInsertBinInfo(®Info, &binLevel1); | ||
| 100 | + NnopbaseCollectorInsertBinInfo(®Info, &binLevel2); | ||
| 101 | + | ||
| 102 | + StaticKernelPlatformInfo runtimeLevel2{{24U, 48U}, 2}; | ||
| 103 | + EXPECT_EQ(NnopbaseCollectorFindBinInfo(®Info, binLevel1.binInfoKey.hashKey, verbose, verboseLen, &runtimeLevel2), | ||
| 104 | + &binLevel2); | ||
| 105 | + | ||
| 106 | + StaticKernelPlatformInfo runtimeLevel3{{24U, 48U}, 3}; | ||
| 107 | + EXPECT_EQ(NnopbaseCollectorFindBinInfo(®Info, binLevel1.binInfoKey.hashKey, verbose, verboseLen, &runtimeLevel3), | ||
| 108 | + nullptr); | ||
| 109 | +} | ||
| 110 | + | ||
| 73 | TEST_F(NnopbaseCollectorUnitTest, test_get_soc_version_ok) | 111 | TEST_F(NnopbaseCollectorUnitTest, test_get_soc_version_ok) |
| 74 | { | 112 | { |
| 75 | NnopbaseBinCollector* bin_collector = new NnopbaseBinCollector; | 113 | NnopbaseBinCollector* bin_collector = new NnopbaseBinCollector; |
| @@ -996,22 +996,34 @@ TEST_F(NnopbaseExecutorUnitTest, ExecutorSetOverflowAddrUndef) | |||
| 996 | TEST_F(NnopbaseExecutorUnitTest, ExecutorSetDeterministicClose) | 996 | TEST_F(NnopbaseExecutorUnitTest, ExecutorSetDeterministicClose) |
| 997 | { | 997 | { |
| 998 | const int64_t configVal = 0; | 998 | const int64_t configVal = 0; |
| 999 | - aclrtCtxSetSysParamOpt(ACL_OPT_DETERMINISTIC, configVal); | 999 | + aclrtSetSysParamOpt(ACL_OPT_DETERMINISTIC, configVal); |
| 1000 | NnopbaseExecutorSetGlobalConfig(); | 1000 | NnopbaseExecutorSetGlobalConfig(); |
| 1001 | - ASSERT_EQ(g_nnopbaseSysCfgParams.deterministic, false); | 1001 | + ASSERT_EQ(g_nnopbaseSysCfgParams.deterministicLevel, 0U); |
| 1002 | } | 1002 | } |
| 1003 | 1003 | ||
| 1004 | TEST_F(NnopbaseExecutorUnitTest, ExecutorSetDeterministicOpen) | 1004 | TEST_F(NnopbaseExecutorUnitTest, ExecutorSetDeterministicOpen) |
| 1005 | { | 1005 | { |
| 1006 | int64_t configVal = 1; | 1006 | int64_t configVal = 1; |
| 1007 | - aclrtCtxSetSysParamOpt(ACL_OPT_DETERMINISTIC, configVal); | 1007 | + aclrtSetSysParamOpt(ACL_OPT_DETERMINISTIC, configVal); |
| 1008 | + aclrtSetSysParamOpt(ACL_OPT_STRONG_CONSISTENCY, 0); | ||
| 1008 | NnopbaseExecutorSetGlobalConfig(); | 1009 | NnopbaseExecutorSetGlobalConfig(); |
| 1009 | - ASSERT_EQ(g_nnopbaseSysCfgParams.deterministic, true); | 1010 | + ASSERT_EQ(g_nnopbaseSysCfgParams.deterministicLevel, 1U); |
| 1010 | 1011 | ||
| 1011 | configVal = 0; | 1012 | configVal = 0; |
| 1012 | - aclrtCtxSetSysParamOpt(ACL_OPT_DETERMINISTIC, configVal); | 1013 | + aclrtSetSysParamOpt(ACL_OPT_DETERMINISTIC, configVal); |
| 1013 | NnopbaseExecutorSetGlobalConfig(); | 1014 | NnopbaseExecutorSetGlobalConfig(); |
| 1014 | - ASSERT_EQ(g_nnopbaseSysCfgParams.deterministic, false); | 1015 | + ASSERT_EQ(g_nnopbaseSysCfgParams.deterministicLevel, 0U); |
| 1016 | +} | ||
| 1017 | + | ||
| 1018 | +TEST_F(NnopbaseExecutorUnitTest, ExecutorSetDeterministicStrongConsistency) | ||
| 1019 | +{ | ||
| 1020 | + aclrtSetSysParamOpt(ACL_OPT_DETERMINISTIC, 1); | ||
| 1021 | + aclrtSetSysParamOpt(ACL_OPT_STRONG_CONSISTENCY, 1); | ||
| 1022 | + NnopbaseExecutorSetGlobalConfig(); | ||
| 1023 | + ASSERT_EQ(g_nnopbaseSysCfgParams.deterministicLevel, 2U); | ||
| 1024 | + | ||
| 1025 | + aclrtSetSysParamOpt(ACL_OPT_STRONG_CONSISTENCY, 0); | ||
| 1026 | + aclrtSetSysParamOpt(ACL_OPT_DETERMINISTIC, 0); | ||
| 1015 | } | 1027 | } |
| 1016 | 1028 | ||
| 1017 | TEST_F(NnopbaseExecutorUnitTest, ExecutorSetImplMode) | 1029 | TEST_F(NnopbaseExecutorUnitTest, ExecutorSetImplMode) |
| @@ -1185,14 +1197,15 @@ TEST_F(NnopbaseExecutorUnitTest, TestExecutorInit) | |||
| 1185 | GetExecutor(executor); | 1197 | GetExecutor(executor); |
| 1186 | ASSERT_NE(executor, nullptr); | 1198 | ASSERT_NE(executor, nullptr); |
| 1187 | ASSERT_EQ(executor->args, nullptr); | 1199 | ASSERT_EQ(executor->args, nullptr); |
| 1188 | - ASSERT_EQ(executor->tilingKey, nullptr); | 1200 | + ASSERT_EQ(executor->tiling.tilingKey, nullptr); |
| 1189 | - ASSERT_EQ(executor->numBlocks, nullptr); | 1201 | + ASSERT_EQ(executor->tiling.numBlocks, nullptr); |
| 1202 | + ASSERT_EQ(executor->tiling.aicpuNumBlocks, nullptr); | ||
| 1190 | ASSERT_EQ(executor->workspaces.num, 0); | 1203 | ASSERT_EQ(executor->workspaces.num, 0); |
| 1191 | ASSERT_EQ(executor->binInfoKey.len, 0); | 1204 | ASSERT_EQ(executor->binInfoKey.len, 0); |
| 1192 | ASSERT_EQ(executor->binInfoKey.bufLen, 0); | 1205 | ASSERT_EQ(executor->binInfoKey.bufLen, 0); |
| 1193 | ASSERT_EQ(executor->hasTiling, true); | 1206 | ASSERT_EQ(executor->hasTiling, true); |
| 1194 | ASSERT_EQ(executor->isWork, false); | 1207 | ASSERT_EQ(executor->isWork, false); |
| 1195 | - ASSERT_EQ(executor->tilingId, nullptr); | 1208 | + ASSERT_EQ(executor->dfx.tilingId, nullptr); |
| 1196 | NnopbaseExecutorGcSpace((void*)executor->space); | 1209 | NnopbaseExecutorGcSpace((void*)executor->space); |
| 1197 | NnopbaseExecutorDeInit(executor); | 1210 | NnopbaseExecutorDeInit(executor); |
| 1198 | delete executor; | 1211 | delete executor; |
| @@ -1353,7 +1366,7 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbaseCacheMatchArgs) | |||
| 1353 | 1366 | ||
| 1354 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor), false); | 1367 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor), false); |
| 1355 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor), OK); | 1368 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor), OK); |
| 1356 | - executor->args->isVist = false; | 1369 | + executor->args->isVisit = false; |
| 1357 | NnopbaseBinInfo binInfo; | 1370 | NnopbaseBinInfo binInfo; |
| 1358 | binInfo.isStaticShape = false; | 1371 | binInfo.isStaticShape = false; |
| 1359 | executor->args->binInfo = &binInfo; | 1372 | executor->args->binInfo = &binInfo; |
| @@ -1381,7 +1394,7 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbaseCacheNoMatchArgs) | |||
| 1381 | 1394 | ||
| 1382 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor1), false); | 1395 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor1), false); |
| 1383 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor1), OK); | 1396 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor1), OK); |
| 1384 | - executor1->args->isVist = false; | 1397 | + executor1->args->isVisit = false; |
| 1385 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor2), false); | 1398 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor2), false); |
| 1386 | 1399 | ||
| 1387 | NnopbaseExecutorGcSpace((void*)space); | 1400 | NnopbaseExecutorGcSpace((void*)space); |
| @@ -1407,7 +1420,7 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbaseExceededMaxNum) | |||
| 1407 | for (auto& iter : nnopbase::ArgsPool::GetInstance().argsMap) { | 1420 | for (auto& iter : nnopbase::ArgsPool::GetInstance().argsMap) { |
| 1408 | for (auto& args : iter.second) { | 1421 | for (auto& args : iter.second) { |
| 1409 | if (args != nullptr) { | 1422 | if (args != nullptr) { |
| 1410 | - args->isVist = false; | 1423 | + args->isVisit = false; |
| 1411 | } | 1424 | } |
| 1412 | } | 1425 | } |
| 1413 | } | 1426 | } |
| @@ -1443,7 +1456,7 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbaseOneCacheNum) | |||
| 1443 | nnopbase::ArgsPool::GetInstance().Finalize(); | 1456 | nnopbase::ArgsPool::GetInstance().Finalize(); |
| 1444 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor1), false); | 1457 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor1), false); |
| 1445 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor1), OK); | 1458 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor1), OK); |
| 1446 | - executor1->args->isVist = false; | 1459 | + executor1->args->isVisit = false; |
| 1447 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor2), OK); | 1460 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor2), OK); |
| 1448 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor2), OK); | 1461 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor2), OK); |
| 1449 | 1462 | ||
| @@ -2084,7 +2097,7 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbaseNotCacheMatchArgs) | |||
| 2084 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor), false); | 2097 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().MatchArgs(executor), false); |
| 2085 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor), OK); | 2098 | ASSERT_EQ(nnopbase::ArgsPool::GetInstance().CreateArgs(executor), OK); |
| 2086 | auto& args = executor->ownArgs; | 2099 | auto& args = executor->ownArgs; |
| 2087 | - executor->args->isVist = false; | 2100 | + executor->args->isVisit = false; |
| 2088 | NnopbaseBinInfo binInfo; | 2101 | NnopbaseBinInfo binInfo; |
| 2089 | binInfo.isStaticShape = false; | 2102 | binInfo.isStaticShape = false; |
| 2090 | executor->args->binInfo = &binInfo; | 2103 | executor->args->binInfo = &binInfo; |
| @@ -2265,13 +2278,13 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbasePrepareMC2ParamsSuccess) | |||
| 2265 | ASSERT_NE(executor, nullptr); | 2278 | ASSERT_NE(executor, nullptr); |
| 2266 | 2279 | ||
| 2267 | executor->opType = strdup("test_op"); | 2280 | executor->opType = strdup("test_op"); |
| 2268 | - executor->mc2OpCfg.sType = NNOPBASE_HCCL_SERVER_TYPE_AICPU; | 2281 | + executor->mc2.serverType = NNOPBASE_HCCL_SERVER_TYPE_AICPU; |
| 2269 | - executor->mc2OpCfg.isMc2 = true; | 2282 | + executor->mc2.enabled = true; |
| 2270 | executor->collector = new NnopbaseBinCollector; | 2283 | executor->collector = new NnopbaseBinCollector; |
| 2271 | executor->collector->isMc2FusionLaunch = false; | 2284 | executor->collector->isMc2FusionLaunch = false; |
| 2272 | executor->args = new NnopbaseExecutorArgs; | 2285 | executor->args = new NnopbaseExecutorArgs; |
| 2273 | executor->argsExt.hostInputInfoNum = 1U; | 2286 | executor->argsExt.hostInputInfoNum = 1U; |
| 2274 | - executor->aicpuArgs.hostInputInfoNum = 1U; | 2287 | + executor->mc2.aicpuArgs.hostInputInfoNum = 1U; |
| 2275 | NnopbaseHcclCommParamDesc paramDesc = {0, 0, 0, 0, 0}; | 2288 | NnopbaseHcclCommParamDesc paramDesc = {0, 0, 0, 0, 0}; |
| 2276 | NnopbaseExecutorArgsAddr argsAddr = {nullptr, nullptr, nullptr, nullptr, ¶mDesc}; | 2289 | NnopbaseExecutorArgsAddr argsAddr = {nullptr, nullptr, nullptr, nullptr, ¶mDesc}; |
| 2277 | argsAddr.ptr = executor->args->argsBuf.data() + 2 * sizeof(void*); | 2290 | argsAddr.ptr = executor->args->argsBuf.data() + 2 * sizeof(void*); |
| @@ -2279,7 +2292,7 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbasePrepareMC2ParamsSuccess) | |||
| 2279 | argsAddr.aicpuHostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr + | 2292 | argsAddr.aicpuHostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr + |
| 2280 | sizeof(aclrtPlaceHolderInfo)); | 2293 | sizeof(aclrtPlaceHolderInfo)); |
| 2281 | argsAddr.hostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr); | 2294 | argsAddr.hostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr); |
| 2282 | - executor->aicpuArgs.args = argsAddr.ptr; | 2295 | + executor->mc2.aicpuArgs.args = argsAddr.ptr; |
| 2283 | executor->argsExt.args = op::internal::PtrCastTo<void>(argsAddr.ptr + sizeof(void*)); | 2296 | executor->argsExt.args = op::internal::PtrCastTo<void>(argsAddr.ptr + sizeof(void*)); |
| 2284 | 2297 | ||
| 2285 | NnopbaseUChar* soNamePtr = argsAddr.hostInputData; | 2298 | NnopbaseUChar* soNamePtr = argsAddr.hostInputData; |
| @@ -2307,13 +2320,13 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbasePrepareMC2ParamsSuccessForascend950With | |||
| 2307 | ASSERT_NE(executor, nullptr); | 2320 | ASSERT_NE(executor, nullptr); |
| 2308 | 2321 | ||
| 2309 | executor->opType = strdup("test_op"); | 2322 | executor->opType = strdup("test_op"); |
| 2310 | - executor->mc2OpCfg.sType = NNOPBASE_HCCL_SERVER_TYPE_AICPU; | 2323 | + executor->mc2.serverType = NNOPBASE_HCCL_SERVER_TYPE_AICPU; |
| 2311 | - executor->mc2OpCfg.isMc2 = true; | 2324 | + executor->mc2.enabled = true; |
| 2312 | executor->collector = new NnopbaseBinCollector; | 2325 | executor->collector = new NnopbaseBinCollector; |
| 2313 | executor->collector->isMc2FusionLaunch = false; | 2326 | executor->collector->isMc2FusionLaunch = false; |
| 2314 | executor->args = new NnopbaseExecutorArgs; | 2327 | executor->args = new NnopbaseExecutorArgs; |
| 2315 | executor->argsExt.hostInputInfoNum = 1U; | 2328 | executor->argsExt.hostInputInfoNum = 1U; |
| 2316 | - executor->aicpuArgs.hostInputInfoNum = 1U; | 2329 | + executor->mc2.aicpuArgs.hostInputInfoNum = 1U; |
| 2317 | NnopbaseHcclCommParamDesc paramDesc = {0, 0, 0, 0, 0}; | 2330 | NnopbaseHcclCommParamDesc paramDesc = {0, 0, 0, 0, 0}; |
| 2318 | NnopbaseExecutorArgsAddr argsAddr = {nullptr, nullptr, nullptr, nullptr, ¶mDesc}; | 2331 | NnopbaseExecutorArgsAddr argsAddr = {nullptr, nullptr, nullptr, nullptr, ¶mDesc}; |
| 2319 | argsAddr.ptr = executor->args->argsBuf.data() + 2 * sizeof(void*); | 2332 | argsAddr.ptr = executor->args->argsBuf.data() + 2 * sizeof(void*); |
| @@ -2321,7 +2334,7 @@ TEST_F(NnopbaseExecutorUnitTest, NnopbasePrepareMC2ParamsSuccessForascend950With | |||
| 2321 | argsAddr.aicpuHostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr + | 2334 | argsAddr.aicpuHostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr + |
| 2322 | sizeof(aclrtPlaceHolderInfo)); | 2335 | sizeof(aclrtPlaceHolderInfo)); |
| 2323 | argsAddr.hostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr); | 2336 | argsAddr.hostInputInfo = op::internal::PtrCastTo<aclrtPlaceHolderInfo>(argsAddr.ptr); |
| 2324 | - executor->aicpuArgs.args = argsAddr.ptr; | 2337 | + executor->mc2.aicpuArgs.args = argsAddr.ptr; |
| 2325 | executor->argsExt.args = op::internal::PtrCastTo<void>(argsAddr.ptr + sizeof(void*)); | 2338 | executor->argsExt.args = op::internal::PtrCastTo<void>(argsAddr.ptr + sizeof(void*)); |
| 2326 | auto oriSocVersion = nnopbase::IndvSoc::GetInstance().GetCurSocVersion(); | 2339 | auto oriSocVersion = nnopbase::IndvSoc::GetInstance().GetCurSocVersion(); |
| 2327 | struct SocVersionGuard { | 2340 | struct SocVersionGuard { |
| @@ -0,0 +1,150 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <array> | ||
| 12 | +#include <cstdint> | ||
| 13 | +#include <cstring> | ||
| 14 | +#include <initializer_list> | ||
| 15 | + | ||
| 16 | +#include <gtest/gtest.h> | ||
| 17 | + | ||
| 18 | +#include "executor/indv_args.h" | ||
| 19 | +#include "executor/indv_bininfo.h" | ||
| 20 | +#include "executor/indv_executor.h" | ||
| 21 | + | ||
| 22 | +namespace { | ||
| 23 | +void SetParamInstance(NnopbaseParamInstance& instance, uint32_t startIndex, uint32_t num, bool isDynamic, bool isInput) | ||
| 24 | +{ | ||
| 25 | + instance.startIndex = startIndex; | ||
| 26 | + instance.num = num; | ||
| 27 | + instance.cfgNum = isDynamic ? 2U : 1U; | ||
| 28 | + instance.isDynamic = isDynamic; | ||
| 29 | + instance.isInput = isInput; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +void SetTensor(NnopbaseTensor& tensor, void* addr, gert::TensorPlacement placement, | ||
| 33 | + std::initializer_list<int64_t> shape, ge::DataType dtype = ge::DT_FLOAT) | ||
| 34 | +{ | ||
| 35 | + tensor.isNull = false; | ||
| 36 | + GertShape gertShape(shape); | ||
| 37 | + tensor.rt2Tensor.MutableOriginShape() = gertShape; | ||
| 38 | + tensor.rt2Tensor.MutableStorageShape() = gertShape; | ||
| 39 | + tensor.rt2Tensor.SetDataType(dtype); | ||
| 40 | + tensor.rt2Tensor.SetOriginFormat(ge::FORMAT_ND); | ||
| 41 | + tensor.rt2Tensor.SetStorageFormat(ge::FORMAT_ND); | ||
| 42 | + tensor.rt2Tensor.MutableTensorData().SetPlacement(placement); | ||
| 43 | + tensor.rt2Tensor.SetSize(sizeof(uint64_t)); | ||
| 44 | + ASSERT_EQ(tensor.rt2Tensor.MutableTensorData().SetAddr(addr, nullptr), ge::GRAPH_SUCCESS); | ||
| 45 | +} | ||
| 46 | +} // namespace | ||
| 47 | + | ||
| 48 | +class NnopbaseIndvArgsTest : public testing::Test { | ||
| 49 | +protected: | ||
| 50 | + void SetUp() override | ||
| 51 | + { | ||
| 52 | + executor_.args = &args_; | ||
| 53 | + executor_.argsExt.args = launchBuf_.data(); | ||
| 54 | + args_.binInfo = &binInfo_; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + NnopbaseExecutor executor_{}; | ||
| 58 | + NnopbaseExecutorArgs args_{}; | ||
| 59 | + NnopbaseBinInfo binInfo_{}; | ||
| 60 | + std::array<NnopbaseUChar, 2048U> launchBuf_{}; | ||
| 61 | +}; | ||
| 62 | + | ||
| 63 | +TEST_F(NnopbaseIndvArgsTest, PrepareInputsParamsExtEncodesDeviceHostDynamicAndOptionalInputs) | ||
| 64 | +{ | ||
| 65 | + args_.inputs.paramDescs.count = 4U; | ||
| 66 | + args_.inputs.paramDescs.instances.resize(4U); | ||
| 67 | + SetParamInstance(args_.inputs.paramDescs.instances[0], 0U, 1U, false, true); | ||
| 68 | + SetParamInstance(args_.inputs.paramDescs.instances[1], 1U, 1U, false, true); | ||
| 69 | + SetParamInstance(args_.inputs.paramDescs.instances[2], 2U, 1U, false, true); | ||
| 70 | + SetParamInstance(args_.inputs.paramDescs.instances[3], 3U, 2U, true, true); | ||
| 71 | + args_.inputs.extTensors.resize(5U); | ||
| 72 | + args_.inputs.num = 5U; | ||
| 73 | + | ||
| 74 | + uint64_t deviceData = 0x1111U; | ||
| 75 | + uint64_t hostData = 0x2222U; | ||
| 76 | + uint64_t dynData0 = 0x3333U; | ||
| 77 | + uint64_t dynData1 = 0x4444U; | ||
| 78 | + SetTensor(args_.inputs.extTensors[0], &deviceData, gert::kOnDeviceHbm, {4}); | ||
| 79 | + args_.inputs.extTensors[1].isNull = true; | ||
| 80 | + SetTensor(args_.inputs.extTensors[2], &hostData, gert::kOnHost, {1}, ge::DT_UINT64); | ||
| 81 | + SetTensor(args_.inputs.extTensors[3], &dynData0, gert::kOnDeviceHbm, {2, 3}); | ||
| 82 | + SetTensor(args_.inputs.extTensors[4], &dynData1, gert::kOnDeviceHbm, {5}); | ||
| 83 | + | ||
| 84 | + auto* params = reinterpret_cast<void**>(launchBuf_.data()); | ||
| 85 | + auto* hostInfo = reinterpret_cast<aclrtPlaceHolderInfo*>(launchBuf_.data() + 512U); | ||
| 86 | + auto* hostDataStart = launchBuf_.data() + 768U; | ||
| 87 | + NnopbaseHcclCommParamDesc hcclDesc{}; | ||
| 88 | + NnopbaseExecutorArgsAddr argsAddr{hostDataStart, hostInfo, launchBuf_.data() + 1600U, nullptr, &hcclDesc}; | ||
| 89 | + | ||
| 90 | + void** ret = NnopbaseExecutorPrepareInputsParamsExt(&executor_, params, &argsAddr); | ||
| 91 | + | ||
| 92 | + ASSERT_EQ(ret, params + 4U); | ||
| 93 | + EXPECT_EQ(params[0], &deviceData); | ||
| 94 | + EXPECT_EQ(params[1], nullptr); | ||
| 95 | + EXPECT_EQ(params[2], hostDataStart); | ||
| 96 | + EXPECT_EQ(*reinterpret_cast<uint64_t*>(params[2]), hostData); | ||
| 97 | + EXPECT_EQ(hcclDesc.isDyn, 1ULL << 3U); | ||
| 98 | + | ||
| 99 | + auto* dynamicBase = reinterpret_cast<NnopbaseUChar*>(params[3]); | ||
| 100 | + ASSERT_NE(dynamicBase, nullptr); | ||
| 101 | + const auto dynamicDataOffset = *reinterpret_cast<uint64_t*>(dynamicBase); | ||
| 102 | + EXPECT_EQ(dynamicDataOffset, 48U); | ||
| 103 | + EXPECT_EQ(*reinterpret_cast<void**>(dynamicBase + dynamicDataOffset), &dynData0); | ||
| 104 | + EXPECT_EQ(*reinterpret_cast<void**>(dynamicBase + dynamicDataOffset + sizeof(void*)), &dynData1); | ||
| 105 | + | ||
| 106 | + const auto base = reinterpret_cast<uintptr_t>(launchBuf_.data()); | ||
| 107 | + EXPECT_EQ(hostInfo[0].addrOffset, reinterpret_cast<uintptr_t>(¶ms[2]) - base); | ||
| 108 | + EXPECT_EQ(hostInfo[0].dataOffset, reinterpret_cast<uintptr_t>(hostDataStart) - base); | ||
| 109 | + EXPECT_EQ(hostInfo[1].addrOffset, reinterpret_cast<uintptr_t>(¶ms[3]) - base); | ||
| 110 | + EXPECT_EQ(hostInfo[1].dataOffset, reinterpret_cast<uintptr_t>(dynamicBase) - base); | ||
| 111 | + EXPECT_GT(args_.inputs.extTensors[3].argsOffset, 0U); | ||
| 112 | + EXPECT_GT(args_.inputs.extTensors[4].argsOffset, args_.inputs.extTensors[3].argsOffset); | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +TEST_F(NnopbaseIndvArgsTest, PrepareNullTensorsReservesLaunchSlotOnlyForDynamicShapeBin) | ||
| 116 | +{ | ||
| 117 | + std::array<void*, 2U> params = {reinterpret_cast<void*>(0x1234), reinterpret_cast<void*>(0x5678)}; | ||
| 118 | + size_t tensorIndex = 0U; | ||
| 119 | + | ||
| 120 | + binInfo_.isStaticShape = false; | ||
| 121 | + void** ret = NnopbaseExecutorPrepareNullTensors(&executor_, params.data(), &tensorIndex); | ||
| 122 | + EXPECT_EQ(ret, params.data() + 1U); | ||
| 123 | + EXPECT_EQ(tensorIndex, 1U); | ||
| 124 | + EXPECT_EQ(params[0], nullptr); | ||
| 125 | + | ||
| 126 | + params = {reinterpret_cast<void*>(0x1234), reinterpret_cast<void*>(0x5678)}; | ||
| 127 | + tensorIndex = 0U; | ||
| 128 | + binInfo_.isStaticShape = true; | ||
| 129 | + ret = NnopbaseExecutorPrepareNullTensors(&executor_, params.data(), &tensorIndex); | ||
| 130 | + EXPECT_EQ(ret, params.data()); | ||
| 131 | + EXPECT_EQ(tensorIndex, 1U); | ||
| 132 | + EXPECT_EQ(params[0], reinterpret_cast<void*>(0x1234)); | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +TEST_F(NnopbaseIndvArgsTest, GetIrIndexMapsFlattenedDynamicTensorIndexBackToIrInput) | ||
| 136 | +{ | ||
| 137 | + NnopbaseParamDesc desc{}; | ||
| 138 | + desc.count = 3U; | ||
| 139 | + desc.instances.resize(3U); | ||
| 140 | + SetParamInstance(desc.instances[0], 0U, 1U, false, true); | ||
| 141 | + SetParamInstance(desc.instances[1], 1U, 3U, true, true); | ||
| 142 | + SetParamInstance(desc.instances[2], 4U, 1U, false, true); | ||
| 143 | + | ||
| 144 | + size_t irIndex = 0U; | ||
| 145 | + size_t relativeIndex = 0U; | ||
| 146 | + NnopbaseGetIrIndex(desc, 3U, irIndex, relativeIndex); | ||
| 147 | + | ||
| 148 | + EXPECT_EQ(irIndex, 1U); | ||
| 149 | + EXPECT_EQ(relativeIndex, 2U); | ||
| 150 | +} | ||
| @@ -0,0 +1,158 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <array> | ||
| 12 | +#include <cstdint> | ||
| 13 | +#include <cstring> | ||
| 14 | + | ||
| 15 | +#include <gtest/gtest.h> | ||
| 16 | + | ||
| 17 | +#include "executor/indv_compute_node_info.h" | ||
| 18 | +#include "executor/indv_executor.h" | ||
| 19 | +#include "exe_graph/runtime/continuous_vector.h" | ||
| 20 | + | ||
| 21 | +namespace { | ||
| 22 | +void SetParamInstance(NnopbaseParamInstance& instance, uint32_t startIndex, uint32_t num, bool isDynamic, bool isInput) | ||
| 23 | +{ | ||
| 24 | + instance.startIndex = startIndex; | ||
| 25 | + instance.num = num; | ||
| 26 | + instance.cfgNum = isDynamic ? 2U : 1U; | ||
| 27 | + instance.isDynamic = isDynamic; | ||
| 28 | + instance.isInput = isInput; | ||
| 29 | +} | ||
| 30 | +} // namespace | ||
| 31 | + | ||
| 32 | +class NnopbaseComputeNodeInfoTest : public testing::Test { | ||
| 33 | +protected: | ||
| 34 | + void SetUp() override | ||
| 35 | + { | ||
| 36 | + executor_.args = &args_; | ||
| 37 | + executor_.opType = opType_.data(); | ||
| 38 | + ASSERT_EQ(NnopbaseComputeNodeInfoInit(&executor_.tiling.contextExt.nodeExt), OK); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + void TearDown() override { NnopbaseComputeNodeInfoDeInit(&executor_.tiling.contextExt.nodeExt); } | ||
| 42 | + | ||
| 43 | + std::array<char, 32U> opType_ = {"BusinessExecutorOp"}; | ||
| 44 | + NnopbaseExecutor executor_{}; | ||
| 45 | + NnopbaseExecutorArgs args_{}; | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +TEST_F(NnopbaseComputeNodeInfoTest, InfoUpdtLaysOutDynamicAndOptionalIrInstancesForExecutorNode) | ||
| 49 | +{ | ||
| 50 | + args_.inputs.paramDescs.count = 3U; | ||
| 51 | + args_.inputs.paramDescs.instances.resize(3U); | ||
| 52 | + SetParamInstance(args_.inputs.paramDescs.instances[0], 0U, 1U, false, true); | ||
| 53 | + SetParamInstance(args_.inputs.paramDescs.instances[1], 1U, 1U, false, true); | ||
| 54 | + SetParamInstance(args_.inputs.paramDescs.instances[2], 2U, 2U, true, true); | ||
| 55 | + args_.inputs.num = 4U; | ||
| 56 | + args_.inputs.hasDynamic = true; | ||
| 57 | + | ||
| 58 | + args_.outputs.paramDescs.count = 2U; | ||
| 59 | + args_.outputs.paramDescs.instances.resize(2U); | ||
| 60 | + SetParamInstance(args_.outputs.paramDescs.instances[0], 0U, 1U, false, false); | ||
| 61 | + SetParamInstance(args_.outputs.paramDescs.instances[1], 1U, 3U, true, false); | ||
| 62 | + args_.outputs.num = 4U; | ||
| 63 | + args_.outputs.hasDynamic = true; | ||
| 64 | + | ||
| 65 | + auto& nodeExt = executor_.tiling.contextExt.nodeExt; | ||
| 66 | + ASSERT_EQ(NnopbaseComputeNodeInfoUpdt(&executor_), OK); | ||
| 67 | + | ||
| 68 | + ASSERT_EQ(nodeExt.node->nodeType, opType_.data()); | ||
| 69 | + ASSERT_EQ(nodeExt.node->nodeName, opType_.data()); | ||
| 70 | + EXPECT_EQ(nodeExt.node->irInputsNum, 3U); | ||
| 71 | + EXPECT_EQ(nodeExt.node->irOutputsNum, 2U); | ||
| 72 | + EXPECT_EQ(nodeExt.node->inputsNum, 4U); | ||
| 73 | + EXPECT_EQ(nodeExt.node->outputsNum, 4U); | ||
| 74 | + EXPECT_EQ(nodeExt.inputTdStart, reinterpret_cast<NnopbaseCompileTimeTensorDesc*>(nodeExt.instStart + 3U)); | ||
| 75 | + EXPECT_EQ(nodeExt.outputTdStart, nodeExt.inputTdStart + 4U); | ||
| 76 | + EXPECT_EQ(nodeExt.attrStart, reinterpret_cast<NnopbaseRuntimeAttrsDef*>(nodeExt.outputTdStart + 4U)); | ||
| 77 | + EXPECT_EQ(nodeExt.outputInstStart, | ||
| 78 | + reinterpret_cast<NnopbaseAnchorInstanceInfo*>(reinterpret_cast<NnopbaseUChar*>(nodeExt.attrStart) + | ||
| 79 | + nodeExt.node->attrSize)); | ||
| 80 | + | ||
| 81 | + EXPECT_EQ(nodeExt.instStart[0].GetInstanceStart(), 0U); | ||
| 82 | + EXPECT_EQ(nodeExt.instStart[0].GetInstanceNum(), 1U); | ||
| 83 | + EXPECT_EQ(nodeExt.instStart[1].GetInstanceStart(), 1U); | ||
| 84 | + EXPECT_EQ(nodeExt.instStart[1].GetInstanceNum(), 1U); | ||
| 85 | + EXPECT_EQ(nodeExt.instStart[2].GetInstanceStart(), 2U); | ||
| 86 | + EXPECT_EQ(nodeExt.instStart[2].GetInstanceNum(), 2U); | ||
| 87 | + EXPECT_EQ(nodeExt.outputInstStart[0].GetInstanceStart(), 0U); | ||
| 88 | + EXPECT_EQ(nodeExt.outputInstStart[0].GetInstanceNum(), 1U); | ||
| 89 | + EXPECT_EQ(nodeExt.outputInstStart[1].GetInstanceStart(), 1U); | ||
| 90 | + EXPECT_EQ(nodeExt.outputInstStart[1].GetInstanceNum(), 3U); | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +TEST_F(NnopbaseComputeNodeInfoTest, AttrsUpdtCopiesScalarAndVectorAttrsIntoRuntimeBuffer) | ||
| 94 | +{ | ||
| 95 | + args_.inputs.paramDescs.count = 1U; | ||
| 96 | + args_.inputs.paramDescs.instances.resize(1U); | ||
| 97 | + SetParamInstance(args_.inputs.paramDescs.instances[0], 0U, 1U, false, true); | ||
| 98 | + args_.inputs.num = 1U; | ||
| 99 | + | ||
| 100 | + args_.outputs.paramDescs.count = 1U; | ||
| 101 | + args_.outputs.paramDescs.instances.resize(1U); | ||
| 102 | + SetParamInstance(args_.outputs.paramDescs.instances[0], 0U, 1U, false, false); | ||
| 103 | + args_.outputs.num = 1U; | ||
| 104 | + | ||
| 105 | + int64_t scalarValue = 42; | ||
| 106 | + std::array<int32_t, 3U> vectorValue = {7, 8, 9}; | ||
| 107 | + std::array<NnopbaseAttr, 2U> attrStorage{}; | ||
| 108 | + attrStorage[0].addr = {&scalarValue, sizeof(scalarValue), false, false, sizeof(scalarValue)}; | ||
| 109 | + attrStorage[0].dtype = kNnopbaseInt; | ||
| 110 | + attrStorage[1].addr = {vectorValue.data(), vectorValue.size() * sizeof(int32_t), false, true, sizeof(int32_t)}; | ||
| 111 | + attrStorage[1].dtype = kNnopbaseInt; | ||
| 112 | + executor_.attrs.attrs = attrStorage.data(); | ||
| 113 | + executor_.attrs.num = attrStorage.size(); | ||
| 114 | + executor_.attrs.totalSize = sizeof(scalarValue) + sizeof(gert::ContinuousVector) + | ||
| 115 | + vectorValue.size() * sizeof(int32_t); | ||
| 116 | + | ||
| 117 | + ASSERT_EQ(NnopbaseComputeNodeInfoUpdt(&executor_), OK); | ||
| 118 | + ASSERT_EQ(NnopbaseComputeNodeAttrsUpdt(&executor_.tiling.contextExt.nodeExt, &executor_.attrs), OK); | ||
| 119 | + | ||
| 120 | + auto* attrDef = executor_.tiling.contextExt.nodeExt.attrStart; | ||
| 121 | + ASSERT_NE(attrDef, nullptr); | ||
| 122 | + EXPECT_EQ(attrDef->attr_num, attrStorage.size()); | ||
| 123 | + auto* attrBase = reinterpret_cast<NnopbaseUChar*>(attrDef); | ||
| 124 | + EXPECT_EQ(*reinterpret_cast<int64_t*>(attrBase + attrDef->offset[0]), scalarValue); | ||
| 125 | + | ||
| 126 | + auto* vector = reinterpret_cast<gert::ContinuousVector*>(attrBase + attrDef->offset[1]); | ||
| 127 | + ASSERT_EQ(vector->GetSize(), vectorValue.size()); | ||
| 128 | + ASSERT_EQ(vector->GetCapacity(), vectorValue.size()); | ||
| 129 | + EXPECT_EQ(std::memcmp(vector->GetData(), vectorValue.data(), vectorValue.size() * sizeof(int32_t)), 0); | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +TEST_F(NnopbaseComputeNodeInfoTest, InfoUpdtReallocatesNodeBufferWhenRuntimeAttrsExceedDefaultStorage) | ||
| 133 | +{ | ||
| 134 | + args_.inputs.paramDescs.count = 1U; | ||
| 135 | + args_.inputs.paramDescs.instances.resize(1U); | ||
| 136 | + SetParamInstance(args_.inputs.paramDescs.instances[0], 0U, 1U, false, true); | ||
| 137 | + args_.inputs.num = 1U; | ||
| 138 | + | ||
| 139 | + args_.outputs.paramDescs.count = 1U; | ||
| 140 | + args_.outputs.paramDescs.instances.resize(1U); | ||
| 141 | + SetParamInstance(args_.outputs.paramDescs.instances[0], 0U, 1U, false, false); | ||
| 142 | + args_.outputs.num = 1U; | ||
| 143 | + | ||
| 144 | + std::array<NnopbaseAttr, 1U> attrs{}; | ||
| 145 | + uint8_t attrValue = 1U; | ||
| 146 | + attrs[0].addr = {&attrValue, sizeof(attrValue), false, false, sizeof(attrValue)}; | ||
| 147 | + executor_.attrs.attrs = attrs.data(); | ||
| 148 | + executor_.attrs.num = attrs.size(); | ||
| 149 | + executor_.attrs.totalSize = NNOPBASE_COMPUTE_NODE_BUF_LEN + 1U; | ||
| 150 | + | ||
| 151 | + auto* oldBuf = executor_.tiling.contextExt.nodeExt.buf; | ||
| 152 | + ASSERT_EQ(NnopbaseComputeNodeInfoUpdt(&executor_), OK); | ||
| 153 | + | ||
| 154 | + EXPECT_NE(executor_.tiling.contextExt.nodeExt.buf, oldBuf); | ||
| 155 | + EXPECT_GT(executor_.tiling.contextExt.nodeExt.bufLen, | ||
| 156 | + sizeof(NnopbaseComputeNodeInfo) + NNOPBASE_COMPUTE_NODE_BUF_LEN); | ||
| 157 | + EXPECT_EQ(executor_.tiling.contextExt.nodeExt.node->nodeType, opType_.data()); | ||
| 158 | +} | ||
| @@ -0,0 +1,147 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <array> | ||
| 12 | +#include <cstdint> | ||
| 13 | +#include <initializer_list> | ||
| 14 | + | ||
| 15 | +#include <gtest/gtest.h> | ||
| 16 | + | ||
| 17 | +#include "executor/indv_tilingcontext_builder.h" | ||
| 18 | + | ||
| 19 | +namespace { | ||
| 20 | +constexpr uint32_t kTilingContextPadding = 32U; | ||
| 21 | + | ||
| 22 | +void SetParamInstance(NnopbaseParamInstance& instance, uint32_t startIndex, uint32_t num, bool isDynamic, bool isInput) | ||
| 23 | +{ | ||
| 24 | + instance.startIndex = startIndex; | ||
| 25 | + instance.num = num; | ||
| 26 | + instance.cfgNum = isDynamic ? 2U : 1U; | ||
| 27 | + instance.isDynamic = isDynamic; | ||
| 28 | + instance.isInput = isInput; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +void SetTensor(NnopbaseTensor& tensor, void* addr, std::initializer_list<int64_t> shape, ge::DataType dtype, | ||
| 32 | + ge::Format format) | ||
| 33 | +{ | ||
| 34 | + tensor.isNull = false; | ||
| 35 | + GertShape gertShape(shape); | ||
| 36 | + tensor.rt2Tensor.MutableOriginShape() = gertShape; | ||
| 37 | + tensor.rt2Tensor.MutableStorageShape() = gertShape; | ||
| 38 | + tensor.rt2Tensor.SetDataType(dtype); | ||
| 39 | + tensor.rt2Tensor.SetOriginFormat(format); | ||
| 40 | + tensor.rt2Tensor.SetStorageFormat(format); | ||
| 41 | + tensor.rt2Tensor.MutableTensorData().SetPlacement(gert::kOnDeviceHbm); | ||
| 42 | + tensor.rt2Tensor.SetSize(sizeof(uint64_t)); | ||
| 43 | + ASSERT_EQ(tensor.rt2Tensor.MutableTensorData().SetAddr(addr, nullptr), ge::GRAPH_SUCCESS); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +size_t ExpectedKernelRunContextLen(uint32_t valueNum) | ||
| 47 | +{ | ||
| 48 | + const size_t offset = valueNum * sizeof(void*) + sizeof(NnopbaseKernelRunContext) + kTilingContextPadding; | ||
| 49 | + return offset + valueNum * sizeof(NnopbaseAsyncAnyValue); | ||
| 50 | +} | ||
| 51 | +} // namespace | ||
| 52 | + | ||
| 53 | +class NnopbaseTilingContextBuilderTest : public testing::Test { | ||
| 54 | +protected: | ||
| 55 | + void SetUp() override | ||
| 56 | + { | ||
| 57 | + executor_.args = &executor_.ownArgs; | ||
| 58 | + executor_.opType = opType_.data(); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + void TearDown() override | ||
| 62 | + { | ||
| 63 | + if (executor_.tiling.contextExt.context != nullptr || executor_.tiling.contextExt.nodeExt.buf != nullptr) { | ||
| 64 | + NnopbaseTilingContextDeInit(&executor_); | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + std::array<char, 32U> opType_ = {"TilingBusinessOp"}; | ||
| 69 | + NnopbaseExecutor executor_{}; | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +TEST_F(NnopbaseTilingContextBuilderTest, ContextInitAllocatesDynamicSlotsForExecutorTilingValues) | ||
| 73 | +{ | ||
| 74 | + executor_.ownArgs.inputs.nonDynamicCnt = 2U; | ||
| 75 | + executor_.ownArgs.inputs.hasDynamic = true; | ||
| 76 | + executor_.ownArgs.inputs.dynamicNum = 1U; | ||
| 77 | + executor_.ownArgs.outputs.nonDynamicCnt = 1U; | ||
| 78 | + | ||
| 79 | + ASSERT_EQ(NnopbaseTilingContextInit(&executor_), OK); | ||
| 80 | + | ||
| 81 | + const uint32_t expectedValues = executor_.ownArgs.inputs.nonDynamicCnt + executor_.ownArgs.outputs.nonDynamicCnt + | ||
| 82 | + static_cast<uint32_t>(kInputsAppendEnd) + | ||
| 83 | + static_cast<uint32_t>(gert::TilingContext::kOutputNum) + | ||
| 84 | + NNOPBASE_DYNAMIC_PARAM_DEF_NUM; | ||
| 85 | + EXPECT_EQ(executor_.tiling.contextExt.contextLen, ExpectedKernelRunContextLen(expectedValues)); | ||
| 86 | + EXPECT_FALSE(executor_.tiling.contextExt.hasPrepared); | ||
| 87 | + ASSERT_NE(executor_.tiling.contextExt.context, nullptr); | ||
| 88 | + EXPECT_EQ(executor_.tiling.contextExt.context->compute_node_info, executor_.tiling.contextExt.nodeExt.node); | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +TEST_F(NnopbaseTilingContextBuilderTest, BuildOpInputsAndOutputsBindRuntimeTensorsAndCompileTensorDescs) | ||
| 92 | +{ | ||
| 93 | + auto& args = executor_.ownArgs; | ||
| 94 | + args.inputs.paramDescs.count = 3U; | ||
| 95 | + args.inputs.paramDescs.instances.resize(3U); | ||
| 96 | + SetParamInstance(args.inputs.paramDescs.instances[0], 0U, 1U, false, true); | ||
| 97 | + SetParamInstance(args.inputs.paramDescs.instances[1], 1U, 1U, false, true); | ||
| 98 | + SetParamInstance(args.inputs.paramDescs.instances[2], 2U, 1U, false, true); | ||
| 99 | + args.inputs.num = 3U; | ||
| 100 | + args.inputs.nonDynamicCnt = 3U; | ||
| 101 | + args.inputs.extTensors.resize(3U); | ||
| 102 | + | ||
| 103 | + args.outputs.paramDescs.count = 2U; | ||
| 104 | + args.outputs.paramDescs.instances.resize(2U); | ||
| 105 | + SetParamInstance(args.outputs.paramDescs.instances[0], 0U, 1U, false, false); | ||
| 106 | + SetParamInstance(args.outputs.paramDescs.instances[1], 1U, 1U, false, false); | ||
| 107 | + args.outputs.num = 2U; | ||
| 108 | + args.outputs.nonDynamicCnt = 2U; | ||
| 109 | + args.outputs.extTensors.resize(2U); | ||
| 110 | + | ||
| 111 | + uint64_t input0 = 0x11U; | ||
| 112 | + uint64_t input2 = 0x22U; | ||
| 113 | + uint64_t output0 = 0x33U; | ||
| 114 | + SetTensor(args.inputs.extTensors[0], &input0, {2, 2}, ge::DT_FLOAT16, ge::FORMAT_ND); | ||
| 115 | + args.inputs.extTensors[1].isNull = true; | ||
| 116 | + SetTensor(args.inputs.extTensors[2], &input2, {4}, ge::DT_INT32, ge::FORMAT_ND); | ||
| 117 | + SetTensor(args.outputs.extTensors[0], &output0, {2, 2}, ge::DT_FLOAT, ge::FORMAT_ND); | ||
| 118 | + args.outputs.extTensors[1].isNull = true; | ||
| 119 | + | ||
| 120 | + ASSERT_EQ(NnopbaseTilingContextInit(&executor_), OK); | ||
| 121 | + ASSERT_EQ(NnopbaseTilingContextUpdtPrepare(&executor_), OK); | ||
| 122 | + NnopbaseTilingBuildOpInputs(&executor_); | ||
| 123 | + NnopbaseTilingBuildOpOutputs(&executor_); | ||
| 124 | + | ||
| 125 | + auto* context = executor_.tiling.contextExt.context; | ||
| 126 | + ASSERT_NE(context, nullptr); | ||
| 127 | + EXPECT_EQ(context->input_size, args.inputs.num + args.outputs.num + static_cast<uint32_t>(kInputsAppendEnd)); | ||
| 128 | + EXPECT_EQ(context->output_size, gert::TilingContext::kOutputNum); | ||
| 129 | + EXPECT_EQ(context->compute_node_info, executor_.tiling.contextExt.nodeExt.node); | ||
| 130 | + EXPECT_EQ(context->values[0]->data.pointer, &args.inputs.extTensors[0].rt2Tensor); | ||
| 131 | + EXPECT_EQ(context->values[1]->data.pointer, nullptr); | ||
| 132 | + EXPECT_EQ(context->values[2]->data.pointer, &args.inputs.extTensors[2].rt2Tensor); | ||
| 133 | + EXPECT_EQ(context->values[3]->data.pointer, &args.outputs.extTensors[0].rt2Tensor); | ||
| 134 | + EXPECT_EQ(context->values[4]->data.pointer, nullptr); | ||
| 135 | + | ||
| 136 | + auto* inputTd = executor_.tiling.contextExt.nodeExt.inputTdStart; | ||
| 137 | + ASSERT_NE(inputTd, nullptr); | ||
| 138 | + EXPECT_EQ(inputTd[0].GetDataType(), ge::DT_FLOAT16); | ||
| 139 | + EXPECT_EQ(inputTd[0].GetStorageFormat(), ge::FORMAT_ND); | ||
| 140 | + EXPECT_EQ(inputTd[2].GetDataType(), ge::DT_INT32); | ||
| 141 | + EXPECT_EQ(inputTd[2].GetStorageFormat(), ge::FORMAT_ND); | ||
| 142 | + | ||
| 143 | + auto* outputTd = executor_.tiling.contextExt.nodeExt.outputTdStart; | ||
| 144 | + ASSERT_NE(outputTd, nullptr); | ||
| 145 | + EXPECT_EQ(outputTd[0].GetDataType(), ge::DT_FLOAT); | ||
| 146 | + EXPECT_EQ(outputTd[0].GetStorageFormat(), ge::FORMAT_ND); | ||
| 147 | +} | ||