已合并
【feat】: om2 支持aipp #4082
lidaoming1创建于 7月20日
【feat】: om2 支持aipp #4082
已合并
lidaoming1创建于 7月20日
28 个文件变更+3375-532
CANN-robotCANN-robot7月20日

【openlibing.ci】检测到当前PR中存在代码检查告警抑制 1 处,详情见下表,请Committer检视合理性。 / Detected 1 code check alert suppression(s) in this PR, see table below. Committers please review.

文件路径/File 行号/Line 代码片段/Snippet 工具/Tool
tests/ge/ut/ge/executor/
om2_model_executor_unittest.cc
2507 // NOLINTBEGIN clang-tidy
likedislike
@@ -29,162 +29,12 @@
29 29 
30namespace {30namespace {
31constexpr size_t STATIC_BATCH_INFO_SIZE = 1U;31constexpr size_t STATIC_BATCH_INFO_SIZE = 1U;
32-constexpr uint32_t MAX_NPU_ARCH_LEN = 32U;
33- 
34-static std::string GetNpuArch() {
35- char npuArch[MAX_NPU_ARCH_LEN] = {0};
36- const auto ret = rtGetSocSpec("version", "NpuArch", npuArch, sizeof(npuArch));
37- if (ret != RT_ERROR_NONE) {
38- return "";
39- }
40- return std::string(npuArch);
41-}
42- 
43-static aclError SetIODims(const ge::InputOutputDims &oriDims, aclmdlIODims &dstDims) {
44- ACL_LOG_DEBUG("start to execute SetIODims");
45- dstDims.dimCount = oriDims.dim_num;
46- if (oriDims.dims.size() > static_cast<size_t>(ACL_MAX_DIM_CNT)) {
47- ACL_LOG_INNER_ERROR("[Check][Params]size of dims[%zu] must be smaller than ACL_MAX_DIM_CNT(128)",
48- oriDims.dims.size());
49- return ACL_ERROR_GE_FAILURE;
50- }
51- for (size_t i = 0U; i < oriDims.dims.size(); ++i) {
52- dstDims.dims[i] = oriDims.dims[i];
53- }
54- if (oriDims.name.empty()) {
55- ACL_LOG_DEBUG("the name of oriDims is empty");
56- return ACL_SUCCESS;
57- }
58- const auto ret = strncpy_s(dstDims.name, sizeof(dstDims.name), oriDims.name.c_str(), oriDims.name.size());
59- if (ret != EOK) {
60- ACL_LOG_INNER_ERROR("[Copy][Str]call strncpy_s failed");
61- return ACL_ERROR_FAILURE;
62- }
63- return ACL_SUCCESS;
64-}
65 32 
66/**33/**
67 * @ingroup fp16_t global filed34 * @ingroup fp16_t global filed
68 * @brief round mode of last valid digital35 * @brief round mode of last valid digital
69 */36 */
70 37 
71-union TypeUnion {
72- float32_t fVal;
73- uint32_t uVal;
74-};
75- 
76-#define FP16_EXTRAC_SIGN(x) (((x) >> 15U) & 1U)
77-#define FP16_EXTRAC_EXP(x) (((x) >> 10U) & acl::FP16_MAX_EXP)
78-#define FP16_EXTRAC_MAN(x) ((((x) >> 0U) & 0x3FFU) | ((((((x) >> 10U) & 0x1FU) > 0U) ? 1U : 0U) * 0x400U))
79-#define FP32_CONSTRUCTOR(s, e, m) \
80- (((s) << acl::FP32_SIGN_INDEX) | ((e) << acl::FP32_MAN_LEN) | ((m) & acl::FP32_MAX_MAN))
81- 
82-void ExtractFP16(const uint16_t val, uint16_t *const s, int16_t *const e, uint16_t *const m) {
83- // 1.Extract
84- *s = FP16_EXTRAC_SIGN(val);
85- *e = static_cast<int16_t>(FP16_EXTRAC_EXP(val));
86- *m = FP16_EXTRAC_MAN(val);
87- 
88- // Denormal
89- if ((*e) == 0) {
90- *e = 1;
91- }
92-}
93- 
94-float32_t Fp16ToFloat(const uint16_t val) {
95- uint16_t hfSign;
96- uint16_t hfMan;
97- int16_t hfExp;
98- ExtractFP16(val, &hfSign, &hfExp, &hfMan);
99- 
100- while ((hfMan != 0U) && ((hfMan & acl::FP16_MAN_HIDE_BIT) == 0U)) {
101- hfMan <<= 1U;
102- hfExp--;
103- }
104- 
105- uint32_t eRet;
106- uint32_t mRet;
107- if (hfMan == 0U) {
108- eRet = 0U;
109- mRet = 0U;
110- } else {
111- eRet = static_cast<uint32_t>(hfExp + static_cast<int16_t>(acl::FP32_EXP_BIAS - acl::FP16_EXP_BIAS));
112- mRet = static_cast<uint32_t>(hfMan & acl::FP16_MAN_MASK);
113- mRet = mRet << (acl::FP32_MAN_LEN - acl::FP16_MAN_LEN);
114- }
115- 
116- const uint32_t sRet = hfSign;
117- TypeUnion u;
118- u.uVal = FP32_CONSTRUCTOR(sRet, eRet, mRet);
119- const auto ret = u.fVal;
120- return ret;
121-}
122- 
123-static std::string AippBatchParaDebugString(const kAippDynamicBatchPara &aippBatchPara) {
124- std::stringstream ss;
125- ss << "kAippDynamicBatchPara[";
126- ss << " cropSwitch:" << static_cast<int32_t>(aippBatchPara.cropSwitch);
127- ss << " cropStartPosW:" << aippBatchPara.cropStartPosW;
128- ss << " cropStartPosH:" << aippBatchPara.cropStartPosH;
129- ss << " cropSizeW:" << aippBatchPara.cropSizeW;
130- ss << " cropSizeH:" << aippBatchPara.cropSizeH;
131- ss << " scfSwitch:" << static_cast<int32_t>(aippBatchPara.scfSwitch);
132- ss << " scfInputSizeW:" << aippBatchPara.scfInputSizeW;
133- ss << " scfInputSizeH:" << aippBatchPara.scfInputSizeH;
134- ss << " scfOutputSizeW:" << aippBatchPara.scfOutputSizeW;
135- ss << " scfOutputSizeH:" << aippBatchPara.scfOutputSizeH;
136- ss << " paddingSwitch:" << static_cast<int32_t>(aippBatchPara.paddingSwitch);
137- ss << " paddingSizeTop:" << aippBatchPara.paddingSizeTop;
138- ss << " paddingSizeBottom:" << aippBatchPara.paddingSizeBottom;
139- ss << " paddingSizeLeft:" << aippBatchPara.paddingSizeLeft;
140- ss << " paddingSizeRight:" << aippBatchPara.paddingSizeRight;
141- ss << " rotateSwitch:" << static_cast<int32_t>(aippBatchPara.rotateSwitch);
142- ss << " dtcPixelMeanChn0:" << static_cast<int32_t>(aippBatchPara.dtcPixelMeanChn0);
143- ss << " dtcPixelMeanChn1:" << static_cast<int32_t>(aippBatchPara.dtcPixelMeanChn1);
144- ss << " dtcPixelMeanChn2:" << static_cast<int32_t>(aippBatchPara.dtcPixelMeanChn2);
145- ss << " dtcPixelMeanChn3:" << static_cast<int32_t>(aippBatchPara.dtcPixelMeanChn3);
146- ss << " dtcPixelMinChn0:" << static_cast<uint32_t>(aippBatchPara.dtcPixelMinChn0);
147- ss << " dtcPixelMinChn1:" << static_cast<uint32_t>(aippBatchPara.dtcPixelMinChn1);
148- ss << " dtcPixelMinChn2:" << static_cast<uint32_t>(aippBatchPara.dtcPixelMinChn2);
149- ss << " dtcPixelMinChn3:" << static_cast<uint32_t>(aippBatchPara.dtcPixelMinChn3);
150- ss << " dtcPixelVarReciChn0:" << Fp16ToFloat(aippBatchPara.dtcPixelVarReciChn0);
151- ss << " dtcPixelVarReciChn1:" << Fp16ToFloat(aippBatchPara.dtcPixelVarReciChn1);
152- ss << " dtcPixelVarReciChn2:" << Fp16ToFloat(aippBatchPara.dtcPixelVarReciChn2);
153- ss << " dtcPixelVarReciChn3:" << Fp16ToFloat(aippBatchPara.dtcPixelVarReciChn3);
154- ss << " ]";
155- 
156- return ss.str();
157-}
158- 
159-static std::string AippParmsDebugString(const kAippDynamicPara &aippParms) {
160- std::stringstream ss;
161- ss << "kAippDynamicPara[";
162- ss << " inputFormat:" << static_cast<uint32_t>(aippParms.inputFormat);
163- ss << " cscSwitch:" << static_cast<int32_t>(aippParms.cscSwitch);
164- ss << " rbuvSwapSwitch:" << static_cast<int32_t>(aippParms.rbuvSwapSwitch);
165- ss << " axSwapSwitch:" << static_cast<int32_t>(aippParms.axSwapSwitch);
166- ss << " batchNum:" << static_cast<int32_t>(aippParms.batchNum);
167- ss << " srcImageSizeW:" << aippParms.srcImageSizeW;
168- ss << " srcImageSizeH:" << aippParms.srcImageSizeH;
169- ss << " cscMatrixR0C0:" << static_cast<int32_t>(aippParms.cscMatrixR0C0);
170- ss << " cscMatrixR0C1:" << static_cast<int32_t>(aippParms.cscMatrixR0C1);
171- ss << " cscMatrixR0C2:" << static_cast<int32_t>(aippParms.cscMatrixR0C2);
172- ss << " cscMatrixR1C0:" << static_cast<int32_t>(aippParms.cscMatrixR1C0);
173- ss << " cscMatrixR1C1:" << static_cast<int32_t>(aippParms.cscMatrixR1C1);
174- ss << " cscMatrixR1C2:" << static_cast<int32_t>(aippParms.cscMatrixR1C2);
175- ss << " cscMatrixR2C0:" << static_cast<int32_t>(aippParms.cscMatrixR2C0);
176- ss << " cscMatrixR2C1:" << static_cast<int32_t>(aippParms.cscMatrixR2C1);
177- ss << " cscMatrixR2C2:" << static_cast<int32_t>(aippParms.cscMatrixR2C2);
178- ss << " cscOutputBiasR0:" << static_cast<uint32_t>(aippParms.cscOutputBiasR0);
179- ss << " cscOutputBiasR1:" << static_cast<uint32_t>(aippParms.cscOutputBiasR1);
180- ss << " cscOutputBiasR2:" << static_cast<uint32_t>(aippParms.cscOutputBiasR2);
181- ss << " cscInputBiasR0:" << static_cast<uint32_t>(aippParms.cscInputBiasR0);
182- ss << " cscInputBiasR1:" << static_cast<uint32_t>(aippParms.cscInputBiasR1);
183- ss << " cscInputBiasR2:" << static_cast<uint32_t>(aippParms.cscInputBiasR2);
184- ss << " ]";
185- 
186- return ss.str();
187-}
188static bool IsDynamicModel(const uint32_t modelId, std::shared_ptr<gert::ModelV2Executor> &executorRt2) {38static bool IsDynamicModel(const uint32_t modelId, std::shared_ptr<gert::ModelV2Executor> &executorRt2) {
189 if (acl::AclResourceManager::GetInstance().IsRuntimeV2Enable(true)) {39 if (acl::AclResourceManager::GetInstance().IsRuntimeV2Enable(true)) {
190 executorRt2 = acl::AclResourceManager::GetInstance().GetExecutor(modelId);40 executorRt2 = acl::AclResourceManager::GetInstance().GetExecutor(modelId);
@@ -254,19 +104,6 @@ static ge::Status GetAippType(const uint32_t modelId, const uint32_t index, ge::
254 }104 }
255}105}
256 106 
257-static size_t GetMaxShapeIndex(const std::vector<ge::InputOutputDims> &inputDims) {
258- size_t maxShapeIndex = 0U;
259- uint32_t shapeSize = 0U;
260- for (size_t i = 0U; i < inputDims.size(); ++i) {
261- if (inputDims[i].size > shapeSize) {
262- shapeSize = inputDims[i].size;
263- maxShapeIndex = i;
264- }
265- }
266- ACL_LOG_INFO("GetMaxShapeIndex success, maxShapeIndex[%zu]", maxShapeIndex);
267- return maxShapeIndex;
268-}
269- 
270static aclError GetModelOriDims(const uint32_t modelId, const uint32_t relatedInputRank, bool &isGetDim,107static aclError GetModelOriDims(const uint32_t modelId, const uint32_t relatedInputRank, bool &isGetDim,
271 int64_t &mdlOriH, int64_t &mdlOriW, int64_t &mdlOriN) {108 int64_t &mdlOriH, int64_t &mdlOriW, int64_t &mdlOriN) {
272 // get model origin input info109 // get model origin input info
@@ -301,9 +138,9 @@ static aclError GetModelOriDims(const uint32_t modelId, const uint32_t relatedIn
301 return ACL_ERROR_GE_FAILURE;138 return ACL_ERROR_GE_FAILURE;
302 }139 }
303 // Get the index of the maximum gear140 // Get the index of the maximum gear
304- const size_t maxShapeIndex = GetMaxShapeIndex(inputDims);141+ const size_t maxShapeIndex = acl::GetMaxShapeIndex(inputDims);
305 aclmdlIODims srcDims;142 aclmdlIODims srcDims;
306- const aclError ioRet = SetIODims(inputDims[maxShapeIndex], srcDims);143+ const aclError ioRet = acl::SetIODims(inputDims[maxShapeIndex], srcDims);
307 if (ioRet != ACL_SUCCESS) {144 if (ioRet != ACL_SUCCESS) {
308 ACL_LOG_INNER_ERROR("[Set][IODims]srcDims SetIODims failed, modelId[%u], result[%d]", modelId, ioRet);145 ACL_LOG_INNER_ERROR("[Set][IODims]srcDims SetIODims failed, modelId[%u], result[%d]", modelId, ioRet);
309 return ioRet;146 return ioRet;
@@ -357,7 +194,7 @@ static aclError GetAndCheckAippOutputShape(const uint32_t modelId, const aclmdlD
357 int64_t mdlOriH = 0;194 int64_t mdlOriH = 0;
358 int64_t mdlOriW = 0;195 int64_t mdlOriW = 0;
359 int64_t mdlOriN = 0;196 int64_t mdlOriN = 0;
360- const aclError result = acl::GetAippOutputHW(aippParmsSet, 0U, GetNpuArch(), aippOutputW, aippOutputH);197+ const aclError result = acl::GetAippOutputHW(aippParmsSet, 0U, acl::GetNpuArch(), aippOutputW, aippOutputH);
361 if (result != ACL_SUCCESS) {198 if (result != ACL_SUCCESS) {
362 return result;199 return result;
363 }200 }
@@ -421,7 +258,7 @@ static aclError GetAndCheckAippParams(const uint32_t modelId, const aclmdlDesc &
421 } else {258 } else {
422 ACL_LOG_INFO("current used model is old");259 ACL_LOG_INFO("current used model is old");
423 }260 }
424- return acl::AippParamsCheck(aippParmsSet, GetNpuArch());261+ return acl::AippParamsCheck(aippParmsSet, acl::GetNpuArch());
425}262}
426 263 
427static aclError VerifyIndex(const uint32_t modelId, const size_t idx, aclmdlDesc *const modelDesc) {264static aclError VerifyIndex(const uint32_t modelId, const size_t idx, aclmdlDesc *const modelDesc) {
@@ -474,163 +311,6 @@ static aclError CheckAippDataIndex(const uint32_t modelId, const size_t idx, con
474 }311 }
475}312}
476 313 
477-static std::string AippInfoDebugString(const aclAippInfo *const aippInfo) {
478- if (aippInfo == nullptr) {
479- ACL_LOG_INNER_ERROR("[Check][aippInfo]param aippInfo must not be null");
480- return "";
481- }
482- std::stringstream ss;
483- ss << "aclAippInfo[";
484- ss << " inputFormat:" << static_cast<int32_t>(aippInfo->inputFormat);
485- ss << " srcImageSizeW:" << aippInfo->srcImageSizeW;
486- ss << " srcImageSizeH:" << aippInfo->srcImageSizeH;
487- 
488- ss << " cropSwitch:" << static_cast<int32_t>(aippInfo->cropSwitch);
489- ss << " loadStartPosW:" << aippInfo->loadStartPosW;
490- ss << " loadStartPosH:" << aippInfo->loadStartPosH;
491- ss << " cropSizeW:" << aippInfo->cropSizeW;
492- ss << " cropSizeH:" << aippInfo->cropSizeH;
493- 
494- ss << " resizeSwitch:" << static_cast<int32_t>(aippInfo->resizeSwitch);
495- ss << " resizeOutputW:" << aippInfo->resizeOutputW;
496- ss << " resizeOutputH:" << aippInfo->resizeOutputH;
497- 
498- ss << " paddingSwitch:" << static_cast<int32_t>(aippInfo->paddingSwitch);
499- ss << " leftPaddingSize:" << aippInfo->leftPaddingSize;
500- ss << " rightPaddingSize:" << aippInfo->rightPaddingSize;
501- ss << " topPaddingSize:" << aippInfo->topPaddingSize;
502- ss << " bottomPaddingSize:" << aippInfo->bottomPaddingSize;
503- 
504- ss << " cscSwitch:" << static_cast<int32_t>(aippInfo->cscSwitch);
505- ss << " rbuvSwapSwitch:" << static_cast<int32_t>(aippInfo->rbuvSwapSwitch);
506- ss << " axSwapSwitch:" << static_cast<int32_t>(aippInfo->axSwapSwitch);
507- ss << " singleLineMode:" << static_cast<int32_t>(aippInfo->singleLineMode);
508- 
509- ss << " matrixR0C0:" << aippInfo->matrixR0C0;
510- ss << " matrixR0C1:" << aippInfo->matrixR0C1;
511- ss << " matrixR0C2:" << aippInfo->matrixR0C2;
512- ss << " matrixR1C0:" << aippInfo->matrixR1C0;
513- ss << " matrixR1C1:" << aippInfo->matrixR1C1;
514- ss << " matrixR1C2:" << aippInfo->matrixR1C2;
515- ss << " matrixR2C0:" << aippInfo->matrixR2C0;
516- ss << " matrixR2C1:" << aippInfo->matrixR2C1;
517- ss << " matrixR2C2:" << aippInfo->matrixR2C2;
518- 
519- ss << " outputBias0:" << aippInfo->outputBias0;
520- ss << " outputBias1:" << aippInfo->outputBias1;
521- ss << " outputBias2:" << aippInfo->outputBias2;
522- ss << " inputBias0:" << aippInfo->inputBias0;
523- ss << " inputBias1:" << aippInfo->inputBias1;
524- ss << " inputBias2:" << aippInfo->inputBias2;
525- 
526- ss << " meanChn0:" << aippInfo->meanChn0;
527- ss << " meanChn1:" << aippInfo->meanChn1;
528- ss << " meanChn2:" << aippInfo->meanChn2;
529- ss << " meanChn3:" << aippInfo->meanChn3;
530- ss << " minChn0:" << aippInfo->minChn0;
531- ss << " minChn1:" << aippInfo->minChn1;
532- ss << " minChn2:" << aippInfo->minChn2;
533- ss << " minChn3:" << aippInfo->minChn3;
534- ss << " varReciChn0:" << aippInfo->varReciChn0;
535- ss << " varReciChn1:" << aippInfo->varReciChn1;
536- ss << " varReciChn2:" << aippInfo->varReciChn2;
537- ss << " varReciChn3:" << aippInfo->varReciChn3;
538- 
539- ss << " shapeCount:" << aippInfo->shapeCount;
540- ss << " srcFormat:" << aippInfo->srcFormat;
541- ss << " srcDatatype:" << aippInfo->srcDatatype;
542- ss << " srcDimNum:" << aippInfo->srcDimNum;
543- ss << " ]";
544- return ss.str();
545-}
546- 
547-static std::string DimsDebugString(const aclmdlIODims &ioDims) {
548- std::stringstream ss;
549- ss << "[" << " tensorName:" << ioDims.name;
550- ss << " dimcount:" << static_cast<int32_t>(ioDims.dimCount);
551- ss << " dims:";
552- for (size_t i = 0U; i < ioDims.dimCount; i++) {
553- ss << " " << ioDims.dims[i];
554- }
555- ss << "]; ";
556- return ss.str();
557-}
558- 
559-static std::string AippDimsDebugString(const aclAippDims *const aippDims, const size_t shapeCount) {
560- std::stringstream ssDims;
561- for (size_t i = 0U; i < shapeCount; i++) {
562- ssDims << " aclAippDims[" << i << "]: ";
563- ssDims << DimsDebugString(aippDims[i].srcDims);
564- ssDims << " srcSize:" << aippDims[i].srcSize;
565- ssDims << DimsDebugString(aippDims[i].aippOutdims);
566- ssDims << " aippOutSize:" << aippDims[i].aippOutSize;
567- }
568- return ssDims.str();
569-}
570- 
571-static void SetAippInfo(aclAippInfo *const aippInfo, const ge::AippConfigInfo &aippParams) {
572- ACL_LOG_DEBUG("start to execute SetAippInfo");
573- if (aippInfo == nullptr) {
574- ACL_LOG_INNER_ERROR("[Check][AippInfo]param aippInfo must not be null");
575- return;
576- }
577- aippInfo->inputFormat = static_cast<aclAippInputFormat>(aippParams.input_format);
578- aippInfo->srcImageSizeW = aippParams.src_image_size_w;
579- aippInfo->srcImageSizeH = aippParams.src_image_size_h;
580- 
581- aippInfo->cropSwitch = aippParams.crop;
582- aippInfo->loadStartPosW = aippParams.load_start_pos_w;
583- aippInfo->loadStartPosH = aippParams.load_start_pos_h;
584- aippInfo->cropSizeW = aippParams.crop_size_w;
585- aippInfo->cropSizeH = aippParams.crop_size_h;
586- 
587- aippInfo->resizeSwitch = aippParams.resize;
588- aippInfo->resizeOutputW = aippParams.resize_output_w;
589- aippInfo->resizeOutputH = aippParams.resize_output_h;
590- 
591- aippInfo->paddingSwitch = aippParams.padding;
592- aippInfo->leftPaddingSize = aippParams.left_padding_size;
593- aippInfo->rightPaddingSize = aippParams.right_padding_size;
594- aippInfo->topPaddingSize = aippParams.top_padding_size;
595- aippInfo->bottomPaddingSize = aippParams.bottom_padding_size;
596- 
597- aippInfo->cscSwitch = aippParams.csc_switch;
598- aippInfo->rbuvSwapSwitch = aippParams.rbuv_swap_switch;
599- aippInfo->axSwapSwitch = aippParams.ax_swap_switch;
600- aippInfo->singleLineMode = aippParams.single_line_mode;
601- 
602- aippInfo->matrixR0C0 = aippParams.matrix_r0c0;
603- aippInfo->matrixR0C1 = aippParams.matrix_r0c1;
604- aippInfo->matrixR0C2 = aippParams.matrix_r0c2;
605- aippInfo->matrixR1C0 = aippParams.matrix_r1c0;
606- aippInfo->matrixR1C1 = aippParams.matrix_r1c1;
607- aippInfo->matrixR1C2 = aippParams.matrix_r1c2;
608- aippInfo->matrixR2C0 = aippParams.matrix_r2c0;
609- aippInfo->matrixR2C1 = aippParams.matrix_r2c1;
610- aippInfo->matrixR2C2 = aippParams.matrix_r2c2;
611- 
612- aippInfo->outputBias0 = aippParams.output_bias_0;
613- aippInfo->outputBias1 = aippParams.output_bias_1;
614- aippInfo->outputBias2 = aippParams.output_bias_2;
615- aippInfo->inputBias0 = aippParams.input_bias_0;
616- aippInfo->inputBias1 = aippParams.input_bias_1;
617- aippInfo->inputBias2 = aippParams.input_bias_2;
618- 
619- aippInfo->meanChn0 = aippParams.mean_chn_0;
620- aippInfo->meanChn1 = aippParams.mean_chn_1;
621- aippInfo->meanChn2 = aippParams.mean_chn_2;
622- aippInfo->meanChn3 = aippParams.mean_chn_3;
623- aippInfo->minChn0 = aippParams.min_chn_0;
624- aippInfo->minChn1 = aippParams.min_chn_1;
625- aippInfo->minChn2 = aippParams.min_chn_2;
626- aippInfo->minChn3 = aippParams.min_chn_3;
627- 
628- aippInfo->varReciChn0 = aippParams.var_reci_chn_0;
629- aippInfo->varReciChn1 = aippParams.var_reci_chn_1;
630- aippInfo->varReciChn2 = aippParams.var_reci_chn_2;
631- aippInfo->varReciChn3 = aippParams.var_reci_chn_3;
632- ACL_LOG_DEBUG("end to execute SetAippInfo");
633-}
634} // namespace314} // namespace
635 315 
636namespace acl {316namespace acl {
@@ -756,10 +436,10 @@ aclError aclmdlSetInputAIPPImpl(uint32_t modelId, aclmdlDataset *dataset, size_t
756 return ACL_ERROR_INVALID_PARAM;436 return ACL_ERROR_INVALID_PARAM;
757 }437 }
758 const uint64_t memSize = aclGetDataBufferSizeV2(buff);438 const uint64_t memSize = aclGetDataBufferSizeV2(buff);
759- ACL_LOG_DEBUG("aippParmsSet->aippParms: %s .", AippParmsDebugString(aippParmsSet->aippParms).c_str());439+ ACL_LOG_DEBUG("aippParmsSet->aippParms: %s .", acl::AippParmsDebugString(aippParmsSet->aippParms).c_str());
760 for (size_t i = 0U; i < aippParmsSet->aippBatchPara.size(); ++i) {440 for (size_t i = 0U; i < aippParmsSet->aippBatchPara.size(); ++i) {
761 ACL_LOG_DEBUG("batchIndex[%lu] aippParmsSet->aippBatchPara: %s .", i,441 ACL_LOG_DEBUG("batchIndex[%lu] aippParmsSet->aippBatchPara: %s .", i,
762- AippBatchParaDebugString(aippParmsSet->aippBatchPara[i]).c_str());442+ acl::AippBatchParaDebugString(aippParmsSet->aippBatchPara[i]).c_str());
763 }443 }
764 // send dynamic aipp to GE444 // send dynamic aipp to GE
765 ACL_LOG_INFO("call ge interface executor.SetDynamicAippData, modelId[%u]", modelId);445 ACL_LOG_INFO("call ge interface executor.SetDynamicAippData, modelId[%u]", modelId);
@@ -839,7 +519,7 @@ aclError aclmdlGetFirstAippInfoImpl(uint32_t modelId, size_t index, aclAippInfo
839 ret);519 ret);
840 return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));520 return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
841 }521 }
842- SetAippInfo(aippInfo, aippParams);522+ acl::SetAippInfo(aippInfo, aippParams);
843 size_t shapeCount;523 size_t shapeCount;
844 ACL_LOG_DEBUG("call ge interface executor.GetBatchInfoSize");524 ACL_LOG_DEBUG("call ge interface executor.GetBatchInfoSize");
845 std::shared_ptr<gert::ModelV2Executor> executorRt2;525 std::shared_ptr<gert::ModelV2Executor> executorRt2;
@@ -870,7 +550,7 @@ aclError aclmdlGetFirstAippInfoImpl(uint32_t modelId, size_t index, aclAippInfo
870 aippInfo->srcFormat = static_cast<aclFormat>(inputInfo.format);550 aippInfo->srcFormat = static_cast<aclFormat>(inputInfo.format);
871 aippInfo->srcDatatype = static_cast<aclDataType>(inputInfo.data_type);551 aippInfo->srcDatatype = static_cast<aclDataType>(inputInfo.data_type);
872 aippInfo->srcDimNum = inputInfo.dim_num;552 aippInfo->srcDimNum = inputInfo.dim_num;
873- ACL_LOG_DEBUG("aclAippInfo: %s .", AippInfoDebugString(aippInfo).c_str());553+ ACL_LOG_DEBUG("aclAippInfo: %s .", acl::AippInfoDebugString(aippInfo).c_str());
874 554 
875 std::vector<ge::InputOutputDims> inputDims;555 std::vector<ge::InputOutputDims> inputDims;
876 std::vector<ge::InputOutputDims> outputDims;556 std::vector<ge::InputOutputDims> outputDims;
@@ -894,14 +574,14 @@ aclError aclmdlGetFirstAippInfoImpl(uint32_t modelId, size_t index, aclAippInfo
894 return ACL_ERROR_GE_FAILURE;574 return ACL_ERROR_GE_FAILURE;
895 }575 }
896 for (size_t i = 0U; i < shapeCount; i++) {576 for (size_t i = 0U; i < shapeCount; i++) {
897- aclError ioRet = SetIODims(inputDims[i], aippInfo->outDims[i].srcDims);577+ aclError ioRet = acl::SetIODims(inputDims[i], aippInfo->outDims[i].srcDims);
898 if (ioRet != ACL_SUCCESS) {578 if (ioRet != ACL_SUCCESS) {
899 ACL_LOG_INNER_ERROR("[Set][IODims]srcDims SetIODims failed, modelId[%u], index[%zu], result[%d]", modelId, index,579 ACL_LOG_INNER_ERROR("[Set][IODims]srcDims SetIODims failed, modelId[%u], index[%zu], result[%d]", modelId, index,
900 ioRet);580 ioRet);
901 return ioRet;581 return ioRet;
902 }582 }
903 aippInfo->outDims[i].srcSize = inputDims[i].size;583 aippInfo->outDims[i].srcSize = inputDims[i].size;
904- ioRet = SetIODims(outputDims[i], aippInfo->outDims[i].aippOutdims);584+ ioRet = acl::SetIODims(outputDims[i], aippInfo->outDims[i].aippOutdims);
905 if (ioRet != ACL_SUCCESS) {585 if (ioRet != ACL_SUCCESS) {
906 ACL_LOG_INNER_ERROR("[Set][IODims]aippOutdims SetIODims failed, modelId[%u], index[%zu], result[%d]", modelId,586 ACL_LOG_INNER_ERROR("[Set][IODims]aippOutdims SetIODims failed, modelId[%u], index[%zu], result[%d]", modelId,
907 index, ioRet);587 index, ioRet);
@@ -910,6 +590,6 @@ aclError aclmdlGetFirstAippInfoImpl(uint32_t modelId, size_t index, aclAippInfo
910 aippInfo->outDims[i].aippOutSize = outputDims[i].size;590 aippInfo->outDims[i].aippOutSize = outputDims[i].size;
911 }591 }
912 ACL_LOG_DEBUG("successfully execute aclmdlGetFirstAippInfo, aclAippDims: %s",592 ACL_LOG_DEBUG("successfully execute aclmdlGetFirstAippInfo, aclAippDims: %s",
913- AippDimsDebugString(aippInfo->outDims, aippInfo->shapeCount).c_str());593+ acl::AippDimsDebugString(aippInfo->outDims, aippInfo->shapeCount).c_str());
914 return ACL_SUCCESS;594 return ACL_SUCCESS;
915}595}
@@ -9,13 +9,21 @@
9 */9 */
10 10 
11#include <map>11#include <map>
12+#include <sstream>
12#include "acl/acl_mdl.h"13#include "acl/acl_mdl.h"
14+#include "common/prof_api_reg.h"
15+#include "acl/acl_rt.h"
13#include "common/dynamic_aipp.h"16#include "common/dynamic_aipp.h"
14#include "model_desc_internal.h"17#include "model_desc_internal.h"
15#include "common/log_inner.h"18#include "common/log_inner.h"
16#include "utils/math_utils.h"19#include "utils/math_utils.h"
17#include "model/acl_model_impl_om2.h"20#include "model/acl_model_impl_om2.h"
18#include "model_common.h"21#include "model_common.h"
22+#include "acl_resource_manager_om2.h"
23+#include "framework/runtime/om2_model_executor.h"
24+#include "error_codes_inner.h"
25+#include "securec.h"
26+#include "aipp_param_check.h"
19 27 
20namespace acl {28namespace acl {
21struct Fp16Type {29struct Fp16Type {
@@ -95,6 +103,230 @@ struct Fp16Type {
95};103};
96} // namespace acl104} // namespace acl
97 105 
106+namespace {
107+aclError VerifyIndexOm2(const std::shared_ptr<gert::Om2ModelExecutor> &executor, size_t index) {
108+ const std::vector<ge::Om2TensorDesc> *input_desc = nullptr;
109+ const std::vector<ge::Om2TensorDesc> *output_desc = nullptr;
110+ const auto ret = executor->GetModelDescInfo(input_desc, output_desc);
111+ if (ret != ge::SUCCESS || input_desc == nullptr) {
112+ ACL_LOG_INNER_ERROR("[Get][ModelDesc]GetModelDescInfo failed, ret[%u]", ret);
113+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
114+ }
115+ if (index >= input_desc->size()) {
116+ ACL_LOG_ERROR("[Check][Index]index[%zu] is invalid, input tensor count is %zu", index, input_desc->size());
117+ return ACL_ERROR_INVALID_PARAM;
118+ }
119+ return ACL_SUCCESS;
120+}
121+ 
122+static aclError CheckAippDataIndexOm2(const std::shared_ptr<gert::Om2ModelExecutor> &executor, const uint32_t modelId,
123+ const size_t idx) {
124+ ACL_LOG_INFO("call ge interface executor.GetAippType, modelId[%u]", modelId);
125+ ge::InputAippType type;
126+ size_t aippIndex = 0U;
127+ const ge::Status ret = executor->GetAippType(static_cast<uint32_t>(idx), type, aippIndex);
128+ if (ret != ge::SUCCESS) {
129+ ACL_LOG_CALL_ERROR("[Get][AippType]Get aipp type failed, ge result[%u]", ret);
130+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
131+ }
132+ if (type == ge::DYNAMIC_AIPP_NODE) {
133+ ACL_LOG_INFO("Index [%zu] entered by the user is dynamic aipp data", idx);
134+ return ACL_SUCCESS;
135+ } else if (type == ge::DATA_WITHOUT_AIPP) {
136+ // maybe this is old om when getaipptype interface is unsupported, ensure compatibility
137+ const std::vector<ge::Om2TensorDesc> *input_desc = nullptr;
138+ const std::vector<ge::Om2TensorDesc> *output_desc = nullptr;
139+ const auto desc_ret = executor->GetModelDescInfo(input_desc, output_desc);
140+ if (desc_ret != ge::SUCCESS || input_desc == nullptr) {
141+ ACL_LOG_INNER_ERROR("[Get][ModelDesc]GetModelDescInfo failed, ret[%u]", desc_ret);
142+ return ACL_ERROR_INVALID_PARAM;
143+ }
144+ size_t index_in_model = 0U;
145+ bool found = false;
146+ for (size_t i = 0U; i < input_desc->size(); ++i) {
147+ if ((*input_desc)[i].GetName() == "ascend_dynamic_aipp_data") {
148+ index_in_model = i;
149+ found = true;
150+ break;
151+ }
152+ }
153+ if (!found) {
154+ ACL_LOG_INNER_ERROR("[Get][InputIndex]the model is not a dynamic aipp model, there is no dynamic aipp node");
155+ return ACL_ERROR_INVALID_PARAM;
156+ }
157+ if (index_in_model != idx) {
158+ ACL_LOG_INNER_ERROR("[Check][indexInModel]index[%zu] entered by the user is not dynamic aipp index[%zu]", idx,
159+ index_in_model);
160+ return ACL_ERROR_INVALID_PARAM;
161+ }
162+ return ACL_SUCCESS;
163+ } else {
164+ ACL_LOG_INNER_ERROR("[Check][Index]index[%zu] entered by the user is not dynamic aipp data index.", idx);
165+ return ACL_ERROR_INVALID_PARAM;
166+ }
167+}
168+ 
169+static aclError GetModelOriDimsOm2(const std::shared_ptr<gert::Om2ModelExecutor> &executor, const uint32_t model_id,
170+ const uint32_t related_input_rank, bool &is_get_dim, int64_t &mdl_ori_h,
171+ int64_t &mdl_ori_w, int64_t &mdl_ori_n) {
172+ // get model origin input info
173+ ge::OriginInputInfo input_info;
174+ auto ret = executor->GetOrigInputInfo(related_input_rank, input_info);
175+ if (ret != ge::SUCCESS) {
176+ ACL_LOG_CALL_ERROR("[Get][OrigInputInfo]GetOrigInputInfo failed, modelId[%u], index[%u], ret[%u]", model_id,
177+ related_input_rank, ret);
178+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
179+ }
180+ const aclFormat src_format = static_cast<aclFormat>(input_info.format);
181+ 
182+ // get model origin input dims
183+ std::vector<ge::InputOutputDims> input_dims;
184+ std::vector<ge::InputOutputDims> output_dims;
185+ ret = executor->GetAllAippInputOutputDims(related_input_rank, input_dims, output_dims);
186+ if (ret != ge::SUCCESS) {
187+ ACL_LOG_CALL_ERROR("[Get][AllAippInputOutputDims]GetAllAippInputOutputDims failed, modelId[%u], index[%u], ret[%u]",
188+ model_id, related_input_rank, ret);
189+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
190+ }
191+ 
192+ // Parse NHW from input Dims when inputDims is not empty
193+ if (input_dims.empty()) {
194+ ACL_LOG_INNER_ERROR("[Check][InputDims]get model origin input dims fail, origin input dims is empty");
195+ return ACL_ERROR_GE_FAILURE;
196+ }
197+ // Get the index of the maximum gear
198+ const size_t max_shape_index = acl::GetMaxShapeIndex(input_dims);
199+ aclmdlIODims src_dims;
200+ const aclError io_ret = acl::SetIODims(input_dims[max_shape_index], src_dims);
201+ if (io_ret != ACL_SUCCESS) {
202+ ACL_LOG_INNER_ERROR("[Set][IODims]srcDims SetIODims failed, modelId[%u], result[%d]", model_id, io_ret);
203+ return io_ret;
204+ }
205+ switch (src_format) {
206+ case ACL_FORMAT_NCHW:
207+ if (src_dims.dimCount == 4U) {
208+ mdl_ori_h = src_dims.dims[2];
209+ mdl_ori_w = src_dims.dims[3];
210+ mdl_ori_n = src_dims.dims[0];
211+ }
212+ is_get_dim = true;
213+ break;
214+ case ACL_FORMAT_NHWC:
215+ if (src_dims.dimCount == 4U) {
216+ mdl_ori_h = src_dims.dims[1];
217+ mdl_ori_w = src_dims.dims[2];
218+ mdl_ori_n = src_dims.dims[0];
219+ }
220+ is_get_dim = true;
221+ break;
222+ default:
223+ ACL_LOG_INFO("the model origin format[%d] is invalid, only support ACL_FORMAT_NHWC or ACL_FORMAT_NCHW",
224+ static_cast<int32_t>(src_format));
225+ is_get_dim = false;
226+ break;
227+ }
228+ return ACL_SUCCESS;
229+}
230+ 
231+static aclError GetAndCheckAippOutputShapeOm2(const std::shared_ptr<gert::Om2ModelExecutor> &executor,
232+ const uint32_t model_id, const uint32_t idx,
233+ const aclmdlAIPP *const aipp_parms_set) {
234+ const int64_t batch_size = static_cast<int64_t>(aipp_parms_set->batchSize);
235+ 
236+ const std::vector<ge::Om2TensorDesc> *input_desc = nullptr;
237+ const std::vector<ge::Om2TensorDesc> *output_desc = nullptr;
238+ const auto desc_ret = executor->GetModelDescInfo(input_desc, output_desc);
239+ if (desc_ret != ge::SUCCESS || input_desc == nullptr) {
240+ ACL_LOG_INNER_ERROR("[Get][ModelDesc]GetModelDescInfo failed, ret[%u]", desc_ret);
241+ return ACL_ERROR_INVALID_PARAM;
242+ }
243+ if (idx >= input_desc->size()) {
244+ ACL_LOG_INNER_ERROR("[Check][Params]index[%u] cannot greater than or equal to tensor size[%zu]", idx,
245+ input_desc->size());
246+ return ACL_ERROR_INVALID_PARAM;
247+ }
248+ const auto &shape_ranges = (*input_desc)[idx].GetShapeRange();
249+ if (!shape_ranges.empty()) {
250+ ACL_LOG_INFO("check aipp parameters of dynamic shape model[%u]", model_id);
251+ return ACL_SUCCESS;
252+ }
253+ 
254+ ACL_LOG_INFO("check aipp parameters of static shape model[%u]", model_id);
255+ int32_t aipp_output_w = 0;
256+ int32_t aipp_output_h = 0;
257+ const aclError hw_ret = acl::GetAippOutputHW(aipp_parms_set, 0U, acl::GetNpuArch(), aipp_output_w, aipp_output_h);
258+ if (hw_ret != ACL_SUCCESS) {
259+ return hw_ret;
260+ }
261+ 
262+ bool is_get_dim = false;
263+ int64_t mdl_ori_h = 0;
264+ int64_t mdl_ori_w = 0;
265+ int64_t mdl_ori_n = 0;
266+ const aclError mdl_ret = GetModelOriDimsOm2(executor, model_id, idx, is_get_dim, mdl_ori_h, mdl_ori_w, mdl_ori_n);
267+ if (mdl_ret != ACL_SUCCESS) {
268+ ACL_LOG_INNER_ERROR("[Get][ModelOriDims]get model original dims fail");
269+ return mdl_ret;
270+ }
271+ 
272+ if (is_get_dim) {
273+ ACL_LOG_INFO("relatedInputRank[%u], mdlOriH[%ld], mdlOriW[%ld], mdlOriN[%ld]", idx, mdl_ori_h, mdl_ori_w,
274+ mdl_ori_n);
275+ // check batchSize
276+ if ((batch_size != mdl_ori_n) || (aipp_output_w != mdl_ori_w) || (aipp_output_h != mdl_ori_h)) {
277+ ACL_LOG_ERROR(
278+ "[Check][Params]aipp output shape set by ACL must be equal to aipp output shape in the model! "
279+ "AclAippBatchSize = %ld, AclAippOutputW = %d, AclAippOutputH = %d, "
280+ "ModelAippBatchSize = %ld, ModelAippOutputW = %ld, ModelAippOutputH = %ld.",
281+ batch_size, aipp_output_w, aipp_output_h, mdl_ori_n, mdl_ori_w, mdl_ori_h);
282+ const std::string errMsg = acl::AclErrorLogManager::FormatStr(
283+ "aipp output shape set by ACL "
284+ "must be equal to aipp output shape in the model! AclAippBatchSize = %ld, AclAippOutputW = %d, "
285+ "AclAippOutputH = %d, ModelAippBatchSize = %ld, ModelAippOutputW = %ld, ModelAippOutputH = %ld.",
286+ batch_size, aipp_output_w, aipp_output_h, mdl_ori_n, mdl_ori_w, mdl_ori_h);
287+ acl::AclErrorLogManager::ReportInputError(acl::INVALID_AIPP_MSG, std::vector<const char *>({"param", "reason"}),
288+ std::vector<const char *>({"dynamic aipp shape", errMsg.c_str()}));
289+ return ACL_ERROR_INVALID_PARAM;
290+ }
291+ } else {
292+ ACL_LOG_INFO("cant not get model H W N, current used model is old");
293+ }
294+ return ACL_SUCCESS;
295+}
296+ 
297+static aclError GetAndCheckAippParamsOm2(const std::shared_ptr<gert::Om2ModelExecutor> &executor,
298+ const uint32_t modelId, const size_t idx,
299+ const aclmdlAIPP *const aippParmsSet) {
300+ // check dynamic aipp parameters
301+ ge::AippConfigInfo aippParams;
302+ const auto aipp_ret = executor->GetAippInfo(static_cast<uint32_t>(idx), aippParams);
303+ if (aipp_ret == ge::SUCCESS) {
304+ const uint32_t relatedInputRank = aippParams.related_input_rank;
305+ const uint64_t maxSrcImageSize = static_cast<uint64_t>(aippParams.max_src_image_size);
306+ // check max_src_image_size
307+ const uint64_t size = acl::GetSrcImageSize(aippParmsSet);
308+ ACL_LOG_INFO("Input SrcImageSize = %lu", size);
309+ if (size > maxSrcImageSize) {
310+ ACL_LOG_ERROR("[Check][Size]the dynamic aipp size[%lu] is bigger than max_src_image_size[%lu]", size,
311+ maxSrcImageSize);
312+ const std::string errMsg =
313+ acl::AclErrorLogManager::FormatStr("bigger than max_src_image_size[%lu]", maxSrcImageSize);
314+ acl::AclErrorLogManager::ReportInputError(acl::INVALID_AIPP_MSG, std::vector<const char *>({"param", "reason"}),
315+ std::vector<const char *>({"dynamic aipp size", errMsg.c_str()}));
316+ return ACL_ERROR_INVALID_PARAM;
317+ }
318+ const aclError ret =
319+ GetAndCheckAippOutputShapeOm2(executor, modelId, static_cast<uint32_t>(relatedInputRank), aippParmsSet);
320+ if (ret != ACL_SUCCESS) {
321+ return ret;
322+ }
323+ } else {
324+ ACL_LOG_INFO("current used model is old");
325+ }
326+ return acl::AippParamsCheck(aippParmsSet, acl::GetNpuArch());
327+}
328+} // namespace
329+ 
98aclmdlAIPP *aclmdlCreateAIPPImplOm2(uint64_t batchSize) {330aclmdlAIPP *aclmdlCreateAIPPImplOm2(uint64_t batchSize) {
99 aclmdlAIPP *aippParmsSet = nullptr;331 aclmdlAIPP *aippParmsSet = nullptr;
100 try {332 try {
@@ -459,39 +691,203 @@ aclError aclmdlSetAIPPPixelVarReciImplOm2(aclmdlAIPP *aippParmsSet, float dtcPix
459 return ACL_SUCCESS;691 return ACL_SUCCESS;
460}692}
461 693 
462-// These 4 functions involve model operations, keep as stubs for now694+aclError aclmdlGetAippTypeImplOm2(uint32_t modelId, size_t index, aclmdlInputAippType *type,
695+ size_t *dynamicAttachedDataIndex) {
696+ ACL_LOG_INFO("start to execute aclmdlGetAippType(OM2), modelId[%u], index[%zu]", modelId, index);
697+ ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(dynamicAttachedDataIndex);
698+ ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(type);
699+ auto executor = acl::AclResourceManagerOm2::GetInstance().GetOm2Executor(modelId);
700+ if (executor == nullptr) {
701+ ACL_LOG_INNER_ERROR("[Check][Executor]Om2 executor not found, modelId[%u]", modelId);
702+ return ACL_ERROR_INVALID_PARAM;
703+ }
704+ ACL_REQUIRES_OK(VerifyIndexOm2(executor, index));
705+ *dynamicAttachedDataIndex = ACL_INVALID_NODE_INDEX;
706+ ge::InputAippType aipp_type = ge::DATA_WITHOUT_AIPP;
707+ const auto ret = executor->GetAippType(static_cast<uint32_t>(index), aipp_type, *dynamicAttachedDataIndex);
708+ if (ret != ge::SUCCESS) {
709+ ACL_LOG_CALL_ERROR("[Get][AippType]GetAippType failed, modelId[%u], index[%zu], ret[%u]", modelId, index, ret);
710+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
711+ }
712+ *type = static_cast<aclmdlInputAippType>(aipp_type);
713+ ACL_LOG_INFO("successfully execute aclmdlGetAippType(OM2), modelId[%u], index[%zu], type[%d], dataIdx[%zu]", modelId,
714+ index, static_cast<int32_t>(*type), *dynamicAttachedDataIndex);
715+ return ACL_SUCCESS;
716+}
717+ 
718+aclError aclmdlGetFirstAippInfoImplOm2(uint32_t modelId, size_t index, aclAippInfo *aippInfo) {
719+ ACL_LOG_DEBUG("start to execute aclmdlGetFirstAippInfo(OM2), modelId[%u], index[%zu]", modelId, index);
720+ ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(aippInfo);
721+ auto executor = acl::AclResourceManagerOm2::GetInstance().GetOm2Executor(modelId);
722+ if (executor == nullptr) {
723+ ACL_LOG_INNER_ERROR("[Check][Executor]Om2 executor not found, modelId[%u]", modelId);
724+ return ACL_ERROR_INVALID_PARAM;
725+ }
726+ ACL_REQUIRES_OK(VerifyIndexOm2(executor, index));
727+ ge::AippConfigInfo aippParams;
728+ auto ret = executor->GetAippInfo(static_cast<uint32_t>(index), aippParams);
729+ if (ret == ACL_ERROR_GE_AIPP_NOT_EXIST) {
730+ ACL_LOG_INFO("the tensor index[%zu] is not configured with aipp, modelId[%u], ret[%u]", index, modelId, ret);
731+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
732+ }
733+ if (ret != ge::SUCCESS) {
734+ ACL_LOG_CALL_ERROR("[Get][AippInfo]GetAippInfo failed, modelId[%u], index[%zu], ret[%u]", modelId, index, ret);
735+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
736+ }
737+ acl::SetAippInfo(aippInfo, aippParams);
738+ 
739+ // Get batch info size for shapeCount, matching OM1 behavior
740+ size_t shapeCount = 0U;
741+ ret = executor->GetBatchInfoSize(shapeCount);
742+ if (ret != ge::SUCCESS) {
743+ ACL_LOG_CALL_ERROR("[Get][BatchInfo]GetBatchInfoSize failed, modelId[%u], index[%zu], ret[%u]", modelId, index,
744+ ret);
745+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
746+ }
747+ 
748+ ACL_LOG_DEBUG("get shapeCount[%zu]", shapeCount);
749+ aippInfo->shapeCount = shapeCount;
750+ 
751+ // Get origin input info, fail on error matching OM1
752+ ge::OriginInputInfo inputInfo;
753+ ret = executor->GetOrigInputInfo(static_cast<uint32_t>(index), inputInfo);
754+ if (ret != ge::SUCCESS) {
755+ ACL_LOG_CALL_ERROR("[Get][OrigInputInfo]GetOrigInputInfo failed, modelId[%u], index[%zu], ret[%u]", modelId, index,
756+ ret);
757+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
758+ }
759+ aippInfo->srcFormat = static_cast<aclFormat>(inputInfo.format);
760+ aippInfo->srcDatatype = static_cast<aclDataType>(inputInfo.data_type);
761+ aippInfo->srcDimNum = inputInfo.dim_num;
762+ ACL_LOG_DEBUG("aclAippInfo: %s .", acl::AippInfoDebugString(aippInfo).c_str());
763+ 
764+ // Get AllAippInputOutputDims, fail on error matching OM1
765+ std::vector<ge::InputOutputDims> input_dims;
766+ std::vector<ge::InputOutputDims> output_dims;
767+ ret = executor->GetAllAippInputOutputDims(static_cast<uint32_t>(index), input_dims, output_dims);
768+ if (ret != ge::SUCCESS) {
769+ ACL_LOG_CALL_ERROR(
770+ "[Get][AllAippInputOutputDims]GetAllAippInputOutputDims failed, modelId[%u], index[%zu], ret[%u]", modelId,
771+ index, ret);
772+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
773+ }
774+ ACL_LOG_DEBUG("GetAllAippInputOutputDims success");
775+ if ((shapeCount > static_cast<size_t>(ACL_MAX_SHAPE_COUNT)) || (shapeCount != input_dims.size()) ||
776+ (shapeCount != output_dims.size())) {
777+ ACL_LOG_INNER_ERROR(
778+ "[Check][Params]shapeCount[%zu] should be smaller than ACL_MAX_SHAPE_COUNT(128) and it "
779+ "should be equal to size of inputDims[%zu], size of outputDims[%zu]",
780+ shapeCount, input_dims.size(), output_dims.size());
781+ return ACL_ERROR_GE_FAILURE;
782+ }
783+ 
784+ // Copy dims using SetIODims including tensor names matching OM1
785+ for (size_t i = 0U; i < shapeCount; ++i) {
786+ aclError io_ret = acl::SetIODims(input_dims[i], aippInfo->outDims[i].srcDims);
787+ if (io_ret != ACL_SUCCESS) {
788+ ACL_LOG_INNER_ERROR("[Set][IODims]srcDims SetIODims failed, modelId[%u], index[%zu], ret[%d]", modelId, index,
789+ io_ret);
790+ return io_ret;
791+ }
792+ aippInfo->outDims[i].srcSize = input_dims[i].size;
793+ io_ret = acl::SetIODims(output_dims[i], aippInfo->outDims[i].aippOutdims);
794+ if (io_ret != ACL_SUCCESS) {
795+ ACL_LOG_INNER_ERROR("[Set][IODims]aippOutdims SetIODims failed, modelId[%u], index[%zu], ret[%d]", modelId, index,
796+ io_ret);
797+ return io_ret;
798+ }
799+ aippInfo->outDims[i].aippOutSize = output_dims[i].size;
800+ }
801+ ACL_LOG_DEBUG("successfully execute aclmdlGetFirstAippInfo(om2), aclAippDims: %s",
802+ acl::AippDimsDebugString(aippInfo->outDims, aippInfo->shapeCount).c_str());
803+ return ACL_SUCCESS;
804+}
805+ 
463aclError aclmdlSetInputAIPPImplOm2(uint32_t modelId, aclmdlDataset *dataset, size_t index,806aclError aclmdlSetInputAIPPImplOm2(uint32_t modelId, aclmdlDataset *dataset, size_t index,
464 const aclmdlAIPP *aippParmsSet) {807 const aclmdlAIPP *aippParmsSet) {
465- (void)modelId;808+ ACL_PROFILING_REG(acl::AclProfType::AclmdlSetInputAIPP);
466- (void)dataset;809+ ACL_LOG_DEBUG("start to execute aclmdlSetInputAIPP(OM2), modelId[%u], index[%zu]", modelId, index);
467- (void)index;810+ ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(dataset);
468- (void)aippParmsSet;811+ ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(aippParmsSet);
469- return ACL_ERROR_API_NOT_SUPPORT;812+ auto executor = acl::AclResourceManagerOm2::GetInstance().GetOm2Executor(modelId);
813+ if (executor == nullptr) {
814+ ACL_LOG_INNER_ERROR("[Check][Executor]Om2 executor not found, modelId[%u]", modelId);
815+ return ACL_ERROR_INVALID_PARAM;
816+ }
817+ // check dynamic aipp index
818+ ACL_REQUIRES_OK(VerifyIndexOm2(executor, index));
819+ 
820+ auto mdlRet = CheckAippDataIndexOm2(executor, modelId, index);
821+ if (mdlRet != ACL_SUCCESS) {
822+ ACL_LOG_ERROR("[Check][AippData]Dynamic AIPP data index %zu is invalid, parameters verification failed", index);
823+ const std::string errMsg = acl::AclErrorLogManager::FormatStr("index %zu is invalid", index);
824+ acl::AclErrorLogManager::ReportInputError(acl::INVALID_AIPP_MSG, std::vector<const char *>({"param", "reason"}),
825+ std::vector<const char *>({"Dynamic AIPP data index", errMsg.c_str()}));
826+ return mdlRet;
827+ }
828+ 
829+ mdlRet = GetAndCheckAippParamsOm2(executor, modelId, index, aippParmsSet);
830+ if (mdlRet != ACL_SUCCESS) {
831+ ACL_LOG_ERROR("[Check][AippParams]Dynamic AIPP parameters is invalid, parameters verification failed");
832+ acl::AclErrorLogManager::ReportInputError(
833+ acl::INVALID_AIPP_MSG, std::vector<const char *>({"param", "reason"}),
834+ std::vector<const char *>({"parameters", "parameters verification failed"}));
835+ return mdlRet;
836+ }
837+ 
838+ const aclDataBuffer *const buff = aclmdlGetDatasetBufferImplOm2(dataset, index);
839+ if (buff == nullptr) {
840+ ACL_LOG_INNER_ERROR("[Check][Buff]failed to get data buffer by index[%zu]", index);
841+ return ACL_ERROR_INVALID_PARAM;
842+ }
843+ void *const dev_ptr = aclGetDataBufferAddr(buff);
844+ if (dev_ptr == nullptr) {
845+ ACL_LOG_INNER_ERROR("[Check][DevPtr]failed to get addr by index[%zu]", index);
846+ return ACL_ERROR_INVALID_PARAM;
847+ }
848+ const uint64_t mem_size = aclGetDataBufferSizeV2(buff);
849+ ACL_LOG_DEBUG("aippParmsSet->aippParms: %s .", acl::AippParmsDebugString(aippParmsSet->aippParms).c_str());
850+ for (size_t i = 0U; i < aippParmsSet->aippBatchPara.size(); ++i) {
851+ ACL_LOG_DEBUG("batchIndex[%lu] aippParmsSet->aippBatchPara: %s .", i,
852+ acl::AippBatchParaDebugString(aippParmsSet->aippBatchPara[i]).c_str());
853+ }
854+ // send dynamic aipp to device
855+ ACL_LOG_INFO("call om2 executor.SetDynamicAippData, modelId[%u]", modelId);
856+ const auto ret =
857+ executor->SetDynamicAippData(dev_ptr, mem_size, aippParmsSet->aippBatchPara, aippParmsSet->aippParms);
858+ if (ret != ge::SUCCESS) {
859+ ACL_LOG_CALL_ERROR("[Set][DynamicAippData]SetDynamicAippData failed, ge result[%u]", ret);
860+ return ACL_GET_ERRCODE_GE(static_cast<int32_t>(ret));
861+ }
862+ ACL_LOG_INFO("successfully execute aclmdlSetInputAIPP(OM2), modelId[%u], index[%zu]", modelId, index);
863+ return ACL_SUCCESS;
470}864}
471 865 
472aclError aclmdlSetAIPPByInputIndexImplOm2(uint32_t modelId, aclmdlDataset *dataset, size_t index,866aclError aclmdlSetAIPPByInputIndexImplOm2(uint32_t modelId, aclmdlDataset *dataset, size_t index,
473 const aclmdlAIPP *aippParmsSet) {867 const aclmdlAIPP *aippParmsSet) {
474- (void)modelId;868+ ACL_LOG_INFO("start to execute aclmdlSetAIPPByInputIndex(OM2), modelId[%u], index[%zu]", modelId, index);
475- (void)dataset;869+ ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(aippParmsSet);
476- (void)index;870+ if ((dataset == nullptr) || (index >= dataset->blobs.size())) {
477- (void)aippParmsSet;871+ ACL_LOG_ERROR("[Check][Dataset]input param is invalid, dataset[%p], index[%zu]", static_cast<void *>(dataset),
478- return ACL_ERROR_API_NOT_SUPPORT;872+ index);
479-}873+ const std::string errMsg =
480- 874+ acl::AclErrorLogManager::FormatStr("dataset[%p], index[%zu]", static_cast<void *>(dataset), index);
481-aclError aclmdlGetAippTypeImplOm2(uint32_t modelId, size_t index, aclmdlInputAippType *type,875+ acl::AclErrorLogManager::ReportInputError(acl::INVALID_AIPP_MSG, std::vector<const char *>({"param", "reason"}),
482- size_t *dynamicAttachedDataIndex) {876+ std::vector<const char *>({"params", errMsg.c_str()}));
483- (void)modelId;877+ return ACL_ERROR_INVALID_PARAM;
484- (void)index;878+ }
485- (void)type;879+ aclmdlInputAippType aipp_type = ACL_DATA_WITHOUT_AIPP;
486- (void)dynamicAttachedDataIndex;880+ size_t dynamicAttachedDataIndex = 0U;
487- return ACL_ERROR_API_NOT_SUPPORT;881+ const auto ret = aclmdlGetAippTypeImplOm2(modelId, index, &aipp_type, &dynamicAttachedDataIndex);
488-}882+ if (ret != ACL_SUCCESS) {
489- 883+ return ret;
490-aclError aclmdlGetFirstAippInfoImplOm2(uint32_t modelId, size_t index, aclAippInfo *aippInfo) {884+ }
491- (void)modelId;885+ if (aipp_type != ACL_DATA_WITH_DYNAMIC_AIPP) {
492- (void)index;886+ ACL_LOG_INNER_ERROR("[Check][Type]input[%zu] has no dynamic aipp linked, modelId[%u]", index, modelId);
493- (void)aippInfo;887+ return ACL_ERROR_FAILURE;
494- return ACL_ERROR_API_NOT_SUPPORT;888+ }
889+ ACL_LOG_INFO("successfully execute aclmdlSetAIPPByInputIndex(OM2), modelId[%u], index[%zu]", modelId, index);
890+ return aclmdlSetInputAIPPImplOm2(modelId, dataset, dynamicAttachedDataIndex, aippParmsSet);
495}891}
496 892 
497aclError aclmdlSetAttributeImplOm2(uint32_t modelId, aclmdlAttr attr, aclmdlAttrValue_t *attrValue) {893aclError aclmdlSetAttributeImplOm2(uint32_t modelId, aclmdlAttr attr, aclmdlAttrValue_t *attrValue) {
@@ -212,8 +212,8 @@ static aclError AippCropSizeCheck(const aclmdlAIPP *const aippParmsSet, const si
212 return ACL_SUCCESS;212 return ACL_SUCCESS;
213}213}
214 214 
215-aclError GetAippOutputHW(const aclmdlAIPP *const aippParmsSet, const size_t batchIndex, const std::string &npuArch,215+ACL_FUNC_VISIBILITY aclError GetAippOutputHW(const aclmdlAIPP *const aippParmsSet, const size_t batchIndex,
216- int32_t &aippOutputW, int32_t &aippOutputH) {216+ const std::string &npuArch, int32_t &aippOutputW, int32_t &aippOutputH) {
217 if (aippParmsSet->aippBatchPara.empty()) {217 if (aippParmsSet->aippBatchPara.empty()) {
218 ACL_LOG_INNER_ERROR("[Check][Params]aippParmsSet->aippBatchPara is empty!");218 ACL_LOG_INNER_ERROR("[Check][Params]aippParmsSet->aippBatchPara is empty!");
219 return ACL_ERROR_INVALID_PARAM;219 return ACL_ERROR_INVALID_PARAM;
@@ -309,7 +309,7 @@ static aclError AippDynamicBatchParaCheck(const aclmdlAIPP *const aippParmsSet,
309 return ACL_SUCCESS;309 return ACL_SUCCESS;
310}310}
311 311 
312-aclError AippParamsCheck(const aclmdlAIPP *const aippParmsSet, const std::string &npuArch) {312+ACL_FUNC_VISIBILITY aclError AippParamsCheck(const aclmdlAIPP *const aippParmsSet, const std::string &npuArch) {
313 ACL_LOG_INFO("start to execute aclAippParamsCheck");313 ACL_LOG_INFO("start to execute aclAippParamsCheck");
314 ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(aippParmsSet);314 ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(aippParmsSet);
315 315 
@@ -346,7 +346,7 @@ aclError AippParamsCheck(const aclmdlAIPP *const aippParmsSet, const std::string
346 return ACL_SUCCESS;346 return ACL_SUCCESS;
347}347}
348 348 
349-uint64_t GetSrcImageSize(const aclmdlAIPP *const aippParmsSet) {349+ACL_FUNC_VISIBILITY uint64_t GetSrcImageSize(const aclmdlAIPP *const aippParmsSet) {
350 if (aippParmsSet == nullptr) {350 if (aippParmsSet == nullptr) {
351 return 0UL;351 return 0UL;
352 }352 }
@@ -13,11 +13,13 @@
13#include <cstdio>13#include <cstdio>
14#include <cstring>14#include <cstring>
15#include <queue>15#include <queue>
16+#include <sstream>
16#include <vector>17#include <vector>
17#include "common/log_inner.h"18#include "common/log_inner.h"
18#include "model_desc_internal.h"19#include "model_desc_internal.h"
19#include "framework/common/framework_types_internal.h"20#include "framework/common/framework_types_internal.h"
20#include "securec.h"21#include "securec.h"
22+#include "rt_external_base.h"
21 23 
22namespace {24namespace {
23constexpr size_t DYNAMIC_BATCH_SIZE = 1U;25constexpr size_t DYNAMIC_BATCH_SIZE = 1U;
@@ -487,4 +489,324 @@ ACL_FUNC_VISIBILITY aclError GetDims(const aclmdlDesc *const modelDesc, const Te
487 return ACL_SUCCESS;489 return ACL_SUCCESS;
488}490}
489 491 
492+ACL_FUNC_VISIBILITY void SetAippInfo(aclAippInfo *const aippInfo, const ge::AippConfigInfo &aippParams) {
493+ ACL_LOG_DEBUG("start to execute SetAippInfo");
494+ if (aippInfo == nullptr) {
495+ ACL_LOG_INNER_ERROR("[Check][AippInfo]param aippInfo must not be null");
496+ return;
497+ }
498+ aippInfo->inputFormat = static_cast<aclAippInputFormat>(aippParams.input_format);
499+ aippInfo->srcImageSizeW = aippParams.src_image_size_w;
500+ aippInfo->srcImageSizeH = aippParams.src_image_size_h;
501+ 
502+ aippInfo->cropSwitch = aippParams.crop;
503+ aippInfo->loadStartPosW = aippParams.load_start_pos_w;
504+ aippInfo->loadStartPosH = aippParams.load_start_pos_h;
505+ aippInfo->cropSizeW = aippParams.crop_size_w;
506+ aippInfo->cropSizeH = aippParams.crop_size_h;
507+ 
508+ aippInfo->resizeSwitch = aippParams.resize;
509+ aippInfo->resizeOutputW = aippParams.resize_output_w;
510+ aippInfo->resizeOutputH = aippParams.resize_output_h;
511+ 
512+ aippInfo->paddingSwitch = aippParams.padding;
513+ aippInfo->leftPaddingSize = aippParams.left_padding_size;
514+ aippInfo->rightPaddingSize = aippParams.right_padding_size;
515+ aippInfo->topPaddingSize = aippParams.top_padding_size;
516+ aippInfo->bottomPaddingSize = aippParams.bottom_padding_size;
517+ 
518+ aippInfo->cscSwitch = aippParams.csc_switch;
519+ aippInfo->rbuvSwapSwitch = aippParams.rbuv_swap_switch;
520+ aippInfo->axSwapSwitch = aippParams.ax_swap_switch;
521+ aippInfo->singleLineMode = aippParams.single_line_mode;
522+ 
523+ aippInfo->matrixR0C0 = aippParams.matrix_r0c0;
524+ aippInfo->matrixR0C1 = aippParams.matrix_r0c1;
525+ aippInfo->matrixR0C2 = aippParams.matrix_r0c2;
526+ aippInfo->matrixR1C0 = aippParams.matrix_r1c0;
527+ aippInfo->matrixR1C1 = aippParams.matrix_r1c1;
528+ aippInfo->matrixR1C2 = aippParams.matrix_r1c2;
529+ aippInfo->matrixR2C0 = aippParams.matrix_r2c0;
530+ aippInfo->matrixR2C1 = aippParams.matrix_r2c1;
531+ aippInfo->matrixR2C2 = aippParams.matrix_r2c2;
532+ 
533+ aippInfo->outputBias0 = aippParams.output_bias_0;
534+ aippInfo->outputBias1 = aippParams.output_bias_1;
535+ aippInfo->outputBias2 = aippParams.output_bias_2;
536+ aippInfo->inputBias0 = aippParams.input_bias_0;
537+ aippInfo->inputBias1 = aippParams.input_bias_1;
538+ aippInfo->inputBias2 = aippParams.input_bias_2;
539+ 
540+ aippInfo->meanChn0 = aippParams.mean_chn_0;
541+ aippInfo->meanChn1 = aippParams.mean_chn_1;
542+ aippInfo->meanChn2 = aippParams.mean_chn_2;
543+ aippInfo->meanChn3 = aippParams.mean_chn_3;
544+ aippInfo->minChn0 = aippParams.min_chn_0;
545+ aippInfo->minChn1 = aippParams.min_chn_1;
546+ aippInfo->minChn2 = aippParams.min_chn_2;
547+ aippInfo->minChn3 = aippParams.min_chn_3;
548+ 
549+ aippInfo->varReciChn0 = aippParams.var_reci_chn_0;
550+ aippInfo->varReciChn1 = aippParams.var_reci_chn_1;
551+ aippInfo->varReciChn2 = aippParams.var_reci_chn_2;
552+ aippInfo->varReciChn3 = aippParams.var_reci_chn_3;
553+ ACL_LOG_DEBUG("end to execute SetAippInfo");
554+}
555+ 
556+ACL_FUNC_VISIBILITY std::string GetNpuArch() {
557+ char npu_arch[MAX_NPU_ARCH_LEN] = {0};
558+ const auto ret = rtGetSocSpec("version", "NpuArch", npu_arch, sizeof(npu_arch));
559+ if (ret != RT_ERROR_NONE) {
560+ return "";
561+ }
562+ return std::string(npu_arch);
563+}
564+ 
565+ACL_FUNC_VISIBILITY aclError SetIODims(const ge::InputOutputDims &oriDims, aclmdlIODims &dstDims) {
566+ ACL_LOG_DEBUG("start to execute SetIODims");
567+ dstDims.dimCount = oriDims.dim_num;
568+ if (oriDims.dims.size() > static_cast<size_t>(ACL_MAX_DIM_CNT)) {
569+ ACL_LOG_INNER_ERROR("[Check][Params]size of dims[%zu] must be smaller than ACL_MAX_DIM_CNT(128)",
570+ oriDims.dims.size());
571+ return ACL_ERROR_GE_FAILURE;
572+ }
573+ for (size_t i = 0U; i < oriDims.dims.size(); ++i) {
574+ dstDims.dims[i] = oriDims.dims[i];
575+ }
576+ if (oriDims.name.empty()) {
577+ ACL_LOG_DEBUG("the name of oriDims is empty");
578+ return ACL_SUCCESS;
579+ }
580+ const auto ret = strncpy_s(dstDims.name, sizeof(dstDims.name), oriDims.name.c_str(), oriDims.name.size());
581+ if (ret != EOK) {
582+ ACL_LOG_INNER_ERROR("[Copy][Str]call strncpy_s failed");
583+ return ACL_ERROR_FAILURE;
584+ }
585+ return ACL_SUCCESS;
586+}
587+ 
588+ACL_FUNC_VISIBILITY std::string AippInfoDebugString(const aclAippInfo *const aippInfo) {
589+ if (aippInfo == nullptr) {
590+ ACL_LOG_INNER_ERROR("[Check][aippInfo]param aippInfo must not be null");
591+ return "";
592+ }
593+ std::stringstream ss;
594+ ss << "aclAippInfo[";
595+ ss << " inputFormat:" << static_cast<int32_t>(aippInfo->inputFormat);
596+ ss << " srcImageSizeW:" << aippInfo->srcImageSizeW;
597+ ss << " srcImageSizeH:" << aippInfo->srcImageSizeH;
598+ 
599+ ss << " cropSwitch:" << static_cast<int32_t>(aippInfo->cropSwitch);
600+ ss << " loadStartPosW:" << aippInfo->loadStartPosW;
601+ ss << " loadStartPosH:" << aippInfo->loadStartPosH;
602+ ss << " cropSizeW:" << aippInfo->cropSizeW;
603+ ss << " cropSizeH:" << aippInfo->cropSizeH;
604+ 
605+ ss << " resizeSwitch:" << static_cast<int32_t>(aippInfo->resizeSwitch);
606+ ss << " resizeOutputW:" << aippInfo->resizeOutputW;
607+ ss << " resizeOutputH:" << aippInfo->resizeOutputH;
608+ 
609+ ss << " paddingSwitch:" << static_cast<int32_t>(aippInfo->paddingSwitch);
610+ ss << " leftPaddingSize:" << aippInfo->leftPaddingSize;
611+ ss << " rightPaddingSize:" << aippInfo->rightPaddingSize;
612+ ss << " topPaddingSize:" << aippInfo->topPaddingSize;
613+ ss << " bottomPaddingSize:" << aippInfo->bottomPaddingSize;
614+ 
615+ ss << " cscSwitch:" << static_cast<int32_t>(aippInfo->cscSwitch);
616+ ss << " rbuvSwapSwitch:" << static_cast<int32_t>(aippInfo->rbuvSwapSwitch);
617+ ss << " axSwapSwitch:" << static_cast<int32_t>(aippInfo->axSwapSwitch);
618+ ss << " singleLineMode:" << static_cast<int32_t>(aippInfo->singleLineMode);
619+ 
620+ ss << " matrixR0C0:" << aippInfo->matrixR0C0;
621+ ss << " matrixR0C1:" << aippInfo->matrixR0C1;
622+ ss << " matrixR0C2:" << aippInfo->matrixR0C2;
623+ ss << " matrixR1C0:" << aippInfo->matrixR1C0;
624+ ss << " matrixR1C1:" << aippInfo->matrixR1C1;
625+ ss << " matrixR1C2:" << aippInfo->matrixR1C2;
626+ ss << " matrixR2C0:" << aippInfo->matrixR2C0;
627+ ss << " matrixR2C1:" << aippInfo->matrixR2C1;
628+ ss << " matrixR2C2:" << aippInfo->matrixR2C2;
629+ 
630+ ss << " outputBias0:" << aippInfo->outputBias0;
631+ ss << " outputBias1:" << aippInfo->outputBias1;
632+ ss << " outputBias2:" << aippInfo->outputBias2;
633+ ss << " inputBias0:" << aippInfo->inputBias0;
634+ ss << " inputBias1:" << aippInfo->inputBias1;
635+ ss << " inputBias2:" << aippInfo->inputBias2;
636+ 
637+ ss << " meanChn0:" << aippInfo->meanChn0;
638+ ss << " meanChn1:" << aippInfo->meanChn1;
639+ ss << " meanChn2:" << aippInfo->meanChn2;
640+ ss << " meanChn3:" << aippInfo->meanChn3;
641+ ss << " minChn0:" << aippInfo->minChn0;
642+ ss << " minChn1:" << aippInfo->minChn1;
643+ ss << " minChn2:" << aippInfo->minChn2;
644+ ss << " minChn3:" << aippInfo->minChn3;
645+ ss << " varReciChn0:" << aippInfo->varReciChn0;
646+ ss << " varReciChn1:" << aippInfo->varReciChn1;
647+ ss << " varReciChn2:" << aippInfo->varReciChn2;
648+ ss << " varReciChn3:" << aippInfo->varReciChn3;
649+ 
650+ ss << " shapeCount:" << aippInfo->shapeCount;
651+ ss << " srcFormat:" << aippInfo->srcFormat;
652+ ss << " srcDatatype:" << aippInfo->srcDatatype;
653+ ss << " srcDimNum:" << aippInfo->srcDimNum;
654+ ss << " ]";
655+ return ss.str();
656+}
657+ 
658+ACL_FUNC_VISIBILITY std::string DimsDebugString(const aclmdlIODims &ioDims) {
659+ std::stringstream ss;
660+ ss << "[" << " tensorName:" << ioDims.name;
661+ ss << " dimcount:" << static_cast<int32_t>(ioDims.dimCount);
662+ ss << " dims:";
663+ for (size_t i = 0U; i < ioDims.dimCount; ++i) {
664+ ss << " " << ioDims.dims[i];
665+ }
666+ ss << "]; ";
667+ return ss.str();
668+}
669+ 
670+ACL_FUNC_VISIBILITY std::string AippDimsDebugString(const aclAippDims *const aippDims, const size_t shapeCount) {
671+ if (aippDims == nullptr) {
672+ ACL_LOG_INNER_ERROR("[Check][aippDims]param aippDims must not be null");
673+ return "";
674+ }
675+ std::stringstream ssDims;
676+ for (size_t i = 0U; i < shapeCount; ++i) {
677+ ssDims << " aclAippDims[" << i << "]: ";
678+ ssDims << DimsDebugString(aippDims[i].srcDims);
679+ ssDims << " srcSize:" << aippDims[i].srcSize;
680+ ssDims << DimsDebugString(aippDims[i].aippOutdims);
681+ ssDims << " aippOutSize:" << aippDims[i].aippOutSize;
682+ }
683+ return ssDims.str();
684+}
685+ 
686+// FP16 debug helpers, internal use only
687+union TypeUnion {
688+ float32_t fVal;
689+ uint32_t uVal;
690+};
691+ 
692+#define FP16_EXTRAC_SIGN(x) (((x) >> 15U) & 1U)
693+#define FP16_EXTRAC_EXP(x) (((x) >> 10U) & acl::FP16_MAX_EXP)
694+#define FP16_EXTRAC_MAN(x) ((((x) >> 0U) & 0x3FFU) | ((((((x) >> 10U) & 0x1FU) > 0U) ? 1U : 0U) * 0x400U))
695+#define FP32_CONSTRUCTOR(s, e, m) \
696+ (((s) << acl::FP32_SIGN_INDEX) | ((e) << acl::FP32_MAN_LEN) | ((m) & acl::FP32_MAX_MAN))
697+ 
698+static void ExtractFP16(const uint16_t val, uint16_t *const s, int16_t *const e, uint16_t *const m) {
699+ *s = FP16_EXTRAC_SIGN(val);
700+ *e = static_cast<int16_t>(FP16_EXTRAC_EXP(val));
701+ *m = FP16_EXTRAC_MAN(val);
702+ if ((*e) == 0) {
703+ *e = 1;
704+ }
705+}
706+ 
707+static float32_t Fp16ToFloat(const uint16_t val) {
708+ uint16_t hf_sign;
709+ uint16_t hf_man;
710+ int16_t hf_exp;
711+ ExtractFP16(val, &hf_sign, &hf_exp, &hf_man);
712+ 
713+ while ((hf_man != 0U) && ((hf_man & acl::FP16_MAN_HIDE_BIT) == 0U)) {
714+ hf_man <<= 1U;
715+ hf_exp--;
716+ }
717+ 
718+ uint32_t exp_ret;
719+ uint32_t man_ret;
720+ if (hf_man == 0U) {
721+ exp_ret = 0U;
722+ man_ret = 0U;
723+ } else {
724+ exp_ret = static_cast<uint32_t>(hf_exp + static_cast<int16_t>(acl::FP32_EXP_BIAS - acl::FP16_EXP_BIAS));
725+ man_ret = static_cast<uint32_t>(hf_man & acl::FP16_MAN_MASK);
726+ man_ret = man_ret << (acl::FP32_MAN_LEN - acl::FP16_MAN_LEN);
727+ }
728+ 
729+ const uint32_t sign_ret = hf_sign;
730+ TypeUnion type_union;
731+ type_union.uVal = FP32_CONSTRUCTOR(sign_ret, exp_ret, man_ret);
732+ return type_union.fVal;
733+}
734+ 
735+ACL_FUNC_VISIBILITY std::string AippParmsDebugString(const kAippDynamicPara &aipp_parms) {
736+ std::stringstream ss;
737+ ss << "kAippDynamicPara[";
738+ ss << " inputFormat:" << static_cast<uint32_t>(aipp_parms.inputFormat);
739+ ss << " cscSwitch:" << static_cast<int32_t>(aipp_parms.cscSwitch);
740+ ss << " rbuvSwapSwitch:" << static_cast<int32_t>(aipp_parms.rbuvSwapSwitch);
741+ ss << " axSwapSwitch:" << static_cast<int32_t>(aipp_parms.axSwapSwitch);
742+ ss << " batchNum:" << static_cast<int32_t>(aipp_parms.batchNum);
743+ ss << " srcImageSizeW:" << aipp_parms.srcImageSizeW;
744+ ss << " srcImageSizeH:" << aipp_parms.srcImageSizeH;
745+ ss << " cscMatrixR0C0:" << static_cast<int32_t>(aipp_parms.cscMatrixR0C0);
746+ ss << " cscMatrixR0C1:" << static_cast<int32_t>(aipp_parms.cscMatrixR0C1);
747+ ss << " cscMatrixR0C2:" << static_cast<int32_t>(aipp_parms.cscMatrixR0C2);
748+ ss << " cscMatrixR1C0:" << static_cast<int32_t>(aipp_parms.cscMatrixR1C0);
749+ ss << " cscMatrixR1C1:" << static_cast<int32_t>(aipp_parms.cscMatrixR1C1);
750+ ss << " cscMatrixR1C2:" << static_cast<int32_t>(aipp_parms.cscMatrixR1C2);
751+ ss << " cscMatrixR2C0:" << static_cast<int32_t>(aipp_parms.cscMatrixR2C0);
752+ ss << " cscMatrixR2C1:" << static_cast<int32_t>(aipp_parms.cscMatrixR2C1);
753+ ss << " cscMatrixR2C2:" << static_cast<int32_t>(aipp_parms.cscMatrixR2C2);
754+ ss << " cscOutputBiasR0:" << static_cast<uint32_t>(aipp_parms.cscOutputBiasR0);
755+ ss << " cscOutputBiasR1:" << static_cast<uint32_t>(aipp_parms.cscOutputBiasR1);
756+ ss << " cscOutputBiasR2:" << static_cast<uint32_t>(aipp_parms.cscOutputBiasR2);
757+ ss << " cscInputBiasR0:" << static_cast<uint32_t>(aipp_parms.cscInputBiasR0);
758+ ss << " cscInputBiasR1:" << static_cast<uint32_t>(aipp_parms.cscInputBiasR1);
759+ ss << " cscInputBiasR2:" << static_cast<uint32_t>(aipp_parms.cscInputBiasR2);
760+ ss << " ]";
761+ return ss.str();
762+}
763+ 
764+ACL_FUNC_VISIBILITY std::string AippBatchParaDebugString(const kAippDynamicBatchPara &aipp_batch_para) {
765+ std::stringstream ss;
766+ ss << "kAippDynamicBatchPara[";
767+ ss << " cropSwitch:" << static_cast<int32_t>(aipp_batch_para.cropSwitch);
768+ ss << " cropStartPosW:" << aipp_batch_para.cropStartPosW;
769+ ss << " cropStartPosH:" << aipp_batch_para.cropStartPosH;
770+ ss << " cropSizeW:" << aipp_batch_para.cropSizeW;
771+ ss << " cropSizeH:" << aipp_batch_para.cropSizeH;
772+ ss << " scfSwitch:" << static_cast<int32_t>(aipp_batch_para.scfSwitch);
773+ ss << " scfInputSizeW:" << aipp_batch_para.scfInputSizeW;
774+ ss << " scfInputSizeH:" << aipp_batch_para.scfInputSizeH;
775+ ss << " scfOutputSizeW:" << aipp_batch_para.scfOutputSizeW;
776+ ss << " scfOutputSizeH:" << aipp_batch_para.scfOutputSizeH;
777+ ss << " paddingSwitch:" << static_cast<int32_t>(aipp_batch_para.paddingSwitch);
778+ ss << " paddingSizeTop:" << aipp_batch_para.paddingSizeTop;
779+ ss << " paddingSizeBottom:" << aipp_batch_para.paddingSizeBottom;
780+ ss << " paddingSizeLeft:" << aipp_batch_para.paddingSizeLeft;
781+ ss << " paddingSizeRight:" << aipp_batch_para.paddingSizeRight;
782+ ss << " rotateSwitch:" << static_cast<int32_t>(aipp_batch_para.rotateSwitch);
783+ ss << " dtcPixelMeanChn0:" << static_cast<int32_t>(aipp_batch_para.dtcPixelMeanChn0);
784+ ss << " dtcPixelMeanChn1:" << static_cast<int32_t>(aipp_batch_para.dtcPixelMeanChn1);
785+ ss << " dtcPixelMeanChn2:" << static_cast<int32_t>(aipp_batch_para.dtcPixelMeanChn2);
786+ ss << " dtcPixelMeanChn3:" << static_cast<int32_t>(aipp_batch_para.dtcPixelMeanChn3);
787+ ss << " dtcPixelMinChn0:" << static_cast<uint32_t>(aipp_batch_para.dtcPixelMinChn0);
788+ ss << " dtcPixelMinChn1:" << static_cast<uint32_t>(aipp_batch_para.dtcPixelMinChn1);
789+ ss << " dtcPixelMinChn2:" << static_cast<uint32_t>(aipp_batch_para.dtcPixelMinChn2);
790+ ss << " dtcPixelMinChn3:" << static_cast<uint32_t>(aipp_batch_para.dtcPixelMinChn3);
791+ ss << " dtcPixelVarReciChn0:" << Fp16ToFloat(aipp_batch_para.dtcPixelVarReciChn0);
792+ ss << " dtcPixelVarReciChn1:" << Fp16ToFloat(aipp_batch_para.dtcPixelVarReciChn1);
793+ ss << " dtcPixelVarReciChn2:" << Fp16ToFloat(aipp_batch_para.dtcPixelVarReciChn2);
794+ ss << " dtcPixelVarReciChn3:" << Fp16ToFloat(aipp_batch_para.dtcPixelVarReciChn3);
795+ ss << " ]";
796+ return ss.str();
797+}
798+ 
799+ACL_FUNC_VISIBILITY size_t GetMaxShapeIndex(const std::vector<ge::InputOutputDims> &inputDims) {
800+ size_t maxShapeIndex = 0U;
801+ uint32_t shapeSize = 0U;
802+ for (size_t i = 0U; i < inputDims.size(); ++i) {
803+ if (inputDims[i].size > shapeSize) {
804+ shapeSize = inputDims[i].size;
805+ maxShapeIndex = i;
806+ }
807+ }
808+ ACL_LOG_INFO("GetMaxShapeIndex success, maxShapeIndex[%zu]", maxShapeIndex);
809+ return maxShapeIndex;
810+}
811+ 
490} // namespace acl812} // namespace acl
@@ -17,6 +17,8 @@
17#include <set>17#include <set>
18#include "acl/acl_base.h"18#include "acl/acl_base.h"
19#include "acl/acl_mdl.h"19#include "acl/acl_mdl.h"
20+#include "common/ge_common/ge_types.h"
21+#include "common/dynamic_aipp.h"
20#include "framework/runtime/rt_session.h"22#include "framework/runtime/rt_session.h"
21 23 
22// Common enums for tensor/dims operations24// Common enums for tensor/dims operations
@@ -111,6 +113,7 @@ constexpr float32_t MIN_CHN_MIN = 0.0F;
111constexpr float32_t MIN_CHN_MAX = 255.0F;113constexpr float32_t MIN_CHN_MAX = 255.0F;
112constexpr float32_t VR_CHN_MIN = -65504.0F;114constexpr float32_t VR_CHN_MIN = -65504.0F;
113constexpr float32_t VR_CHN_MAX = 65504.0F;115constexpr float32_t VR_CHN_MAX = 65504.0F;
116+constexpr uint32_t MAX_NPU_ARCH_LEN = 32U;
114 117 
115inline bool IsRoundOne(const uint64_t man, const uint16_t truncLen) {118inline bool IsRoundOne(const uint64_t man, const uint16_t truncLen) {
116 const uint16_t shiftOut = truncLen - 2U;119 const uint16_t shiftOut = truncLen - 2U;
@@ -137,6 +140,17 @@ inline void Fp16Normalize(int16_t &expo, uint16_t &man) {
137 man = 0U;140 man = 0U;
138 }141 }
139}142}
143+ 
144+void SetAippInfo(aclAippInfo *const aippInfo, const ge::AippConfigInfo &aippParams);
145+ 
146+std::string GetNpuArch();
147+std::string AippInfoDebugString(const aclAippInfo *aippInfo);
148+aclError SetIODims(const ge::InputOutputDims &oriDims, aclmdlIODims &dstDims);
149+std::string DimsDebugString(const aclmdlIODims &ioDims);
150+std::string AippDimsDebugString(const aclAippDims *aippDims, size_t shapeCount);
151+std::string AippParmsDebugString(const kAippDynamicPara &aippParms);
152+std::string AippBatchParaDebugString(const kAippDynamicBatchPara &aippBatchPara);
153+size_t GetMaxShapeIndex(const std::vector<ge::InputOutputDims> &inputDims);
140} // namespace acl154} // namespace acl
141 155 
142#endif // ACL_MODEL_SRC_MODEL_MODEL_COMMON_H_156#endif // ACL_MODEL_SRC_MODEL_MODEL_COMMON_H_
@@ -995,10 +995,6 @@ class GFlagUtils {
995 GE_ASSERT_SUCCESS(CheckOm2UserOptionsValid(ge::flgs::GetUserOptions()), "[Check][OM2][UserOptions] failed!");995 GE_ASSERT_SUCCESS(CheckOm2UserOptionsValid(ge::flgs::GetUserOptions()), "[Check][OM2][UserOptions] failed!");
996 GE_ASSERT_SUCCESS(ge::CheckOm2HostEnvValid(FLAGS_host_env_os, FLAGS_host_env_cpu),996 GE_ASSERT_SUCCESS(ge::CheckOm2HostEnvValid(FLAGS_host_env_os, FLAGS_host_env_cpu),
997 "[Check][OM2][HostEnv] failed!");997 "[Check][OM2][HostEnv] failed!");
998- if (!FLAGS_insert_op_conf.empty()) {
999- GE_ASSERT_SUCCESS(ge::InsertAippOpUtil::ValidateStaticAippOnly(FLAGS_insert_op_conf),
1000- "[Check][OM2][InsertOpConf] Dynamic AIPP is not supported in OM2 mode.");
1001- }
1002 } else {998 } else {
1003 GE_ASSERT_SUCCESS(ge::CheckHostEnvOsAndHostEnvCpuStringValid(FLAGS_host_env_os, FLAGS_host_env_cpu),999 GE_ASSERT_SUCCESS(ge::CheckHostEnvOsAndHostEnvCpuStringValid(FLAGS_host_env_os, FLAGS_host_env_cpu),
1004 "[Check][HostEnvOsCpu] failed!");1000 "[Check][HostEnvOsCpu] failed!");
@@ -86,6 +86,19 @@ class JsonFile {
86 }86 }
87 }87 }
88 88 
89+ bool Get(const std::string &key, JsonFile &out) const {
90+ if (!valid_ || !data_.contains(key)) {
91+ return false;
92+ }
93+ try {
94+ out = JsonFile(data_.at(key));
95+ return true;
96+ } catch (const std::exception &e) {
97+ GELOGW("Cannot get value with key [%s], msg: %s", key.c_str(), e.what());
98+ return false;
99+ }
100+ }
101+ 
89 std::string Dump(const bool pretty = true) const {102 std::string Dump(const bool pretty = true) const {
90 if (!valid_) {103 if (!valid_) {
91 return "{}";104 return "{}";
@@ -93,6 +106,10 @@ class JsonFile {
93 return pretty ? data_.dump(kJsonPrettyIndent) : data_.dump();106 return pretty ? data_.dump(kJsonPrettyIndent) : data_.dump();
94 }107 }
95 108 
109+ const json &operator[](const std::string &key) const {
110+ return data_[key];
111+ }
112+ 
96 const json &Raw() const {113 const json &Raw() const {
97 return data_;114 return data_;
98 }115 }
@@ -117,6 +117,103 @@ Status SerializeKernelBinaries(const gert::Om2ModelData &model_data,
117 return SUCCESS;117 return SUCCESS;
118}118}
119 119 
120+JsonFile SerializeAippDimsToJson(const std::vector<ge::InputOutputDims> &dims_list, const std::string &fmt_str,
121+ const std::string &dt_str) {
122+ JsonFile::json arr = JsonFile::json::array();
123+ for (const auto &dims : dims_list) {
124+ std::string dim_csv;
125+ for (size_t d = 0U; d < dims.dims.size(); ++d) {
126+ if (d > 0U) {
127+ dim_csv += ",";
128+ }
129+ dim_csv += std::to_string(dims.dims[d]);
130+ }
131+ arr.push_back(fmt_str + ":" + dt_str + ":" + dims.name + ":" + std::to_string(dims.size) + ":" +
132+ std::to_string(dims.dim_num) + ":" + dim_csv);
133+ }
134+ return JsonFile(arr);
135+}
136+ 
137+void SerializeAippMeta(const gert::Om2ModelMeta &model_meta, JsonFile &model_meta_info) {
138+ if (model_meta.aipp_infos.empty()) {
139+ return;
140+ }
141+ GELOGI("[OM2] Serializing %zu AIPP entries to model_meta.json", model_meta.aipp_infos.size());
142+ JsonFile::json aipp_infos_arr = JsonFile::json::array();
143+ for (size_t i = 0U; i < model_meta.aipp_infos.size(); ++i) {
144+ const auto &meta = model_meta.aipp_infos[i];
145+ if (meta.aipp_type == ge::DATA_WITHOUT_AIPP) {
146+ continue;
147+ }
148+ const std::string fmt_str = ge::TypeUtils::FormatToSerialString(meta.orig_input_info.format);
149+ const std::string dt_str = ge::TypeUtils::DataTypeToSerialString(meta.orig_input_info.data_type);
150+ JsonFile entry;
151+ entry.Set("index", i)
152+ .Set("aipp_type", static_cast<int32_t>(meta.aipp_type))
153+ .Set("aipp_data_index", meta.aipp_data_index)
154+ .Set("aipp_mode", static_cast<int32_t>(meta.aipp_config_info.aipp_mode))
155+ .Set("input_format", static_cast<int32_t>(meta.aipp_config_info.input_format))
156+ .Set("src_image_size_w", meta.aipp_config_info.src_image_size_w)
157+ .Set("src_image_size_h", meta.aipp_config_info.src_image_size_h)
158+ .Set("crop", static_cast<int32_t>(meta.aipp_config_info.crop))
159+ .Set("load_start_pos_w", meta.aipp_config_info.load_start_pos_w)
160+ .Set("load_start_pos_h", meta.aipp_config_info.load_start_pos_h)
161+ .Set("crop_size_w", meta.aipp_config_info.crop_size_w)
162+ .Set("crop_size_h", meta.aipp_config_info.crop_size_h)
163+ .Set("resize", static_cast<int32_t>(meta.aipp_config_info.resize))
164+ .Set("resize_output_w", meta.aipp_config_info.resize_output_w)
165+ .Set("resize_output_h", meta.aipp_config_info.resize_output_h)
166+ .Set("padding", static_cast<int32_t>(meta.aipp_config_info.padding))
167+ .Set("left_padding_size", meta.aipp_config_info.left_padding_size)
168+ .Set("right_padding_size", meta.aipp_config_info.right_padding_size)
169+ .Set("top_padding_size", meta.aipp_config_info.top_padding_size)
170+ .Set("bottom_padding_size", meta.aipp_config_info.bottom_padding_size)
171+ .Set("csc_switch", static_cast<int32_t>(meta.aipp_config_info.csc_switch))
172+ .Set("rbuv_swap_switch", static_cast<int32_t>(meta.aipp_config_info.rbuv_swap_switch))
173+ .Set("ax_swap_switch", static_cast<int32_t>(meta.aipp_config_info.ax_swap_switch))
174+ .Set("single_line_mode", static_cast<int32_t>(meta.aipp_config_info.single_line_mode))
175+ .Set("matrix_r0c0", meta.aipp_config_info.matrix_r0c0)
176+ .Set("matrix_r0c1", meta.aipp_config_info.matrix_r0c1)
177+ .Set("matrix_r0c2", meta.aipp_config_info.matrix_r0c2)
178+ .Set("matrix_r1c0", meta.aipp_config_info.matrix_r1c0)
179+ .Set("matrix_r1c1", meta.aipp_config_info.matrix_r1c1)
180+ .Set("matrix_r1c2", meta.aipp_config_info.matrix_r1c2)
181+ .Set("matrix_r2c0", meta.aipp_config_info.matrix_r2c0)
182+ .Set("matrix_r2c1", meta.aipp_config_info.matrix_r2c1)
183+ .Set("matrix_r2c2", meta.aipp_config_info.matrix_r2c2)
184+ .Set("output_bias_0", meta.aipp_config_info.output_bias_0)
185+ .Set("output_bias_1", meta.aipp_config_info.output_bias_1)
186+ .Set("output_bias_2", meta.aipp_config_info.output_bias_2)
187+ .Set("input_bias_0", meta.aipp_config_info.input_bias_0)
188+ .Set("input_bias_1", meta.aipp_config_info.input_bias_1)
189+ .Set("input_bias_2", meta.aipp_config_info.input_bias_2)
190+ .Set("mean_chn_0", meta.aipp_config_info.mean_chn_0)
191+ .Set("mean_chn_1", meta.aipp_config_info.mean_chn_1)
192+ .Set("mean_chn_2", meta.aipp_config_info.mean_chn_2)
193+ .Set("mean_chn_3", meta.aipp_config_info.mean_chn_3)
194+ .Set("min_chn_0", meta.aipp_config_info.min_chn_0)
195+ .Set("min_chn_1", meta.aipp_config_info.min_chn_1)
196+ .Set("min_chn_2", meta.aipp_config_info.min_chn_2)
197+ .Set("min_chn_3", meta.aipp_config_info.min_chn_3)
198+ .Set("var_reci_chn_0", meta.aipp_config_info.var_reci_chn_0)
199+ .Set("var_reci_chn_1", meta.aipp_config_info.var_reci_chn_1)
200+ .Set("var_reci_chn_2", meta.aipp_config_info.var_reci_chn_2)
201+ .Set("var_reci_chn_3", meta.aipp_config_info.var_reci_chn_3)
202+ .Set("support_rotation", static_cast<int32_t>(meta.aipp_config_info.support_rotation))
203+ .Set("related_input_rank", meta.aipp_config_info.related_input_rank)
204+ .Set("max_src_image_size", meta.aipp_config_info.max_src_image_size)
205+ .Set("aipp_inputs", SerializeAippDimsToJson(meta.aipp_input_dims, fmt_str, dt_str))
206+ .Set("aipp_outputs", SerializeAippDimsToJson(meta.aipp_output_dims, fmt_str, dt_str))
207+ .Set("orig_input_format", static_cast<int32_t>(meta.orig_input_info.format))
208+ .Set("orig_input_data_type", static_cast<int32_t>(meta.orig_input_info.data_type))
209+ .Set("orig_input_dim_num", meta.orig_input_info.dim_num);
210+ aipp_infos_arr.push_back(entry.Raw());
211+ }
212+ JsonFile aipp_json;
213+ (void)aipp_json.Set("aipp_infos", aipp_infos_arr);
214+ (void)model_meta_info.Set("aipp", aipp_json);
215+}
216+ 
120Status SerializeModelMeta(const gert::Om2ModelData &model_data, const std::shared_ptr<ZipArchiveWriter> &zip_writer) {217Status SerializeModelMeta(const gert::Om2ModelData &model_data, const std::shared_ptr<ZipArchiveWriter> &zip_writer) {
121 const size_t model_index = 0UL;218 const size_t model_index = 0UL;
122 JsonFile model_meta_info;219 JsonFile model_meta_info;
@@ -166,6 +263,9 @@ Status SerializeModelMeta(const gert::Om2ModelData &model_data, const std::share
166 (void)model_meta_info.Set("name", model_data.model_meta.model_name);263 (void)model_meta_info.Set("name", model_data.model_meta.model_name);
167 (void)model_meta_info.Set("root_graph_name", model_data.model_meta.root_graph_name);264 (void)model_meta_info.Set("root_graph_name", model_data.model_meta.root_graph_name);
168 265 
266+ // 序列化 AIPP 元数据
267+ SerializeAippMeta(model_data.model_meta, model_meta_info);
268+ 
169 const auto model_meta_info_str = model_meta_info.Dump();269 const auto model_meta_info_str = model_meta_info.Dump();
170 const auto model_meta_entry_path = FormatOm2Path(OM2_MODEL_META_PATH_FORMAT, std::to_string(model_index).c_str());270 const auto model_meta_entry_path = FormatOm2Path(OM2_MODEL_META_PATH_FORMAT, std::to_string(model_index).c_str());
171 GE_ASSERT_TRUE(271 GE_ASSERT_TRUE(
@@ -35,6 +35,13 @@ constexpr auto kAttrKernelName = "_kernelname";
35const std::string kOm2ConstantsConfigSuffix = "_constants_config.json";35const std::string kOm2ConstantsConfigSuffix = "_constants_config.json";
36const std::string kOm2ExternalWeightDirName = "weight";36const std::string kOm2ExternalWeightDirName = "weight";
37 37 
38+constexpr size_t kAippDimPartsNum = 6U;
39+constexpr size_t kAippDimNameIdx = 2U;
40+constexpr size_t kAippDimSizeIdx = 3U;
41+constexpr size_t kAippDimDimNumIdx = 4U;
42+constexpr size_t kAippDimShapeIdx = 5U;
43+constexpr int32_t kAippDecimalRadix = 10;
44+ 
38struct ModelIoNodes {45struct ModelIoNodes {
39 std::map<uint32_t, OpDescPtr> input_ops;46 std::map<uint32_t, OpDescPtr> input_ops;
40 std::vector<OpDescPtr> output_ops;47 std::vector<OpDescPtr> output_ops;
@@ -374,6 +381,219 @@ Status SetOm2CompatibleOmInfoList(const GeModelPtr &ge_model) {
374 return FAILED);381 return FAILED);
375 return SUCCESS;382 return SUCCESS;
376}383}
384+ 
385+static void ConvertAippAttrToConfigInfo(const GeAttrValue::NamedAttrs &aipp_attr, ge::AippConfigInfo &info) {
386+ GELOGD("[OM2] Converting NamedAttrs to AippConfigInfo");
387+ int64_t i64_val = 0;
388+ float32_t f32_val = 0.0F;
389+ bool b_val = false;
390+ std::vector<int64_t> i64_vec;
391+ std::vector<float32_t> f32_vec;
392+ 
393+ auto getInt = [&aipp_attr, &i64_val](const char *k) -> int64_t {
394+ (void)aipp_attr.GetItem(k).GetValue<GeAttrValue::INT>(i64_val);
395+ return i64_val;
396+ };
397+ auto getF32 = [&aipp_attr, &f32_val](const char *k) -> float32_t {
398+ (void)aipp_attr.GetItem(k).GetValue<GeAttrValue::FLOAT>(f32_val);
399+ return f32_val;
400+ };
401+ auto getBool = [&aipp_attr, &b_val](const char *k) -> bool {
402+ (void)aipp_attr.GetItem(k).GetValue<GeAttrValue::BOOL>(b_val);
403+ return b_val;
404+ };
405+ auto getListIntFirst = [&aipp_attr, &i64_vec](const char *k) -> int32_t {
406+ if (aipp_attr.GetItem(k).GetValue<GeAttrValue::LIST_INT>(i64_vec) == SUCCESS && !i64_vec.empty()) {
407+ return static_cast<int32_t>(i64_vec[0]);
408+ }
409+ return 0;
410+ };
411+ auto getListF32First = [&aipp_attr, &f32_vec](const char *k) -> float32_t {
412+ if (aipp_attr.GetItem(k).GetValue<GeAttrValue::LIST_FLOAT>(f32_vec) == SUCCESS && !f32_vec.empty()) {
413+ return f32_vec[0];
414+ }
415+ return 0.0F;
416+ };
417+ 
418+ info.aipp_mode = static_cast<int8_t>(getInt("aipp_mode"));
419+ info.input_format = static_cast<int8_t>(getInt("input_format"));
420+ info.src_image_size_w = static_cast<int32_t>(getInt("src_image_size_w"));
421+ info.src_image_size_h = static_cast<int32_t>(getInt("src_image_size_h"));
422+ info.crop = static_cast<int8_t>(getBool("crop"));
423+ info.load_start_pos_w = static_cast<int32_t>(getInt("load_start_pos_w"));
424+ info.load_start_pos_h = static_cast<int32_t>(getInt("load_start_pos_h"));
425+ info.crop_size_w = static_cast<int32_t>(getInt("crop_size_w"));
426+ info.crop_size_h = static_cast<int32_t>(getInt("crop_size_h"));
427+ info.resize = static_cast<int8_t>(getBool("resize"));
428+ info.resize_output_w = static_cast<int32_t>(getInt("resize_output_w"));
429+ info.resize_output_h = static_cast<int32_t>(getInt("resize_output_h"));
430+ info.padding = static_cast<int8_t>(getBool("padding"));
431+ info.left_padding_size = static_cast<int32_t>(getInt("left_padding_size"));
432+ info.right_padding_size = static_cast<int32_t>(getInt("right_padding_size"));
433+ info.top_padding_size = static_cast<int32_t>(getInt("top_padding_size"));
434+ info.bottom_padding_size = static_cast<int32_t>(getInt("bottom_padding_size"));
435+ info.csc_switch = static_cast<int8_t>(getBool("csc_switch"));
436+ info.rbuv_swap_switch = static_cast<int8_t>(getBool("rbuv_swap_switch"));
437+ info.ax_swap_switch = static_cast<int8_t>(getBool("ax_swap_switch"));
438+ info.single_line_mode = static_cast<int8_t>(getBool("single_line_mode"));
439+ info.matrix_r0c0 = getListIntFirst("matrix_r0c0");
440+ info.matrix_r0c1 = getListIntFirst("matrix_r0c1");
441+ info.matrix_r0c2 = getListIntFirst("matrix_r0c2");
442+ info.matrix_r1c0 = getListIntFirst("matrix_r1c0");
443+ info.matrix_r1c1 = getListIntFirst("matrix_r1c1");
444+ info.matrix_r1c2 = getListIntFirst("matrix_r1c2");
445+ info.matrix_r2c0 = getListIntFirst("matrix_r2c0");
446+ info.matrix_r2c1 = getListIntFirst("matrix_r2c1");
447+ info.matrix_r2c2 = getListIntFirst("matrix_r2c2");
448+ info.output_bias_0 = getListIntFirst("output_bias_0");
449+ info.output_bias_1 = getListIntFirst("output_bias_1");
450+ info.output_bias_2 = getListIntFirst("output_bias_2");
451+ info.input_bias_0 = getListIntFirst("input_bias_0");
452+ info.input_bias_1 = getListIntFirst("input_bias_1");
453+ info.input_bias_2 = getListIntFirst("input_bias_2");
454+ info.mean_chn_0 = static_cast<int32_t>(getInt("mean_chn_0"));
455+ info.mean_chn_1 = static_cast<int32_t>(getInt("mean_chn_1"));
456+ info.mean_chn_2 = static_cast<int32_t>(getInt("mean_chn_2"));
457+ info.mean_chn_3 = static_cast<int32_t>(getInt("mean_chn_3"));
458+ info.min_chn_0 = getF32("min_chn_0");
459+ info.min_chn_1 = getF32("min_chn_1");
460+ info.min_chn_2 = getF32("min_chn_2");
461+ info.min_chn_3 = getF32("min_chn_3");
462+ info.var_reci_chn_0 = getListF32First("var_reci_chn_0");
463+ info.var_reci_chn_1 = getListF32First("var_reci_chn_1");
464+ info.var_reci_chn_2 = getListF32First("var_reci_chn_2");
465+ info.var_reci_chn_3 = getListF32First("var_reci_chn_3");
466+ info.support_rotation = static_cast<int8_t>(getBool("support_rotation"));
467+ info.related_input_rank = static_cast<uint32_t>(getInt("related_input_rank"));
468+ info.max_src_image_size = static_cast<uint32_t>(getInt("max_src_image_size"));
469+}
470+ 
471+static Status ParseAippModeStr(const std::string &mode, ge::InputAippType &aipp_type) {
472+ if (mode == "static_aipp") {
473+ aipp_type = ge::DATA_WITH_STATIC_AIPP;
474+ } else if (mode == "dynamic_aipp") {
475+ aipp_type = ge::DATA_WITH_DYNAMIC_AIPP;
476+ } else if (mode == "dynamic_aipp_conf") {
477+ aipp_type = ge::DYNAMIC_AIPP_NODE;
478+ } else {
479+ GELOGE(PARAM_INVALID, "[OM2] Unknown AIPP mode: %s", mode.c_str());
480+ return PARAM_INVALID;
481+ }
482+ return SUCCESS;
483+}
484+ 
485+static size_t ResolveAippDataIndex(const std::map<std::string, uint32_t> &data_index_map,
486+ const std::string &target_name) {
487+ const auto iter = data_index_map.find(target_name);
488+ return (iter != data_index_map.end()) ? static_cast<size_t>(iter->second) : 0U;
489+}
490+ 
491+static void ParseOrigInputInfoFromStr(const std::string &input_str, ge::OriginInputInfo &orig_info) {
492+ const auto parts = StringUtils::Split(input_str, ':');
493+ if (parts.size() >= 5U) {
494+ orig_info.format = static_cast<ge::Format>(ge::TypeUtils::SerialStringToFormat(parts[0]));
495+ orig_info.data_type = static_cast<ge::DataType>(ge::TypeUtils::SerialStringToDataType(parts[1]));
496+ orig_info.dim_num =
497+ static_cast<uint32_t>(std::strtol(parts[kAippDimDimNumIdx].c_str(), nullptr, kAippDecimalRadix));
498+ }
499+}
500+ 
501+// 将 "NCHW:DT_FLOAT:data:0:4:1,3,224,224" 格式的字符串解析为 InputOutputDims
502+static Status ParseAippDimInfo(const std::string &info_str, ge::InputOutputDims &dims_info) {
503+ const auto parts = StringUtils::Split(info_str, ':');
504+ if (parts.size() != kAippDimPartsNum) {
505+ GELOGW("[OM2][AIPP] Invalid aipp dim info: %s, parts=%zu", info_str.c_str(), parts.size());
506+ return FAILED;
507+ }
508+ dims_info.name = parts[kAippDimNameIdx];
509+ dims_info.size = static_cast<uint32_t>(std::strtol(parts[kAippDimSizeIdx].c_str(), nullptr, kAippDecimalRadix));
510+ dims_info.dim_num = static_cast<size_t>(std::strtol(parts[kAippDimDimNumIdx].c_str(), nullptr, kAippDecimalRadix));
511+ 
512+ const auto dim_strs = StringUtils::Split(parts[kAippDimShapeIdx], ',');
513+ for (const auto &dim_str : dim_strs) {
514+ if (dim_str.empty()) {
515+ continue;
516+ }
517+ dims_info.dims.emplace_back(std::strtol(dim_str.c_str(), nullptr, kAippDecimalRadix));
518+ }
519+ return SUCCESS;
520+}
521+ 
522+static Status ParseAippDims(const std::vector<std::string> &dim_strs, std::vector<ge::InputOutputDims> &dims) {
523+ for (const auto &s : dim_strs) {
524+ ge::InputOutputDims dim_info;
525+ GE_CHK_STATUS_RET(ParseAippDimInfo(s, dim_info), "[Parse][AippDimInfo] failed for: %s", s.c_str());
526+ dims.push_back(std::move(dim_info));
527+ }
528+ return SUCCESS;
529+}
530+ 
531+static Status ExtractAippMetaFromOpDesc(const OpDescPtr &op_desc, const std::map<std::string, uint32_t> &data_index_map,
532+ gert::Om2AippMeta &meta) {
533+ GELOGD("[OM2] Extract AIPP meta from node: %s", op_desc->GetName().c_str());
534+ GeAttrValue::NamedAttrs aipp_attr;
535+ if (ge::AttrUtils::GetNamedAttrs(op_desc, ATTR_NAME_AIPP, aipp_attr)) {
536+ ConvertAippAttrToConfigInfo(aipp_attr, meta.aipp_config_info);
537+ }
538+ const std::string *related_name = ge::AttrUtils::GetStr(op_desc, ATTR_DATA_AIPP_DATA_NAME_MAP);
539+ if (related_name != nullptr) {
540+ meta.aipp_data_index = ResolveAippDataIndex(data_index_map, *related_name);
541+ }
542+ std::vector<std::string> aipp_inputs;
543+ std::vector<std::string> aipp_outputs;
544+ (void)ge::AttrUtils::GetListStr(op_desc, ATTR_NAME_AIPP_INPUTS, aipp_inputs);
545+ (void)ge::AttrUtils::GetListStr(op_desc, ATTR_NAME_AIPP_OUTPUTS, aipp_outputs);
546+ GE_CHK_STATUS_RET(ParseAippDims(aipp_inputs, meta.aipp_input_dims));
547+ GE_CHK_STATUS_RET(ParseAippDims(aipp_outputs, meta.aipp_output_dims));
548+ if (!aipp_inputs.empty()) {
549+ ParseOrigInputInfoFromStr(aipp_inputs[0], meta.orig_input_info);
550+ }
551+ return SUCCESS;
552+}
553+ 
554+static Status CollectAippMetas(const ComputeGraphPtr &graph, gert::Om2ModelMeta &model_meta) {
555+ std::map<std::string, uint32_t> data_index_map;
556+ for (const auto &node : graph->GetDirectNode()) {
557+ const auto op_desc = node->GetOpDesc();
558+ if (op_desc != nullptr) {
559+ uint32_t index = 0U;
560+ if (ge::AttrUtils::GetInt(op_desc, ATTR_NAME_INDEX, index)) {
561+ data_index_map[op_desc->GetName()] = index;
562+ }
563+ }
564+ }
565+ 
566+ for (const auto &node : graph->GetDirectNode()) {
567+ const auto op_desc = node->GetOpDesc();
568+ if (op_desc == nullptr) {
569+ continue;
570+ }
571+ const std::string *mode = ge::AttrUtils::GetStr(op_desc, ATTR_DATA_RELATED_AIPP_MODE);
572+ if (mode == nullptr) {
573+ continue;
574+ }
575+ GELOGI("[OM2] Found AIPP node: %s, mode=%s", op_desc->GetName().c_str(), mode->c_str());
576+ ge::InputAippType aipp_type;
577+ GE_CHK_STATUS_RET(ParseAippModeStr(*mode, aipp_type), "[Parse][AippMode] Unknown AIPP mode for node: %s",
578+ op_desc->GetName().c_str());
579+ uint32_t input_index = 0U;
580+ (void)ge::AttrUtils::GetInt(op_desc, ATTR_NAME_INDEX, input_index);
581+ if (input_index >= model_meta.aipp_infos.size()) {
582+ model_meta.aipp_infos.resize(input_index + 1U);
583+ }
584+ gert::Om2AippMeta &meta = model_meta.aipp_infos[input_index];
585+ meta.aipp_type = aipp_type;
586+ const Status ret = ExtractAippMetaFromOpDesc(op_desc, data_index_map, meta);
587+ if (ret != SUCCESS) {
588+ GELOGE(ret, "[OM2] ExtractAippMetaFromOpDesc failed for node: %s", op_desc->GetName().c_str());
589+ return ret;
590+ }
591+ model_meta.has_aipp = true;
592+ }
593+ GELOGI("[OM2] Collected %zu AIPP metas", model_meta.aipp_infos.size());
594+ return SUCCESS;
595+}
596+ 
377} // namespace597} // namespace
378 598 
379Status Om2PackageHelper::SaveToOmRootModel(const GeRootModelPtr &ge_root_model, const std::string &output_file,599Status Om2PackageHelper::SaveToOmRootModel(const GeRootModelPtr &ge_root_model, const std::string &output_file,
@@ -931,6 +1151,8 @@ Status Om2PackageHelper::BuildModelMeta(const GeModelPtr &ge_model, gert::Om2Mod
931 model_meta.dynamic_output_shape = extra_info.dynamic_output_shape;1151 model_meta.dynamic_output_shape = extra_info.dynamic_output_shape;
932 model_meta.user_designate_shape_order = extra_info.user_designate_shape_order;1152 model_meta.user_designate_shape_order = extra_info.user_designate_shape_order;
933 1153 
1154+ GE_CHK_STATUS_RET(CollectAippMetas(graph, model_meta));
1155+ 
934 GELOGI("[OM2] Successfully built model meta");1156 GELOGI("[OM2] Successfully built model meta");
935 return SUCCESS;1157 return SUCCESS;
936}1158}
@@ -19,6 +19,7 @@
19#include <vector>19#include <vector>
20 20 
21#include "common/om2/codegen/om2_codegen_types.h"21#include "common/om2/codegen/om2_codegen_types.h"
22+#include "common/ge_common/ge_types.h"
22#include "framework/common/om2_tensor_desc.h"23#include "framework/common/om2_tensor_desc.h"
23 24 
24namespace gert {25namespace gert {
@@ -34,6 +35,18 @@ struct Om2ProgramBody {
34 ge::Om2CodegenArtifact so_artifact;35 ge::Om2CodegenArtifact so_artifact;
35};36};
36 37 
38+/// AIPP 元数据,编译期从 ComputeGraph 提取,序列化到 model_meta.json 的 aipp 字段
39+struct Om2AippMeta {
40+ ge::InputAippType aipp_type = ge::DATA_WITHOUT_AIPP;
41+ size_t aipp_data_index = 0U;
42+ ge::AippConfigInfo aipp_config_info;
43+ std::vector<ge::InputOutputDims> aipp_input_dims;
44+ std::vector<ge::InputOutputDims> aipp_output_dims;
45+ ge::OriginInputInfo orig_input_info;
46+};
47+ 
48+using Om2AippInfo = Om2AippMeta;
49+ 
37/// 模型元数据50/// 模型元数据
38struct Om2ModelMeta {51struct Om2ModelMeta {
39 std::string model_name;52 std::string model_name;
@@ -49,6 +62,8 @@ struct Om2ModelMeta {
49 std::vector<std::string> dynamic_output_shape;62 std::vector<std::string> dynamic_output_shape;
50 std::vector<std::string> user_designate_shape_order;63 std::vector<std::string> user_designate_shape_order;
51 std::vector<std::vector<int64_t>> origin_input_dims;64 std::vector<std::vector<int64_t>> origin_input_dims;
65+ std::vector<Om2AippMeta> aipp_infos;
66+ bool has_aipp = false;
52};67};
53 68 
54struct Om2ConstantsData {69struct Om2ConstantsData {
@@ -1080,11 +1080,6 @@ graphStatus Impl::BuildModel(const Graph &graph, const std::map<std::string, std
1080 if (IsOm2BuildMode(offline_mode)) {1080 if (IsOm2BuildMode(offline_mode)) {
1081 GE_ASSERT_SUCCESS(CheckOm2UnsupportedOptions(options), "[Check][OM2][BuildOptions] failed!");1081 GE_ASSERT_SUCCESS(CheckOm2UnsupportedOptions(options), "[Check][OM2][BuildOptions] failed!");
1082 GE_ASSERT_SUCCESS(CheckUserSpecifiedGlobalOptionsForOm2(), "[Check][OM2][GlobalOptions] failed!");1082 GE_ASSERT_SUCCESS(CheckUserSpecifiedGlobalOptionsForOm2(), "[Check][OM2][GlobalOptions] failed!");
1083- const auto insert_op_iter = options.find(ge::ir_option::INSERT_OP_FILE);
1084- if (insert_op_iter != options.cend()) {
1085- GE_ASSERT_SUCCESS(InsertAippOpUtil::ValidateStaticAippOnly(insert_op_iter->second),
1086- "[Check][OM2][InsertOpConf] Dynamic AIPP is not supported in OM2 mode.");
1087- }
1088 }1083 }
1089 ge::PrintOptionMap(options, "BuildModel option");1084 ge::PrintOptionMap(options, "BuildModel option");
1090 ret = Init(graph, options);1085 ret = Init(graph, options);
@@ -748,27 +748,4 @@ Status InsertAippOpUtil::SetModelInputDims(NodePtr &data_node, NodePtr &aipp_nod
748 return SUCCESS;748 return SUCCESS;
749}749}
750 750 
751-Status InsertAippOpUtil::ValidateStaticAippOnly(const std::string &config_path) {
752- if (config_path.empty()) {
753- return SUCCESS;
754- }
755- domi::InsertNewOps insert_ops;
756- GE_CHK_BOOL_RET_STATUS(ReadProtoFromText(config_path.c_str(), &insert_ops), PARAM_INVALID,
757- "[Read][Proto] from file:%s failed", config_path.c_str());
758- for (int32_t i = 0; i < insert_ops.aipp_op_size(); ++i) {
759- const auto &aipp_op = insert_ops.aipp_op(i);
760- if (aipp_op.aipp_mode() == domi::AippOpParams::dynamic) {
761- REPORT_PREDEFINED_ERR_MSG(
762- "E10001", std::vector<const char_t *>({"parameter", "value", "reason"}),
763- std::vector<const char_t *>({"--insert_op_conf", config_path.c_str(),
764- "dynamic AIPP is not supported in om2 mode. Please use aipp_mode: static."}));
765- GELOGE(PARAM_INVALID,
766- "[Check][OM2][AippMode] Dynamic AIPP (aipp_op[%d]) is not supported in OM2 build mode. "
767- "Please use aipp_mode: static.",
768- i);
769- return PARAM_INVALID;
770- }
771- }
772- return SUCCESS;
773-}
774} // namespace ge751} // namespace ge
@@ -35,10 +35,6 @@ class InsertAippOpUtil {
35 35 
36 Status InsertAippOps(ge::ComputeGraphPtr &graph, std::string &aippConfigPath);36 Status InsertAippOps(ge::ComputeGraphPtr &graph, std::string &aippConfigPath);
37 37 
38- /// @brief Validate that insert_op_conf contains no dynamic AIPP (OM2 only supports static AIPP).
39- /// Called at entry points (ATC / aclgrphBuildModel) where OM2 mode is already known.
40- static Status ValidateStaticAippOnly(const std::string &config_path);
41- 
42 void ClearNewOps();38 void ClearNewOps();
43 39 
44 Status UpdateDataNodeByAipp(const ComputeGraphPtr &graph) const;40 Status UpdateDataNodeByAipp(const ComputeGraphPtr &graph) const;
@@ -14,6 +14,7 @@
14#include <vector>14#include <vector>
15#include "common/ge_visibility.h"15#include "common/ge_visibility.h"
16#include "common/ge_common/ge_types.h"16#include "common/ge_common/ge_types.h"
17+#include "common/dynamic_aipp.h"
17#include "framework/common/om2_tensor_desc.h"18#include "framework/common/om2_tensor_desc.h"
18 19 
19namespace gert {20namespace gert {
@@ -61,6 +62,15 @@ class VISIBILITY_EXPORT Om2ModelExecutor {
61 ge::Status GetOpAttr(std::map<std::string, std::map<std::string, std::string>> &op_attr_map) const;62 ge::Status GetOpAttr(std::map<std::string, std::map<std::string, std::string>> &op_attr_map) const;
62 ge::Status GetOpDescInfo(uint32_t device_id, uint32_t stream_id, uint32_t task_id,63 ge::Status GetOpDescInfo(uint32_t device_id, uint32_t stream_id, uint32_t task_id,
63 ge::OpDescInfo &op_desc_info) const;64 ge::OpDescInfo &op_desc_info) const;
65+ ge::Status GetAippInfo(uint32_t index, ge::AippConfigInfo &aipp_info) const;
66+ ge::Status GetAippType(uint32_t index, ge::InputAippType &aipp_type, size_t &aipp_data_index) const;
67+ ge::Status GetOrigInputInfo(uint32_t index, ge::OriginInputInfo &orig_input_info) const;
68+ ge::Status GetAllAippInputOutputDims(uint32_t index, std::vector<ge::InputOutputDims> &input_dims,
69+ std::vector<ge::InputOutputDims> &output_dims) const;
70+ ge::Status GetBatchInfoSize(size_t &shape_count) const;
71+ ge::Status SetDynamicAippData(void *dynamic_input_addr, uint64_t length,
72+ const std::vector<kAippDynamicBatchPara> &aipp_batch_para,
73+ const kAippDynamicPara &aipp_parms);
64 74 
65 private:75 private:
66 class Impl;76 class Impl;
@@ -0,0 +1,163 @@
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 "om2_aipp_utils.h"
12+#include <cstdlib>
13+#include "common/ge_common/string_util.h"
14+#include "framework/common/debug/log.h"
15+#include "nlohmann/json.hpp"
16+ 
17+namespace gert {
18+namespace om2 {
19+ 
20+// 将 "NCHW:DT_FLOAT:data:0:4:1,3,224,224" 格式的字符串解析为 InputOutputDims
21+ge::Status ParseAippDimInfo(const std::string &info_str, ge::InputOutputDims &dims_info) {
22+ const auto parts = ge::StringUtils::Split(info_str, ':');
23+ if (parts.size() != kAippDimPartsNum) {
24+ GELOGW("[OM2][AIPP] Invalid aipp dim info: %s, parts=%zu", info_str.c_str(), parts.size());
25+ return ge::FAILED;
26+ }
27+ dims_info.name = parts[kAippDimNameIdx];
28+ dims_info.size = static_cast<uint32_t>(std::strtol(parts[kAippDimSizeIdx].c_str(), nullptr, kAippDecimalRadix));
29+ dims_info.dim_num = static_cast<size_t>(std::strtol(parts[kAippDimDimNumIdx].c_str(), nullptr, kAippDecimalRadix));
30+ 
31+ const auto dim_strs = ge::StringUtils::Split(parts[kAippDimShapeIdx], ',');
32+ for (const auto &dim_str : dim_strs) {
33+ if (dim_str.empty()) {
34+ continue;
35+ }
36+ dims_info.dims.emplace_back(std::strtol(dim_str.c_str(), nullptr, kAippDecimalRadix));
37+ }
38+ return ge::SUCCESS;
39+}
40+ 
41+// 从 JsonFile 解析 AippConfigInfo(打包侧保证所有字段存在)
42+ge::AippConfigInfo ParseAippConfigFromJson(const ge::JsonFile &entry) {
43+ ge::AippConfigInfo info = {};
44+ 
45+ entry.Get("aipp_mode", info.aipp_mode);
46+ entry.Get("input_format", info.input_format);
47+ entry.Get("src_image_size_w", info.src_image_size_w);
48+ entry.Get("src_image_size_h", info.src_image_size_h);
49+ entry.Get("crop", info.crop);
50+ entry.Get("load_start_pos_w", info.load_start_pos_w);
51+ entry.Get("load_start_pos_h", info.load_start_pos_h);
52+ entry.Get("crop_size_w", info.crop_size_w);
53+ entry.Get("crop_size_h", info.crop_size_h);
54+ entry.Get("resize", info.resize);
55+ entry.Get("resize_output_w", info.resize_output_w);
56+ entry.Get("resize_output_h", info.resize_output_h);
57+ entry.Get("padding", info.padding);
58+ entry.Get("left_padding_size", info.left_padding_size);
59+ entry.Get("right_padding_size", info.right_padding_size);
60+ entry.Get("top_padding_size", info.top_padding_size);
61+ entry.Get("bottom_padding_size", info.bottom_padding_size);
62+ entry.Get("csc_switch", info.csc_switch);
63+ entry.Get("rbuv_swap_switch", info.rbuv_swap_switch);
64+ entry.Get("ax_swap_switch", info.ax_swap_switch);
65+ entry.Get("single_line_mode", info.single_line_mode);
66+ entry.Get("matrix_r0c0", info.matrix_r0c0);
67+ entry.Get("matrix_r0c1", info.matrix_r0c1);
68+ entry.Get("matrix_r0c2", info.matrix_r0c2);
69+ entry.Get("matrix_r1c0", info.matrix_r1c0);
70+ entry.Get("matrix_r1c1", info.matrix_r1c1);
71+ entry.Get("matrix_r1c2", info.matrix_r1c2);
72+ entry.Get("matrix_r2c0", info.matrix_r2c0);
73+ entry.Get("matrix_r2c1", info.matrix_r2c1);
74+ entry.Get("matrix_r2c2", info.matrix_r2c2);
75+ entry.Get("output_bias_0", info.output_bias_0);
76+ entry.Get("output_bias_1", info.output_bias_1);
77+ entry.Get("output_bias_2", info.output_bias_2);
78+ entry.Get("input_bias_0", info.input_bias_0);
79+ entry.Get("input_bias_1", info.input_bias_1);
80+ entry.Get("input_bias_2", info.input_bias_2);
81+ entry.Get("mean_chn_0", info.mean_chn_0);
82+ entry.Get("mean_chn_1", info.mean_chn_1);
83+ entry.Get("mean_chn_2", info.mean_chn_2);
84+ entry.Get("mean_chn_3", info.mean_chn_3);
85+ entry.Get("min_chn_0", info.min_chn_0);
86+ entry.Get("min_chn_1", info.min_chn_1);
87+ entry.Get("min_chn_2", info.min_chn_2);
88+ entry.Get("min_chn_3", info.min_chn_3);
89+ entry.Get("var_reci_chn_0", info.var_reci_chn_0);
90+ entry.Get("var_reci_chn_1", info.var_reci_chn_1);
91+ entry.Get("var_reci_chn_2", info.var_reci_chn_2);
92+ entry.Get("var_reci_chn_3", info.var_reci_chn_3);
93+ entry.Get("support_rotation", info.support_rotation);
94+ entry.Get("related_input_rank", info.related_input_rank);
95+ entry.Get("max_src_image_size", info.max_src_image_size);
96+ 
97+ return info;
98+}
99+ 
100+// 从 JsonFile 解析 OriginInputInfo
101+ge::OriginInputInfo ParseOriginInputFromJson(const ge::JsonFile &entry) {
102+ ge::OriginInputInfo info = {};
103+ entry.Get("orig_input_format", info.format);
104+ entry.Get("orig_input_data_type", info.data_type);
105+ entry.Get("orig_input_dim_num", info.dim_num);
106+ return info;
107+}
108+ 
109+// 从 JsonFile 的字符串数组解析 InputOutputDims 列表
110+std::vector<ge::InputOutputDims> ParseAippDimsFromJson(const ge::JsonFile &entry, const char *key) {
111+ std::vector<ge::InputOutputDims> result;
112+ for (const auto &str : entry[key]) {
113+ ge::InputOutputDims dims;
114+ if (ParseAippDimInfo(str.get<std::string>(), dims) == ge::SUCCESS) {
115+ result.emplace_back(std::move(dims));
116+ }
117+ }
118+ return result;
119+}
120+ 
121+// 从 model_meta.json 的 aipp 字段解析 AIPP 信息
122+ge::Status ParseAippJson(const ge::JsonFile &aipp_json, std::vector<Om2AippMeta> &aipp_infos, bool &has_aipp) {
123+ GELOGI("[OM2][AIPP] Parsing aipp section from model_meta.json");
124+ try {
125+ if (!aipp_json["aipp_infos"].is_array()) {
126+ return ge::SUCCESS;
127+ }
128+ has_aipp = true;
129+ for (const auto &item : aipp_json["aipp_infos"]) {
130+ if (!item.is_object()) {
131+ continue;
132+ }
133+ const ge::JsonFile aipp_item(item);
134+ uint32_t input_index = 0U;
135+ aipp_item.Get("index", input_index);
136+ if (input_index >= aipp_infos.size()) {
137+ aipp_infos.resize(input_index + 1U);
138+ }
139+ int32_t aipp_type = 0;
140+ aipp_item.Get("aipp_type", aipp_type);
141+ size_t aipp_data_index = 0U;
142+ aipp_item.Get("aipp_data_index", aipp_data_index);
143+ aipp_infos[input_index] = {
144+ static_cast<ge::InputAippType>(aipp_type),
145+ aipp_data_index,
146+ ParseAippConfigFromJson(aipp_item),
147+ ParseAippDimsFromJson(aipp_item, "aipp_inputs"),
148+ ParseAippDimsFromJson(aipp_item, "aipp_outputs"),
149+ ParseOriginInputFromJson(aipp_item),
150+ };
151+ }
152+ } catch (const std::exception &e) {
153+ GELOGW("[OM2][AIPP] Failed to parse aipp json: %s, falling back to no-AIPP", e.what());
154+ aipp_infos.clear();
155+ has_aipp = false;
156+ return ge::FAILED;
157+ }
158+ GELOGI("[OM2][AIPP] Successfully parsed aipp section");
159+ return ge::SUCCESS;
160+}
161+ 
162+} // namespace om2
163+} // namespace gert
@@ -0,0 +1,51 @@
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 RUNTIME_OM2_OM2_AIPP_UTILS_H_
12+#define RUNTIME_OM2_OM2_AIPP_UTILS_H_
13+ 
14+#include <string>
15+#include <vector>
16+#include "common/dynamic_aipp.h"
17+#include "common/ge_common/ge_types.h"
18+#include "common/helper/om2/json_file.h"
19+#include "common/om2/om2_model_data.h"
20+#include "graph/types.h"
21+ 
22+namespace gert {
23+namespace om2 {
24+ 
25+// AIPP dim info 解析常量
26+constexpr size_t kAippDimPartsNum = 6U;
27+constexpr size_t kAippDimNameIdx = 2U;
28+constexpr size_t kAippDimSizeIdx = 3U;
29+constexpr size_t kAippDimDimNumIdx = 4U;
30+constexpr size_t kAippDimShapeIdx = 5U;
31+constexpr int32_t kAippDecimalRadix = 10;
32+ 
33+// 将 "NCHW:DT_FLOAT:data:0:4:1,3,224,224" 格式的字符串解析为 InputOutputDims
34+ge::Status ParseAippDimInfo(const std::string &info_str, ge::InputOutputDims &dims_info);
35+ 
36+// 从 JSON 解析 AippConfigInfo(打包侧保证所有字段存在)
37+ge::AippConfigInfo ParseAippConfigFromJson(const ge::JsonFile &entry);
38+ 
39+// 从 JSON 解析 OriginInputInfo
40+ge::OriginInputInfo ParseOriginInputFromJson(const ge::JsonFile &entry);
41+ 
42+// 从 JSON 字符串数组解析 InputOutputDims 列表
43+std::vector<ge::InputOutputDims> ParseAippDimsFromJson(const ge::JsonFile &entry, const char *key);
44+ 
45+// 从 model_meta.json 的 aipp 字段 JSON 对象中解析 AIPP 信息
46+ge::Status ParseAippJson(const ge::JsonFile &aipp_json, std::vector<Om2AippMeta> &aipp_infos, bool &has_aipp);
47+ 
48+} // namespace om2
49+} // namespace gert
50+ 
51+#endif // RUNTIME_OM2_OM2_AIPP_UTILS_H_
Mruntime/om2/om2_model_executor.cc+150-0文件内容审核中,请稍后刷新重试
@@ -2130,6 +2130,40 @@ const std::vector<std::vector<int64_t>> &Om2ModelExecutor::GetOriginInputDims()
2130 return MockFunctionTest::aclStubInstance().GetOriginInputDims();2130 return MockFunctionTest::aclStubInstance().GetOriginInputDims();
2131}2131}
2132 2132 
2133+ge::Status Om2ModelExecutor::GetAippInfo(uint32_t index, ge::AippConfigInfo &aipp_info) const {
2134+ return MockFunctionTest::aclStubInstance().GetAippInfo(index, aipp_info);
2135+}
2136+ 
2137+ge::Status Om2ModelExecutor::GetAippType(uint32_t index, ge::InputAippType &aipp_type, size_t &aipp_data_index) const {
2138+ return MockFunctionTest::aclStubInstance().GetAippType(index, aipp_type, aipp_data_index);
2139+}
2140+ 
2141+ge::Status Om2ModelExecutor::GetOrigInputInfo(uint32_t index, ge::OriginInputInfo &orig_input_info) const {
2142+ (void)index;
2143+ (void)orig_input_info;
2144+ return ge::SUCCESS;
2145+}
2146+ 
2147+ge::Status Om2ModelExecutor::GetAllAippInputOutputDims(uint32_t index, std::vector<ge::InputOutputDims> &input_dims,
2148+ std::vector<ge::InputOutputDims> &output_dims) const {
2149+ return MockFunctionTest::aclStubInstance().GetAllAippInputOutputDims(index, input_dims, output_dims);
2150+}
2151+ 
2152+ge::Status Om2ModelExecutor::GetBatchInfoSize(size_t &shape_count) const {
2153+ shape_count = 0U;
2154+ return ge::SUCCESS;
2155+}
2156+ 
2157+ge::Status Om2ModelExecutor::SetDynamicAippData(void *dynamic_input_addr, uint64_t length,
2158+ const std::vector<kAippDynamicBatchPara> &aipp_batch_para,
2159+ const kAippDynamicPara &aipp_parms) {
2160+ (void)dynamic_input_addr;
2161+ (void)length;
2162+ (void)aipp_batch_para;
2163+ (void)aipp_parms;
2164+ return ge::SUCCESS;
2165+}
2166+ 
2133class Om2ModelExecutor::Impl {2167class Om2ModelExecutor::Impl {
2134 public:2168 public:
2135 int dummy;2169 int dummy;
@@ -5953,9 +5953,9 @@ TEST_F(UTEST_ACL_Model, aclmdlLoadFromMemWithQ_Om2Model_ReturnsNotSupported) {
5953// OM2 Interface Test Cases - AIPP Interfaces5953// OM2 Interface Test Cases - AIPP Interfaces
5954// ============================================================================5954// ============================================================================
5955 5955 
5956-TEST_F(UTEST_ACL_Model, aclmdlGetAippType_Om2ModelId_ReturnsNotSupported) {5956+TEST_F(UTEST_ACL_Model, aclmdlGetAippType_Om2ModelId_Success) {
5957- // Test that aclmdlGetAippType returns not supported for OM2 model5957+ // Test that aclmdlGetAippType works for OM2 models (now implemented)
5958- // First load an OM2 model to get a valid OM2 model ID5958+ // Load an OM2 model to get a valid OM2 model ID
5959 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))5959 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))
5960 .WillRepeatedly(Invoke(IsOm2ModelFromFile));5960 .WillRepeatedly(Invoke(IsOm2ModelFromFile));
5961 5961 
@@ -5963,22 +5963,22 @@ TEST_F(UTEST_ACL_Model, aclmdlGetAippType_Om2ModelId_ReturnsNotSupported) {
5963 aclError load_ret = aclmdlLoadFromFile("test_om2_model.om2", &modelId);5963 aclError load_ret = aclmdlLoadFromFile("test_om2_model.om2", &modelId);
5964 5964 
5965 if (load_ret == ACL_SUCCESS && modelId >= std::numeric_limits<uint32_t>::max() / 2U) {5965 if (load_ret == ACL_SUCCESS && modelId >= std::numeric_limits<uint32_t>::max() / 2U) {
5966- // Try to get AIPP type - should return not supported5966+ // Get AIPP type - now returns real result (not ACL_ERROR_FEATURE_UNSUPPORTED)
5967 aclmdlInputAippType aippType;5967 aclmdlInputAippType aippType;
5968 size_t aippTypeNum = 0;5968 size_t aippTypeNum = 0;
5969 aclError ret = aclmdlGetAippType(modelId, 0, &aippType, &aippTypeNum);5969 aclError ret = aclmdlGetAippType(modelId, 0, &aippType, &aippTypeNum);
5970 5970 
5971- // Verify that the function returns not supported error5971+ // Verify the function is now implemented and returns success or appropriate error
5972- EXPECT_EQ(ret, ACL_ERROR_FEATURE_UNSUPPORTED);5972+ EXPECT_TRUE(ret == ACL_SUCCESS || ret == static_cast<int32_t>(ACL_ERROR_GE_AIPP_NOT_EXIST));
5973 5973 
5974 // Cleanup5974 // Cleanup
5975 acl::AclResourceManagerOm2::GetInstance().DeleteOm2Executor(modelId);5975 acl::AclResourceManagerOm2::GetInstance().DeleteOm2Executor(modelId);
5976 }5976 }
5977}5977}
atomgit-bot
atomgit-botatomgit-bot7月20日

🟡 Medium Priority

新增测试 aclmdlGetFirstAippInfo_Om2ModelId_SuccessaclmdlSetInputAIPP_Om2ModelId_Success 等用例中,使用 aclmdlLoadFromFile("test_om2_model.om2", &modelId) 加载模型,但该文件在测试环境中可能不存在。当加载失败时,测试体因 if (load_ret == ACL_SUCCESS && ...) 保护而静默跳过,未产生任何断言——即测试"通过"但实际未验证任何行为。这意味着 OM2 AIPP 接口实现的正确性未被这些用例真正覆盖,存在假阳性风险(代码存在回归时测试仍显示通过)。

建议:在测试加载失败时添加 FAIL()ADD_FAILURE() 以确保测试不会被静默跳过;或者使用 mock/stub 方式模拟 OM2 模型加载成功,直接注入 Om2ModelExecutor 到 AclResourceManagerOm2 中来测试 AIPP 接口逻辑(类似新测试 aclmdlGetFirstAippInfo_Om2ModelId_NullAippInfo 的做法),避免依赖外部测试文件。

likedislike
不准确?
5978 5978 
5979-TEST_F(UTEST_ACL_Model, aclmdlGetFirstAippInfo_Om2ModelId_ReturnsNotSupported) {5979+TEST_F(UTEST_ACL_Model, aclmdlGetFirstAippInfo_Om2ModelId_Success) {
5980- // Test that aclmdlGetFirstAippInfo returns not supported for OM2 model5980+ // Test that aclmdlGetFirstAippInfo works for OM2 models (now implemented)
5981- // First load an OM2 model to get a valid OM2 model ID5981+ // Load an OM2 model to get a valid OM2 model ID
5982 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))5982 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))
5983 .WillRepeatedly(Invoke(IsOm2ModelFromFile));5983 .WillRepeatedly(Invoke(IsOm2ModelFromFile));
5984 5984 
@@ -5986,21 +5986,41 @@ TEST_F(UTEST_ACL_Model, aclmdlGetFirstAippInfo_Om2ModelId_ReturnsNotSupported) {
5986 aclError load_ret = aclmdlLoadFromFile("test_om2_model.om2", &modelId);5986 aclError load_ret = aclmdlLoadFromFile("test_om2_model.om2", &modelId);
5987 5987 
5988 if (load_ret == ACL_SUCCESS && modelId >= std::numeric_limits<uint32_t>::max() / 2U) {5988 if (load_ret == ACL_SUCCESS && modelId >= std::numeric_limits<uint32_t>::max() / 2U) {
5989- // Try to get first AIPP info - should return not supported5989+ // Get first AIPP info - now returns real result (not ACL_ERROR_FEATURE_UNSUPPORTED)
5990 aclAippInfo aippInfo;5990 aclAippInfo aippInfo;
5991 aclError ret = aclmdlGetFirstAippInfo(modelId, 0, &aippInfo);5991 aclError ret = aclmdlGetFirstAippInfo(modelId, 0, &aippInfo);
5992 5992 
5993- // Verify that the function returns not supported error5993+ // Verify the function is now implemented: returns success or specific AIPP error
5994- EXPECT_EQ(ret, ACL_ERROR_FEATURE_UNSUPPORTED);5994+ EXPECT_TRUE(ret == ACL_SUCCESS || ret == static_cast<int32_t>(ACL_ERROR_GE_AIPP_NOT_EXIST));
5995 5995 
5996 // Cleanup5996 // Cleanup
5997 acl::AclResourceManagerOm2::GetInstance().DeleteOm2Executor(modelId);5997 acl::AclResourceManagerOm2::GetInstance().DeleteOm2Executor(modelId);
5998 }5998 }
5999}5999}
6000 6000 
6001-TEST_F(UTEST_ACL_Model, aclmdlSetInputAIPP_Om2ModelId_ReturnsNotSupported) {6001+TEST_F(UTEST_ACL_Model, aclmdlGetFirstAippInfo_Om2ModelId_NullAippInfo) {
6002- // Test that aclmdlSetInputAIPP returns not supported for OM2 model6002+ // Test that aclmdlGetFirstAippInfo returns error for null aippInfo
6003- // First load an OM2 model to get a valid OM2 model ID6003+ uint32_t modelId = 101U;
6004+ auto executor = std::unique_ptr<gert::Om2ModelExecutor>(new (std::nothrow) gert::Om2ModelExecutor);
6005+ if (executor != nullptr) {
6006+ acl::AclResourceManagerOm2::GetInstance().AddOm2ExecutorWithModelId(modelId, std::move(executor));
6007+ aclError ret = aclmdlGetFirstAippInfo(modelId, 0, nullptr);
6008+ EXPECT_NE(ret, ACL_SUCCESS);
6009+ acl::AclResourceManagerOm2::GetInstance().DeleteOm2Executor(modelId);
6010+ }
6011+}
6012+ 
6013+TEST_F(UTEST_ACL_Model, aclmdlGetFirstAippInfo_Om2ModelId_ExecutorNotFound) {
6014+ // Test that aclmdlGetFirstAippInfo returns error when executor is not found
6015+ uint32_t modelId = 102U;
6016+ aclAippInfo aippInfo;
6017+ aclError ret = aclmdlGetFirstAippInfo(modelId, 0, &aippInfo);
6018+ EXPECT_NE(ret, ACL_SUCCESS);
6019+}
6020+ 
6021+TEST_F(UTEST_ACL_Model, aclmdlSetInputAIPP_Om2ModelId_Success) {
6022+ // Test that aclmdlSetInputAIPP works for OM2 models (now implemented)
6023+ // Load an OM2 model to get a valid OM2 model ID
6004 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))6024 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))
6005 .WillRepeatedly(Invoke(IsOm2ModelFromFile));6025 .WillRepeatedly(Invoke(IsOm2ModelFromFile));
6006 6026 
@@ -6012,11 +6032,11 @@ TEST_F(UTEST_ACL_Model, aclmdlSetInputAIPP_Om2ModelId_ReturnsNotSupported) {
6012 aclmdlDataset *dataset = aclmdlCreateDataset();6032 aclmdlDataset *dataset = aclmdlCreateDataset();
6013 ASSERT_NE(dataset, nullptr);6033 ASSERT_NE(dataset, nullptr);
6014 6034 
6015- // Try to set input AIPP - should return not supported6035+ // Set input AIPP - now returns real result (not ACL_ERROR_FEATURE_UNSUPPORTED)
6016 aclError ret = aclmdlSetInputAIPP(modelId, dataset, 0, nullptr);6036 aclError ret = aclmdlSetInputAIPP(modelId, dataset, 0, nullptr);
6017 6037 
6018- // Verify that the function returns not supported error6038+ // Verify the function is now implemented: returns appropriate error for null aippParmsSet
6019- EXPECT_EQ(ret, ACL_ERROR_FEATURE_UNSUPPORTED);6039+ EXPECT_NE(ret, ACL_ERROR_FEATURE_UNSUPPORTED);
6020 6040 
6021 // Cleanup6041 // Cleanup
6022 aclmdlDestroyDataset(dataset);6042 aclmdlDestroyDataset(dataset);
@@ -6024,9 +6044,9 @@ TEST_F(UTEST_ACL_Model, aclmdlSetInputAIPP_Om2ModelId_ReturnsNotSupported) {
6024 }6044 }
6025}6045}
6026 6046 
6027-TEST_F(UTEST_ACL_Model, aclmdlSetAIPPByInputIndex_Om2ModelId_ReturnsNotSupported) {6047+TEST_F(UTEST_ACL_Model, aclmdlSetAIPPByInputIndex_Om2ModelId_Success) {
6028- // Test that aclmdlSetAIPPByInputIndex returns not supported for OM2 model6048+ // Test that aclmdlSetAIPPByInputIndex works for OM2 models (now implemented)
6029- // First load an OM2 model to get a valid OM2 model ID6049+ // Load an OM2 model to get a valid OM2 model ID
6030 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))6050 EXPECT_CALL(MockFunctionTest::aclStubInstance(), IsOm2Model(testing::_, testing::_))
6031 .WillRepeatedly(Invoke(IsOm2ModelFromFile));6051 .WillRepeatedly(Invoke(IsOm2ModelFromFile));
6032 6052 
@@ -6038,11 +6058,11 @@ TEST_F(UTEST_ACL_Model, aclmdlSetAIPPByInputIndex_Om2ModelId_ReturnsNotSupported
6038 aclmdlDataset *dataset = aclmdlCreateDataset();6058 aclmdlDataset *dataset = aclmdlCreateDataset();
6039 ASSERT_NE(dataset, nullptr);6059 ASSERT_NE(dataset, nullptr);
6040 6060 
6041- // Try to set AIPP by input index - should return not supported6061+ // Set AIPP by input index - now returns real result (not ACL_ERROR_FEATURE_UNSUPPORTED)
6042 aclError ret = aclmdlSetAIPPByInputIndex(modelId, dataset, 0, nullptr);6062 aclError ret = aclmdlSetAIPPByInputIndex(modelId, dataset, 0, nullptr);
6043 6063 
6044- // Verify that the function returns not supported error6064+ // Verify the function is now implemented: returns appropriate error for null aippParmsSet
6045- EXPECT_EQ(ret, ACL_ERROR_FEATURE_UNSUPPORTED);6065+ EXPECT_NE(ret, ACL_ERROR_FEATURE_UNSUPPORTED);
6046 6066 
6047 // Cleanup6067 // Cleanup
6048 aclmdlDestroyDataset(dataset);6068 aclmdlDestroyDataset(dataset);
@@ -6667,6 +6687,326 @@ TEST_F(UTEST_ACL_Model, GetModelOutputShapeInfoHelp_WithStaticOutputs_ParsesCorr
6667 }6687 }
6668}6688}
6669 6689 
6690+// ============================================================================
6691+// Test Cases for model_common AIPP Utility Functions
6692+// ============================================================================
6693+ 
6694+TEST_F(UTEST_ACL_Model, SetAippInfo_NullAippInfo_DoesNotCrash) {
6695+ ge::AippConfigInfo config{};
6696+ config.src_image_size_w = 224;
6697+ config.src_image_size_h = 224;
6698+ config.input_format = 2;
6699+ 
6700+ // Should not crash, just log error and return
6701+ acl::SetAippInfo(nullptr, config);
6702+ SUCCEED();
6703+}
6704+ 
6705+TEST_F(UTEST_ACL_Model, SetAippInfo_ValidConfig_MapsAllFields) {
6706+ // 构造含所有关键字段的 AippConfigInfo
6707+ ge::AippConfigInfo config{};
6708+ config.aipp_mode = 1;
6709+ config.input_format = 2;
6710+ config.src_image_size_w = 640;
6711+ config.src_image_size_h = 480;
6712+ config.crop = 1;
6713+ config.load_start_pos_w = 10;
6714+ config.load_start_pos_h = 20;
6715+ config.crop_size_w = 224;
6716+ config.crop_size_h = 224;
6717+ config.resize = 1;
6718+ config.resize_output_w = 112;
6719+ config.resize_output_h = 112;
6720+ config.padding = 1;
6721+ config.left_padding_size = 3;
6722+ config.right_padding_size = 4;
6723+ config.top_padding_size = 5;
6724+ config.bottom_padding_size = 6;
6725+ config.csc_switch = 1;
6726+ config.rbuv_swap_switch = 1;
6727+ config.ax_swap_switch = 0;
6728+ config.single_line_mode = 1;
6729+ config.matrix_r0c0 = 256;
6730+ config.matrix_r0c1 = 0;
6731+ config.matrix_r0c2 = 0;
6732+ config.matrix_r1c0 = 0;
6733+ config.matrix_r1c1 = 256;
6734+ config.matrix_r1c2 = 0;
6735+ config.matrix_r2c0 = 0;
6736+ config.matrix_r2c1 = 0;
6737+ config.matrix_r2c2 = 256;
6738+ config.output_bias_0 = 16;
6739+ config.output_bias_1 = 128;
6740+ config.output_bias_2 = 128;
6741+ config.input_bias_0 = 16;
6742+ config.input_bias_1 = 128;
6743+ config.input_bias_2 = 128;
6744+ config.mean_chn_0 = 104;
6745+ config.mean_chn_1 = 117;
6746+ config.mean_chn_2 = 123;
6747+ config.mean_chn_3 = 0;
6748+ config.min_chn_0 = 0.0F;
6749+ config.min_chn_1 = 0.0F;
6750+ config.min_chn_2 = 0.0F;
6751+ config.min_chn_3 = 0.0F;
6752+ config.var_reci_chn_0 = 0.003921F;
6753+ config.var_reci_chn_1 = 0.003921F;
6754+ config.var_reci_chn_2 = 0.003921F;
6755+ config.var_reci_chn_3 = 1.0F;
6756+ config.support_rotation = 0;
6757+ config.related_input_rank = 0U;
6758+ config.max_src_image_size = 8192U;
6759+ 
6760+ aclAippInfo aipp_info{};
6761+ (void)memset(&aipp_info, 0, sizeof(aipp_info));
6762+ acl::SetAippInfo(&aipp_info, config);
6763+ 
6764+ // 校验所有关键字段正确映射
6765+ EXPECT_EQ(aipp_info.inputFormat, 2);
6766+ EXPECT_EQ(aipp_info.srcImageSizeW, 640);
6767+ EXPECT_EQ(aipp_info.srcImageSizeH, 480);
6768+ EXPECT_EQ(aipp_info.cropSwitch, 1);
6769+ EXPECT_EQ(aipp_info.loadStartPosW, 10);
6770+ EXPECT_EQ(aipp_info.loadStartPosH, 20);
6771+ EXPECT_EQ(aipp_info.cropSizeW, 224);
6772+ EXPECT_EQ(aipp_info.cropSizeH, 224);
6773+ EXPECT_EQ(aipp_info.resizeSwitch, 1);
6774+ EXPECT_EQ(aipp_info.resizeOutputW, 112);
6775+ EXPECT_EQ(aipp_info.resizeOutputH, 112);
6776+ EXPECT_EQ(aipp_info.paddingSwitch, 1);
6777+ EXPECT_EQ(aipp_info.leftPaddingSize, 3);
6778+ EXPECT_EQ(aipp_info.rightPaddingSize, 4);
6779+ EXPECT_EQ(aipp_info.topPaddingSize, 5);
6780+ EXPECT_EQ(aipp_info.bottomPaddingSize, 6);
6781+ EXPECT_EQ(aipp_info.cscSwitch, 1);
6782+ EXPECT_EQ(aipp_info.rbuvSwapSwitch, 1);
6783+ EXPECT_EQ(aipp_info.axSwapSwitch, 0);
6784+ EXPECT_EQ(aipp_info.singleLineMode, 1);
6785+ EXPECT_EQ(aipp_info.matrixR0C0, 256);
6786+ EXPECT_EQ(aipp_info.matrixR0C1, 0);
6787+ EXPECT_EQ(aipp_info.matrixR0C2, 0);
6788+ EXPECT_EQ(aipp_info.matrixR1C0, 0);
6789+ EXPECT_EQ(aipp_info.matrixR1C1, 256);
6790+ EXPECT_EQ(aipp_info.matrixR1C2, 0);
6791+ EXPECT_EQ(aipp_info.matrixR2C0, 0);
6792+ EXPECT_EQ(aipp_info.matrixR2C1, 0);
6793+ EXPECT_EQ(aipp_info.matrixR2C2, 256);
6794+ EXPECT_EQ(aipp_info.outputBias0, 16);
6795+ EXPECT_EQ(aipp_info.outputBias1, 128);
6796+ EXPECT_EQ(aipp_info.outputBias2, 128);
6797+ EXPECT_EQ(aipp_info.inputBias0, 16);
6798+ EXPECT_EQ(aipp_info.inputBias1, 128);
6799+ EXPECT_EQ(aipp_info.inputBias2, 128);
6800+ EXPECT_EQ(aipp_info.meanChn0, 104);
6801+ EXPECT_EQ(aipp_info.meanChn1, 117);
6802+ EXPECT_EQ(aipp_info.meanChn2, 123);
6803+ EXPECT_EQ(aipp_info.meanChn3, 0);
6804+ EXPECT_FLOAT_EQ(aipp_info.minChn0, 0.0F);
6805+ EXPECT_FLOAT_EQ(aipp_info.minChn1, 0.0F);
6806+ EXPECT_FLOAT_EQ(aipp_info.minChn2, 0.0F);
6807+ EXPECT_FLOAT_EQ(aipp_info.minChn3, 0.0F);
6808+ EXPECT_FLOAT_EQ(aipp_info.varReciChn0, 0.003921F);
6809+ EXPECT_FLOAT_EQ(aipp_info.varReciChn1, 0.003921F);
6810+ EXPECT_FLOAT_EQ(aipp_info.varReciChn2, 0.003921F);
6811+ EXPECT_FLOAT_EQ(aipp_info.varReciChn3, 1.0F);
6812+}
6813+ 
6814+TEST_F(UTEST_ACL_Model, GetNpuArch_RtGetSocSpecFails_ReturnsEmpty) {
6815+ EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtGetSocSpec(testing::_, testing::_, testing::_, testing::_))
6816+ .WillOnce(testing::Return(static_cast<rtError_t>(1)));
6817+ 
6818+ const std::string arch = acl::GetNpuArch();
6819+ EXPECT_TRUE(arch.empty());
6820+}
6821+ 
6822+TEST_F(UTEST_ACL_Model, GetNpuArch_RtGetSocSpecSucceeds_ReturnsArch) {
6823+ const std::string expected_arch = "Davinci200";
6824+ EXPECT_CALL(MockFunctionTest::aclStubInstance(), rtGetSocSpec(testing::_, testing::_, testing::_, testing::_))
6825+ .WillOnce(testing::DoAll(testing::SetArrayArgument<2>(expected_arch.begin(), expected_arch.end()),
6826+ testing::Return(RT_ERROR_NONE)));
6827+ 
6828+ const std::string arch = acl::GetNpuArch();
6829+ EXPECT_EQ(arch, expected_arch);
6830+}
6831+ 
6832+TEST_F(UTEST_ACL_Model, SetIODims_ValidDims_CopiesFieldsCorrectly) {
6833+ ge::InputOutputDims ori_dims;
6834+ ori_dims.name = "test_tensor";
6835+ ori_dims.dim_num = 4U;
6836+ ori_dims.size = 100U;
6837+ ori_dims.dims = {1, 3, 224, 224};
6838+ 
6839+ aclmdlIODims dst_dims{};
6840+ const aclError ret = acl::SetIODims(ori_dims, dst_dims);
6841+ EXPECT_EQ(ret, ACL_SUCCESS);
6842+ 
6843+ EXPECT_EQ(dst_dims.dimCount, 4U);
6844+ EXPECT_EQ(dst_dims.dims[0], 1);
6845+ EXPECT_EQ(dst_dims.dims[1], 3);
6846+ EXPECT_EQ(dst_dims.dims[2], 224);
6847+ EXPECT_EQ(dst_dims.dims[3], 224);
6848+ EXPECT_STREQ(dst_dims.name, "test_tensor");
6849+}
6850+ 
6851+TEST_F(UTEST_ACL_Model, SetIODims_DimsExceedMaxCnt_ReturnsError) {
6852+ ge::InputOutputDims ori_dims;
6853+ ori_dims.name = "overflow_tensor";
6854+ ori_dims.dim_num = 200U;
6855+ // 构造超过 ACL_MAX_DIM_CNT(128) 的 dims
6856+ for (size_t dim_idx = 0U; dim_idx < 129U; ++dim_idx) {
6857+ ori_dims.dims.emplace_back(static_cast<int64_t>(dim_idx));
6858+ }
6859+ ori_dims.size = 0U;
6860+ 
6861+ aclmdlIODims dst_dims{};
6862+ const aclError ret = acl::SetIODims(ori_dims, dst_dims);
6863+ EXPECT_EQ(ret, ACL_ERROR_GE_FAILURE);
6864+}
6865+ 
6866+TEST_F(UTEST_ACL_Model, SetIODims_EmptyName_ReturnsSuccess) {
6867+ ge::InputOutputDims ori_dims;
6868+ ori_dims.name = "";
6869+ ori_dims.dim_num = 2U;
6870+ ori_dims.size = 32U;
6871+ ori_dims.dims = {1, 10};
6872+ 
6873+ aclmdlIODims dst_dims{};
6874+ const aclError ret = acl::SetIODims(ori_dims, dst_dims);
6875+ EXPECT_EQ(ret, ACL_SUCCESS);
6876+ 
6877+ // dims 仍应正确复制
6878+ EXPECT_EQ(dst_dims.dimCount, 2U);
6879+ EXPECT_EQ(dst_dims.dims[0], 1);
6880+ EXPECT_EQ(dst_dims.dims[1], 10);
6881+}
6882+ 
6883+TEST_F(UTEST_ACL_Model, AippInfoDebugString_NullInput_ReturnsEmpty) {
6884+ const std::string result = acl::AippInfoDebugString(nullptr);
6885+ EXPECT_TRUE(result.empty());
6886+}
6887+ 
6888+TEST_F(UTEST_ACL_Model, AippInfoDebugString_ValidInput_ContainsKeyFields) {
6889+ aclAippInfo aipp_info{};
6890+ aipp_info.inputFormat = static_cast<aclAippInputFormat>(2);
6891+ aipp_info.srcImageSizeW = 640;
6892+ aipp_info.srcImageSizeH = 480;
6893+ aipp_info.cropSwitch = 1;
6894+ aipp_info.srcFormat = ACL_FORMAT_NCHW;
6895+ aipp_info.srcDatatype = ACL_FLOAT;
6896+ 
6897+ const std::string result = acl::AippInfoDebugString(&aipp_info);
6898+ EXPECT_FALSE(result.empty());
6899+ EXPECT_NE(result.find("aclAippInfo"), std::string::npos);
6900+ EXPECT_NE(result.find("inputFormat:2"), std::string::npos);
6901+ EXPECT_NE(result.find("srcImageSizeW:640"), std::string::npos);
6902+ EXPECT_NE(result.find("srcImageSizeH:480"), std::string::npos);
6903+ EXPECT_NE(result.find("cropSwitch:1"), std::string::npos);
6904+}
6905+ 
6906+TEST_F(UTEST_ACL_Model, DimsDebugString_ValidInput_ContainsTensorName) {
6907+ aclmdlIODims io_dims{};
6908+ io_dims.dimCount = 3U;
6909+ io_dims.dims[0] = 1;
6910+ io_dims.dims[1] = 512;
6911+ io_dims.dims[2] = 512;
6912+ (void)snprintf(io_dims.name, sizeof(io_dims.name), "%s", "input_0");
6913+ 
6914+ const std::string result = acl::DimsDebugString(io_dims);
6915+ EXPECT_FALSE(result.empty());
6916+ EXPECT_NE(result.find("tensorName:input_0"), std::string::npos);
6917+ EXPECT_NE(result.find("dimcount:3"), std::string::npos);
6918+ EXPECT_NE(result.find("1"), std::string::npos);
6919+ EXPECT_NE(result.find("512"), std::string::npos);
6920+}
6921+ 
6922+TEST_F(UTEST_ACL_Model, AippDimsDebugString_NullInput_ReturnsEmpty) {
6923+ const std::string result = acl::AippDimsDebugString(nullptr, 1U);
6924+ EXPECT_TRUE(result.empty());
6925+}
6926+ 
6927+TEST_F(UTEST_ACL_Model, AippDimsDebugString_ValidInput_FormatsMultipleItems) {
6928+ aclAippDims aipp_dims[2]{};
6929+ aipp_dims[0].srcDims.dimCount = 3U;
6930+ aipp_dims[0].srcDims.dims[0] = 1;
6931+ aipp_dims[0].srcDims.dims[1] = 3;
6932+ aipp_dims[0].srcDims.dims[2] = 224;
6933+ aipp_dims[0].srcSize = 100U;
6934+ aipp_dims[0].aippOutdims.dimCount = 3U;
6935+ aipp_dims[0].aippOutdims.dims[0] = 1;
6936+ aipp_dims[0].aippOutdims.dims[1] = 3;
6937+ aipp_dims[0].aippOutdims.dims[2] = 224;
6938+ aipp_dims[0].aippOutSize = 100U;
6939+ 
6940+ aipp_dims[1].srcDims.dimCount = 3U;
6941+ aipp_dims[1].srcDims.dims[0] = 1;
6942+ aipp_dims[1].srcDims.dims[1] = 3;
6943+ aipp_dims[1].srcDims.dims[2] = 448;
6944+ aipp_dims[1].srcSize = 200U;
6945+ aipp_dims[1].aippOutdims.dimCount = 3U;
6946+ aipp_dims[1].aippOutdims.dims[0] = 1;
6947+ aipp_dims[1].aippOutdims.dims[1] = 3;
6948+ aipp_dims[1].aippOutdims.dims[2] = 448;
6949+ aipp_dims[1].aippOutSize = 200U;
6950+ 
6951+ const std::string result = acl::AippDimsDebugString(aipp_dims, 2U);
6952+ EXPECT_FALSE(result.empty());
6953+ // 包含两个 aclAippDims 条目
6954+ EXPECT_NE(result.find("aclAippDims[0]"), std::string::npos);
6955+ EXPECT_NE(result.find("aclAippDims[1]"), std::string::npos);
6956+ EXPECT_NE(result.find("srcSize:100"), std::string::npos);
6957+ EXPECT_NE(result.find("srcSize:200"), std::string::npos);
6958+ EXPECT_NE(result.find("aippOutSize:100"), std::string::npos);
6959+ EXPECT_NE(result.find("aippOutSize:200"), std::string::npos);
6960+}
6961+ 
6962+TEST_F(UTEST_ACL_Model, AippParmsDebugString_ValidInput_ContainsKeyFields) {
6963+ kAippDynamicPara aipp_parms{};
6964+ aipp_parms.inputFormat = 2U;
6965+ aipp_parms.cscSwitch = 1;
6966+ aipp_parms.rbuvSwapSwitch = 0;
6967+ aipp_parms.axSwapSwitch = 0;
6968+ aipp_parms.batchNum = 1;
6969+ aipp_parms.srcImageSizeW = 640;
6970+ aipp_parms.srcImageSizeH = 480;
6971+ aipp_parms.cscMatrixR0C0 = 256;
6972+ aipp_parms.cscMatrixR1C1 = 256;
6973+ aipp_parms.cscMatrixR2C2 = 256;
6974+ 
6975+ const std::string result = acl::AippParmsDebugString(aipp_parms);
6976+ EXPECT_FALSE(result.empty());
6977+ EXPECT_NE(result.find("kAippDynamicPara"), std::string::npos);
6978+ EXPECT_NE(result.find("inputFormat:2"), std::string::npos);
6979+ EXPECT_NE(result.find("cscSwitch:1"), std::string::npos);
6980+ EXPECT_NE(result.find("srcImageSizeW:640"), std::string::npos);
6981+ EXPECT_NE(result.find("srcImageSizeH:480"), std::string::npos);
6982+}
6983+ 
6984+TEST_F(UTEST_ACL_Model, AippBatchParaDebugString_ValidInput_ContainsKeyFields) {
6985+ kAippDynamicBatchPara batch_para{};
6986+ batch_para.cropSwitch = 1;
6987+ batch_para.cropStartPosW = 10;
6988+ batch_para.cropStartPosH = 20;
6989+ batch_para.cropSizeW = 224;
6990+ batch_para.cropSizeH = 224;
6991+ batch_para.scfSwitch = 1;
6992+ batch_para.scfInputSizeW = 224;
6993+ batch_para.scfInputSizeH = 224;
6994+ batch_para.scfOutputSizeW = 112;
6995+ batch_para.scfOutputSizeH = 112;
6996+ batch_para.paddingSwitch = 1;
6997+ batch_para.paddingSizeTop = 5;
6998+ batch_para.paddingSizeBottom = 5;
6999+ batch_para.paddingSizeLeft = 5;
7000+ batch_para.paddingSizeRight = 5;
7001+ 
7002+ const std::string result = acl::AippBatchParaDebugString(batch_para);
7003+ EXPECT_FALSE(result.empty());
7004+ EXPECT_NE(result.find("kAippDynamicBatchPara"), std::string::npos);
7005+ EXPECT_NE(result.find("cropSwitch:1"), std::string::npos);
7006+ EXPECT_NE(result.find("cropSizeW:224"), std::string::npos);
7007+ EXPECT_NE(result.find("cropSizeH:224"), std::string::npos);
7008+}
7009+ 
6670// ============================================================================7010// ============================================================================
6671// Additional ACL Interface Test Cases - Boundary Conditions7011// Additional ACL Interface Test Cases - Boundary Conditions
6672// ============================================================================7012// ============================================================================
@@ -199,12 +199,12 @@ TEST_F(AippSTest, StaticAipp_Config_Invalid) {
199 ASSERT_NE(ret, SUCCESS);199 ASSERT_NE(ret, SUCCESS);
200}200}
201 201 
202-TEST_F(AippSTest, Om2Mode_DynamicAipp_Rejected) {202+TEST_F(AippSTest, Om2Mode_DynamicAipp_NotRejected) {
203 auto path = ModelFactory::GenerateModel_1();203 auto path = ModelFactory::GenerateModel_1();
204 std::string model_arg = "--model=" + path;204 std::string model_arg = "--model=" + path;
205 auto om_path = PathJoin(GetRunPath().c_str(), "temp");205 auto om_path = PathJoin(GetRunPath().c_str(), "temp");
206 Mkdir(om_path.c_str());206 Mkdir(om_path.c_str());
207- om_path = PathJoin(om_path.c_str(), "om2_dynamic_aipp_rejected");207+ om_path = PathJoin(om_path.c_str(), "om2_dynamic_aipp_not_rejected");
208 std::string output_arg = "--output=" + om_path;208 std::string output_arg = "--output=" + om_path;
209 209 
210 std::string conf_path = GetAirPath() + "/tests/ge/st/config_file/aipp_conf/aipp_dynamic.cfg";210 std::string conf_path = GetAirPath() + "/tests/ge/st/config_file/aipp_conf/aipp_dynamic.cfg";
@@ -223,7 +223,7 @@ TEST_F(AippSTest, Om2Mode_DynamicAipp_Rejected) {
223 "--output_type=FP32",223 "--output_type=FP32",
224 };224 };
225 auto ret = main_impl(sizeof(argv) / sizeof(argv[0]), argv);225 auto ret = main_impl(sizeof(argv) / sizeof(argv[0]), argv);
226- EXPECT_NE(ret, 0); // dynamic AIPP must be rejected in OM2 mode226+ (void)ret;
227 ReInitGe();227 ReInitGe();
228}228}
229 229 
@@ -250,11 +250,6 @@ TEST_F(AippSTest, Om2Mode_StaticAipp_ValidatePasses) {
250 "--input_format=NCHW",250 "--input_format=NCHW",
251 "--output_type=FP32",251 "--output_type=FP32",
252 };252 };
253- // ValidateStaticAippOnly should pass (static config). The build may fail later
254- // due to the simplified test env, but the key paths are covered:
255- // - main_impl.cc: if-block entered, ValidateStaticAippOnly returns SUCCESS
256- // - ge_ir_build.cc: ValidateStaticAippOnly called via aclgrphBuildModel
257- // - insert_aipp_op_util.cc: ValidateStaticAippOnly success path
258 auto ret = main_impl(sizeof(argv) / sizeof(argv[0]), argv);253 auto ret = main_impl(sizeof(argv) / sizeof(argv[0]), argv);
259 (void)ret; // result depends on env completeness; coverage is the goal254 (void)ret; // result depends on env completeness; coverage is the goal
260 ReInitGe();255 ReInitGe();
@@ -3140,34 +3140,6 @@ TEST_F(AtcCommonSTest, GeFlags_raw_ge_options_om2_unsupported_option_failed) {
3140 ReInitGe();3140 ReInitGe();
3141}3141}
3142 3142 
3143-TEST_F(AtcCommonSTest, GeFlags_om2_dynamic_aipp_rejected) {
3144- const auto cfg_path = WriteAippConfig("om2_dynamic_aipp.cfg", "dynamic");
3145- auto om_path = PathJoin(GetRunPath().c_str(), "temp");
3146- Mkdir(om_path.c_str());
3147- om_path = PathJoin(om_path.c_str(), "om2_dynamic_aipp_rejected");
3148- std::string model_arg = "--model=st_run_data/origin_model/add.pb";
3149- std::string output_arg = "--output=" + om_path;
3150- std::string insert_conf_arg = "--insert_op_conf=" + cfg_path;
3151- char *argv[] = {"atc",
3152- const_cast<char *>(model_arg.c_str()),
3153- const_cast<char *>(output_arg.c_str()),
3154- "--framework=3",
3155- "--mode=7",
3156- "--soc_version=Ascend310",
3157- "--input_format=NCHW",
3158- "--input_shape=Placeholder_1:1,256,256,3",
3159- const_cast<char *>(insert_conf_arg.c_str())};
3160- int32_t ret = main_impl(sizeof(argv) / sizeof(argv[0]), argv);
3161- EXPECT_NE(ret, 0);
3162- ReInitGe();
3163-}
3164- 
3165-TEST_F(AtcCommonSTest, GeFlags_om2_static_aipp_validate_passes) {
3166- EXPECT_EQ(InsertAippOpUtil::ValidateStaticAippOnly(""), SUCCESS);
3167- const auto cfg_path = WriteAippConfig("om2_static_aipp.cfg", "static");
3168- EXPECT_EQ(InsertAippOpUtil::ValidateStaticAippOnly(cfg_path), SUCCESS);
3169-}
3170- 
3171TEST_F(AtcCommonSTest, GeFlags_param_static_model_ops_lower_limit_invalid) {3143TEST_F(AtcCommonSTest, GeFlags_param_static_model_ops_lower_limit_invalid) {
3172 auto om_path = PathJoin(GetRunPath().c_str(), "temp");3144 auto om_path = PathJoin(GetRunPath().c_str(), "temp");
3173 Mkdir(om_path.c_str());3145 Mkdir(om_path.c_str());
@@ -74,18 +74,6 @@ graphStatus StubInferFunction(Operator &op) {
74 return GRAPH_SUCCESS;74 return GRAPH_SUCCESS;
75}75}
76 76 
77-std::string WriteDynamicAippConfig() {
78- const std::string cfg_path = "om2_dynamic_aipp_build.cfg";
79- std::ofstream cfg_file(cfg_path);
80- cfg_file << "aipp_op {\n"
81- << " aipp_mode: dynamic\n"
82- << " related_input_rank: 0\n"
83- << " max_src_image_size: 752640\n"
84- << " input_format: RGB888_U8\n"
85- << " csc_switch: false\n"
86- << "}\n";
87- return cfg_path;
88-}
89class ScopedGraphOptions {77class ScopedGraphOptions {
90 public:78 public:
91 explicit ScopedGraphOptions(const std::map<std::string, std::string> &options)79 explicit ScopedGraphOptions(const std::map<std::string, std::string> &options)
@@ -480,22 +468,6 @@ TEST_F(GeIrBuildTest, TestBuildModelOm2UnsupportedGlobalOption) {
480 aclgrphBuildFinalize();468 aclgrphBuildFinalize();
481}469}
482 470 
483-TEST_F(GeIrBuildTest, TestBuildModelOm2DynamicAippRejected) {
484- aclgrphBuildFinalize();
485- std::map<std::string, std::string> init_options;
486- ASSERT_EQ(aclgrphBuildInitialize(init_options), SUCCESS);
487- 
488- auto graph = GraphFactory::SingeOpGraph2();
489- const auto cfg_path = WriteDynamicAippConfig();
490- const std::map<std::string, std::string> build_options = {
491- {"ge.offlineMode", "7"},
492- {ge::ir_option::INSERT_OP_FILE, cfg_path},
493- };
494- ModelBufferData model_buffer_data;
495- EXPECT_EQ(aclgrphBuildModel(graph, build_options, model_buffer_data), PARAM_INVALID);
496- aclgrphBuildFinalize();
497-}
498- 
499TEST_F(GeIrBuildTest, TestDumpGraph) {471TEST_F(GeIrBuildTest, TestDumpGraph) {
500 auto graph = GraphFactory::SingeOpGraph2();472 auto graph = GraphFactory::SingeOpGraph2();
501 std::string file_path = "dump.bin";473 std::string file_path = "dump.bin";
@@ -42,6 +42,7 @@
42#include "graph/utils/graph_utils_ex.h"42#include "graph/utils/graph_utils_ex.h"
43#include "graph_metadef/depends/checker/tensor_check_utils.h"43#include "graph_metadef/depends/checker/tensor_check_utils.h"
44#include "proto/ge_ir.pb.h"44#include "proto/ge_ir.pb.h"
45+#include "proto/insert_op.pb.h"
45 46 
46#include "graph/ge_local_context.h"47#include "graph/ge_local_context.h"
47#include "ge_runtime_stub/include/common/share_graph.h"48#include "ge_runtime_stub/include/common/share_graph.h"
@@ -2851,4 +2852,379 @@ TEST_F(Om2St, CrossCompileDevlibMissing_Rejected) {
2851 EXPECT_NE(SaveAicoreOm2WithGraphOptions(test_work_dir, options, "cross_devlib_missing.om2"), SUCCESS);2852 EXPECT_NE(SaveAicoreOm2WithGraphOptions(test_work_dir, options, "cross_devlib_missing.om2"), SUCCESS);
2852}2853}
2853 2854 
2855+// ============================================================================
2856+// OM2 AIPP System Tests - 编译期 AIPP 元数据序列化为 model_meta.json
2857+// ============================================================================
2858+ 
2859+TEST_F(Om2St, ConvertOm2Model_WithStaticAipp_WritesAippMetaToJson) {
2860+ // 构造带静态 AIPP 属性的计算图
2861+ auto graph = gert::ShareGraph::AicoreStaticGraph();
2862+ graph->TopologicalSorting();
2863+ 
2864+ // 在第一个 DATA 节点上添加静态 AIPP 属性
2865+ for (const auto &node : graph->GetDirectNode()) {
2866+ auto op_desc = node->GetOpDesc();
2867+ if ((op_desc != nullptr) && (op_desc->GetType() == DATA)) {
2868+ ge::NamedAttrs aipp_attr;
2869+ aipp_attr.SetAttr("aipp_mode", ge::GeAttrValue::CreateFrom<int64_t>(domi::AippOpParams_AippMode_static_));
2870+ aipp_attr.SetAttr("input_format", ge::GeAttrValue::CreateFrom<int64_t>(0));
2871+ aipp_attr.SetAttr("src_image_size_w", ge::GeAttrValue::CreateFrom<int64_t>(640));
2872+ aipp_attr.SetAttr("src_image_size_h", ge::GeAttrValue::CreateFrom<int64_t>(480));
2873+ aipp_attr.SetAttr("crop", ge::GeAttrValue::CreateFrom<int64_t>(0));
2874+ aipp_attr.SetAttr("load_start_pos_w", ge::GeAttrValue::CreateFrom<int64_t>(0));
2875+ aipp_attr.SetAttr("load_start_pos_h", ge::GeAttrValue::CreateFrom<int64_t>(0));
2876+ aipp_attr.SetAttr("crop_size_w", ge::GeAttrValue::CreateFrom<int64_t>(0));
2877+ aipp_attr.SetAttr("crop_size_h", ge::GeAttrValue::CreateFrom<int64_t>(0));
2878+ aipp_attr.SetAttr("resize", ge::GeAttrValue::CreateFrom<int64_t>(0));
2879+ aipp_attr.SetAttr("resize_output_w", ge::GeAttrValue::CreateFrom<int64_t>(0));
2880+ aipp_attr.SetAttr("resize_output_h", ge::GeAttrValue::CreateFrom<int64_t>(0));
2881+ aipp_attr.SetAttr("padding", ge::GeAttrValue::CreateFrom<int64_t>(0));
2882+ aipp_attr.SetAttr("left_padding_size", ge::GeAttrValue::CreateFrom<int64_t>(0));
2883+ aipp_attr.SetAttr("right_padding_size", ge::GeAttrValue::CreateFrom<int64_t>(0));
2884+ aipp_attr.SetAttr("top_padding_size", ge::GeAttrValue::CreateFrom<int64_t>(0));
2885+ aipp_attr.SetAttr("bottom_padding_size", ge::GeAttrValue::CreateFrom<int64_t>(0));
2886+ aipp_attr.SetAttr("csc_switch", ge::GeAttrValue::CreateFrom<int64_t>(1));
2887+ aipp_attr.SetAttr("rbuv_swap_switch", ge::GeAttrValue::CreateFrom<int64_t>(0));
2888+ aipp_attr.SetAttr("ax_swap_switch", ge::GeAttrValue::CreateFrom<int64_t>(0));
2889+ aipp_attr.SetAttr("single_line_mode", ge::GeAttrValue::CreateFrom<int64_t>(0));
2890+ aipp_attr.SetAttr("related_input_rank", ge::GeAttrValue::CreateFrom<int64_t>(0));
2891+ aipp_attr.SetAttr("max_src_image_size", ge::GeAttrValue::CreateFrom<int64_t>(8192));
2892+ aipp_attr.SetAttr("support_rotation", ge::GeAttrValue::CreateFrom<int64_t>(0));
2893+ (void)ge::AttrUtils::SetNamedAttrs(op_desc, ge::ATTR_NAME_AIPP, aipp_attr);
2894+ (void)ge::AttrUtils::SetStr(op_desc, ge::ATTR_DATA_RELATED_AIPP_MODE, "static_aipp");
2895+ (void)ge::AttrUtils::SetInt(op_desc, ge::ATTR_NAME_INDEX, 0);
2896+ 
2897+ std::vector<std::string> aipp_inputs = {"NCHW:DT_FLOAT:data_0:100:4:1,3,640,480"};
2898+ (void)ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_AIPP_INPUTS, aipp_inputs);
2899+ std::vector<std::string> aipp_outputs = {"NCHW:DT_FLOAT:data_0_out:200:4:1,3,640,480"};
2900+ (void)ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_AIPP_OUTPUTS, aipp_outputs);
2901+ break;
2902+ }
2903+ }
2904+ 
2905+ // 构建 GeRootModel
2906+ gert::GeModelBuilder builder(graph);
2907+ auto ge_root_model =
2908+ builder
2909+ .AddTaskDef("Add",
2910+ gert::AiCoreTaskDefFaker("add_stub").ArgsFormat("{i_instance0*}{i_instance1*}{o_instance0*}"))
2911+ .FakeTbeBin({"Add"})
2912+ .BuildGeRootModel();
2913+ ASSERT_NE(ge_root_model, nullptr);
2914+ auto &compute_graph = ge_root_model->GetRootGraph();
2915+ compute_graph->SetGraphUnknownFlag(false);
2916+ 
2917+ for (const auto &node : compute_graph->GetDirectNode()) {
2918+ auto op_desc = node->GetOpDesc();
2919+ ASSERT_NE(op_desc, nullptr);
2920+ if ((op_desc->GetType() == DATA)) {
2921+ op_desc->SetOutputOffset({1024});
2922+ } else if (op_desc->GetType() == NETOUTPUT) {
2923+ op_desc->SetInputOffset({3072});
2924+ } else {
2925+ op_desc->SetInputOffset(std::vector<int64_t>(op_desc->GetInputsSize(), 1024));
2926+ op_desc->SetOutputOffset(std::vector<int64_t>(op_desc->GetOutputsSize(), 1024));
2927+ if (op_desc->GetType() == "Add") {
2928+ op_desc->SetIsInputConst({true, true});
2929+ auto input_desc0 = op_desc->MutableInputDesc(0);
2930+ auto input_desc1 = op_desc->MutableInputDesc(1);
2931+ if ((input_desc0 == nullptr) || (input_desc1 == nullptr)) {
2932+ ASSERT_TRUE(false) << "MutableInputDesc returned nullptr";
2933+ }
2934+ TensorUtils::SetDataOffset(*input_desc0, 0);
2935+ TensorUtils::SetDataOffset(*input_desc1, 200704);
2936+ }
2937+ }
2938+ }
2939+ 
2940+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
2941+ ASSERT_NE(ge_model, nullptr);
2942+ std::vector<uint8_t> weights_value(401408, 1U);
2943+ const size_t weight_size = weights_value.size();
2944+ ge_model->SetWeight(Buffer::CopyFrom(weights_value.data(), weight_size));
2945+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 2048);
2946+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_WEIGHT_SIZE, weight_size);
2947+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);
2948+ 
2949+ // 保存为 OM2 并验证 aipp 字段被正确写入 model_meta.json
2950+ Om2PackageHelper om2_packager;
2951+ ModelBufferData model_buffer;
2952+ const std::string output_file = PathUtils::Join({test_work_dir, kZipFileBaseName + "_aipp.om2"});
2953+ SyncKernelNameForAllModels(ge_root_model);
2954+ ASSERT_EQ(om2_packager.SaveToOmRootModel(ge_root_model, output_file, model_buffer, false), SUCCESS);
2955+ ASSERT_EQ(mmAccess2(output_file.c_str(), M_F_OK), EOK);
2956+ 
2957+ uint32_t model_buf_size = 0U;
2958+ const auto model_buf = GetBinDataFromFile(output_file, model_buf_size);
2959+ ASSERT_NE(model_buf, nullptr);
2960+ ASSERT_GT(model_buf_size, 0U);
2961+ 
2962+ RAIIZipArchive archive(reinterpret_cast<const uint8_t *>(model_buf.get()), model_buf_size);
2963+ ASSERT_TRUE(archive.IsGood());
2964+ 
2965+ size_t model_meta_size = 0U;
2966+ const std::string aipp_meta_path = kZipFileBaseName + "_aipp/data/model_0/model_meta.json";
2967+ const auto model_meta_buf = archive.ExtractToMem(aipp_meta_path, model_meta_size);
2968+ ASSERT_NE(model_meta_buf, nullptr);
2969+ ASSERT_GT(model_meta_size, 0U);
2970+ 
2971+ const std::string model_meta_json(reinterpret_cast<const char *>(model_meta_buf.get()), model_meta_size);
2972+ // 验证 SaveToOmRootModel 全流程:含 AIPP 属性的模型保存不崩溃
2973+ EXPECT_FALSE(model_meta_json.empty());
2974+ SUCCEED();
2975+}
2976+ 
2977+TEST_F(Om2St, ConvertOm2Model_WithoutAipp_HasNoAippSection) {
2978+ // 无 AIPP 属性的模型不应包含 aipp 字段
2979+ auto graph = gert::ShareGraph::AicoreStaticGraph();
2980+ graph->TopologicalSorting();
2981+ gert::GeModelBuilder builder(graph);
2982+ auto ge_root_model =
2983+ builder
2984+ .AddTaskDef("Add",
2985+ gert::AiCoreTaskDefFaker("add_stub").ArgsFormat("{i_instance0*}{i_instance1*}{o_instance0*}"))
2986+ .FakeTbeBin({"Add"})
2987+ .BuildGeRootModel();
2988+ ASSERT_NE(ge_root_model, nullptr);
2989+ auto &compute_graph = ge_root_model->GetRootGraph();
2990+ compute_graph->SetGraphUnknownFlag(false);
2991+ 
2992+ for (const auto &node : compute_graph->GetDirectNode()) {
2993+ auto op_desc = node->GetOpDesc();
2994+ ASSERT_NE(op_desc, nullptr);
2995+ if ((op_desc->GetType() == DATA)) {
2996+ op_desc->SetOutputOffset({1024});
2997+ } else if (op_desc->GetType() == NETOUTPUT) {
2998+ op_desc->SetInputOffset({3072});
2999+ } else {
3000+ op_desc->SetInputOffset(std::vector<int64_t>(op_desc->GetInputsSize(), 1024));
3001+ op_desc->SetOutputOffset(std::vector<int64_t>(op_desc->GetOutputsSize(), 1024));
3002+ }
3003+ }
3004+ 
3005+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
3006+ ASSERT_NE(ge_model, nullptr);
3007+ std::vector<uint8_t> weights_value(512, 1U);
3008+ ge_model->SetWeight(Buffer::CopyFrom(weights_value.data(), weights_value.size()));
3009+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 2048);
3010+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_WEIGHT_SIZE, weights_value.size());
3011+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);
3012+ 
3013+ Om2PackageHelper om2_packager;
3014+ ModelBufferData model_buffer;
3015+ const std::string output_file = PathUtils::Join({test_work_dir, "no_aipp.om2"});
3016+ SyncKernelNameForAllModels(ge_root_model);
3017+ ASSERT_EQ(om2_packager.SaveToOmRootModel(ge_root_model, output_file, model_buffer, false), SUCCESS);
3018+ 
3019+ uint32_t model_buf_size = 0U;
3020+ const auto model_buf = GetBinDataFromFile(output_file, model_buf_size);
3021+ ASSERT_NE(model_buf, nullptr);
3022+ 
3023+ RAIIZipArchive archive(reinterpret_cast<const uint8_t *>(model_buf.get()), model_buf_size);
3024+ ASSERT_TRUE(archive.IsGood());
3025+ 
3026+ size_t model_meta_size = 0U;
3027+ const std::string noaipp_meta_path = "no_aipp/data/model_0/model_meta.json";
3028+ const auto model_meta_buf = archive.ExtractToMem(noaipp_meta_path, model_meta_size);
3029+ ASSERT_NE(model_meta_buf, nullptr);
3030+ ASSERT_GT(model_meta_size, 0U);
3031+ 
3032+ const std::string model_meta_json(reinterpret_cast<const char *>(model_meta_buf.get()), model_meta_size);
3033+ // 无 AIPP 属性时不应出现 aipp 字段
3034+ EXPECT_EQ(model_meta_json.find("\"aipp\""), std::string::npos) << "aipp section should NOT exist in model_meta.json";
3035+}
3036+ 
3037+// 创建带指定 AIPP mode 的模型,用于 SaveModelInfo 分支覆盖
3038+static GeRootModelPtr CreateGeRootModelWithAippMode(const std::string &aipp_mode, bool set_aipp_attr = true,
3039+ const std::string &data_name = "") {
3040+ auto graph = gert::ShareGraph::AicoreStaticGraph();
3041+ graph->TopologicalSorting();
3042+ for (const auto &node : graph->GetDirectNode()) {
3043+ auto op_desc = node->GetOpDesc();
3044+ if ((op_desc != nullptr) && (op_desc->GetType() == DATA)) {
3045+ (void)ge::AttrUtils::SetStr(op_desc, ge::ATTR_DATA_RELATED_AIPP_MODE, aipp_mode);
3046+ (void)ge::AttrUtils::SetInt(op_desc, ge::ATTR_NAME_INDEX, 0);
3047+ if (!data_name.empty()) {
3048+ (void)ge::AttrUtils::SetStr(op_desc, ge::ATTR_DATA_AIPP_DATA_NAME_MAP, data_name);
3049+ }
3050+ if (set_aipp_attr) {
3051+ ge::NamedAttrs aipp_attr;
3052+ aipp_attr.SetAttr("aipp_mode", ge::GeAttrValue::CreateFrom<int64_t>(0));
3053+ aipp_attr.SetAttr("input_format", ge::GeAttrValue::CreateFrom<int64_t>(0));
3054+ aipp_attr.SetAttr("src_image_size_w", ge::GeAttrValue::CreateFrom<int64_t>(640));
3055+ aipp_attr.SetAttr("src_image_size_h", ge::GeAttrValue::CreateFrom<int64_t>(480));
3056+ aipp_attr.SetAttr("support_rotation", ge::GeAttrValue::CreateFrom<int64_t>(0));
3057+ (void)ge::AttrUtils::SetNamedAttrs(op_desc, ge::ATTR_NAME_AIPP, aipp_attr);
3058+ }
3059+ break;
3060+ }
3061+ }
3062+ gert::GeModelBuilder builder(graph);
3063+ auto ge_root_model =
3064+ builder
3065+ .AddTaskDef("Add",
3066+ gert::AiCoreTaskDefFaker("add_stub").ArgsFormat("{i_instance0*}{i_instance1*}{o_instance0*}"))
3067+ .FakeTbeBin({"Add"})
3068+ .BuildGeRootModel();
3069+ if (ge_root_model == nullptr) {
3070+ return nullptr;
3071+ }
3072+ auto &compute_graph = ge_root_model->GetRootGraph();
3073+ compute_graph->SetGraphUnknownFlag(false);
3074+ for (const auto &node : compute_graph->GetDirectNode()) {
3075+ auto op_desc = node->GetOpDesc();
3076+ if (op_desc == nullptr) {
3077+ return nullptr;
3078+ }
3079+ if ((op_desc->GetType() == DATA)) {
3080+ op_desc->SetOutputOffset({1024});
3081+ } else if (op_desc->GetType() == NETOUTPUT) {
3082+ op_desc->SetInputOffset({3072});
3083+ } else {
3084+ op_desc->SetInputOffset(std::vector<int64_t>(op_desc->GetInputsSize(), 1024));
3085+ op_desc->SetOutputOffset(std::vector<int64_t>(op_desc->GetOutputsSize(), 1024));
3086+ }
3087+ }
3088+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
3089+ if (ge_model == nullptr) {
3090+ return nullptr;
3091+ }
3092+ std::vector<uint8_t> weights_value(401408, 1U);
3093+ ge_model->SetWeight(Buffer::CopyFrom(weights_value.data(), weights_value.size()));
3094+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 2048);
3095+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);
3096+ return ge_root_model;
3097+}
3098+ 
3099+// 通过 SaveModelInfo 调用 FillAippModelMetaInfo,覆盖 AIPP 函数的 ST 覆盖率
3100+TEST_F(Om2St, SaveModelInfo_WithStaticAipp_WritesAippJson) {
3101+ auto graph = gert::ShareGraph::AicoreStaticGraph();
3102+ graph->TopologicalSorting();
3103+ for (const auto &node : graph->GetDirectNode()) {
3104+ auto op_desc = node->GetOpDesc();
3105+ if ((op_desc != nullptr) && (op_desc->GetType() == DATA)) {
3106+ ge::NamedAttrs aipp_attr;
3107+ aipp_attr.SetAttr("aipp_mode", ge::GeAttrValue::CreateFrom<int64_t>(0));
3108+ aipp_attr.SetAttr("input_format", ge::GeAttrValue::CreateFrom<int64_t>(0));
3109+ aipp_attr.SetAttr("src_image_size_w", ge::GeAttrValue::CreateFrom<int64_t>(640));
3110+ aipp_attr.SetAttr("src_image_size_h", ge::GeAttrValue::CreateFrom<int64_t>(480));
3111+ aipp_attr.SetAttr("support_rotation", ge::GeAttrValue::CreateFrom<int64_t>(0));
3112+ (void)ge::AttrUtils::SetNamedAttrs(op_desc, ge::ATTR_NAME_AIPP, aipp_attr);
3113+ (void)ge::AttrUtils::SetStr(op_desc, ge::ATTR_DATA_RELATED_AIPP_MODE, "static_aipp");
3114+ (void)ge::AttrUtils::SetInt(op_desc, ge::ATTR_NAME_INDEX, 0);
3115+ break;
3116+ }
3117+ }
3118+ 
3119+ gert::GeModelBuilder builder(graph);
3120+ auto ge_root_model =
3121+ builder
3122+ .AddTaskDef("Add",
3123+ gert::AiCoreTaskDefFaker("add_stub").ArgsFormat("{i_instance0*}{i_instance1*}{o_instance0*}"))
3124+ .FakeTbeBin({"Add"})
3125+ .BuildGeRootModel();
3126+ ASSERT_NE(ge_root_model, nullptr);
3127+ auto &compute_graph = ge_root_model->GetRootGraph();
3128+ compute_graph->SetGraphUnknownFlag(false);
3129+ for (const auto &node : compute_graph->GetDirectNode()) {
3130+ auto op_desc = node->GetOpDesc();
3131+ ASSERT_NE(op_desc, nullptr);
3132+ if ((op_desc->GetType() == DATA)) {
3133+ op_desc->SetOutputOffset({1024});
3134+ } else if (op_desc->GetType() == NETOUTPUT) {
3135+ op_desc->SetInputOffset({3072});
3136+ } else {
3137+ op_desc->SetInputOffset(std::vector<int64_t>(op_desc->GetInputsSize(), 1024));
3138+ op_desc->SetOutputOffset(std::vector<int64_t>(op_desc->GetOutputsSize(), 1024));
3139+ }
3140+ }
3141+ 
3142+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
3143+ ASSERT_NE(ge_model, nullptr);
3144+ std::vector<uint8_t> weights_value(401408, 1U);
3145+ ge_model->SetWeight(Buffer::CopyFrom(weights_value.data(), weights_value.size()));
3146+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 2048);
3147+ (void)AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);
3148+ ge_model->GetGraph()->SetParentGraph(std::make_shared<ComputeGraph>("root_g1"));
3149+ 
3150+ const std::string output_file = PathUtils::Join({test_work_dir, "st_smi_aipp.om2"});
3151+ auto zip_writer = std::make_shared<ZipArchiveWriter>(output_file);
3152+ ASSERT_TRUE(zip_writer->IsMemFileOpened());
3153+ SyncKernelNameFromOpDesc(ge_model);
3154+ ASSERT_EQ(Om2PackageHelper::SaveModelInfo(zip_writer, ge_model, 0UL), SUCCESS);
3155+ ASSERT_TRUE(zip_writer->SaveModelDataToFile());
3156+ 
3157+ uint32_t model_buf_size = 0U;
3158+ const auto model_buf = GetBinDataFromFile(output_file, model_buf_size);
3159+ ASSERT_NE(model_buf, nullptr);
3160+ 
3161+ RAIIZipArchive archive(reinterpret_cast<const uint8_t *>(model_buf.get()), model_buf_size);
3162+ ASSERT_TRUE(archive.IsGood());
3163+ size_t model_meta_size = 0U;
3164+ const auto model_meta_buf = archive.ExtractToMem("st_smi_aipp/data/model_0/model_meta.json", model_meta_size);
3165+ ASSERT_NE(model_meta_buf, nullptr);
3166+ const std::string model_meta_json(reinterpret_cast<const char *>(model_meta_buf.get()), model_meta_size);
3167+ EXPECT_FALSE(model_meta_json.empty());
3168+}
3169+ 
3170+// 覆盖 dynamic_aipp 分支
3171+TEST_F(Om2St, SaveModelInfo_DynamicAipp_WritesAippJson) {
3172+ const auto ge_root_model = CreateGeRootModelWithAippMode("dynamic_aipp");
3173+ ASSERT_NE(ge_root_model, nullptr);
3174+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
3175+ ASSERT_NE(ge_model, nullptr);
3176+ ge_model->GetGraph()->SetParentGraph(std::make_shared<ComputeGraph>("root"));
3177+ 
3178+ const std::string output_file = PathUtils::Join({test_work_dir, "st_dyn_aipp.om2"});
3179+ auto zip_writer = std::make_shared<ZipArchiveWriter>(output_file);
3180+ ASSERT_TRUE(zip_writer->IsMemFileOpened());
3181+ SyncKernelNameFromOpDesc(ge_model);
3182+ ASSERT_EQ(Om2PackageHelper::SaveModelInfo(zip_writer, ge_model, 0UL), SUCCESS);
3183+}
3184+ 
3185+// 覆盖 unknown mode 分支
3186+TEST_F(Om2St, SaveModelInfo_UnknownAippMode_Skipped) {
3187+ const auto ge_root_model = CreateGeRootModelWithAippMode("unknown_aipp_mode");
3188+ ASSERT_NE(ge_root_model, nullptr);
3189+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
3190+ ASSERT_NE(ge_model, nullptr);
3191+ ge_model->GetGraph()->SetParentGraph(std::make_shared<ComputeGraph>("root"));
3192+ 
3193+ const std::string output_file = PathUtils::Join({test_work_dir, "st_unknown_aipp.om2"});
3194+ auto zip_writer = std::make_shared<ZipArchiveWriter>(output_file);
3195+ ASSERT_TRUE(zip_writer->IsMemFileOpened());
3196+ SyncKernelNameFromOpDesc(ge_model);
3197+ ASSERT_EQ(Om2PackageHelper::SaveModelInfo(zip_writer, ge_model, 0UL), SUCCESS);
3198+}
3199+ 
3200+// 覆盖缺 ATTR_NAME_AIPP 分支
3201+TEST_F(Om2St, SaveModelInfo_MissingAippAttr_Skipped) {
3202+ const auto ge_root_model = CreateGeRootModelWithAippMode("static_aipp", false);
3203+ ASSERT_NE(ge_root_model, nullptr);
3204+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
3205+ ASSERT_NE(ge_model, nullptr);
3206+ ge_model->GetGraph()->SetParentGraph(std::make_shared<ComputeGraph>("root"));
3207+ 
3208+ const std::string output_file = PathUtils::Join({test_work_dir, "st_missing_aipp.om2"});
3209+ auto zip_writer = std::make_shared<ZipArchiveWriter>(output_file);
3210+ ASSERT_TRUE(zip_writer->IsMemFileOpened());
3211+ SyncKernelNameFromOpDesc(ge_model);
3212+ ASSERT_EQ(Om2PackageHelper::SaveModelInfo(zip_writer, ge_model, 0UL), SUCCESS);
3213+}
3214+ 
3215+// 覆盖 ResolveAippDataIndex found-in-map 分支 (设置 ATTR_DATA_AIPP_DATA_NAME_MAP)
3216+TEST_F(Om2St, SaveModelInfo_WithAippDataNameMap_WritesAippJson) {
3217+ const auto ge_root_model = CreateGeRootModelWithAippMode("static_aipp", true, "data1");
3218+ ASSERT_NE(ge_root_model, nullptr);
3219+ const auto ge_model = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
3220+ ASSERT_NE(ge_model, nullptr);
3221+ ge_model->GetGraph()->SetParentGraph(std::make_shared<ComputeGraph>("root"));
3222+ 
3223+ const std::string output_file = PathUtils::Join({test_work_dir, "st_datamap_aipp.om2"});
3224+ auto zip_writer = std::make_shared<ZipArchiveWriter>(output_file);
3225+ ASSERT_TRUE(zip_writer->IsMemFileOpened());
3226+ SyncKernelNameFromOpDesc(ge_model);
3227+ ASSERT_EQ(Om2PackageHelper::SaveModelInfo(zip_writer, ge_model, 0UL), SUCCESS);
3228+}
3229+ 
2854} // namespace ge3230} // namespace ge