Merged
fix: 1.越界问题;2.Clean Code;3. memset二级指针场景不展开 #838
fix: 1.越界问题;2.Clean Code;3. memset二级指针场景不展开 #838
Merged
ren-botaoAdd on Sep 10
Total: 13 files changed+138-77
@@ -10,7 +10,6 @@
10 10 
11#ifndef OP_DFX_INTERNAL_H_11#ifndef OP_DFX_INTERNAL_H_
12#define OP_DFX_INTERNAL_H_12#define OP_DFX_INTERNAL_H_
13-#include <atomic>
14#include "profiling/aprof_pub.h"13#include "profiling/aprof_pub.h"
15#include "op_dfx_util.h"14#include "op_dfx_util.h"
16#include "op_cache_internal.h"15#include "op_cache_internal.h"
@@ -165,10 +164,7 @@ void PrepareL2DumpTensor(std::vector<Adx::TensorInfoV2>& dumpTensors, const std:
165bool GetOpProfilingRecordArgFlag();164bool GetOpProfilingRecordArgFlag();
166void SetOpProfilingRecordArgFlag(bool value);165void SetOpProfilingRecordArgFlag(bool value);
167 166 
168-extern std::atomic<bool> g_aclnnDebugEnabled;167+bool IsAclnnDebugEnabled();
169- 
170-void InitAclnnDebugSwitch();
171-inline bool IsAclnnDebugEnabled() { return g_aclnnDebugEnabled.load(std::memory_order_relaxed); }
172 168 
173#ifdef __cplusplus169#ifdef __cplusplus
174extern "C" {170extern "C" {
@@ -19,31 +19,37 @@ void CalcAclTensorNum([[maybe_unused]] size_t idx, const aclTensor* tensor, size
19{19{
20 // tbe 算子(genPlaceholder 为 false)跳过 null 入参;ascendc 算子对 null 入参占位计数,与 json argIdx_ 编址对齐20 // tbe 算子(genPlaceholder 为 false)跳过 null 入参;ascendc 算子对 null 入参占位计数,与 json argIdx_ 编址对齐
21 if (tensor == nullptr && !genPlaceholder) {21 if (tensor == nullptr && !genPlaceholder) {
22- OP_LOGW("Op input is null. idx: %zu.", idx);22+ OP_LOGW("Op input tensor is null, index: %zu.", idx);
23 return;23 return;
24 }24 }
25 num++;25 num++;
26}26}
27 27 
28-void CalcAclTensorNum([[maybe_unused]] size_t idx, const aclTensorList* tensor, size_t& num, bool genPlaceholder)28+void CalcAclTensorNum([[maybe_unused]] size_t idx, const aclTensorList* tensorList, size_t& num, bool genPlaceholder,
29+ bool hasDevPtrArg)
29{30{
30- if (tensor == nullptr) {31+ if (tensorList == nullptr) {
31- OP_LOGW("Op input tensorlist is null. idx: %zu.", idx);32+ OP_LOGW("Op input tensor list is null, index: %zu.", idx);
32 return;33 return;
33 }34 }
34- for (size_t i = 0; i < tensor->Size(); i++) {35+ if (hasDevPtrArg) {
35- CalcAclTensorNum(idx, (*tensor)[i], num, genPlaceholder);36+ OP_LOGI("Op input tensor list at index %zu, and this op supports folded_with_desc.", idx);
37+ num++;
38+ return;
39+ }
40+ for (size_t i = 0; i < tensorList->Size(); i++) {
41+ CalcAclTensorNum(idx, (*tensorList)[i], num, genPlaceholder);
36 }42 }
37}43}
38 44 
39-void CalcAclTensorNum(size_t idx, OpArg& arg, size_t& num, bool genPlaceholder)45+void CalcAclTensorNum(size_t idx, OpArg& arg, size_t& num, bool genPlaceholder, bool hasDevPtrArg)
40{46{
41 switch (arg.type) {47 switch (arg.type) {
42 case OpArgType::OPARG_ACLTENSOR:48 case OpArgType::OPARG_ACLTENSOR:
43 CalcAclTensorNum(idx, reinterpret_cast<aclTensor*>(arg->pointer), num, genPlaceholder);49 CalcAclTensorNum(idx, reinterpret_cast<aclTensor*>(arg->pointer), num, genPlaceholder);
44 break;50 break;
45 case OpArgType::OPARG_ACLTENSOR_LIST:51 case OpArgType::OPARG_ACLTENSOR_LIST:
46- CalcAclTensorNum(idx, reinterpret_cast<aclTensorList*>(arg->pointer), num, genPlaceholder);52+ CalcAclTensorNum(idx, reinterpret_cast<aclTensorList*>(arg->pointer), num, genPlaceholder, hasDevPtrArg);
47 break;53 break;
48 default:54 default:
49 break;55 break;
@@ -189,24 +189,14 @@ inline aclnnStatus GenKeyByAttrs(char*& key, size_t& remainLen, std::vector<Attr
189}189}
190 190 
191void CalcAclTensorNum(size_t idx, const aclTensor* tensor, size_t& num, bool genPlaceholder);191void CalcAclTensorNum(size_t idx, const aclTensor* tensor, size_t& num, bool genPlaceholder);
192-void CalcAclTensorNum(size_t idx, const aclTensorList* tensor, size_t& num, bool genPlaceholder);192+void CalcAclTensorNum(size_t idx, const aclTensorList* tensorList, size_t& num, bool genPlaceholder, bool hasDevPtrArg);
193-void CalcAclTensorNum(size_t idx, OpArg& arg, size_t& num, bool genPlaceholder);193+void CalcAclTensorNum(size_t idx, OpArg& arg, size_t& num, bool genPlaceholder, bool hasDevPtrArg);
194 194 
195-inline size_t GetAclTensorCount(OpArgList& args, bool genPlaceholder)195+inline size_t GetAclTensorCount(OpArgList& args, bool genPlaceholder, bool hasDevPtrArg)
196{196{
197 size_t num = 0;197 size_t num = 0;
198- args.VisitByNoReturn(198+ args.VisitByNoReturn([&num, genPlaceholder, hasDevPtrArg](size_t idx, OpArg& elem) {
199- [&num, genPlaceholder](size_t idx, OpArg& elem) { CalcAclTensorNum(idx, elem, num, genPlaceholder); });199+ CalcAclTensorNum(idx, elem, num, genPlaceholder, hasDevPtrArg);
200- return num;
201-}
202- 
203-inline size_t GetArgCount4DevPtrArg(OpArgList& args)
204-{
205- size_t num = 0;
206- args.VisitByNoReturn([&num]([[maybe_unused]] size_t idx, OpArg& elem) {
207- if (elem.type == OpArgType::OPARG_ACLTENSOR || elem.type == OpArgType::OPARG_ACLTENSOR_LIST) {
208- num++;
209- }
210 });200 });
211 return num;201 return num;
212}202}
@@ -124,18 +124,19 @@ void SetOpProfilingRecordArgFlag(bool value)
124 opProfilingSwitch.recordOpArgFlag = value;124 opProfilingSwitch.recordOpArgFlag = value;
125}125}
126 126 
127+namespace {
127std::atomic<bool> g_aclnnDebugEnabled{false};128std::atomic<bool> g_aclnnDebugEnabled{false};
128-static std::once_flag g_aclnnDebugOnceFlag;
129 129 
130-void InitAclnnDebugSwitch()130+__attribute__((constructor)) void InitAclnnDebugSwitch()
131{131{
132- std::call_once(g_aclnnDebugOnceFlag, []() {132+ if (CheckLogLevelInner(OP_ID, OP_LOG_INFO) == 1) {
133- if (CheckLogLevelInner(OP_ID, OP_LOG_INFO) == 1) {133+ g_aclnnDebugEnabled.store(true, std::memory_order_relaxed);
134- g_aclnnDebugEnabled.store(true, std::memory_order_relaxed);134+ OP_LOGI("Aclnn debug mode is enabled by log level.");
135- OP_LOGI("Aclnn debug mode is enabled by log level.");135+ }
136- }
137- });
138}136}
137+} // namespace
138+ 
139+bool IsAclnnDebugEnabled() { return g_aclnnDebugEnabled.load(std::memory_order_relaxed); }
139 140 
140OpThreadLocalContext& GetThreadLocalContext()141OpThreadLocalContext& GetThreadLocalContext()
141{142{
@@ -1036,7 +1036,6 @@ int64_t GetDeterministicLevelFromRt()
1036 1036 
1037void InitL2Phase1Context(const char* l2Name, [[maybe_unused]] aclOpExecutor** executor)1037void InitL2Phase1Context(const char* l2Name, [[maybe_unused]] aclOpExecutor** executor)
1038{1038{
1039- InitAclnnDebugSwitch();
1040 OP_CHECK_NO_RETURN(op::internal::InitPcieThroughInfo() == ACLNN_SUCCESS, OP_LOGW("InitPcieThroughInfo failed"));1039 OP_CHECK_NO_RETURN(op::internal::InitPcieThroughInfo() == ACLNN_SUCCESS, OP_LOGW("InitPcieThroughInfo failed"));
1041 auto& opTlsCtx = op::internal::GetThreadLocalContext();1040 auto& opTlsCtx = op::internal::GetThreadLocalContext();
1042 opTlsCtx.logInfo_.l2ApiName = l2Name;1041 opTlsCtx.logInfo_.l2ApiName = l2Name;
@@ -848,24 +848,11 @@ public:
848 848 
849 // for multi thread849 // for multi thread
850 memSetValueCtx_ = memSetValue_;850 memSetValueCtx_ = memSetValue_;
851- if (memsetVersion == MemsetVersion::MEMSET_V2) {851+ size_t inputNum = GetAclTensorCount(*args->GetOpArg(op::OP_INPUT_ARG), genPlaceholder_, hasDevPtrArg_);
852- size_t inputNum = 0;852+ CollectMemSetTensor(args, inputNum, needAlign, memsetVersion);
853- if (hasDevPtrArg_) {
854- inputNum = GetArgCount4DevPtrArg(*args->GetOpArg(op::OP_INPUT_ARG));
855- } else {
856- inputNum = GetAclTensorCount(*args->GetOpArg(op::OP_INPUT_ARG), genPlaceholder_);
857- }
858- CollectMemSetTensor(args, inputNum, needAlign, memsetVersion);
859#if !defined(NNOPBASE_UT) && !defined(NNOPBASE_ST)853#if !defined(NNOPBASE_UT) && !defined(NNOPBASE_ST)
860- return memsetBin->MemSetV2(stream, memSetValueCtx_);854+ return memsetBin->MemSet(stream, memSetValueCtx_);
861#endif855#endif
862- } else {
863- size_t inputNum = GetAclTensorCount(*args->GetOpArg(op::OP_INPUT_ARG), genPlaceholder_);
864- CollectMemSetTensor(args, inputNum, needAlign, memsetVersion);
865-#if !defined(NNOPBASE_UT) && !defined(NNOPBASE_ST)
866- return memsetBin->MemSet(stream, memSetValueCtx_);
867-#endif
868- }
869 return ACLNN_SUCCESS;856 return ACLNN_SUCCESS;
870 }857 }
871 858 
@@ -657,21 +657,21 @@ void AddArgInfoToCache(OpExecCache* cache, LaunchArgCache::ArgInfo* argInfo, con
657 OP_CHECK(p != nullptr, OP_LOGD("The cache cannot add launch data for devPtrArgAddr, the cache is invalid."),657 OP_CHECK(p != nullptr, OP_LOGD("The cache cannot add launch data for devPtrArgAddr, the cache is invalid."),
658 return);658 return);
659 *p++ = dataSize;659 *p++ = dataSize;
660- for (size_t i = 0; i < tensors->Size(); i++) {660+ for (size_t tensorIdx = 0; tensorIdx < tensors->Size(); tensorIdx++) {
661- if ((*tensors)[i] == nullptr) {661+ if ((*tensors)[tensorIdx] == nullptr) {
662 *p++ = (static_cast<int64_t>(1) << RtsArg::DEV_PTR_DIM_SHIFT_BIT) + static_cast<int64_t>(0);662 *p++ = (static_cast<int64_t>(1) << RtsArg::DEV_PTR_DIM_SHIFT_BIT) + static_cast<int64_t>(0);
663 continue;663 continue;
664 }664 }
665- const auto& shape = (*tensors)[i]->GetStorageShape();665+ const auto& shape = (*tensors)[tensorIdx]->GetStorageShape();
666 size_t dim = shape.GetDimNum();666 size_t dim = shape.GetDimNum();
667 *p++ = (static_cast<int64_t>(1) << RtsArg::DEV_PTR_DIM_SHIFT_BIT) + dim;667 *p++ = (static_cast<int64_t>(1) << RtsArg::DEV_PTR_DIM_SHIFT_BIT) + dim;
668 for (size_t j = 0; j < dim; j++) {668 for (size_t j = 0; j < dim; j++) {
669 *p++ = shape.GetDim(j);669 *p++ = shape.GetDim(j);
670 }670 }
671 }671 }
672- for (size_t i = 0; i < tensors->Size(); i++) {672+ for (size_t tensorIdx = 0; tensorIdx < tensors->Size(); tensorIdx++) {
673- if ((*tensors)[i] != nullptr) {673+ if ((*tensors)[tensorIdx] != nullptr) {
674- OP_CHECK((cache->AddLaunchTensor((*tensors)[i], sizeof(void*)) != nullptr),674+ OP_CHECK((cache->AddLaunchTensor((*tensors)[tensorIdx], sizeof(void*)) != nullptr),
675 OP_LOGD("The cache cannot add the launch tensor for devPtrArgAddr, the cache is invalid."),675 OP_LOGD("The cache cannot add the launch tensor for devPtrArgAddr, the cache is invalid."),
676 return);676 return);
677 } else {677 } else {
@@ -20,15 +20,15 @@ aclnnStatus KernelGraphUtils::Link(const KernelNode* fromNode, const KernelNode*
20 }20 }
21 21 
22 auto& fromNodeOutputs = fromNode->GetOutputs();22 auto& fromNodeOutputs = fromNode->GetOutputs();
23- if (from > fromNodeOutputs.size()) {23+ if (from >= fromNodeOutputs.size()) {
24- OP_LOGE(ACLNN_ERR_INNER, "From index %zu is larger than fromNode output size %zu.", from,24+ OP_LOGE(ACLNN_ERR_INNER, "From index %zu is out of range, fromNode output size %zu.", from,
25 fromNodeOutputs.size());25 fromNodeOutputs.size());
26 return ACLNN_ERR_INNER;26 return ACLNN_ERR_INNER;
27 }27 }
28 28 
29 auto& toNodeInputs = toNode->GetInputs();29 auto& toNodeInputs = toNode->GetInputs();
30- if (to > toNodeInputs.size()) {30+ if (to >= toNodeInputs.size()) {
31- OP_LOGE(ACLNN_ERR_INNER, "To index %zu is larger than toNode input size %zu.", to, toNodeInputs.size());31+ OP_LOGE(ACLNN_ERR_INNER, "To index %zu is out of range, toNode input size %zu.", to, toNodeInputs.size());
32 return ACLNN_ERR_INNER;32 return ACLNN_ERR_INNER;
33 }33 }
34 auto* fromTensor = fromNodeOutputs.at(from);34 auto* fromTensor = fromNodeOutputs.at(from);
@@ -159,8 +159,8 @@ TEST_F(KernelLaunchUT, KernelLaunchUTCase4)
159 auto output = OP_OUTPUT(out.get());159 auto output = OP_OUTPUT(out.get());
160 auto ctx = op::MakeOpArgContext(input, output);160 auto ctx = op::MakeOpArgContext(input, output);
161 161 
162- size_t tn_list = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false);162+ size_t tn_list = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false, false);
163- size_t tn = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG), false);163+ size_t tn = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG), false, false);
164 delete inputList;164 delete inputList;
165 op::DestroyOpArgContext(ctx);165 op::DestroyOpArgContext(ctx);
166 EXPECT_EQ(tn, 1u);166 EXPECT_EQ(tn, 1u);
@@ -219,7 +219,7 @@ TEST_F(KernelLaunchUT, GetAclTensorCountTerst1)
219 auto ctx = op::MakeOpArgContext(input_arg);219 auto ctx = op::MakeOpArgContext(input_arg);
220 220 
221 // tbe 语义:null 入参不计数221 // tbe 语义:null 入参不计数
222- size_t num = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false);222+ size_t num = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false, false);
223 op::DestroyOpArgContext(ctx);223 op::DestroyOpArgContext(ctx);
224 EXPECT_EQ(num, 0u);224 EXPECT_EQ(num, 0u);
225}225}
@@ -156,8 +156,8 @@ TEST_F(KernelLaunchNewRtsUT, KernelLaunchUTCase4)
156 auto output = OP_OUTPUT(out.get());156 auto output = OP_OUTPUT(out.get());
157 auto ctx = op::MakeOpArgContext(input, output);157 auto ctx = op::MakeOpArgContext(input, output);
158 158 
159- size_t tn_list = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false);159+ size_t tn_list = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false, false);
160- size_t tn = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG), false);160+ size_t tn = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG), false, false);
161 delete inputList;161 delete inputList;
162 op::DestroyOpArgContext(ctx);162 op::DestroyOpArgContext(ctx);
163 EXPECT_EQ(tn, 1u);163 EXPECT_EQ(tn, 1u);
@@ -254,7 +254,7 @@ TEST_F(KernelLaunchNewRtsUT, GetAclTensorCountTerst1)
254 auto input_arg = OP_INPUT(nullTensor, nullTensorList);254 auto input_arg = OP_INPUT(nullTensor, nullTensorList);
255 auto ctx = op::MakeOpArgContext(input_arg);255 auto ctx = op::MakeOpArgContext(input_arg);
256 // tbe 语义:null 入参不计数256 // tbe 语义:null 入参不计数
257- size_t num = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false);257+ size_t num = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false, false);
258 op::DestroyOpArgContext(ctx);258 op::DestroyOpArgContext(ctx);
259 EXPECT_EQ(num, 0u);259 EXPECT_EQ(num, 0u);
260}260}
@@ -150,6 +150,10 @@ TEST_F(memory_allocator_ut, TestCase1)
150 KernelGraphUtils::Link(b, d, 0, 1);150 KernelGraphUtils::Link(b, d, 0, 1);
151 KernelGraphUtils::Link(d, e, 0, 0);151 KernelGraphUtils::Link(d, e, 0, 0);
152 152 
153+ // 越界索引(index == size)应返回错误码,不应走到 SmallVector::at 的越界异常
154+ EXPECT_EQ(KernelGraphUtils::Link(a, b, 1, 0), ACLNN_ERR_INNER); // a 只声明 1 个输出,索引 1 越界
155+ EXPECT_EQ(KernelGraphUtils::Link(a, b, 0, 1), ACLNN_ERR_INNER); // b 只声明 1 个输入,索引 1 越界
156+ 
153 KernelGraph* kernel_graph = new KernelGraph(0);157 KernelGraph* kernel_graph = new KernelGraph(0);
154 158 
155 op::FVector<KernelNode*, DEFAULT_NODE_NUM> kernel_nodes;159 op::FVector<KernelNode*, DEFAULT_NODE_NUM> kernel_nodes;
@@ -194,8 +194,8 @@ TEST_F(KernelLaunchUT, KernelLaunchUTCase4)
194 194 
195 auto ctx = op::MakeOpArgContext(input, output);195 auto ctx = op::MakeOpArgContext(input, output);
196 196 
197- size_t tn_list = op::internal::GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), false);197+ size_t tn_list = op::internal::GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), false, false);
198- size_t tn = op::internal::GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG)), false);198+ size_t tn = op::internal::GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG)), false, false);
199 delete inputList;199 delete inputList;
200 EXPECT_EQ(tn, 1u);200 EXPECT_EQ(tn, 1u);
201 EXPECT_EQ(tn_list, 2u);201 EXPECT_EQ(tn_list, 2u);
@@ -559,7 +559,7 @@ TEST_F(KernelLaunchUT, GetAclTensorCountTerst1)
559 // create arg559 // create arg
560 auto ctx = op::MakeOpArgContext(input_arg);560 auto ctx = op::MakeOpArgContext(input_arg);
561 // tbe 语义:null 入参不计数561 // tbe 语义:null 入参不计数
562- size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), false);562+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), false, false);
563 EXPECT_EQ(num, 0u);563 EXPECT_EQ(num, 0u);
564}564}
565 565 
@@ -571,7 +571,7 @@ TEST_F(KernelLaunchUT, GetAclTensorCountAscendCPlaceholder)
571 auto input_arg = OP_INPUT(nullTensor, nullTensorList);571 auto input_arg = OP_INPUT(nullTensor, nullTensorList);
572 auto ctx = op::MakeOpArgContext(input_arg);572 auto ctx = op::MakeOpArgContext(input_arg);
573 // nullTensor 计 1,nullTensorList 跳过,期望 1573 // nullTensor 计 1,nullTensorList 跳过,期望 1
574- size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), true);574+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), true, false);
575 EXPECT_EQ(num, 1u);575 EXPECT_EQ(num, 1u);
576}576}
577 577 
@@ -586,10 +586,88 @@ TEST_F(KernelLaunchUT, GetAclTensorCountAscendCPlaceholderAlign)
586 auto input_arg = OP_INPUT(nullTensor, validTensor.get());586 auto input_arg = OP_INPUT(nullTensor, validTensor.get());
587 auto ctx = op::MakeOpArgContext(input_arg);587 auto ctx = op::MakeOpArgContext(input_arg);
588 // null 占位计 1 + 有效 tensor 计 1 = 2u;若 null 被错误跳过则会是 1u588 // null 占位计 1 + 有效 tensor 计 1 = 2u;若 null 被错误跳过则会是 1u
589- size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), true);589+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), true, false);
590 EXPECT_EQ(num, 2u);590 EXPECT_EQ(num, 2u);
591}591}
592 592 
593+TEST_F(KernelLaunchUT, GetAclTensorCountDevPtrTensorList)
594+{
595+ // device ptr 模式:整个 tensorList 占 1 个入参槽位,不按元素展开
596+ op::Shape shape{33, 15, 64};
597+ aclTensor tensor1(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
598+ aclTensor tensor2(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
599+ aclTensor tensor3(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
600+ const aclTensor* tensorArr[3] = {&tensor1, &tensor2, &tensor3};
601+ aclTensorList* tensorList = aclCreateTensorList(tensorArr, 3);
602+ auto input_arg = OP_INPUT(&tensor1, tensorList);
603+ auto ctx = op::MakeOpArgContext(input_arg);
604+ // 有效 tensor 计 1 + 整个 list 计 1 = 2u;若 list 仍按元素展开则为 4u
605+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), false, true);
606+ EXPECT_EQ(num, 2u);
607+ delete tensorList;
608+}
609+ 
610+TEST_F(KernelLaunchUT, GetAclTensorCountDevPtrNullTensorList)
611+{
612+ // device ptr 模式:null tensorList 不占槽位(与下发侧 launch_arg_info.h 一致)
613+ aclTensor* nullTensor = nullptr;
614+ aclTensorList* nullTensorList = nullptr;
615+ auto input_arg = OP_INPUT(nullTensor, nullTensorList);
616+ auto ctx = op::MakeOpArgContext(input_arg);
617+ // null tensor 占位计 1 + null list 计 0 = 1u;若 null list 被误计 1 槽则为 2u
618+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), true, true);
619+ EXPECT_EQ(num, 1u);
620+}
621+ 
622+TEST_F(KernelLaunchUT, GetAclTensorCountDevPtrMixed)
623+{
624+ // device ptr 模式混合输入:null tensor 占位 + 有效 list 计 1 + null list 计 0
625+ aclTensor* nullTensor = nullptr;
626+ aclTensorList* nullTensorList = nullptr;
627+ op::Shape shape{33, 15, 64};
628+ aclTensor tensor1(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
629+ aclTensor tensor2(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
630+ aclTensor tensor3(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
631+ const aclTensor* tensorArr[3] = {&tensor1, &tensor2, &tensor3};
632+ aclTensorList* tensorList = aclCreateTensorList(tensorArr, 3);
633+ auto input_arg = OP_INPUT(nullTensor, tensorList, nullTensorList);
634+ auto ctx = op::MakeOpArgContext(input_arg);
635+ // 1 + 1 + 0 = 2u
636+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), true, true);
637+ EXPECT_EQ(num, 2u);
638+ delete tensorList;
639+}
640+ 
641+TEST_F(KernelLaunchUT, GetAclTensorCountNonDevPtrTensorList)
642+{
643+ // 非 device ptr 模式:list 仍按元素展开(确认原有语义未被破坏)
644+ op::Shape shape{33, 15, 64};
645+ aclTensor tensor1(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
646+ aclTensor tensor2(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
647+ aclTensor tensor3(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
648+ const aclTensor* tensorArr[3] = {&tensor1, &tensor2, &tensor3};
649+ aclTensorList* tensorList = aclCreateTensorList(tensorArr, 3);
650+ auto input_arg = OP_INPUT(&tensor1, tensorList);
651+ auto ctx = op::MakeOpArgContext(input_arg);
652+ // 有效 tensor 计 1 + 3 个元素各计 1 = 4u
653+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), false, false);
654+ EXPECT_EQ(num, 4u);
655+ delete tensorList;
656+}
657+ 
658+TEST_F(KernelLaunchUT, GetAclTensorCountDevPtrNullTensor)
659+{
660+ // device ptr 模式不会让 null tensor 计 1:单 tensor 只受 genPlaceholder 控制
661+ aclTensor* nullTensor = nullptr;
662+ op::Shape shape{33, 15, 64};
663+ aclTensor validTensor(shape, op::DataType::DT_FLOAT, op::Format::FORMAT_ND, nullptr);
664+ auto input_arg = OP_INPUT(nullTensor, &validTensor);
665+ auto ctx = op::MakeOpArgContext(input_arg);
666+ // null tensor 跳过计 0 + 有效 tensor 计 1 = 1u;若 devPtr 让 null tensor 也计 1 则为 2u
667+ size_t num = GetAclTensorCount(*(ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG)), false, true);
668+ EXPECT_EQ(num, 1u);
669+}
670+ 
593TEST_F(KernelLaunchUT, SetMemSetFlagFromJsonTest)671TEST_F(KernelLaunchUT, SetMemSetFlagFromJsonTest)
594{672{
595 const char* p = std::getenv("ASCEND_OPP_PATH");673 const char* p = std::getenv("ASCEND_OPP_PATH");
@@ -196,8 +196,8 @@ TEST_F(KernelLaunchNewRtsUT, KernelLaunchUTCase4)
196 auto output = OP_OUTPUT(out.get());196 auto output = OP_OUTPUT(out.get());
197 auto ctx = op::MakeOpArgContext(input, output);197 auto ctx = op::MakeOpArgContext(input, output);
198 198 
199- size_t tn_list = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false);199+ size_t tn_list = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false, false);
200- size_t tn = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG), false);200+ size_t tn = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_OUTPUT_ARG), false, false);
201 op::DestroyOpArgContext(ctx);201 op::DestroyOpArgContext(ctx);
202 delete inputList;202 delete inputList;
203 EXPECT_EQ(tn, 1u);203 EXPECT_EQ(tn, 1u);
@@ -361,7 +361,7 @@ TEST_F(KernelLaunchNewRtsUT, GetAclTensorCountTerst1)
361 auto ctx = op::MakeOpArgContext(input_arg);361 auto ctx = op::MakeOpArgContext(input_arg);
362 362 
363 // tbe 语义:null 入参不计数363 // tbe 语义:null 入参不计数
364- size_t num = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false);364+ size_t num = op::internal::GetAclTensorCount(*ctx->GetOpArg(op::OpArgDef::OP_INPUT_ARG), false, false);
365 op::DestroyOpArgContext(ctx);365 op::DestroyOpArgContext(ctx);
366 EXPECT_EQ(num, 0u);366 EXPECT_EQ(num, 0u);
367}367}