Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 "args_format_constructor.h"
12 : #include "framework/common/framework_types_internal.h"
13 : #include "common/op_tensor_utils.h"
14 : #include "common/platform_utils.h"
15 : #include "common/aicore_util_types.h"
16 : #include "common/aicore_util_attr_define.h"
17 : #include "common/aicore_util_constants.h"
18 : #include "common/fe_op_info_common.h"
19 : #include "graph/debug/ge_attr_define.h"
20 : #include "graph/utils/op_desc_utils.h"
21 : #include "register/graph_optimizer/fusion_common/unknown_shape_utils.h"
22 :
23 : namespace fe {
24 : void ArgsFormatConstructor::AddDynamicDesc(const std::pair<size_t, size_t> &range, size_t ir_index, bool is_input) {
25 : dyn_io_v_.clear();
26 : for (size_t dy_idx = 0; dy_idx < range.second; ++dy_idx) {
27 : if (!is_dy_folded_) {
28 : if (is_input) {
29 : format_desc_.Append(ge::AddrType::INPUT, ir_index);
30 : } else {
31 : format_desc_.Append(ge::AddrType::OUTPUT, ir_index);
32 : }
33 : return;
34 : }
35 : if (dy_idx == 0) {
36 : if (is_input) {
37 : format_desc_.Append(ge::AddrType::INPUT_DESC, ir_index, true);
38 : } else {
39 : format_desc_.Append(ge::AddrType::OUTPUT_DESC, ir_index, true);
40 : }
41 : }
42 : dyn_io_v_.emplace_back(static_cast<int64_t>(range.first + dy_idx));
43 : }
44 : dyn_io_vv_.emplace_back(dyn_io_v_);
45 : }
46 : bool GetInIrIndexByName(const std::vector<std::pair<std::string, ge::IrInputType>> &ir_inputs, const std::string &name,
47 : size_t &ir_index) {
48 : size_t ir_size = ir_inputs.size();
49 : for (size_t i = 0UL; i < ir_size; ++i) {
50 : if (ir_inputs[i].first == name) {
51 : ir_index = i;
52 : return true;
53 : }
54 : }
55 : return false;
56 : }
57 :
58 : bool GetOutIrIndexByName(const std::vector<std::pair<std::string, ge::IrOutputType>> &ir_outputs,
59 : const std::string &name, size_t &ir_index) {
60 : size_t ir_size = ir_outputs.size();
61 : for (size_t i = 0UL; i < ir_size; ++i) {
62 : if (ir_outputs[i].first == name) {
63 : ir_index = i;
64 : return true;
65 : }
66 : }
67 : return false;
68 : }
69 :
70 : bool FindInputInGraph(size_t idx, const std::vector<InputOrOutputInfoPtr> &input_infos,
71 : std::vector<std::string> &input_name_list) {
72 : auto &input_name = input_infos[idx]->GetName();
73 : auto paramType = input_infos[idx]->GetParamType();
74 : if (paramType == REQUIRED || paramType == DYNAMIC) {
75 : return true;
76 : }
77 : auto input_size = input_name_list.size();
78 : for (size_t j = 0; j < input_size; ++j) {
79 : FE_LOGD("Input name [%s].", input_name_list[j].c_str());
80 : if (input_name == input_name_list[j]) {
81 : return true;
82 : }
83 : }
84 : FE_LOGD("Input name [%s] not find, with input size %zu.", input_name.c_str(), input_size);
85 : return false;
86 : }
87 :
88 : bool ArgsFormatConstructor::FindOptInsertPos(size_t ir_idx, const std::vector<InputOrOutputInfoPtr> &input_infos,
89 : std::vector<std::string> &input_name_list, size_t &insert_pos) const {
90 : insert_pos = 0;
91 : if (ir_idx == 0) {
92 : return true;
93 : }
94 : auto &pre_input_name = input_infos[ir_idx - 1]->GetName();
95 : for (size_t j = input_name_list.size(); j > 0; --j) {
96 : if (pre_input_name == input_name_list[j - 1]) {
97 : insert_pos = j;
98 : break;
99 : }
100 : }
101 : if (insert_pos == 0) {
102 : REPORT_FE_ERROR("[ArgsFormatConstructor] Op[name=%s,type=%s]Not find pre input name [%s].",
103 : op_desc_->GetName().c_str(), op_desc_->GetType().c_str(), pre_input_name.c_str());
104 : return false;
105 : }
106 : return true;
107 : }
108 :
109 : bool ArgsFormatConstructor::InsertMissOptInput(std::vector<uint32_t> &input_type_list,
110 : std::vector<int32_t> &input_graph_idx,
111 : std::vector<std::string> &input_name_list, size_t exp_num) const {
112 : int64_t imply_type = -1;
113 : (void)ge::AttrUtils::GetInt(op_desc_, FE_IMPLY_TYPE, imply_type);
114 : OpKernelInfoPtr op_kernel_info_ptr =
115 : OpsKernelManager::Instance(op_desc_->GetOpEngineName())
116 : .GetOpKernelInfoByOpType(static_cast<OpImplType>(imply_type), op_desc_->GetType());
117 : if (op_kernel_info_ptr == nullptr) {
118 : REPORT_FE_ERROR("[ArgsFormatConstructor] Op[name=%s,type=%s] Failed to get kernel info.",
119 : op_desc_->GetName().c_str(), op_desc_->GetType().c_str());
120 : return false;
121 : }
122 : const auto &input_infos = op_kernel_info_ptr->GetAllInputInfo();
123 : std::vector<uint32_t> insert_pos_vec;
124 : for (size_t i = 0; i < input_infos.size(); ++i) {
125 : if (FindInputInGraph(i, input_infos, input_name_list)) {
126 : continue;
127 : }
128 : size_t insert_pos = 0;
129 : if (!FindOptInsertPos(i, input_infos, input_name_list, insert_pos)) {
130 : return false;
131 : }
132 : auto &input_name = input_infos[i]->GetName();
133 : FE_LOGD("Insert miss optional input [%s] at pos[%zu].", input_name.c_str(), insert_pos);
134 : insert_pos_vec.emplace_back(insert_pos);
135 : input_type_list.insert(input_type_list.begin() + insert_pos, static_cast<uint32_t>(OPTIONAL));
136 : input_name_list.insert(input_name_list.begin() + insert_pos, input_name);
137 : input_graph_idx.insert(input_graph_idx.begin() + insert_pos, -1);
138 : }
139 : for (size_t i = 0; i < input_name_list.size(); ++i) {
140 : FE_LOGD("After reconstructing the input name [%s].", input_name_list[i].c_str());
141 : }
142 : if (input_type_list.size() != exp_num) {
143 : REPORT_FE_ERROR("[ArgsFormatConstructor] Op[name=%s,type=%s]In size[%zu] not equal[%zu].",
144 : op_desc_->GetName().c_str(), op_desc_->GetType().c_str(), input_type_list.size(), exp_num);
145 : return false;
146 : }
147 : (void)ge::AttrUtils::SetListInt(op_desc_, kInputParaTypeList, input_type_list);
148 : (void)ge::AttrUtils::SetListStr(op_desc_, kInputNameList, input_name_list);
149 : (void)ge::AttrUtils::SetListInt(op_desc_, kInputInsertOptPosList, insert_pos_vec);
150 : return true;
151 : }
152 :
153 : bool ArgsFormatConstructor::GetOpInputInfo(std::vector<uint32_t> &input_type_list,
154 : std::vector<int32_t> &input_graph_idx,
155 : std::vector<std::string> &input_name_list,
156 : std::map<size_t, std::pair<size_t, size_t>> &ir_input_2_range) {
157 : (void)ge::AttrUtils::GetListInt(op_desc_, kInputParaTypeList, input_type_list);
158 : (void)ge::AttrUtils::GetListStr(op_desc_, kInputNameList, input_name_list);
159 : // (ir index, (input index on graph, range))
160 : if (ge::OpDescUtils::GetIrInputInstanceDescRange(op_desc_, ir_input_2_range) != ge::GRAPH_SUCCESS) {
161 : FE_LOGW("Get ir input range failed.");
162 : return false;
163 : }
164 : size_t input_size = input_name_list.size();
165 : if (input_type_list.size() != input_size) {
166 : FE_LOGW("Input name size[%zu] not equal with type size[%zu].", input_size, input_type_list.size());
167 : return false;
168 : }
169 : for (size_t i = 0; i < input_size; ++i) {
170 : input_graph_idx.emplace_back(i);
171 : }
172 : size_t all_num = 0;
173 : size_t exp_num = 0;
174 : for (const auto &range : ir_input_2_range) {
175 : all_num += range.second.second;
176 : if (range.second.second > 1) {
177 : exp_num += (range.second.second - 1);
178 : }
179 : }
180 : if (all_num > input_size) {
181 : FE_LOGW("Input name size[%zu] less size by ir[%zu].", input_size, all_num);
182 : return false;
183 : }
184 : FE_LOGD("Op[%s] dynamic input expand num is %zu.", op_desc_->GetNamePtr(), exp_num);
185 : (void)ge::AttrUtils::SetInt(op_desc_, kDyInputsAddNum, exp_num);
186 :
187 : size_t ops_in_size = 0;
188 : (void)ge::AttrUtils::GetInt(op_desc_, kOpKernelAllInputSize, ops_in_size);
189 : exp_num += ops_in_size;
190 : FE_LOGD("Op expect input num[%zu] with real[%zu].", exp_num, input_size);
191 : if (!is_input_gen_place_ || (exp_num <= input_size)) {
192 : return true;
193 : }
194 : return InsertMissOptInput(input_type_list, input_graph_idx, input_name_list, exp_num);
195 : }
196 :
197 : Status ArgsFormatConstructor::ConstructInArgsDescByOps(
198 : const std::vector<std::pair<std::string, ge::IrInputType>> &ir_inputs) {
199 : std::vector<uint32_t> input_type_list;
200 : std::vector<int32_t> input_graph_idx;
201 : std::vector<std::string> input_name_list;
202 : std::map<size_t, std::pair<size_t, size_t>> ir_input_2_range;
203 : if (!GetOpInputInfo(input_type_list, input_graph_idx, input_name_list, ir_input_2_range)) {
204 : return FAILED;
205 : }
206 : size_t in_num = input_type_list.size();
207 : size_t dy_ir_idx = 0xFFFF;
208 : size_t ir_index = 0;
209 : for (size_t in_idx = 0; in_idx < in_num; ++in_idx) {
210 : auto input_type = input_type_list[in_idx];
211 : auto &input_name = input_name_list[in_idx];
212 : if (!GetInIrIndexByName(ir_inputs, input_name, ir_index)) {
213 : FE_LOGW("Op[%s] Input name[%s] not found in ir.", op_desc_->GetNamePtr(), input_name.c_str());
214 : return FAILED;
215 : }
216 : FE_CHECK(ir_index >= ir_input_2_range.size(), FE_LOGW("Index [%zu] is out of range.", ir_index), return FAILED);
217 : auto &range = ir_input_2_range[ir_index];
218 : FE_LOGD("Input[%zu]/IR_idx[%zu] with name[%s]/type[%u] and range[%zu/%zu].", in_idx, ir_index, input_name.c_str(),
219 : input_type, range.first, range.second);
220 : if (input_type == static_cast<uint32_t>(OpParamType::REQUIRED)) {
221 : if (range.second == 0) {
222 : FE_LOGW("The required input size for Op [%s, %s] is 0.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr());
223 : return FAILED;
224 : }
225 : format_desc_.Append(ge::AddrType::INPUT, ir_index);
226 : } else if (input_type == static_cast<uint32_t>(OpParamType::OPTIONAL)) {
227 : auto graph_idx = input_graph_idx[in_idx];
228 : bool is_used = (graph_idx != -1 && op_desc_->GetInputDesc(graph_idx).IsValid() == ge::GRAPH_SUCCESS);
229 : FE_LOGD("Ir Input[%u] with graph id [%d] has used flag as %d.", in_idx, graph_idx, is_used);
230 : if (is_used || is_input_gen_place_) {
231 : format_desc_.Append(ge::AddrType::INPUT, ir_index);
232 : }
233 : } else if (input_type == static_cast<uint32_t>(OpParamType::DYNAMIC)) {
234 : if (dy_ir_idx == ir_index) {
235 : continue;
236 : }
237 : dy_ir_idx = ir_index;
238 : if (range.second == 0 || (range.second > in_num)) {
239 : // if dynamic is 0 need gen place holder, here need append INPUT desc
240 : FE_LOGW("Op[%s] Dy Input[%zu] size[%zu] invalid.", op_desc_->GetNamePtr(), ir_index, range.second);
241 : return FAILED;
242 : }
243 : AddDynamicDesc(range, ir_index, true);
244 : } else {
245 : return FAILED;
246 : }
247 : }
248 : if (!dyn_io_vv_.empty()) {
249 : (void)ge::AttrUtils::SetListListInt(op_desc_, kDyInputsIndexes, dyn_io_vv_);
250 : }
251 : return SUCCESS;
252 : }
253 :
254 : void ArgsFormatConstructor::ConstructOptOutputArgs(size_t ir_index) {
255 : auto output_desc_ptr = op_desc_->MutableOutputDesc(ir_index);
256 : if (output_desc_ptr == nullptr) {
257 : return;
258 : }
259 : int32_t calc_type = 0;
260 : (void)ge::AttrUtils::GetInt(output_desc_ptr, ge::ATTR_NAME_MEMORY_SIZE_CALC_TYPE, calc_type);
261 : if (calc_type == static_cast<int32_t>(ge::MemorySizeCalcType::ALWAYS_EMPTY)) {
262 : FE_LOGD("Op[%s:%s] opt output[%zu] mem type empty, is_output_gen_place_[%d]", op_desc_->GetNamePtr(),
263 : op_desc_->GetTypePtr(), ir_index, is_output_gen_place_);
264 : if (is_output_gen_place_) {
265 : format_desc_.Append(ge::AddrType::PLACEHOLDER);
266 : }
267 : return;
268 : }
269 : format_desc_.Append(ge::AddrType::OUTPUT, ir_index);
270 : return;
271 : }
272 :
273 : bool ArgsFormatConstructor::GetOpOutputInfo(std::vector<uint32_t> &output_type_list,
274 : std::vector<std::string> &output_name_list,
275 : std::map<size_t, std::pair<size_t, size_t>> &ir_out_2_range) {
276 : (void)ge::AttrUtils::GetListInt(op_desc_, kOutputParaTypeList, output_type_list);
277 : (void)ge::AttrUtils::GetListStr(op_desc_, kOutputNameList, output_name_list);
278 : if (ge::OpDescUtils::GetIrOutputDescRange(op_desc_, ir_out_2_range) != ge::GRAPH_SUCCESS) {
279 : FE_LOGW("Get ir input range failed.");
280 : return false;
281 : }
282 : if (output_name_list.size() != output_type_list.size()) {
283 : FE_LOGW("Output name size[%zu] not equal with type size[%zu].", output_name_list.size(), output_type_list.size());
284 : return false;
285 : }
286 : size_t all_num = 0;
287 : for (const auto &range : ir_out_2_range) {
288 : all_num += range.second.second;
289 : }
290 : if (all_num > output_name_list.size()) {
291 : FE_LOGW("Output name size [%zu] is smaller than IR size [%zu].", output_name_list.size(), all_num);
292 : return false;
293 : }
294 : return true;
295 : }
296 :
297 : Status ArgsFormatConstructor::ConstructOutArgsDescByOps(
298 : const std::vector<std::pair<std::string, ge::IrOutputType>> &ir_outputs) {
299 : std::vector<uint32_t> output_type_list;
300 : std::vector<std::string> output_name_list;
301 : // (ir index, (input index on graph, range))
302 : std::map<size_t, std::pair<size_t, size_t>> ir_out_2_range;
303 : if (!GetOpOutputInfo(output_type_list, output_name_list, ir_out_2_range)) {
304 : return FAILED;
305 : }
306 : size_t out_num = output_type_list.size();
307 : size_t dy_ir_idx = 0xFFFF;
308 : for (size_t out_idx = 0; out_idx < out_num; ++out_idx) {
309 : auto output_type = output_type_list[out_idx];
310 : auto &output_name = output_name_list[out_idx];
311 : size_t ir_index = 0;
312 : if (!GetOutIrIndexByName(ir_outputs, output_name, ir_index)) {
313 : FE_LOGW("Op[%s,%s] output[%s] not in ir.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr(), output_name.c_str());
314 : return FAILED;
315 : }
316 : FE_CHECK(ir_index >= ir_out_2_range.size(), FE_LOGW("Index [%zu] is out of range.", ir_index), return FAILED);
317 : auto &range = ir_out_2_range[ir_index];
318 : FE_LOGD("Output[%zu]/IR_idx[%zu] with name[%s]/type[%u] and range[%zu/%zu].", out_idx, ir_index,
319 : output_name.c_str(), output_type, range.first, range.second);
320 : if (output_type == static_cast<uint32_t>(OpParamType::REQUIRED)) {
321 : if (range.second == 0) {
322 : FE_LOGW("Op[%s,%s] Output[%zu][%s] not found in ir.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr(), ir_index,
323 : output_name.c_str());
324 : return FAILED;
325 : }
326 : format_desc_.Append(ge::AddrType::OUTPUT, ir_index);
327 : } else if (output_type == static_cast<uint32_t>(OpParamType::DYNAMIC)) {
328 : if (dy_ir_idx == ir_index) {
329 : continue;
330 : }
331 : dy_ir_idx = ir_index;
332 : if (range.second == 0 || (range.second > out_num)) {
333 : // if dynamic is 0 need gen place holder, here need append INPUT desc
334 : FE_LOGW("Op[%s,%s]Dynamic input[%zu] no use.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr(), ir_index);
335 : return FAILED;
336 : }
337 : AddDynamicDesc(range, ir_index, false);
338 : } else if (output_type == static_cast<uint32_t>(OpParamType::OPTIONAL)) {
339 : ConstructOptOutputArgs(ir_index);
340 : } else {
341 : return FAILED;
342 : }
343 : }
344 : if (!dyn_io_vv_.empty()) {
345 : (void)ge::AttrUtils::SetListListInt(op_desc_, kDyOutputsIndexes, dyn_io_vv_);
346 : }
347 : return SUCCESS;
348 : }
349 :
350 : inline bool NeedConstructByIR(const ge::OpDescPtr op_desc, bool is_dy_folded, bool is_gen_place) {
351 : bool ret = (!op_desc->GetIrInputs().empty() || !op_desc->GetIrOutputs().empty()) &&
352 : (!ge::AttrUtils::HasAttr(op_desc, kAttrNameIsFusionOp));
353 : ret &= (is_dy_folded || is_gen_place);
354 : FE_LOGD("Need by ir[%d].", ret);
355 : return ret;
356 : }
357 :
358 : void ArgsFormatConstructor::ConstructArgsDescByGraph() {
359 : format_desc_.Clear();
360 : if (need_sync_) {
361 : FE_LOGD("Add ffts addr arg.");
362 : format_desc_.Append(ge::AddrType::FFTS_ADDR);
363 : }
364 : size_t all_num = op_desc_->GetAllInputsSize();
365 : size_t arg_id = 0;
366 : for (size_t id = 0; id < all_num; ++id) {
367 : bool has_input = (op_desc_->GetInputDescPtr(id) != nullptr);
368 : FE_LOGD("Input[%zu] is used flag:%d.", id, has_input);
369 : if (has_input) {
370 : format_desc_.Append(ge::AddrType::INPUT_INSTANCE, arg_id++);
371 : } else if (is_input_gen_place_) {
372 : format_desc_.Append(ge::AddrType::PLACEHOLDER);
373 : }
374 : }
375 : all_num = op_desc_->GetOutputsSize();
376 : arg_id = 0;
377 : for (size_t id = 0; id < all_num; ++id) {
378 : auto output_desc_ptr = op_desc_->MutableOutputDesc(id);
379 : if (output_desc_ptr == nullptr) {
380 : continue;
381 : }
382 : int32_t calc_type = 0;
383 : (void)ge::AttrUtils::GetInt(output_desc_ptr, ge::ATTR_NAME_MEMORY_SIZE_CALC_TYPE, calc_type);
384 : if (calc_type == static_cast<int32_t>(ge::MemorySizeCalcType::ALWAYS_EMPTY)) {
385 : FE_LOGD("Op[%s:%s] Output[%zu] is always empty, is_output_gen_place_[%d]", op_desc_->GetNamePtr(),
386 : op_desc_->GetTypePtr(), id, is_output_gen_place_);
387 : if (is_output_gen_place_) {
388 : format_desc_.Append(ge::AddrType::PLACEHOLDER);
389 : }
390 : continue;
391 : }
392 : // normal output
393 : format_desc_.Append(ge::AddrType::OUTPUT_INSTANCE, arg_id++);
394 : }
395 : return;
396 : }
397 :
398 : // INPUT_INSTANCE: arg_id represent input edge index in graph
399 : Status ArgsFormatConstructor::ConstructInArgsDesc() {
400 : const auto &ir_inputs = op_desc_->GetIrInputs();
401 : if (by_ir_) {
402 : if (ConstructInArgsDescByOps(ir_inputs) == SUCCESS) {
403 : return SUCCESS;
404 : }
405 : FE_LOGW("Op[%s][%s] cannot be constructed by IR.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr());
406 : by_ir_ = false;
407 : }
408 : if (is_dy_folded_) {
409 : REPORT_FE_ERROR("Node[%s][%s] needs to be dynamically folded but does not have IR.", op_desc_->GetNamePtr(),
410 : op_desc_->GetTypePtr());
411 : return FAILED;
412 : }
413 : return SUCCESS;
414 : }
415 :
416 : Status ArgsFormatConstructor::ConstructOutArgsDesc() {
417 : const auto &ir_outputs = op_desc_->GetIrOutputs();
418 : if (by_ir_) {
419 : if (ConstructOutArgsDescByOps(ir_outputs) == SUCCESS) {
420 : return SUCCESS;
421 : }
422 : FE_LOGW("Op[%s][%s] cannot be constructed by IR.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr());
423 : }
424 : if (is_dy_folded_) {
425 : REPORT_FE_ERROR("Node [%s][%s] needs to be dynamically folded but does not have output IR.", op_desc_->GetNamePtr(),
426 : op_desc_->GetTypePtr());
427 : return FAILED;
428 : }
429 : ConstructArgsDescByGraph();
430 : return SUCCESS;
431 : }
432 :
433 : Status ArgsFormatConstructor::ConstructNodeArgsDesc() {
434 : FE_CHECK_NOTNULL(op_desc_);
435 : std::string dyn_mode;
436 : (void)ge::AttrUtils::GetStr(op_desc_, fe::kAttrDynamicParamMode, dyn_mode);
437 : is_dy_folded_ = (dyn_mode == fe::kFoldedWithDesc);
438 : std::string input_opt_mode;
439 : (void)ge::AttrUtils::GetStr(op_desc_, fe::kAttrOptionalInputMode, input_opt_mode);
440 : is_input_gen_place_ = (input_opt_mode == fe::kGenPlaceholder);
441 : std::string output_opt_mode;
442 : (void)ge::AttrUtils::GetStr(op_desc_, fe::kAttrOptionalOutputMode, output_opt_mode);
443 : is_output_gen_place_ = (output_opt_mode == fe::kGenPlaceholder);
444 : std::string core_type;
445 : (void)ge::AttrUtils::GetStr(op_desc_, ATTR_NAME_CUBE_VECTOR_CORE_TYPE, core_type);
446 : need_sync_ = (core_type == kCoreTypeMixEnhance) && (PlatformUtils::Instance().GetFftsMode() == FFTS_MODE_FFTS_PLUS);
447 : need_sync_ = need_sync_ || (op_desc_->HasAttr(ATTR_NAME_ALIAS_ENGINE_NAME));
448 : if (need_sync_) {
449 : FE_LOGD("Add ffts addr arg.");
450 : format_desc_.Append(ge::AddrType::FFTS_ADDR);
451 : }
452 : by_ir_ = NeedConstructByIR(op_desc_, is_dy_folded_, (is_input_gen_place_ || is_output_gen_place_));
453 : if (ConstructInArgsDesc() != SUCCESS) {
454 : FE_LOGE("Node [%s][%s] failed to in args desc.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr());
455 : return FAILED;
456 : }
457 : dyn_io_v_.clear();
458 : dyn_io_vv_.clear();
459 : if (ConstructOutArgsDesc() != SUCCESS) {
460 : FE_LOGE("Node[%s][%s] construct out args desc failed.", op_desc_->GetNamePtr(), op_desc_->GetTypePtr());
461 : return FAILED;
462 : }
463 : auto tiling_type = is_ffts_plus_ ? ge::AddrType::TILING_FFTS : ge::AddrType::TILING;
464 : if (fe::UnknownShapeUtils::IsUnknownShapeOp(*op_desc_)) {
465 : format_desc_.Append(ge::AddrType::WORKSPACE);
466 : format_desc_.Append(tiling_type);
467 : } else {
468 : auto work_size = op_desc_->GetWorkspaceBytes().size();
469 : std::vector<uint32_t> aicpu_workspace_type;
470 : ge::AttrUtils::GetListInt(op_desc_, ge::ATTR_NAME_AICPU_WORKSPACE_TYPE, aicpu_workspace_type);
471 : for (size_t i = 0; i < work_size; ++i) {
472 : if ((IsCustomOp(*op_desc_) || IsPrefixOpsPath(*op_desc_)) && work_size == aicpu_workspace_type.size() &&
473 : aicpu_workspace_type[i] == ge::AicpuWorkSpaceType::CUST_LOG) {
474 : FE_LOGI("Node[%s][%s] custom op tiling sink remove CUST_LOG workspace[%zu]", op_desc_->GetNamePtr(),
475 : op_desc_->GetTypePtr(), i);
476 : continue;
477 : }
478 : format_desc_.Append(ge::AddrType::WORKSPACE, i);
479 : }
480 : if (fe::OpTensorUtils::IsStaticReuseBinaryOp(op_desc_)) {
481 : format_desc_.Append(tiling_type);
482 : }
483 : }
484 : if (!is_ffts_plus_ && ge::AttrUtils::HasAttr(op_desc_, ge::GLOBALWORKSPACE_TYPE)) {
485 : format_desc_.Append(ge::AddrType::OVERFLOW_ADDR);
486 : }
487 : return SUCCESS;
488 : }
489 :
490 : Status ArgsFormatConstructor::GetArgsSize(size_t &args_size) {
491 : if (format_desc_.GetArgsSize(op_desc_, args_size) != ge::GRAPH_SUCCESS) {
492 : return FAILED;
493 : }
494 : return SUCCESS;
495 : }
496 :
497 84 : std::string ArgsFormatConstructor::GetArgsFormatString() const {
498 : return format_desc_.ToString();
499 : }
500 : } // namespace fe
|