Merged
aclnn自动框架支持pcie_through算子 #741
pengjiahao96Add on Aug 15
aclnn自动框架支持pcie_through算子 #741
Merged
pengjiahao96Add on Aug 15
Total: 22 files changed+1007-520
@@ -11,6 +11,9 @@
11#ifndef OP_API_OP_API_COMMON_INC_OPDEV_NNOPBASE_H11#ifndef OP_API_OP_API_COMMON_INC_OPDEV_NNOPBASE_H
12#define OP_API_OP_API_COMMON_INC_OPDEV_NNOPBASE_H12#define OP_API_OP_API_COMMON_INC_OPDEV_NNOPBASE_H
13 13 
14+#include <memory>
15+#include <mutex>
16+#include <string>
14#include "opdev/common_types.h"17#include "opdev/common_types.h"
15 18 
16#ifdef __cplusplus19#ifdef __cplusplus
@@ -38,6 +41,7 @@ struct NnopbaseStaticRuntimeInfo {
38 uint32_t aivNum;41 uint32_t aivNum;
39 int64_t implMode;42 int64_t implMode;
40 int64_t deterMode;43 int64_t deterMode;
44+ bool enablePcie = false;
41};45};
42 46 
43/**47/**
@@ -15,14 +15,15 @@
15 15 
16namespace aclnnOpInfoRecord {16namespace aclnnOpInfoRecord {
17struct OpCompilerOption {17struct OpCompilerOption {
18- explicit OpCompilerOption(const std::string& impl_mode_v, uint8_t deterministic_v = true)18+ explicit OpCompilerOption(const std::string& impl_mode_v, uint8_t deterministic_v = true, bool enablePcie_v = false)
19- : impl_mode(impl_mode_v), deterministic(deterministic_v)19+ : impl_mode(impl_mode_v), deterministic(deterministic_v), enablePcie(enablePcie_v)
20 {}20 {}
21- explicit OpCompilerOption(const char* impl_mode_v, uint8_t deterministic_v = true)21+ explicit OpCompilerOption(const char* impl_mode_v, uint8_t deterministic_v = true, bool enablePcie_v = false)
22- : impl_mode(impl_mode_v), deterministic(deterministic_v)22+ : impl_mode(impl_mode_v), deterministic(deterministic_v), enablePcie(enablePcie_v)
23 {}23 {}
24 std::string impl_mode;24 std::string impl_mode;
25 uint8_t deterministic;25 uint8_t deterministic;
26+ bool enablePcie;
26};27};
27 28 
28struct OpKernelInfo {29struct OpKernelInfo {
@@ -49,4 +50,4 @@ int32_t OpInfoDump(void);
49 50 
50} // namespace aclnnOpInfoRecord51} // namespace aclnnOpInfoRecord
51 52 
52-#endif53+#endif
@@ -258,6 +258,7 @@ int32_t OpInfoSerialize(const gert::TilingContext* ctx, const aclnnOpInfoRecord:
258 return 0;258 return 0;
259 }259 }
260 AddPlatformInfoToJson(jsonDebug, ctx);260 AddPlatformInfoToJson(jsonDebug, ctx);
261+ jsonDebug["platform_info"]["pcie_through_flag"] = opt.enablePcie;
261 jsonDebug["impl_mode"] = opt.impl_mode;262 jsonDebug["impl_mode"] = opt.impl_mode;
262 jsonDebug["deterministic"] = (opt.deterministic == 0U) ? "false" : "true";263 jsonDebug["deterministic"] = (opt.deterministic == 0U) ? "false" : "true";
263 jsonDebug["deterministic_level"] = opt.deterministic;264 jsonDebug["deterministic_level"] = opt.deterministic;
@@ -1365,15 +1365,18 @@ public:
1365 OP_LOGD("implMode %ld, determin %ld. tensor size %zu, dynamic size %zu, attr size %zu, value depend size %zu.",1365 OP_LOGD("implMode %ld, determin %ld. tensor size %zu, dynamic size %zu, attr size %zu, value depend size %zu.",
1366 implMode, determinConfig, tensors.size(), dynamicCount.size(), attrsVec.size(),1366 implMode, determinConfig, tensors.size(), dynamicCount.size(), attrsVec.size(),
1367 valueDependIndex_.size());1367 valueDependIndex_.size());
1368- OP_LOGD("Finding static kernel with [aicNum %u, aivNum %u, deterministicLevel %lld].",1368+ OP_LOGD("Finding static kernel with [aicNum %u, aivNum %u, deterministicLevel %lld, enablePcie %d].",
1369 GetThreadLocalContext().opConfigInfo_.aicNum_, GetThreadLocalContext().opConfigInfo_.aivNum_,1369 GetThreadLocalContext().opConfigInfo_.aicNum_, GetThreadLocalContext().opConfigInfo_.aivNum_,
1370- determinConfig);1370+ determinConfig, GetThreadLocalContext().opConfigInfo_.usePcieAddr);
1371 NnopbaseStaticTensorNumInfo tensorNumInfo{1371 NnopbaseStaticTensorNumInfo tensorNumInfo{
1372 static_cast<int64_t>(tensors.size()), static_cast<int64_t>(dynamicCount.size()),1372 static_cast<int64_t>(tensors.size()), static_cast<int64_t>(dynamicCount.size()),
1373 static_cast<int64_t>(attrsVec.size()), static_cast<int64_t>(valueDependIndex_.size())};1373 static_cast<int64_t>(attrsVec.size()), static_cast<int64_t>(valueDependIndex_.size())};
1374- NnopbaseStaticRuntimeInfo staticRuntimeInfo{opTypeStr_, GetThreadLocalContext().opConfigInfo_.aicNum_,1374+ NnopbaseStaticRuntimeInfo staticRuntimeInfo{opTypeStr_,
1375- GetThreadLocalContext().opConfigInfo_.aivNum_, implMode,1375+ GetThreadLocalContext().opConfigInfo_.aicNum_,
1376- determinConfig};1376+ GetThreadLocalContext().opConfigInfo_.aivNum_,
1377+ implMode,
1378+ determinConfig,
1379+ GetThreadLocalContext().opConfigInfo_.usePcieAddr};
1377 simpKey = NnopbaseFindStaticKernel((tensors.data()), const_cast<const NnopbaseAttrAddr**>(attrsVec.data()),1380 simpKey = NnopbaseFindStaticKernel((tensors.data()), const_cast<const NnopbaseAttrAddr**>(attrsVec.data()),
1378 valueDependIndex_.data(), &tensorNumInfo, &staticRuntimeInfo);1381 valueDependIndex_.data(), &tensorNumInfo, &staticRuntimeInfo);
1379 if (simpKey != nullptr) {1382 if (simpKey != nullptr) {
@@ -246,10 +246,11 @@ public:
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 auto opCompilerOpt = aclnnOpInfoRecord::OpCompilerOption(248 auto opCompilerOpt = aclnnOpInfoRecord::OpCompilerOption(
249- implMode, GetThreadLocalContext().opConfigInfo_.deterministicLevel_);249+ implMode, GetThreadLocalContext().opConfigInfo_.deterministicLevel_,
250- OP_LOGI("Call OpInfoSerialize, deterministic level %d, impl mode %s. kernel info %d %s.",250+ GetThreadLocalContext().opConfigInfo_.usePcieAddr);
251+ OP_LOGI("Call OpInfoSerialize, deterministic level %d, impl mode %s. kernel info %d %s, enablePcie %d.",
251 opCompilerOpt.deterministic, opCompilerOpt.impl_mode.c_str(), kernelInfo.bin_type,252 opCompilerOpt.deterministic, opCompilerOpt.impl_mode.c_str(), kernelInfo.bin_type,
252- kernelInfo.bin_info.c_str());253+ kernelInfo.bin_info.c_str(), GetThreadLocalContext().opConfigInfo_.usePcieAddr);
253 OP_CHECK_NO_RETURN(aclnnOpInfoRecord::OpInfoSerialize(ctx, opCompilerOpt, &kernelInfo) == 0,254 OP_CHECK_NO_RETURN(aclnnOpInfoRecord::OpInfoSerialize(ctx, opCompilerOpt, &kernelInfo) == 0,
254 OP_LOGW("OpInfoSerialize return failed!"));255 OP_LOGW("OpInfoSerialize return failed!"));
255 }256 }
@@ -135,10 +135,12 @@ public:
135 gert::TilingContext* ctx = PtrCastTo<gert::TilingContext>(tilingCtx_);135 gert::TilingContext* ctx = PtrCastTo<gert::TilingContext>(tilingCtx_);
136 if (op::internal::GetOpProfilingRecordArgFlag()) {136 if (op::internal::GetOpProfilingRecordArgFlag()) {
137 auto opCompilerOpt = aclnnOpInfoRecord::OpCompilerOption(137 auto opCompilerOpt = aclnnOpInfoRecord::OpCompilerOption(
138- tilingParseCtx->GetOpImplModeStr(), GetThreadLocalContext().opConfigInfo_.deterministicLevel_);138+ tilingParseCtx->GetOpImplModeStr(), GetThreadLocalContext().opConfigInfo_.deterministicLevel_,
139- OP_LOGI("Call OpInfoSerialize, deterministic level %d, impl mode %s. kernel info %d %s.",139+ GetThreadLocalContext().opConfigInfo_.usePcieAddr);
140+ OP_LOGI("Call OpInfoSerialize, deterministic level %d, impl mode %s. kernel info %d %s, enable pcie is %d.",
140 opCompilerOpt.deterministic, opCompilerOpt.impl_mode.c_str(),141 opCompilerOpt.deterministic, opCompilerOpt.impl_mode.c_str(),
141- tilingParseCtx->GetOpKernelInfo()->bin_type, tilingParseCtx->GetOpKernelInfo()->bin_info.c_str());142+ tilingParseCtx->GetOpKernelInfo()->bin_type, tilingParseCtx->GetOpKernelInfo()->bin_info.c_str(),
143+ GetThreadLocalContext().opConfigInfo_.usePcieAddr);
142 OP_CHECK_NO_RETURN(144 OP_CHECK_NO_RETURN(
143 aclnnOpInfoRecord::OpInfoSerialize(ctx, opCompilerOpt, tilingParseCtx->GetOpKernelInfo()) == 0,145 aclnnOpInfoRecord::OpInfoSerialize(ctx, opCompilerOpt, tilingParseCtx->GetOpKernelInfo()) == 0,
144 OP_LOGW("OpInfoSerialize return failed!"));146 OP_LOGW("OpInfoSerialize return failed!"));
@@ -24,11 +24,13 @@
24#include "executor/indv_bininfo.h"24#include "executor/indv_bininfo.h"
25#include "executor/indv_args_pool.h"25#include "executor/indv_args_pool.h"
26#include "executor/indv_cache_key_builder.h"26#include "executor/indv_cache_key_builder.h"
27+#include "executor/static_kernel_helper.h"
27#include "profiling/prof_api.h"28#include "profiling/prof_api.h"
28#include "aclnn/aclnn_base.h"29#include "aclnn/aclnn_base.h"
29#include "thread_local_context.h"30#include "thread_local_context.h"
30#include "opdev/platform.h"31#include "opdev/platform.h"
31#include "op_dfx_internal.h"32#include "op_dfx_internal.h"
33+#include "op_feature_internal.h"
32#include "nnopbase_error_msg.h"34#include "nnopbase_error_msg.h"
33 35 
34void NnopbaseOpLogE(const aclnnStatus code, const NnopbaseChar* const expr) { OP_LOGE(code, "Check %s failed", expr); }36void NnopbaseOpLogE(const aclnnStatus code, const NnopbaseChar* const expr) { OP_LOGE(code, "Check %s failed", expr); }
@@ -41,27 +43,6 @@ constexpr size_t MAX_PRINT_NUM = 128U;
41 return; \43 return; \
42 }44 }
43 45 
44-static inline std::string NnopbaseBuildShapeStridesStr(const aclTensor* const tensor)
45-{
46- const auto& shape = tensor->GetViewShape();
47- const auto& strides = tensor->GetViewStrides();
48- std::stringstream ss;
49- ss << "shape=[";
50- for (size_t i = 0U; i < shape.GetDimNum(); i++) {
51- if (i > 0)
52- ss << ",";
53- ss << shape.GetDim(i);
54- }
55- ss << "], strides=[";
56- for (size_t i = 0U; i < strides.size(); i++) {
57- if (i > 0)
58- ss << ",";
59- ss << strides[i];
60- }
61- ss << "]";
62- return ss.str();
63-}
64- 
65static inline void NnopbaseLogTensorInfo(const char* const paramName, const aclTensor* const tensor,46static inline void NnopbaseLogTensorInfo(const char* const paramName, const aclTensor* const tensor,
66 const uint32_t index)47 const uint32_t index)
67{48{
@@ -70,10 +51,35 @@ static inline void NnopbaseLogTensorInfo(const char* const paramName, const aclT
70 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);51 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);
71 return;52 return;
72 }53 }
73- OP_LOGI("[DFX] %s[%u] dtype=%s, format=%s, placement=%d, addr=%p, %s, offset=%lld.", paramName, index,54+ OP_LOGI("[DFX] %s[%u] %s.", paramName, index, tensor->ToString().GetString());
74- op::ToString(tensor->GetDataType()).GetString(), op::ToString(tensor->GetStorageFormat()).GetString(),55+}
75- static_cast<int32_t>(tensor->GetPlacement()), tensor->GetData(),56+ 
76- NnopbaseBuildShapeStridesStr(tensor).c_str(), static_cast<int64_t>(tensor->GetViewOffset()));57+static inline void NnopbaseUpdatePcieThroughFlag(NnopbaseExecutor* const executor, const aclTensor* const tensor)
58+{
59+ if ((executor == nullptr) || (tensor == nullptr) || executor->isEnablePcie ||
60+ !op::internal::IsPcieThroughEnabled()) {
61+ return;
62+ }
63+ void* const addr = tensor->GetStorageAddr();
64+ if ((addr != nullptr) && op::internal::IsTensorAddrInPcieRange(addr)) {
65+ executor->isEnablePcie = true;
66+ OP_LOGI("Storage address %p is in PCIe range, enable PCIe through.", addr);
67+ }
68+}
69+ 
70+static inline void NnopbaseUpdatePcieThroughFlag(NnopbaseExecutor* const executor,
71+ const aclTensorList* const tensorList)
72+{
73+ if ((executor == nullptr) || (tensorList == nullptr) || executor->isEnablePcie ||
74+ !op::internal::IsPcieThroughEnabled()) {
75+ return;
76+ }
77+ for (uint64_t i = 0U; i < tensorList->Size(); ++i) {
78+ NnopbaseUpdatePcieThroughFlag(executor, (*tensorList)[i]);
79+ if (executor->isEnablePcie) {
80+ return;
81+ }
82+ }
77}83}
78 84 
79static inline void NnopbaseLogTensorListInfo(const char* const paramName, const aclTensorList* const tensorList,85static inline void NnopbaseLogTensorListInfo(const char* const paramName, const aclTensorList* const tensorList,
@@ -84,16 +90,14 @@ static inline void NnopbaseLogTensorListInfo(const char* const paramName, const
84 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);90 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);
85 return;91 return;
86 }92 }
87- OP_LOGI("[DFX] %s[%u] dtype=aclTensorList, size=%llu, addr=%p.", paramName, index, tensorList->Size(),93+ OP_LOGI("[DFX] %s[%u] aclTensorList size=%lu.", paramName, index, tensorList->Size());
88- static_cast<const void*>(tensorList));94+ for (uint64_t i = 0U; i < tensorList->Size(); ++i) {
89- for (uint64_t i = 0; i < tensorList->Size(); i++) {95+ const aclTensor* const tensor = (*tensorList)[i];
90- if ((*tensorList)[i] != nullptr) {96+ if (tensor == nullptr) {
91- const auto& t = (*tensorList)[i];97+ OP_LOGI("[DFX] %s[%u][%lu] addr=nullptr.", paramName, index, i);
92- OP_LOGI("[DFX] %s[%u][%llu] dtype=%s, format=%s, placement=%d, addr=%p, %s, offset=%lld.", paramName, index,98+ continue;
93- i, op::ToString(t->GetDataType()).GetString(), op::ToString(t->GetStorageFormat()).GetString(),
94- static_cast<int32_t>(t->GetPlacement()), t->GetData(), NnopbaseBuildShapeStridesStr(t).c_str(),
95- static_cast<int64_t>(t->GetViewOffset()));
96 }99 }
100+ OP_LOGI("[DFX] %s[%u][%lu] %s.", paramName, index, i, tensor->ToString().GetString());
97 }101 }
98}102}
99 103 
@@ -105,8 +109,7 @@ static inline void NnopbaseLogScalarInfo(const char* const paramName, const aclS
105 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);109 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);
106 return;110 return;
107 }111 }
108- OP_LOGI("[DFX] %s[%u] info=%s, size=%llu, addr=%p.", paramName, index, scalar->ToString().GetString(),112+ OP_LOGI("[DFX] %s[%u] %s.", paramName, index, scalar->ToString().GetString());
109- static_cast<uint64_t>(scalar->Size()), static_cast<const void*>(scalar));
110}113}
111 114 
112static inline void NnopbaseLogScalarListInfo(const char* const paramName, const aclScalarList* const scalarList,115static inline void NnopbaseLogScalarListInfo(const char* const paramName, const aclScalarList* const scalarList,
@@ -117,21 +120,7 @@ static inline void NnopbaseLogScalarListInfo(const char* const paramName, const
117 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);120 OP_LOGI("[DFX] %s[%u] addr=nullptr.", paramName, index);
118 return;121 return;
119 }122 }
120- OP_LOGI("[DFX] %s[%u] dtype=ScalarList, size=%llu, addr=%p.", paramName, index, scalarList->Size(),123+ OP_LOGI("[DFX] %s[%u] aclScalarList[%s].", paramName, index, scalarList->ToString().GetString());
121- static_cast<const void*>(scalarList));
122- const uint64_t totalSize = scalarList->Size();
123- for (uint64_t i = 0U; i < totalSize; i++) {
124- if (i >= static_cast<uint64_t>(MAX_PRINT_NUM)) {
125- OP_LOGI("[DFX] %s[%u][%llu]...", paramName, index, i);
126- break;
127- }
128- const aclScalar* const scalar = (*scalarList)[i];
129- if (scalar != nullptr) {
130- OP_LOGI("[DFX] %s[%u][%llu] info=%s, size=%llu, addr=%p.", paramName, index, i,
131- scalar->ToString().GetString(), static_cast<uint64_t>(scalar->Size()),
132- static_cast<const void*>(scalar));
133- }
134- }
135}124}
136 125 
137template <typename T>126template <typename T>
@@ -143,30 +132,7 @@ static inline void NnopbaseLogArrayInfo(const char* const typeName, const char*
143 OP_LOGI("[DFX] %s[%zu] dtype=%s, addr=nullptr.", paramName, index, typeName);132 OP_LOGI("[DFX] %s[%zu] dtype=%s, addr=nullptr.", paramName, index, typeName);
144 return;133 return;
145 }134 }
146- const size_t size = array->Size();135+ OP_LOGI("[DFX] %s[%zu] %s%s.", paramName, index, typeName, array->ToString().GetString());
147- const void* data = array->GetData();
148- std::stringstream ss;
149- ss << "[";
150- if (data != nullptr) {
151- for (size_t i = 0U; i < std::min(size, MAX_PRINT_NUM); i++) {
152- if (i > 0)
153- ss << ",";
154- if constexpr (std::is_same<T, aclIntArray>::value) {
155- ss << static_cast<const int64_t*>(data)[i];
156- } else if constexpr (std::is_same<T, aclBoolArray>::value) {
157- ss << static_cast<const bool*>(data)[i];
158- } else if constexpr (std::is_same<T, aclFloatArray>::value) {
159- ss << static_cast<const float*>(data)[i];
160- }
161- }
162- if (size > MAX_PRINT_NUM)
163- ss << ",...";
164- } else {
165- ss << "<null data>";
166- }
167- ss << "]";
168- OP_LOGI("[DFX] %s[%zu] dtype=%s, size=%zu, addr=%p, values=%s.", paramName, index, typeName, size, data,
169- ss.str().c_str());
170}136}
171 137 
172static inline void NnopbaseLogAttrValueInfo(const NnopbaseAttrDtype dtype, const void* const addr, const size_t attrLen,138static inline void NnopbaseLogAttrValueInfo(const NnopbaseAttrDtype dtype, const void* const addr, const size_t attrLen,
@@ -267,6 +233,8 @@ aclnnStatus NnopbaseInit()
267 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseCollectorWork(binCollector.get()));233 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseCollectorWork(binCollector.get()));
268 gBinCollector = binCollector.release();234 gBinCollector = binCollector.release();
269 }235 }
236+ OP_CHECK_NO_RETURN(op::internal::InitPcieThroughInfo() == ACLNN_SUCCESS,
237+ OP_LOGW("Failed to execute InitPcieThroughInfo."));
270 NnopbaseExecutorSpaceSetInit(&g_nnopbaseSpaceSet);238 NnopbaseExecutorSpaceSetInit(&g_nnopbaseSpaceSet);
271 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseExecutorSetGlobalConfig());239 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseExecutorSetGlobalConfig());
272 PrintNnopbaseInitTimeStampInfo();240 PrintNnopbaseInitTimeStampInfo();
@@ -397,6 +365,7 @@ aclnnStatus NnopbaseAddInput(void* executor, const aclTensor* tensor, const uint
397 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);365 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);
398 NnopbaseLogTensorInfo("AddInput", tensor, index);366 NnopbaseLogTensorInfo("AddInput", tensor, index);
399 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);367 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);
368+ NnopbaseUpdatePcieThroughFlag(nnopExecutor, tensor);
400 const auto tensors = &nnopExecutor->ownArgs.inputs;369 const auto tensors = &nnopExecutor->ownArgs.inputs;
401 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {370 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {
402 tensors->paramDescs.instances[index].tensor = tensor;371 tensors->paramDescs.instances[index].tensor = tensor;
@@ -413,6 +382,7 @@ aclnnStatus NnopbaseAddIgnoreContinuesInput(void* executor, const aclTensor* ten
413 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);382 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);
414 NnopbaseLogTensorInfo("AddIgnoreContInput", tensor, index);383 NnopbaseLogTensorInfo("AddIgnoreContInput", tensor, index);
415 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);384 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);
385+ NnopbaseUpdatePcieThroughFlag(nnopExecutor, tensor);
416 const auto tensors = &nnopExecutor->ownArgs.inputs;386 const auto tensors = &nnopExecutor->ownArgs.inputs;
417 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {387 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {
418 tensors->paramDescs.instances[index].ignoreCont = true;388 tensors->paramDescs.instances[index].ignoreCont = true;
@@ -499,6 +469,7 @@ aclnnStatus NnopbaseAddDynamicInput(void* executor, const aclTensorList* tensorL
499 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);469 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);
500 NnopbaseLogTensorListInfo("AddDynamicInput", tensorList, index);470 NnopbaseLogTensorListInfo("AddDynamicInput", tensorList, index);
501 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);471 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);
472+ NnopbaseUpdatePcieThroughFlag(nnopExecutor, tensorList);
502 const auto tensors = &nnopExecutor->ownArgs.inputs;473 const auto tensors = &nnopExecutor->ownArgs.inputs;
503 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {474 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {
504 tensors->paramDescs.instances[index].tensorList = tensorList;475 tensors->paramDescs.instances[index].tensorList = tensorList;
@@ -515,6 +486,7 @@ aclnnStatus NnopbaseAddIgnoreContiguousDynamicInput(void* executor, const aclTen
515 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);486 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);
516 NnopbaseLogTensorListInfo("AddIgnoreContDynInput", tensorList, index);487 NnopbaseLogTensorListInfo("AddIgnoreContDynInput", tensorList, index);
517 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);488 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);
489+ NnopbaseUpdatePcieThroughFlag(nnopExecutor, tensorList);
518 const auto tensors = &nnopExecutor->ownArgs.inputs;490 const auto tensors = &nnopExecutor->ownArgs.inputs;
519 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {491 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {
520 tensors->paramDescs.instances[index].ignoreCont = true;492 tensors->paramDescs.instances[index].ignoreCont = true;
@@ -531,6 +503,7 @@ aclnnStatus NnopbaseAddOutput(void* executor, const aclTensor* tensor, const uin
531 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);503 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);
532 NnopbaseLogTensorInfo("AddOutput", tensor, index);504 NnopbaseLogTensorInfo("AddOutput", tensor, index);
533 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);505 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);
506+ NnopbaseUpdatePcieThroughFlag(nnopExecutor, tensor);
534 const auto tensors = &nnopExecutor->ownArgs.outputs;507 const auto tensors = &nnopExecutor->ownArgs.outputs;
535 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {508 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {
536 tensors->paramDescs.instances[index].tensor = tensor;509 tensors->paramDescs.instances[index].tensor = tensor;
@@ -554,7 +527,11 @@ aclnnStatus NnopbaseAddOutputShapeDependTensor(void* executor, aclTensor* tensor
554 NnopbaseTensors* tensors = &(((NnopbaseExecutor*)executor)->ownArgs.outputs);527 NnopbaseTensors* tensors = &(((NnopbaseExecutor*)executor)->ownArgs.outputs);
555 tensors->outPutShapeSize += sizeof(uint64_t) * 9U; // 9 表示1个count和8个dim528 tensors->outPutShapeSize += sizeof(uint64_t) * 9U; // 9 表示1个count和8个dim
556 tensors->outPutShapeMap[index] = tensor; // 覆盖刷新tensor地址529 tensors->outPutShapeMap[index] = tensor; // 覆盖刷新tensor地址
557- OP_LOGI("[DFX] AddShapeDependOutputTensor[%u] addr=%p.", index, tensor);530+ if (tensor == nullptr) {
531+ OP_LOGI("[DFX] AddShapeDependOutputTensor[%u] addr=nullptr.", index);
532+ } else {
533+ OP_LOGI("[DFX] AddShapeDependOutputTensor[%u] %s.", index, tensor->ToString().GetString());
534+ }
558 return NnopbaseAddOutput(executor, tensor, index);535 return NnopbaseAddOutput(executor, tensor, index);
559}536}
560 537 
@@ -563,6 +540,7 @@ aclnnStatus NnopbaseAddDynamicOutput(void* executor, const aclTensorList* tensor
563 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);540 NNOPBASE_ASSERT_NOTNULL_RETVAL(executor);
564 NnopbaseLogTensorListInfo("AddDynamicOutput", tensorList, index);541 NnopbaseLogTensorListInfo("AddDynamicOutput", tensorList, index);
565 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);542 NnopbaseExecutor* nnopExecutor = PtrCastTo<NnopbaseExecutor>(executor);
543+ NnopbaseUpdatePcieThroughFlag(nnopExecutor, tensorList);
566 const auto tensors = &nnopExecutor->ownArgs.outputs;544 const auto tensors = &nnopExecutor->ownArgs.outputs;
567 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {545 if (NnopbaseIsV2CacheKeyEnabled(nnopExecutor)) {
568 tensors->paramDescs.instances[index].tensorList = tensorList;546 tensors->paramDescs.instances[index].tensorList = tensorList;
@@ -1121,34 +1099,8 @@ const NnopbaseChar* NnopbaseFindStaticKernel(const aclTensor* tensors[], const N
1121 return nullptr;1099 return nullptr;
1122 }1100 }
1123 }1101 }
1124- thread_local static NnopbaseUChar verbose[NNOPBASE_MAX_STATICKEY_LEN];1102+ return Indv::StaticKernelHelper::FindStaticKernelPath(tensors, attrs, valueDepend, tensorNumInfo,
1125- NnopbaseUChar* verKey1 = verbose;1103+ staticRuntimeInfo);
1126- NnopbaseRegInfoKey regInfoKey;
1127- regInfoKey.opType = staticRuntimeInfo->opType;
1128- regInfoKey.hashKey = static_cast<uint64_t>(
1129- NnopbaseHashBinary(PtrCastTo<NnopbaseUChar>(regInfoKey.opType.c_str()), regInfoKey.opType.size()) %
1130- NNOPBASE_NORM_MAX_BIN_BUCKETS);
1131- OP_LOGI("OpType is %s, hashkey is %lu.", regInfoKey.opType.c_str(), regInfoKey.hashKey);
1132- 
1133- verKey1 = NnopbaseCollectorGenStaticKey(verKey1, &regInfoKey, tensorNumInfo, tensors, attrs,
1134- staticRuntimeInfo->implMode, staticRuntimeInfo->deterMode, valueDepend,
1135- true);
1136- 
1137- StaticKernelPlatformInfo platformInfo{{staticRuntimeInfo->aicNum, staticRuntimeInfo->aivNum},
1138- static_cast<int8_t>(staticRuntimeInfo->deterMode)};
1139- auto simplifiedKey = NnopbaseCollectorGetStaticKernelBin(regInfoKey.opType.c_str(), regInfoKey.hashKey, verbose,
1140- uint32_t(verKey1 - verbose), &platformInfo);
1141- if (simplifiedKey != nullptr) {
1142- return simplifiedKey;
1143- } else {
1144- OP_LOGW("Cannot find static kernel bin with stride information, trying to find without stride again.");
1145- NnopbaseUChar* verKey2 = verbose;
1146- verKey2 = NnopbaseCollectorGenStaticKey(verKey2, &regInfoKey, tensorNumInfo, tensors, attrs,
1147- staticRuntimeInfo->implMode, staticRuntimeInfo->deterMode, valueDepend,
1148- false);
1149- return NnopbaseCollectorGetStaticKernelBin(regInfoKey.opType.c_str(), regInfoKey.hashKey, verbose,
1150- uint32_t(verKey2 - verbose), &platformInfo);
1151- }
1152}1104}
1153 1105 
1154aclnnStatus NnopbaseGetStreamAndEvent(const aclrtStream stream, aclrtStream* subStream, aclrtEvent* evtA,1106aclnnStatus NnopbaseGetStreamAndEvent(const aclrtStream stream, aclrtStream* subStream, aclrtEvent* evtA,
@@ -92,6 +92,12 @@ bool ArgsPool::IsArgsMatch(NnopbaseExecutorArgs* const args, NnopbaseExecutor* e
92bool ArgsPool::MatchArgs(NnopbaseExecutor* executor)92bool ArgsPool::MatchArgs(NnopbaseExecutor* executor)
93{93{
94 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kMatchCacheStart);94 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kMatchCacheStart);
95+ if (executor->isEnablePcie) {
96+ executor->ownArgs.enableCache = false;
97+ OP_LOGI("Op %s skip args cache because current op has tensor using PCIe addr.", executor->opType);
98+ RecordNnopbaseTime(executor, NnopbaseTimeIdx::kMatchCacheEnd);
99+ return false;
100+ }
95 if (maxCacheNum == 0U) {101 if (maxCacheNum == 0U) {
96 executor->ownArgs.enableCache = false;102 executor->ownArgs.enableCache = false;
97 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kMatchCacheEnd);103 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kMatchCacheEnd);
@@ -235,4 +241,4 @@ void ArgsPool::ReleaseFixedCache(NnopbaseExecutorArgs* const args)
235 OP_LOGI("Release fixed args cache successfully, current fixed cache pool size is %zu", fixedCacheMap.size());241 OP_LOGI("Release fixed args cache successfully, current fixed cache pool size is %zu", fixedCacheMap.size());
236 return;242 return;
237}243}
238-} // namespace nnopbase244+} // namespace nnopbase
@@ -10,6 +10,7 @@
10#ifndef INDV_BIN_INFO_H_10#ifndef INDV_BIN_INFO_H_
11#define INDV_BIN_INFO_H_11#define INDV_BIN_INFO_H_
12 12 
13+#include <algorithm>
13#include <string>14#include <string>
14#include "securec.h"15#include "securec.h"
15#include "utils/indv_dlist.h"16#include "utils/indv_dlist.h"
@@ -66,6 +67,24 @@ struct BinInfoKey {
66 std::vector<NnopbaseUChar> verbose;67 std::vector<NnopbaseUChar> verbose;
67 uint32_t len = 0U;68 uint32_t len = 0U;
68 uint32_t bufLen = 0U;69 uint32_t bufLen = 0U;
70+ 
71+ void Clear()
72+ {
73+ verbose = std::vector<NnopbaseUChar>();
74+ len = 0U;
75+ bufLen = 0U;
76+ hashKey = 0U;
77+ }
78+ 
79+ void Reset()
80+ {
81+ if (!verbose.empty()) {
82+ std::fill(verbose.begin(), verbose.end(), 0U);
83+ bufLen = static_cast<uint32_t>(verbose.size());
84+ }
85+ len = 0U;
86+ hashKey = 0U;
87+ }
69};88};
70 89 
71enum NnopbaseTaskRation {90enum NnopbaseTaskRation {
@@ -202,123 +202,6 @@ static constexpr int32_t NNOPBASE_COMPILE_ARGS_INDEX = 1;
202 202 
203NnopbaseBinCollector* gBinCollector = nullptr;203NnopbaseBinCollector* gBinCollector = nullptr;
204 204 
205-// if usingStride = false,
206-// [OpType, determin, precision, {dtype,format,shape}....attrs] to generate staticKey
207-// if usingStride = true,
208-// [OpType, determin, precision, {dtype,format,shape,stride,offset}....attrs] to generate staticKey
209-NnopbaseUChar* NnopbaseCollectorGenStaticKey(NnopbaseUChar* verKey, const NnopbaseRegInfoKey* const regInfoKey,
210- const NnopbaseStaticTensorNumInfo* const tensorNumInfo,
211- const aclTensor* tensors[], const NnopbaseAttrAddr* attrs[],
212- const int64_t implMode, const int64_t deterMin,
213- const int64_t* const vDepend, const bool usingStride)
214-{
215- verKey = NnopbaseAppendBinary(verKey, NNOPBASE_MAX_STATICKEY_LEN, &(regInfoKey->opType[0U]),
216- regInfoKey->opType.size());
217- uint64_t determinLevel = (deterMin == 0U) ? 0U : 1U;
218- verKey = NnopbaseAppend8Byte(verKey, determinLevel);
219- verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(implMode));
220- OP_LOGI("Get deterministic is %llu, high precision is %lld", determinLevel, implMode);
221- 
222- std::vector<bool> valueDepend(tensorNumInfo->numTensors, false);
223- for (int64_t i = 0; i < tensorNumInfo->numValueDepend; i++) {
224- valueDepend[vDepend[i]] = true;
225- }
226- ge::DataType dtype = ge::DT_INT32;
227- ge::Format format = ge::FORMAT_ND;
228- const NnopbaseUChar* addr = nullptr;
229- // input and output
230- for (int64_t i = 0; i < tensorNumInfo->numTensors; i++) {
231- if (tensors[i] == nullptr) {
232- verKey = NnopbaseAppend8Byte(verKey, '_');
233- continue;
234- }
235- 
236- dtype = tensors[i]->GetDataType();
237- verKey = NnopbaseAppend8Byte(verKey, dtype);
238- format = tensors[i]->GetStorageFormat();
239- verKey = NnopbaseAppend8Byte(verKey, format);
240- OP_LOGI("Get tensor[%ld] datatype is %d, format is %d.", i, dtype, format);
241- const gert::Shape& shape = tensors[i]->GetStorageShape();
242- const size_t dimNum = shape.GetDimNum();
243- for (size_t j = 0U; j < dimNum; j++) {
244- verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(shape.GetDim(j)));
245- }
246- if (usingStride) {
247- const auto stride = tensors[i]->GetTensor()->GetStride();
248- const size_t strideDimNum = stride.GetDimNum();
249- const int64_t offset = tensors[i]->GetTensor()->GetOffset();
250- std::string strideStr = "[";
251- for (size_t j = 0U; j < strideDimNum; j++) {
252- verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(stride.GetStride(j)));
253- strideStr += std::to_string(stride.GetStride(j));
254- if (j != strideDimNum - 1) {
255- strideStr += ", ";
256- }
257- }
258- strideStr += "]";
259- OP_LOGI("Tensor[%ld] strideDim is %zu, stride is %s, offset is %lld.", i, strideDimNum, strideStr.c_str(),
260- offset);
261- verKey = NnopbaseAppend8Byte(verKey, offset);
262- }
263- if (valueDepend[i]) {
264- const int64_t elementSize = tensors[i]->Size();
265- addr = op::internal::PtrCastTo<NnopbaseUChar>(tensors[i]->GetData());
266- const size_t typeSize = op::TypeSize(tensors[i]->GetDataType());
267- for (int64_t k = 0; k < elementSize; k++) {
268- verKey = NnopbaseExecutor8ByteCopy(typeSize, verKey, addr + typeSize * k);
269- }
270- }
271- }
272- // attrs
273- if (tensorNumInfo->numAttrs > 0) {
274- size_t length = 0U;
275- for (int64_t j = 0; j < tensorNumInfo->numAttrs; j++) {
276- if (attrs[j] == nullptr) {
277- verKey = NnopbaseAppend8Byte(verKey, '_');
278- continue;
279- }
280- if (attrs[j]->addr == nullptr || attrs[j]->size == 0U) {
281- OP_LOGW("Attr[%zu] addr is nullptr or size is 0, skip concat simplifiedKey.", j);
282- continue;
283- };
284- if (!attrs[j]->isVector) {
285- addr = op::internal::PtrCastTo<const NnopbaseUChar>(attrs[j]->addr);
286- length = attrs[j]->size;
287- verKey = NnopbaseExecutor8ByteCopy(length, verKey, addr);
288- } else {
289- const size_t elementSize = attrs[j]->elementSize;
290- if (attrs[j]->elementSize == 0U) {
291- OP_LOGW("Attr[%zu] elementSize is 0, skip concat simplifiedKey.", j);
292- continue;
293- }
294- const size_t elementSizeNumber = attrs[j]->size / elementSize;
295- for (size_t i = 0U; i < elementSizeNumber; i++) {
296- addr = op::internal::PtrCastTo<const NnopbaseUChar>(attrs[j]->addr) + elementSize * i;
297- verKey = NnopbaseExecutor8ByteCopy(elementSize, verKey, addr);
298- }
299- }
300- }
301- }
302- return verKey;
303-}
304- 
305-const NnopbaseChar* NnopbaseCollectorGetStaticKernelBin(const NnopbaseChar* const opType, const uint64_t key,
306- const NnopbaseUChar* verbose, const uint32_t verbLen,
307- const StaticKernelPlatformInfo* const platformInfo)
308-{
309- NnopbaseRegInfo* regInfo = NnopbaseCollectorFindRegInfoInTbl(gBinCollector, opType, key);
310- if (regInfo == nullptr) {
311- return nullptr;
312- }
313- const size_t hashKey = NnopbaseHashBinary(verbose, static_cast<size_t>(verbLen)) % NNOPBASE_NORM_MAX_BIN_BUCKETS;
314- const NnopbaseBinInfo* binInfo = NnopbaseCollectorFindBinInfo(regInfo, hashKey, verbose, verbLen, platformInfo);
315- if (binInfo == nullptr) {
316- return nullptr;
317- }
318- OP_LOGI("Found %s static kernel, verboseLen: %u, hashKey is: %zu.", opType, verbLen, hashKey);
319- return binInfo->binPath.c_str();
320-}
321- 
322aclnnStatus NnopbaseCollectorSetTiling(const NnopbaseJsonInfo& jsonInfo, TilingFun* const tiling,205aclnnStatus NnopbaseCollectorSetTiling(const NnopbaseJsonInfo& jsonInfo, TilingFun* const tiling,
323 GenSimplifiedKeyFun* const genSimplifiedKey,206 GenSimplifiedKeyFun* const genSimplifiedKey,
324 gert::OppImplVersionTag oppImplVersion)207 gert::OppImplVersionTag oppImplVersion)
@@ -12,6 +12,7 @@
12#define INDV_COLLECTOR_H_12#define INDV_COLLECTOR_H_
13 13 
14#include <string>14#include <string>
15+#include <vector>
15#include "nlohmann/json.hpp"16#include "nlohmann/json.hpp"
16#include "utils/indv_base.h"17#include "utils/indv_base.h"
17#include "utils/indv_dlist.h"18#include "utils/indv_dlist.h"
@@ -90,14 +91,8 @@ aclnnStatus NnopbaseCollectorSetTiling(const NnopbaseJsonInfo& jsonInfo, TilingF
90 GenSimplifiedKeyFun* const genSimplifiedKey,91 GenSimplifiedKeyFun* const genSimplifiedKey,
91 gert::OppImplVersionTag oppImplVersion);92 gert::OppImplVersionTag oppImplVersion);
92bool NnopbaseReadConfigFile(const std::string& configPath, std::vector<std::string>& subPath);93bool NnopbaseReadConfigFile(const std::string& configPath, std::vector<std::string>& subPath);
93-NnopbaseUChar* NnopbaseCollectorGenStaticKey(NnopbaseUChar* verKey, const NnopbaseRegInfoKey* const regInfoKey,94+NnopbaseRegInfo* NnopbaseCollectorFindRegInfoInTbl(const NnopbaseBinCollector* const collector,
94- const NnopbaseStaticTensorNumInfo* const tensorNumInfo,95+ const NnopbaseChar* const opType, const uint64_t hashKey);
95- const aclTensor* tensors[], const NnopbaseAttrAddr* attrs[],
96- const int64_t implMode, const int64_t deterMin,
97- const int64_t* const vDepend, const bool usingStride);
98-const char* NnopbaseCollectorGetStaticKernelBin(const NnopbaseChar* const opType, const uint64_t key,
99- const NnopbaseUChar* verbose, const uint32_t verbLen,
100- const StaticKernelPlatformInfo* const platformInfo = nullptr);
101aclnnStatus NnopbaseCollectorGetStaticKernelPathAndReadConfig(NnopbaseBinCollector* const collector,96aclnnStatus NnopbaseCollectorGetStaticKernelPathAndReadConfig(NnopbaseBinCollector* const collector,
102 const std::string& basePath = "");97 const std::string& basePath = "");
103aclnnStatus NnopbaseCollectorDeleteStaticBins(NnopbaseRegInfo* regInfo);98aclnnStatus NnopbaseCollectorDeleteStaticBins(NnopbaseRegInfo* regInfo);
@@ -137,9 +132,6 @@ static inline void NnopbaseCollectorInitBinTbl(BinTbl* binTbl)
137 binTbl->buckets[i].isVisit = false;132 binTbl->buckets[i].isVisit = false;
138 }133 }
139}134}
140- 
141-NnopbaseRegInfo* NnopbaseCollectorFindRegInfoInTbl(const NnopbaseBinCollector* const collector,
142- const NnopbaseChar* const opType, const uint64_t hashKey);
143#ifdef __cplusplus135#ifdef __cplusplus
144}136}
145#endif137#endif
@@ -24,6 +24,7 @@
24#include "indv_mc2_aicpu.h"24#include "indv_mc2_aicpu.h"
25#include "opdev/data_type_utils.h"25#include "opdev/data_type_utils.h"
26#include "kernel_utils.h"26#include "kernel_utils.h"
27+#include "static_kernel_helper.h"
27#include "bridge_dfx.h"28#include "bridge_dfx.h"
28#include "acl/acl_rt.h"29#include "acl/acl_rt.h"
29#ifndef PRODUCT_SIDE_IS_DEVICE30#ifndef PRODUCT_SIDE_IS_DEVICE
@@ -79,8 +80,8 @@ aclnnStatus RegisterCustomizedCallback(NnopbaseExecutor* const executor, Nnopbas
79 (METADEF_VERSION_NUM >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER)80 (METADEF_VERSION_NUM >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER)
80 int32_t metadefVerNum = -1;81 int32_t metadefVerNum = -1;
81 int32_t runtimeVerNum = -1;82 int32_t runtimeVerNum = -1;
82- auto aclRetForMetadef = aclsysGetVersionNum("metadef", &metadefVerNum);83+ static auto aclRetForMetadef = aclsysGetVersionNum("metadef", &metadefVerNum);
83- auto aclRetForRts = aclsysGetVersionNum("runtime", &runtimeVerNum);84+ static auto aclRetForRts = aclsysGetVersionNum("runtime", &runtimeVerNum);
84 if (aclRetForMetadef == ACL_SUCCESS && aclRetForRts == ACL_SUCCESS &&85 if (aclRetForMetadef == ACL_SUCCESS && aclRetForRts == ACL_SUCCESS &&
85 metadefVerNum >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER &&86 metadefVerNum >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER &&
86 runtimeVerNum >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER) {87 runtimeVerNum >= CUSTOM_EXCEPTION_CALL_BACK_SUPPORT_VER) {
@@ -124,25 +125,6 @@ void ResizeExecutorArgsBuf(NnopbaseExecutor* executor)
124 OP_LOGI("Finish resizing %s args buffer.", executor->opType);125 OP_LOGI("Finish resizing %s args buffer.", executor->opType);
125}126}
126 127 
127-bool GenStaticKeyAndFindStaticBin(NnopbaseExecutor* executor, bool usingStride)
128-{
129- if (NnopbaseExecutorGenStaticKey(executor, usingStride) != OK) {
130- return false;
131- }
132- // 已在缓存匹配流程调用控核接口,保证executor的coreNum/determisiticLevel不为非法值
133- StaticKernelPlatformInfo platformInfo{NnopbaseCoreNum{executor->coreNum.aicNum, executor->coreNum.aivNum},
134- static_cast<int8_t>(executor->deterministicLevel)};
135- auto binInfo = NnopbaseCollectorFindBinInfo(executor->regInfo, executor->binInfoKey.hashKey,
136- &(executor->binInfoKey.verbose[0U]), executor->binInfoKey.len,
137- &platformInfo);
138- if ((binInfo != nullptr) && (NnopbaseKernelRegister(executor, binInfo) == OK)) {
139- executor->args->binInfo = binInfo;
140- executor->hasTiling = false;
141- return true;
142- }
143- return false;
144-}
145- 
146void UpdateStaticKernelTilingInfo(NnopbaseExecutor* executor)128void UpdateStaticKernelTilingInfo(NnopbaseExecutor* executor)
147{129{
148 OP_LOGI("Start updating %s tilingInfo.", executor->opType);130 OP_LOGI("Start updating %s tilingInfo.", executor->opType);
@@ -812,10 +794,13 @@ aclnnStatus NnopbaseKernelRegister(NnopbaseExecutor* executor, NnopbaseBinInfo*
812 794 
813bool NnopbaseExecutorGetStaticBinInfo(NnopbaseExecutor* const executor)795bool NnopbaseExecutorGetStaticBinInfo(NnopbaseExecutor* const executor)
814{796{
815- if (!GenStaticKeyAndFindStaticBin(executor, true)) {797+ executor->binInfoKey.Clear();
816- OP_LOGW("Cannot find static kernel bin with stride information, trying to find without stride again.");798+ auto binInfo = Indv::StaticKernelHelper::FindStaticBinInfo(executor, executor->binInfoKey);
817- return GenStaticKeyAndFindStaticBin(executor, false);799+ if (binInfo == nullptr) {
800+ return false;
818 }801 }
802+ executor->args->binInfo = binInfo;
803+ executor->hasTiling = false;
819 return true;804 return true;
820}805}
821 806 
@@ -948,6 +933,10 @@ aclnnStatus NnopbaseExecutorTilingAndUpdateBinInfo(NnopbaseExecutor* executor)
948 // find static bin933 // find static bin
949 if (executor->regInfo->hasStaticShapeBin && NnopbaseExecutorGetStaticBinInfo(executor)) {934 if (executor->regInfo->hasStaticShapeBin && NnopbaseExecutorGetStaticBinInfo(executor)) {
950 OP_LOGI("Op[%s] has found static bin.", executor->opType);935 OP_LOGI("Op[%s] has found static bin.", executor->opType);
936+ if (NnopbaseKernelRegister(executor, executor->args->binInfo) != OK) {
937+ executor->binInfoKey.Clear();
938+ return ACLNN_ERR_PARAM_INVALID;
939+ }
951 UpdateStaticKernelTilingInfo(executor);940 UpdateStaticKernelTilingInfo(executor);
952 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kFindStaticEnd);941 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kFindStaticEnd);
953 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kFindBinEnd);942 RecordNnopbaseTime(executor, NnopbaseTimeIdx::kFindBinEnd);
@@ -1090,7 +1079,13 @@ aclnnStatus NnopbaseExecutorMatchCache(NnopbaseExecutor* executor)
1090 }1079 }
1091 1080 
1092 // 开启dump不开启缓存匹配1081 // 开启dump不开启缓存匹配
1093- if ((!g_nnopbaseSysCfgParams.enableArgsCache) || op::internal::GetOpProfilingRecordArgFlag()) {1082+ if (executor->isEnablePcie) {
1083+ executor->ownArgs.enableCache = false;
1084+ OP_LOGI("Op %s skip args cache because current op has tensor using PCIe addr.", executor->opType);
1085+ if (NnopbaseIsV2CacheKeyEnabled(executor)) {
1086+ NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddIoTensors(executor));
1087+ }
1088+ } else if ((!g_nnopbaseSysCfgParams.enableArgsCache) || op::internal::GetOpProfilingRecordArgFlag()) {
1094 executor->ownArgs.enableCache = false;1089 executor->ownArgs.enableCache = false;
1095 } else if (NnopbaseExecutorCachedArgs(executor)) {1090 } else if (NnopbaseExecutorCachedArgs(executor)) {
1096 return OK;1091 return OK;
@@ -1145,7 +1140,8 @@ static inline aclnnStatus NnopbaseDumpNodeInfo(NnopbaseExecutor* executor)
1145 executor->dfx.opKernelInfo.isMc2 = executor->mc2.enabled;1140 executor->dfx.opKernelInfo.isMc2 = executor->mc2.enabled;
1146 aclnnOpInfoRecord::OpInfoSerialize(1141 aclnnOpInfoRecord::OpInfoSerialize(
1147 op::internal::PtrCastTo<const gert::TilingContext>(executor->tiling.contextExt.context),1142 op::internal::PtrCastTo<const gert::TilingContext>(executor->tiling.contextExt.context),
1148- aclnnOpInfoRecord::OpCompilerOption(g_nnopbaseSysCfgParams.implMode, executor->deterministicLevel),1143+ aclnnOpInfoRecord::OpCompilerOption(g_nnopbaseSysCfgParams.implMode, executor->deterministicLevel,
1144+ executor->isEnablePcie),
1149 &executor->dfx.opKernelInfo);1145 &executor->dfx.opKernelInfo);
1150 OP_LOGI("Dump node info for operator %s finished.", executor->opType);1146 OP_LOGI("Dump node info for operator %s finished.", executor->opType);
1151 }1147 }
@@ -170,6 +170,9 @@ typedef struct {
170 NnopbaseCoreNum coreNum{0, 0};170 NnopbaseCoreNum coreNum{0, 0};
171 bool deterministic = false;171 bool deterministic = false;
172 uint8_t deterministicLevel = 0U;172 uint8_t deterministicLevel = 0U;
173+ bool isEnablePcie = false;
174+ bool
175+ completeIoByPcie = false; // 由于Pcie检测输入输出无法感知全局,只有在添加Io结束&缓存时通过置true来避免重复配置Io
173 NnopbaseParamCheckMode paramCheckMode = NnopbaseParamCheckMode::kCheckEnd;176 NnopbaseParamCheckMode paramCheckMode = NnopbaseParamCheckMode::kCheckEnd;
174} NnopbaseExecutor;177} NnopbaseExecutor;
175 178 
@@ -231,13 +234,8 @@ void NnopbaseExecutorDeInit(NnopbaseExecutor* executor);
231void StreamMapClear(aclrtStream stream);234void StreamMapClear(aclrtStream stream);
232aclnnStatus CheckSocVersionAndParam(NnopbaseExecutor* executor,235aclnnStatus CheckSocVersionAndParam(NnopbaseExecutor* executor,
233 NnopbaseParamCheckMode mode = NnopbaseParamCheckMode::kCheckRequiredIo);236 NnopbaseParamCheckMode mode = NnopbaseParamCheckMode::kCheckRequiredIo);
234-aclnnStatus NnopbaseExecutorGenStaticKey(NnopbaseExecutor* const executor, const bool usingStride = false);
235void NnopbaseExecutorGenDynamicKey(NnopbaseExecutor* const executor);237void NnopbaseExecutorGenDynamicKey(NnopbaseExecutor* const executor);
236aclnnStatus NnopbaseExecutorGenCustomizedDynamicKey(NnopbaseExecutor* const executor);238aclnnStatus NnopbaseExecutorGenCustomizedDynamicKey(NnopbaseExecutor* const executor);
237-size_t NnopbaseExecutorComputeGenKeySize(const NnopbaseExecutor* const executor, bool usingStride = false);
238-NnopbaseUChar* NnopbaseExecutorGenAttrsKey(const NnopbaseAttrs* const attrs, NnopbaseUChar* verKey);
239-NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, const NnopbaseTensors* const tensors,
240- const size_t tensorNum, const bool usingStride = false);
241bool NnopbaseExecutorGetStaticBinInfo(NnopbaseExecutor* const executor);239bool NnopbaseExecutorGetStaticBinInfo(NnopbaseExecutor* const executor);
242NnopbaseUChar* NnopbaseExecutor8ByteCopy(const size_t totalSize, NnopbaseUChar* verKey, const NnopbaseUChar* addr);240NnopbaseUChar* NnopbaseExecutor8ByteCopy(const size_t totalSize, NnopbaseUChar* verKey, const NnopbaseUChar* addr);
243aclnnStatus SetTensorDataSizeToInitValue(NnopbaseExecutor* executor);241aclnnStatus SetTensorDataSizeToInitValue(NnopbaseExecutor* executor);
@@ -8,6 +8,7 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10#include "indv_executor.h"10#include "indv_executor.h"
11+#include <algorithm>
11#include "indv_tilingcontext_builder.h"12#include "indv_tilingcontext_builder.h"
12#include "indv_args_pool.h"13#include "indv_args_pool.h"
13#include "indv_collector.h"14#include "indv_collector.h"
@@ -25,7 +26,6 @@ static constexpr size_t NNOPBASE_VERKEY_EXT_BUF_LEN = 16U;
25static constexpr size_t NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN = 250U;26static constexpr size_t NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN = 250U;
26static constexpr size_t NNOPBASE_VERKEY_TENSOR_DESC_NUM = 2U;27static constexpr size_t NNOPBASE_VERKEY_TENSOR_DESC_NUM = 2U;
27static constexpr size_t NNOPBASE_OP_VERB_HEAD_LEN = 2U;28static constexpr size_t NNOPBASE_OP_VERB_HEAD_LEN = 2U;
28-static constexpr uint32_t NNOPBASE_DTYPE_AND_FORMAT_SIZE = 16U;
29std::unordered_map<void*, NnopbaseStreamForCombineExecution> g_nnopbaseStreamMap;29std::unordered_map<void*, NnopbaseStreamForCombineExecution> g_nnopbaseStreamMap;
30std::unordered_map<void*, std::shared_ptr<std::mutex>> g_nnopbaseStreamMtxMap;30std::unordered_map<void*, std::shared_ptr<std::mutex>> g_nnopbaseStreamMtxMap;
31static bool g_isNnopbaseRegisteredCallback = false;31static bool g_isNnopbaseRegisteredCallback = false;
@@ -93,6 +93,8 @@ void NnopbaseExecutorReset(NnopbaseExecutor* executor)
93 executor->matchArgsV2 = false;93 executor->matchArgsV2 = false;
94 executor->deterministicLevel = 0U;94 executor->deterministicLevel = 0U;
95 executor->deterministic = false;95 executor->deterministic = false;
96+ executor->isEnablePcie = false;
97+ executor->completeIoByPcie = false;
96}98}
97} // namespace99} // namespace
98 100 
@@ -284,8 +286,7 @@ aclnnStatus NnopbaseExecutorInit(NnopbaseExecutor* executor, const NnopbaseOpInf
284 executor->workspaces.length = 0U;286 executor->workspaces.length = 0U;
285 executor->opType = nullptr;287 executor->opType = nullptr;
286 executor->space = nullptr;288 executor->space = nullptr;
287- executor->binInfoKey.len = 0U;289+ executor->binInfoKey.Clear();
288- executor->binInfoKey.bufLen = 0U;
289 executor->hasTiling = true;290 executor->hasTiling = true;
290 executor->isWork = false;291 executor->isWork = false;
291 executor->dfx.Init();292 executor->dfx.Init();
@@ -300,6 +301,9 @@ aclnnStatus NnopbaseExecutorInit(NnopbaseExecutor* executor, const NnopbaseOpInf
300 executor->inUncontWsSize = 0U;301 executor->inUncontWsSize = 0U;
301 executor->repeatFlag = false;302 executor->repeatFlag = false;
302 executor->formatCheckOption = kNnopbaseDefault;303 executor->formatCheckOption = kNnopbaseDefault;
304+ executor->matchArgsV2 = false;
305+ executor->completeIoByPcie = false;
306+ executor->isEnablePcie = false;
303 (void)NnopbaseTilingContextInit(executor);307 (void)NnopbaseTilingContextInit(executor);
304 return OK;308 return OK;
305}309}
@@ -1058,10 +1062,7 @@ bool NnopbaseExecutorGetDynamicBinInfo(NnopbaseExecutor* const executor)
1058 }1062 }
1059 1063 
1060 if (isCustomizedKey) {1064 if (isCustomizedKey) {
1061- executor->binInfoKey.verbose = std::vector<NnopbaseUChar>();1065+ executor->binInfoKey.Clear();
1062- executor->binInfoKey.len = 0U;
1063- executor->binInfoKey.bufLen = 0U;
1064- executor->binInfoKey.hashKey = 0U;
1065 }1066 }
1066 1067 
1067 NnopbaseExecutorGenDynamicKey(executor);1068 NnopbaseExecutorGenDynamicKey(executor);
@@ -1077,196 +1078,6 @@ bool NnopbaseExecutorGetDynamicBinInfo(NnopbaseExecutor* const executor)
1077 return true;1078 return true;
1078}1079}
1079 1080 
1080-NnopbaseUChar* NnopbaseExecutorGenTensorsKey(NnopbaseUChar* verKey, const NnopbaseTensors* const tensors,
1081- const size_t tensorNum, const bool usingStride)
1082-{
1083- const NnopbaseUChar* addr;
1084- size_t length;
1085- for (size_t i = 0U; i < tensorNum; i++) {
1086- if (tensors->extTensors[i].isNull) {
1087- OP_LOGI("Tensor[%zu] is null.", i);
1088- verKey = NnopbaseAppend8Byte(verKey, '_');
1089- continue;
1090- }
1091- if (tensors->extTensors[i].isRequired || tensors->extTensors[i].isOptional) {
1092- verKey = NnopbaseAppend8Byte(verKey, tensors->extTensors[i].rt2Tensor.GetDataType());
1093- verKey = NnopbaseAppend8Byte(verKey, tensors->extTensors[i].rt2Tensor.GetStorageFormat());
1094- OP_LOGI("Tensor[%zu] datatype is %d, format is %d, isRequired is %s, isOptional is %s.", i,
1095- static_cast<int32_t>(tensors->extTensors[i].rt2Tensor.GetDataType()),
1096- static_cast<int32_t>(tensors->extTensors[i].rt2Tensor.GetStorageFormat()),
1097- tensors->extTensors[i].isRequired ? "true" : "false",
1098- tensors->extTensors[i].isOptional ? "true" : "false");
1099- }
1100- const GertShape& shape = tensors->extTensors[i].rt2Tensor.GetStorageShape();
1101- const size_t dimNum = shape.GetDimNum();
1102- for (size_t j = 0U; j < dimNum; j++) {
1103- verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(shape.GetDim(j)));
1104- OP_LOGI("Tensor[%zu] storageShape[%zu] is %ld", i, j, shape.GetDim(j));
1105- }
1106- if (usingStride) {
1107- const auto& stride = tensors->extTensors[i].rt2Tensor.GetStride();
1108- const size_t strideNum = stride.GetDimNum();
1109- for (size_t k = 0U; k < strideNum; k++) {
1110- verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(stride.GetStride(k)));
1111- }
1112- verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(tensors->extTensors[i].rt2Tensor.GetOffset()));
1113- }
1114- if (tensors->extTensors[i].valueDepend) {
1115- addr = op::internal::PtrCastTo<const NnopbaseUChar>(tensors->extTensors[i].rt2Tensor.GetAddr());
1116- const auto dtype = tensors->extTensors[i].rt2Tensor.GetDataType();
1117- length = tensors->extTensors[i].rt2Tensor.GetSize();
1118- const size_t typeSize = op::TypeSize(dtype);
1119- const size_t elementNum = length / typeSize;
1120- for (size_t k = 0; k < elementNum; k++) {
1121- verKey = NnopbaseExecutor8ByteCopy(typeSize, verKey, addr + typeSize * k);
1122- }
1123- }
1124- }
1125- return verKey;
1126-}
1127- 
1128-NnopbaseUChar* NnopbaseExecutorGenAttrsKey(const NnopbaseAttrs* const attrs, NnopbaseUChar* verKey)
1129-{
1130- const NnopbaseUChar* addr = nullptr;
1131- size_t length = 0;
1132- for (size_t j = 0; j < attrs->num; j++) {
1133- // 传入时已校验 attrs[j].addr.addr 不为空
1134- if (!attrs->attrs[j].addr.isVector) {
1135- if (attrs->attrs[j].dtype == NnopbaseAttrDtype::kNnopbaseString && attrs->attrs[j].addr.size == 1U) {
1136- OP_LOGW("For Attr %zu, this is a string type and actual value is empty, skip concating verKey.", j);
1137- continue;
1138- }
1139- addr = op::internal::PtrCastTo<const NnopbaseUChar>(attrs->attrs[j].addr.addr);
1140- length = attrs->attrs[j].addr.size;
1141- verKey = NnopbaseExecutor8ByteCopy(length, verKey, addr);
1142- } else {
1143- const size_t elementSize = attrs->attrs[j].addr.elementSize;
1144- if (elementSize == 0) {
1145- continue;
1146- }
1147- for (size_t i = 0U; i < attrs->attrs[j].addr.size / elementSize; i++) {
1148- addr = op::internal::PtrCastTo<const NnopbaseUChar>(attrs->attrs[j].addr.addr) + elementSize * i;
1149- verKey = NnopbaseExecutor8ByteCopy(elementSize, verKey, addr);
1150- }
1151- }
1152- }
1153- return verKey;
1154-}
1155- 
1156-static size_t NnopbaseComputeStaticTensorsKeySize(const NnopbaseTensors* const tensors, const size_t tensorNum,
1157- const bool usingStride, const bool withValueDepend)
1158-{
1159- size_t len = 0U;
1160- for (size_t i = 0U; i < tensorNum; i++) {
1161- if (tensors->extTensors[i].isNull) {
1162- len += sizeof(uint64_t); // '_' 占位
1163- continue;
1164- }
1165- if (tensors->extTensors[i].isRequired || tensors->extTensors[i].isOptional) {
1166- len += NNOPBASE_DTYPE_AND_FORMAT_SIZE;
1167- }
1168- const GertShape& shape = tensors->extTensors[i].rt2Tensor.GetStorageShape();
1169- len += shape.GetDimNum() * sizeof(uint64_t);
1170- if (usingStride) {
1171- len += tensors->extTensors[i].rt2Tensor.GetStride().GetDimNum() * sizeof(uint64_t) + sizeof(uint64_t);
1172- }
1173- if (withValueDepend && tensors->extTensors[i].valueDepend) {
1174- len += (tensors->extTensors[i].rt2Tensor.GetSize() /
1175- (op::TypeSize(tensors->extTensors[i].rt2Tensor.GetDataType()))) *
1176- sizeof(uint64_t);
1177- }
1178- }
1179- return len;
1180-}
1181- 
1182-static size_t NnopbaseComputeStaticAttrsKeySize(const NnopbaseAttrs* const attrs)
1183-{
1184- size_t len = 0U;
1185- for (size_t i = 0U; i < attrs->num; i++) {
1186- if (!attrs->attrs[i].addr.isVector) {
1187- NnopbaseExecutorGet8ByteSize(attrs->attrs[i].addr.size, op::internal::PtrCastTo<uint32_t>(&len));
1188- } else {
1189- len += (attrs->attrs[i].addr.size / attrs->attrs[i].addr.elementSize) * sizeof(uint64_t);
1190- }
1191- }
1192- return len;
1193-}
1194- 
1195-size_t NnopbaseExecutorComputeGenKeySize(const NnopbaseExecutor* const executor, bool usingStride)
1196-{
1197- const NnopbaseTensors* const inputs = &executor->ownArgs.inputs;
1198- const NnopbaseAttrs* const attrs = &executor->attrs;
1199- const NnopbaseTensors* const outputs = &executor->ownArgs.outputs;
1200- size_t len = executor->regInfo->key.opType.size() + NNOPBASE_OP_VERB_HEAD_LEN * sizeof(uint64_t);
1201- OP_LOGD("Op %s after add [optype, deterministic and precision or performance], length is %zu.", executor->opType,
1202- len);
1203- const size_t inputTensorNum = static_cast<size_t>(inputs->nonDynamicCnt + inputs->dynamicCnt);
1204- len += NnopbaseComputeStaticTensorsKeySize(inputs, inputTensorNum, usingStride, true);
1205- OP_LOGD("Op %s after add input, length is %zu.", executor->opType, len);
1206- const size_t outputTensorNum = outputs->nonDynamicCnt + outputs->dynamicCnt;
1207- len += NnopbaseComputeStaticTensorsKeySize(outputs, outputTensorNum, usingStride, false);
1208- OP_LOGD("Op %s after add output, length is %zu.", executor->opType, len);
1209- len += NnopbaseComputeStaticAttrsKeySize(attrs);
1210- OP_LOGD("Op %s after add attr, length is %zu.", executor->opType, len);
1211- return len;
1212-}
1213- 
1214-static NnopbaseUChar* NnopbaseInitStaticKeyBuffer(NnopbaseExecutor* const executor, const size_t len)
1215-{
1216- NnopbaseUChar* verKey = nullptr;
1217- if (len > executor->binInfoKey.bufLen) {
1218- executor->binInfoKey.verbose = std::vector<NnopbaseUChar>(len + NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN, '\0');
1219- verKey = &(executor->binInfoKey.verbose[0U]);
1220- executor->binInfoKey.bufLen = static_cast<uint32_t>(len) + NNOPBASE_REPLAY_VERKEY_EXT_BUF_LEN;
1221- verKey = NnopbaseAppendBinary(verKey, static_cast<size_t>(executor->binInfoKey.bufLen),
1222- &(executor->regInfo->key.opType[0U]), executor->regInfo->key.opType.size());
1223- } else {
1224- verKey = &(executor->binInfoKey.verbose[0U]) + executor->regInfo->key.opType.size();
1225- }
1226- return verKey;
1227-}
1228- 
1229-static NnopbaseUChar* NnopbaseAppendStaticKeyHead(const NnopbaseExecutor* const executor, NnopbaseUChar* verKey)
1230-{
1231- uint64_t deterministicLevel = (executor->deterministicLevel == 0U) ? 0U : 1U;
1232- verKey = NnopbaseAppend8Byte(verKey, deterministicLevel);
1233- verKey = NnopbaseAppend8Byte(verKey, static_cast<uint64_t>(g_nnopbaseSysCfgParams.precision));
1234- OP_LOGI("Op %s HighPrecision is %d, Deterministic is %d, binInfoKey length is %u.", executor->opType,
1235- g_nnopbaseSysCfgParams.precision, deterministicLevel, executor->binInfoKey.bufLen);
1236- return verKey;
1237-}
1238- 
1239-aclnnStatus NnopbaseExecutorGenStaticKey(NnopbaseExecutor* const executor, const bool usingStride)
1240-{
1241- const NnopbaseTensors* const inputs = &executor->ownArgs.inputs;
1242- const NnopbaseAttrs* const attrs = &executor->attrs;
1243- const NnopbaseTensors* const outputs = &executor->ownArgs.outputs;
1244- /*
1245- when usingStride = false:
1246- verb key format = op_type/Deterministic/Precision/{dtype, format, (shape)}/.../attr binary
1247- when usingStride = true:
1248- verb key format = op_type/Deterministic/Precision/{dtype, format, (shape),(stride),offset}/.../attr binary
1249- */
1250- const size_t len = NnopbaseExecutorComputeGenKeySize(executor, usingStride);
1251- OP_LOGI("Op %s staticGenKey size %lu, usingStride = %d", executor->opType, len, usingStride);
1252- if (len > NNOPBASE_MAX_STATICKEY_LEN) {
1253- OP_LOGW("Op %s staticGenKey size is too large[%lu].", executor->opType, len);
1254- return ACLNN_ERR_PARAM_INVALID;
1255- }
1256- 
1257- NnopbaseUChar* verKey = NnopbaseInitStaticKeyBuffer(executor, len);
1258- verKey = NnopbaseAppendStaticKeyHead(executor, verKey);
1259- const size_t inputTensorNum = inputs->nonDynamicCnt + inputs->dynamicCnt;
1260- verKey = NnopbaseExecutorGenTensorsKey(verKey, inputs, inputTensorNum, usingStride);
1261- const size_t outputTensorNum = static_cast<size_t>(outputs->nonDynamicCnt + outputs->dynamicCnt);
1262- verKey = NnopbaseExecutorGenTensorsKey(verKey, outputs, outputTensorNum, usingStride);
1263- verKey = NnopbaseExecutorGenAttrsKey(attrs, verKey);
1264- executor->binInfoKey.len = static_cast<uint32_t>(verKey - &(executor->binInfoKey.verbose[0U]));
1265- executor->binInfoKey.hashKey = NnopbaseHashBinary(&(executor->binInfoKey.verbose[0U]), executor->binInfoKey.len) %
1266- NNOPBASE_NORM_MAX_BIN_BUCKETS;
1267- return OK;
1268-}
1269- 
1270aclnnStatus NnopbaseExecutorSetUnContExecutor(NnopbaseExecutor* executor, aclOpExecutor* inExe, const size_t inWsSize)1081aclnnStatus NnopbaseExecutorSetUnContExecutor(NnopbaseExecutor* executor, aclOpExecutor* inExe, const size_t inWsSize)
1271{1082{
1272 OP_LOGI("Op %s set UnContExe %p, executor addr is %p.", executor->opType, inExe, executor);1083 OP_LOGI("Op %s set UnContExe %p, executor addr is %p.", executor->opType, inExe, executor);
@@ -32,6 +32,24 @@ static thread_local struct NnopbasePlatformInfos g_nnopbasePlatformMgr = {false,
32 32 
33namespace {33namespace {
34static constexpr uint32_t TILING_CONTEXT_INIT_PADDING = 32U;34static constexpr uint32_t TILING_CONTEXT_INIT_PADDING = 32U;
35+ 
36+void NnopbaseSetTilingRuntimeFlags(NnopbaseAsyncAnyValue** values, const uint32_t appendBaseIndex,
37+ const NnopbaseExecutor* executor)
38+{
39+ /* kInputsDeterministic. */
40+ *op::internal::PtrCastTo<int32_t>(
41+ values[appendBaseIndex + kInputsDeterministic]->data.inplace) = executor->deterministic ? 1 : 0;
42+ values[appendBaseIndex + kInputsDeterministic]->deleter = nullptr;
43+ /* kInputsDeterministicLevel. */
44+ *op::internal::PtrCastTo<int32_t>(values[appendBaseIndex + kInputsDeterministicLevel]
45+ ->data.inplace) = static_cast<int32_t>(executor->deterministicLevel);
46+ values[appendBaseIndex + kInputsDeterministicLevel]->deleter = nullptr;
47+ /* kInputsEnablePcieThrough. */
48+ *op::internal::PtrCastTo<int32_t>(
49+ values[appendBaseIndex + kInputsEnablePcieThrough]->data.inplace) = executor->isEnablePcie ? 1 : 0;
50+ values[appendBaseIndex + kInputsEnablePcieThrough]->deleter = nullptr;
51+}
52+ 
35uint32_t NnopbaseGetKernelRunContextValuesInitNum(NnopbaseExecutor* executor)53uint32_t NnopbaseGetKernelRunContextValuesInitNum(NnopbaseExecutor* executor)
36{54{
37 uint32_t num = executor->ownArgs.inputs.nonDynamicCnt + executor->ownArgs.outputs.nonDynamicCnt +55 uint32_t num = executor->ownArgs.inputs.nonDynamicCnt + executor->ownArgs.outputs.nonDynamicCnt +
@@ -219,36 +237,25 @@ aclnnStatus NnopbaseTilingContextBuild(NnopbaseExecutor* executor)
219 NnopbaseAsyncAnyValue** values = executor->tiling.contextExt.context->values;237 NnopbaseAsyncAnyValue** values = executor->tiling.contextExt.context->values;
220 OP_LOGD("During tiling, deterministic is %d. deterministic level is %u.", executor->deterministic,238 OP_LOGD("During tiling, deterministic is %d. deterministic level is %u.", executor->deterministic,
221 executor->deterministicLevel);239 executor->deterministicLevel);
240+ const uint32_t appendBaseIndex = executor->args->inputs.num + executor->args->outputs.num;
222 // executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt for option input241 // executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt for option input
223 if ((!executor->tiling.contextExt.hasPrepared) || executor->args->inputs.hasDynamic ||242 if ((!executor->tiling.contextExt.hasPrepared) || executor->args->inputs.hasDynamic ||
224 executor->args->outputs.hasDynamic ||243 executor->args->outputs.hasDynamic ||
225 (executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt)) {244 (executor->args->inputs.nonDynamicCnt > executor->args->inputs.requiredCnt)) {
226 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseTilingContextUpdtPrepare(executor));245 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseTilingContextUpdtPrepare(executor));
227- uint32_t index = executor->args->inputs.num + executor->args->outputs.num;
228 /* kInputsCompileInfo. */246 /* kInputsCompileInfo. */
229- values[index]->data.pointer = nullptr;247+ values[appendBaseIndex + kInputsCompileInfo]->data.pointer = nullptr;
230- values[index]->deleter = nullptr;248+ values[appendBaseIndex + kInputsCompileInfo]->deleter = nullptr;
231- index++;
232- /* kInputsPlatformInfo. */
233- index++;
234 /* kInputsTilingFunc. */249 /* kInputsTilingFunc. */
235- values[index]->data.pointer = nullptr;250+ values[appendBaseIndex + kInputsTilingFunc]->data.pointer = nullptr;
236- values[index]->deleter = nullptr;251+ values[appendBaseIndex + kInputsTilingFunc]->deleter = nullptr;
237- index++;
238- /* kInputsDeterministic. */
239- *op::internal::PtrCastTo<int32_t>(values[index]->data.inplace) = executor->deterministic ? 1 : 0;
240- values[index]->deleter = nullptr;
241- index++;
242- *op::internal::PtrCastTo<int32_t>(values[index]->data.inplace) = static_cast<int32_t>(
243- executor->deterministicLevel);
244- values[index]->deleter = nullptr;
245 NnopbaseTilingSetContextOutputStep1(executor);252 NnopbaseTilingSetContextOutputStep1(executor);
246 executor->tiling.contextExt.hasPrepared = true;253 executor->tiling.contextExt.hasPrepared = true;
247 }254 }
248 /* kInputsPlatformInfo. */255 /* kInputsPlatformInfo. */
249- uint32_t platformInfIndex = executor->args->inputs.num + executor->args->outputs.num + 1U;256+ values[appendBaseIndex + kInputsPlatformInfo]->data.pointer = static_cast<void*>(g_nnopbasePlatformMgr.infos.get());
250- values[platformInfIndex]->data.pointer = static_cast<void*>(g_nnopbasePlatformMgr.infos.get());257+ values[appendBaseIndex + kInputsPlatformInfo]->deleter = nullptr;
251- values[platformInfIndex]->deleter = nullptr;258+ NnopbaseSetTilingRuntimeFlags(values, appendBaseIndex, executor);
252 259 
253 *(executor->tiling.tilingKey) = 0U;260 *(executor->tiling.tilingKey) = 0U;
254 *(executor->tiling.numBlocks) = 0U;261 *(executor->tiling.numBlocks) = 0U;
@@ -338,7 +345,7 @@ aclnnStatus NnopbaseMemsetTilingContextInit(const std::vector<NnopbaseInitValueI
338 startIndex, desc->instances[i].num));345 startIndex, desc->instances[i].num));
339 }346 }
340 347 
341- // 5 for tiling compile info parsed struct,platform,tilingfunc,deterministic,deterministic level348+ // compile info parsed struct, platform, tilingfunc, deterministic, deterministic level, pcie through
342 contextExt->context->input_size = node->inputsNum + static_cast<uint32_t>(kInputsAppendEnd);349 contextExt->context->input_size = node->inputsNum + static_cast<uint32_t>(kInputsAppendEnd);
343 contextExt->context->output_size = gert::TilingContext::kOutputNum;350 contextExt->context->output_size = gert::TilingContext::kOutputNum;
344 contextExt->context->output_start = contextExt->context->values + contextExt->context->input_size;351 contextExt->context->output_start = contextExt->context->values + contextExt->context->input_size;
@@ -450,39 +457,28 @@ static void NnopbaseSetMemsetTilingKeyAndNumBlocks(NnopbaseExecutor* const execu
450aclnnStatus NnopbaseBuildMemsetTilingContext(NnopbaseExecutor* executor)457aclnnStatus NnopbaseBuildMemsetTilingContext(NnopbaseExecutor* executor)
451{458{
452 NnopbaseKernelRunContextExt* contextExt = &executor->args->binInfo->memsetInfo->contextExt;459 NnopbaseKernelRunContextExt* contextExt = &executor->args->binInfo->memsetInfo->contextExt;
460+ NnopbaseAsyncAnyValue** values = contextExt->context->values;
461+ const uint32_t appendBaseIndex = executor->args->binInfo->initValues.size() + 1U; // 1 is for workspace
453 if (!contextExt->hasPrepared) {462 if (!contextExt->hasPrepared) {
454- NnopbaseAsyncAnyValue** values = contextExt->context->values;
455- uint32_t index = executor->args->binInfo->initValues.size() + 1U; // 1 is for workspace
456 /* kInputsCompileInfo. */463 /* kInputsCompileInfo. */
457- values[index]->data.pointer = executor->args->binInfo->memsetInfo->tilingParseContext464+ values[appendBaseIndex + kInputsCompileInfo]
458- ->values[kCompileInfoStruct]465+ ->data.pointer = executor->args->binInfo->memsetInfo->tilingParseContext->values[kCompileInfoStruct]
459- ->data.pointer;466+ ->data.pointer;
460- values[index]->deleter = nullptr;467+ values[appendBaseIndex + kInputsCompileInfo]->deleter = nullptr;
461- index++;
462 /* kInputsPlatformInfo. */468 /* kInputsPlatformInfo. */
463- values[index]->data.pointer = nullptr; // tiling里从compileinfo中获取platform469+ values[appendBaseIndex + kInputsPlatformInfo]->data.pointer = nullptr; // tiling里从compileinfo中获取platform
464- values[index]->deleter = nullptr;470+ values[appendBaseIndex + kInputsPlatformInfo]->deleter = nullptr;
465- index++;
466 /* kInputsTilingFunc. */471 /* kInputsTilingFunc. */
467- values[index]->data.pointer = nullptr;472+ values[appendBaseIndex + kInputsTilingFunc]->data.pointer = nullptr;
468- values[index]->deleter = nullptr;473+ values[appendBaseIndex + kInputsTilingFunc]->deleter = nullptr;
469- index++;
470- /* kInputsDeterministic. */
471- *op::internal::PtrCastTo<int32_t>(values[index]->data.inplace) = executor->deterministic ? 1 : 0;
472- values[index]->deleter = nullptr;
473- index++;
474- 
475- *op::internal::PtrCastTo<int32_t>(values[index]->data.inplace) = static_cast<int32_t>(
476- executor->deterministicLevel);
477- values[index]->deleter = nullptr;
478 NnopbaseSetMemsetTilingKeyAndNumBlocks(executor);474 NnopbaseSetMemsetTilingKeyAndNumBlocks(executor);
479 contextExt->hasPrepared = true;475 contextExt->hasPrepared = true;
480 }476 }
477+ NnopbaseSetTilingRuntimeFlags(values, appendBaseIndex, executor);
481 *(executor->args->binInfo->memsetInfo->tilingKey) = 0U;478 *(executor->args->binInfo->memsetInfo->tilingKey) = 0U;
482 *(executor->args->binInfo->memsetInfo->scheMode) = 0U;479 *(executor->args->binInfo->memsetInfo->scheMode) = 0U;
483 *(executor->args->binInfo->memsetInfo->dynUBufSize) = 0U;480 *(executor->args->binInfo->memsetInfo->dynUBufSize) = 0U;
484 *(executor->args->binInfo->memsetInfo->numBlocks) = 0U;481 *(executor->args->binInfo->memsetInfo->numBlocks) = 0U;
485- NnopbaseAsyncAnyValue** values = executor->args->binInfo->memsetInfo->contextExt.context->values;
486 // 3 for tilingkey, numBlocks, atomic482 // 3 for tilingkey, numBlocks, atomic
487 size_t index = executor->args->binInfo->memsetInfo->contextExt.context->input_size + 3U;483 size_t index = executor->args->binInfo->memsetInfo->contextExt.context->input_size + 3U;
488 /* kOutputTilingData. */484 /* kOutputTilingData. */
@@ -347,12 +347,16 @@ void NnopbaseClearParamInstance(NnopbaseTensors* tensors)
347 347 
348aclnnStatus NnopbaseAddIoTensors(NnopbaseExecutor* executor)348aclnnStatus NnopbaseAddIoTensors(NnopbaseExecutor* executor)
349{349{
350+ if (executor->completeIoByPcie) {
351+ return OK;
352+ }
350 for (uint32_t i = 0U; i < executor->ownArgs.inputs.paramDescs.count; i++) {353 for (uint32_t i = 0U; i < executor->ownArgs.inputs.paramDescs.count; i++) {
351 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddInputsTensors(executor, &executor->ownArgs.inputs, i));354 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddInputsTensors(executor, &executor->ownArgs.inputs, i));
352 }355 }
353 for (uint32_t i = 0U; i < executor->ownArgs.outputs.paramDescs.count; i++) {356 for (uint32_t i = 0U; i < executor->ownArgs.outputs.paramDescs.count; i++) {
354 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddOutputsTensors(executor, &executor->ownArgs.outputs, i));357 NNOPBASE_ASSERT_OK_RETVAL(NnopbaseAddOutputsTensors(executor, &executor->ownArgs.outputs, i));
355 }358 }
359+ executor->completeIoByPcie = true;
356 return OK;360 return OK;
357}361}
358 362 
@@ -0,0 +1,560 @@
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 "static_kernel_helper.h"
12+ 
13+#include <algorithm>
14+#include <array>
15+#include <initializer_list>
16+#include <limits>
17+#include <utility>
18+#include <vector>
19+#include "indv_collector.h"
20+#include "indv_executor.h"
21+#include "indv_executor_utils.h"
22+#include "opdev/data_type_utils.h"
23+ 
24+using namespace op::internal;
25+ 
26+namespace Indv {
27+namespace {
28+constexpr size_t NNOPBASE_OP_VERB_HEAD_LEN = 2U;
29+constexpr size_t NNOPBASE_STATIC_BIN_VERBOSE_INIT_LEN = 4096U;
30+constexpr size_t NNOPBASE_BIN_INFO_KEY_MAX_LEN = std::numeric_limits<uint32_t>::max();
31+ 
32+size_t Align8ByteSize(const size_t size)
33+{
34+ return ((size + sizeof(uint64_t) - 1U) / sizeof(uint64_t)) * sizeof(uint64_t);
35+}
36+ 
37+class StaticKeySegments {
38+public:
39+ explicit StaticKeySegments(std::string opType) : opType_(std::move(opType)) {}
40+ 
41+ enum class Id : size_t {
42+ kHead = 0U,
43+ kPcie,
44+ kTensorsWithStride,
45+ kTensorsWithoutStride,
46+ kAttrs,
47+ kMax,
48+ };
49+ 
50+ aclnnStatus InitOpHead(int64_t deterministicMode, int64_t implMode);
51+ aclnnStatus InitPcie(bool enablePcie);
52+ aclnnStatus InitTensorWithStride(const NnopbaseStaticTensorNumInfo* tensorNumInfo, const aclTensor* tensors[],
53+ const int64_t* valueDepend);
54+ aclnnStatus InitTensor(const NnopbaseStaticTensorNumInfo* tensorNumInfo, const aclTensor* tensors[],
55+ const int64_t* valueDepend);
56+ aclnnStatus InitAttr(const NnopbaseStaticTensorNumInfo* tensorNumInfo, const NnopbaseAttrAddr* attrs[]);
57+ aclnnStatus InitTensorWithStride(const NnopbaseTensors* inputs, size_t inputTensorNum,
58+ const NnopbaseTensors* outputs, size_t outputTensorNum);
59+ aclnnStatus InitTensor(const NnopbaseTensors* inputs, size_t inputTensorNum, const NnopbaseTensors* outputs,
60+ size_t outputTensorNum);
61+ aclnnStatus InitAttr(const NnopbaseAttrs* attrs);
62+ NnopbaseBinInfo* FindWithLayout(BinInfoKey& binInfoKey, NnopbaseRegInfo* regInfo, std::initializer_list<Id> layout,
63+ const StaticKernelPlatformInfo* platformInfo) const;
64+ 
65+private:
66+ static constexpr size_t ToIndex(Id id) { return static_cast<size_t>(id); }
67+ 
68+ std::string opType_;
69+ std::array<BinInfoKey, static_cast<size_t>(Id::kMax)> segments_;
70+};
71+ 
72+struct StaticBinSearchContext {
73+ StaticKeySegments& segments;
74+ BinInfoKey& binInfoKey;
75+ NnopbaseRegInfo* regInfo;
76+ const StaticKernelPlatformInfo* platformInfo;
77+ bool enablePcie;
78+};
79+ 
80+aclnnStatus EnsureBinInfoKeyCapacity(BinInfoKey& binInfoKey, const size_t appendLen,
81+ const size_t maxLen = NNOPBASE_MAX_STATICKEY_LEN)
82+{
83+ if (appendLen == 0U) {
84+ return OK;
85+ }
86+ 
87+ const size_t usedLen = static_cast<size_t>(binInfoKey.len);
88+ CHECK_COND(appendLen <= maxLen && usedLen <= maxLen - appendLen, ACLNN_ERR_PARAM_INVALID,
89+ "Static binInfoKey size is too large[%zu].", usedLen + appendLen);
90+ if (binInfoKey.verbose.empty()) {
91+ binInfoKey.verbose.resize(std::max(NNOPBASE_STATIC_BIN_VERBOSE_INIT_LEN, appendLen));
92+ binInfoKey.bufLen = static_cast<uint32_t>(binInfoKey.verbose.size());
93+ return OK;
94+ }
95+ 
96+ CHECK_COND(usedLen <= static_cast<size_t>(binInfoKey.bufLen), ACLNN_ERR_PARAM_INVALID,
97+ "Static binInfoKey length[%zu] is larger than buffer length[%u].", usedLen, binInfoKey.bufLen);
98+ const size_t remainLen = static_cast<size_t>(binInfoKey.bufLen) - usedLen;
99+ if (remainLen >= appendLen) {
100+ return OK;
@@ -0,0 +1,32 @@
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+#ifndef STATIC_KERNEL_HELPER_H_
12+#define STATIC_KERNEL_HELPER_H_
13+ 
14+#include "individual_op_internal.h"
15+#include "indv_bininfo.h"
16+#include "indv_executor.h"
17+ 
18+namespace Indv {
19+ 
20+class StaticKernelHelper {
21+public:
22+ static const NnopbaseChar* FindStaticKernelPath(const aclTensor* tensors[], const NnopbaseAttrAddr* attrs[],
23+ const int64_t valueDepend[],
24+ const NnopbaseStaticTensorNumInfo* const tensorNumInfo,
25+ const NnopbaseStaticRuntimeInfo* const staticRuntimeInfo);
26+ 
27+ static NnopbaseBinInfo* FindStaticBinInfo(NnopbaseExecutor* const executor, BinInfoKey& binInfoKey);
28+};
29+ 
30+} // namespace Indv
31+ 
32+#endif
@@ -53,6 +53,7 @@ enum InputsAppend {
53 kInputsTilingFunc,53 kInputsTilingFunc,
54 kInputsDeterministic,54 kInputsDeterministic,
55 kInputsDeterministicLevel,55 kInputsDeterministicLevel,
56+ kInputsEnablePcieThrough,
56 kInputsAppendEnd57 kInputsAppendEnd
57};58};
58 59 
@@ -2084,6 +2084,109 @@ TEST_F(NnopbaseUnitTest, NnopBaseAddArrayInputSuccess)
2084 NnopbaseUnsetEnvAndClearFolder();2084 NnopbaseUnsetEnvAndClearFolder();
2085}2085}
2086 2086 
2087+TEST_F(NnopbaseUnitTest, NnopbaseLogAddApiPrintCoverage)
2088+{
2089+ NnopbaseSetStubFiles(OP_API_COMMON_UT_SRC_DIR);
2090+ setenv("ASCEND_GLOBAL_LOG_LEVEL", "1", 1);
2091+ 
2092+ void* executorSpace = nullptr;
2093+ ASSERT_EQ(NnopbaseCreateExecutorSpace(&executorSpace), OK);
2094+ 
2095+ const char* opType = "bninference_d_kernel";
2096+ char inputDesc[] = {1, 1, 2, 2, 0, 0, 0, 1, 1};
2097+ char outputDesc[] = {1, 1, 2};
2098+ char attrDesc[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
2099+ void* executor = NnopbaseGetExecutor(executorSpace, opType, inputDesc, sizeof(inputDesc) / sizeof(char), outputDesc,
2100+ sizeof(outputDesc) / sizeof(char), attrDesc, sizeof(attrDesc) / sizeof(char));
2101+ ASSERT_NE(executor, nullptr);
2102+ MOCKER(CheckLogLevelInner).stubs().will(returnValue(1));
2103+ 
2104+ std::vector<int64_t> shape = {1, 1, 1, 1, 1};
2105+ aclTensor* inputTensor = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT, nullptr, 0,
2106+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), data);
2107+ aclTensor* ignoreContTensor = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT, nullptr, 0,
2108+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), data + 8);
2109+ aclTensor* outputTensor = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT, nullptr, 0,
2110+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), data + 16);
2111+ aclTensor* shapeDependOutput = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT, nullptr, 0,
2112+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), data + 24);
2113+ aclTensor* dynamicTensor0 = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT, nullptr, 0,
2114+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), data + 32);
2115+ aclTensor* dynamicTensor1 = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT, nullptr, 0,
2116+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), data + 40);
2117+ std::vector<const aclTensor*> tensorList = {dynamicTensor0, dynamicTensor1};
2118+ aclTensorList* aclTensorTestList = aclCreateTensorList(tensorList.data(), tensorList.size());
2119+ 
2120+ int64_t intValues[] = {3, 4, 5};
2121+ bool boolValues[] = {true, false, true};
2122+ float floatValues[] = {0.1F, 0.2F, 0.3F};
2123+ auto* intArray = aclCreateIntArray(intValues, sizeof(intValues) / sizeof(intValues[0]));
2124+ auto* boolArray = aclCreateBoolArray(boolValues, sizeof(boolValues) / sizeof(boolValues[0]));
2125+ auto* floatArray = aclCreateFloatArray(floatValues, sizeof(floatValues) / sizeof(floatValues[0]));
2126+ 
2127+ int32_t scalarValue = 5;
2128+ int32_t scalarListValue = 6;
2129+ auto* scalar = aclCreateScalar(&scalarValue, aclDataType::ACL_INT32);
2130+ auto* scalarForList = aclCreateScalar(&scalarListValue, aclDataType::ACL_INT32);
2131+ auto* scalarList = aclCreateScalarList(&scalarForList, 1);
2132+ 
2133+ ASSERT_EQ(NnopbaseAddInput(executor, inputTensor, 0), OK);
2134+ ASSERT_EQ(NnopbaseAddIgnoreContinuesInput(executor, ignoreContTensor, 1), OK);
2135+ ASSERT_EQ(NnopbaseAddDynamicInput(executor, aclTensorTestList, 2), OK);
2136+ ASSERT_EQ(NnopbaseAddIgnoreContiguousDynamicInput(executor, aclTensorTestList, 3), OK);
2137+ ASSERT_EQ(NnopbaseAddIntArrayInput(executor, intArray, 4), OK);
2138+ ASSERT_EQ(NnopbaseAddBoolArrayInput(executor, boolArray, 5), OK);
2139+ ASSERT_EQ(NnopbaseAddFloatArrayInput(executor, floatArray, 6), OK);
2140+ ASSERT_EQ(NnopbaseAddScalarInput(executor, scalar, 7, -1, ge::DT_UNDEFINED), OK);
2141+ ASSERT_EQ(NnopbaseAddScalarListInput(executor, scalarList, 8, -1, ge::DT_UNDEFINED), OK);
2142+ 
2143+ ASSERT_EQ(NnopbaseAddOutput(executor, outputTensor, 0), OK);
2144+ ASSERT_EQ(NnopbaseAddOutputShapeDependTensor(executor, shapeDependOutput, 1), OK);
2145+ ASSERT_EQ(NnopbaseAddDynamicOutput(executor, aclTensorTestList, 2), OK);
2146+ 
2147+ int64_t intAttr = 7;
2148+ float floatAttr = 1.5F;
2149+ bool boolAttr = true;
2150+ char stringAttr[] = "log_attr";
2151+ int64_t rawIntAttr[] = {1, 2, 3};
2152+ bool rawBoolAttr[] = {true, false};
2153+ float rawFloatAttr[] = {1.0F, 2.0F};
2154+ ASSERT_EQ(NnopbaseAddAttr(executor, &intAttr, sizeof(intAttr), 0), OK);
2155+ ASSERT_EQ(NnopbaseAddAttrWithDtype(executor, &intAttr, sizeof(intAttr), 1, kNnopbaseInt), OK);
2156+ ASSERT_EQ(NnopbaseAddAttrWithDtype(executor, &floatAttr, sizeof(floatAttr), 2, kNnopbaseFloat), OK);
2157+ ASSERT_EQ(NnopbaseAddAttrWithDtype(executor, &boolAttr, sizeof(boolAttr), 3, kNnopbaseBool), OK);
2158+ ASSERT_EQ(NnopbaseAddAttrWithDtype(executor, stringAttr, sizeof(stringAttr), 4, kNnopbaseString), OK);
2159+ ASSERT_EQ(NnopbaseAddBoolArrayAttr(executor, boolArray, 5), OK);
2160+ ASSERT_EQ(NnopbaseAddFloatArrayAttr(executor, floatArray, 6), OK);
2161+ ASSERT_EQ(NnopbaseAddIntArrayAttr(executor, intArray, 7), OK);
2162+ ASSERT_EQ(NnopbaseAddArrayAttr(executor, rawBoolAttr, sizeof(rawBoolAttr) / sizeof(rawBoolAttr[0]),
2163+ sizeof(rawBoolAttr[0]), 8),
2164+ OK);
2165+ ASSERT_EQ(NnopbaseAddArrayAttrWithDtype(executor, rawIntAttr, sizeof(rawIntAttr) / sizeof(rawIntAttr[0]),
2166+ sizeof(rawIntAttr[0]), 9, kNnopbaseInt),
2167+ OK);
2168+ ASSERT_EQ(NnopbaseAddArrayAttrWithDtype(executor, rawFloatAttr, sizeof(rawFloatAttr) / sizeof(rawFloatAttr[0]),
2169+ sizeof(rawFloatAttr[0]), 10, kNnopbaseFloat),
2170+ OK);
2171+ ASSERT_EQ(NnopbaseAddArrayAttrWithDtype(executor, rawBoolAttr, sizeof(rawBoolAttr) / sizeof(rawBoolAttr[0]),
2172+ sizeof(rawBoolAttr[0]), 11, kNnopbaseBool),
2173+ OK);
2174+ 
2175+ NnopbaseExecutorGcSpace(executorSpace);
2176+ aclDestroyTensor(inputTensor);
2177+ aclDestroyTensor(ignoreContTensor);
2178+ aclDestroyTensor(outputTensor);
2179+ aclDestroyTensor(shapeDependOutput);
2180+ aclDestroyTensorList((const aclTensorList*)aclTensorTestList);
2181+ aclDestroyScalar(scalar);
2182+ aclDestroyScalarList(scalarList);
2183+ aclDestroyIntArray(intArray);
2184+ aclDestroyBoolArray(boolArray);
2185+ aclDestroyFloatArray(floatArray);
2186+ unsetenv("ASCEND_GLOBAL_LOG_LEVEL");
2187+ NnopbaseUnsetEnvAndClearFolder();
2188+}
2189+ 
2087TEST_F(NnopbaseUnitTest, NnopBaseRunWithHostAndDynamicInput)2190TEST_F(NnopbaseUnitTest, NnopBaseRunWithHostAndDynamicInput)
2088{2191{
2089 NnopbaseSetStubFiles(OP_API_COMMON_UT_SRC_DIR);2192 NnopbaseSetStubFiles(OP_API_COMMON_UT_SRC_DIR);
@@ -8,6 +8,7 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10#include <cstdio>10#include <cstdio>
11+#include "individual_op_internal.h"
11#include "utils/indv_types.h"12#include "utils/indv_types.h"
12#include "executor/indv_collector.h"13#include "executor/indv_collector.h"
13#include "executor/indv_executor.h"14#include "executor/indv_executor.h"
@@ -16,6 +17,7 @@
16#include <gtest/gtest.h>17#include <gtest/gtest.h>
17#include <memory>18#include <memory>
18#include <string.h>19#include <string.h>
20+#include <vector>
19#include <sys/stat.h>21#include <sys/stat.h>
20#include <sys/types.h>22#include <sys/types.h>
21#include <stdio.h>23#include <stdio.h>
@@ -34,6 +36,67 @@ void SetSocVersion(const std::string& version)
34 soc.socVersion = version;36 soc.socVersion = version;
35 soc.isInit = true;37 soc.isInit = true;
36}38}
39+ 
40+constexpr const char* STATIC_FIND_OP_TYPE = "StaticPcieThroughFindTest";
41+constexpr const char* PCIE_WITH_STRIDE_SIMPLIFIED_KEY = "StaticPcieThroughFindTest/d=0,p=0,pt=1/0,2,(2,3),0";
42+constexpr const char* STRIDE_SIMPLIFIED_KEY = "StaticPcieThroughFindTest/d=0,p=0/0,2,(2,3),0";
43+constexpr const char* NO_STRIDE_SIMPLIFIED_KEY = "StaticPcieThroughFindTest/d=0,p=0/0,2,(2,3)";
44+ 
45+aclnnStatus InitStaticBinBySimplifiedKey(NnopbaseBinInfo& binInfo, const std::string& simplifiedKey,
46+ const std::string& binPath)
47+{
48+ std::vector<NnopbaseUChar> verbose(NNOPBASE_MAX_STATICKEY_LEN, 0U);
49+ uint32_t len = 0U;
50+ NNOPBASE_ASSERT_OK_RETVAL(NnopbaseCollectorConvertStaticVerbKey(simplifiedKey.c_str(), verbose.data(), &len));
51+ NnopbaseBinInfoInit(&binInfo);
52+ binInfo.binPath = binPath;
53+ return NnopbaseBinInfoSetOpBinInfoKey(&binInfo, verbose.data(), len);
54+}
55+ 
56+class ScopedBinCollector {
57+public:
58+ explicit ScopedBinCollector(NnopbaseBinCollector* collector) : oldCollector_(gBinCollector)
59+ {
60+ gBinCollector = collector;
61+ }
62+ 
63+ ~ScopedBinCollector() { gBinCollector = oldCollector_; }
64+ 
65+private:
66+ NnopbaseBinCollector* oldCollector_;
67+};
68+ 
69+void InsertStaticFindRegInfo(NnopbaseBinCollector& collector, NnopbaseRegInfo& regInfo)
70+{
71+ regInfo.key.hashKey = static_cast<uint64_t>(
72+ NnopbaseHashBinary(op::internal::PtrCastTo<NnopbaseUChar>(regInfo.key.opType.c_str()),
73+ regInfo.key.opType.size()) %
74+ NNOPBASE_NORM_MAX_BIN_BUCKETS);
75+ DoubleListNodeInit(&regInfo.dllNode);
76+ DoubleListAppend(&regInfo.dllNode, &collector.regInfoTbl.buckets[regInfo.key.hashKey].head);
77+}
78+ 
79+const char* FindStaticPathForTest(const bool enablePcie)
80+{
81+ std::vector<int64_t> shape = {2, 3};
82+ std::vector<int64_t> stride = {3, 1};
83+ aclTensor* tensor = aclCreateTensor(shape.data(), shape.size(), aclDataType::ACL_FLOAT, stride.data(), 0,
84+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), nullptr);
85+ const aclTensor* tensors[] = {tensor};
86+ const NnopbaseAttrAddr* attrs[] = {};
87+ const int64_t valueDepend[] = {};
88+ NnopbaseStaticTensorNumInfo tensorNumInfo{1, 0, 0, 0};
89+ NnopbaseStaticRuntimeInfo runtimeInfo{STATIC_FIND_OP_TYPE, 0U, 0U, 0, 0, enablePcie};
90+ const char* path = NnopbaseFindStaticKernel(tensors, attrs, valueDepend, &tensorNumInfo, &runtimeInfo);
91+ aclDestroyTensor(tensor);
92+ return path;
93+}
94+ 
95+void InitStaticFindRegInfo(NnopbaseRegInfo& regInfo)
96+{
97+ regInfo.key.opType = STATIC_FIND_OP_TYPE;
98+ NnopbaseCollectorInitBinTbl(&regInfo.binTbl);
99+}
37} // namespace100} // namespace
38 101 
39class NnopbaseCollectorUnitTest : public testing::Test {102class NnopbaseCollectorUnitTest : public testing::Test {
@@ -109,6 +172,66 @@ TEST_F(NnopbaseCollectorUnitTest, StaticKernelMatchChecksDeterministicLevelAfter
109 nullptr);172 nullptr);
110}173}
111 174 
175+TEST_F(NnopbaseCollectorUnitTest, StaticKernelFindPrefersPcieWithStride)
176+{
177+ NnopbaseBinCollector collector;
178+ ASSERT_EQ(NnopbaseCollectorInit(&collector), OK);
179+ ScopedBinCollector scopedCollector(&collector);
180+ NnopbaseRegInfo regInfo;
181+ InitStaticFindRegInfo(regInfo);
182+ InsertStaticFindRegInfo(collector, regInfo);
183+ 
184+ NnopbaseBinInfo pcieWithStrideBin;
185+ ASSERT_EQ(InitStaticBinBySimplifiedKey(pcieWithStrideBin, PCIE_WITH_STRIDE_SIMPLIFIED_KEY, "pcie_stride.o"), OK);
186+ NnopbaseBinInfo strideBin;
187+ ASSERT_EQ(InitStaticBinBySimplifiedKey(strideBin, STRIDE_SIMPLIFIED_KEY, "stride.o"), OK);
188+ NnopbaseBinInfo noStrideBin;
189+ ASSERT_EQ(InitStaticBinBySimplifiedKey(noStrideBin, NO_STRIDE_SIMPLIFIED_KEY, "no_stride.o"), OK);
190+ 
191+ NnopbaseCollectorInsertBinInfo(&regInfo, &noStrideBin);
192+ NnopbaseCollectorInsertBinInfo(&regInfo, &strideBin);
193+ NnopbaseCollectorInsertBinInfo(&regInfo, &pcieWithStrideBin);
194+ 
195+ EXPECT_STREQ(FindStaticPathForTest(true), "pcie_stride.o");
196+}
197+ 
198+TEST_F(NnopbaseCollectorUnitTest, StaticKernelFindFallbacksToStrideWithoutPcie)
199+{
200+ NnopbaseBinCollector collector;
201+ ASSERT_EQ(NnopbaseCollectorInit(&collector), OK);
202+ ScopedBinCollector scopedCollector(&collector);
203+ NnopbaseRegInfo regInfo;
204+ InitStaticFindRegInfo(regInfo);
205+ InsertStaticFindRegInfo(collector, regInfo);
206+ 
207+ NnopbaseBinInfo strideBin;
208+ ASSERT_EQ(InitStaticBinBySimplifiedKey(strideBin, STRIDE_SIMPLIFIED_KEY, "stride.o"), OK);
209+ NnopbaseBinInfo noStrideBin;
210+ ASSERT_EQ(InitStaticBinBySimplifiedKey(noStrideBin, NO_STRIDE_SIMPLIFIED_KEY, "no_stride.o"), OK);
211+ 
212+ NnopbaseCollectorInsertBinInfo(&regInfo, &noStrideBin);
213+ NnopbaseCollectorInsertBinInfo(&regInfo, &strideBin);
214+ 
215+ EXPECT_STREQ(FindStaticPathForTest(true), "stride.o");
216+}
217+ 
218+TEST_F(NnopbaseCollectorUnitTest, StaticKernelFindFallbacksToNoStride)
219+{
220+ NnopbaseBinCollector collector;
221+ ASSERT_EQ(NnopbaseCollectorInit(&collector), OK);
222+ ScopedBinCollector scopedCollector(&collector);
223+ NnopbaseRegInfo regInfo;
224+ InitStaticFindRegInfo(regInfo);
225+ InsertStaticFindRegInfo(collector, regInfo);
226+ 
227+ NnopbaseBinInfo noStrideBin;
228+ ASSERT_EQ(InitStaticBinBySimplifiedKey(noStrideBin, NO_STRIDE_SIMPLIFIED_KEY, "no_stride.o"), OK);
229+ 
230+ NnopbaseCollectorInsertBinInfo(&regInfo, &noStrideBin);
231+ 
232+ EXPECT_STREQ(FindStaticPathForTest(true), "no_stride.o");
233+}
234+ 
112TEST_F(NnopbaseCollectorUnitTest, test_get_soc_version_ok)235TEST_F(NnopbaseCollectorUnitTest, test_get_soc_version_ok)
113{236{
114 NnopbaseBinCollector* bin_collector = new NnopbaseBinCollector;237 NnopbaseBinCollector* bin_collector = new NnopbaseBinCollector;
@@ -2215,7 +2215,6 @@ TEST_F(NnopbaseExecutorUnitTest, TestInvalidStaticShape)
2215 intValues = std::vector<int64_t>(100000);2215 intValues = std::vector<int64_t>(100000);
2216 executor = GetIntArrayExecutor(executorSpace, intValues.data(), intValues.size());2216 executor = GetIntArrayExecutor(executorSpace, intValues.data(), intValues.size());
2217 opExecutor = (NnopbaseExecutor*)executor;2217 opExecutor = (NnopbaseExecutor*)executor;
2218- ASSERT_EQ(NnopbaseExecutorGenStaticKey(opExecutor, false), ACLNN_ERR_PARAM_INVALID);
2219 ASSERT_EQ(NnopbaseExecutorGetStaticBinInfo(opExecutor), false);2218 ASSERT_EQ(NnopbaseExecutorGetStaticBinInfo(opExecutor), false);
2220 2219 
2221 NnopbaseExecutorGcSpace(executorSpace);2220 NnopbaseExecutorGcSpace(executorSpace);