1be168c0dSopenharmony_ciFrom 17b5a08e7c53b25a912bcc9d65cc47febb7fc835 Mon Sep 17 00:00:00 2001 2be168c0dSopenharmony_ciFrom: zhangyanhui <zhangyanhui17@huawei.com> 3be168c0dSopenharmony_ciDate: Tue, 30 Jan 2024 16:23:22 +0800 4be168c0dSopenharmony_ciSubject: [PATCH] 0010-micro 5be168c0dSopenharmony_ci 6be168c0dSopenharmony_ci--- 7be168c0dSopenharmony_ci .../lite/include/registry/deobf_processor.h | 2 +- 8be168c0dSopenharmony_ci .../config_parser/config_file_parser.cc | 8 +-- 9be168c0dSopenharmony_ci .../config_parser/config_file_parser.h | 2 +- 10be168c0dSopenharmony_ci .../config_parser/micro_param_parser.cc | 8 +-- 11be168c0dSopenharmony_ci .../config_parser/micro_param_parser.h | 3 +- 12be168c0dSopenharmony_ci mindspore/lite/tools/converter/converter.cc | 10 ++-- 13be168c0dSopenharmony_ci .../lite/tools/converter/micro/coder/coder.cc | 1 + 14be168c0dSopenharmony_ci .../lite/tools/converter/micro/coder/config.h | 9 ++++ 15be168c0dSopenharmony_ci .../generator/component/common_component.cc | 49 ++++++++++++++++--- 16be168c0dSopenharmony_ci .../component/const_blocks/calib_output.cc | 19 +++++++ 17be168c0dSopenharmony_ci .../component/const_blocks/mtensor.cc | 2 +- 18be168c0dSopenharmony_ci 11 files changed, 90 insertions(+), 23 deletions(-) 19be168c0dSopenharmony_ci 20be168c0dSopenharmony_cidiff --git a/mindspore/lite/include/registry/deobf_processor.h b/mindspore/lite/include/registry/deobf_processor.h 21be168c0dSopenharmony_ciindex 5987233f..c70735b2 100644 22be168c0dSopenharmony_ci--- a/mindspore/lite/include/registry/deobf_processor.h 23be168c0dSopenharmony_ci+++ b/mindspore/lite/include/registry/deobf_processor.h 24be168c0dSopenharmony_ci@@ -21,7 +21,7 @@ 25be168c0dSopenharmony_ci #include <string> 26be168c0dSopenharmony_ci #include <numeric> 27be168c0dSopenharmony_ci #include "src/common/prim_util.h" 28be168c0dSopenharmony_ci-#include "src/common/log.h" 29be168c0dSopenharmony_ci+#include "src/common/log_adapter.h" 30be168c0dSopenharmony_ci #include "include/model.h" 31be168c0dSopenharmony_ci #include "schema/inner/model_generated.h" 32be168c0dSopenharmony_ci 33be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/config_parser/config_file_parser.cc b/mindspore/lite/tools/converter/config_parser/config_file_parser.cc 34be168c0dSopenharmony_ciindex 7b47fb8c..eed1c1ef 100644 35be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/config_parser/config_file_parser.cc 36be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/config_parser/config_file_parser.cc 37be168c0dSopenharmony_ci@@ -230,7 +230,7 @@ int ParseInputShapeTemplate(const std::string &shape_template, std::set<std::str 38be168c0dSopenharmony_ci return RET_OK; 39be168c0dSopenharmony_ci } 40be168c0dSopenharmony_ci 41be168c0dSopenharmony_ci-int ParseDynmiacDimTemplate(const std::string &dims_template, std::set<std::string> *dynamic_symbols, 42be168c0dSopenharmony_ci+int ParseDynamicDimTemplate(const std::string &dims_template, std::set<std::string> *dynamic_symbols, 43be168c0dSopenharmony_ci MicroParamString *micro_param_string) { 44be168c0dSopenharmony_ci // the dynamic_dim_params config is like: d0:[1,3~6];d1:[1~8] 45be168c0dSopenharmony_ci auto dim_info_vec = SplitStringToVector(dims_template, ';'); 46be168c0dSopenharmony_ci@@ -259,7 +259,7 @@ int ParseDynmiacDimTemplate(const std::string &dims_template, std::set<std::stri 47be168c0dSopenharmony_ci MS_LOG(ERROR) << "the dynamic_dim_params range value must be greater than 0"; 48be168c0dSopenharmony_ci return RET_INPUT_PARAM_INVALID; 49be168c0dSopenharmony_ci } 50be168c0dSopenharmony_ci- micro_param_string->dynamic_symbols_map[symbol] += continuous_dim[0] + ","; 51be168c0dSopenharmony_ci+ micro_param_string->dynamic_symbols_map[symbol].emplace_back(std::stoi(continuous_dim[0])); 52be168c0dSopenharmony_ci continue; 53be168c0dSopenharmony_ci } 54be168c0dSopenharmony_ci if (!IsNumber(continuous_dim[0]) || std::stoi(continuous_dim[0]) <= 0 || !IsNumber(continuous_dim[1]) || 55be168c0dSopenharmony_ci@@ -270,7 +270,7 @@ int ParseDynmiacDimTemplate(const std::string &dims_template, std::set<std::stri 56be168c0dSopenharmony_ci auto start = std::stoi(continuous_dim[0]); 57be168c0dSopenharmony_ci auto end = std::stoi(continuous_dim[1]); 58be168c0dSopenharmony_ci for (auto i = start; i <= end; ++i) { 59be168c0dSopenharmony_ci- micro_param_string->dynamic_symbols_map[symbol] += std::to_string(i) + ","; 60be168c0dSopenharmony_ci+ micro_param_string->dynamic_symbols_map[symbol].emplace_back(i); 61be168c0dSopenharmony_ci } 62be168c0dSopenharmony_ci } 63be168c0dSopenharmony_ci } 64be168c0dSopenharmony_ci@@ -597,7 +597,7 @@ int ConfigFileParser::ParseMicroParamString(const std::map<std::string, std::map 65be168c0dSopenharmony_ci const std::string dynamic_dims = "dynamic_dim_params"; 66be168c0dSopenharmony_ci if (!dynamic_symbols.empty() && map.find(dynamic_dims) != map.end()) { 67be168c0dSopenharmony_ci const auto &dims_template = map.at(dynamic_dims); 68be168c0dSopenharmony_ci- ParseDynmiacDimTemplate(dims_template, &dynamic_symbols, µ_param_string_); 69be168c0dSopenharmony_ci+ ParseDynamicDimTemplate(dims_template, &dynamic_symbols, µ_param_string_); 70be168c0dSopenharmony_ci } 71be168c0dSopenharmony_ci std::map<std::string, std::string &> parse_map{ 72be168c0dSopenharmony_ci {"target", micro_param_string_.target}, 73be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/config_parser/config_file_parser.h b/mindspore/lite/tools/converter/config_parser/config_file_parser.h 74be168c0dSopenharmony_ciindex 163782b7..b6267c0c 100644 75be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/config_parser/config_file_parser.h 76be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/config_parser/config_file_parser.h 77be168c0dSopenharmony_ci@@ -110,7 +110,7 @@ struct MicroParamString { 78be168c0dSopenharmony_ci std::string changeable_weights_name; 79be168c0dSopenharmony_ci std::string inputs_shape; 80be168c0dSopenharmony_ci std::string dynamic_dim_params; 81be168c0dSopenharmony_ci- std::map<std::string, std::string> dynamic_symbols_map; 82be168c0dSopenharmony_ci+ std::map<std::string, std::vector<int>> dynamic_symbols_map; 83be168c0dSopenharmony_ci }; 84be168c0dSopenharmony_ci 85be168c0dSopenharmony_ci struct ThirdPartyModelString { 86be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/config_parser/micro_param_parser.cc b/mindspore/lite/tools/converter/config_parser/micro_param_parser.cc 87be168c0dSopenharmony_ciindex 903f2863..da5b46eb 100644 88be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/config_parser/micro_param_parser.cc 89be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/config_parser/micro_param_parser.cc 90be168c0dSopenharmony_ci@@ -117,7 +117,7 @@ STATUS MicroParamParser::ParseChangeableWeightsName(const std::string &changeabl 91be168c0dSopenharmony_ci } 92be168c0dSopenharmony_ci 93be168c0dSopenharmony_ci STATUS MicroParamParser::ParseGraphInputsShapeTemplate(const std::string &graph_inputs_shape_template, 94be168c0dSopenharmony_ci- const std::map<std::string, std::string> &dynamic_symbols_map, 95be168c0dSopenharmony_ci+ const std::map<std::string, std::vector<int>> &dynamic_symbols_map, 96be168c0dSopenharmony_ci micro::MicroParam *micro_param) { 97be168c0dSopenharmony_ci MS_LOG(DEBUG) << "Micro record inputs shape: " << graph_inputs_shape_template; 98be168c0dSopenharmony_ci if (!graph_inputs_shape_template.empty()) { 99be168c0dSopenharmony_ci@@ -145,9 +145,8 @@ STATUS MicroParamParser::ParseGraphInputsShapeTemplate(const std::string &graph_ 100be168c0dSopenharmony_ci for (const auto &item : dynamic_symbols_map) { 101be168c0dSopenharmony_ci symbols_index[item.first] = index++; 102be168c0dSopenharmony_ci symbols.push_back(item.first); 103be168c0dSopenharmony_ci- auto num_str_list = SplitStringToVector(item.second, ','); 104be168c0dSopenharmony_ci- for (const auto &num_str : num_str_list) { 105be168c0dSopenharmony_ci- symbols_to_num[item.first].push_back(std::stoi(num_str)); 106be168c0dSopenharmony_ci+ for (const auto &num : item.second) { 107be168c0dSopenharmony_ci+ symbols_to_num[item.first].push_back(num); 108be168c0dSopenharmony_ci } 109be168c0dSopenharmony_ci if (symbols_to_num[item.first].empty()) { 110be168c0dSopenharmony_ci MS_LOG(ERROR) << "Micro param invalid, dynamic symbol must have value."; 111be168c0dSopenharmony_ci@@ -158,6 +157,7 @@ STATUS MicroParamParser::ParseGraphInputsShapeTemplate(const std::string &graph_ 112be168c0dSopenharmony_ci } 113be168c0dSopenharmony_ci micro_param->dynamic_symbols = symbols; 114be168c0dSopenharmony_ci micro_param->dynamic_symbols_num = scene_num_by_symbol; 115be168c0dSopenharmony_ci+ micro_param->dynamic_symbols_map = dynamic_symbols_map; 116be168c0dSopenharmony_ci std::vector<size_t> post_multi(symbols.size(), 1); 117be168c0dSopenharmony_ci for (int i = static_cast<int>(post_multi.size()) - 2; i >= 0; --i) { 118be168c0dSopenharmony_ci post_multi[i] = post_multi[i + 1] * scene_num_by_symbol[i + 1]; 119be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/config_parser/micro_param_parser.h b/mindspore/lite/tools/converter/config_parser/micro_param_parser.h 120be168c0dSopenharmony_ciindex eb95c571..fe818b90 100644 121be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/config_parser/micro_param_parser.h 122be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/config_parser/micro_param_parser.h 123be168c0dSopenharmony_ci@@ -17,6 +17,7 @@ 124be168c0dSopenharmony_ci #define MINDSPORE_LITE_TOOLS_CONVERTER_CONFIG_PARSER_MICRO_PARAM_PARSER_H_ 125be168c0dSopenharmony_ci 126be168c0dSopenharmony_ci #include <string> 127be168c0dSopenharmony_ci+#include <vector> 128be168c0dSopenharmony_ci #include "tools/converter/config_parser/config_file_parser.h" 129be168c0dSopenharmony_ci #include "tools/converter/micro/coder/config.h" 130be168c0dSopenharmony_ci #include "include/errorcode.h" 131be168c0dSopenharmony_ci@@ -38,7 +39,7 @@ class MicroParamParser { 132be168c0dSopenharmony_ci STATUS ParseKeepOriginalWeight(const std::string &keep_weight, micro::MicroParam *micro_param); 133be168c0dSopenharmony_ci STATUS ParseChangeableWeightsName(const std::string &changeable_weights_name, micro::MicroParam *micro_param); 134be168c0dSopenharmony_ci STATUS ParseGraphInputsShapeTemplate(const std::string &graph_inputs_shape_template, 135be168c0dSopenharmony_ci- const std::map<std::string, std::string> &dynamic_symbols_map, 136be168c0dSopenharmony_ci+ const std::map<std::string, std::vector<int>> &dynamic_symbols_map, 137be168c0dSopenharmony_ci micro::MicroParam *micro_param); 138be168c0dSopenharmony_ci }; 139be168c0dSopenharmony_ci } // namespace lite 140be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/converter.cc b/mindspore/lite/tools/converter/converter.cc 141be168c0dSopenharmony_ciindex 4703e889..e2a5e6a1 100644 142be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/converter.cc 143be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/converter.cc 144be168c0dSopenharmony_ci@@ -455,10 +455,12 @@ int ConverterImpl::InitConfigParam(const std::shared_ptr<ConverterPara> ¶m, 145be168c0dSopenharmony_ci MS_LOG(ERROR) << "Parse mixed bit weight quant param failed."; 146be168c0dSopenharmony_ci return ret; 147be168c0dSopenharmony_ci } 148be168c0dSopenharmony_ci- ret = lite::ThirdPartyParamParser::Parse(config_parser.GetThirdPartyModelString(), ¶m->thirdPartyModelParam); 149be168c0dSopenharmony_ci- if (ret != RET_OK) { 150be168c0dSopenharmony_ci- MS_LOG(ERROR) << "Parse third party param failed."; 151be168c0dSopenharmony_ci- return ret; 152be168c0dSopenharmony_ci+ if (param->fmk_type == converter::kFmkTypeThirdParty) { 153be168c0dSopenharmony_ci+ ret = lite::ThirdPartyParamParser::Parse(config_parser.GetThirdPartyModelString(), ¶m->thirdPartyModelParam); 154be168c0dSopenharmony_ci+ if (ret != RET_OK) { 155be168c0dSopenharmony_ci+ MS_LOG(ERROR) << "Parse third party param failed."; 156be168c0dSopenharmony_ci+ return ret; 157be168c0dSopenharmony_ci+ } 158be168c0dSopenharmony_ci } 159be168c0dSopenharmony_ci ret = InitExtendedIntegrationInfo(param, config_parser); 160be168c0dSopenharmony_ci if (ret != RET_OK) { 161be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/micro/coder/coder.cc b/mindspore/lite/tools/converter/micro/coder/coder.cc 162be168c0dSopenharmony_ciindex a502500d..065cbdfd 100644 163be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/micro/coder/coder.cc 164be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/micro/coder/coder.cc 165be168c0dSopenharmony_ci@@ -238,6 +238,7 @@ int Coder::Init(const MicroParam ¶m) const { 166be168c0dSopenharmony_ci config->set_graph_inputs_shape_infos(param.graph_inputs_shape_infos); 167be168c0dSopenharmony_ci config->set_dynamic_symbols(param.dynamic_symbols); 168be168c0dSopenharmony_ci config->set_dynamic_symbols_num(param.dynamic_symbols_num); 169be168c0dSopenharmony_ci+ config->set_dynamic_symbols_map(param.dynamic_symbols_map); 170be168c0dSopenharmony_ci config->set_user_graph_inputs_template(param.graph_inputs_template); 171be168c0dSopenharmony_ci 172be168c0dSopenharmony_ci auto print_parameter = [](auto name, auto value) { 173be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/micro/coder/config.h b/mindspore/lite/tools/converter/micro/coder/config.h 174be168c0dSopenharmony_ciindex fb90a2fc..3afea051 100644 175be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/micro/coder/config.h 176be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/micro/coder/config.h 177be168c0dSopenharmony_ci@@ -18,6 +18,8 @@ 178be168c0dSopenharmony_ci #define MINDSPORE_LITE_TOOLS_CONVERTER_MICRO_CODER_CONFIG_H_ 179be168c0dSopenharmony_ci 180be168c0dSopenharmony_ci #include <string> 181be168c0dSopenharmony_ci+#include <map> 182be168c0dSopenharmony_ci+#include <vector> 183be168c0dSopenharmony_ci 184be168c0dSopenharmony_ci namespace mindspore::lite::micro { 185be168c0dSopenharmony_ci enum Target { kX86 = 0, kCortex_M = 1, kARM32 = 2, kARM64 = 3, kAllTargets = 4, kTargetUnknown = 99 }; 186be168c0dSopenharmony_ci@@ -38,6 +40,7 @@ struct MicroParam { 187be168c0dSopenharmony_ci std::map<std::string, std::vector<std::string>> graph_inputs_origin_info; 188be168c0dSopenharmony_ci std::vector<std::string> dynamic_symbols; 189be168c0dSopenharmony_ci std::vector<size_t> dynamic_symbols_num; 190be168c0dSopenharmony_ci+ std::map<std::string, std::vector<int>> dynamic_symbols_map; 191be168c0dSopenharmony_ci std::vector<std::vector<std::vector<int>>> graph_inputs_shape_infos; 192be168c0dSopenharmony_ci std::map<std::string, std::vector<std::vector<int>>> inputs_shape_by_scenes; 193be168c0dSopenharmony_ci }; 194be168c0dSopenharmony_ci@@ -84,6 +87,11 @@ class Configurator { 195be168c0dSopenharmony_ci } 196be168c0dSopenharmony_ci const std::vector<size_t> &dynamic_symbols_num() const { return dynamic_symbols_num_; } 197be168c0dSopenharmony_ci 198be168c0dSopenharmony_ci+ void set_dynamic_symbols_map(const std::map<std::string, std::vector<int>> &dynamic_symbols_map) { 199be168c0dSopenharmony_ci+ dynamic_symbols_map_ = dynamic_symbols_map; 200be168c0dSopenharmony_ci+ } 201be168c0dSopenharmony_ci+ const std::map<std::string, std::vector<int>> &dynamic_symbols_map() const { return dynamic_symbols_map_; } 202be168c0dSopenharmony_ci+ 203be168c0dSopenharmony_ci void set_user_graph_inputs_template(const std::vector<std::vector<std::string>> &graph_inputs_template) { 204be168c0dSopenharmony_ci user_graph_inputs_template_ = graph_inputs_template; 205be168c0dSopenharmony_ci } 206be168c0dSopenharmony_ci@@ -110,6 +118,7 @@ class Configurator { 207be168c0dSopenharmony_ci std::string changeable_weights_name_; 208be168c0dSopenharmony_ci std::vector<std::string> dynamic_symbols_; 209be168c0dSopenharmony_ci std::vector<size_t> dynamic_symbols_num_; 210be168c0dSopenharmony_ci+ std::map<std::string, std::vector<int>> dynamic_symbols_map_; 211be168c0dSopenharmony_ci std::vector<std::vector<std::vector<int>>> graph_inputs_shape_infos_; 212be168c0dSopenharmony_ci std::vector<std::vector<std::string>> user_graph_inputs_template_; 213be168c0dSopenharmony_ci }; 214be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc b/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc 215be168c0dSopenharmony_ciindex 62c2f668..b9ab846e 100644 216be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc 217be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc 218be168c0dSopenharmony_ci@@ -492,6 +492,19 @@ void CodeMSModelResize(std::ofstream &ofs, const std::unique_ptr<CoderContext> & 219be168c0dSopenharmony_ci for (auto &item : symbol_to_indexes) { 220be168c0dSopenharmony_ci ofs << " int dim" << index << " = shape_infos[" << item.second[0] << "].shape[" << item.second[1] << "];\n"; 221be168c0dSopenharmony_ci inner_to_outer[item.first] = "dim" + std::to_string(index); 222be168c0dSopenharmony_ci+ std::string cur_dim_symbol; 223be168c0dSopenharmony_ci+ for (std::map<std::string, std::string>::iterator it = user_to_inner.begin(); it != user_to_inner.end(); it++) { 224be168c0dSopenharmony_ci+ if (it->second == item.first) { 225be168c0dSopenharmony_ci+ cur_dim_symbol = it->first; 226be168c0dSopenharmony_ci+ break; 227be168c0dSopenharmony_ci+ } 228be168c0dSopenharmony_ci+ } 229be168c0dSopenharmony_ci+ auto dynamic_dim_range = config.dynamic_symbols_map().at(cur_dim_symbol); 230be168c0dSopenharmony_ci+ ofs << " int dim" << index << "_range[" << dynamic_dim_range.size() << "] = {"; 231be168c0dSopenharmony_ci+ for (const auto dim : dynamic_dim_range) { 232be168c0dSopenharmony_ci+ ofs << dim << ", "; 233be168c0dSopenharmony_ci+ } 234be168c0dSopenharmony_ci+ ofs << "};\n"; 235be168c0dSopenharmony_ci ++index; 236be168c0dSopenharmony_ci } 237be168c0dSopenharmony_ci std::string condition; 238be168c0dSopenharmony_ci@@ -508,18 +521,40 @@ void CodeMSModelResize(std::ofstream &ofs, const std::unique_ptr<CoderContext> & 239be168c0dSopenharmony_ci for (size_t i = 0; i < symbol_to_indexes.size(); ++i) { 240be168c0dSopenharmony_ci ofs << " store" + std::to_string(ctx->GetCurModelIndex()) + "_" << i << " = dim" << i << ";\n"; 241be168c0dSopenharmony_ci } 242be168c0dSopenharmony_ci+ auto &dynamic_symbols = config.dynamic_symbols(); 243be168c0dSopenharmony_ci+ int id = 0; 244be168c0dSopenharmony_ci+ for (auto &symbol : dynamic_symbols) { 245be168c0dSopenharmony_ci+ auto cur_dim = inner_to_outer[user_to_inner[symbol]]; 246be168c0dSopenharmony_ci+ auto dim_list = cur_dim + "_range"; 247be168c0dSopenharmony_ci+ ofs << " int index" << id << " = 0;\n"; 248be168c0dSopenharmony_ci+ ofs << " for (int i = 0; i < sizeof(" << dim_list << ") / sizeof(" << dim_list << "[0]); i++) {\n" 249be168c0dSopenharmony_ci+ << " if (" << dim_list << "[i] == " << cur_dim << ") {\n" 250be168c0dSopenharmony_ci+ << " index" << id << " = i;\n" 251be168c0dSopenharmony_ci+ << " break;\n" 252be168c0dSopenharmony_ci+ << " }\n" 253be168c0dSopenharmony_ci+ << " }\n"; 254be168c0dSopenharmony_ci+ id++; 255be168c0dSopenharmony_ci+ } 256be168c0dSopenharmony_ci ofs << " if (" << kBufferPrefixName << " != NULL) {\n"; 257be168c0dSopenharmony_ci ofs << " free(" << kBufferPrefixName << ");\n"; 258be168c0dSopenharmony_ci+ ofs << " " << kBufferPrefixName << " = NULL;\n"; 259be168c0dSopenharmony_ci ofs << " }\n"; 260be168c0dSopenharmony_ci- std::string real_array_index; 261be168c0dSopenharmony_ci- auto &dynamic_symbols = config.dynamic_symbols(); 262be168c0dSopenharmony_ci- for (auto &symbol : dynamic_symbols) { 263be168c0dSopenharmony_ci- real_array_index += "[" + inner_to_outer[user_to_inner[symbol]] + " - 1]"; 264be168c0dSopenharmony_ci+ ofs << " " << kBufferPrefixName << " = malloc(buffer_sizes"; 265be168c0dSopenharmony_ci+ for (size_t i = 0; i < dynamic_symbols.size(); i++) { 266be168c0dSopenharmony_ci+ ofs << "[index" << i << "]"; 267be168c0dSopenharmony_ci } 268be168c0dSopenharmony_ci- ofs << " " << kBufferPrefixName << " = malloc(buffer_sizes" << real_array_index << ");\n"; 269be168c0dSopenharmony_ci+ ofs << ");\n"; 270be168c0dSopenharmony_ci ofs << " micro_model->runtime_buffer = " << kBufferPrefixName << ";\n"; 271be168c0dSopenharmony_ci- ofs << " " << kShapePrefixName << " = &shapes" << real_array_index << "[0];\n"; 272be168c0dSopenharmony_ci- ofs << " " << kOffsetPrefixName << " = &offsets" << real_array_index << "[0];\n"; 273be168c0dSopenharmony_ci+ ofs << " " << kShapePrefixName << " = &shapes"; 274be168c0dSopenharmony_ci+ for (size_t i = 0; i < dynamic_symbols.size(); i++) { 275be168c0dSopenharmony_ci+ ofs << "[index" << i << "]"; 276be168c0dSopenharmony_ci+ } 277be168c0dSopenharmony_ci+ ofs << "[0];\n"; 278be168c0dSopenharmony_ci+ ofs << " " << kOffsetPrefixName << " = &offsets"; 279be168c0dSopenharmony_ci+ for (size_t i = 0; i < dynamic_symbols.size(); i++) { 280be168c0dSopenharmony_ci+ ofs << "[index" << i << "]"; 281be168c0dSopenharmony_ci+ } 282be168c0dSopenharmony_ci+ ofs << "[0];\n"; 283be168c0dSopenharmony_ci ofs << " OH_AI_TensorHandleArray outputs = OH_AI_ModelGetOutputs(model);\n"; 284be168c0dSopenharmony_ci for (size_t i = 0; i < ctx->graph_outputs().size(); ++i) { 285be168c0dSopenharmony_ci ofs << " OH_AI_TensorSetData(outputs.handle_list[" << i << "], NULL);\n"; 286be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/calib_output.cc b/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/calib_output.cc 287be168c0dSopenharmony_ciindex 66af9069..bd020d83 100644 288be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/calib_output.cc 289be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/calib_output.cc 290be168c0dSopenharmony_ci@@ -80,6 +80,9 @@ const char *calib_source = R"RAW(/** 291be168c0dSopenharmony_ci #include <stdlib.h> 292be168c0dSopenharmony_ci #include <math.h> 293be168c0dSopenharmony_ci #include <string.h> 294be168c0dSopenharmony_ci+#ifdef ENABLE_FP16 295be168c0dSopenharmony_ci+#include <arm_neon.h> 296be168c0dSopenharmony_ci+#endif 297be168c0dSopenharmony_ci 298be168c0dSopenharmony_ci #define kToleranceVal 0.0001f 299be168c0dSopenharmony_ci #define kMaxOutput 5 300be168c0dSopenharmony_ci@@ -196,6 +199,22 @@ int CompareOutputs(OH_AI_TensorHandleArray outputs, CalibTensor **calib_tensors, 301be168c0dSopenharmony_ci } 302be168c0dSopenharmony_ci break; 303be168c0dSopenharmony_ci } 304be168c0dSopenharmony_ci+#ifdef ENABLE_FP16 305be168c0dSopenharmony_ci+ case OH_AI_DATATYPE_NUMBERTYPE_FLOAT16: { 306be168c0dSopenharmony_ci+ float16_t *float16_output = (float16_t *)output->data; 307be168c0dSopenharmony_ci+ for (size_t j = 0; j < elements; ++j) { 308be168c0dSopenharmony_ci+ if (isnan(float16_output[j]) || isinf(float16_output[j]) || isnan(calib[i].data_[j]) || 309be168c0dSopenharmony_ci+ isinf(calib[i].data_[j])) { 310be168c0dSopenharmony_ci+ printf("error, output data is nan or inf\n"); 311be168c0dSopenharmony_ci+ return OH_AI_STATUS_LITE_ERROR; 312be168c0dSopenharmony_ci+ } 313be168c0dSopenharmony_ci+ dot += float16_output[j] * calib[i].data_[j]; 314be168c0dSopenharmony_ci+ normx += float16_output[j] * float16_output[j]; 315be168c0dSopenharmony_ci+ normy += calib[i].data_[j] * calib[i].data_[j]; 316be168c0dSopenharmony_ci+ } 317be168c0dSopenharmony_ci+ break; 318be168c0dSopenharmony_ci+ } 319be168c0dSopenharmony_ci+#endif 320be168c0dSopenharmony_ci case OH_AI_DATATYPE_NUMBERTYPE_INT8: { 321be168c0dSopenharmony_ci int8_t *int_output = (int8_t *)output->data; 322be168c0dSopenharmony_ci for (size_t j = 0; j < elements; ++j) { 323be168c0dSopenharmony_cidiff --git a/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/mtensor.cc b/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/mtensor.cc 324be168c0dSopenharmony_ciindex e4581829..8d8e6768 100644 325be168c0dSopenharmony_ci--- a/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/mtensor.cc 326be168c0dSopenharmony_ci+++ b/mindspore/lite/tools/converter/micro/coder/generator/component/const_blocks/mtensor.cc 327be168c0dSopenharmony_ci@@ -315,12 +315,12 @@ void *TransformInput(OH_AI_TensorHandle tensor, int expect_type, bool *type_chan 328be168c0dSopenharmony_ci if (type_trans_mode == TypeTransMode_UNSUPPORT) { 329be168c0dSopenharmony_ci return NULL; 330be168c0dSopenharmony_ci } 331be168c0dSopenharmony_ci+#ifdef ENABLE_FP16 332be168c0dSopenharmony_ci int shape_size = micro_tensor->ndim; 333be168c0dSopenharmony_ci int num = 1; 334be168c0dSopenharmony_ci for (int i = 0; i < shape_size; ++i) { 335be168c0dSopenharmony_ci num *= micro_tensor->shape[i]; 336be168c0dSopenharmony_ci } 337be168c0dSopenharmony_ci-#ifdef ENABLE_FP16 338be168c0dSopenharmony_ci if (type_trans_mode == TypeTransMode_FP32_TO_FP16) { 339be168c0dSopenharmony_ci void *expect_input_fp16 = (void *)malloc(DataTypeSize(expect_type) * num); 340be168c0dSopenharmony_ci Fp32CastToFp16((float *)micro_tensor->data, (float16_t *)expect_input_fp16, num); 341be168c0dSopenharmony_ci-- 342be168c0dSopenharmony_ci2.25.1 343be168c0dSopenharmony_ci 344