1be168c0dSopenharmony_ciFrom bcefb7478b4c90c3d09ce7c089e2cb00cd494c8e Mon Sep 17 00:00:00 2001 2be168c0dSopenharmony_ciFrom: chengfeng27 <chengfeng27@huawei.com> 3be168c0dSopenharmony_ciDate: Tue, 30 Jan 2024 19:55:44 +0800 4be168c0dSopenharmony_ciSubject: [PATCH] add mindir ops interface 5be168c0dSopenharmony_ci 6be168c0dSopenharmony_ciSigned-off-by: chengfeng27 <chengfeng27@huawei.com> 7be168c0dSopenharmony_ci--- 8be168c0dSopenharmony_ci mindspore/lite/BUILD.gn | 5 +- 9be168c0dSopenharmony_ci mindspore/lite/mindir/BUILD.gn | 15 +- 10be168c0dSopenharmony_ci mindspore/lite/mindir/include/mindir.h | 152 +- 11be168c0dSopenharmony_ci mindspore/lite/mindir/include/mindir_tensor.h | 29 - 12be168c0dSopenharmony_ci mindspore/lite/mindir/include/mindir_types.h | 21 + 13be168c0dSopenharmony_ci mindspore/lite/mindir/src/mindir.cc | 1179 +++++++++++++ 14be168c0dSopenharmony_ci .../src/mindir_nnrt_lite_graph_to_model.cc | 1496 ---------------- 15be168c0dSopenharmony_ci .../mindir_nnrt_lite_graph_to_model_v2_0.cc | 1497 ----------------- 16be168c0dSopenharmony_ci mindspore/lite/mindir/src/mindir_tensor.cc | 80 - 17be168c0dSopenharmony_ci mindspore/lite/src/litert/c_api/context_c.cc | 4 + 18be168c0dSopenharmony_ci .../cpu/fp32_grad/strided_slice_grad.cc | 124 +- 19be168c0dSopenharmony_ci .../kernel/cpu/fp32_grad/strided_slice_grad.h | 5 + 20be168c0dSopenharmony_ci mindspore/lite/src/litert/lite_model.cc | 4 +- 21be168c0dSopenharmony_ci 13 files changed, 1446 insertions(+), 3165 deletions(-) 22be168c0dSopenharmony_ci delete mode 100644 mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model.cc 23be168c0dSopenharmony_ci delete mode 100644 mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model_v2_0.cc 24be168c0dSopenharmony_ci 25be168c0dSopenharmony_cidiff --git a/mindspore/lite/BUILD.gn b/mindspore/lite/BUILD.gn 26be168c0dSopenharmony_ciindex d7fe4f55..4a83f498 100644 27be168c0dSopenharmony_ci--- a/mindspore/lite/BUILD.gn 28be168c0dSopenharmony_ci+++ b/mindspore/lite/BUILD.gn 29be168c0dSopenharmony_ci@@ -366,6 +366,7 @@ ohos_shared_library("mindspore_lib") { 30be168c0dSopenharmony_ci "../core/mindrt/:mindrt_obj", 31be168c0dSopenharmony_ci "src/litert/kernel/cpu/:cpu_kernel_obj", 32be168c0dSopenharmony_ci "src/common/:lite_common_mid_obj", 33be168c0dSopenharmony_ci+ "//third_party/flatbuffers:flatbuffers_install_action", 34be168c0dSopenharmony_ci ] 35be168c0dSopenharmony_ci 36be168c0dSopenharmony_ci sources = all_sources 37be168c0dSopenharmony_ci@@ -473,7 +474,8 @@ ohos_shared_library("mindspore_lib") { 38be168c0dSopenharmony_ci ohos_shared_library("mindspore_ndk") { 39be168c0dSopenharmony_ci deps = [ 40be168c0dSopenharmony_ci ":mindspore_lib", 41be168c0dSopenharmony_ci- ":mindspore_train_lib" 42be168c0dSopenharmony_ci+ ":mindspore_train_lib", 43be168c0dSopenharmony_ci+ "//third_party/flatbuffers:flatbuffers_install_action", 44be168c0dSopenharmony_ci ] 45be168c0dSopenharmony_ci 46be168c0dSopenharmony_ci sources = c_api_sources 47be168c0dSopenharmony_ci@@ -636,6 +638,7 @@ all_train_sources += fp32_train_kernel_sources 48be168c0dSopenharmony_ci ohos_shared_library("mindspore_train_lib") { 49be168c0dSopenharmony_ci deps = [ 50be168c0dSopenharmony_ci ":mindspore_lib", 51be168c0dSopenharmony_ci+ "//third_party/flatbuffers:flatbuffers_install_action", 52be168c0dSopenharmony_ci ] 53be168c0dSopenharmony_ci 54be168c0dSopenharmony_ci sources = all_train_sources 55be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/BUILD.gn b/mindspore/lite/mindir/BUILD.gn 56be168c0dSopenharmony_ciindex b1435ef7..ad4eff84 100644 57be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/BUILD.gn 58be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/BUILD.gn 59be168c0dSopenharmony_ci@@ -19,11 +19,17 @@ import("//build/ohos.gni") 60be168c0dSopenharmony_ci # "tests:mindir_test", 61be168c0dSopenharmony_ci # ] 62be168c0dSopenharmony_ci # } 63be168c0dSopenharmony_ci+ 64be168c0dSopenharmony_ci+config("mindir_config") { 65be168c0dSopenharmony_ci+ include_dirs = [ 66be168c0dSopenharmony_ci+ "include", 67be168c0dSopenharmony_ci+ ] 68be168c0dSopenharmony_ci+} 69be168c0dSopenharmony_ci+ 70be168c0dSopenharmony_ci ohos_shared_library("mindir_lib") { 71be168c0dSopenharmony_ci include_dirs = [ 72be168c0dSopenharmony_ci "../", 73be168c0dSopenharmony_ci "../../core", 74be168c0dSopenharmony_ci- "include", 75be168c0dSopenharmony_ci "inner_headers", 76be168c0dSopenharmony_ci "//third_party/flatbuffers/include", 77be168c0dSopenharmony_ci "//third_party/bounds_checking_function/include", 78be168c0dSopenharmony_ci@@ -34,8 +40,6 @@ ohos_shared_library("mindir_lib") { 79be168c0dSopenharmony_ci "src/mindir.cc", 80be168c0dSopenharmony_ci "src/mindir_memory_manager.cc", 81be168c0dSopenharmony_ci "src/mindir_nnrt_lite_graph.cc", 82be168c0dSopenharmony_ci- "src/mindir_nnrt_lite_graph_to_model.cc", 83be168c0dSopenharmony_ci- "src/mindir_nnrt_lite_graph_to_model_v2_0.cc", 84be168c0dSopenharmony_ci "src/mindir_tensor.cc", 85be168c0dSopenharmony_ci "src/utils.cc", 86be168c0dSopenharmony_ci ] 87be168c0dSopenharmony_ci@@ -45,14 +49,17 @@ ohos_shared_library("mindir_lib") { 88be168c0dSopenharmony_ci "drivers_interface_nnrt:libnnrt_proxy_2.0", 89be168c0dSopenharmony_ci "hdf_core:libhdi", 90be168c0dSopenharmony_ci "hilog:libhilog", 91be168c0dSopenharmony_ci- "ipc:ipc_core", 92be168c0dSopenharmony_ci "bounds_checking_function:libsec_shared", 93be168c0dSopenharmony_ci "drivers_interface_nnrt:nnrt_idl_headers" 94be168c0dSopenharmony_ci ] 95be168c0dSopenharmony_ci+ deps = [ 96be168c0dSopenharmony_ci+ "//third_party/flatbuffers:flatbuffers_install_action", 97be168c0dSopenharmony_ci+ ] 98be168c0dSopenharmony_ci configs = [ 99be168c0dSopenharmony_ci "../:disable_android", 100be168c0dSopenharmony_ci "../:secure_option", 101be168c0dSopenharmony_ci ] 102be168c0dSopenharmony_ci+ public_configs = [ ":mindir_config" ] 103be168c0dSopenharmony_ci defines = [ "MS_COMPILE_OHOS" ] 104be168c0dSopenharmony_ci output_name = "mindir" 105be168c0dSopenharmony_ci innerapi_tags = [ "platformsdk_indirect" ] 106be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/include/mindir.h b/mindspore/lite/mindir/include/mindir.h 107be168c0dSopenharmony_ciindex f47cad8c..4f633493 100644 108be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/include/mindir.h 109be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/include/mindir.h 110be168c0dSopenharmony_ci@@ -19,25 +19,6 @@ 111be168c0dSopenharmony_ci #include "mindir_lite_graph.h" 112be168c0dSopenharmony_ci #include "mindir_tensor.h" 113be168c0dSopenharmony_ci #include "mindir_primitive.h" 114be168c0dSopenharmony_ci-namespace OHOS { 115be168c0dSopenharmony_ci-namespace HDI { 116be168c0dSopenharmony_ci-namespace Nnrt { 117be168c0dSopenharmony_ci-namespace V1_0 { 118be168c0dSopenharmony_ci-struct Model; 119be168c0dSopenharmony_ci-} // namespace V1_0 120be168c0dSopenharmony_ci-} // namespace Nnrt 121be168c0dSopenharmony_ci-} // namespace HDI 122be168c0dSopenharmony_ci-} // namespace OHOS 123be168c0dSopenharmony_ci- 124be168c0dSopenharmony_ci-namespace OHOS { 125be168c0dSopenharmony_ci-namespace HDI { 126be168c0dSopenharmony_ci-namespace Nnrt { 127be168c0dSopenharmony_ci-namespace V2_0 { 128be168c0dSopenharmony_ci-struct Model; 129be168c0dSopenharmony_ci-} // namespace V2_0 130be168c0dSopenharmony_ci-} // namespace Nnrt 131be168c0dSopenharmony_ci-} // namespace HDI 132be168c0dSopenharmony_ci-} // namespace OHOS 133be168c0dSopenharmony_ci 134be168c0dSopenharmony_ci namespace mindspore { 135be168c0dSopenharmony_ci namespace schema { 136be168c0dSopenharmony_ci@@ -45,16 +26,6 @@ struct Attribute; 137be168c0dSopenharmony_ci } 138be168c0dSopenharmony_ci 139be168c0dSopenharmony_ci namespace lite { 140be168c0dSopenharmony_ci- 141be168c0dSopenharmony_ci-// ********** Model ********** 142be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V1_0::Model *MindIR_LiteGraph_To_Model(const LiteGraph *lite_graph, 143be168c0dSopenharmony_ci- const OHOS::HDI::Nnrt::V1_0::SharedBuffer &buffer); 144be168c0dSopenharmony_ci-void MindIR_Model_Destroy(OHOS::HDI::Nnrt::V1_0::Model **model); 145be168c0dSopenharmony_ci- 146be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V2_0::Model *MindIR_LiteGraph_To_Model(const LiteGraph *lite_graph, 147be168c0dSopenharmony_ci- const OHOS::HDI::Nnrt::V2_0::SharedBuffer &buffer); 148be168c0dSopenharmony_ci-void MindIR_Model_Destroy(OHOS::HDI::Nnrt::V2_0::Model **model); 149be168c0dSopenharmony_ci- 150be168c0dSopenharmony_ci // ********** Activation ********** 151be168c0dSopenharmony_ci PrimitivePtr MindIR_Activation_CreatePrimitive(ActivationType activation_type, float alpha, float min_val, 152be168c0dSopenharmony_ci float max_val, bool approximate); 153be168c0dSopenharmony_ci@@ -440,6 +411,129 @@ PrimitivePtr MindIR_Unsqueeze_CreatePrimitive(const std::vector<int64_t> &axis); 154be168c0dSopenharmony_ci std::vector<int64_t> MindIR_Unsqueeze_GetAxis(ConstPrimitivePtr primitive); 155be168c0dSopenharmony_ci void MindIR_Unsqueeze_SetAxis(PrimitivePtr *primitive, const std::vector<int64_t> &axis); 156be168c0dSopenharmony_ci 157be168c0dSopenharmony_ci+// ********** Abs ********** 158be168c0dSopenharmony_ci+PrimitivePtr MindIR_Abs_CreatePrimitive(); 159be168c0dSopenharmony_ci+ 160be168c0dSopenharmony_ci+// ********** BroadcastTo ********** 161be168c0dSopenharmony_ci+PrimitivePtr MindIR_BroadcastTo_CreatePrimitive(const std::vector<int64_t> &shape); 162be168c0dSopenharmony_ci+std::vector<int64_t> MindIR_BroadcastTo_GetShape(ConstPrimitivePtr primitive); 163be168c0dSopenharmony_ci+void MindIR_BroadcastTo_SetShape(PrimitivePtr *primitive, const std::vector<int64_t> &shape); 164be168c0dSopenharmony_ci+ 165be168c0dSopenharmony_ci+// ********** ConstantOfShape ********** 166be168c0dSopenharmony_ci+PrimitivePtr MindIR_ConstantOfShape_CreatePrimitive(int64_t data_type, const std::vector<float> &value); 167be168c0dSopenharmony_ci+int64_t MindIR_ConstantOfShape_GetDataType(ConstPrimitivePtr primitive); 168be168c0dSopenharmony_ci+void MindIR_ConstantOfShape_SetDataType(PrimitivePtr *primitive, int64_t data_type); 169be168c0dSopenharmony_ci+std::vector<float> MindIR_ConstantOfShape_GetValue(ConstPrimitivePtr primitive); 170be168c0dSopenharmony_ci+void MindIR_ConstantOfShape_SetValue(PrimitivePtr *primitive, const std::vector<float> &value); 171be168c0dSopenharmony_ci+ 172be168c0dSopenharmony_ci+// ********** DepthToSpace ********** 173be168c0dSopenharmony_ci+PrimitivePtr MindIR_DepthToSpace_CreatePrimitive(int64_t block_size, Format &format, std::string mode); 174be168c0dSopenharmony_ci+int64_t MindIR_DepthToSpace_GetBlockSize(ConstPrimitivePtr primitive); 175be168c0dSopenharmony_ci+void MindIR_DepthToSpace_SetBlockSize(PrimitivePtr *primitive, int64_t block_size); 176be168c0dSopenharmony_ci+Format MindIR_DepthToSpace_GetFormat(ConstPrimitivePtr primitive); 177be168c0dSopenharmony_ci+void MindIR_DepthToSpace_SetFormat(PrimitivePtr *primitive, Format &format); 178be168c0dSopenharmony_ci+std::string MindIR_DepthToSpace_GetMode(ConstPrimitivePtr primitive); 179be168c0dSopenharmony_ci+void MindIR_DepthToSpace_SetMode(PrimitivePtr *primitive, std::string mode); 180be168c0dSopenharmony_ci+ 181be168c0dSopenharmony_ci+// ********** ExpFusion ********** 182be168c0dSopenharmony_ci+PrimitivePtr MindIR_ExpFusion_CreatePrimitive(float base, float scale, float shift); 183be168c0dSopenharmony_ci+float MindIR_ExpFusion_GetBase(ConstPrimitivePtr primitive); 184be168c0dSopenharmony_ci+void MindIR_ExpFusion_SetBase(PrimitivePtr *primitive, float base); 185be168c0dSopenharmony_ci+float MindIR_ExpFusion_GetScale(ConstPrimitivePtr primitive); 186be168c0dSopenharmony_ci+void MindIR_ExpFusion_SetScale(PrimitivePtr *primitive, float scale); 187be168c0dSopenharmony_ci+float MindIR_ExpFusion_GetShift(ConstPrimitivePtr primitive); 188be168c0dSopenharmony_ci+void MindIR_ExpFusion_SetShift(PrimitivePtr *primitive, float shift); 189be168c0dSopenharmony_ci+ 190be168c0dSopenharmony_ci+// ********** Flatten ********** 191be168c0dSopenharmony_ci+PrimitivePtr MindIR_Flatten_CreatePrimitive(int64_t axis); 192be168c0dSopenharmony_ci+int64_t MindIR_Flatten_GetAxis(ConstPrimitivePtr primitive); 193be168c0dSopenharmony_ci+void MindIR_Flatten_SetAxis(PrimitivePtr *primitive, int64_t axis); 194be168c0dSopenharmony_ci+ 195be168c0dSopenharmony_ci+// ********** InstanceNorm ********** 196be168c0dSopenharmony_ci+PrimitivePtr MindIR_InstanceNorm_CreatePrimitive(float epsilon); 197be168c0dSopenharmony_ci+float MindIR_InstanceNorm_GetEpsilon(ConstPrimitivePtr primitive); 198be168c0dSopenharmony_ci+void MindIR_InstanceNorm_SetEpsilon(PrimitivePtr *primitive, float epsilon); 199be168c0dSopenharmony_ci+ 200be168c0dSopenharmony_ci+// ********** Less ********** 201be168c0dSopenharmony_ci+PrimitivePtr MindIR_Less_CreatePrimitive(); 202be168c0dSopenharmony_ci+ 203be168c0dSopenharmony_ci+// ********** Range ********** 204be168c0dSopenharmony_ci+PrimitivePtr MindIR_Range_CreatePrimitive(int64_t d_type, int64_t start, int64_t limit, int64_t delta); 205be168c0dSopenharmony_ci+int64_t MindIR_Range_GetDType(ConstPrimitivePtr primitive); 206be168c0dSopenharmony_ci+void MindIR_Range_SetDType(PrimitivePtr *primitive, int64_t d_type); 207be168c0dSopenharmony_ci+int64_t MindIR_Range_GetStart(ConstPrimitivePtr primitive); 208be168c0dSopenharmony_ci+void MindIR_Range_SetStart(PrimitivePtr *primitive, int64_t start); 209be168c0dSopenharmony_ci+int64_t MindIR_Range_GetLimit(ConstPrimitivePtr primitive); 210be168c0dSopenharmony_ci+void MindIR_Range_SetLimit(PrimitivePtr *primitive, int64_t limit); 211be168c0dSopenharmony_ci+int64_t MindIR_Range_GetDelta(ConstPrimitivePtr primitive); 212be168c0dSopenharmony_ci+void MindIR_Range_SetDelta(PrimitivePtr *primitive, int64_t delta); 213be168c0dSopenharmony_ci+ 214be168c0dSopenharmony_ci+// ********** RealDiv ********** 215be168c0dSopenharmony_ci+PrimitivePtr MindIR_RealDiv_CreatePrimitive(); 216be168c0dSopenharmony_ci+ 217be168c0dSopenharmony_ci+// ********** Square ********** 218be168c0dSopenharmony_ci+PrimitivePtr MindIR_Square_CreatePrimitive(); 219be168c0dSopenharmony_ci+ 220be168c0dSopenharmony_ci+// ********** Unstack ********** 221be168c0dSopenharmony_ci+PrimitivePtr MindIR_Unstack_CreatePrimitive(int64_t axis); 222be168c0dSopenharmony_ci+int64_t MindIR_Unstack_GetAxis(ConstPrimitivePtr primitive); 223be168c0dSopenharmony_ci+void MindIR_Unstack_SetAxis(PrimitivePtr *primitive, int64_t axis); 224be168c0dSopenharmony_ci+ 225be168c0dSopenharmony_ci+// ********** Select ********** 226be168c0dSopenharmony_ci+PrimitivePtr MindIR_Select_CreatePrimitive(); 227be168c0dSopenharmony_ci+ 228be168c0dSopenharmony_ci+// ********** Erf ********** 229be168c0dSopenharmony_ci+PrimitivePtr MindIR_Erf_CreatePrimitive(); 230be168c0dSopenharmony_ci+ 231be168c0dSopenharmony_ci+// ********** Equal ********** 232be168c0dSopenharmony_ci+PrimitivePtr MindIR_Equal_CreatePrimitive(); 233be168c0dSopenharmony_ci+ 234be168c0dSopenharmony_ci+// ********** Greater ********** 235be168c0dSopenharmony_ci+PrimitivePtr MindIR_Greater_CreatePrimitive(); 236be168c0dSopenharmony_ci+ 237be168c0dSopenharmony_ci+// ********** GreaterEqual ********** 238be168c0dSopenharmony_ci+PrimitivePtr MindIR_GreaterEqual_CreatePrimitive(); 239be168c0dSopenharmony_ci+ 240be168c0dSopenharmony_ci+// ********** NotEqual ********** 241be168c0dSopenharmony_ci+PrimitivePtr MindIR_NotEqual_CreatePrimitive(); 242be168c0dSopenharmony_ci+ 243be168c0dSopenharmony_ci+// ********** LeakyRelu ********** 244be168c0dSopenharmony_ci+PrimitivePtr MindIR_LeakyRelu_CreatePrimitive(float negative_slope); 245be168c0dSopenharmony_ci+float MindIR_LeakyRelu_GetNegativeSlope(ConstPrimitivePtr primitive); 246be168c0dSopenharmony_ci+void MindIR_LeakyRelu_SetNegativeSlope(PrimitivePtr *primitive, float negative_slope); 247be168c0dSopenharmony_ci+ 248be168c0dSopenharmony_ci+// ********** LSTM ********** 249be168c0dSopenharmony_ci+PrimitivePtr MindIR_LSTM_CreatePrimitive( 250be168c0dSopenharmony_ci+ bool bidirectional, bool has_bias, int64_t input_size, int64_t hidden_size, int64_t num_layers, 251be168c0dSopenharmony_ci+ int64_t num_directions, float dropout, float zoneout_cell, float zoneout_hidden, int64_t proj_size); 252be168c0dSopenharmony_ci+bool MindIR_LSTM_GetBidirectional(ConstPrimitivePtr primitive); 253be168c0dSopenharmony_ci+void MindIR_LSTM_SetBidirectional(PrimitivePtr *primitive, bool bidirectional); 254be168c0dSopenharmony_ci+bool MindIR_LSTM_GetHasBias(ConstPrimitivePtr primitive); 255be168c0dSopenharmony_ci+void MindIR_LSTM_SetHasBias(PrimitivePtr *primitive, bool has_bias); 256be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetInputSize(ConstPrimitivePtr primitive); 257be168c0dSopenharmony_ci+void MindIR_LSTM_SetInputSize(PrimitivePtr *primitive, int64_t input_size); 258be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetHiddenSize(ConstPrimitivePtr primitive); 259be168c0dSopenharmony_ci+void MindIR_LSTM_SetHiddenSize(PrimitivePtr *primitive, int64_t hidden_size); 260be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetNumLayers(ConstPrimitivePtr primitive); 261be168c0dSopenharmony_ci+void MindIR_LSTM_SetNumLayers(PrimitivePtr *primitive, int64_t num_layers); 262be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetNumDirections(ConstPrimitivePtr primitive); 263be168c0dSopenharmony_ci+void MindIR_LSTM_SetNumDirections(PrimitivePtr *primitive, int64_t num_directions); 264be168c0dSopenharmony_ci+float MindIR_LSTM_GetDropout(ConstPrimitivePtr primitive); 265be168c0dSopenharmony_ci+void MindIR_LSTM_SetDropout(PrimitivePtr *primitive, float dropout); 266be168c0dSopenharmony_ci+float MindIR_LSTM_GetZoneoutCell(ConstPrimitivePtr primitive); 267be168c0dSopenharmony_ci+void MindIR_LSTM_SetZoneoutCell(PrimitivePtr *primitive, float zoneout_cell); 268be168c0dSopenharmony_ci+float MindIR_LSTM_GetZoneoutHidden(ConstPrimitivePtr primitive); 269be168c0dSopenharmony_ci+void MindIR_LSTM_SetZoneoutHidden(PrimitivePtr *primitive, float zoneout_hidden); 270be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetProjSize(ConstPrimitivePtr primitive); 271be168c0dSopenharmony_ci+void MindIR_LSTM_SetProjSize(PrimitivePtr *primitive, int64_t proj_size); 272be168c0dSopenharmony_ci+ 273be168c0dSopenharmony_ci+// ********** Clip ********** 274be168c0dSopenharmony_ci+PrimitivePtr MindIR_Clip_CreatePrimitive(float max, float min); 275be168c0dSopenharmony_ci+float MindIR_Clip_GetMax(ConstPrimitivePtr primitive); 276be168c0dSopenharmony_ci+void MindIR_Clip_SetMax(PrimitivePtr *primitive, float max); 277be168c0dSopenharmony_ci+float MindIR_Clip_GetMin(ConstPrimitivePtr primitive); 278be168c0dSopenharmony_ci+void MindIR_Clip_SetMin(PrimitivePtr *primitive, float min); 279be168c0dSopenharmony_ci+ 280be168c0dSopenharmony_ci // ********** Custom ********** 281be168c0dSopenharmony_ci std::vector<const mindspore::schema::Attribute *> MindIR_Custom_GetAttr(ConstPrimitivePtr primitive); 282be168c0dSopenharmony_ci std::string MindIR_Attribute_GetName(const mindspore::schema::Attribute &attr); 283be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/include/mindir_tensor.h b/mindspore/lite/mindir/include/mindir_tensor.h 284be168c0dSopenharmony_ciindex 836bc8af..c1ac89bf 100644 285be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/include/mindir_tensor.h 286be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/include/mindir_tensor.h 287be168c0dSopenharmony_ci@@ -3,26 +3,6 @@ 288be168c0dSopenharmony_ci #include "mindir_lite_graph.h" 289be168c0dSopenharmony_ci #include "mindir_types.h" 290be168c0dSopenharmony_ci 291be168c0dSopenharmony_ci-namespace OHOS { 292be168c0dSopenharmony_ci-namespace HDI { 293be168c0dSopenharmony_ci-namespace Nnrt { 294be168c0dSopenharmony_ci-namespace V1_0 { 295be168c0dSopenharmony_ci-struct SharedBuffer; 296be168c0dSopenharmony_ci-} // namespace V1_0 297be168c0dSopenharmony_ci-} // namespace Nnrt 298be168c0dSopenharmony_ci-} // namespace HDI 299be168c0dSopenharmony_ci-} // namespace OHOS 300be168c0dSopenharmony_ci- 301be168c0dSopenharmony_ci-namespace OHOS { 302be168c0dSopenharmony_ci-namespace HDI { 303be168c0dSopenharmony_ci-namespace Nnrt { 304be168c0dSopenharmony_ci-namespace V2_0 { 305be168c0dSopenharmony_ci-struct SharedBuffer; 306be168c0dSopenharmony_ci-} // namespace V2_0 307be168c0dSopenharmony_ci-} // namespace Nnrt 308be168c0dSopenharmony_ci-} // namespace HDI 309be168c0dSopenharmony_ci-} // namespace OHOS 310be168c0dSopenharmony_ci- 311be168c0dSopenharmony_ci namespace mindspore { 312be168c0dSopenharmony_ci namespace lite { 313be168c0dSopenharmony_ci 314be168c0dSopenharmony_ci@@ -39,15 +19,6 @@ std::vector<int32_t> MindIR_Tensor_GetDims(ConstTensorPtr tensor); 315be168c0dSopenharmony_ci void MindIR_Tensor_SetDims(TensorPtr *tensor, const std::vector<int32_t> &dims); 316be168c0dSopenharmony_ci Format MindIR_Tensor_GetFormat(ConstTensorPtr tensor); 317be168c0dSopenharmony_ci void MindIR_Tensor_SetFormat(TensorPtr *tensor, Format format); 318be168c0dSopenharmony_ci- 319be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V1_0::SharedBuffer MindIR_Tensor_GetData(ConstTensorPtr tensor, 320be168c0dSopenharmony_ci- const OHOS::HDI::Nnrt::V1_0::SharedBuffer &buffer_templete, 321be168c0dSopenharmony_ci- uint8_t *mmap_ptr, unsigned int offset); 322be168c0dSopenharmony_ci- 323be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V2_0::SharedBuffer MindIR_Tensor_GetData_V2_0(ConstTensorPtr tensor, 324be168c0dSopenharmony_ci- const OHOS::HDI::Nnrt::V2_0::SharedBuffer &buffer_templete, 325be168c0dSopenharmony_ci- uint8_t *mmap_ptr, unsigned int offset); 326be168c0dSopenharmony_ci- 327be168c0dSopenharmony_ci void MindIR_Tensor_SetData(TensorPtr *tensor, const std::vector<uint8_t> &data); 328be168c0dSopenharmony_ci std::vector<uint8_t> MindIR_Tensor_GetData(ConstTensorPtr tensor); 329be168c0dSopenharmony_ci std::vector<QuantParam> MindIR_Tensor_GetQuantParams(ConstTensorPtr tensor); 330be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/include/mindir_types.h b/mindspore/lite/mindir/include/mindir_types.h 331be168c0dSopenharmony_ciindex ad272f8e..3ee6aca1 100644 332be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/include/mindir_types.h 333be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/include/mindir_types.h 334be168c0dSopenharmony_ci@@ -53,34 +53,51 @@ enum QuantType : int8_t { 335be168c0dSopenharmony_ci 336be168c0dSopenharmony_ci enum NodeType : uint32_t { 337be168c0dSopenharmony_ci NODE_TYPE_NONE = 0, 338be168c0dSopenharmony_ci+ NODE_TYPE_ABS = 1, 339be168c0dSopenharmony_ci NODE_TYPE_ACTIVATION = 2, 340be168c0dSopenharmony_ci NODE_TYPE_ADD_FUSION = 5, 341be168c0dSopenharmony_ci NODE_TYPE_ARGMAX_FUSION = 11, 342be168c0dSopenharmony_ci NODE_TYPE_AVG_POOL_FUSION = 17, 343be168c0dSopenharmony_ci NODE_TYPE_BATCH_TO_SPACE_ND = 22, 344be168c0dSopenharmony_ci NODE_TYPE_BIAS_ADD = 23, 345be168c0dSopenharmony_ci+ NODE_TYPE_BROADCAST_TO = 27, 346be168c0dSopenharmony_ci NODE_TYPE_CAST = 28, 347be168c0dSopenharmony_ci+ NODE_TYPE_CLIP = 30, 348be168c0dSopenharmony_ci NODE_TYPE_CONCAT = 31, 349be168c0dSopenharmony_ci NODE_TYPE_CONV2D_FUSION = 35, 350be168c0dSopenharmony_ci NODE_TYPE_CONV2D_TRANSPOSE_FUSION = 36, 351be168c0dSopenharmony_ci+ NODE_TYPE_CONSTANT_OF_SHAPE = 38, 352be168c0dSopenharmony_ci+ NODE_TYPE_DEPTH_TO_SPACE = 45, 353be168c0dSopenharmony_ci NODE_TYPE_DIV_FUSION = 47, 354be168c0dSopenharmony_ci NODE_TYPE_ELTWISE = 52, 355be168c0dSopenharmony_ci+ NODE_TYPE_EQUAL = 53, 356be168c0dSopenharmony_ci+ NODE_TYPE_EXPFUSION = 55, 357be168c0dSopenharmony_ci NODE_TYPE_EXPAND_DIMS = 56, 358be168c0dSopenharmony_ci+ NODE_TYPE_FLATTEN = 61, 359be168c0dSopenharmony_ci NODE_TYPE_FILL = 66, 360be168c0dSopenharmony_ci NODE_TYPE_FULL_CONNECTION = 67, 361be168c0dSopenharmony_ci NODE_TYPE_FUSED_BATCH_NORM = 68, 362be168c0dSopenharmony_ci NODE_TYPE_GATHER = 69, 363be168c0dSopenharmony_ci+ NODE_TYPE_GREATER = 71, 364be168c0dSopenharmony_ci+ NODE_TYPE_GREATER_EQUAL = 72, 365be168c0dSopenharmony_ci+ NODE_TYPE_INSTANCE_NORM = 74, 366be168c0dSopenharmony_ci NODE_TYPE_LAYER_NORM_FUSION = 75, 367be168c0dSopenharmony_ci+ NODE_TYPE_LEAKY_RELU = 76, 368be168c0dSopenharmony_ci+ NODE_TYPE_LESS = 77, 369be168c0dSopenharmony_ci NODE_TYPE_LESS_EQUAL = 78, 370be168c0dSopenharmony_ci+ NODE_TYPE_LSTM = 87, 371be168c0dSopenharmony_ci NODE_TYPE_MATMUL_FUSION = 89, 372be168c0dSopenharmony_ci NODE_TYPE_MAXIMUM = 90, 373be168c0dSopenharmony_ci NODE_TYPE_MAX_POOL_FUSION = 92, 374be168c0dSopenharmony_ci NODE_TYPE_MUL_FUSION = 99, 375be168c0dSopenharmony_ci+ NODE_TYPE_NOT_EQUAL = 103, 376be168c0dSopenharmony_ci NODE_TYPE_ONE_HOT = 105, 377be168c0dSopenharmony_ci NODE_TYPE_PAD_FUSION = 107, 378be168c0dSopenharmony_ci NODE_TYPE_POW_FUSION = 110, 379be168c0dSopenharmony_ci NODE_TYPE_PRELU_FUSION = 112, 380be168c0dSopenharmony_ci NODE_TYPE_QUANT_DTYPE_CAST = 113, 381be168c0dSopenharmony_ci+ NODE_TYPE_RANGE = 115, 382be168c0dSopenharmony_ci+ NODE_TYPE_REAL_DIV = 117, 383be168c0dSopenharmony_ci NODE_TYPE_REDUCE_FUSION = 118, 384be168c0dSopenharmony_ci NODE_TYPE_RESHAPE = 119, 385be168c0dSopenharmony_ci NODE_TYPE_RESIZE = 120, 386be168c0dSopenharmony_ci@@ -93,6 +110,7 @@ enum NodeType : uint32_t { 387be168c0dSopenharmony_ci NODE_TYPE_SPLIT = 145, 388be168c0dSopenharmony_ci NODE_TYPE_SQRT = 146, 389be168c0dSopenharmony_ci NODE_TYPE_SQUEEZE = 147, 390be168c0dSopenharmony_ci+ NODE_TYPE_SQUARE = 148, 391be168c0dSopenharmony_ci NODE_TYPE_SQUARED_DIFFERENCE = 149, 392be168c0dSopenharmony_ci NODE_TYPE_STACK = 150, 393be168c0dSopenharmony_ci NODE_TYPE_STRIDED_SLICE = 151, 394be168c0dSopenharmony_ci@@ -101,6 +119,9 @@ enum NodeType : uint32_t { 395be168c0dSopenharmony_ci NODE_TYPE_TOPK_FUSION = 161, 396be168c0dSopenharmony_ci NODE_TYPE_TRANSPOSE = 162, 397be168c0dSopenharmony_ci NODE_TYPE_UNSQUEEZE = 165, 398be168c0dSopenharmony_ci+ NODE_TYPE_UNSTACK = 166, 399be168c0dSopenharmony_ci+ NODE_TYPE_SELECT = 170, 400be168c0dSopenharmony_ci+ NODE_TYPE_ERF = 178, 401be168c0dSopenharmony_ci NODE_TYPE_CUSTOM = 191, 402be168c0dSopenharmony_ci }; 403be168c0dSopenharmony_ci 404be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/src/mindir.cc b/mindspore/lite/mindir/src/mindir.cc 405be168c0dSopenharmony_ciindex 374bbef5..36056c59 100644 406be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/src/mindir.cc 407be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/src/mindir.cc 408be168c0dSopenharmony_ci@@ -4339,6 +4339,1185 @@ void MindIR_Unsqueeze_SetAxis(PrimitivePtr *primitive, const std::vector<int64_t 409be168c0dSopenharmony_ci } 410be168c0dSopenharmony_ci } 411be168c0dSopenharmony_ci 412be168c0dSopenharmony_ci+// ********** Abs ********** 413be168c0dSopenharmony_ci+PrimitivePtr MindIR_Abs_CreatePrimitive() { 414be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 415be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateAbs(fbb); 416be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ABS), ops_offset.o); 417be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 418be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 419be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 420be168c0dSopenharmony_ci+ return ret_value; 421be168c0dSopenharmony_ci+} 422be168c0dSopenharmony_ci+ 423be168c0dSopenharmony_ci+// ********** BroadcastTo ********** 424be168c0dSopenharmony_ci+PrimitivePtr MindIR_BroadcastTo_CreatePrimitive(const std::vector<int64_t> &shape) { 425be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 426be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateBroadcastTo(fbb, fbb.CreateVector(shape.data(), shape.size())); 427be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_BROADCAST_TO), ops_offset.o); 428be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 429be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 430be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 431be168c0dSopenharmony_ci+ return ret_value; 432be168c0dSopenharmony_ci+} 433be168c0dSopenharmony_ci+ 434be168c0dSopenharmony_ci+std::vector<int64_t> MindIR_BroadcastTo_GetShape(ConstPrimitivePtr primitive) { 435be168c0dSopenharmony_ci+ if (primitive != nullptr) { 436be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 437be168c0dSopenharmony_ci+ auto value = prim->value_as_BroadcastTo(); 438be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 439be168c0dSopenharmony_ci+ std::vector<int64_t> result; 440be168c0dSopenharmony_ci+ auto src = value->shape(); 441be168c0dSopenharmony_ci+ result.resize(src->size()); 442be168c0dSopenharmony_ci+ std::transform(src->begin(), src->end(), result.begin(), [](int64_t item) { return item; }); 443be168c0dSopenharmony_ci+ return result; 444be168c0dSopenharmony_ci+ } else { 445be168c0dSopenharmony_ci+ return {}; 446be168c0dSopenharmony_ci+ } 447be168c0dSopenharmony_ci+ } else { 448be168c0dSopenharmony_ci+ return {}; 449be168c0dSopenharmony_ci+ } 450be168c0dSopenharmony_ci+} 451be168c0dSopenharmony_ci+ 452be168c0dSopenharmony_ci+void MindIR_BroadcastTo_SetShape(PrimitivePtr *primitive, const std::vector<int64_t> &shape) { 453be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 454be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 455be168c0dSopenharmony_ci+ auto value = prim->value_as_BroadcastTo(); 456be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 457be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 458be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateBroadcastTo( 459be168c0dSopenharmony_ci+ fbb, fbb.CreateVector(shape.data(), shape.size())); 460be168c0dSopenharmony_ci+ auto prim_offset = 461be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_BROADCAST_TO), ops_offset.o); 462be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 463be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 464be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 465be168c0dSopenharmony_ci+ *primitive = ret_value; 466be168c0dSopenharmony_ci+ } 467be168c0dSopenharmony_ci+ } 468be168c0dSopenharmony_ci+} 469be168c0dSopenharmony_ci+ 470be168c0dSopenharmony_ci+// ********** ConstantOfShape ********** 471be168c0dSopenharmony_ci+PrimitivePtr MindIR_ConstantOfShape_CreatePrimitive(int64_t data_type, const std::vector<float> &value) { 472be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 473be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateConstantOfShape(fbb, data_type, fbb.CreateVector(value.data(), value.size())); 474be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_CONSTANT_OF_SHAPE), ops_offset.o); 475be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 476be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 477be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 478be168c0dSopenharmony_ci+ return ret_value; 479be168c0dSopenharmony_ci+} 480be168c0dSopenharmony_ci+ 481be168c0dSopenharmony_ci+int64_t MindIR_ConstantOfShape_GetDataType(ConstPrimitivePtr primitive) { 482be168c0dSopenharmony_ci+ if (primitive != nullptr) { 483be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 484be168c0dSopenharmony_ci+ auto value_ = prim->value_as_ConstantOfShape(); 485be168c0dSopenharmony_ci+ if (prim != nullptr && value_ != nullptr) { 486be168c0dSopenharmony_ci+ return value_->data_type(); 487be168c0dSopenharmony_ci+ } else { 488be168c0dSopenharmony_ci+ return 0; 489be168c0dSopenharmony_ci+ } 490be168c0dSopenharmony_ci+ } else { 491be168c0dSopenharmony_ci+ return 0; 492be168c0dSopenharmony_ci+ } 493be168c0dSopenharmony_ci+} 494be168c0dSopenharmony_ci+ 495be168c0dSopenharmony_ci+void MindIR_ConstantOfShape_SetDataType(PrimitivePtr *primitive, int64_t data_type) { 496be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 497be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 498be168c0dSopenharmony_ci+ auto value_ = prim->value_as_ConstantOfShape(); 499be168c0dSopenharmony_ci+ if (prim != nullptr && value_ != nullptr) { 500be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 501be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateConstantOfShape(fbb, data_type, fbb.CreateVector(value_->value()->data(), value_->value()->size())); 502be168c0dSopenharmony_ci+ auto prim_offset = 503be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_CONSTANT_OF_SHAPE), ops_offset.o); 504be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 505be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 506be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 507be168c0dSopenharmony_ci+ *primitive = ret_value; 508be168c0dSopenharmony_ci+ } 509be168c0dSopenharmony_ci+ } 510be168c0dSopenharmony_ci+} 511be168c0dSopenharmony_ci+ 512be168c0dSopenharmony_ci+std::vector<float> MindIR_ConstantOfShape_GetValue(ConstPrimitivePtr primitive) { 513be168c0dSopenharmony_ci+ if (primitive != nullptr) { 514be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 515be168c0dSopenharmony_ci+ auto value_ = prim->value_as_ConstantOfShape(); 516be168c0dSopenharmony_ci+ if (prim != nullptr && value_ != nullptr) { 517be168c0dSopenharmony_ci+ std::vector<float> result; 518be168c0dSopenharmony_ci+ auto src = value_->value(); 519be168c0dSopenharmony_ci+ result.resize(src->size()); 520be168c0dSopenharmony_ci+ std::transform(src->begin(), src->end(), result.begin(), [](float item) { return item; }); 521be168c0dSopenharmony_ci+ return result; 522be168c0dSopenharmony_ci+ } else { 523be168c0dSopenharmony_ci+ return {}; 524be168c0dSopenharmony_ci+ } 525be168c0dSopenharmony_ci+ } else { 526be168c0dSopenharmony_ci+ return {}; 527be168c0dSopenharmony_ci+ } 528be168c0dSopenharmony_ci+} 529be168c0dSopenharmony_ci+ 530be168c0dSopenharmony_ci+void MindIR_ConstantOfShape_SetValue(PrimitivePtr *primitive, const std::vector<float> &value) { 531be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 532be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 533be168c0dSopenharmony_ci+ auto value_ = prim->value_as_ConstantOfShape(); 534be168c0dSopenharmony_ci+ if (prim != nullptr && value_ != nullptr) { 535be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 536be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateConstantOfShape( 537be168c0dSopenharmony_ci+ fbb, value_->data_type(), fbb.CreateVector(value.data(), value.size())); 538be168c0dSopenharmony_ci+ auto prim_offset = 539be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_CONSTANT_OF_SHAPE), ops_offset.o); 540be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 541be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 542be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 543be168c0dSopenharmony_ci+ *primitive = ret_value; 544be168c0dSopenharmony_ci+ } 545be168c0dSopenharmony_ci+ } 546be168c0dSopenharmony_ci+} 547be168c0dSopenharmony_ci+ 548be168c0dSopenharmony_ci+// ********** DepthToSpace ********** 549be168c0dSopenharmony_ci+PrimitivePtr MindIR_DepthToSpace_CreatePrimitive(int64_t block_size, Format &format, std::string mode) { 550be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 551be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateDepthToSpace(fbb, block_size, static_cast<schema::Format>(format), fbb.CreateString(mode)); 552be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_DEPTH_TO_SPACE), ops_offset.o); 553be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 554be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 555be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 556be168c0dSopenharmony_ci+ return ret_value; 557be168c0dSopenharmony_ci+} 558be168c0dSopenharmony_ci+ 559be168c0dSopenharmony_ci+int64_t MindIR_DepthToSpace_GetBlockSize(ConstPrimitivePtr primitive) { 560be168c0dSopenharmony_ci+ if (primitive != nullptr) { 561be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 562be168c0dSopenharmony_ci+ auto value = prim->value_as_DepthToSpace(); 563be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 564be168c0dSopenharmony_ci+ return value->block_size(); 565be168c0dSopenharmony_ci+ } else { 566be168c0dSopenharmony_ci+ return 0; 567be168c0dSopenharmony_ci+ } 568be168c0dSopenharmony_ci+ } else { 569be168c0dSopenharmony_ci+ return 0; 570be168c0dSopenharmony_ci+ } 571be168c0dSopenharmony_ci+} 572be168c0dSopenharmony_ci+ 573be168c0dSopenharmony_ci+void MindIR_DepthToSpace_SetBlockSize(PrimitivePtr *primitive, int64_t block_size) { 574be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 575be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 576be168c0dSopenharmony_ci+ auto value = prim->value_as_DepthToSpace(); 577be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 578be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 579be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateDepthToSpace(fbb, block_size, static_cast<schema::Format>(value->format()), 580be168c0dSopenharmony_ci+ fbb.CreateString(std::string(value->mode()->c_str(), value->mode()->size()))); 581be168c0dSopenharmony_ci+ auto prim_offset = 582be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_DEPTH_TO_SPACE), ops_offset.o); 583be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 584be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 585be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 586be168c0dSopenharmony_ci+ *primitive = ret_value; 587be168c0dSopenharmony_ci+ } 588be168c0dSopenharmony_ci+ } 589be168c0dSopenharmony_ci+} 590be168c0dSopenharmony_ci+ 591be168c0dSopenharmony_ci+Format MindIR_DepthToSpace_GetFormat(ConstPrimitivePtr primitive) { 592be168c0dSopenharmony_ci+ if (primitive != nullptr) { 593be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 594be168c0dSopenharmony_ci+ auto value = prim->value_as_DepthToSpace(); 595be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 596be168c0dSopenharmony_ci+ return static_cast<Format>(value->format()); 597be168c0dSopenharmony_ci+ } else { 598be168c0dSopenharmony_ci+ Format en = static_cast<Format>(0); 599be168c0dSopenharmony_ci+ return en; 600be168c0dSopenharmony_ci+ } 601be168c0dSopenharmony_ci+ } else { 602be168c0dSopenharmony_ci+ Format en = static_cast<Format>(0); 603be168c0dSopenharmony_ci+ return en; 604be168c0dSopenharmony_ci+ } 605be168c0dSopenharmony_ci+} 606be168c0dSopenharmony_ci+ 607be168c0dSopenharmony_ci+void MindIR_DepthToSpace_SetFormat(PrimitivePtr *primitive, Format &format) { 608be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 609be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 610be168c0dSopenharmony_ci+ auto value = prim->value_as_DepthToSpace(); 611be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 612be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 613be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateDepthToSpace(fbb, value->block_size(), static_cast<schema::Format>(format), 614be168c0dSopenharmony_ci+ fbb.CreateString(std::string(value->mode()->c_str(), value->mode()->size()))); 615be168c0dSopenharmony_ci+ auto prim_offset = 616be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_DEPTH_TO_SPACE), ops_offset.o); 617be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 618be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 619be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 620be168c0dSopenharmony_ci+ *primitive = ret_value; 621be168c0dSopenharmony_ci+ } 622be168c0dSopenharmony_ci+ } 623be168c0dSopenharmony_ci+} 624be168c0dSopenharmony_ci+ 625be168c0dSopenharmony_ci+std::string MindIR_DepthToSpace_GetMode(ConstPrimitivePtr primitive) { 626be168c0dSopenharmony_ci+ if (primitive != nullptr) { 627be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 628be168c0dSopenharmony_ci+ auto value = prim->value_as_DepthToSpace(); 629be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 630be168c0dSopenharmony_ci+ return std::string(value->mode()->c_str(),value->mode()->size()); 631be168c0dSopenharmony_ci+ } else { 632be168c0dSopenharmony_ci+ return nullptr; 633be168c0dSopenharmony_ci+ } 634be168c0dSopenharmony_ci+ } else { 635be168c0dSopenharmony_ci+ return nullptr; 636be168c0dSopenharmony_ci+ } 637be168c0dSopenharmony_ci+} 638be168c0dSopenharmony_ci+ 639be168c0dSopenharmony_ci+void MindIR_DepthToSpace_SetMode(PrimitivePtr *primitive, std::string mode) { 640be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 641be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 642be168c0dSopenharmony_ci+ auto value = prim->value_as_DepthToSpace(); 643be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 644be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 645be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateDepthToSpace(fbb, value->block_size(), static_cast<schema::Format>(value->format()), fbb.CreateString(mode)); 646be168c0dSopenharmony_ci+ auto prim_offset = 647be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_DEPTH_TO_SPACE), ops_offset.o); 648be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 649be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 650be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 651be168c0dSopenharmony_ci+ *primitive = ret_value; 652be168c0dSopenharmony_ci+ } 653be168c0dSopenharmony_ci+ } 654be168c0dSopenharmony_ci+} 655be168c0dSopenharmony_ci+ 656be168c0dSopenharmony_ci+// ********** ExpFusion ********** 657be168c0dSopenharmony_ci+PrimitivePtr MindIR_ExpFusion_CreatePrimitive(float base, float scale, float shift) { 658be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 659be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateExpFusion(fbb, base, scale, shift); 660be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_EXPFUSION), ops_offset.o); 661be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 662be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 663be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 664be168c0dSopenharmony_ci+ return ret_value; 665be168c0dSopenharmony_ci+} 666be168c0dSopenharmony_ci+ 667be168c0dSopenharmony_ci+float MindIR_ExpFusion_GetBase(ConstPrimitivePtr primitive) { 668be168c0dSopenharmony_ci+ if (primitive != nullptr) { 669be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 670be168c0dSopenharmony_ci+ auto value = prim->value_as_ExpFusion(); 671be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 672be168c0dSopenharmony_ci+ return value->base(); 673be168c0dSopenharmony_ci+ } else { 674be168c0dSopenharmony_ci+ return .0; 675be168c0dSopenharmony_ci+ } 676be168c0dSopenharmony_ci+ } else { 677be168c0dSopenharmony_ci+ return .0; 678be168c0dSopenharmony_ci+ } 679be168c0dSopenharmony_ci+} 680be168c0dSopenharmony_ci+ 681be168c0dSopenharmony_ci+void MindIR_ExpFusion_SetBase(PrimitivePtr *primitive, float base) { 682be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 683be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 684be168c0dSopenharmony_ci+ auto value = prim->value_as_ExpFusion(); 685be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 686be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 687be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateExpFusion(fbb, base, value->scale(), value->shift()); 688be168c0dSopenharmony_ci+ auto prim_offset = 689be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_EXPFUSION), ops_offset.o); 690be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 691be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 692be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 693be168c0dSopenharmony_ci+ *primitive = ret_value; 694be168c0dSopenharmony_ci+ } 695be168c0dSopenharmony_ci+ } 696be168c0dSopenharmony_ci+} 697be168c0dSopenharmony_ci+ 698be168c0dSopenharmony_ci+float MindIR_ExpFusion_GetScale(ConstPrimitivePtr primitive) { 699be168c0dSopenharmony_ci+ if (primitive != nullptr) { 700be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 701be168c0dSopenharmony_ci+ auto value = prim->value_as_ExpFusion(); 702be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 703be168c0dSopenharmony_ci+ return value->scale(); 704be168c0dSopenharmony_ci+ } else { 705be168c0dSopenharmony_ci+ return .0; 706be168c0dSopenharmony_ci+ } 707be168c0dSopenharmony_ci+ } else { 708be168c0dSopenharmony_ci+ return .0; 709be168c0dSopenharmony_ci+ } 710be168c0dSopenharmony_ci+} 711be168c0dSopenharmony_ci+ 712be168c0dSopenharmony_ci+void MindIR_ExpFusion_SetScale(PrimitivePtr *primitive, float scale) { 713be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 714be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 715be168c0dSopenharmony_ci+ auto value = prim->value_as_ExpFusion(); 716be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 717be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 718be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateExpFusion(fbb, value->base(), scale, value->shift()); 719be168c0dSopenharmony_ci+ auto prim_offset = 720be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_EXPFUSION), ops_offset.o); 721be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 722be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 723be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 724be168c0dSopenharmony_ci+ *primitive = ret_value; 725be168c0dSopenharmony_ci+ } 726be168c0dSopenharmony_ci+ } 727be168c0dSopenharmony_ci+} 728be168c0dSopenharmony_ci+ 729be168c0dSopenharmony_ci+float MindIR_ExpFusion_GetShift(ConstPrimitivePtr primitive) { 730be168c0dSopenharmony_ci+ if (primitive != nullptr) { 731be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 732be168c0dSopenharmony_ci+ auto value = prim->value_as_ExpFusion(); 733be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 734be168c0dSopenharmony_ci+ return value->shift(); 735be168c0dSopenharmony_ci+ } else { 736be168c0dSopenharmony_ci+ return .0; 737be168c0dSopenharmony_ci+ } 738be168c0dSopenharmony_ci+ } else { 739be168c0dSopenharmony_ci+ return .0; 740be168c0dSopenharmony_ci+ } 741be168c0dSopenharmony_ci+} 742be168c0dSopenharmony_ci+ 743be168c0dSopenharmony_ci+void MindIR_ExpFusion_SetShift(PrimitivePtr *primitive, float shift) { 744be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 745be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 746be168c0dSopenharmony_ci+ auto value = prim->value_as_ExpFusion(); 747be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 748be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 749be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateExpFusion(fbb, value->base(), value->scale(), shift); 750be168c0dSopenharmony_ci+ auto prim_offset = 751be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_EXPFUSION), ops_offset.o); 752be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 753be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 754be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 755be168c0dSopenharmony_ci+ *primitive = ret_value; 756be168c0dSopenharmony_ci+ } 757be168c0dSopenharmony_ci+ } 758be168c0dSopenharmony_ci+} 759be168c0dSopenharmony_ci+ 760be168c0dSopenharmony_ci+// ********** Flatten ********** 761be168c0dSopenharmony_ci+PrimitivePtr MindIR_Flatten_CreatePrimitive(int64_t axis) { 762be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 763be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateFlatten(fbb, axis); 764be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_FLATTEN), ops_offset.o); 765be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 766be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 767be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 768be168c0dSopenharmony_ci+ return ret_value; 769be168c0dSopenharmony_ci+} 770be168c0dSopenharmony_ci+ 771be168c0dSopenharmony_ci+int64_t MindIR_Flatten_GetAxis(ConstPrimitivePtr primitive) { 772be168c0dSopenharmony_ci+ if (primitive != nullptr) { 773be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 774be168c0dSopenharmony_ci+ auto value = prim->value_as_Flatten(); 775be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 776be168c0dSopenharmony_ci+ return value->axis(); 777be168c0dSopenharmony_ci+ } else { 778be168c0dSopenharmony_ci+ return 0; 779be168c0dSopenharmony_ci+ } 780be168c0dSopenharmony_ci+ } else { 781be168c0dSopenharmony_ci+ return 0; 782be168c0dSopenharmony_ci+ } 783be168c0dSopenharmony_ci+} 784be168c0dSopenharmony_ci+ 785be168c0dSopenharmony_ci+void MindIR_Flatten_SetAxis(PrimitivePtr *primitive, int64_t axis) { 786be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 787be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 788be168c0dSopenharmony_ci+ auto value = prim->value_as_Flatten(); 789be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 790be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 791be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateFlatten(fbb, axis); 792be168c0dSopenharmony_ci+ auto prim_offset = 793be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_FLATTEN), ops_offset.o); 794be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 795be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 796be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 797be168c0dSopenharmony_ci+ *primitive = ret_value; 798be168c0dSopenharmony_ci+ } 799be168c0dSopenharmony_ci+ } 800be168c0dSopenharmony_ci+} 801be168c0dSopenharmony_ci+ 802be168c0dSopenharmony_ci+// ********** InstanceNorm ********** 803be168c0dSopenharmony_ci+PrimitivePtr MindIR_InstanceNorm_CreatePrimitive(float epsilon) { 804be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 805be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateInstanceNorm(fbb, epsilon); 806be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_INSTANCE_NORM), ops_offset.o); 807be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 808be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 809be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 810be168c0dSopenharmony_ci+ return ret_value; 811be168c0dSopenharmony_ci+} 812be168c0dSopenharmony_ci+ 813be168c0dSopenharmony_ci+float MindIR_InstanceNorm_GetEpsilon(ConstPrimitivePtr primitive) { 814be168c0dSopenharmony_ci+ if (primitive != nullptr) { 815be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 816be168c0dSopenharmony_ci+ auto value = prim->value_as_InstanceNorm(); 817be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 818be168c0dSopenharmony_ci+ return value->epsilon(); 819be168c0dSopenharmony_ci+ } else { 820be168c0dSopenharmony_ci+ return .0; 821be168c0dSopenharmony_ci+ } 822be168c0dSopenharmony_ci+ } else { 823be168c0dSopenharmony_ci+ return .0; 824be168c0dSopenharmony_ci+ } 825be168c0dSopenharmony_ci+} 826be168c0dSopenharmony_ci+ 827be168c0dSopenharmony_ci+void MindIR_InstanceNorm_SetEpsilon(PrimitivePtr *primitive, float epsilon) { 828be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 829be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 830be168c0dSopenharmony_ci+ auto value = prim->value_as_InstanceNorm(); 831be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 832be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 833be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateInstanceNorm(fbb, epsilon); 834be168c0dSopenharmony_ci+ auto prim_offset = 835be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_INSTANCE_NORM), ops_offset.o); 836be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 837be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 838be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 839be168c0dSopenharmony_ci+ *primitive = ret_value; 840be168c0dSopenharmony_ci+ } 841be168c0dSopenharmony_ci+ } 842be168c0dSopenharmony_ci+} 843be168c0dSopenharmony_ci+ 844be168c0dSopenharmony_ci+// ********** Less ********** 845be168c0dSopenharmony_ci+PrimitivePtr MindIR_Less_CreatePrimitive() { 846be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 847be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateLess(fbb); 848be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LESS), ops_offset.o); 849be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 850be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 851be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 852be168c0dSopenharmony_ci+ return ret_value; 853be168c0dSopenharmony_ci+} 854be168c0dSopenharmony_ci+ 855be168c0dSopenharmony_ci+// ********** Range ********** 856be168c0dSopenharmony_ci+PrimitivePtr MindIR_Range_CreatePrimitive(int64_t d_type, int64_t start, int64_t limit, int64_t delta) { 857be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 858be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateRange(fbb, d_type, start, limit, delta); 859be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_RANGE), ops_offset.o); 860be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 861be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 862be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 863be168c0dSopenharmony_ci+ return ret_value; 864be168c0dSopenharmony_ci+} 865be168c0dSopenharmony_ci+ 866be168c0dSopenharmony_ci+int64_t MindIR_Range_GetDType(ConstPrimitivePtr primitive) { 867be168c0dSopenharmony_ci+ if (primitive != nullptr) { 868be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 869be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 870be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 871be168c0dSopenharmony_ci+ return value->d_type(); 872be168c0dSopenharmony_ci+ } else { 873be168c0dSopenharmony_ci+ return 0; 874be168c0dSopenharmony_ci+ } 875be168c0dSopenharmony_ci+ } else { 876be168c0dSopenharmony_ci+ return 0; 877be168c0dSopenharmony_ci+ } 878be168c0dSopenharmony_ci+} 879be168c0dSopenharmony_ci+ 880be168c0dSopenharmony_ci+void MindIR_Range_SetDType(PrimitivePtr *primitive, int64_t d_type) { 881be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 882be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 883be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 884be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 885be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 886be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateRange(fbb, d_type, value->start(), value->limit(), value->delta()); 887be168c0dSopenharmony_ci+ auto prim_offset = 888be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_RANGE), ops_offset.o); 889be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 890be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 891be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 892be168c0dSopenharmony_ci+ *primitive = ret_value; 893be168c0dSopenharmony_ci+ } 894be168c0dSopenharmony_ci+ } 895be168c0dSopenharmony_ci+} 896be168c0dSopenharmony_ci+ 897be168c0dSopenharmony_ci+int64_t MindIR_Range_GetStart(ConstPrimitivePtr primitive) { 898be168c0dSopenharmony_ci+ if (primitive != nullptr) { 899be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 900be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 901be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 902be168c0dSopenharmony_ci+ return value->start(); 903be168c0dSopenharmony_ci+ } else { 904be168c0dSopenharmony_ci+ return 0; 905be168c0dSopenharmony_ci+ } 906be168c0dSopenharmony_ci+ } else { 907be168c0dSopenharmony_ci+ return 0; 908be168c0dSopenharmony_ci+ } 909be168c0dSopenharmony_ci+} 910be168c0dSopenharmony_ci+ 911be168c0dSopenharmony_ci+void MindIR_Range_SetStart(PrimitivePtr *primitive, int64_t start) { 912be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 913be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 914be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 915be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 916be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 917be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateRange(fbb, value->d_type(), start, value->limit(), value->delta()); 918be168c0dSopenharmony_ci+ auto prim_offset = 919be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_RANGE), ops_offset.o); 920be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 921be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 922be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 923be168c0dSopenharmony_ci+ *primitive = ret_value; 924be168c0dSopenharmony_ci+ } 925be168c0dSopenharmony_ci+ } 926be168c0dSopenharmony_ci+} 927be168c0dSopenharmony_ci+ 928be168c0dSopenharmony_ci+int64_t MindIR_Range_GetLimit(ConstPrimitivePtr primitive) { 929be168c0dSopenharmony_ci+ if (primitive != nullptr) { 930be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 931be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 932be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 933be168c0dSopenharmony_ci+ return value->limit(); 934be168c0dSopenharmony_ci+ } else { 935be168c0dSopenharmony_ci+ return 0; 936be168c0dSopenharmony_ci+ } 937be168c0dSopenharmony_ci+ } else { 938be168c0dSopenharmony_ci+ return 0; 939be168c0dSopenharmony_ci+ } 940be168c0dSopenharmony_ci+} 941be168c0dSopenharmony_ci+ 942be168c0dSopenharmony_ci+void MindIR_Range_SetLimit(PrimitivePtr *primitive, int64_t limit) { 943be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 944be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 945be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 946be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 947be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 948be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateRange(fbb, value->d_type(), value->start(), limit, value->delta()); 949be168c0dSopenharmony_ci+ auto prim_offset = 950be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_RANGE), ops_offset.o); 951be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 952be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 953be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 954be168c0dSopenharmony_ci+ *primitive = ret_value; 955be168c0dSopenharmony_ci+ } 956be168c0dSopenharmony_ci+ } 957be168c0dSopenharmony_ci+} 958be168c0dSopenharmony_ci+ 959be168c0dSopenharmony_ci+int64_t MindIR_Range_GetDelta(ConstPrimitivePtr primitive) { 960be168c0dSopenharmony_ci+ if (primitive != nullptr) { 961be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 962be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 963be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 964be168c0dSopenharmony_ci+ return value->delta(); 965be168c0dSopenharmony_ci+ } else { 966be168c0dSopenharmony_ci+ return 0; 967be168c0dSopenharmony_ci+ } 968be168c0dSopenharmony_ci+ } else { 969be168c0dSopenharmony_ci+ return 0; 970be168c0dSopenharmony_ci+ } 971be168c0dSopenharmony_ci+} 972be168c0dSopenharmony_ci+ 973be168c0dSopenharmony_ci+void MindIR_Range_SetDelta(PrimitivePtr *primitive, int64_t delta) { 974be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 975be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 976be168c0dSopenharmony_ci+ auto value = prim->value_as_Range(); 977be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 978be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 979be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateRange(fbb, value->d_type(), value->start(), value->limit(), delta); 980be168c0dSopenharmony_ci+ auto prim_offset = 981be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_RANGE), ops_offset.o); 982be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 983be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 984be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 985be168c0dSopenharmony_ci+ *primitive = ret_value; 986be168c0dSopenharmony_ci+ } 987be168c0dSopenharmony_ci+ } 988be168c0dSopenharmony_ci+} 989be168c0dSopenharmony_ci+ 990be168c0dSopenharmony_ci+// ********** RealDiv ********** 991be168c0dSopenharmony_ci+PrimitivePtr MindIR_RealDiv_CreatePrimitive() { 992be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 993be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateRealDiv(fbb); 994be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_REAL_DIV), ops_offset.o); 995be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 996be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 997be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 998be168c0dSopenharmony_ci+ return ret_value; 999be168c0dSopenharmony_ci+} 1000be168c0dSopenharmony_ci+ 1001be168c0dSopenharmony_ci+ 1002be168c0dSopenharmony_ci+// ********** Square ********** 1003be168c0dSopenharmony_ci+PrimitivePtr MindIR_Square_CreatePrimitive() { 1004be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1005be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateSquare(fbb); 1006be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_SQUARE), ops_offset.o); 1007be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1008be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1009be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1010be168c0dSopenharmony_ci+ return ret_value; 1011be168c0dSopenharmony_ci+} 1012be168c0dSopenharmony_ci+ 1013be168c0dSopenharmony_ci+// ********** Unstack ********** 1014be168c0dSopenharmony_ci+PrimitivePtr MindIR_Unstack_CreatePrimitive(int64_t axis) { 1015be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1016be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateUnstack(fbb, axis); 1017be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_UNSTACK), ops_offset.o); 1018be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1019be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1020be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1021be168c0dSopenharmony_ci+ return ret_value; 1022be168c0dSopenharmony_ci+} 1023be168c0dSopenharmony_ci+ 1024be168c0dSopenharmony_ci+int64_t MindIR_Unstack_GetAxis(ConstPrimitivePtr primitive) { 1025be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1026be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1027be168c0dSopenharmony_ci+ auto value = prim->value_as_Unstack(); 1028be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1029be168c0dSopenharmony_ci+ return value->axis(); 1030be168c0dSopenharmony_ci+ } else { 1031be168c0dSopenharmony_ci+ return 0; 1032be168c0dSopenharmony_ci+ } 1033be168c0dSopenharmony_ci+ } else { 1034be168c0dSopenharmony_ci+ return 0; 1035be168c0dSopenharmony_ci+ } 1036be168c0dSopenharmony_ci+} 1037be168c0dSopenharmony_ci+ 1038be168c0dSopenharmony_ci+void MindIR_Unstack_SetAxis(PrimitivePtr *primitive, int64_t axis) { 1039be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1040be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1041be168c0dSopenharmony_ci+ auto value = prim->value_as_Unstack(); 1042be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1043be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1044be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateUnstack(fbb, axis); 1045be168c0dSopenharmony_ci+ auto prim_offset = 1046be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_UNSTACK), ops_offset.o); 1047be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1048be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1049be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1050be168c0dSopenharmony_ci+ *primitive = ret_value; 1051be168c0dSopenharmony_ci+ } 1052be168c0dSopenharmony_ci+ } 1053be168c0dSopenharmony_ci+} 1054be168c0dSopenharmony_ci+ 1055be168c0dSopenharmony_ci+// ********** Select ********** 1056be168c0dSopenharmony_ci+PrimitivePtr MindIR_Select_CreatePrimitive() { 1057be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1058be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateSelect(fbb); 1059be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_SELECT), ops_offset.o); 1060be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1061be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1062be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1063be168c0dSopenharmony_ci+ return ret_value; 1064be168c0dSopenharmony_ci+} 1065be168c0dSopenharmony_ci+ 1066be168c0dSopenharmony_ci+// ********** Erf ********** 1067be168c0dSopenharmony_ci+PrimitivePtr MindIR_Erf_CreatePrimitive() { 1068be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1069be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateErf(fbb); 1070be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ERF), ops_offset.o); 1071be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1072be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1073be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1074be168c0dSopenharmony_ci+ return ret_value; 1075be168c0dSopenharmony_ci+} 1076be168c0dSopenharmony_ci+ 1077be168c0dSopenharmony_ci+// ********** Equal ********** 1078be168c0dSopenharmony_ci+PrimitivePtr MindIR_Equal_CreatePrimitive() { 1079be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1080be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateEqual(fbb); 1081be168c0dSopenharmony_ci+ auto prim_offset = 1082be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_EQUAL), ops_offset.o); 1083be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1084be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1085be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1086be168c0dSopenharmony_ci+ return ret_value; 1087be168c0dSopenharmony_ci+} 1088be168c0dSopenharmony_ci+ 1089be168c0dSopenharmony_ci+// ********** Greater ********** 1090be168c0dSopenharmony_ci+PrimitivePtr MindIR_Greater_CreatePrimitive() { 1091be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1092be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateGreater(fbb); 1093be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_GREATER), ops_offset.o); 1094be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1095be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1096be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1097be168c0dSopenharmony_ci+ return ret_value; 1098be168c0dSopenharmony_ci+} 1099be168c0dSopenharmony_ci+ 1100be168c0dSopenharmony_ci+// ********** GreaterEqual ********** 1101be168c0dSopenharmony_ci+PrimitivePtr MindIR_GreaterEqual_CreatePrimitive() { 1102be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1103be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateGreaterEqual(fbb); 1104be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_GREATER_EQUAL), ops_offset.o); 1105be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1106be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1107be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1108be168c0dSopenharmony_ci+ return ret_value; 1109be168c0dSopenharmony_ci+} 1110be168c0dSopenharmony_ci+ 1111be168c0dSopenharmony_ci+// ********** NotEqual ********** 1112be168c0dSopenharmony_ci+PrimitivePtr MindIR_NotEqual_CreatePrimitive() { 1113be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1114be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateNotEqual(fbb); 1115be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_NOT_EQUAL), ops_offset.o); 1116be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1117be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1118be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1119be168c0dSopenharmony_ci+ return ret_value; 1120be168c0dSopenharmony_ci+} 1121be168c0dSopenharmony_ci+ 1122be168c0dSopenharmony_ci+// ********** LeakyRelu ********** 1123be168c0dSopenharmony_ci+PrimitivePtr MindIR_LeakyRelu_CreatePrimitive(float negative_slope) { 1124be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1125be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateLeakyRelu(fbb, negative_slope); 1126be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LEAKY_RELU), ops_offset.o); 1127be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1128be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1129be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1130be168c0dSopenharmony_ci+ return ret_value; 1131be168c0dSopenharmony_ci+} 1132be168c0dSopenharmony_ci+ 1133be168c0dSopenharmony_ci+float MindIR_LeakyRelu_GetNegativeSlope(ConstPrimitivePtr primitive) { 1134be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1135be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1136be168c0dSopenharmony_ci+ auto value = prim->value_as_LeakyRelu(); 1137be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1138be168c0dSopenharmony_ci+ return value->negative_slope(); 1139be168c0dSopenharmony_ci+ } else { 1140be168c0dSopenharmony_ci+ return .0; 1141be168c0dSopenharmony_ci+ } 1142be168c0dSopenharmony_ci+ } else { 1143be168c0dSopenharmony_ci+ return .0; 1144be168c0dSopenharmony_ci+ } 1145be168c0dSopenharmony_ci+} 1146be168c0dSopenharmony_ci+ 1147be168c0dSopenharmony_ci+void MindIR_LeakyRelu_SetNegativeSlope(PrimitivePtr *primitive, float negative_slope) { 1148be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1149be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1150be168c0dSopenharmony_ci+ auto value = prim->value_as_LeakyRelu(); 1151be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1152be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1153be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateInstanceNorm(fbb, negative_slope); 1154be168c0dSopenharmony_ci+ auto prim_offset = 1155be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LEAKY_RELU), ops_offset.o); 1156be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1157be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1158be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1159be168c0dSopenharmony_ci+ *primitive = ret_value; 1160be168c0dSopenharmony_ci+ } 1161be168c0dSopenharmony_ci+ } 1162be168c0dSopenharmony_ci+} 1163be168c0dSopenharmony_ci+ 1164be168c0dSopenharmony_ci+// ********** LSTM ********** 1165be168c0dSopenharmony_ci+PrimitivePtr MindIR_LSTM_CreatePrimitive( 1166be168c0dSopenharmony_ci+ bool bidirectional, bool has_bias, int64_t input_size, int64_t hidden_size, int64_t num_layers, 1167be168c0dSopenharmony_ci+ int64_t num_directions, float dropout, float zoneout_cell, float zoneout_hidden, int64_t proj_size) { 1168be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1169be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateLSTM(fbb, bidirectional, has_bias, input_size, hidden_size, num_layers, 1170be168c0dSopenharmony_ci+ num_directions,dropout, zoneout_cell, zoneout_hidden, proj_size); 1171be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1172be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1173be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1174be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1175be168c0dSopenharmony_ci+ return ret_value; 1176be168c0dSopenharmony_ci+} 1177be168c0dSopenharmony_ci+ 1178be168c0dSopenharmony_ci+bool MindIR_LSTM_GetBidirectional(ConstPrimitivePtr primitive) { 1179be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1180be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1181be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1182be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1183be168c0dSopenharmony_ci+ return value->bidirectional(); 1184be168c0dSopenharmony_ci+ } else { 1185be168c0dSopenharmony_ci+ return false; 1186be168c0dSopenharmony_ci+ } 1187be168c0dSopenharmony_ci+ } else { 1188be168c0dSopenharmony_ci+ return false; 1189be168c0dSopenharmony_ci+ } 1190be168c0dSopenharmony_ci+} 1191be168c0dSopenharmony_ci+ 1192be168c0dSopenharmony_ci+void MindIR_LSTM_SetBidirectional(PrimitivePtr *primitive, bool bidirectional) { 1193be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1194be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1195be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1196be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1197be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1198be168c0dSopenharmony_ci+ auto ops_offset = 1199be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, bidirectional, value->has_bias(), value->input_size(), value->hidden_size(), 1200be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), value->dropout(), value->zoneout_cell(), 1201be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1202be168c0dSopenharmony_ci+ auto prim_offset = 1203be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1204be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1205be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1206be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1207be168c0dSopenharmony_ci+ *primitive = ret_value; 1208be168c0dSopenharmony_ci+ } 1209be168c0dSopenharmony_ci+ } 1210be168c0dSopenharmony_ci+} 1211be168c0dSopenharmony_ci+ 1212be168c0dSopenharmony_ci+bool MindIR_LSTM_GetHasBias(ConstPrimitivePtr primitive) { 1213be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1214be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1215be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1216be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1217be168c0dSopenharmony_ci+ return value->has_bias(); 1218be168c0dSopenharmony_ci+ } else { 1219be168c0dSopenharmony_ci+ return false; 1220be168c0dSopenharmony_ci+ } 1221be168c0dSopenharmony_ci+ } else { 1222be168c0dSopenharmony_ci+ return false; 1223be168c0dSopenharmony_ci+ } 1224be168c0dSopenharmony_ci+} 1225be168c0dSopenharmony_ci+ 1226be168c0dSopenharmony_ci+void MindIR_LSTM_SetHasBias(PrimitivePtr *primitive, bool has_bias) { 1227be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1228be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1229be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1230be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1231be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1232be168c0dSopenharmony_ci+ auto ops_offset = 1233be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), has_bias, value->input_size(), value->hidden_size(), 1234be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), value->dropout(), value->zoneout_cell(), 1235be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1236be168c0dSopenharmony_ci+ auto prim_offset = 1237be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1238be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1239be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1240be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1241be168c0dSopenharmony_ci+ *primitive = ret_value; 1242be168c0dSopenharmony_ci+ } 1243be168c0dSopenharmony_ci+ } 1244be168c0dSopenharmony_ci+} 1245be168c0dSopenharmony_ci+ 1246be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetInputSize(ConstPrimitivePtr primitive) { 1247be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1248be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1249be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1250be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1251be168c0dSopenharmony_ci+ return value->input_size(); 1252be168c0dSopenharmony_ci+ } else { 1253be168c0dSopenharmony_ci+ return 0; 1254be168c0dSopenharmony_ci+ } 1255be168c0dSopenharmony_ci+ } else { 1256be168c0dSopenharmony_ci+ return 0; 1257be168c0dSopenharmony_ci+ } 1258be168c0dSopenharmony_ci+} 1259be168c0dSopenharmony_ci+ 1260be168c0dSopenharmony_ci+void MindIR_LSTM_SetInputSize(PrimitivePtr *primitive, int64_t input_size) { 1261be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1262be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1263be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1264be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1265be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1266be168c0dSopenharmony_ci+ auto ops_offset = 1267be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), input_size, value->hidden_size(), 1268be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), value->dropout(), value->zoneout_cell(), 1269be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1270be168c0dSopenharmony_ci+ auto prim_offset = 1271be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1272be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1273be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1274be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1275be168c0dSopenharmony_ci+ *primitive = ret_value; 1276be168c0dSopenharmony_ci+ } 1277be168c0dSopenharmony_ci+ } 1278be168c0dSopenharmony_ci+} 1279be168c0dSopenharmony_ci+ 1280be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetHiddenSize(ConstPrimitivePtr primitive) { 1281be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1282be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1283be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1284be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1285be168c0dSopenharmony_ci+ return value->hidden_size(); 1286be168c0dSopenharmony_ci+ } else { 1287be168c0dSopenharmony_ci+ return 0; 1288be168c0dSopenharmony_ci+ } 1289be168c0dSopenharmony_ci+ } else { 1290be168c0dSopenharmony_ci+ return 0; 1291be168c0dSopenharmony_ci+ } 1292be168c0dSopenharmony_ci+} 1293be168c0dSopenharmony_ci+ 1294be168c0dSopenharmony_ci+void MindIR_LSTM_SetHiddenSize(PrimitivePtr *primitive, int64_t hidden_size) { 1295be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1296be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1297be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1298be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1299be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1300be168c0dSopenharmony_ci+ auto ops_offset = 1301be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), value->input_size(), hidden_size, 1302be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), value->dropout(), value->zoneout_cell(), 1303be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1304be168c0dSopenharmony_ci+ auto prim_offset = 1305be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1306be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1307be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1308be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1309be168c0dSopenharmony_ci+ *primitive = ret_value; 1310be168c0dSopenharmony_ci+ } 1311be168c0dSopenharmony_ci+ } 1312be168c0dSopenharmony_ci+} 1313be168c0dSopenharmony_ci+ 1314be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetNumLayers(ConstPrimitivePtr primitive) { 1315be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1316be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1317be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1318be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1319be168c0dSopenharmony_ci+ return value->num_layers(); 1320be168c0dSopenharmony_ci+ } else { 1321be168c0dSopenharmony_ci+ return 0; 1322be168c0dSopenharmony_ci+ } 1323be168c0dSopenharmony_ci+ } else { 1324be168c0dSopenharmony_ci+ return 0; 1325be168c0dSopenharmony_ci+ } 1326be168c0dSopenharmony_ci+} 1327be168c0dSopenharmony_ci+ 1328be168c0dSopenharmony_ci+void MindIR_LSTM_SetNumLayers(PrimitivePtr *primitive, int64_t num_layers) { 1329be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1330be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1331be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1332be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1333be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1334be168c0dSopenharmony_ci+ auto ops_offset = 1335be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), value->input_size(), value->hidden_size(), 1336be168c0dSopenharmony_ci+ num_layers, value->num_directions(), value->dropout(), value->zoneout_cell(), 1337be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1338be168c0dSopenharmony_ci+ auto prim_offset = 1339be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1340be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1341be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1342be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1343be168c0dSopenharmony_ci+ *primitive = ret_value; 1344be168c0dSopenharmony_ci+ } 1345be168c0dSopenharmony_ci+ } 1346be168c0dSopenharmony_ci+} 1347be168c0dSopenharmony_ci+ 1348be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetNumDirections(ConstPrimitivePtr primitive) { 1349be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1350be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1351be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1352be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1353be168c0dSopenharmony_ci+ return value->num_directions(); 1354be168c0dSopenharmony_ci+ } else { 1355be168c0dSopenharmony_ci+ return 0; 1356be168c0dSopenharmony_ci+ } 1357be168c0dSopenharmony_ci+ } else { 1358be168c0dSopenharmony_ci+ return 0; 1359be168c0dSopenharmony_ci+ } 1360be168c0dSopenharmony_ci+} 1361be168c0dSopenharmony_ci+ 1362be168c0dSopenharmony_ci+void MindIR_LSTM_SetNumDirections(PrimitivePtr *primitive, int64_t num_directions) { 1363be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1364be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1365be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1366be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1367be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1368be168c0dSopenharmony_ci+ auto ops_offset = 1369be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), value->input_size(), value->hidden_size(), 1370be168c0dSopenharmony_ci+ value->num_layers(), num_directions, value->dropout(), value->zoneout_cell(), 1371be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1372be168c0dSopenharmony_ci+ auto prim_offset = 1373be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1374be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1375be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1376be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1377be168c0dSopenharmony_ci+ *primitive = ret_value; 1378be168c0dSopenharmony_ci+ } 1379be168c0dSopenharmony_ci+ } 1380be168c0dSopenharmony_ci+} 1381be168c0dSopenharmony_ci+ 1382be168c0dSopenharmony_ci+float MindIR_LSTM_GetDropout(ConstPrimitivePtr primitive) { 1383be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1384be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1385be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1386be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1387be168c0dSopenharmony_ci+ return value->dropout(); 1388be168c0dSopenharmony_ci+ } else { 1389be168c0dSopenharmony_ci+ return .0; 1390be168c0dSopenharmony_ci+ } 1391be168c0dSopenharmony_ci+ } else { 1392be168c0dSopenharmony_ci+ return .0; 1393be168c0dSopenharmony_ci+ } 1394be168c0dSopenharmony_ci+} 1395be168c0dSopenharmony_ci+ 1396be168c0dSopenharmony_ci+void MindIR_LSTM_SetDropout(PrimitivePtr *primitive, float dropout) { 1397be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1398be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1399be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1400be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1401be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1402be168c0dSopenharmony_ci+ auto ops_offset = 1403be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), value->input_size(), value->hidden_size(), 1404be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), dropout, value->zoneout_cell(), 1405be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1406be168c0dSopenharmony_ci+ auto prim_offset = 1407be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1408be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1409be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1410be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1411be168c0dSopenharmony_ci+ *primitive = ret_value; 1412be168c0dSopenharmony_ci+ } 1413be168c0dSopenharmony_ci+ } 1414be168c0dSopenharmony_ci+} 1415be168c0dSopenharmony_ci+ 1416be168c0dSopenharmony_ci+float MindIR_LSTM_GetZoneoutCell(ConstPrimitivePtr primitive) { 1417be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1418be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1419be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1420be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1421be168c0dSopenharmony_ci+ return value->zoneout_cell(); 1422be168c0dSopenharmony_ci+ } else { 1423be168c0dSopenharmony_ci+ return .0; 1424be168c0dSopenharmony_ci+ } 1425be168c0dSopenharmony_ci+ } else { 1426be168c0dSopenharmony_ci+ return .0; 1427be168c0dSopenharmony_ci+ } 1428be168c0dSopenharmony_ci+} 1429be168c0dSopenharmony_ci+ 1430be168c0dSopenharmony_ci+void MindIR_LSTM_SetZoneoutCell(PrimitivePtr *primitive, float zoneout_cell) { 1431be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1432be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1433be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1434be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1435be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1436be168c0dSopenharmony_ci+ auto ops_offset = 1437be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), value->input_size(), value->hidden_size(), 1438be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), value->dropout(), zoneout_cell, 1439be168c0dSopenharmony_ci+ value->zoneout_hidden(), value->proj_size()); 1440be168c0dSopenharmony_ci+ auto prim_offset = 1441be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1442be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1443be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1444be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1445be168c0dSopenharmony_ci+ *primitive = ret_value; 1446be168c0dSopenharmony_ci+ } 1447be168c0dSopenharmony_ci+ } 1448be168c0dSopenharmony_ci+} 1449be168c0dSopenharmony_ci+ 1450be168c0dSopenharmony_ci+float MindIR_LSTM_GetZoneoutHidden(ConstPrimitivePtr primitive) { 1451be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1452be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1453be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1454be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1455be168c0dSopenharmony_ci+ return value->zoneout_hidden(); 1456be168c0dSopenharmony_ci+ } else { 1457be168c0dSopenharmony_ci+ return .0; 1458be168c0dSopenharmony_ci+ } 1459be168c0dSopenharmony_ci+ } else { 1460be168c0dSopenharmony_ci+ return .0; 1461be168c0dSopenharmony_ci+ } 1462be168c0dSopenharmony_ci+} 1463be168c0dSopenharmony_ci+ 1464be168c0dSopenharmony_ci+void MindIR_LSTM_SetZoneoutHidden(PrimitivePtr *primitive, float zoneout_hidden) { 1465be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1466be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1467be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1468be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1469be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1470be168c0dSopenharmony_ci+ auto ops_offset = 1471be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), value->input_size(), value->hidden_size(), 1472be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), value->dropout(), value->zoneout_cell(), 1473be168c0dSopenharmony_ci+ zoneout_hidden, value->proj_size()); 1474be168c0dSopenharmony_ci+ auto prim_offset = 1475be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1476be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1477be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1478be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1479be168c0dSopenharmony_ci+ *primitive = ret_value; 1480be168c0dSopenharmony_ci+ } 1481be168c0dSopenharmony_ci+ } 1482be168c0dSopenharmony_ci+} 1483be168c0dSopenharmony_ci+ 1484be168c0dSopenharmony_ci+int64_t MindIR_LSTM_GetProjSize(ConstPrimitivePtr primitive) { 1485be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1486be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1487be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1488be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1489be168c0dSopenharmony_ci+ return value->proj_size(); 1490be168c0dSopenharmony_ci+ } else { 1491be168c0dSopenharmony_ci+ return 0; 1492be168c0dSopenharmony_ci+ } 1493be168c0dSopenharmony_ci+ } else { 1494be168c0dSopenharmony_ci+ return 0; 1495be168c0dSopenharmony_ci+ } 1496be168c0dSopenharmony_ci+} 1497be168c0dSopenharmony_ci+ 1498be168c0dSopenharmony_ci+void MindIR_LSTM_SetProjSize(PrimitivePtr *primitive, int64_t proj_size) { 1499be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1500be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1501be168c0dSopenharmony_ci+ auto value = prim->value_as_LSTM(); 1502be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1503be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1504be168c0dSopenharmony_ci+ auto ops_offset = 1505be168c0dSopenharmony_ci+ schema::CreateLSTM(fbb, value->bidirectional(), value->has_bias(), value->input_size(), value->hidden_size(), 1506be168c0dSopenharmony_ci+ value->num_layers(), value->num_directions(), value->dropout(), value->zoneout_cell(), 1507be168c0dSopenharmony_ci+ value->zoneout_hidden(), proj_size); 1508be168c0dSopenharmony_ci+ auto prim_offset = 1509be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_LSTM), ops_offset.o); 1510be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1511be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1512be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1513be168c0dSopenharmony_ci+ *primitive = ret_value; 1514be168c0dSopenharmony_ci+ } 1515be168c0dSopenharmony_ci+ } 1516be168c0dSopenharmony_ci+} 1517be168c0dSopenharmony_ci+ 1518be168c0dSopenharmony_ci+// ********** Clip ********** 1519be168c0dSopenharmony_ci+PrimitivePtr MindIR_Clip_CreatePrimitive(float max, float min) { 1520be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1521be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateClip(fbb, max, min); 1522be168c0dSopenharmony_ci+ auto prim_offset = schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_CLIP), ops_offset.o); 1523be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1524be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, nullptr); 1525be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1526be168c0dSopenharmony_ci+ return ret_value; 1527be168c0dSopenharmony_ci+} 1528be168c0dSopenharmony_ci+ 1529be168c0dSopenharmony_ci+float MindIR_Clip_GetMax(ConstPrimitivePtr primitive) { 1530be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1531be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1532be168c0dSopenharmony_ci+ auto value = prim->value_as_Clip(); 1533be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1534be168c0dSopenharmony_ci+ return value->max(); 1535be168c0dSopenharmony_ci+ } else { 1536be168c0dSopenharmony_ci+ return .0; 1537be168c0dSopenharmony_ci+ } 1538be168c0dSopenharmony_ci+ } else { 1539be168c0dSopenharmony_ci+ return .0; 1540be168c0dSopenharmony_ci+ } 1541be168c0dSopenharmony_ci+} 1542be168c0dSopenharmony_ci+ 1543be168c0dSopenharmony_ci+void MindIR_Clip_SetMax(PrimitivePtr *primitive, float max) { 1544be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1545be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1546be168c0dSopenharmony_ci+ auto value = prim->value_as_Clip(); 1547be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1548be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1549be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateClip(fbb, max, value->min()); 1550be168c0dSopenharmony_ci+ auto prim_offset = 1551be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_CLIP), ops_offset.o); 1552be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1553be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1554be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1555be168c0dSopenharmony_ci+ *primitive = ret_value; 1556be168c0dSopenharmony_ci+ } 1557be168c0dSopenharmony_ci+ } 1558be168c0dSopenharmony_ci+} 1559be168c0dSopenharmony_ci+ 1560be168c0dSopenharmony_ci+float MindIR_Clip_GetMin(ConstPrimitivePtr primitive) { 1561be168c0dSopenharmony_ci+ if (primitive != nullptr) { 1562be168c0dSopenharmony_ci+ auto prim = static_cast<const schema::Primitive *>(primitive); 1563be168c0dSopenharmony_ci+ auto value = prim->value_as_Clip(); 1564be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1565be168c0dSopenharmony_ci+ return value->min(); 1566be168c0dSopenharmony_ci+ } else { 1567be168c0dSopenharmony_ci+ return .0; 1568be168c0dSopenharmony_ci+ } 1569be168c0dSopenharmony_ci+ } else { 1570be168c0dSopenharmony_ci+ return .0; 1571be168c0dSopenharmony_ci+ } 1572be168c0dSopenharmony_ci+} 1573be168c0dSopenharmony_ci+ 1574be168c0dSopenharmony_ci+void MindIR_Clip_SetMin(PrimitivePtr *primitive, float min) { 1575be168c0dSopenharmony_ci+ if (primitive != nullptr && *primitive != nullptr) { 1576be168c0dSopenharmony_ci+ auto prim = static_cast<schema::Primitive *>(*primitive); 1577be168c0dSopenharmony_ci+ auto value = prim->value_as_Clip(); 1578be168c0dSopenharmony_ci+ if (prim != nullptr && value != nullptr) { 1579be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 1580be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateClip(fbb, value->max(), min); 1581be168c0dSopenharmony_ci+ auto prim_offset = 1582be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_CLIP), ops_offset.o); 1583be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 1584be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 1585be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 1586be168c0dSopenharmony_ci+ *primitive = ret_value; 1587be168c0dSopenharmony_ci+ } 1588be168c0dSopenharmony_ci+ } 1589be168c0dSopenharmony_ci+} 1590be168c0dSopenharmony_ci+ 1591be168c0dSopenharmony_ci // ********** Custom ********** 1592be168c0dSopenharmony_ci std::vector<const mindspore::schema::Attribute *> MindIR_Custom_GetAttr(ConstPrimitivePtr primitive) { 1593be168c0dSopenharmony_ci if (primitive == nullptr) { 1594be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model.cc b/mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model.cc 1595be168c0dSopenharmony_cideleted file mode 100644 1596be168c0dSopenharmony_ciindex df39e04b..00000000 1597be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model.cc 1598be168c0dSopenharmony_ci+++ /dev/null 1599be168c0dSopenharmony_ci@@ -1,1496 +0,0 @@ 1600be168c0dSopenharmony_ci-/** 1601be168c0dSopenharmony_ci- * Copyright 2021 Huawei Technologies Co., Ltd 1602be168c0dSopenharmony_ci- * 1603be168c0dSopenharmony_ci- * Licensed under the Apache License, Version 2.0 (the "License"); 1604be168c0dSopenharmony_ci- * you may not use this file except in compliance with the License. 1605be168c0dSopenharmony_ci- * You may obtain a copy of the License at 1606be168c0dSopenharmony_ci- * 1607be168c0dSopenharmony_ci- * http://www.apache.org/licenses/LICENSE-2.0 1608be168c0dSopenharmony_ci- * 1609be168c0dSopenharmony_ci- * Unless required by applicable law or agreed to in writing, software 1610be168c0dSopenharmony_ci- * distributed under the License is distributed on an "AS IS" BASIS, 1611be168c0dSopenharmony_ci- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1612be168c0dSopenharmony_ci- * See the License for the specific language governing permissions and 1613be168c0dSopenharmony_ci- * limitations under the License. 1614be168c0dSopenharmony_ci- */ 1615be168c0dSopenharmony_ci-#include "mindir.h" 1616be168c0dSopenharmony_ci-#include <vector> 1617be168c0dSopenharmony_ci-#include <algorithm> 1618be168c0dSopenharmony_ci-#include <sys/mman.h> 1619be168c0dSopenharmony_ci-#include "src/common/log.h" 1620be168c0dSopenharmony_ci-#include "lite_graph.h" 1621be168c0dSopenharmony_ci-#include "schema/model_generated.h" 1622be168c0dSopenharmony_ci-#include "mindir_types.h" 1623be168c0dSopenharmony_ci-#include "message_parcel.h" 1624be168c0dSopenharmony_ci-#include "nnrt/v1_0/nnrt_types.h" 1625be168c0dSopenharmony_ci-#include "nnrt/v1_0/node_attr_types.h" 1626be168c0dSopenharmony_ci-#include "nnrt/v1_0/model_types.h" 1627be168c0dSopenharmony_ci- 1628be168c0dSopenharmony_ci-using namespace OHOS::HDI::Nnrt::V1_0; 1629be168c0dSopenharmony_ci-namespace mindspore { 1630be168c0dSopenharmony_ci-namespace lite { 1631be168c0dSopenharmony_ci- 1632be168c0dSopenharmony_ci-constexpr size_t kNumTwo = 2; 1633be168c0dSopenharmony_ci-constexpr size_t kNumFour = 4; 1634be168c0dSopenharmony_ci-constexpr size_t kNumEight = 8; 1635be168c0dSopenharmony_ci- 1636be168c0dSopenharmony_ci-inline std::vector<OHOS::HDI::Nnrt::V1_0::QuantParam> MindIR_Tensor_GetQuantParams_OHOS(TensorPtr tensor) { 1637be168c0dSopenharmony_ci- if (tensor != nullptr) { 1638be168c0dSopenharmony_ci- auto value = static_cast<schema::Tensor *>(tensor); 1639be168c0dSopenharmony_ci- 1640be168c0dSopenharmony_ci- if (value != nullptr) { 1641be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V1_0::QuantParam> result; 1642be168c0dSopenharmony_ci- auto src = value->quantParams(); 1643be168c0dSopenharmony_ci- if (src == nullptr) { 1644be168c0dSopenharmony_ci- return {}; 1645be168c0dSopenharmony_ci- } 1646be168c0dSopenharmony_ci- size_t size = src->size(); 1647be168c0dSopenharmony_ci- result.reserve(src->size()); 1648be168c0dSopenharmony_ci- for (size_t i = 0; i < size; i++) { 1649be168c0dSopenharmony_ci- auto tmp = src->Get(i); 1650be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V1_0::QuantParam quantParam{tmp->numBits(), tmp->zeroPoint(), tmp->scale()}; 1651be168c0dSopenharmony_ci- result.emplace_back(quantParam); 1652be168c0dSopenharmony_ci- } 1653be168c0dSopenharmony_ci- return result; 1654be168c0dSopenharmony_ci- } else { 1655be168c0dSopenharmony_ci- return {}; 1656be168c0dSopenharmony_ci- } 1657be168c0dSopenharmony_ci- } else { 1658be168c0dSopenharmony_ci- return {}; 1659be168c0dSopenharmony_ci- } 1660be168c0dSopenharmony_ci-} 1661be168c0dSopenharmony_ci- 1662be168c0dSopenharmony_ci-void MindIR_Model_Destroy(OHOS::HDI::Nnrt::V1_0::Model **model) { 1663be168c0dSopenharmony_ci- if (model != nullptr) { 1664be168c0dSopenharmony_ci- auto model_data = *model; 1665be168c0dSopenharmony_ci- if (model_data != nullptr) { 1666be168c0dSopenharmony_ci- delete (model_data); 1667be168c0dSopenharmony_ci- *model = nullptr; 1668be168c0dSopenharmony_ci- } else { 1669be168c0dSopenharmony_ci- MS_LOG(ERROR) << "*model is nullptr, desrtoy model fail."; 1670be168c0dSopenharmony_ci- } 1671be168c0dSopenharmony_ci- } 1672be168c0dSopenharmony_ci-} 1673be168c0dSopenharmony_ci- 1674be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V1_0::Model *MindIR_LiteGraph_To_Model(const LiteGraph *lite_graph, const OHOS::HDI::Nnrt::V1_0::SharedBuffer &buffer) { 1675be168c0dSopenharmony_ci- if (lite_graph != nullptr) { 1676be168c0dSopenharmony_ci- MS_LOG(INFO) << "MindIR_LiteGraph_To_Model begin"; 1677be168c0dSopenharmony_ci- if (!lite_graph->name_.empty()) { 1678be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting lite graph,name =" << lite_graph->name_; 1679be168c0dSopenharmony_ci- } else { 1680be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting lite graph, but lite graph has no name."; 1681be168c0dSopenharmony_ci- } 1682be168c0dSopenharmony_ci- std::vector<uint32_t> inputIndex; 1683be168c0dSopenharmony_ci- std::vector<uint32_t> outputIndex; 1684be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V1_0::Node> nodes; 1685be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V1_0::Tensor> allTensors; 1686be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V1_0::SubGraph> subGraph; 1687be168c0dSopenharmony_ci- // nodes 1688be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting nodes, vector size = " << lite_graph->all_nodes_.size(); 1689be168c0dSopenharmony_ci- nodes.reserve(lite_graph->all_nodes_.size()); 1690be168c0dSopenharmony_ci- for (auto node : lite_graph->all_nodes_) { 1691be168c0dSopenharmony_ci- if (node == nullptr) { 1692be168c0dSopenharmony_ci- MS_LOG(ERROR) << "node is nullptr, convert fail."; 1693be168c0dSopenharmony_ci- return nullptr; 1694be168c0dSopenharmony_ci- } 1695be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V1_0::Node tmp; 1696be168c0dSopenharmony_ci- tmp.name = node->name_; 1697be168c0dSopenharmony_ci- if (node->primitive_ == nullptr) { 1698be168c0dSopenharmony_ci- MS_LOG(ERROR) << "node primitive is nullptr, convert fail."; 1699be168c0dSopenharmony_ci- return nullptr; 1700be168c0dSopenharmony_ci- } 1701be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(node->primitive_); 1702be168c0dSopenharmony_ci- auto value = prim->value_type(); 1703be168c0dSopenharmony_ci- tmp.nodeType = static_cast<HDI::Nnrt::V1_0::NodeType>(value); 1704be168c0dSopenharmony_ci- tmp.nodeAttr = Convert(static_cast<NodeType>(value), node->primitive_); 1705be168c0dSopenharmony_ci- tmp.inputIndex = node->input_indices_; 1706be168c0dSopenharmony_ci- tmp.outputIndex = node->output_indices_; 1707be168c0dSopenharmony_ci- tmp.quantType = static_cast<HDI::Nnrt::V1_0::QuantType>(node->quant_type_); 1708be168c0dSopenharmony_ci- nodes.emplace_back(tmp); 1709be168c0dSopenharmony_ci- } 1710be168c0dSopenharmony_ci- 1711be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting Tensor,Tensor size=" << lite_graph->all_tensors_.size(); 1712be168c0dSopenharmony_ci- // Tensor 1713be168c0dSopenharmony_ci- allTensors.reserve(lite_graph->all_tensors_.size()); 1714be168c0dSopenharmony_ci- unsigned int tensor_buffer_offset = 0; 1715be168c0dSopenharmony_ci- uint8_t *mmap_ptr = nullptr; 1716be168c0dSopenharmony_ci- if (buffer.fd != -1) { 1717be168c0dSopenharmony_ci- mmap_ptr = 1718be168c0dSopenharmony_ci- static_cast<uint8_t *>(mmap(nullptr, buffer.bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0)); 1719be168c0dSopenharmony_ci- if (mmap_ptr == MAP_FAILED) { 1720be168c0dSopenharmony_ci- MS_LOG(ERROR) << "mmap failed"; 1721be168c0dSopenharmony_ci- return nullptr; 1722be168c0dSopenharmony_ci- } 1723be168c0dSopenharmony_ci- } 1724be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start parsing tensor, mmap buffer size = " << buffer.bufferSize; 1725be168c0dSopenharmony_ci- for (auto tensor : lite_graph->all_tensors_) { 1726be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V1_0::Tensor tmp; 1727be168c0dSopenharmony_ci- tmp.name = MindIR_Tensor_GetName(tensor); 1728be168c0dSopenharmony_ci- tmp.dataType = static_cast<HDI::Nnrt::V1_0::HDI::Nnrt::V1_0::DataType>(MindIR_Tensor_GetDataType(tensor)); 1729be168c0dSopenharmony_ci- tmp.dims = MindIR_Tensor_GetDims(tensor); 1730be168c0dSopenharmony_ci- tmp.format = static_cast<HDI::Nnrt::V1_0::HDI::Nnrt::V1_0::Format>(MindIR_Tensor_GetFormat(tensor)); 1731be168c0dSopenharmony_ci- tmp.data = MindIR_Tensor_GetData(tensor, buffer, mmap_ptr, tensor_buffer_offset); 1732be168c0dSopenharmony_ci- tmp.quantParams = MindIR_Tensor_GetQuantParams_OHOS(tensor); 1733be168c0dSopenharmony_ci- allTensors.emplace_back(tmp); 1734be168c0dSopenharmony_ci- tensor_buffer_offset = tmp.data.offset + tmp.data.dataSize; 1735be168c0dSopenharmony_ci- } 1736be168c0dSopenharmony_ci- MS_LOG(INFO) << ("Parsing tensor finish."); 1737be168c0dSopenharmony_ci- if (buffer.fd != -1) { 1738be168c0dSopenharmony_ci- auto munmap_res = munmap(mmap_ptr, buffer.bufferSize); 1739be168c0dSopenharmony_ci- if (munmap_res != 0) { 1740be168c0dSopenharmony_ci- MS_LOG(ERROR) << "unmap failed."; 1741be168c0dSopenharmony_ci- return nullptr; 1742be168c0dSopenharmony_ci- } 1743be168c0dSopenharmony_ci- } 1744be168c0dSopenharmony_ci- 1745be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting SubGraph,SubGraph size=" << lite_graph->sub_graphs_.size(); 1746be168c0dSopenharmony_ci- // SubGraph 1747be168c0dSopenharmony_ci- subGraph.reserve(lite_graph->sub_graphs_.size()); 1748be168c0dSopenharmony_ci- for (auto graph : lite_graph->sub_graphs_) { 1749be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V1_0::SubGraph tmp; 1750be168c0dSopenharmony_ci- tmp.name = graph->name_; 1751be168c0dSopenharmony_ci- tmp.inputIndices = std::vector<uint32_t>(graph->input_indices_); 1752be168c0dSopenharmony_ci- tmp.outputIndices = std::vector<uint32_t>(graph->output_indices_); 1753be168c0dSopenharmony_ci- tmp.nodeIndices = std::vector<uint32_t>(graph->node_indices_); 1754be168c0dSopenharmony_ci- subGraph.emplace_back(tmp); 1755be168c0dSopenharmony_ci- } 1756be168c0dSopenharmony_ci- 1757be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start copying model"; 1758be168c0dSopenharmony_ci- auto *ret_model = new (std::nothrow) Model(); 1759be168c0dSopenharmony_ci- if (ret_model == nullptr) { 1760be168c0dSopenharmony_ci- MS_LOG(ERROR) << "new Model failed."; 1761be168c0dSopenharmony_ci- return nullptr; 1762be168c0dSopenharmony_ci- } 1763be168c0dSopenharmony_ci- ret_model->name = lite_graph->name_; 1764be168c0dSopenharmony_ci- ret_model->inputIndex = lite_graph->input_indices_; 1765be168c0dSopenharmony_ci- ret_model->outputIndex = lite_graph->output_indices_; 1766be168c0dSopenharmony_ci- ret_model->nodes = nodes; 1767be168c0dSopenharmony_ci- ret_model->allTensors = allTensors; 1768be168c0dSopenharmony_ci- ret_model->subGraph = subGraph; 1769be168c0dSopenharmony_ci- MS_LOG(INFO) << "MindIR_LiteGraph_To_Model success"; 1770be168c0dSopenharmony_ci- return ret_model; 1771be168c0dSopenharmony_ci- } else { 1772be168c0dSopenharmony_ci- MS_LOG(ERROR) << "lite graph is nullptr"; 1773be168c0dSopenharmony_ci- return nullptr; 1774be168c0dSopenharmony_ci- } 1775be168c0dSopenharmony_ci-} 1776be168c0dSopenharmony_ci- 1777be168c0dSopenharmony_ci-std::vector<int8_t> ConvertActivation(PrimitivePtr primitive) { 1778be168c0dSopenharmony_ci- if (primitive != nullptr) { 1779be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1780be168c0dSopenharmony_ci- auto value = prim->value_as_Activation(); 1781be168c0dSopenharmony_ci- if (value != nullptr) { 1782be168c0dSopenharmony_ci- Activation activation{}; 1783be168c0dSopenharmony_ci- activation.activationType = 1784be168c0dSopenharmony_ci- static_cast<HDI::Nnrt::V1_0::HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 1785be168c0dSopenharmony_ci- activation.alpha = value->alpha(); 1786be168c0dSopenharmony_ci- activation.minVal = value->min_val(); 1787be168c0dSopenharmony_ci- activation.maxVal = value->max_val(); 1788be168c0dSopenharmony_ci- activation.approximate = value->approximate(); 1789be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1790be168c0dSopenharmony_ci- (void)ActivationBlockMarshalling(data, activation); 1791be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1792be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1793be168c0dSopenharmony_ci- return ret; 1794be168c0dSopenharmony_ci- } else { 1795be168c0dSopenharmony_ci- return {}; 1796be168c0dSopenharmony_ci- } 1797be168c0dSopenharmony_ci- } else { 1798be168c0dSopenharmony_ci- return {}; 1799be168c0dSopenharmony_ci- } 1800be168c0dSopenharmony_ci-} 1801be168c0dSopenharmony_ci-std::vector<int8_t> ConvertAddFusion(PrimitivePtr primitive) { 1802be168c0dSopenharmony_ci- if (primitive != nullptr) { 1803be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1804be168c0dSopenharmony_ci- auto value = prim->value_as_AddFusion(); 1805be168c0dSopenharmony_ci- if (value != nullptr) { 1806be168c0dSopenharmony_ci- AddFusion add_fusion{}; 1807be168c0dSopenharmony_ci- add_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 1808be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1809be168c0dSopenharmony_ci- (void)AddFusionBlockMarshalling(data, add_fusion); 1810be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1811be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1812be168c0dSopenharmony_ci- return ret; 1813be168c0dSopenharmony_ci- } else { 1814be168c0dSopenharmony_ci- return {}; 1815be168c0dSopenharmony_ci- } 1816be168c0dSopenharmony_ci- } else { 1817be168c0dSopenharmony_ci- return {}; 1818be168c0dSopenharmony_ci- } 1819be168c0dSopenharmony_ci-} 1820be168c0dSopenharmony_ci-std::vector<int8_t> ConvertArgMaxFusion(PrimitivePtr primitive) { 1821be168c0dSopenharmony_ci- if (primitive != nullptr) { 1822be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1823be168c0dSopenharmony_ci- auto value = prim->value_as_ArgMaxFusion(); 1824be168c0dSopenharmony_ci- if (value != nullptr) { 1825be168c0dSopenharmony_ci- ArgMaxFusion arg_max_fusion{}; 1826be168c0dSopenharmony_ci- arg_max_fusion.axis = value->axis(); 1827be168c0dSopenharmony_ci- arg_max_fusion.topK = value->top_k(); 1828be168c0dSopenharmony_ci- arg_max_fusion.keepDims = value->keep_dims(); 1829be168c0dSopenharmony_ci- arg_max_fusion.outMaxValue = value->out_max_value(); 1830be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1831be168c0dSopenharmony_ci- (void)ArgMaxFusionBlockMarshalling(data, arg_max_fusion); 1832be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1833be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1834be168c0dSopenharmony_ci- return ret; 1835be168c0dSopenharmony_ci- } else { 1836be168c0dSopenharmony_ci- return {}; 1837be168c0dSopenharmony_ci- } 1838be168c0dSopenharmony_ci- } else { 1839be168c0dSopenharmony_ci- return {}; 1840be168c0dSopenharmony_ci- } 1841be168c0dSopenharmony_ci-} 1842be168c0dSopenharmony_ci-std::vector<int8_t> ConvertAvgPoolFusion(PrimitivePtr primitive) { 1843be168c0dSopenharmony_ci- if (primitive != nullptr) { 1844be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1845be168c0dSopenharmony_ci- auto value = prim->value_as_AvgPoolFusion(); 1846be168c0dSopenharmony_ci- if (value != nullptr) { 1847be168c0dSopenharmony_ci- AvgPoolFusion avg_pool_fusion{}; 1848be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 1849be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 1850be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 1851be168c0dSopenharmony_ci- kernel_size = {}; 1852be168c0dSopenharmony_ci- } else { 1853be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 1854be168c0dSopenharmony_ci- } 1855be168c0dSopenharmony_ci- std::vector<int64_t> strides; 1856be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 1857be168c0dSopenharmony_ci- if (value->strides() == nullptr || value->strides()->size() < kNumTwo) { 1858be168c0dSopenharmony_ci- strides = {}; 1859be168c0dSopenharmony_ci- } else { 1860be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->strides()->begin(), value->strides()->end()); 1861be168c0dSopenharmony_ci- } 1862be168c0dSopenharmony_ci- std::vector<int64_t> padList; 1863be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 1864be168c0dSopenharmony_ci- if (value->pad() == nullptr || value->pad()->size() < kNumFour) { 1865be168c0dSopenharmony_ci- padList = {}; 1866be168c0dSopenharmony_ci- } else { 1867be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad()->begin(), value->pad()->end()); 1868be168c0dSopenharmony_ci- } 1869be168c0dSopenharmony_ci- avg_pool_fusion.kernelSize = kernel_size; 1870be168c0dSopenharmony_ci- avg_pool_fusion.strides = strides; 1871be168c0dSopenharmony_ci- avg_pool_fusion.pad = padList; 1872be168c0dSopenharmony_ci- avg_pool_fusion.padMode = static_cast<HDI::Nnrt::V1_0::PadMode>(value->pad_mode()); 1873be168c0dSopenharmony_ci- avg_pool_fusion.roundMode = static_cast<HDI::Nnrt::V1_0::RoundMode>(value->round_mode()); 1874be168c0dSopenharmony_ci- avg_pool_fusion.format = static_cast<HDI::Nnrt::V1_0::Format>(value->format()); 1875be168c0dSopenharmony_ci- avg_pool_fusion.global = value->global(); 1876be168c0dSopenharmony_ci- avg_pool_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 1877be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1878be168c0dSopenharmony_ci- (void)AvgPoolFusionBlockMarshalling(data, avg_pool_fusion); 1879be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1880be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1881be168c0dSopenharmony_ci- return ret; 1882be168c0dSopenharmony_ci- } else { 1883be168c0dSopenharmony_ci- return {}; 1884be168c0dSopenharmony_ci- } 1885be168c0dSopenharmony_ci- } else { 1886be168c0dSopenharmony_ci- return {}; 1887be168c0dSopenharmony_ci- } 1888be168c0dSopenharmony_ci-} 1889be168c0dSopenharmony_ci-std::vector<int8_t> ConvertBatchToSpaceND(PrimitivePtr primitive) { 1890be168c0dSopenharmony_ci- if (primitive != nullptr) { 1891be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1892be168c0dSopenharmony_ci- auto value = prim->value_as_BatchToSpaceND(); 1893be168c0dSopenharmony_ci- if (value != nullptr) { 1894be168c0dSopenharmony_ci- BatchToSpaceND batch_to_space_n_d{}; 1895be168c0dSopenharmony_ci- std::vector<int64_t> blockShape; 1896be168c0dSopenharmony_ci- blockShape.reserve(kNumTwo); 1897be168c0dSopenharmony_ci- if (value->block_shape() == nullptr || value->block_shape()->size() < kNumTwo) { 1898be168c0dSopenharmony_ci- blockShape = {0, 0}; 1899be168c0dSopenharmony_ci- } else { 1900be168c0dSopenharmony_ci- blockShape = std::vector<int64_t>(value->block_shape()->begin(), value->block_shape()->end()); 1901be168c0dSopenharmony_ci- } 1902be168c0dSopenharmony_ci- batch_to_space_n_d.blockShape = blockShape; 1903be168c0dSopenharmony_ci- auto crops = value->crops(); 1904be168c0dSopenharmony_ci- std::vector<std::vector<int64_t>> crops_vec2d; 1905be168c0dSopenharmony_ci- if (crops->data() == nullptr) { 1906be168c0dSopenharmony_ci- MS_LOG(ERROR) << "crops_data is nullptr"; 1907be168c0dSopenharmony_ci- crops_vec2d = {{}}; 1908be168c0dSopenharmony_ci- } else { 1909be168c0dSopenharmony_ci- crops_vec2d.reserve(crops->data()->size()); 1910be168c0dSopenharmony_ci- for (size_t i = 0; i < crops->data()->size(); i++) { 1911be168c0dSopenharmony_ci- auto vet = crops->data()->Get(i); 1912be168c0dSopenharmony_ci- crops_vec2d.emplace_back(std::vector<int64_t>(vet->data()->begin(), vet->data()->end())); 1913be168c0dSopenharmony_ci- } 1914be168c0dSopenharmony_ci- } 1915be168c0dSopenharmony_ci- batch_to_space_n_d.crops = crops_vec2d; 1916be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1917be168c0dSopenharmony_ci- (void)BatchToSpaceNDBlockMarshalling(data, batch_to_space_n_d); 1918be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1919be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1920be168c0dSopenharmony_ci- return ret; 1921be168c0dSopenharmony_ci- } else { 1922be168c0dSopenharmony_ci- return {}; 1923be168c0dSopenharmony_ci- } 1924be168c0dSopenharmony_ci- } else { 1925be168c0dSopenharmony_ci- return {}; 1926be168c0dSopenharmony_ci- } 1927be168c0dSopenharmony_ci-} 1928be168c0dSopenharmony_ci-std::vector<int8_t> ConvertBiasAdd(PrimitivePtr primitive) { 1929be168c0dSopenharmony_ci- if (primitive != nullptr) { 1930be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1931be168c0dSopenharmony_ci- auto value = prim->value_as_BiasAdd(); 1932be168c0dSopenharmony_ci- if (value != nullptr) { 1933be168c0dSopenharmony_ci- BiasAdd bias_add{}; 1934be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1935be168c0dSopenharmony_ci- (void)BiasAddBlockMarshalling(data, bias_add); 1936be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1937be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1938be168c0dSopenharmony_ci- return ret; 1939be168c0dSopenharmony_ci- } else { 1940be168c0dSopenharmony_ci- return {}; 1941be168c0dSopenharmony_ci- } 1942be168c0dSopenharmony_ci- } else { 1943be168c0dSopenharmony_ci- return {}; 1944be168c0dSopenharmony_ci- } 1945be168c0dSopenharmony_ci-} 1946be168c0dSopenharmony_ci-std::vector<int8_t> ConvertCast(PrimitivePtr primitive) { 1947be168c0dSopenharmony_ci- if (primitive != nullptr) { 1948be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1949be168c0dSopenharmony_ci- auto value = prim->value_as_Cast(); 1950be168c0dSopenharmony_ci- if (value != nullptr) { 1951be168c0dSopenharmony_ci- Cast cast{}; 1952be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1953be168c0dSopenharmony_ci- (void)CastBlockMarshalling(data, cast); 1954be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1955be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1956be168c0dSopenharmony_ci- return ret; 1957be168c0dSopenharmony_ci- } else { 1958be168c0dSopenharmony_ci- return {}; 1959be168c0dSopenharmony_ci- } 1960be168c0dSopenharmony_ci- } else { 1961be168c0dSopenharmony_ci- return {}; 1962be168c0dSopenharmony_ci- } 1963be168c0dSopenharmony_ci-} 1964be168c0dSopenharmony_ci-std::vector<int8_t> ConvertConcat(PrimitivePtr primitive) { 1965be168c0dSopenharmony_ci- if (primitive != nullptr) { 1966be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1967be168c0dSopenharmony_ci- auto value = prim->value_as_Concat(); 1968be168c0dSopenharmony_ci- if (value != nullptr) { 1969be168c0dSopenharmony_ci- Concat concat{}; 1970be168c0dSopenharmony_ci- concat.axis = value->axis(); 1971be168c0dSopenharmony_ci- OHOS::MessageParcel data; 1972be168c0dSopenharmony_ci- (void)ConcatBlockMarshalling(data, concat); 1973be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 1974be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 1975be168c0dSopenharmony_ci- return ret; 1976be168c0dSopenharmony_ci- } else { 1977be168c0dSopenharmony_ci- return {}; 1978be168c0dSopenharmony_ci- } 1979be168c0dSopenharmony_ci- } else { 1980be168c0dSopenharmony_ci- return {}; 1981be168c0dSopenharmony_ci- } 1982be168c0dSopenharmony_ci-} 1983be168c0dSopenharmony_ci-std::vector<int8_t> ConvertConv2DFusion(PrimitivePtr primitive) { 1984be168c0dSopenharmony_ci- if (primitive != nullptr) { 1985be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 1986be168c0dSopenharmony_ci- auto value = prim->value_as_Conv2DFusion(); 1987be168c0dSopenharmony_ci- if (value != nullptr) { 1988be168c0dSopenharmony_ci- Conv2DFusion conv2_d_fusion{}; 1989be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 1990be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 1991be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 1992be168c0dSopenharmony_ci- kernel_size = {}; 1993be168c0dSopenharmony_ci- } else { 1994be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 1995be168c0dSopenharmony_ci- } 1996be168c0dSopenharmony_ci- std::vector<int64_t> strides; 1997be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 1998be168c0dSopenharmony_ci- if (value->stride() == nullptr || value->stride()->size() < kNumTwo) { 1999be168c0dSopenharmony_ci- strides = {}; 2000be168c0dSopenharmony_ci- } else { 2001be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->stride()->begin(), value->stride()->end()); 2002be168c0dSopenharmony_ci- } 2003be168c0dSopenharmony_ci- std::vector<int64_t> dilation; 2004be168c0dSopenharmony_ci- dilation.reserve(kNumTwo); 2005be168c0dSopenharmony_ci- if (value->dilation() == nullptr || value->dilation()->size() < kNumTwo) { 2006be168c0dSopenharmony_ci- dilation = {}; 2007be168c0dSopenharmony_ci- } else { 2008be168c0dSopenharmony_ci- dilation = std::vector<int64_t>(value->dilation()->begin(), value->dilation()->end()); 2009be168c0dSopenharmony_ci- } 2010be168c0dSopenharmony_ci- std::vector<int64_t> padList; 2011be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 2012be168c0dSopenharmony_ci- if (value->pad_list() == nullptr || value->pad_list()->size() < kNumFour) { 2013be168c0dSopenharmony_ci- padList = {}; 2014be168c0dSopenharmony_ci- } else { 2015be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad_list()->begin(), value->pad_list()->end()); 2016be168c0dSopenharmony_ci- } 2017be168c0dSopenharmony_ci- conv2_d_fusion.kernelSize = kernel_size; 2018be168c0dSopenharmony_ci- conv2_d_fusion.stride = strides; 2019be168c0dSopenharmony_ci- conv2_d_fusion.dilation = dilation; 2020be168c0dSopenharmony_ci- conv2_d_fusion.padMode = static_cast<HDI::Nnrt::V1_0::PadMode>(value->pad_mode()); 2021be168c0dSopenharmony_ci- conv2_d_fusion.padList = padList; 2022be168c0dSopenharmony_ci- conv2_d_fusion.group = value->group(); 2023be168c0dSopenharmony_ci- conv2_d_fusion.inChannel = value->in_channel(); 2024be168c0dSopenharmony_ci- conv2_d_fusion.outChannel = value->out_channel(); 2025be168c0dSopenharmony_ci- conv2_d_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2026be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2027be168c0dSopenharmony_ci- (void)Conv2DFusionBlockMarshalling(data, conv2_d_fusion); 2028be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2029be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2030be168c0dSopenharmony_ci- return ret; 2031be168c0dSopenharmony_ci- } else { 2032be168c0dSopenharmony_ci- return {}; 2033be168c0dSopenharmony_ci- } 2034be168c0dSopenharmony_ci- } else { 2035be168c0dSopenharmony_ci- return {}; 2036be168c0dSopenharmony_ci- } 2037be168c0dSopenharmony_ci-} 2038be168c0dSopenharmony_ci-std::vector<int8_t> ConvertConv2dTransposeFusion(PrimitivePtr primitive) { 2039be168c0dSopenharmony_ci- if (primitive != nullptr) { 2040be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2041be168c0dSopenharmony_ci- auto value = prim->value_as_Conv2dTransposeFusion(); 2042be168c0dSopenharmony_ci- if (value != nullptr) { 2043be168c0dSopenharmony_ci- Conv2dTransposeFusion conv2d_transpose_fusion{}; 2044be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 2045be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 2046be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 2047be168c0dSopenharmony_ci- kernel_size = {}; 2048be168c0dSopenharmony_ci- } else { 2049be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 2050be168c0dSopenharmony_ci- } 2051be168c0dSopenharmony_ci- std::vector<int64_t> strides; 2052be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 2053be168c0dSopenharmony_ci- if (value->stride() == nullptr || value->stride()->size() < kNumTwo) { 2054be168c0dSopenharmony_ci- strides = {}; 2055be168c0dSopenharmony_ci- } else { 2056be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->stride()->begin(), value->stride()->end()); 2057be168c0dSopenharmony_ci- } 2058be168c0dSopenharmony_ci- std::vector<int64_t> dilation; 2059be168c0dSopenharmony_ci- dilation.reserve(kNumTwo); 2060be168c0dSopenharmony_ci- if (value->dilation() == nullptr || value->dilation()->size() < kNumTwo) { 2061be168c0dSopenharmony_ci- dilation = {}; 2062be168c0dSopenharmony_ci- } else { 2063be168c0dSopenharmony_ci- dilation = std::vector<int64_t>(value->dilation()->begin(), value->dilation()->end()); 2064be168c0dSopenharmony_ci- } 2065be168c0dSopenharmony_ci- std::vector<int64_t> padList; 2066be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 2067be168c0dSopenharmony_ci- if (value->pad_list() == nullptr || value->pad_list()->size() < kNumFour) { 2068be168c0dSopenharmony_ci- padList = {}; 2069be168c0dSopenharmony_ci- } else { 2070be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad_list()->begin(), value->pad_list()->end()); 2071be168c0dSopenharmony_ci- } 2072be168c0dSopenharmony_ci- std::vector<int64_t> output_paddings; 2073be168c0dSopenharmony_ci- output_paddings.reserve(kNumTwo); 2074be168c0dSopenharmony_ci- if (value->output_paddings() == nullptr || value->output_paddings()->size() < kNumTwo) { 2075be168c0dSopenharmony_ci- output_paddings = {}; 2076be168c0dSopenharmony_ci- } else { 2077be168c0dSopenharmony_ci- output_paddings = std::vector<int64_t>(value->output_paddings()->begin(), value->output_paddings()->end()); 2078be168c0dSopenharmony_ci- } 2079be168c0dSopenharmony_ci- conv2d_transpose_fusion.kernelSize = kernel_size; 2080be168c0dSopenharmony_ci- conv2d_transpose_fusion.stride = strides; 2081be168c0dSopenharmony_ci- conv2d_transpose_fusion.dilation = dilation; 2082be168c0dSopenharmony_ci- conv2d_transpose_fusion.padMode = static_cast<HDI::Nnrt::V1_0::PadMode>(value->pad_mode()); 2083be168c0dSopenharmony_ci- conv2d_transpose_fusion.padList = padList; 2084be168c0dSopenharmony_ci- conv2d_transpose_fusion.group = value->group(); 2085be168c0dSopenharmony_ci- conv2d_transpose_fusion.inChannel = value->in_channel(); 2086be168c0dSopenharmony_ci- conv2d_transpose_fusion.outChannel = value->out_channel(); 2087be168c0dSopenharmony_ci- conv2d_transpose_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2088be168c0dSopenharmony_ci- conv2d_transpose_fusion.outputPaddings = output_paddings; 2089be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2090be168c0dSopenharmony_ci- (void)Conv2dTransposeFusionBlockMarshalling(data, conv2d_transpose_fusion); 2091be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2092be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2093be168c0dSopenharmony_ci- return ret; 2094be168c0dSopenharmony_ci- } else { 2095be168c0dSopenharmony_ci- return {}; 2096be168c0dSopenharmony_ci- } 2097be168c0dSopenharmony_ci- } else { 2098be168c0dSopenharmony_ci- return {}; 2099be168c0dSopenharmony_ci- } 2100be168c0dSopenharmony_ci-} 2101be168c0dSopenharmony_ci-std::vector<int8_t> ConvertDivFusion(PrimitivePtr primitive) { 2102be168c0dSopenharmony_ci- if (primitive != nullptr) { 2103be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2104be168c0dSopenharmony_ci- auto value = prim->value_as_DivFusion(); 2105be168c0dSopenharmony_ci- if (value != nullptr) { 2106be168c0dSopenharmony_ci- DivFusion div_fusion{}; 2107be168c0dSopenharmony_ci- div_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2108be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2109be168c0dSopenharmony_ci- (void)DivFusionBlockMarshalling(data, div_fusion); 2110be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2111be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2112be168c0dSopenharmony_ci- return ret; 2113be168c0dSopenharmony_ci- } else { 2114be168c0dSopenharmony_ci- return {}; 2115be168c0dSopenharmony_ci- } 2116be168c0dSopenharmony_ci- } else { 2117be168c0dSopenharmony_ci- return {}; 2118be168c0dSopenharmony_ci- } 2119be168c0dSopenharmony_ci-} 2120be168c0dSopenharmony_ci-std::vector<int8_t> ConvertEltwise(PrimitivePtr primitive) { 2121be168c0dSopenharmony_ci- if (primitive != nullptr) { 2122be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2123be168c0dSopenharmony_ci- auto value = prim->value_as_Eltwise(); 2124be168c0dSopenharmony_ci- if (value != nullptr) { 2125be168c0dSopenharmony_ci- Eltwise eltwise{}; 2126be168c0dSopenharmony_ci- eltwise.mode = static_cast<HDI::Nnrt::V1_0::EltwiseMode>(value->mode()); 2127be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2128be168c0dSopenharmony_ci- (void)EltwiseBlockMarshalling(data, eltwise); 2129be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2130be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2131be168c0dSopenharmony_ci- return ret; 2132be168c0dSopenharmony_ci- } else { 2133be168c0dSopenharmony_ci- return {}; 2134be168c0dSopenharmony_ci- } 2135be168c0dSopenharmony_ci- } else { 2136be168c0dSopenharmony_ci- return {}; 2137be168c0dSopenharmony_ci- } 2138be168c0dSopenharmony_ci-} 2139be168c0dSopenharmony_ci-std::vector<int8_t> ConvertExpandDims(PrimitivePtr primitive) { 2140be168c0dSopenharmony_ci- if (primitive != nullptr) { 2141be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2142be168c0dSopenharmony_ci- auto value = prim->value_as_ExpandDims(); 2143be168c0dSopenharmony_ci- if (value != nullptr) { 2144be168c0dSopenharmony_ci- ExpandDims expand_dims{}; 2145be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2146be168c0dSopenharmony_ci- (void)ExpandDimsBlockMarshalling(data, expand_dims); 2147be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2148be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2149be168c0dSopenharmony_ci- return ret; 2150be168c0dSopenharmony_ci- } else { 2151be168c0dSopenharmony_ci- return {}; 2152be168c0dSopenharmony_ci- } 2153be168c0dSopenharmony_ci- } else { 2154be168c0dSopenharmony_ci- return {}; 2155be168c0dSopenharmony_ci- } 2156be168c0dSopenharmony_ci-} 2157be168c0dSopenharmony_ci-std::vector<int8_t> ConvertFill(PrimitivePtr primitive) { 2158be168c0dSopenharmony_ci- if (primitive != nullptr) { 2159be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2160be168c0dSopenharmony_ci- auto value = prim->value_as_Fill(); 2161be168c0dSopenharmony_ci- if (value != nullptr) { 2162be168c0dSopenharmony_ci- Fill fill{}; 2163be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2164be168c0dSopenharmony_ci- (void)FillBlockMarshalling(data, fill); 2165be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2166be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2167be168c0dSopenharmony_ci- return ret; 2168be168c0dSopenharmony_ci- } else { 2169be168c0dSopenharmony_ci- return {}; 2170be168c0dSopenharmony_ci- } 2171be168c0dSopenharmony_ci- } else { 2172be168c0dSopenharmony_ci- return {}; 2173be168c0dSopenharmony_ci- } 2174be168c0dSopenharmony_ci-} 2175be168c0dSopenharmony_ci-std::vector<int8_t> ConvertFullConnection(PrimitivePtr primitive) { 2176be168c0dSopenharmony_ci- if (primitive != nullptr) { 2177be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2178be168c0dSopenharmony_ci- auto value = prim->value_as_FullConnection(); 2179be168c0dSopenharmony_ci- if (value != nullptr) { 2180be168c0dSopenharmony_ci- FullConnection full_connection{}; 2181be168c0dSopenharmony_ci- full_connection.hasBias = value->has_bias(); 2182be168c0dSopenharmony_ci- full_connection.useAxis = value->use_axis(); 2183be168c0dSopenharmony_ci- full_connection.axis = value->axis(); 2184be168c0dSopenharmony_ci- full_connection.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2185be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2186be168c0dSopenharmony_ci- (void)FullConnectionBlockMarshalling(data, full_connection); 2187be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2188be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2189be168c0dSopenharmony_ci- return ret; 2190be168c0dSopenharmony_ci- } else { 2191be168c0dSopenharmony_ci- return {}; 2192be168c0dSopenharmony_ci- } 2193be168c0dSopenharmony_ci- } else { 2194be168c0dSopenharmony_ci- return {}; 2195be168c0dSopenharmony_ci- } 2196be168c0dSopenharmony_ci-} 2197be168c0dSopenharmony_ci-std::vector<int8_t> ConvertFusedBatchNorm(PrimitivePtr primitive) { 2198be168c0dSopenharmony_ci- if (primitive != nullptr) { 2199be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2200be168c0dSopenharmony_ci- auto value = prim->value_as_FusedBatchNorm(); 2201be168c0dSopenharmony_ci- if (value != nullptr) { 2202be168c0dSopenharmony_ci- FusedBatchNorm fused_batch_norm{}; 2203be168c0dSopenharmony_ci- fused_batch_norm.epsilon = value->epsilon(); 2204be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2205be168c0dSopenharmony_ci- (void)FusedBatchNormBlockMarshalling(data, fused_batch_norm); 2206be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2207be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2208be168c0dSopenharmony_ci- return ret; 2209be168c0dSopenharmony_ci- } else { 2210be168c0dSopenharmony_ci- return {}; 2211be168c0dSopenharmony_ci- } 2212be168c0dSopenharmony_ci- } else { 2213be168c0dSopenharmony_ci- return {}; 2214be168c0dSopenharmony_ci- } 2215be168c0dSopenharmony_ci-} 2216be168c0dSopenharmony_ci-std::vector<int8_t> ConvertGather(PrimitivePtr primitive) { 2217be168c0dSopenharmony_ci- if (primitive != nullptr) { 2218be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2219be168c0dSopenharmony_ci- auto value = prim->value_as_Gather(); 2220be168c0dSopenharmony_ci- if (value != nullptr) { 2221be168c0dSopenharmony_ci- Gather gather{}; 2222be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2223be168c0dSopenharmony_ci- (void)GatherBlockMarshalling(data, gather); 2224be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2225be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2226be168c0dSopenharmony_ci- return ret; 2227be168c0dSopenharmony_ci- } else { 2228be168c0dSopenharmony_ci- return {}; 2229be168c0dSopenharmony_ci- } 2230be168c0dSopenharmony_ci- } else { 2231be168c0dSopenharmony_ci- return {}; 2232be168c0dSopenharmony_ci- } 2233be168c0dSopenharmony_ci-} 2234be168c0dSopenharmony_ci-std::vector<int8_t> ConvertLayerNormFusion(PrimitivePtr primitive) { 2235be168c0dSopenharmony_ci- if (primitive != nullptr) { 2236be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2237be168c0dSopenharmony_ci- auto value = prim->value_as_LayerNormFusion(); 2238be168c0dSopenharmony_ci- if (value != nullptr) { 2239be168c0dSopenharmony_ci- LayerNormFusion layer_norm_fusion{}; 2240be168c0dSopenharmony_ci- layer_norm_fusion.beginNormAxis = value->begin_norm_axis(); 2241be168c0dSopenharmony_ci- layer_norm_fusion.epsilon = value->epsilon(); 2242be168c0dSopenharmony_ci- layer_norm_fusion.elementwiseAffine = value->elementwise_affine(); 2243be168c0dSopenharmony_ci- layer_norm_fusion.beginParamsAxis = value->begin_params_axis(); 2244be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2245be168c0dSopenharmony_ci- (void)LayerNormFusionBlockMarshalling(data, layer_norm_fusion); 2246be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2247be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2248be168c0dSopenharmony_ci- return ret; 2249be168c0dSopenharmony_ci- } else { 2250be168c0dSopenharmony_ci- return {}; 2251be168c0dSopenharmony_ci- } 2252be168c0dSopenharmony_ci- } else { 2253be168c0dSopenharmony_ci- return {}; 2254be168c0dSopenharmony_ci- } 2255be168c0dSopenharmony_ci-} 2256be168c0dSopenharmony_ci-std::vector<int8_t> ConvertLessEqual(PrimitivePtr primitive) { 2257be168c0dSopenharmony_ci- if (primitive != nullptr) { 2258be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2259be168c0dSopenharmony_ci- auto value = prim->value_as_LessEqual(); 2260be168c0dSopenharmony_ci- if (value != nullptr) { 2261be168c0dSopenharmony_ci- LessEqual less_equal{}; 2262be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2263be168c0dSopenharmony_ci- (void)LessEqualBlockMarshalling(data, less_equal); 2264be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2265be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2266be168c0dSopenharmony_ci- return ret; 2267be168c0dSopenharmony_ci- } else { 2268be168c0dSopenharmony_ci- return {}; 2269be168c0dSopenharmony_ci- } 2270be168c0dSopenharmony_ci- } else { 2271be168c0dSopenharmony_ci- return {}; 2272be168c0dSopenharmony_ci- } 2273be168c0dSopenharmony_ci-} 2274be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMatMulFusion(PrimitivePtr primitive) { 2275be168c0dSopenharmony_ci- if (primitive != nullptr) { 2276be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2277be168c0dSopenharmony_ci- auto value = prim->value_as_MatMulFusion(); 2278be168c0dSopenharmony_ci- if (value != nullptr) { 2279be168c0dSopenharmony_ci- MatMulFusion mat_mul_fusion{}; 2280be168c0dSopenharmony_ci- mat_mul_fusion.transposeA = value->transpose_a(); 2281be168c0dSopenharmony_ci- mat_mul_fusion.transposeB = value->transpose_b(); 2282be168c0dSopenharmony_ci- mat_mul_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2283be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2284be168c0dSopenharmony_ci- (void)MatMulFusionBlockMarshalling(data, mat_mul_fusion); 2285be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2286be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2287be168c0dSopenharmony_ci- return ret; 2288be168c0dSopenharmony_ci- } else { 2289be168c0dSopenharmony_ci- return {}; 2290be168c0dSopenharmony_ci- } 2291be168c0dSopenharmony_ci- } else { 2292be168c0dSopenharmony_ci- return {}; 2293be168c0dSopenharmony_ci- } 2294be168c0dSopenharmony_ci-} 2295be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMaximum(PrimitivePtr primitive) { 2296be168c0dSopenharmony_ci- if (primitive != nullptr) { 2297be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2298be168c0dSopenharmony_ci- auto value = prim->value_as_Maximum(); 2299be168c0dSopenharmony_ci- if (value != nullptr) { 2300be168c0dSopenharmony_ci- Maximum maximum{}; 2301be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2302be168c0dSopenharmony_ci- (void)MaximumBlockMarshalling(data, maximum); 2303be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2304be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2305be168c0dSopenharmony_ci- return ret; 2306be168c0dSopenharmony_ci- } else { 2307be168c0dSopenharmony_ci- return {}; 2308be168c0dSopenharmony_ci- } 2309be168c0dSopenharmony_ci- } else { 2310be168c0dSopenharmony_ci- return {}; 2311be168c0dSopenharmony_ci- } 2312be168c0dSopenharmony_ci-} 2313be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMaxPoolFusion(PrimitivePtr primitive) { 2314be168c0dSopenharmony_ci- if (primitive != nullptr) { 2315be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2316be168c0dSopenharmony_ci- auto value = prim->value_as_MaxPoolFusion(); 2317be168c0dSopenharmony_ci- if (value != nullptr) { 2318be168c0dSopenharmony_ci- MaxPoolFusion max_pool_fusion{}; 2319be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 2320be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 2321be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 2322be168c0dSopenharmony_ci- kernel_size = {}; 2323be168c0dSopenharmony_ci- } else { 2324be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 2325be168c0dSopenharmony_ci- } 2326be168c0dSopenharmony_ci- std::vector<int64_t> strides; 2327be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 2328be168c0dSopenharmony_ci- if (value->strides() == nullptr || value->strides()->size() < kNumTwo) { 2329be168c0dSopenharmony_ci- strides = {}; 2330be168c0dSopenharmony_ci- } else { 2331be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->strides()->begin(), value->strides()->end()); 2332be168c0dSopenharmony_ci- } 2333be168c0dSopenharmony_ci- std::vector<int64_t> padList; 2334be168c0dSopenharmony_ci- padList.reserve(kNumFour); 2335be168c0dSopenharmony_ci- if (value->pad() == nullptr || value->pad()->size() < kNumFour) { 2336be168c0dSopenharmony_ci- padList = {}; 2337be168c0dSopenharmony_ci- } else { 2338be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad()->begin(), value->pad()->end()); 2339be168c0dSopenharmony_ci- } 2340be168c0dSopenharmony_ci- max_pool_fusion.kernelSize = kernel_size; 2341be168c0dSopenharmony_ci- max_pool_fusion.strides = strides; 2342be168c0dSopenharmony_ci- max_pool_fusion.pad = padList; 2343be168c0dSopenharmony_ci- max_pool_fusion.padMode = static_cast<HDI::Nnrt::V1_0::PadMode>(value->pad_mode()); 2344be168c0dSopenharmony_ci- max_pool_fusion.format = static_cast<HDI::Nnrt::V1_0::Format>(value->format()); 2345be168c0dSopenharmony_ci- max_pool_fusion.global = value->global(); 2346be168c0dSopenharmony_ci- max_pool_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2347be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2348be168c0dSopenharmony_ci- (void)MaxPoolFusionBlockMarshalling(data, max_pool_fusion); 2349be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2350be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2351be168c0dSopenharmony_ci- return ret; 2352be168c0dSopenharmony_ci- } else { 2353be168c0dSopenharmony_ci- return {}; 2354be168c0dSopenharmony_ci- } 2355be168c0dSopenharmony_ci- } else { 2356be168c0dSopenharmony_ci- return {}; 2357be168c0dSopenharmony_ci- } 2358be168c0dSopenharmony_ci-} 2359be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMulFusion(PrimitivePtr primitive) { 2360be168c0dSopenharmony_ci- if (primitive != nullptr) { 2361be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2362be168c0dSopenharmony_ci- auto value = prim->value_as_MulFusion(); 2363be168c0dSopenharmony_ci- if (value != nullptr) { 2364be168c0dSopenharmony_ci- MulFusion mul_fusion{}; 2365be168c0dSopenharmony_ci- mul_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2366be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2367be168c0dSopenharmony_ci- (void)MulFusionBlockMarshalling(data, mul_fusion); 2368be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2369be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2370be168c0dSopenharmony_ci- return ret; 2371be168c0dSopenharmony_ci- } else { 2372be168c0dSopenharmony_ci- return {}; 2373be168c0dSopenharmony_ci- } 2374be168c0dSopenharmony_ci- } else { 2375be168c0dSopenharmony_ci- return {}; 2376be168c0dSopenharmony_ci- } 2377be168c0dSopenharmony_ci-} 2378be168c0dSopenharmony_ci-std::vector<int8_t> ConvertOneHot(PrimitivePtr primitive) { 2379be168c0dSopenharmony_ci- if (primitive != nullptr) { 2380be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2381be168c0dSopenharmony_ci- auto value = prim->value_as_OneHot(); 2382be168c0dSopenharmony_ci- if (value != nullptr) { 2383be168c0dSopenharmony_ci- OneHot one_hot{}; 2384be168c0dSopenharmony_ci- one_hot.axis = value->axis(); 2385be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2386be168c0dSopenharmony_ci- (void)OneHotBlockMarshalling(data, one_hot); 2387be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2388be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2389be168c0dSopenharmony_ci- return ret; 2390be168c0dSopenharmony_ci- } else { 2391be168c0dSopenharmony_ci- return {}; 2392be168c0dSopenharmony_ci- } 2393be168c0dSopenharmony_ci- } else { 2394be168c0dSopenharmony_ci- return {}; 2395be168c0dSopenharmony_ci- } 2396be168c0dSopenharmony_ci-} 2397be168c0dSopenharmony_ci-std::vector<int8_t> ConvertPadFusion(PrimitivePtr primitive) { 2398be168c0dSopenharmony_ci- if (primitive != nullptr) { 2399be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2400be168c0dSopenharmony_ci- auto value = prim->value_as_PadFusion(); 2401be168c0dSopenharmony_ci- if (value != nullptr) { 2402be168c0dSopenharmony_ci- PadFusion pad_fusion{}; 2403be168c0dSopenharmony_ci- auto paddings = value->paddings(); 2404be168c0dSopenharmony_ci- std::vector<std::vector<int64_t>> paddings_vec2d; 2405be168c0dSopenharmony_ci- if (paddings == nullptr || paddings->data()->size() < kNumTwo) { 2406be168c0dSopenharmony_ci- paddings_vec2d = {{0}, {0}, {0}, {0}}; 2407be168c0dSopenharmony_ci- } else { 2408be168c0dSopenharmony_ci- paddings_vec2d.reserve(paddings->data()->size()); 2409be168c0dSopenharmony_ci- for (size_t i = 0; i < paddings->data()->size(); i++) { 2410be168c0dSopenharmony_ci- auto vet = paddings->data()->Get(i); 2411be168c0dSopenharmony_ci- paddings_vec2d.emplace_back(std::vector<int64_t>(vet->data()->begin(), vet->data()->end())); 2412be168c0dSopenharmony_ci- } 2413be168c0dSopenharmony_ci- } 2414be168c0dSopenharmony_ci- pad_fusion.paddings = paddings_vec2d; 2415be168c0dSopenharmony_ci- pad_fusion.paddingMode = static_cast<HDI::Nnrt::V1_0::PaddingMode>(value->padding_mode()); 2416be168c0dSopenharmony_ci- pad_fusion.constantValue = value->constant_value(); 2417be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2418be168c0dSopenharmony_ci- (void)PadFusionBlockMarshalling(data, pad_fusion); 2419be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2420be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2421be168c0dSopenharmony_ci- return ret; 2422be168c0dSopenharmony_ci- } else { 2423be168c0dSopenharmony_ci- return {}; 2424be168c0dSopenharmony_ci- } 2425be168c0dSopenharmony_ci- } else { 2426be168c0dSopenharmony_ci- return {}; 2427be168c0dSopenharmony_ci- } 2428be168c0dSopenharmony_ci-} 2429be168c0dSopenharmony_ci-std::vector<int8_t> ConvertPowFusion(PrimitivePtr primitive) { 2430be168c0dSopenharmony_ci- if (primitive != nullptr) { 2431be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2432be168c0dSopenharmony_ci- auto value = prim->value_as_PowFusion(); 2433be168c0dSopenharmony_ci- if (value != nullptr) { 2434be168c0dSopenharmony_ci- PowFusion pow_fusion{}; 2435be168c0dSopenharmony_ci- pow_fusion.scale = value->scale(); 2436be168c0dSopenharmony_ci- pow_fusion.shift = value->shift(); 2437be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2438be168c0dSopenharmony_ci- (void)PowFusionBlockMarshalling(data, pow_fusion); 2439be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2440be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2441be168c0dSopenharmony_ci- return ret; 2442be168c0dSopenharmony_ci- } else { 2443be168c0dSopenharmony_ci- return {}; 2444be168c0dSopenharmony_ci- } 2445be168c0dSopenharmony_ci- } else { 2446be168c0dSopenharmony_ci- return {}; 2447be168c0dSopenharmony_ci- } 2448be168c0dSopenharmony_ci-} 2449be168c0dSopenharmony_ci-std::vector<int8_t> ConvertPReLUFusion(PrimitivePtr primitive) { 2450be168c0dSopenharmony_ci- if (primitive != nullptr) { 2451be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2452be168c0dSopenharmony_ci- auto value = prim->value_as_PReLUFusion(); 2453be168c0dSopenharmony_ci- if (value != nullptr) { 2454be168c0dSopenharmony_ci- PReLUFusion p_re_l_u_fusion{}; 2455be168c0dSopenharmony_ci- p_re_l_u_fusion.channelShared = value->channel_shared(); 2456be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2457be168c0dSopenharmony_ci- (void)PReLUFusionBlockMarshalling(data, p_re_l_u_fusion); 2458be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2459be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2460be168c0dSopenharmony_ci- return ret; 2461be168c0dSopenharmony_ci- } else { 2462be168c0dSopenharmony_ci- return {}; 2463be168c0dSopenharmony_ci- } 2464be168c0dSopenharmony_ci- } else { 2465be168c0dSopenharmony_ci- return {}; 2466be168c0dSopenharmony_ci- } 2467be168c0dSopenharmony_ci-} 2468be168c0dSopenharmony_ci-std::vector<int8_t> ConvertQuantDTypeCast(PrimitivePtr primitive) { 2469be168c0dSopenharmony_ci- if (primitive != nullptr) { 2470be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2471be168c0dSopenharmony_ci- auto value = prim->value_as_QuantDTypeCast(); 2472be168c0dSopenharmony_ci- if (value != nullptr) { 2473be168c0dSopenharmony_ci- QuantDTypeCast quant_d_type_cast{}; 2474be168c0dSopenharmony_ci- quant_d_type_cast.srcT = value->src_t(); 2475be168c0dSopenharmony_ci- quant_d_type_cast.dstT = value->dst_t(); 2476be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2477be168c0dSopenharmony_ci- (void)QuantDTypeCastBlockMarshalling(data, quant_d_type_cast); 2478be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2479be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2480be168c0dSopenharmony_ci- return ret; 2481be168c0dSopenharmony_ci- } else { 2482be168c0dSopenharmony_ci- return {}; 2483be168c0dSopenharmony_ci- } 2484be168c0dSopenharmony_ci- } else { 2485be168c0dSopenharmony_ci- return {}; 2486be168c0dSopenharmony_ci- } 2487be168c0dSopenharmony_ci-} 2488be168c0dSopenharmony_ci-std::vector<int8_t> ConvertReduceFusion(PrimitivePtr primitive) { 2489be168c0dSopenharmony_ci- if (primitive != nullptr) { 2490be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2491be168c0dSopenharmony_ci- auto value = prim->value_as_ReduceFusion(); 2492be168c0dSopenharmony_ci- if (value != nullptr) { 2493be168c0dSopenharmony_ci- ReduceFusion reduce_fusion{}; 2494be168c0dSopenharmony_ci- reduce_fusion.keepDims = value->keep_dims(); 2495be168c0dSopenharmony_ci- reduce_fusion.mode = static_cast<HDI::Nnrt::V1_0::ReduceMode>(value->mode()); 2496be168c0dSopenharmony_ci- reduce_fusion.reduceToEnd = value->reduce_to_end(); 2497be168c0dSopenharmony_ci- reduce_fusion.coeff = value->coeff(); 2498be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2499be168c0dSopenharmony_ci- (void)ReduceFusionBlockMarshalling(data, reduce_fusion); 2500be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2501be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2502be168c0dSopenharmony_ci- return ret; 2503be168c0dSopenharmony_ci- } else { 2504be168c0dSopenharmony_ci- return {}; 2505be168c0dSopenharmony_ci- } 2506be168c0dSopenharmony_ci- } else { 2507be168c0dSopenharmony_ci- return {}; 2508be168c0dSopenharmony_ci- } 2509be168c0dSopenharmony_ci-} 2510be168c0dSopenharmony_ci-std::vector<int8_t> ConvertReshape(PrimitivePtr primitive) { 2511be168c0dSopenharmony_ci- if (primitive != nullptr) { 2512be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2513be168c0dSopenharmony_ci- auto value = prim->value_as_Reshape(); 2514be168c0dSopenharmony_ci- if (value != nullptr) { 2515be168c0dSopenharmony_ci- Reshape reshape{}; 2516be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2517be168c0dSopenharmony_ci- (void)ReshapeBlockMarshalling(data, reshape); 2518be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2519be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2520be168c0dSopenharmony_ci- return ret; 2521be168c0dSopenharmony_ci- } else { 2522be168c0dSopenharmony_ci- return {}; 2523be168c0dSopenharmony_ci- } 2524be168c0dSopenharmony_ci- } else { 2525be168c0dSopenharmony_ci- return {}; 2526be168c0dSopenharmony_ci- } 2527be168c0dSopenharmony_ci-} 2528be168c0dSopenharmony_ci- 2529be168c0dSopenharmony_ci-std::vector<int8_t> ConvertResize(PrimitivePtr primitive) { 2530be168c0dSopenharmony_ci- if (primitive != nullptr) { 2531be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2532be168c0dSopenharmony_ci- auto value = prim->value_as_Resize(); 2533be168c0dSopenharmony_ci- if (value != nullptr) { 2534be168c0dSopenharmony_ci- Resize resize{}; 2535be168c0dSopenharmony_ci- resize.method = static_cast<HDI::Nnrt::V1_0::ResizeMethod>(value->method()); 2536be168c0dSopenharmony_ci- resize.newHeight = value->new_height(); 2537be168c0dSopenharmony_ci- resize.newWidth = value->new_width(); 2538be168c0dSopenharmony_ci- resize.preserveAspectRatio = value->preserve_aspect_ratio(); 2539be168c0dSopenharmony_ci- resize.coordinateTransformMode = 2540be168c0dSopenharmony_ci- static_cast<HDI::Nnrt::V1_0::CoordinateTransformMode>(value->coordinate_transform_mode()); 2541be168c0dSopenharmony_ci- resize.cubicCoeff = value->cubic_coeff(); 2542be168c0dSopenharmony_ci- resize.excludeOutside = value->exclude_outside(); 2543be168c0dSopenharmony_ci- resize.extrapolationValue = value->extrapolation_value(); 2544be168c0dSopenharmony_ci- resize.nearestMode = static_cast<HDI::Nnrt::V1_0::NearestMode>(value->nearest_mode()); 2545be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2546be168c0dSopenharmony_ci- (void)ResizeBlockMarshalling(data, resize); 2547be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2548be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2549be168c0dSopenharmony_ci- return ret; 2550be168c0dSopenharmony_ci- } else { 2551be168c0dSopenharmony_ci- return {}; 2552be168c0dSopenharmony_ci- } 2553be168c0dSopenharmony_ci- } else { 2554be168c0dSopenharmony_ci- return {}; 2555be168c0dSopenharmony_ci- } 2556be168c0dSopenharmony_ci-} 2557be168c0dSopenharmony_ci-std::vector<int8_t> ConvertRsqrt(PrimitivePtr primitive) { 2558be168c0dSopenharmony_ci- if (primitive != nullptr) { 2559be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2560be168c0dSopenharmony_ci- auto value = prim->value_as_Rsqrt(); 2561be168c0dSopenharmony_ci- if (value != nullptr) { 2562be168c0dSopenharmony_ci- Rsqrt rsqrt{}; 2563be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2564be168c0dSopenharmony_ci- (void)RsqrtBlockMarshalling(data, rsqrt); 2565be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2566be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2567be168c0dSopenharmony_ci- return ret; 2568be168c0dSopenharmony_ci- } else { 2569be168c0dSopenharmony_ci- return {}; 2570be168c0dSopenharmony_ci- } 2571be168c0dSopenharmony_ci- } else { 2572be168c0dSopenharmony_ci- return {}; 2573be168c0dSopenharmony_ci- } 2574be168c0dSopenharmony_ci-} 2575be168c0dSopenharmony_ci-std::vector<int8_t> ConvertScaleFusion(PrimitivePtr primitive) { 2576be168c0dSopenharmony_ci- if (primitive != nullptr) { 2577be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2578be168c0dSopenharmony_ci- auto value = prim->value_as_ScaleFusion(); 2579be168c0dSopenharmony_ci- if (value != nullptr) { 2580be168c0dSopenharmony_ci- ScaleFusion scale_fusion{}; 2581be168c0dSopenharmony_ci- scale_fusion.axis = value->axis(); 2582be168c0dSopenharmony_ci- scale_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2583be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2584be168c0dSopenharmony_ci- (void)ScaleFusionBlockMarshalling(data, scale_fusion); 2585be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2586be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2587be168c0dSopenharmony_ci- return ret; 2588be168c0dSopenharmony_ci- } else { 2589be168c0dSopenharmony_ci- return {}; 2590be168c0dSopenharmony_ci- } 2591be168c0dSopenharmony_ci- } else { 2592be168c0dSopenharmony_ci- return {}; 2593be168c0dSopenharmony_ci- } 2594be168c0dSopenharmony_ci-} 2595be168c0dSopenharmony_ci-std::vector<int8_t> ConvertShape(PrimitivePtr primitive) { 2596be168c0dSopenharmony_ci- if (primitive != nullptr) { 2597be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2598be168c0dSopenharmony_ci- auto value = prim->value_as_Shape(); 2599be168c0dSopenharmony_ci- if (value != nullptr) { 2600be168c0dSopenharmony_ci- Shape shape{}; 2601be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2602be168c0dSopenharmony_ci- (void)ShapeBlockMarshalling(data, shape); 2603be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2604be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2605be168c0dSopenharmony_ci- return ret; 2606be168c0dSopenharmony_ci- } else { 2607be168c0dSopenharmony_ci- return {}; 2608be168c0dSopenharmony_ci- } 2609be168c0dSopenharmony_ci- } else { 2610be168c0dSopenharmony_ci- return {}; 2611be168c0dSopenharmony_ci- } 2612be168c0dSopenharmony_ci-} 2613be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSliceFusion(PrimitivePtr primitive) { 2614be168c0dSopenharmony_ci- if (primitive != nullptr) { 2615be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2616be168c0dSopenharmony_ci- auto value = prim->value_as_SliceFusion(); 2617be168c0dSopenharmony_ci- if (value != nullptr) { 2618be168c0dSopenharmony_ci- SliceFusion slice_fusion{}; 2619be168c0dSopenharmony_ci- std::vector<int64_t> axes; 2620be168c0dSopenharmony_ci- if (value->axes() == nullptr) { 2621be168c0dSopenharmony_ci- axes = {1, 2, 3, 4, 5, 6, 7}; 2622be168c0dSopenharmony_ci- } else { 2623be168c0dSopenharmony_ci- axes = std::vector<int64_t>(value->axes()->begin(), value->axes()->end()); 2624be168c0dSopenharmony_ci- } 2625be168c0dSopenharmony_ci- slice_fusion.axes = axes; 2626be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2627be168c0dSopenharmony_ci- (void)SliceFusionBlockMarshalling(data, slice_fusion); 2628be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2629be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2630be168c0dSopenharmony_ci- return ret; 2631be168c0dSopenharmony_ci- } else { 2632be168c0dSopenharmony_ci- return {}; 2633be168c0dSopenharmony_ci- } 2634be168c0dSopenharmony_ci- } else { 2635be168c0dSopenharmony_ci- return {}; 2636be168c0dSopenharmony_ci- } 2637be168c0dSopenharmony_ci-} 2638be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSoftmax(PrimitivePtr primitive) { 2639be168c0dSopenharmony_ci- if (primitive != nullptr) { 2640be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2641be168c0dSopenharmony_ci- auto value = prim->value_as_Softmax(); 2642be168c0dSopenharmony_ci- if (value != nullptr) { 2643be168c0dSopenharmony_ci- Softmax softmax{}; 2644be168c0dSopenharmony_ci- std::vector<int64_t> axis; 2645be168c0dSopenharmony_ci- if (value->axis() == nullptr) { 2646be168c0dSopenharmony_ci- axis = {}; 2647be168c0dSopenharmony_ci- } else { 2648be168c0dSopenharmony_ci- axis = std::vector<int64_t>(value->axis()->begin(), value->axis()->end()); 2649be168c0dSopenharmony_ci- } 2650be168c0dSopenharmony_ci- softmax.axis = axis; 2651be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2652be168c0dSopenharmony_ci- (void)SoftmaxBlockMarshalling(data, softmax); 2653be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2654be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2655be168c0dSopenharmony_ci- return ret; 2656be168c0dSopenharmony_ci- } else { 2657be168c0dSopenharmony_ci- return {}; 2658be168c0dSopenharmony_ci- } 2659be168c0dSopenharmony_ci- } else { 2660be168c0dSopenharmony_ci- return {}; 2661be168c0dSopenharmony_ci- } 2662be168c0dSopenharmony_ci-} 2663be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSpaceToBatchND(PrimitivePtr primitive) { 2664be168c0dSopenharmony_ci- if (primitive != nullptr) { 2665be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2666be168c0dSopenharmony_ci- auto value = prim->value_as_SpaceToBatchND(); 2667be168c0dSopenharmony_ci- if (value != nullptr) { 2668be168c0dSopenharmony_ci- SpaceToBatchND space_to_batch_n_d{}; 2669be168c0dSopenharmony_ci- std::vector<int64_t> blockShape; 2670be168c0dSopenharmony_ci- blockShape.reserve(kNumTwo); 2671be168c0dSopenharmony_ci- if (value->block_shape() == nullptr || value->block_shape()->size() < kNumTwo) { 2672be168c0dSopenharmony_ci- blockShape = {0, 0}; 2673be168c0dSopenharmony_ci- } else { 2674be168c0dSopenharmony_ci- blockShape = std::vector<int64_t>(value->block_shape()->begin(), value->block_shape()->end()); 2675be168c0dSopenharmony_ci- } 2676be168c0dSopenharmony_ci- space_to_batch_n_d.blockShape = blockShape; 2677be168c0dSopenharmony_ci- auto paddings = value->paddings(); 2678be168c0dSopenharmony_ci- std::vector<std::vector<int64_t>> paddings_vec2d; 2679be168c0dSopenharmony_ci- if (paddings == nullptr || paddings->data()->size() == 0 || *(paddings->data()->begin()) == nullptr || 2680be168c0dSopenharmony_ci- (*(paddings->data()->begin()))->data() == nullptr) { 2681be168c0dSopenharmony_ci- paddings_vec2d = {}; 2682be168c0dSopenharmony_ci- } else { 2683be168c0dSopenharmony_ci- paddings_vec2d.reserve(paddings->data()->size()); 2684be168c0dSopenharmony_ci- for (size_t i = 0; i < paddings->data()->size(); i++) { 2685be168c0dSopenharmony_ci- auto vet = paddings->data()->Get(i); 2686be168c0dSopenharmony_ci- paddings_vec2d.emplace_back(std::vector<int64_t>(vet->data()->begin(), vet->data()->end())); 2687be168c0dSopenharmony_ci- } 2688be168c0dSopenharmony_ci- } 2689be168c0dSopenharmony_ci- space_to_batch_n_d.paddings = paddings_vec2d; 2690be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2691be168c0dSopenharmony_ci- (void)SpaceToBatchNDBlockMarshalling(data, space_to_batch_n_d); 2692be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2693be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2694be168c0dSopenharmony_ci- return ret; 2695be168c0dSopenharmony_ci- } else { 2696be168c0dSopenharmony_ci- return {}; 2697be168c0dSopenharmony_ci- } 2698be168c0dSopenharmony_ci- } else { 2699be168c0dSopenharmony_ci- return {}; 2700be168c0dSopenharmony_ci- } 2701be168c0dSopenharmony_ci-} 2702be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSplit(PrimitivePtr primitive) { 2703be168c0dSopenharmony_ci- if (primitive != nullptr) { 2704be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2705be168c0dSopenharmony_ci- auto value = prim->value_as_Split(); 2706be168c0dSopenharmony_ci- if (value != nullptr) { 2707be168c0dSopenharmony_ci- Split split{}; 2708be168c0dSopenharmony_ci- split.outputNum = value->output_num(); 2709be168c0dSopenharmony_ci- std::vector<int64_t> sizeSplits; 2710be168c0dSopenharmony_ci- sizeSplits.reserve(split.outputNum); 2711be168c0dSopenharmony_ci- if (value->size_splits() == nullptr || value->size_splits()->size() <= static_cast<uint32_t>(split.outputNum)) { 2712be168c0dSopenharmony_ci- sizeSplits = {}; 2713be168c0dSopenharmony_ci- } else { 2714be168c0dSopenharmony_ci- sizeSplits = std::vector<int64_t>(value->size_splits()->begin(), value->size_splits()->end()); 2715be168c0dSopenharmony_ci- } 2716be168c0dSopenharmony_ci- split.sizeSplits = sizeSplits; 2717be168c0dSopenharmony_ci- split.axis = value->axis(); 2718be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2719be168c0dSopenharmony_ci- (void)SplitBlockMarshalling(data, split); 2720be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2721be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2722be168c0dSopenharmony_ci- return ret; 2723be168c0dSopenharmony_ci- } else { 2724be168c0dSopenharmony_ci- return {}; 2725be168c0dSopenharmony_ci- } 2726be168c0dSopenharmony_ci- } else { 2727be168c0dSopenharmony_ci- return {}; 2728be168c0dSopenharmony_ci- } 2729be168c0dSopenharmony_ci-} 2730be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSqrt(PrimitivePtr primitive) { 2731be168c0dSopenharmony_ci- if (primitive != nullptr) { 2732be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2733be168c0dSopenharmony_ci- auto value = prim->value_as_Sqrt(); 2734be168c0dSopenharmony_ci- if (value != nullptr) { 2735be168c0dSopenharmony_ci- Sqrt sqrt{}; 2736be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2737be168c0dSopenharmony_ci- (void)SqrtBlockMarshalling(data, sqrt); 2738be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2739be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2740be168c0dSopenharmony_ci- return ret; 2741be168c0dSopenharmony_ci- } else { 2742be168c0dSopenharmony_ci- return {}; 2743be168c0dSopenharmony_ci- } 2744be168c0dSopenharmony_ci- } else { 2745be168c0dSopenharmony_ci- return {}; 2746be168c0dSopenharmony_ci- } 2747be168c0dSopenharmony_ci-} 2748be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSquaredDifference(PrimitivePtr primitive) { 2749be168c0dSopenharmony_ci- if (primitive != nullptr) { 2750be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2751be168c0dSopenharmony_ci- auto value = prim->value_as_SquaredDifference(); 2752be168c0dSopenharmony_ci- if (value != nullptr) { 2753be168c0dSopenharmony_ci- SquaredDifference squared_difference{}; 2754be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2755be168c0dSopenharmony_ci- (void)SquaredDifferenceBlockMarshalling(data, squared_difference); 2756be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2757be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2758be168c0dSopenharmony_ci- return ret; 2759be168c0dSopenharmony_ci- } else { 2760be168c0dSopenharmony_ci- return {}; 2761be168c0dSopenharmony_ci- } 2762be168c0dSopenharmony_ci- } else { 2763be168c0dSopenharmony_ci- return {}; 2764be168c0dSopenharmony_ci- } 2765be168c0dSopenharmony_ci-} 2766be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSqueeze(PrimitivePtr primitive) { 2767be168c0dSopenharmony_ci- if (primitive != nullptr) { 2768be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2769be168c0dSopenharmony_ci- auto value = prim->value_as_Squeeze(); 2770be168c0dSopenharmony_ci- if (value != nullptr) { 2771be168c0dSopenharmony_ci- Squeeze squeeze{}; 2772be168c0dSopenharmony_ci- std::vector<int64_t> axis; 2773be168c0dSopenharmony_ci- if (value->axis() == nullptr) { 2774be168c0dSopenharmony_ci- axis = {}; 2775be168c0dSopenharmony_ci- } else { 2776be168c0dSopenharmony_ci- axis = std::vector<int64_t>(value->axis()->begin(), value->axis()->end()); 2777be168c0dSopenharmony_ci- } 2778be168c0dSopenharmony_ci- squeeze.axis = axis; 2779be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2780be168c0dSopenharmony_ci- (void)SqueezeBlockMarshalling(data, squeeze); 2781be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2782be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2783be168c0dSopenharmony_ci- return ret; 2784be168c0dSopenharmony_ci- } else { 2785be168c0dSopenharmony_ci- return {}; 2786be168c0dSopenharmony_ci- } 2787be168c0dSopenharmony_ci- } else { 2788be168c0dSopenharmony_ci- return {}; 2789be168c0dSopenharmony_ci- } 2790be168c0dSopenharmony_ci-} 2791be168c0dSopenharmony_ci-std::vector<int8_t> ConvertStack(PrimitivePtr primitive) { 2792be168c0dSopenharmony_ci- if (primitive != nullptr) { 2793be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2794be168c0dSopenharmony_ci- auto value = prim->value_as_Stack(); 2795be168c0dSopenharmony_ci- if (value != nullptr) { 2796be168c0dSopenharmony_ci- Stack stack{}; 2797be168c0dSopenharmony_ci- stack.axis = value->axis(); 2798be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2799be168c0dSopenharmony_ci- (void)StackBlockMarshalling(data, stack); 2800be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2801be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2802be168c0dSopenharmony_ci- return ret; 2803be168c0dSopenharmony_ci- } else { 2804be168c0dSopenharmony_ci- return {}; 2805be168c0dSopenharmony_ci- } 2806be168c0dSopenharmony_ci- } else { 2807be168c0dSopenharmony_ci- return {}; 2808be168c0dSopenharmony_ci- } 2809be168c0dSopenharmony_ci-} 2810be168c0dSopenharmony_ci-std::vector<int8_t> ConvertStridedSlice(PrimitivePtr primitive) { 2811be168c0dSopenharmony_ci- if (primitive != nullptr) { 2812be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2813be168c0dSopenharmony_ci- auto value = prim->value_as_StridedSlice(); 2814be168c0dSopenharmony_ci- if (value != nullptr) { 2815be168c0dSopenharmony_ci- StridedSlice strided_slice{}; 2816be168c0dSopenharmony_ci- strided_slice.beginMask = value->begin_mask(); 2817be168c0dSopenharmony_ci- strided_slice.endMask = value->end_mask(); 2818be168c0dSopenharmony_ci- strided_slice.ellipsisMask = value->ellipsis_mask(); 2819be168c0dSopenharmony_ci- strided_slice.newAxisMask = value->new_axis_mask(); 2820be168c0dSopenharmony_ci- strided_slice.shrinkAxisMask = value->shrink_axis_mask(); 2821be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2822be168c0dSopenharmony_ci- (void)StridedSliceBlockMarshalling(data, strided_slice); 2823be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2824be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2825be168c0dSopenharmony_ci- return ret; 2826be168c0dSopenharmony_ci- } else { 2827be168c0dSopenharmony_ci- return {}; 2828be168c0dSopenharmony_ci- } 2829be168c0dSopenharmony_ci- } else { 2830be168c0dSopenharmony_ci- return {}; 2831be168c0dSopenharmony_ci- } 2832be168c0dSopenharmony_ci-} 2833be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSubFusion(PrimitivePtr primitive) { 2834be168c0dSopenharmony_ci- if (primitive != nullptr) { 2835be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2836be168c0dSopenharmony_ci- auto value = prim->value_as_SubFusion(); 2837be168c0dSopenharmony_ci- if (value != nullptr) { 2838be168c0dSopenharmony_ci- SubFusion sub_fusion{}; 2839be168c0dSopenharmony_ci- sub_fusion.activationType = static_cast<HDI::Nnrt::V1_0::ActivationType>(value->activation_type()); 2840be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2841be168c0dSopenharmony_ci- (void)SubFusionBlockMarshalling(data, sub_fusion); 2842be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2843be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2844be168c0dSopenharmony_ci- return ret; 2845be168c0dSopenharmony_ci- } else { 2846be168c0dSopenharmony_ci- return {}; 2847be168c0dSopenharmony_ci- } 2848be168c0dSopenharmony_ci- } else { 2849be168c0dSopenharmony_ci- return {}; 2850be168c0dSopenharmony_ci- } 2851be168c0dSopenharmony_ci-} 2852be168c0dSopenharmony_ci-std::vector<int8_t> ConvertTileFusion(PrimitivePtr primitive) { 2853be168c0dSopenharmony_ci- if (primitive != nullptr) { 2854be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2855be168c0dSopenharmony_ci- auto value = prim->value_as_TileFusion(); 2856be168c0dSopenharmony_ci- if (value != nullptr) { 2857be168c0dSopenharmony_ci- TileFusion tile_fusion{}; 2858be168c0dSopenharmony_ci- std::vector<int64_t> dims; 2859be168c0dSopenharmony_ci- dims.reserve(kNumEight); 2860be168c0dSopenharmony_ci- if (value->dims() == nullptr) { 2861be168c0dSopenharmony_ci- dims = {0, 0, 0, 0, 0, 0, 0, 0}; 2862be168c0dSopenharmony_ci- } else { 2863be168c0dSopenharmony_ci- dims = std::vector<int64_t>(value->dims()->begin(), value->dims()->end()); 2864be168c0dSopenharmony_ci- } 2865be168c0dSopenharmony_ci- tile_fusion.dims = dims; 2866be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2867be168c0dSopenharmony_ci- (void)TileFusionBlockMarshalling(data, tile_fusion); 2868be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2869be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2870be168c0dSopenharmony_ci- return ret; 2871be168c0dSopenharmony_ci- } else { 2872be168c0dSopenharmony_ci- return {}; 2873be168c0dSopenharmony_ci- } 2874be168c0dSopenharmony_ci- } else { 2875be168c0dSopenharmony_ci- return {}; 2876be168c0dSopenharmony_ci- } 2877be168c0dSopenharmony_ci-} 2878be168c0dSopenharmony_ci-std::vector<int8_t> ConvertTopKFusion(PrimitivePtr primitive) { 2879be168c0dSopenharmony_ci- if (primitive != nullptr) { 2880be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2881be168c0dSopenharmony_ci- auto value = prim->value_as_TopKFusion(); 2882be168c0dSopenharmony_ci- if (value != nullptr) { 2883be168c0dSopenharmony_ci- TopKFusion top_k_fusion{}; 2884be168c0dSopenharmony_ci- top_k_fusion.sorted = value->sorted(); 2885be168c0dSopenharmony_ci- top_k_fusion.axis = value->axis(); 2886be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2887be168c0dSopenharmony_ci- (void)TopKFusionBlockMarshalling(data, top_k_fusion); 2888be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2889be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2890be168c0dSopenharmony_ci- return ret; 2891be168c0dSopenharmony_ci- } else { 2892be168c0dSopenharmony_ci- return {}; 2893be168c0dSopenharmony_ci- } 2894be168c0dSopenharmony_ci- } else { 2895be168c0dSopenharmony_ci- return {}; 2896be168c0dSopenharmony_ci- } 2897be168c0dSopenharmony_ci-} 2898be168c0dSopenharmony_ci-std::vector<int8_t> ConvertTranspose(PrimitivePtr primitive) { 2899be168c0dSopenharmony_ci- if (primitive != nullptr) { 2900be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2901be168c0dSopenharmony_ci- auto value = prim->value_as_Transpose(); 2902be168c0dSopenharmony_ci- if (value != nullptr) { 2903be168c0dSopenharmony_ci- Transpose transpose{}; 2904be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2905be168c0dSopenharmony_ci- (void)TransposeBlockMarshalling(data, transpose); 2906be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2907be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2908be168c0dSopenharmony_ci- return ret; 2909be168c0dSopenharmony_ci- } else { 2910be168c0dSopenharmony_ci- return {}; 2911be168c0dSopenharmony_ci- } 2912be168c0dSopenharmony_ci- } else { 2913be168c0dSopenharmony_ci- return {}; 2914be168c0dSopenharmony_ci- } 2915be168c0dSopenharmony_ci-} 2916be168c0dSopenharmony_ci-std::vector<int8_t> ConvertUnsqueeze(PrimitivePtr primitive) { 2917be168c0dSopenharmony_ci- if (primitive != nullptr) { 2918be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 2919be168c0dSopenharmony_ci- auto value = prim->value_as_Unsqueeze(); 2920be168c0dSopenharmony_ci- if (value != nullptr) { 2921be168c0dSopenharmony_ci- Unsqueeze unsqueeze{}; 2922be168c0dSopenharmony_ci- std::vector<int64_t> axis; 2923be168c0dSopenharmony_ci- axis.reserve(kNumEight); 2924be168c0dSopenharmony_ci- if (value->axis() == nullptr) { 2925be168c0dSopenharmony_ci- axis = {0, 0, 0, 0}; 2926be168c0dSopenharmony_ci- } else { 2927be168c0dSopenharmony_ci- axis = std::vector<int64_t>(value->axis()->begin(), value->axis()->end()); 2928be168c0dSopenharmony_ci- } 2929be168c0dSopenharmony_ci- unsqueeze.axis = axis; 2930be168c0dSopenharmony_ci- OHOS::MessageParcel data; 2931be168c0dSopenharmony_ci- (void)UnsqueezeBlockMarshalling(data, unsqueeze); 2932be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 2933be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 2934be168c0dSopenharmony_ci- return ret; 2935be168c0dSopenharmony_ci- } else { 2936be168c0dSopenharmony_ci- return {}; 2937be168c0dSopenharmony_ci- } 2938be168c0dSopenharmony_ci- } else { 2939be168c0dSopenharmony_ci- return {}; 2940be168c0dSopenharmony_ci- } 2941be168c0dSopenharmony_ci-} 2942be168c0dSopenharmony_ci- 2943be168c0dSopenharmony_ci-std::vector<int8_t> Convert(NodeType type, PrimitivePtr primitive) { 2944be168c0dSopenharmony_ci- switch (type) { 2945be168c0dSopenharmony_ci- case NODE_TYPE_ACTIVATION: 2946be168c0dSopenharmony_ci- return ConvertActivation(primitive); 2947be168c0dSopenharmony_ci- break; 2948be168c0dSopenharmony_ci- case NODE_TYPE_ADD_FUSION: 2949be168c0dSopenharmony_ci- return ConvertAddFusion(primitive); 2950be168c0dSopenharmony_ci- break; 2951be168c0dSopenharmony_ci- case NODE_TYPE_ARGMAX_FUSION: 2952be168c0dSopenharmony_ci- return ConvertArgMaxFusion(primitive); 2953be168c0dSopenharmony_ci- break; 2954be168c0dSopenharmony_ci- case NODE_TYPE_AVG_POOL_FUSION: 2955be168c0dSopenharmony_ci- return ConvertAvgPoolFusion(primitive); 2956be168c0dSopenharmony_ci- break; 2957be168c0dSopenharmony_ci- case NODE_TYPE_BATCH_TO_SPACE_ND: 2958be168c0dSopenharmony_ci- return ConvertBatchToSpaceND(primitive); 2959be168c0dSopenharmony_ci- break; 2960be168c0dSopenharmony_ci- case NODE_TYPE_BIAS_ADD: 2961be168c0dSopenharmony_ci- return ConvertBiasAdd(primitive); 2962be168c0dSopenharmony_ci- break; 2963be168c0dSopenharmony_ci- case NODE_TYPE_CAST: 2964be168c0dSopenharmony_ci- return ConvertCast(primitive); 2965be168c0dSopenharmony_ci- break; 2966be168c0dSopenharmony_ci- case NODE_TYPE_CONCAT: 2967be168c0dSopenharmony_ci- return ConvertConcat(primitive); 2968be168c0dSopenharmony_ci- break; 2969be168c0dSopenharmony_ci- case NODE_TYPE_CONV2D_FUSION: 2970be168c0dSopenharmony_ci- return ConvertConv2DFusion(primitive); 2971be168c0dSopenharmony_ci- break; 2972be168c0dSopenharmony_ci- case NODE_TYPE_CONV2D_TRANSPOSE_FUSION: 2973be168c0dSopenharmony_ci- return ConvertConv2dTransposeFusion(primitive); 2974be168c0dSopenharmony_ci- break; 2975be168c0dSopenharmony_ci- case NODE_TYPE_DIV_FUSION: 2976be168c0dSopenharmony_ci- return ConvertDivFusion(primitive); 2977be168c0dSopenharmony_ci- break; 2978be168c0dSopenharmony_ci- case NODE_TYPE_ELTWISE: 2979be168c0dSopenharmony_ci- return ConvertEltwise(primitive); 2980be168c0dSopenharmony_ci- break; 2981be168c0dSopenharmony_ci- case NODE_TYPE_EXPAND_DIMS: 2982be168c0dSopenharmony_ci- return ConvertExpandDims(primitive); 2983be168c0dSopenharmony_ci- break; 2984be168c0dSopenharmony_ci- case NODE_TYPE_FILL: 2985be168c0dSopenharmony_ci- return ConvertFill(primitive); 2986be168c0dSopenharmony_ci- break; 2987be168c0dSopenharmony_ci- case NODE_TYPE_FULL_CONNECTION: 2988be168c0dSopenharmony_ci- return ConvertFullConnection(primitive); 2989be168c0dSopenharmony_ci- break; 2990be168c0dSopenharmony_ci- case NODE_TYPE_FUSED_BATCH_NORM: 2991be168c0dSopenharmony_ci- return ConvertFusedBatchNorm(primitive); 2992be168c0dSopenharmony_ci- break; 2993be168c0dSopenharmony_ci- case NODE_TYPE_GATHER: 2994be168c0dSopenharmony_ci- return ConvertGather(primitive); 2995be168c0dSopenharmony_ci- break; 2996be168c0dSopenharmony_ci- case NODE_TYPE_LAYER_NORM_FUSION: 2997be168c0dSopenharmony_ci- return ConvertLayerNormFusion(primitive); 2998be168c0dSopenharmony_ci- break; 2999be168c0dSopenharmony_ci- case NODE_TYPE_LESS_EQUAL: 3000be168c0dSopenharmony_ci- return ConvertLessEqual(primitive); 3001be168c0dSopenharmony_ci- break; 3002be168c0dSopenharmony_ci- case NODE_TYPE_MATMUL_FUSION: 3003be168c0dSopenharmony_ci- return ConvertMatMulFusion(primitive); 3004be168c0dSopenharmony_ci- break; 3005be168c0dSopenharmony_ci- case NODE_TYPE_MAXIMUM: 3006be168c0dSopenharmony_ci- return ConvertMaximum(primitive); 3007be168c0dSopenharmony_ci- break; 3008be168c0dSopenharmony_ci- case NODE_TYPE_MAX_POOL_FUSION: 3009be168c0dSopenharmony_ci- return ConvertMaxPoolFusion(primitive); 3010be168c0dSopenharmony_ci- break; 3011be168c0dSopenharmony_ci- case NODE_TYPE_MUL_FUSION: 3012be168c0dSopenharmony_ci- return ConvertMulFusion(primitive); 3013be168c0dSopenharmony_ci- break; 3014be168c0dSopenharmony_ci- case NODE_TYPE_ONE_HOT: 3015be168c0dSopenharmony_ci- return ConvertOneHot(primitive); 3016be168c0dSopenharmony_ci- break; 3017be168c0dSopenharmony_ci- case NODE_TYPE_PAD_FUSION: 3018be168c0dSopenharmony_ci- return ConvertPadFusion(primitive); 3019be168c0dSopenharmony_ci- break; 3020be168c0dSopenharmony_ci- case NODE_TYPE_POW_FUSION: 3021be168c0dSopenharmony_ci- return ConvertPowFusion(primitive); 3022be168c0dSopenharmony_ci- break; 3023be168c0dSopenharmony_ci- case NODE_TYPE_PRELU_FUSION: 3024be168c0dSopenharmony_ci- return ConvertPReLUFusion(primitive); 3025be168c0dSopenharmony_ci- break; 3026be168c0dSopenharmony_ci- case NODE_TYPE_QUANT_DTYPE_CAST: 3027be168c0dSopenharmony_ci- return ConvertQuantDTypeCast(primitive); 3028be168c0dSopenharmony_ci- break; 3029be168c0dSopenharmony_ci- case NODE_TYPE_REDUCE_FUSION: 3030be168c0dSopenharmony_ci- return ConvertReduceFusion(primitive); 3031be168c0dSopenharmony_ci- break; 3032be168c0dSopenharmony_ci- case NODE_TYPE_RESHAPE: 3033be168c0dSopenharmony_ci- return ConvertReshape(primitive); 3034be168c0dSopenharmony_ci- break; 3035be168c0dSopenharmony_ci- case NODE_TYPE_RESIZE: 3036be168c0dSopenharmony_ci- return ConvertResize(primitive); 3037be168c0dSopenharmony_ci- break; 3038be168c0dSopenharmony_ci- case NODE_TYPE_RSQRT: 3039be168c0dSopenharmony_ci- return ConvertRsqrt(primitive); 3040be168c0dSopenharmony_ci- break; 3041be168c0dSopenharmony_ci- case NODE_TYPE_SCALE_FUSION: 3042be168c0dSopenharmony_ci- return ConvertScaleFusion(primitive); 3043be168c0dSopenharmony_ci- break; 3044be168c0dSopenharmony_ci- case NODE_TYPE_SHAPE: 3045be168c0dSopenharmony_ci- return ConvertShape(primitive); 3046be168c0dSopenharmony_ci- break; 3047be168c0dSopenharmony_ci- case NODE_TYPE_SLICE_FUSION: 3048be168c0dSopenharmony_ci- return ConvertSliceFusion(primitive); 3049be168c0dSopenharmony_ci- break; 3050be168c0dSopenharmony_ci- case NODE_TYPE_SOFTMAX: 3051be168c0dSopenharmony_ci- return ConvertSoftmax(primitive); 3052be168c0dSopenharmony_ci- break; 3053be168c0dSopenharmony_ci- case NODE_TYPE_SPACE_TO_BATCH_ND: 3054be168c0dSopenharmony_ci- return ConvertSpaceToBatchND(primitive); 3055be168c0dSopenharmony_ci- break; 3056be168c0dSopenharmony_ci- case NODE_TYPE_SPLIT: 3057be168c0dSopenharmony_ci- return ConvertSplit(primitive); 3058be168c0dSopenharmony_ci- break; 3059be168c0dSopenharmony_ci- case NODE_TYPE_SQRT: 3060be168c0dSopenharmony_ci- return ConvertSqrt(primitive); 3061be168c0dSopenharmony_ci- break; 3062be168c0dSopenharmony_ci- case NODE_TYPE_SQUARED_DIFFERENCE: 3063be168c0dSopenharmony_ci- return ConvertSquaredDifference(primitive); 3064be168c0dSopenharmony_ci- break; 3065be168c0dSopenharmony_ci- case NODE_TYPE_SQUEEZE: 3066be168c0dSopenharmony_ci- return ConvertSqueeze(primitive); 3067be168c0dSopenharmony_ci- break; 3068be168c0dSopenharmony_ci- case NODE_TYPE_STACK: 3069be168c0dSopenharmony_ci- return ConvertStack(primitive); 3070be168c0dSopenharmony_ci- break; 3071be168c0dSopenharmony_ci- case NODE_TYPE_STRIDED_SLICE: 3072be168c0dSopenharmony_ci- return ConvertStridedSlice(primitive); 3073be168c0dSopenharmony_ci- break; 3074be168c0dSopenharmony_ci- case NODE_TYPE_SUB_FUSION: 3075be168c0dSopenharmony_ci- return ConvertSubFusion(primitive); 3076be168c0dSopenharmony_ci- break; 3077be168c0dSopenharmony_ci- case NODE_TYPE_TILE_FUSION: 3078be168c0dSopenharmony_ci- return ConvertTileFusion(primitive); 3079be168c0dSopenharmony_ci- break; 3080be168c0dSopenharmony_ci- case NODE_TYPE_TOPK_FUSION: 3081be168c0dSopenharmony_ci- return ConvertTopKFusion(primitive); 3082be168c0dSopenharmony_ci- break; 3083be168c0dSopenharmony_ci- case NODE_TYPE_TRANSPOSE: 3084be168c0dSopenharmony_ci- return ConvertTranspose(primitive); 3085be168c0dSopenharmony_ci- break; 3086be168c0dSopenharmony_ci- case NODE_TYPE_UNSQUEEZE: 3087be168c0dSopenharmony_ci- return ConvertUnsqueeze(primitive); 3088be168c0dSopenharmony_ci- break; 3089be168c0dSopenharmony_ci- default: 3090be168c0dSopenharmony_ci- return {}; 3091be168c0dSopenharmony_ci- } 3092be168c0dSopenharmony_ci-} 3093be168c0dSopenharmony_ci- 3094be168c0dSopenharmony_ci-} // namespace lite 3095be168c0dSopenharmony_ci-} // namespace mindspore 3096be168c0dSopenharmony_ci\ No newline at end of file 3097be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model_v2_0.cc b/mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model_v2_0.cc 3098be168c0dSopenharmony_cideleted file mode 100644 3099be168c0dSopenharmony_ciindex 4e109eff..00000000 3100be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/src/mindir_nnrt_lite_graph_to_model_v2_0.cc 3101be168c0dSopenharmony_ci+++ /dev/null 3102be168c0dSopenharmony_ci@@ -1,1497 +0,0 @@ 3103be168c0dSopenharmony_ci-/** 3104be168c0dSopenharmony_ci- * Copyright 2021 Huawei Technologies Co., Ltd 3105be168c0dSopenharmony_ci- * 3106be168c0dSopenharmony_ci- * Licensed under the Apache License, Version 2.0 (the "License"); 3107be168c0dSopenharmony_ci- * you may not use this file except in compliance with the License. 3108be168c0dSopenharmony_ci- * You may obtain a copy of the License at 3109be168c0dSopenharmony_ci- * 3110be168c0dSopenharmony_ci- * http://www.apache.org/licenses/LICENSE-2.0 3111be168c0dSopenharmony_ci- * 3112be168c0dSopenharmony_ci- * Unless required by applicable law or agreed to in writing, software 3113be168c0dSopenharmony_ci- * distributed under the License is distributed on an "AS IS" BASIS, 3114be168c0dSopenharmony_ci- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 3115be168c0dSopenharmony_ci- * See the License for the specific language governing permissions and 3116be168c0dSopenharmony_ci- * limitations under the License. 3117be168c0dSopenharmony_ci- */ 3118be168c0dSopenharmony_ci-#include "mindir.h" 3119be168c0dSopenharmony_ci-#include <vector> 3120be168c0dSopenharmony_ci-#include <algorithm> 3121be168c0dSopenharmony_ci-#include <sys/mman.h> 3122be168c0dSopenharmony_ci-#include "src/common/log.h" 3123be168c0dSopenharmony_ci-#include "lite_graph.h" 3124be168c0dSopenharmony_ci-#include "schema/model_generated.h" 3125be168c0dSopenharmony_ci-#include "mindir_types.h" 3126be168c0dSopenharmony_ci-#include "message_parcel.h" 3127be168c0dSopenharmony_ci-#include "nnrt/v2_0/nnrt_types.h" 3128be168c0dSopenharmony_ci-#include "nnrt/v2_0/node_attr_types.h" 3129be168c0dSopenharmony_ci-#include "nnrt/v2_0/model_types.h" 3130be168c0dSopenharmony_ci- 3131be168c0dSopenharmony_ci-using namespace OHOS::HDI::Nnrt::V2_0; 3132be168c0dSopenharmony_ci-namespace mindspore { 3133be168c0dSopenharmony_ci-namespace lite { 3134be168c0dSopenharmony_ci- 3135be168c0dSopenharmony_ci-constexpr size_t kNumTwo = 2; 3136be168c0dSopenharmony_ci-constexpr size_t kNumFour = 4; 3137be168c0dSopenharmony_ci-constexpr size_t kNumEight = 8; 3138be168c0dSopenharmony_ci- 3139be168c0dSopenharmony_ci-inline std::vector<OHOS::HDI::Nnrt::V2_0::QuantParam> MindIR_Tensor_GetQuantParams_OHOS_V2_0(TensorPtr tensor) { 3140be168c0dSopenharmony_ci- if (tensor != nullptr) { 3141be168c0dSopenharmony_ci- auto value = static_cast<schema::Tensor *>(tensor); 3142be168c0dSopenharmony_ci- 3143be168c0dSopenharmony_ci- if (value != nullptr) { 3144be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V2_0::QuantParam> result; 3145be168c0dSopenharmony_ci- auto src = value->quantParams(); 3146be168c0dSopenharmony_ci- if (src == nullptr) { 3147be168c0dSopenharmony_ci- return {}; 3148be168c0dSopenharmony_ci- } 3149be168c0dSopenharmony_ci- size_t size = src->size(); 3150be168c0dSopenharmony_ci- result.reserve(src->size()); 3151be168c0dSopenharmony_ci- for (size_t i = 0; i < size; i++) { 3152be168c0dSopenharmony_ci- auto tmp = src->Get(i); 3153be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V2_0::QuantParam quantParam{tmp->numBits(), tmp->zeroPoint(), tmp->scale()}; 3154be168c0dSopenharmony_ci- result.emplace_back(quantParam); 3155be168c0dSopenharmony_ci- } 3156be168c0dSopenharmony_ci- return result; 3157be168c0dSopenharmony_ci- } else { 3158be168c0dSopenharmony_ci- return {}; 3159be168c0dSopenharmony_ci- } 3160be168c0dSopenharmony_ci- } else { 3161be168c0dSopenharmony_ci- return {}; 3162be168c0dSopenharmony_ci- } 3163be168c0dSopenharmony_ci-} 3164be168c0dSopenharmony_ci- 3165be168c0dSopenharmony_ci-void MindIR_Model_Destroy(OHOS::HDI::Nnrt::V2_0::Model **model) { 3166be168c0dSopenharmony_ci- if (model != nullptr) { 3167be168c0dSopenharmony_ci- auto model_data = *model; 3168be168c0dSopenharmony_ci- if (model_data != nullptr) { 3169be168c0dSopenharmony_ci- delete (model_data); 3170be168c0dSopenharmony_ci- *model = nullptr; 3171be168c0dSopenharmony_ci- } else { 3172be168c0dSopenharmony_ci- MS_LOG(ERROR) << "*model is nullptr, desrtoy model fail."; 3173be168c0dSopenharmony_ci- } 3174be168c0dSopenharmony_ci- } 3175be168c0dSopenharmony_ci-} 3176be168c0dSopenharmony_ci- 3177be168c0dSopenharmony_ci-std::vector<int8_t> ConvertActivation_V2_0(PrimitivePtr primitive) { 3178be168c0dSopenharmony_ci- if (primitive != nullptr) { 3179be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3180be168c0dSopenharmony_ci- auto value = prim->value_as_Activation(); 3181be168c0dSopenharmony_ci- if (value != nullptr) { 3182be168c0dSopenharmony_ci- Activation activation{}; 3183be168c0dSopenharmony_ci- activation.activationType = 3184be168c0dSopenharmony_ci- static_cast<HDI::Nnrt::V2_0::HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3185be168c0dSopenharmony_ci- activation.alpha = value->alpha(); 3186be168c0dSopenharmony_ci- activation.minVal = value->min_val(); 3187be168c0dSopenharmony_ci- activation.maxVal = value->max_val(); 3188be168c0dSopenharmony_ci- activation.approximate = value->approximate(); 3189be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3190be168c0dSopenharmony_ci- (void)ActivationBlockMarshalling(data, activation); 3191be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3192be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3193be168c0dSopenharmony_ci- return ret; 3194be168c0dSopenharmony_ci- } else { 3195be168c0dSopenharmony_ci- return {}; 3196be168c0dSopenharmony_ci- } 3197be168c0dSopenharmony_ci- } else { 3198be168c0dSopenharmony_ci- return {}; 3199be168c0dSopenharmony_ci- } 3200be168c0dSopenharmony_ci-} 3201be168c0dSopenharmony_ci-std::vector<int8_t> ConvertAddFusion_V2_0(PrimitivePtr primitive) { 3202be168c0dSopenharmony_ci- if (primitive != nullptr) { 3203be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3204be168c0dSopenharmony_ci- auto value = prim->value_as_AddFusion(); 3205be168c0dSopenharmony_ci- if (value != nullptr) { 3206be168c0dSopenharmony_ci- AddFusion add_fusion{}; 3207be168c0dSopenharmony_ci- add_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3208be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3209be168c0dSopenharmony_ci- (void)AddFusionBlockMarshalling(data, add_fusion); 3210be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3211be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3212be168c0dSopenharmony_ci- return ret; 3213be168c0dSopenharmony_ci- } else { 3214be168c0dSopenharmony_ci- return {}; 3215be168c0dSopenharmony_ci- } 3216be168c0dSopenharmony_ci- } else { 3217be168c0dSopenharmony_ci- return {}; 3218be168c0dSopenharmony_ci- } 3219be168c0dSopenharmony_ci-} 3220be168c0dSopenharmony_ci-std::vector<int8_t> ConvertArgMaxFusion_V2_0(PrimitivePtr primitive) { 3221be168c0dSopenharmony_ci- if (primitive != nullptr) { 3222be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3223be168c0dSopenharmony_ci- auto value = prim->value_as_ArgMaxFusion(); 3224be168c0dSopenharmony_ci- if (value != nullptr) { 3225be168c0dSopenharmony_ci- ArgMaxFusion arg_max_fusion{}; 3226be168c0dSopenharmony_ci- arg_max_fusion.axis = value->axis(); 3227be168c0dSopenharmony_ci- arg_max_fusion.topK = value->top_k(); 3228be168c0dSopenharmony_ci- arg_max_fusion.keepDims = value->keep_dims(); 3229be168c0dSopenharmony_ci- arg_max_fusion.outMaxValue = value->out_max_value(); 3230be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3231be168c0dSopenharmony_ci- (void)ArgMaxFusionBlockMarshalling(data, arg_max_fusion); 3232be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3233be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3234be168c0dSopenharmony_ci- return ret; 3235be168c0dSopenharmony_ci- } else { 3236be168c0dSopenharmony_ci- return {}; 3237be168c0dSopenharmony_ci- } 3238be168c0dSopenharmony_ci- } else { 3239be168c0dSopenharmony_ci- return {}; 3240be168c0dSopenharmony_ci- } 3241be168c0dSopenharmony_ci-} 3242be168c0dSopenharmony_ci-std::vector<int8_t> ConvertAvgPoolFusion_V2_0(PrimitivePtr primitive) { 3243be168c0dSopenharmony_ci- if (primitive != nullptr) { 3244be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3245be168c0dSopenharmony_ci- auto value = prim->value_as_AvgPoolFusion(); 3246be168c0dSopenharmony_ci- if (value != nullptr) { 3247be168c0dSopenharmony_ci- AvgPoolFusion avg_pool_fusion{}; 3248be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 3249be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 3250be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 3251be168c0dSopenharmony_ci- kernel_size = {}; 3252be168c0dSopenharmony_ci- } else { 3253be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 3254be168c0dSopenharmony_ci- } 3255be168c0dSopenharmony_ci- std::vector<int64_t> strides; 3256be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 3257be168c0dSopenharmony_ci- if (value->strides() == nullptr || value->strides()->size() < kNumTwo) { 3258be168c0dSopenharmony_ci- strides = {}; 3259be168c0dSopenharmony_ci- } else { 3260be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->strides()->begin(), value->strides()->end()); 3261be168c0dSopenharmony_ci- } 3262be168c0dSopenharmony_ci- std::vector<int64_t> padList; 3263be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 3264be168c0dSopenharmony_ci- if (value->pad() == nullptr || value->pad()->size() < kNumFour) { 3265be168c0dSopenharmony_ci- padList = {}; 3266be168c0dSopenharmony_ci- } else { 3267be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad()->begin(), value->pad()->end()); 3268be168c0dSopenharmony_ci- } 3269be168c0dSopenharmony_ci- avg_pool_fusion.kernelSize = kernel_size; 3270be168c0dSopenharmony_ci- avg_pool_fusion.strides = strides; 3271be168c0dSopenharmony_ci- avg_pool_fusion.pad = padList; 3272be168c0dSopenharmony_ci- avg_pool_fusion.padMode = static_cast<HDI::Nnrt::V2_0::PadMode>(value->pad_mode()); 3273be168c0dSopenharmony_ci- avg_pool_fusion.roundMode = static_cast<HDI::Nnrt::V2_0::RoundMode>(value->round_mode()); 3274be168c0dSopenharmony_ci- avg_pool_fusion.format = static_cast<HDI::Nnrt::V2_0::Format>(value->format()); 3275be168c0dSopenharmony_ci- avg_pool_fusion.global = value->global(); 3276be168c0dSopenharmony_ci- avg_pool_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3277be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3278be168c0dSopenharmony_ci- (void)AvgPoolFusionBlockMarshalling(data, avg_pool_fusion); 3279be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3280be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3281be168c0dSopenharmony_ci- return ret; 3282be168c0dSopenharmony_ci- } else { 3283be168c0dSopenharmony_ci- return {}; 3284be168c0dSopenharmony_ci- } 3285be168c0dSopenharmony_ci- } else { 3286be168c0dSopenharmony_ci- return {}; 3287be168c0dSopenharmony_ci- } 3288be168c0dSopenharmony_ci-} 3289be168c0dSopenharmony_ci-std::vector<int8_t> ConvertBatchToSpaceND_V2_0(PrimitivePtr primitive) { 3290be168c0dSopenharmony_ci- if (primitive != nullptr) { 3291be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3292be168c0dSopenharmony_ci- auto value = prim->value_as_BatchToSpaceND(); 3293be168c0dSopenharmony_ci- if (value != nullptr) { 3294be168c0dSopenharmony_ci- BatchToSpaceND batch_to_space_n_d{}; 3295be168c0dSopenharmony_ci- std::vector<int64_t> blockShape; 3296be168c0dSopenharmony_ci- blockShape.reserve(kNumTwo); 3297be168c0dSopenharmony_ci- if (value->block_shape() == nullptr || value->block_shape()->size() < kNumTwo) { 3298be168c0dSopenharmony_ci- blockShape = {0, 0}; 3299be168c0dSopenharmony_ci- } else { 3300be168c0dSopenharmony_ci- blockShape = std::vector<int64_t>(value->block_shape()->begin(), value->block_shape()->end()); 3301be168c0dSopenharmony_ci- } 3302be168c0dSopenharmony_ci- batch_to_space_n_d.blockShape = blockShape; 3303be168c0dSopenharmony_ci- auto crops = value->crops(); 3304be168c0dSopenharmony_ci- std::vector<std::vector<int64_t>> crops_vec2d; 3305be168c0dSopenharmony_ci- if (crops->data() == nullptr) { 3306be168c0dSopenharmony_ci- MS_LOG(ERROR) << "crops_data is nullptr"; 3307be168c0dSopenharmony_ci- crops_vec2d = {{}}; 3308be168c0dSopenharmony_ci- } else { 3309be168c0dSopenharmony_ci- crops_vec2d.reserve(crops->data()->size()); 3310be168c0dSopenharmony_ci- for (size_t i = 0; i < crops->data()->size(); i++) { 3311be168c0dSopenharmony_ci- auto vet = crops->data()->Get(i); 3312be168c0dSopenharmony_ci- crops_vec2d.emplace_back(std::vector<int64_t>(vet->data()->begin(), vet->data()->end())); 3313be168c0dSopenharmony_ci- } 3314be168c0dSopenharmony_ci- } 3315be168c0dSopenharmony_ci- batch_to_space_n_d.crops = crops_vec2d; 3316be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3317be168c0dSopenharmony_ci- (void)BatchToSpaceNDBlockMarshalling(data, batch_to_space_n_d); 3318be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3319be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3320be168c0dSopenharmony_ci- return ret; 3321be168c0dSopenharmony_ci- } else { 3322be168c0dSopenharmony_ci- return {}; 3323be168c0dSopenharmony_ci- } 3324be168c0dSopenharmony_ci- } else { 3325be168c0dSopenharmony_ci- return {}; 3326be168c0dSopenharmony_ci- } 3327be168c0dSopenharmony_ci-} 3328be168c0dSopenharmony_ci-std::vector<int8_t> ConvertBiasAdd_V2_0(PrimitivePtr primitive) { 3329be168c0dSopenharmony_ci- if (primitive != nullptr) { 3330be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3331be168c0dSopenharmony_ci- auto value = prim->value_as_BiasAdd(); 3332be168c0dSopenharmony_ci- if (value != nullptr) { 3333be168c0dSopenharmony_ci- BiasAdd bias_add{}; 3334be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3335be168c0dSopenharmony_ci- (void)BiasAddBlockMarshalling(data, bias_add); 3336be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3337be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3338be168c0dSopenharmony_ci- return ret; 3339be168c0dSopenharmony_ci- } else { 3340be168c0dSopenharmony_ci- return {}; 3341be168c0dSopenharmony_ci- } 3342be168c0dSopenharmony_ci- } else { 3343be168c0dSopenharmony_ci- return {}; 3344be168c0dSopenharmony_ci- } 3345be168c0dSopenharmony_ci-} 3346be168c0dSopenharmony_ci-std::vector<int8_t> ConvertCast_V2_0(PrimitivePtr primitive) { 3347be168c0dSopenharmony_ci- if (primitive != nullptr) { 3348be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3349be168c0dSopenharmony_ci- auto value = prim->value_as_Cast(); 3350be168c0dSopenharmony_ci- if (value != nullptr) { 3351be168c0dSopenharmony_ci- Cast cast{}; 3352be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3353be168c0dSopenharmony_ci- (void)CastBlockMarshalling(data, cast); 3354be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3355be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3356be168c0dSopenharmony_ci- return ret; 3357be168c0dSopenharmony_ci- } else { 3358be168c0dSopenharmony_ci- return {}; 3359be168c0dSopenharmony_ci- } 3360be168c0dSopenharmony_ci- } else { 3361be168c0dSopenharmony_ci- return {}; 3362be168c0dSopenharmony_ci- } 3363be168c0dSopenharmony_ci-} 3364be168c0dSopenharmony_ci-std::vector<int8_t> ConvertConcat_V2_0(PrimitivePtr primitive) { 3365be168c0dSopenharmony_ci- if (primitive != nullptr) { 3366be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3367be168c0dSopenharmony_ci- auto value = prim->value_as_Concat(); 3368be168c0dSopenharmony_ci- if (value != nullptr) { 3369be168c0dSopenharmony_ci- Concat concat{}; 3370be168c0dSopenharmony_ci- concat.axis = value->axis(); 3371be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3372be168c0dSopenharmony_ci- (void)ConcatBlockMarshalling(data, concat); 3373be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3374be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3375be168c0dSopenharmony_ci- return ret; 3376be168c0dSopenharmony_ci- } else { 3377be168c0dSopenharmony_ci- return {}; 3378be168c0dSopenharmony_ci- } 3379be168c0dSopenharmony_ci- } else { 3380be168c0dSopenharmony_ci- return {}; 3381be168c0dSopenharmony_ci- } 3382be168c0dSopenharmony_ci-} 3383be168c0dSopenharmony_ci-std::vector<int8_t> ConvertConv2DFusion_V2_0(PrimitivePtr primitive) { 3384be168c0dSopenharmony_ci- if (primitive != nullptr) { 3385be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3386be168c0dSopenharmony_ci- auto value = prim->value_as_Conv2DFusion(); 3387be168c0dSopenharmony_ci- if (value != nullptr) { 3388be168c0dSopenharmony_ci- Conv2DFusion conv2_d_fusion{}; 3389be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 3390be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 3391be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 3392be168c0dSopenharmony_ci- kernel_size = {}; 3393be168c0dSopenharmony_ci- } else { 3394be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 3395be168c0dSopenharmony_ci- } 3396be168c0dSopenharmony_ci- std::vector<int64_t> strides; 3397be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 3398be168c0dSopenharmony_ci- if (value->stride() == nullptr || value->stride()->size() < kNumTwo) { 3399be168c0dSopenharmony_ci- strides = {}; 3400be168c0dSopenharmony_ci- } else { 3401be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->stride()->begin(), value->stride()->end()); 3402be168c0dSopenharmony_ci- } 3403be168c0dSopenharmony_ci- std::vector<int64_t> dilation; 3404be168c0dSopenharmony_ci- dilation.reserve(kNumTwo); 3405be168c0dSopenharmony_ci- if (value->dilation() == nullptr || value->dilation()->size() < kNumTwo) { 3406be168c0dSopenharmony_ci- dilation = {}; 3407be168c0dSopenharmony_ci- } else { 3408be168c0dSopenharmony_ci- dilation = std::vector<int64_t>(value->dilation()->begin(), value->dilation()->end()); 3409be168c0dSopenharmony_ci- } 3410be168c0dSopenharmony_ci- std::vector<int64_t> padList; 3411be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 3412be168c0dSopenharmony_ci- if (value->pad_list() == nullptr || value->pad_list()->size() < kNumFour) { 3413be168c0dSopenharmony_ci- padList = {}; 3414be168c0dSopenharmony_ci- } else { 3415be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad_list()->begin(), value->pad_list()->end()); 3416be168c0dSopenharmony_ci- } 3417be168c0dSopenharmony_ci- conv2_d_fusion.kernelSize = kernel_size; 3418be168c0dSopenharmony_ci- conv2_d_fusion.stride = strides; 3419be168c0dSopenharmony_ci- conv2_d_fusion.dilation = dilation; 3420be168c0dSopenharmony_ci- conv2_d_fusion.padMode = static_cast<HDI::Nnrt::V2_0::PadMode>(value->pad_mode()); 3421be168c0dSopenharmony_ci- conv2_d_fusion.padList = padList; 3422be168c0dSopenharmony_ci- conv2_d_fusion.group = value->group(); 3423be168c0dSopenharmony_ci- conv2_d_fusion.inChannel = value->in_channel(); 3424be168c0dSopenharmony_ci- conv2_d_fusion.outChannel = value->out_channel(); 3425be168c0dSopenharmony_ci- conv2_d_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3426be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3427be168c0dSopenharmony_ci- (void)Conv2DFusionBlockMarshalling(data, conv2_d_fusion); 3428be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3429be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3430be168c0dSopenharmony_ci- return ret; 3431be168c0dSopenharmony_ci- } else { 3432be168c0dSopenharmony_ci- return {}; 3433be168c0dSopenharmony_ci- } 3434be168c0dSopenharmony_ci- } else { 3435be168c0dSopenharmony_ci- return {}; 3436be168c0dSopenharmony_ci- } 3437be168c0dSopenharmony_ci-} 3438be168c0dSopenharmony_ci-std::vector<int8_t> ConvertConv2dTransposeFusion_V2_0(PrimitivePtr primitive) { 3439be168c0dSopenharmony_ci- if (primitive != nullptr) { 3440be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3441be168c0dSopenharmony_ci- auto value = prim->value_as_Conv2dTransposeFusion(); 3442be168c0dSopenharmony_ci- if (value != nullptr) { 3443be168c0dSopenharmony_ci- Conv2dTransposeFusion conv2d_transpose_fusion{}; 3444be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 3445be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 3446be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 3447be168c0dSopenharmony_ci- kernel_size = {}; 3448be168c0dSopenharmony_ci- } else { 3449be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 3450be168c0dSopenharmony_ci- } 3451be168c0dSopenharmony_ci- std::vector<int64_t> strides; 3452be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 3453be168c0dSopenharmony_ci- if (value->stride() == nullptr || value->stride()->size() < kNumTwo) { 3454be168c0dSopenharmony_ci- strides = {}; 3455be168c0dSopenharmony_ci- } else { 3456be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->stride()->begin(), value->stride()->end()); 3457be168c0dSopenharmony_ci- } 3458be168c0dSopenharmony_ci- std::vector<int64_t> dilation; 3459be168c0dSopenharmony_ci- dilation.reserve(kNumTwo); 3460be168c0dSopenharmony_ci- if (value->dilation() == nullptr || value->dilation()->size() < kNumTwo) { 3461be168c0dSopenharmony_ci- dilation = {}; 3462be168c0dSopenharmony_ci- } else { 3463be168c0dSopenharmony_ci- dilation = std::vector<int64_t>(value->dilation()->begin(), value->dilation()->end()); 3464be168c0dSopenharmony_ci- } 3465be168c0dSopenharmony_ci- std::vector<int64_t> padList; 3466be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 3467be168c0dSopenharmony_ci- if (value->pad_list() == nullptr || value->pad_list()->size() < kNumFour) { 3468be168c0dSopenharmony_ci- padList = {}; 3469be168c0dSopenharmony_ci- } else { 3470be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad_list()->begin(), value->pad_list()->end()); 3471be168c0dSopenharmony_ci- } 3472be168c0dSopenharmony_ci- std::vector<int64_t> output_paddings; 3473be168c0dSopenharmony_ci- output_paddings.reserve(kNumTwo); 3474be168c0dSopenharmony_ci- if (value->output_paddings() == nullptr || value->output_paddings()->size() < kNumTwo) { 3475be168c0dSopenharmony_ci- output_paddings = {}; 3476be168c0dSopenharmony_ci- } else { 3477be168c0dSopenharmony_ci- output_paddings = std::vector<int64_t>(value->output_paddings()->begin(), value->output_paddings()->end()); 3478be168c0dSopenharmony_ci- } 3479be168c0dSopenharmony_ci- conv2d_transpose_fusion.kernelSize = kernel_size; 3480be168c0dSopenharmony_ci- conv2d_transpose_fusion.stride = strides; 3481be168c0dSopenharmony_ci- conv2d_transpose_fusion.dilation = dilation; 3482be168c0dSopenharmony_ci- conv2d_transpose_fusion.padMode = static_cast<HDI::Nnrt::V2_0::PadMode>(value->pad_mode()); 3483be168c0dSopenharmony_ci- conv2d_transpose_fusion.padList = padList; 3484be168c0dSopenharmony_ci- conv2d_transpose_fusion.group = value->group(); 3485be168c0dSopenharmony_ci- conv2d_transpose_fusion.inChannel = value->in_channel(); 3486be168c0dSopenharmony_ci- conv2d_transpose_fusion.outChannel = value->out_channel(); 3487be168c0dSopenharmony_ci- conv2d_transpose_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3488be168c0dSopenharmony_ci- conv2d_transpose_fusion.outputPaddings = output_paddings; 3489be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3490be168c0dSopenharmony_ci- (void)Conv2dTransposeFusionBlockMarshalling(data, conv2d_transpose_fusion); 3491be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3492be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3493be168c0dSopenharmony_ci- return ret; 3494be168c0dSopenharmony_ci- } else { 3495be168c0dSopenharmony_ci- return {}; 3496be168c0dSopenharmony_ci- } 3497be168c0dSopenharmony_ci- } else { 3498be168c0dSopenharmony_ci- return {}; 3499be168c0dSopenharmony_ci- } 3500be168c0dSopenharmony_ci-} 3501be168c0dSopenharmony_ci-std::vector<int8_t> ConvertDivFusion_V2_0(PrimitivePtr primitive) { 3502be168c0dSopenharmony_ci- if (primitive != nullptr) { 3503be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3504be168c0dSopenharmony_ci- auto value = prim->value_as_DivFusion(); 3505be168c0dSopenharmony_ci- if (value != nullptr) { 3506be168c0dSopenharmony_ci- DivFusion div_fusion{}; 3507be168c0dSopenharmony_ci- div_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3508be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3509be168c0dSopenharmony_ci- (void)DivFusionBlockMarshalling(data, div_fusion); 3510be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3511be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3512be168c0dSopenharmony_ci- return ret; 3513be168c0dSopenharmony_ci- } else { 3514be168c0dSopenharmony_ci- return {}; 3515be168c0dSopenharmony_ci- } 3516be168c0dSopenharmony_ci- } else { 3517be168c0dSopenharmony_ci- return {}; 3518be168c0dSopenharmony_ci- } 3519be168c0dSopenharmony_ci-} 3520be168c0dSopenharmony_ci-std::vector<int8_t> ConvertEltwise_V2_0(PrimitivePtr primitive) { 3521be168c0dSopenharmony_ci- if (primitive != nullptr) { 3522be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3523be168c0dSopenharmony_ci- auto value = prim->value_as_Eltwise(); 3524be168c0dSopenharmony_ci- if (value != nullptr) { 3525be168c0dSopenharmony_ci- Eltwise eltwise{}; 3526be168c0dSopenharmony_ci- eltwise.mode = static_cast<HDI::Nnrt::V2_0::EltwiseMode>(value->mode()); 3527be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3528be168c0dSopenharmony_ci- (void)EltwiseBlockMarshalling(data, eltwise); 3529be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3530be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3531be168c0dSopenharmony_ci- return ret; 3532be168c0dSopenharmony_ci- } else { 3533be168c0dSopenharmony_ci- return {}; 3534be168c0dSopenharmony_ci- } 3535be168c0dSopenharmony_ci- } else { 3536be168c0dSopenharmony_ci- return {}; 3537be168c0dSopenharmony_ci- } 3538be168c0dSopenharmony_ci-} 3539be168c0dSopenharmony_ci-std::vector<int8_t> ConvertExpandDims_V2_0(PrimitivePtr primitive) { 3540be168c0dSopenharmony_ci- if (primitive != nullptr) { 3541be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3542be168c0dSopenharmony_ci- auto value = prim->value_as_ExpandDims(); 3543be168c0dSopenharmony_ci- if (value != nullptr) { 3544be168c0dSopenharmony_ci- ExpandDims expand_dims{}; 3545be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3546be168c0dSopenharmony_ci- (void)ExpandDimsBlockMarshalling(data, expand_dims); 3547be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3548be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3549be168c0dSopenharmony_ci- return ret; 3550be168c0dSopenharmony_ci- } else { 3551be168c0dSopenharmony_ci- return {}; 3552be168c0dSopenharmony_ci- } 3553be168c0dSopenharmony_ci- } else { 3554be168c0dSopenharmony_ci- return {}; 3555be168c0dSopenharmony_ci- } 3556be168c0dSopenharmony_ci-} 3557be168c0dSopenharmony_ci-std::vector<int8_t> ConvertFill_V2_0(PrimitivePtr primitive) { 3558be168c0dSopenharmony_ci- if (primitive != nullptr) { 3559be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3560be168c0dSopenharmony_ci- auto value = prim->value_as_Fill(); 3561be168c0dSopenharmony_ci- if (value != nullptr) { 3562be168c0dSopenharmony_ci- Fill fill{}; 3563be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3564be168c0dSopenharmony_ci- (void)FillBlockMarshalling(data, fill); 3565be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3566be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3567be168c0dSopenharmony_ci- return ret; 3568be168c0dSopenharmony_ci- } else { 3569be168c0dSopenharmony_ci- return {}; 3570be168c0dSopenharmony_ci- } 3571be168c0dSopenharmony_ci- } else { 3572be168c0dSopenharmony_ci- return {}; 3573be168c0dSopenharmony_ci- } 3574be168c0dSopenharmony_ci-} 3575be168c0dSopenharmony_ci-std::vector<int8_t> ConvertFullConnection_V2_0(PrimitivePtr primitive) { 3576be168c0dSopenharmony_ci- if (primitive != nullptr) { 3577be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3578be168c0dSopenharmony_ci- auto value = prim->value_as_FullConnection(); 3579be168c0dSopenharmony_ci- if (value != nullptr) { 3580be168c0dSopenharmony_ci- FullConnection full_connection{}; 3581be168c0dSopenharmony_ci- full_connection.hasBias = value->has_bias(); 3582be168c0dSopenharmony_ci- full_connection.useAxis = value->use_axis(); 3583be168c0dSopenharmony_ci- full_connection.axis = value->axis(); 3584be168c0dSopenharmony_ci- full_connection.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3585be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3586be168c0dSopenharmony_ci- (void)FullConnectionBlockMarshalling(data, full_connection); 3587be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3588be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3589be168c0dSopenharmony_ci- return ret; 3590be168c0dSopenharmony_ci- } else { 3591be168c0dSopenharmony_ci- return {}; 3592be168c0dSopenharmony_ci- } 3593be168c0dSopenharmony_ci- } else { 3594be168c0dSopenharmony_ci- return {}; 3595be168c0dSopenharmony_ci- } 3596be168c0dSopenharmony_ci-} 3597be168c0dSopenharmony_ci-std::vector<int8_t> ConvertFusedBatchNorm_V2_0(PrimitivePtr primitive) { 3598be168c0dSopenharmony_ci- if (primitive != nullptr) { 3599be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3600be168c0dSopenharmony_ci- auto value = prim->value_as_FusedBatchNorm(); 3601be168c0dSopenharmony_ci- if (value != nullptr) { 3602be168c0dSopenharmony_ci- FusedBatchNorm fused_batch_norm{}; 3603be168c0dSopenharmony_ci- fused_batch_norm.epsilon = value->epsilon(); 3604be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3605be168c0dSopenharmony_ci- (void)FusedBatchNormBlockMarshalling(data, fused_batch_norm); 3606be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3607be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3608be168c0dSopenharmony_ci- return ret; 3609be168c0dSopenharmony_ci- } else { 3610be168c0dSopenharmony_ci- return {}; 3611be168c0dSopenharmony_ci- } 3612be168c0dSopenharmony_ci- } else { 3613be168c0dSopenharmony_ci- return {}; 3614be168c0dSopenharmony_ci- } 3615be168c0dSopenharmony_ci-} 3616be168c0dSopenharmony_ci-std::vector<int8_t> ConvertGather_V2_0(PrimitivePtr primitive) { 3617be168c0dSopenharmony_ci- if (primitive != nullptr) { 3618be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3619be168c0dSopenharmony_ci- auto value = prim->value_as_Gather(); 3620be168c0dSopenharmony_ci- if (value != nullptr) { 3621be168c0dSopenharmony_ci- Gather gather{}; 3622be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3623be168c0dSopenharmony_ci- (void)GatherBlockMarshalling(data, gather); 3624be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3625be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3626be168c0dSopenharmony_ci- return ret; 3627be168c0dSopenharmony_ci- } else { 3628be168c0dSopenharmony_ci- return {}; 3629be168c0dSopenharmony_ci- } 3630be168c0dSopenharmony_ci- } else { 3631be168c0dSopenharmony_ci- return {}; 3632be168c0dSopenharmony_ci- } 3633be168c0dSopenharmony_ci-} 3634be168c0dSopenharmony_ci-std::vector<int8_t> ConvertLayerNormFusion_V2_0(PrimitivePtr primitive) { 3635be168c0dSopenharmony_ci- if (primitive != nullptr) { 3636be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3637be168c0dSopenharmony_ci- auto value = prim->value_as_LayerNormFusion(); 3638be168c0dSopenharmony_ci- if (value != nullptr) { 3639be168c0dSopenharmony_ci- LayerNormFusion layer_norm_fusion{}; 3640be168c0dSopenharmony_ci- layer_norm_fusion.beginNormAxis = value->begin_norm_axis(); 3641be168c0dSopenharmony_ci- layer_norm_fusion.epsilon = value->epsilon(); 3642be168c0dSopenharmony_ci- layer_norm_fusion.elementwiseAffine = value->elementwise_affine(); 3643be168c0dSopenharmony_ci- layer_norm_fusion.beginParamsAxis = value->begin_params_axis(); 3644be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3645be168c0dSopenharmony_ci- (void)LayerNormFusionBlockMarshalling(data, layer_norm_fusion); 3646be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3647be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3648be168c0dSopenharmony_ci- return ret; 3649be168c0dSopenharmony_ci- } else { 3650be168c0dSopenharmony_ci- return {}; 3651be168c0dSopenharmony_ci- } 3652be168c0dSopenharmony_ci- } else { 3653be168c0dSopenharmony_ci- return {}; 3654be168c0dSopenharmony_ci- } 3655be168c0dSopenharmony_ci-} 3656be168c0dSopenharmony_ci-std::vector<int8_t> ConvertLessEqual_V2_0(PrimitivePtr primitive) { 3657be168c0dSopenharmony_ci- if (primitive != nullptr) { 3658be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3659be168c0dSopenharmony_ci- auto value = prim->value_as_LessEqual(); 3660be168c0dSopenharmony_ci- if (value != nullptr) { 3661be168c0dSopenharmony_ci- LessEqual less_equal{}; 3662be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3663be168c0dSopenharmony_ci- (void)LessEqualBlockMarshalling(data, less_equal); 3664be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3665be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3666be168c0dSopenharmony_ci- return ret; 3667be168c0dSopenharmony_ci- } else { 3668be168c0dSopenharmony_ci- return {}; 3669be168c0dSopenharmony_ci- } 3670be168c0dSopenharmony_ci- } else { 3671be168c0dSopenharmony_ci- return {}; 3672be168c0dSopenharmony_ci- } 3673be168c0dSopenharmony_ci-} 3674be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMatMulFusion_V2_0(PrimitivePtr primitive) { 3675be168c0dSopenharmony_ci- if (primitive != nullptr) { 3676be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3677be168c0dSopenharmony_ci- auto value = prim->value_as_MatMulFusion(); 3678be168c0dSopenharmony_ci- if (value != nullptr) { 3679be168c0dSopenharmony_ci- MatMulFusion mat_mul_fusion{}; 3680be168c0dSopenharmony_ci- mat_mul_fusion.transposeA = value->transpose_a(); 3681be168c0dSopenharmony_ci- mat_mul_fusion.transposeB = value->transpose_b(); 3682be168c0dSopenharmony_ci- mat_mul_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3683be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3684be168c0dSopenharmony_ci- (void)MatMulFusionBlockMarshalling(data, mat_mul_fusion); 3685be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3686be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3687be168c0dSopenharmony_ci- return ret; 3688be168c0dSopenharmony_ci- } else { 3689be168c0dSopenharmony_ci- return {}; 3690be168c0dSopenharmony_ci- } 3691be168c0dSopenharmony_ci- } else { 3692be168c0dSopenharmony_ci- return {}; 3693be168c0dSopenharmony_ci- } 3694be168c0dSopenharmony_ci-} 3695be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMaximum_V2_0(PrimitivePtr primitive) { 3696be168c0dSopenharmony_ci- if (primitive != nullptr) { 3697be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3698be168c0dSopenharmony_ci- auto value = prim->value_as_Maximum(); 3699be168c0dSopenharmony_ci- if (value != nullptr) { 3700be168c0dSopenharmony_ci- Maximum maximum{}; 3701be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3702be168c0dSopenharmony_ci- (void)MaximumBlockMarshalling(data, maximum); 3703be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3704be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3705be168c0dSopenharmony_ci- return ret; 3706be168c0dSopenharmony_ci- } else { 3707be168c0dSopenharmony_ci- return {}; 3708be168c0dSopenharmony_ci- } 3709be168c0dSopenharmony_ci- } else { 3710be168c0dSopenharmony_ci- return {}; 3711be168c0dSopenharmony_ci- } 3712be168c0dSopenharmony_ci-} 3713be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMaxPoolFusion_V2_0(PrimitivePtr primitive) { 3714be168c0dSopenharmony_ci- if (primitive != nullptr) { 3715be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3716be168c0dSopenharmony_ci- auto value = prim->value_as_MaxPoolFusion(); 3717be168c0dSopenharmony_ci- if (value != nullptr) { 3718be168c0dSopenharmony_ci- MaxPoolFusion max_pool_fusion{}; 3719be168c0dSopenharmony_ci- std::vector<int64_t> kernel_size; 3720be168c0dSopenharmony_ci- kernel_size.reserve(kNumTwo); 3721be168c0dSopenharmony_ci- if (value->kernel_size() == nullptr || value->kernel_size()->size() < kNumTwo) { 3722be168c0dSopenharmony_ci- kernel_size = {}; 3723be168c0dSopenharmony_ci- } else { 3724be168c0dSopenharmony_ci- kernel_size = std::vector<int64_t>(value->kernel_size()->begin(), value->kernel_size()->end()); 3725be168c0dSopenharmony_ci- } 3726be168c0dSopenharmony_ci- std::vector<int64_t> strides; 3727be168c0dSopenharmony_ci- strides.reserve(kNumTwo); 3728be168c0dSopenharmony_ci- if (value->strides() == nullptr || value->strides()->size() < kNumTwo) { 3729be168c0dSopenharmony_ci- strides = {}; 3730be168c0dSopenharmony_ci- } else { 3731be168c0dSopenharmony_ci- strides = std::vector<int64_t>(value->strides()->begin(), value->strides()->end()); 3732be168c0dSopenharmony_ci- } 3733be168c0dSopenharmony_ci- std::vector<int64_t> padList; 3734be168c0dSopenharmony_ci- padList.reserve(kNumFour); 3735be168c0dSopenharmony_ci- if (value->pad() == nullptr || value->pad()->size() < kNumFour) { 3736be168c0dSopenharmony_ci- padList = {}; 3737be168c0dSopenharmony_ci- } else { 3738be168c0dSopenharmony_ci- padList = std::vector<int64_t>(value->pad()->begin(), value->pad()->end()); 3739be168c0dSopenharmony_ci- } 3740be168c0dSopenharmony_ci- max_pool_fusion.kernelSize = kernel_size; 3741be168c0dSopenharmony_ci- max_pool_fusion.strides = strides; 3742be168c0dSopenharmony_ci- max_pool_fusion.pad = padList; 3743be168c0dSopenharmony_ci- max_pool_fusion.padMode = static_cast<HDI::Nnrt::V2_0::PadMode>(value->pad_mode()); 3744be168c0dSopenharmony_ci- max_pool_fusion.format = static_cast<HDI::Nnrt::V2_0::Format>(value->format()); 3745be168c0dSopenharmony_ci- max_pool_fusion.global = value->global(); 3746be168c0dSopenharmony_ci- max_pool_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3747be168c0dSopenharmony_ci- max_pool_fusion.roundMode = static_cast<HDI::Nnrt::V2_0::RoundMode>(value->round_mode()); 3748be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3749be168c0dSopenharmony_ci- (void)MaxPoolFusionBlockMarshalling(data, max_pool_fusion); 3750be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3751be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3752be168c0dSopenharmony_ci- return ret; 3753be168c0dSopenharmony_ci- } else { 3754be168c0dSopenharmony_ci- return {}; 3755be168c0dSopenharmony_ci- } 3756be168c0dSopenharmony_ci- } else { 3757be168c0dSopenharmony_ci- return {}; 3758be168c0dSopenharmony_ci- } 3759be168c0dSopenharmony_ci-} 3760be168c0dSopenharmony_ci-std::vector<int8_t> ConvertMulFusion_V2_0(PrimitivePtr primitive) { 3761be168c0dSopenharmony_ci- if (primitive != nullptr) { 3762be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3763be168c0dSopenharmony_ci- auto value = prim->value_as_MulFusion(); 3764be168c0dSopenharmony_ci- if (value != nullptr) { 3765be168c0dSopenharmony_ci- MulFusion mul_fusion{}; 3766be168c0dSopenharmony_ci- mul_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3767be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3768be168c0dSopenharmony_ci- (void)MulFusionBlockMarshalling(data, mul_fusion); 3769be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3770be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3771be168c0dSopenharmony_ci- return ret; 3772be168c0dSopenharmony_ci- } else { 3773be168c0dSopenharmony_ci- return {}; 3774be168c0dSopenharmony_ci- } 3775be168c0dSopenharmony_ci- } else { 3776be168c0dSopenharmony_ci- return {}; 3777be168c0dSopenharmony_ci- } 3778be168c0dSopenharmony_ci-} 3779be168c0dSopenharmony_ci-std::vector<int8_t> ConvertOneHot_V2_0(PrimitivePtr primitive) { 3780be168c0dSopenharmony_ci- if (primitive != nullptr) { 3781be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3782be168c0dSopenharmony_ci- auto value = prim->value_as_OneHot(); 3783be168c0dSopenharmony_ci- if (value != nullptr) { 3784be168c0dSopenharmony_ci- OneHot one_hot{}; 3785be168c0dSopenharmony_ci- one_hot.axis = value->axis(); 3786be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3787be168c0dSopenharmony_ci- (void)OneHotBlockMarshalling(data, one_hot); 3788be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3789be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3790be168c0dSopenharmony_ci- return ret; 3791be168c0dSopenharmony_ci- } else { 3792be168c0dSopenharmony_ci- return {}; 3793be168c0dSopenharmony_ci- } 3794be168c0dSopenharmony_ci- } else { 3795be168c0dSopenharmony_ci- return {}; 3796be168c0dSopenharmony_ci- } 3797be168c0dSopenharmony_ci-} 3798be168c0dSopenharmony_ci-std::vector<int8_t> ConvertPadFusion_V2_0(PrimitivePtr primitive) { 3799be168c0dSopenharmony_ci- if (primitive != nullptr) { 3800be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3801be168c0dSopenharmony_ci- auto value = prim->value_as_PadFusion(); 3802be168c0dSopenharmony_ci- if (value != nullptr) { 3803be168c0dSopenharmony_ci- PadFusion pad_fusion{}; 3804be168c0dSopenharmony_ci- auto paddings = value->paddings(); 3805be168c0dSopenharmony_ci- std::vector<std::vector<int64_t>> paddings_vec2d; 3806be168c0dSopenharmony_ci- if (paddings == nullptr || paddings->data()->size() < kNumTwo) { 3807be168c0dSopenharmony_ci- paddings_vec2d = {{0}, {0}, {0}, {0}}; 3808be168c0dSopenharmony_ci- } else { 3809be168c0dSopenharmony_ci- paddings_vec2d.reserve(paddings->data()->size()); 3810be168c0dSopenharmony_ci- for (size_t i = 0; i < paddings->data()->size(); i++) { 3811be168c0dSopenharmony_ci- auto vet = paddings->data()->Get(i); 3812be168c0dSopenharmony_ci- paddings_vec2d.emplace_back(std::vector<int64_t>(vet->data()->begin(), vet->data()->end())); 3813be168c0dSopenharmony_ci- } 3814be168c0dSopenharmony_ci- } 3815be168c0dSopenharmony_ci- pad_fusion.paddings = paddings_vec2d; 3816be168c0dSopenharmony_ci- pad_fusion.paddingMode = static_cast<HDI::Nnrt::V2_0::PaddingMode>(value->padding_mode()); 3817be168c0dSopenharmony_ci- pad_fusion.constantValue = value->constant_value(); 3818be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3819be168c0dSopenharmony_ci- (void)PadFusionBlockMarshalling(data, pad_fusion); 3820be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3821be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3822be168c0dSopenharmony_ci- return ret; 3823be168c0dSopenharmony_ci- } else { 3824be168c0dSopenharmony_ci- return {}; 3825be168c0dSopenharmony_ci- } 3826be168c0dSopenharmony_ci- } else { 3827be168c0dSopenharmony_ci- return {}; 3828be168c0dSopenharmony_ci- } 3829be168c0dSopenharmony_ci-} 3830be168c0dSopenharmony_ci-std::vector<int8_t> ConvertPowFusion_V2_0(PrimitivePtr primitive) { 3831be168c0dSopenharmony_ci- if (primitive != nullptr) { 3832be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3833be168c0dSopenharmony_ci- auto value = prim->value_as_PowFusion(); 3834be168c0dSopenharmony_ci- if (value != nullptr) { 3835be168c0dSopenharmony_ci- PowFusion pow_fusion{}; 3836be168c0dSopenharmony_ci- pow_fusion.scale = value->scale(); 3837be168c0dSopenharmony_ci- pow_fusion.shift = value->shift(); 3838be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3839be168c0dSopenharmony_ci- (void)PowFusionBlockMarshalling(data, pow_fusion); 3840be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3841be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3842be168c0dSopenharmony_ci- return ret; 3843be168c0dSopenharmony_ci- } else { 3844be168c0dSopenharmony_ci- return {}; 3845be168c0dSopenharmony_ci- } 3846be168c0dSopenharmony_ci- } else { 3847be168c0dSopenharmony_ci- return {}; 3848be168c0dSopenharmony_ci- } 3849be168c0dSopenharmony_ci-} 3850be168c0dSopenharmony_ci-std::vector<int8_t> ConvertPReLUFusion_V2_0(PrimitivePtr primitive) { 3851be168c0dSopenharmony_ci- if (primitive != nullptr) { 3852be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3853be168c0dSopenharmony_ci- auto value = prim->value_as_PReLUFusion(); 3854be168c0dSopenharmony_ci- if (value != nullptr) { 3855be168c0dSopenharmony_ci- PReLUFusion p_re_l_u_fusion{}; 3856be168c0dSopenharmony_ci- p_re_l_u_fusion.channelShared = value->channel_shared(); 3857be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3858be168c0dSopenharmony_ci- (void)PReLUFusionBlockMarshalling(data, p_re_l_u_fusion); 3859be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3860be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3861be168c0dSopenharmony_ci- return ret; 3862be168c0dSopenharmony_ci- } else { 3863be168c0dSopenharmony_ci- return {}; 3864be168c0dSopenharmony_ci- } 3865be168c0dSopenharmony_ci- } else { 3866be168c0dSopenharmony_ci- return {}; 3867be168c0dSopenharmony_ci- } 3868be168c0dSopenharmony_ci-} 3869be168c0dSopenharmony_ci-std::vector<int8_t> ConvertQuantDTypeCast_V2_0(PrimitivePtr primitive) { 3870be168c0dSopenharmony_ci- if (primitive != nullptr) { 3871be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3872be168c0dSopenharmony_ci- auto value = prim->value_as_QuantDTypeCast(); 3873be168c0dSopenharmony_ci- if (value != nullptr) { 3874be168c0dSopenharmony_ci- QuantDTypeCast quant_d_type_cast{}; 3875be168c0dSopenharmony_ci- quant_d_type_cast.srcT = value->src_t(); 3876be168c0dSopenharmony_ci- quant_d_type_cast.dstT = value->dst_t(); 3877be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3878be168c0dSopenharmony_ci- (void)QuantDTypeCastBlockMarshalling(data, quant_d_type_cast); 3879be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3880be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3881be168c0dSopenharmony_ci- return ret; 3882be168c0dSopenharmony_ci- } else { 3883be168c0dSopenharmony_ci- return {}; 3884be168c0dSopenharmony_ci- } 3885be168c0dSopenharmony_ci- } else { 3886be168c0dSopenharmony_ci- return {}; 3887be168c0dSopenharmony_ci- } 3888be168c0dSopenharmony_ci-} 3889be168c0dSopenharmony_ci-std::vector<int8_t> ConvertReduceFusion_V2_0(PrimitivePtr primitive) { 3890be168c0dSopenharmony_ci- if (primitive != nullptr) { 3891be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3892be168c0dSopenharmony_ci- auto value = prim->value_as_ReduceFusion(); 3893be168c0dSopenharmony_ci- if (value != nullptr) { 3894be168c0dSopenharmony_ci- ReduceFusion reduce_fusion{}; 3895be168c0dSopenharmony_ci- reduce_fusion.keepDims = value->keep_dims(); 3896be168c0dSopenharmony_ci- reduce_fusion.mode = static_cast<HDI::Nnrt::V2_0::ReduceMode>(value->mode()); 3897be168c0dSopenharmony_ci- reduce_fusion.reduceToEnd = value->reduce_to_end(); 3898be168c0dSopenharmony_ci- reduce_fusion.coeff = value->coeff(); 3899be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3900be168c0dSopenharmony_ci- (void)ReduceFusionBlockMarshalling(data, reduce_fusion); 3901be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3902be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3903be168c0dSopenharmony_ci- return ret; 3904be168c0dSopenharmony_ci- } else { 3905be168c0dSopenharmony_ci- return {}; 3906be168c0dSopenharmony_ci- } 3907be168c0dSopenharmony_ci- } else { 3908be168c0dSopenharmony_ci- return {}; 3909be168c0dSopenharmony_ci- } 3910be168c0dSopenharmony_ci-} 3911be168c0dSopenharmony_ci-std::vector<int8_t> ConvertReshape_V2_0(PrimitivePtr primitive) { 3912be168c0dSopenharmony_ci- if (primitive != nullptr) { 3913be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3914be168c0dSopenharmony_ci- auto value = prim->value_as_Reshape(); 3915be168c0dSopenharmony_ci- if (value != nullptr) { 3916be168c0dSopenharmony_ci- Reshape reshape{}; 3917be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3918be168c0dSopenharmony_ci- (void)ReshapeBlockMarshalling(data, reshape); 3919be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3920be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3921be168c0dSopenharmony_ci- return ret; 3922be168c0dSopenharmony_ci- } else { 3923be168c0dSopenharmony_ci- return {}; 3924be168c0dSopenharmony_ci- } 3925be168c0dSopenharmony_ci- } else { 3926be168c0dSopenharmony_ci- return {}; 3927be168c0dSopenharmony_ci- } 3928be168c0dSopenharmony_ci-} 3929be168c0dSopenharmony_ci- 3930be168c0dSopenharmony_ci-std::vector<int8_t> ConvertResize_V2_0(PrimitivePtr primitive) { 3931be168c0dSopenharmony_ci- if (primitive != nullptr) { 3932be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3933be168c0dSopenharmony_ci- auto value = prim->value_as_Resize(); 3934be168c0dSopenharmony_ci- if (value != nullptr) { 3935be168c0dSopenharmony_ci- Resize resize{}; 3936be168c0dSopenharmony_ci- resize.method = static_cast<HDI::Nnrt::V2_0::ResizeMethod>(value->method()); 3937be168c0dSopenharmony_ci- resize.newHeight = value->new_height(); 3938be168c0dSopenharmony_ci- resize.newWidth = value->new_width(); 3939be168c0dSopenharmony_ci- resize.preserveAspectRatio = value->preserve_aspect_ratio(); 3940be168c0dSopenharmony_ci- resize.coordinateTransformMode = 3941be168c0dSopenharmony_ci- static_cast<HDI::Nnrt::V2_0::CoordinateTransformMode>(value->coordinate_transform_mode()); 3942be168c0dSopenharmony_ci- resize.cubicCoeff = value->cubic_coeff(); 3943be168c0dSopenharmony_ci- resize.excludeOutside = value->exclude_outside(); 3944be168c0dSopenharmony_ci- resize.extrapolationValue = value->extrapolation_value(); 3945be168c0dSopenharmony_ci- resize.nearestMode = static_cast<HDI::Nnrt::V2_0::NearestMode>(value->nearest_mode()); 3946be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3947be168c0dSopenharmony_ci- (void)ResizeBlockMarshalling(data, resize); 3948be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3949be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3950be168c0dSopenharmony_ci- return ret; 3951be168c0dSopenharmony_ci- } else { 3952be168c0dSopenharmony_ci- return {}; 3953be168c0dSopenharmony_ci- } 3954be168c0dSopenharmony_ci- } else { 3955be168c0dSopenharmony_ci- return {}; 3956be168c0dSopenharmony_ci- } 3957be168c0dSopenharmony_ci-} 3958be168c0dSopenharmony_ci-std::vector<int8_t> ConvertRsqrt_V2_0(PrimitivePtr primitive) { 3959be168c0dSopenharmony_ci- if (primitive != nullptr) { 3960be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3961be168c0dSopenharmony_ci- auto value = prim->value_as_Rsqrt(); 3962be168c0dSopenharmony_ci- if (value != nullptr) { 3963be168c0dSopenharmony_ci- Rsqrt rsqrt{}; 3964be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3965be168c0dSopenharmony_ci- (void)RsqrtBlockMarshalling(data, rsqrt); 3966be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3967be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3968be168c0dSopenharmony_ci- return ret; 3969be168c0dSopenharmony_ci- } else { 3970be168c0dSopenharmony_ci- return {}; 3971be168c0dSopenharmony_ci- } 3972be168c0dSopenharmony_ci- } else { 3973be168c0dSopenharmony_ci- return {}; 3974be168c0dSopenharmony_ci- } 3975be168c0dSopenharmony_ci-} 3976be168c0dSopenharmony_ci-std::vector<int8_t> ConvertScaleFusion_V2_0(PrimitivePtr primitive) { 3977be168c0dSopenharmony_ci- if (primitive != nullptr) { 3978be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3979be168c0dSopenharmony_ci- auto value = prim->value_as_ScaleFusion(); 3980be168c0dSopenharmony_ci- if (value != nullptr) { 3981be168c0dSopenharmony_ci- ScaleFusion scale_fusion{}; 3982be168c0dSopenharmony_ci- scale_fusion.axis = value->axis(); 3983be168c0dSopenharmony_ci- scale_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 3984be168c0dSopenharmony_ci- OHOS::MessageParcel data; 3985be168c0dSopenharmony_ci- (void)ScaleFusionBlockMarshalling(data, scale_fusion); 3986be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 3987be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 3988be168c0dSopenharmony_ci- return ret; 3989be168c0dSopenharmony_ci- } else { 3990be168c0dSopenharmony_ci- return {}; 3991be168c0dSopenharmony_ci- } 3992be168c0dSopenharmony_ci- } else { 3993be168c0dSopenharmony_ci- return {}; 3994be168c0dSopenharmony_ci- } 3995be168c0dSopenharmony_ci-} 3996be168c0dSopenharmony_ci-std::vector<int8_t> ConvertShape_V2_0(PrimitivePtr primitive) { 3997be168c0dSopenharmony_ci- if (primitive != nullptr) { 3998be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 3999be168c0dSopenharmony_ci- auto value = prim->value_as_Shape(); 4000be168c0dSopenharmony_ci- if (value != nullptr) { 4001be168c0dSopenharmony_ci- Shape shape{}; 4002be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4003be168c0dSopenharmony_ci- (void)ShapeBlockMarshalling(data, shape); 4004be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4005be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4006be168c0dSopenharmony_ci- return ret; 4007be168c0dSopenharmony_ci- } else { 4008be168c0dSopenharmony_ci- return {}; 4009be168c0dSopenharmony_ci- } 4010be168c0dSopenharmony_ci- } else { 4011be168c0dSopenharmony_ci- return {}; 4012be168c0dSopenharmony_ci- } 4013be168c0dSopenharmony_ci-} 4014be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSliceFusion_V2_0(PrimitivePtr primitive) { 4015be168c0dSopenharmony_ci- if (primitive != nullptr) { 4016be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4017be168c0dSopenharmony_ci- auto value = prim->value_as_SliceFusion(); 4018be168c0dSopenharmony_ci- if (value != nullptr) { 4019be168c0dSopenharmony_ci- SliceFusion slice_fusion{}; 4020be168c0dSopenharmony_ci- std::vector<int64_t> axes; 4021be168c0dSopenharmony_ci- if (value->axes() == nullptr) { 4022be168c0dSopenharmony_ci- axes = {1, 2, 3, 4, 5, 6, 7}; 4023be168c0dSopenharmony_ci- } else { 4024be168c0dSopenharmony_ci- axes = std::vector<int64_t>(value->axes()->begin(), value->axes()->end()); 4025be168c0dSopenharmony_ci- } 4026be168c0dSopenharmony_ci- slice_fusion.axes = axes; 4027be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4028be168c0dSopenharmony_ci- (void)SliceFusionBlockMarshalling(data, slice_fusion); 4029be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4030be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4031be168c0dSopenharmony_ci- return ret; 4032be168c0dSopenharmony_ci- } else { 4033be168c0dSopenharmony_ci- return {}; 4034be168c0dSopenharmony_ci- } 4035be168c0dSopenharmony_ci- } else { 4036be168c0dSopenharmony_ci- return {}; 4037be168c0dSopenharmony_ci- } 4038be168c0dSopenharmony_ci-} 4039be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSoftmax_V2_0(PrimitivePtr primitive) { 4040be168c0dSopenharmony_ci- if (primitive != nullptr) { 4041be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4042be168c0dSopenharmony_ci- auto value = prim->value_as_Softmax(); 4043be168c0dSopenharmony_ci- if (value != nullptr) { 4044be168c0dSopenharmony_ci- Softmax softmax{}; 4045be168c0dSopenharmony_ci- std::vector<int64_t> axis; 4046be168c0dSopenharmony_ci- if (value->axis() == nullptr) { 4047be168c0dSopenharmony_ci- axis = {}; 4048be168c0dSopenharmony_ci- } else { 4049be168c0dSopenharmony_ci- axis = std::vector<int64_t>(value->axis()->begin(), value->axis()->end()); 4050be168c0dSopenharmony_ci- } 4051be168c0dSopenharmony_ci- softmax.axis = axis; 4052be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4053be168c0dSopenharmony_ci- (void)SoftmaxBlockMarshalling(data, softmax); 4054be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4055be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4056be168c0dSopenharmony_ci- return ret; 4057be168c0dSopenharmony_ci- } else { 4058be168c0dSopenharmony_ci- return {}; 4059be168c0dSopenharmony_ci- } 4060be168c0dSopenharmony_ci- } else { 4061be168c0dSopenharmony_ci- return {}; 4062be168c0dSopenharmony_ci- } 4063be168c0dSopenharmony_ci-} 4064be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSpaceToBatchND_V2_0(PrimitivePtr primitive) { 4065be168c0dSopenharmony_ci- if (primitive != nullptr) { 4066be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4067be168c0dSopenharmony_ci- auto value = prim->value_as_SpaceToBatchND(); 4068be168c0dSopenharmony_ci- if (value != nullptr) { 4069be168c0dSopenharmony_ci- SpaceToBatchND space_to_batch_n_d{}; 4070be168c0dSopenharmony_ci- std::vector<int64_t> blockShape; 4071be168c0dSopenharmony_ci- blockShape.reserve(kNumTwo); 4072be168c0dSopenharmony_ci- if (value->block_shape() == nullptr || value->block_shape()->size() < kNumTwo) { 4073be168c0dSopenharmony_ci- blockShape = {0, 0}; 4074be168c0dSopenharmony_ci- } else { 4075be168c0dSopenharmony_ci- blockShape = std::vector<int64_t>(value->block_shape()->begin(), value->block_shape()->end()); 4076be168c0dSopenharmony_ci- } 4077be168c0dSopenharmony_ci- space_to_batch_n_d.blockShape = blockShape; 4078be168c0dSopenharmony_ci- auto paddings = value->paddings(); 4079be168c0dSopenharmony_ci- std::vector<std::vector<int64_t>> paddings_vec2d; 4080be168c0dSopenharmony_ci- if (paddings == nullptr || paddings->data()->size() == 0 || *(paddings->data()->begin()) == nullptr || 4081be168c0dSopenharmony_ci- (*(paddings->data()->begin()))->data() == nullptr) { 4082be168c0dSopenharmony_ci- paddings_vec2d = {}; 4083be168c0dSopenharmony_ci- } else { 4084be168c0dSopenharmony_ci- paddings_vec2d.reserve(paddings->data()->size()); 4085be168c0dSopenharmony_ci- for (size_t i = 0; i < paddings->data()->size(); i++) { 4086be168c0dSopenharmony_ci- auto vet = paddings->data()->Get(i); 4087be168c0dSopenharmony_ci- paddings_vec2d.emplace_back(std::vector<int64_t>(vet->data()->begin(), vet->data()->end())); 4088be168c0dSopenharmony_ci- } 4089be168c0dSopenharmony_ci- } 4090be168c0dSopenharmony_ci- space_to_batch_n_d.paddings = paddings_vec2d; 4091be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4092be168c0dSopenharmony_ci- (void)SpaceToBatchNDBlockMarshalling(data, space_to_batch_n_d); 4093be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4094be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4095be168c0dSopenharmony_ci- return ret; 4096be168c0dSopenharmony_ci- } else { 4097be168c0dSopenharmony_ci- return {}; 4098be168c0dSopenharmony_ci- } 4099be168c0dSopenharmony_ci- } else { 4100be168c0dSopenharmony_ci- return {}; 4101be168c0dSopenharmony_ci- } 4102be168c0dSopenharmony_ci-} 4103be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSplit_V2_0(PrimitivePtr primitive) { 4104be168c0dSopenharmony_ci- if (primitive != nullptr) { 4105be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4106be168c0dSopenharmony_ci- auto value = prim->value_as_Split(); 4107be168c0dSopenharmony_ci- if (value != nullptr) { 4108be168c0dSopenharmony_ci- Split split{}; 4109be168c0dSopenharmony_ci- split.outputNum = value->output_num(); 4110be168c0dSopenharmony_ci- std::vector<int64_t> sizeSplits; 4111be168c0dSopenharmony_ci- sizeSplits.reserve(split.outputNum); 4112be168c0dSopenharmony_ci- if (value->size_splits() == nullptr || value->size_splits()->size() <= static_cast<uint32_t>(split.outputNum)) { 4113be168c0dSopenharmony_ci- sizeSplits = {}; 4114be168c0dSopenharmony_ci- } else { 4115be168c0dSopenharmony_ci- sizeSplits = std::vector<int64_t>(value->size_splits()->begin(), value->size_splits()->end()); 4116be168c0dSopenharmony_ci- } 4117be168c0dSopenharmony_ci- split.sizeSplits = sizeSplits; 4118be168c0dSopenharmony_ci- split.axis = value->axis(); 4119be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4120be168c0dSopenharmony_ci- (void)SplitBlockMarshalling(data, split); 4121be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4122be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4123be168c0dSopenharmony_ci- return ret; 4124be168c0dSopenharmony_ci- } else { 4125be168c0dSopenharmony_ci- return {}; 4126be168c0dSopenharmony_ci- } 4127be168c0dSopenharmony_ci- } else { 4128be168c0dSopenharmony_ci- return {}; 4129be168c0dSopenharmony_ci- } 4130be168c0dSopenharmony_ci-} 4131be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSqrt_V2_0(PrimitivePtr primitive) { 4132be168c0dSopenharmony_ci- if (primitive != nullptr) { 4133be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4134be168c0dSopenharmony_ci- auto value = prim->value_as_Sqrt(); 4135be168c0dSopenharmony_ci- if (value != nullptr) { 4136be168c0dSopenharmony_ci- Sqrt sqrt{}; 4137be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4138be168c0dSopenharmony_ci- (void)SqrtBlockMarshalling(data, sqrt); 4139be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4140be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4141be168c0dSopenharmony_ci- return ret; 4142be168c0dSopenharmony_ci- } else { 4143be168c0dSopenharmony_ci- return {}; 4144be168c0dSopenharmony_ci- } 4145be168c0dSopenharmony_ci- } else { 4146be168c0dSopenharmony_ci- return {}; 4147be168c0dSopenharmony_ci- } 4148be168c0dSopenharmony_ci-} 4149be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSquaredDifference_V2_0(PrimitivePtr primitive) { 4150be168c0dSopenharmony_ci- if (primitive != nullptr) { 4151be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4152be168c0dSopenharmony_ci- auto value = prim->value_as_SquaredDifference(); 4153be168c0dSopenharmony_ci- if (value != nullptr) { 4154be168c0dSopenharmony_ci- SquaredDifference squared_difference{}; 4155be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4156be168c0dSopenharmony_ci- (void)SquaredDifferenceBlockMarshalling(data, squared_difference); 4157be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4158be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4159be168c0dSopenharmony_ci- return ret; 4160be168c0dSopenharmony_ci- } else { 4161be168c0dSopenharmony_ci- return {}; 4162be168c0dSopenharmony_ci- } 4163be168c0dSopenharmony_ci- } else { 4164be168c0dSopenharmony_ci- return {}; 4165be168c0dSopenharmony_ci- } 4166be168c0dSopenharmony_ci-} 4167be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSqueeze_V2_0(PrimitivePtr primitive) { 4168be168c0dSopenharmony_ci- if (primitive != nullptr) { 4169be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4170be168c0dSopenharmony_ci- auto value = prim->value_as_Squeeze(); 4171be168c0dSopenharmony_ci- if (value != nullptr) { 4172be168c0dSopenharmony_ci- Squeeze squeeze{}; 4173be168c0dSopenharmony_ci- std::vector<int64_t> axis; 4174be168c0dSopenharmony_ci- if (value->axis() == nullptr) { 4175be168c0dSopenharmony_ci- axis = {}; 4176be168c0dSopenharmony_ci- } else { 4177be168c0dSopenharmony_ci- axis = std::vector<int64_t>(value->axis()->begin(), value->axis()->end()); 4178be168c0dSopenharmony_ci- } 4179be168c0dSopenharmony_ci- squeeze.axis = axis; 4180be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4181be168c0dSopenharmony_ci- (void)SqueezeBlockMarshalling(data, squeeze); 4182be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4183be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4184be168c0dSopenharmony_ci- return ret; 4185be168c0dSopenharmony_ci- } else { 4186be168c0dSopenharmony_ci- return {}; 4187be168c0dSopenharmony_ci- } 4188be168c0dSopenharmony_ci- } else { 4189be168c0dSopenharmony_ci- return {}; 4190be168c0dSopenharmony_ci- } 4191be168c0dSopenharmony_ci-} 4192be168c0dSopenharmony_ci-std::vector<int8_t> ConvertStack_V2_0(PrimitivePtr primitive) { 4193be168c0dSopenharmony_ci- if (primitive != nullptr) { 4194be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4195be168c0dSopenharmony_ci- auto value = prim->value_as_Stack(); 4196be168c0dSopenharmony_ci- if (value != nullptr) { 4197be168c0dSopenharmony_ci- Stack stack{}; 4198be168c0dSopenharmony_ci- stack.axis = value->axis(); 4199be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4200be168c0dSopenharmony_ci- (void)StackBlockMarshalling(data, stack); 4201be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4202be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4203be168c0dSopenharmony_ci- return ret; 4204be168c0dSopenharmony_ci- } else { 4205be168c0dSopenharmony_ci- return {}; 4206be168c0dSopenharmony_ci- } 4207be168c0dSopenharmony_ci- } else { 4208be168c0dSopenharmony_ci- return {}; 4209be168c0dSopenharmony_ci- } 4210be168c0dSopenharmony_ci-} 4211be168c0dSopenharmony_ci-std::vector<int8_t> ConvertStridedSlice_V2_0(PrimitivePtr primitive) { 4212be168c0dSopenharmony_ci- if (primitive != nullptr) { 4213be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4214be168c0dSopenharmony_ci- auto value = prim->value_as_StridedSlice(); 4215be168c0dSopenharmony_ci- if (value != nullptr) { 4216be168c0dSopenharmony_ci- StridedSlice strided_slice{}; 4217be168c0dSopenharmony_ci- strided_slice.beginMask = value->begin_mask(); 4218be168c0dSopenharmony_ci- strided_slice.endMask = value->end_mask(); 4219be168c0dSopenharmony_ci- strided_slice.ellipsisMask = value->ellipsis_mask(); 4220be168c0dSopenharmony_ci- strided_slice.newAxisMask = value->new_axis_mask(); 4221be168c0dSopenharmony_ci- strided_slice.shrinkAxisMask = value->shrink_axis_mask(); 4222be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4223be168c0dSopenharmony_ci- (void)StridedSliceBlockMarshalling(data, strided_slice); 4224be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4225be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4226be168c0dSopenharmony_ci- return ret; 4227be168c0dSopenharmony_ci- } else { 4228be168c0dSopenharmony_ci- return {}; 4229be168c0dSopenharmony_ci- } 4230be168c0dSopenharmony_ci- } else { 4231be168c0dSopenharmony_ci- return {}; 4232be168c0dSopenharmony_ci- } 4233be168c0dSopenharmony_ci-} 4234be168c0dSopenharmony_ci-std::vector<int8_t> ConvertSubFusion_V2_0(PrimitivePtr primitive) { 4235be168c0dSopenharmony_ci- if (primitive != nullptr) { 4236be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4237be168c0dSopenharmony_ci- auto value = prim->value_as_SubFusion(); 4238be168c0dSopenharmony_ci- if (value != nullptr) { 4239be168c0dSopenharmony_ci- SubFusion sub_fusion{}; 4240be168c0dSopenharmony_ci- sub_fusion.activationType = static_cast<HDI::Nnrt::V2_0::ActivationType>(value->activation_type()); 4241be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4242be168c0dSopenharmony_ci- (void)SubFusionBlockMarshalling(data, sub_fusion); 4243be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4244be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4245be168c0dSopenharmony_ci- return ret; 4246be168c0dSopenharmony_ci- } else { 4247be168c0dSopenharmony_ci- return {}; 4248be168c0dSopenharmony_ci- } 4249be168c0dSopenharmony_ci- } else { 4250be168c0dSopenharmony_ci- return {}; 4251be168c0dSopenharmony_ci- } 4252be168c0dSopenharmony_ci-} 4253be168c0dSopenharmony_ci-std::vector<int8_t> ConvertTileFusion_V2_0(PrimitivePtr primitive) { 4254be168c0dSopenharmony_ci- if (primitive != nullptr) { 4255be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4256be168c0dSopenharmony_ci- auto value = prim->value_as_TileFusion(); 4257be168c0dSopenharmony_ci- if (value != nullptr) { 4258be168c0dSopenharmony_ci- TileFusion tile_fusion{}; 4259be168c0dSopenharmony_ci- std::vector<int64_t> dims; 4260be168c0dSopenharmony_ci- dims.reserve(kNumEight); 4261be168c0dSopenharmony_ci- if (value->dims() == nullptr) { 4262be168c0dSopenharmony_ci- dims = {0, 0, 0, 0, 0, 0, 0, 0}; 4263be168c0dSopenharmony_ci- } else { 4264be168c0dSopenharmony_ci- dims = std::vector<int64_t>(value->dims()->begin(), value->dims()->end()); 4265be168c0dSopenharmony_ci- } 4266be168c0dSopenharmony_ci- tile_fusion.dims = dims; 4267be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4268be168c0dSopenharmony_ci- (void)TileFusionBlockMarshalling(data, tile_fusion); 4269be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4270be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4271be168c0dSopenharmony_ci- return ret; 4272be168c0dSopenharmony_ci- } else { 4273be168c0dSopenharmony_ci- return {}; 4274be168c0dSopenharmony_ci- } 4275be168c0dSopenharmony_ci- } else { 4276be168c0dSopenharmony_ci- return {}; 4277be168c0dSopenharmony_ci- } 4278be168c0dSopenharmony_ci-} 4279be168c0dSopenharmony_ci-std::vector<int8_t> ConvertTopKFusion_V2_0(PrimitivePtr primitive) { 4280be168c0dSopenharmony_ci- if (primitive != nullptr) { 4281be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4282be168c0dSopenharmony_ci- auto value = prim->value_as_TopKFusion(); 4283be168c0dSopenharmony_ci- if (value != nullptr) { 4284be168c0dSopenharmony_ci- TopKFusion top_k_fusion{}; 4285be168c0dSopenharmony_ci- top_k_fusion.sorted = value->sorted(); 4286be168c0dSopenharmony_ci- top_k_fusion.axis = value->axis(); 4287be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4288be168c0dSopenharmony_ci- (void)TopKFusionBlockMarshalling(data, top_k_fusion); 4289be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4290be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4291be168c0dSopenharmony_ci- return ret; 4292be168c0dSopenharmony_ci- } else { 4293be168c0dSopenharmony_ci- return {}; 4294be168c0dSopenharmony_ci- } 4295be168c0dSopenharmony_ci- } else { 4296be168c0dSopenharmony_ci- return {}; 4297be168c0dSopenharmony_ci- } 4298be168c0dSopenharmony_ci-} 4299be168c0dSopenharmony_ci-std::vector<int8_t> ConvertTranspose_V2_0(PrimitivePtr primitive) { 4300be168c0dSopenharmony_ci- if (primitive != nullptr) { 4301be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4302be168c0dSopenharmony_ci- auto value = prim->value_as_Transpose(); 4303be168c0dSopenharmony_ci- if (value != nullptr) { 4304be168c0dSopenharmony_ci- Transpose transpose{}; 4305be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4306be168c0dSopenharmony_ci- (void)TransposeBlockMarshalling(data, transpose); 4307be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4308be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4309be168c0dSopenharmony_ci- return ret; 4310be168c0dSopenharmony_ci- } else { 4311be168c0dSopenharmony_ci- return {}; 4312be168c0dSopenharmony_ci- } 4313be168c0dSopenharmony_ci- } else { 4314be168c0dSopenharmony_ci- return {}; 4315be168c0dSopenharmony_ci- } 4316be168c0dSopenharmony_ci-} 4317be168c0dSopenharmony_ci-std::vector<int8_t> ConvertUnsqueeze_V2_0(PrimitivePtr primitive) { 4318be168c0dSopenharmony_ci- if (primitive != nullptr) { 4319be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(primitive); 4320be168c0dSopenharmony_ci- auto value = prim->value_as_Unsqueeze(); 4321be168c0dSopenharmony_ci- if (value != nullptr) { 4322be168c0dSopenharmony_ci- Unsqueeze unsqueeze{}; 4323be168c0dSopenharmony_ci- std::vector<int64_t> axis; 4324be168c0dSopenharmony_ci- axis.reserve(kNumEight); 4325be168c0dSopenharmony_ci- if (value->axis() == nullptr) { 4326be168c0dSopenharmony_ci- axis = {0, 0, 0, 0}; 4327be168c0dSopenharmony_ci- } else { 4328be168c0dSopenharmony_ci- axis = std::vector<int64_t>(value->axis()->begin(), value->axis()->end()); 4329be168c0dSopenharmony_ci- } 4330be168c0dSopenharmony_ci- unsqueeze.axis = axis; 4331be168c0dSopenharmony_ci- OHOS::MessageParcel data; 4332be168c0dSopenharmony_ci- (void)UnsqueezeBlockMarshalling(data, unsqueeze); 4333be168c0dSopenharmony_ci- std::vector<int8_t> ret(reinterpret_cast<const int8_t *>(data.GetData()), 4334be168c0dSopenharmony_ci- reinterpret_cast<const int8_t *>(data.GetData()) + data.GetDataSize()); 4335be168c0dSopenharmony_ci- return ret; 4336be168c0dSopenharmony_ci- } else { 4337be168c0dSopenharmony_ci- return {}; 4338be168c0dSopenharmony_ci- } 4339be168c0dSopenharmony_ci- } else { 4340be168c0dSopenharmony_ci- return {}; 4341be168c0dSopenharmony_ci- } 4342be168c0dSopenharmony_ci-} 4343be168c0dSopenharmony_ci- 4344be168c0dSopenharmony_ci-std::vector<int8_t> Convert_V2_0(NodeType type, PrimitivePtr primitive) { 4345be168c0dSopenharmony_ci- switch (type) { 4346be168c0dSopenharmony_ci- case NODE_TYPE_ACTIVATION: 4347be168c0dSopenharmony_ci- return ConvertActivation_V2_0(primitive); 4348be168c0dSopenharmony_ci- break; 4349be168c0dSopenharmony_ci- case NODE_TYPE_ADD_FUSION: 4350be168c0dSopenharmony_ci- return ConvertAddFusion_V2_0(primitive); 4351be168c0dSopenharmony_ci- break; 4352be168c0dSopenharmony_ci- case NODE_TYPE_ARGMAX_FUSION: 4353be168c0dSopenharmony_ci- return ConvertArgMaxFusion_V2_0(primitive); 4354be168c0dSopenharmony_ci- break; 4355be168c0dSopenharmony_ci- case NODE_TYPE_AVG_POOL_FUSION: 4356be168c0dSopenharmony_ci- return ConvertAvgPoolFusion_V2_0(primitive); 4357be168c0dSopenharmony_ci- break; 4358be168c0dSopenharmony_ci- case NODE_TYPE_BATCH_TO_SPACE_ND: 4359be168c0dSopenharmony_ci- return ConvertBatchToSpaceND_V2_0(primitive); 4360be168c0dSopenharmony_ci- break; 4361be168c0dSopenharmony_ci- case NODE_TYPE_BIAS_ADD: 4362be168c0dSopenharmony_ci- return ConvertBiasAdd_V2_0(primitive); 4363be168c0dSopenharmony_ci- break; 4364be168c0dSopenharmony_ci- case NODE_TYPE_CAST: 4365be168c0dSopenharmony_ci- return ConvertCast_V2_0(primitive); 4366be168c0dSopenharmony_ci- break; 4367be168c0dSopenharmony_ci- case NODE_TYPE_CONCAT: 4368be168c0dSopenharmony_ci- return ConvertConcat_V2_0(primitive); 4369be168c0dSopenharmony_ci- break; 4370be168c0dSopenharmony_ci- case NODE_TYPE_CONV2D_FUSION: 4371be168c0dSopenharmony_ci- return ConvertConv2DFusion_V2_0(primitive); 4372be168c0dSopenharmony_ci- break; 4373be168c0dSopenharmony_ci- case NODE_TYPE_CONV2D_TRANSPOSE_FUSION: 4374be168c0dSopenharmony_ci- return ConvertConv2dTransposeFusion_V2_0(primitive); 4375be168c0dSopenharmony_ci- break; 4376be168c0dSopenharmony_ci- case NODE_TYPE_DIV_FUSION: 4377be168c0dSopenharmony_ci- return ConvertDivFusion_V2_0(primitive); 4378be168c0dSopenharmony_ci- break; 4379be168c0dSopenharmony_ci- case NODE_TYPE_ELTWISE: 4380be168c0dSopenharmony_ci- return ConvertEltwise_V2_0(primitive); 4381be168c0dSopenharmony_ci- break; 4382be168c0dSopenharmony_ci- case NODE_TYPE_EXPAND_DIMS: 4383be168c0dSopenharmony_ci- return ConvertExpandDims_V2_0(primitive); 4384be168c0dSopenharmony_ci- break; 4385be168c0dSopenharmony_ci- case NODE_TYPE_FILL: 4386be168c0dSopenharmony_ci- return ConvertFill_V2_0(primitive); 4387be168c0dSopenharmony_ci- break; 4388be168c0dSopenharmony_ci- case NODE_TYPE_FULL_CONNECTION: 4389be168c0dSopenharmony_ci- return ConvertFullConnection_V2_0(primitive); 4390be168c0dSopenharmony_ci- break; 4391be168c0dSopenharmony_ci- case NODE_TYPE_FUSED_BATCH_NORM: 4392be168c0dSopenharmony_ci- return ConvertFusedBatchNorm_V2_0(primitive); 4393be168c0dSopenharmony_ci- break; 4394be168c0dSopenharmony_ci- case NODE_TYPE_GATHER: 4395be168c0dSopenharmony_ci- return ConvertGather_V2_0(primitive); 4396be168c0dSopenharmony_ci- break; 4397be168c0dSopenharmony_ci- case NODE_TYPE_LAYER_NORM_FUSION: 4398be168c0dSopenharmony_ci- return ConvertLayerNormFusion_V2_0(primitive); 4399be168c0dSopenharmony_ci- break; 4400be168c0dSopenharmony_ci- case NODE_TYPE_LESS_EQUAL: 4401be168c0dSopenharmony_ci- return ConvertLessEqual_V2_0(primitive); 4402be168c0dSopenharmony_ci- break; 4403be168c0dSopenharmony_ci- case NODE_TYPE_MATMUL_FUSION: 4404be168c0dSopenharmony_ci- return ConvertMatMulFusion_V2_0(primitive); 4405be168c0dSopenharmony_ci- break; 4406be168c0dSopenharmony_ci- case NODE_TYPE_MAXIMUM: 4407be168c0dSopenharmony_ci- return ConvertMaximum_V2_0(primitive); 4408be168c0dSopenharmony_ci- break; 4409be168c0dSopenharmony_ci- case NODE_TYPE_MAX_POOL_FUSION: 4410be168c0dSopenharmony_ci- return ConvertMaxPoolFusion_V2_0(primitive); 4411be168c0dSopenharmony_ci- break; 4412be168c0dSopenharmony_ci- case NODE_TYPE_MUL_FUSION: 4413be168c0dSopenharmony_ci- return ConvertMulFusion_V2_0(primitive); 4414be168c0dSopenharmony_ci- break; 4415be168c0dSopenharmony_ci- case NODE_TYPE_ONE_HOT: 4416be168c0dSopenharmony_ci- return ConvertOneHot_V2_0(primitive); 4417be168c0dSopenharmony_ci- break; 4418be168c0dSopenharmony_ci- case NODE_TYPE_PAD_FUSION: 4419be168c0dSopenharmony_ci- return ConvertPadFusion_V2_0(primitive); 4420be168c0dSopenharmony_ci- break; 4421be168c0dSopenharmony_ci- case NODE_TYPE_POW_FUSION: 4422be168c0dSopenharmony_ci- return ConvertPowFusion_V2_0(primitive); 4423be168c0dSopenharmony_ci- break; 4424be168c0dSopenharmony_ci- case NODE_TYPE_PRELU_FUSION: 4425be168c0dSopenharmony_ci- return ConvertPReLUFusion_V2_0(primitive); 4426be168c0dSopenharmony_ci- break; 4427be168c0dSopenharmony_ci- case NODE_TYPE_QUANT_DTYPE_CAST: 4428be168c0dSopenharmony_ci- return ConvertQuantDTypeCast_V2_0(primitive); 4429be168c0dSopenharmony_ci- break; 4430be168c0dSopenharmony_ci- case NODE_TYPE_REDUCE_FUSION: 4431be168c0dSopenharmony_ci- return ConvertReduceFusion_V2_0(primitive); 4432be168c0dSopenharmony_ci- break; 4433be168c0dSopenharmony_ci- case NODE_TYPE_RESHAPE: 4434be168c0dSopenharmony_ci- return ConvertReshape_V2_0(primitive); 4435be168c0dSopenharmony_ci- break; 4436be168c0dSopenharmony_ci- case NODE_TYPE_RESIZE: 4437be168c0dSopenharmony_ci- return ConvertResize_V2_0(primitive); 4438be168c0dSopenharmony_ci- break; 4439be168c0dSopenharmony_ci- case NODE_TYPE_RSQRT: 4440be168c0dSopenharmony_ci- return ConvertRsqrt_V2_0(primitive); 4441be168c0dSopenharmony_ci- break; 4442be168c0dSopenharmony_ci- case NODE_TYPE_SCALE_FUSION: 4443be168c0dSopenharmony_ci- return ConvertScaleFusion_V2_0(primitive); 4444be168c0dSopenharmony_ci- break; 4445be168c0dSopenharmony_ci- case NODE_TYPE_SHAPE: 4446be168c0dSopenharmony_ci- return ConvertShape_V2_0(primitive); 4447be168c0dSopenharmony_ci- break; 4448be168c0dSopenharmony_ci- case NODE_TYPE_SLICE_FUSION: 4449be168c0dSopenharmony_ci- return ConvertSliceFusion_V2_0(primitive); 4450be168c0dSopenharmony_ci- break; 4451be168c0dSopenharmony_ci- case NODE_TYPE_SOFTMAX: 4452be168c0dSopenharmony_ci- return ConvertSoftmax_V2_0(primitive); 4453be168c0dSopenharmony_ci- break; 4454be168c0dSopenharmony_ci- case NODE_TYPE_SPACE_TO_BATCH_ND: 4455be168c0dSopenharmony_ci- return ConvertSpaceToBatchND_V2_0(primitive); 4456be168c0dSopenharmony_ci- break; 4457be168c0dSopenharmony_ci- case NODE_TYPE_SPLIT: 4458be168c0dSopenharmony_ci- return ConvertSplit_V2_0(primitive); 4459be168c0dSopenharmony_ci- break; 4460be168c0dSopenharmony_ci- case NODE_TYPE_SQRT: 4461be168c0dSopenharmony_ci- return ConvertSqrt_V2_0(primitive); 4462be168c0dSopenharmony_ci- break; 4463be168c0dSopenharmony_ci- case NODE_TYPE_SQUARED_DIFFERENCE: 4464be168c0dSopenharmony_ci- return ConvertSquaredDifference_V2_0(primitive); 4465be168c0dSopenharmony_ci- break; 4466be168c0dSopenharmony_ci- case NODE_TYPE_SQUEEZE: 4467be168c0dSopenharmony_ci- return ConvertSqueeze_V2_0(primitive); 4468be168c0dSopenharmony_ci- break; 4469be168c0dSopenharmony_ci- case NODE_TYPE_STACK: 4470be168c0dSopenharmony_ci- return ConvertStack_V2_0(primitive); 4471be168c0dSopenharmony_ci- break; 4472be168c0dSopenharmony_ci- case NODE_TYPE_STRIDED_SLICE: 4473be168c0dSopenharmony_ci- return ConvertStridedSlice_V2_0(primitive); 4474be168c0dSopenharmony_ci- break; 4475be168c0dSopenharmony_ci- case NODE_TYPE_SUB_FUSION: 4476be168c0dSopenharmony_ci- return ConvertSubFusion_V2_0(primitive); 4477be168c0dSopenharmony_ci- break; 4478be168c0dSopenharmony_ci- case NODE_TYPE_TILE_FUSION: 4479be168c0dSopenharmony_ci- return ConvertTileFusion_V2_0(primitive); 4480be168c0dSopenharmony_ci- break; 4481be168c0dSopenharmony_ci- case NODE_TYPE_TOPK_FUSION: 4482be168c0dSopenharmony_ci- return ConvertTopKFusion_V2_0(primitive); 4483be168c0dSopenharmony_ci- break; 4484be168c0dSopenharmony_ci- case NODE_TYPE_TRANSPOSE: 4485be168c0dSopenharmony_ci- return ConvertTranspose_V2_0(primitive); 4486be168c0dSopenharmony_ci- break; 4487be168c0dSopenharmony_ci- case NODE_TYPE_UNSQUEEZE: 4488be168c0dSopenharmony_ci- return ConvertUnsqueeze_V2_0(primitive); 4489be168c0dSopenharmony_ci- break; 4490be168c0dSopenharmony_ci- default: 4491be168c0dSopenharmony_ci- return {}; 4492be168c0dSopenharmony_ci- } 4493be168c0dSopenharmony_ci-} 4494be168c0dSopenharmony_ci- 4495be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V2_0::Model *MindIR_LiteGraph_To_Model(const LiteGraph *lite_graph, const OHOS::HDI::Nnrt::V2_0::SharedBuffer &buffer) { 4496be168c0dSopenharmony_ci- if (lite_graph != nullptr) { 4497be168c0dSopenharmony_ci- MS_LOG(INFO) << "MindIR_LiteGraph_To_Model begin"; 4498be168c0dSopenharmony_ci- if (!lite_graph->name_.empty()) { 4499be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting lite graph,name =" << lite_graph->name_; 4500be168c0dSopenharmony_ci- } else { 4501be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting lite graph, but lite graph has no name."; 4502be168c0dSopenharmony_ci- } 4503be168c0dSopenharmony_ci- std::vector<uint32_t> inputIndex; 4504be168c0dSopenharmony_ci- std::vector<uint32_t> outputIndex; 4505be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V2_0::Node> nodes; 4506be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V2_0::Tensor> allTensors; 4507be168c0dSopenharmony_ci- std::vector<OHOS::HDI::Nnrt::V2_0::SubGraph> subGraph; 4508be168c0dSopenharmony_ci- // nodes 4509be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting nodes, vector size = " << lite_graph->all_nodes_.size(); 4510be168c0dSopenharmony_ci- nodes.reserve(lite_graph->all_nodes_.size()); 4511be168c0dSopenharmony_ci- for (auto node : lite_graph->all_nodes_) { 4512be168c0dSopenharmony_ci- if (node == nullptr) { 4513be168c0dSopenharmony_ci- MS_LOG(ERROR) << "node is nullptr, convert fail."; 4514be168c0dSopenharmony_ci- return nullptr; 4515be168c0dSopenharmony_ci- } 4516be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V2_0::Node tmp; 4517be168c0dSopenharmony_ci- tmp.name = node->name_; 4518be168c0dSopenharmony_ci- if (node->primitive_ == nullptr) { 4519be168c0dSopenharmony_ci- MS_LOG(ERROR) << "node primitive is nullptr, convert fail."; 4520be168c0dSopenharmony_ci- return nullptr; 4521be168c0dSopenharmony_ci- } 4522be168c0dSopenharmony_ci- auto prim = static_cast<schema::Primitive *>(node->primitive_); 4523be168c0dSopenharmony_ci- auto value = prim->value_type(); 4524be168c0dSopenharmony_ci- tmp.nodeType = static_cast<HDI::Nnrt::V2_0::NodeType>(value); 4525be168c0dSopenharmony_ci- tmp.nodeAttr = Convert_V2_0(static_cast<NodeType>(value), node->primitive_); 4526be168c0dSopenharmony_ci- tmp.inputIndex = node->input_indices_; 4527be168c0dSopenharmony_ci- tmp.outputIndex = node->output_indices_; 4528be168c0dSopenharmony_ci- tmp.quantType = static_cast<HDI::Nnrt::V2_0::QuantType>(node->quant_type_); 4529be168c0dSopenharmony_ci- nodes.emplace_back(tmp); 4530be168c0dSopenharmony_ci- } 4531be168c0dSopenharmony_ci- 4532be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting Tensor,Tensor size=" << lite_graph->all_tensors_.size(); 4533be168c0dSopenharmony_ci- // Tensor 4534be168c0dSopenharmony_ci- allTensors.reserve(lite_graph->all_tensors_.size()); 4535be168c0dSopenharmony_ci- unsigned int tensor_buffer_offset = 0; 4536be168c0dSopenharmony_ci- uint8_t *mmap_ptr = nullptr; 4537be168c0dSopenharmony_ci- if (buffer.fd != -1) { 4538be168c0dSopenharmony_ci- mmap_ptr = 4539be168c0dSopenharmony_ci- static_cast<uint8_t *>(mmap(nullptr, buffer.bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0)); 4540be168c0dSopenharmony_ci- if (mmap_ptr == MAP_FAILED) { 4541be168c0dSopenharmony_ci- MS_LOG(ERROR) << "mmap failed"; 4542be168c0dSopenharmony_ci- return nullptr; 4543be168c0dSopenharmony_ci- } 4544be168c0dSopenharmony_ci- } 4545be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start parsing tensor, mmap buffer size = " << buffer.bufferSize; 4546be168c0dSopenharmony_ci- for (auto tensor : lite_graph->all_tensors_) { 4547be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V2_0::Tensor tmp; 4548be168c0dSopenharmony_ci- tmp.name = MindIR_Tensor_GetName(tensor); 4549be168c0dSopenharmony_ci- tmp.dataType = static_cast<HDI::Nnrt::V2_0::HDI::Nnrt::V2_0::DataType>(MindIR_Tensor_GetDataType(tensor)); 4550be168c0dSopenharmony_ci- tmp.dims = MindIR_Tensor_GetDims(tensor); 4551be168c0dSopenharmony_ci- tmp.format = static_cast<HDI::Nnrt::V2_0::HDI::Nnrt::V2_0::Format>(MindIR_Tensor_GetFormat(tensor)); 4552be168c0dSopenharmony_ci- tmp.data = MindIR_Tensor_GetData_V2_0(tensor, buffer, mmap_ptr, tensor_buffer_offset); 4553be168c0dSopenharmony_ci- tmp.quantParams = MindIR_Tensor_GetQuantParams_OHOS_V2_0(tensor); 4554be168c0dSopenharmony_ci- allTensors.emplace_back(tmp); 4555be168c0dSopenharmony_ci- tensor_buffer_offset = tmp.data.offset + tmp.data.dataSize; 4556be168c0dSopenharmony_ci- } 4557be168c0dSopenharmony_ci- MS_LOG(INFO) << ("Parsing tensor finish."); 4558be168c0dSopenharmony_ci- if (buffer.fd != -1) { 4559be168c0dSopenharmony_ci- auto munmap_res = munmap(mmap_ptr, buffer.bufferSize); 4560be168c0dSopenharmony_ci- if (munmap_res != 0) { 4561be168c0dSopenharmony_ci- MS_LOG(ERROR) << "unmap failed."; 4562be168c0dSopenharmony_ci- return nullptr; 4563be168c0dSopenharmony_ci- } 4564be168c0dSopenharmony_ci- } 4565be168c0dSopenharmony_ci- 4566be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start converting SubGraph,SubGraph size=" << lite_graph->sub_graphs_.size(); 4567be168c0dSopenharmony_ci- // SubGraph 4568be168c0dSopenharmony_ci- subGraph.reserve(lite_graph->sub_graphs_.size()); 4569be168c0dSopenharmony_ci- for (auto graph : lite_graph->sub_graphs_) { 4570be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V2_0::SubGraph tmp; 4571be168c0dSopenharmony_ci- tmp.name = graph->name_; 4572be168c0dSopenharmony_ci- tmp.inputIndices = std::vector<uint32_t>(graph->input_indices_); 4573be168c0dSopenharmony_ci- tmp.outputIndices = std::vector<uint32_t>(graph->output_indices_); 4574be168c0dSopenharmony_ci- tmp.nodeIndices = std::vector<uint32_t>(graph->node_indices_); 4575be168c0dSopenharmony_ci- subGraph.emplace_back(tmp); 4576be168c0dSopenharmony_ci- } 4577be168c0dSopenharmony_ci- 4578be168c0dSopenharmony_ci- MS_LOG(INFO) << "Start copying model"; 4579be168c0dSopenharmony_ci- auto *ret_model = new (std::nothrow) Model(); 4580be168c0dSopenharmony_ci- if (ret_model == nullptr) { 4581be168c0dSopenharmony_ci- MS_LOG(ERROR) << "new Model failed."; 4582be168c0dSopenharmony_ci- return nullptr; 4583be168c0dSopenharmony_ci- } 4584be168c0dSopenharmony_ci- ret_model->name = lite_graph->name_; 4585be168c0dSopenharmony_ci- ret_model->inputIndex = lite_graph->input_indices_; 4586be168c0dSopenharmony_ci- ret_model->outputIndex = lite_graph->output_indices_; 4587be168c0dSopenharmony_ci- ret_model->nodes = nodes; 4588be168c0dSopenharmony_ci- ret_model->allTensors = allTensors; 4589be168c0dSopenharmony_ci- ret_model->subGraph = subGraph; 4590be168c0dSopenharmony_ci- MS_LOG(INFO) << "MindIR_LiteGraph_To_Model success"; 4591be168c0dSopenharmony_ci- return ret_model; 4592be168c0dSopenharmony_ci- } else { 4593be168c0dSopenharmony_ci- MS_LOG(ERROR) << "lite graph is nullptr"; 4594be168c0dSopenharmony_ci- return nullptr; 4595be168c0dSopenharmony_ci- } 4596be168c0dSopenharmony_ci-} 4597be168c0dSopenharmony_ci- 4598be168c0dSopenharmony_ci-} // namespace lite 4599be168c0dSopenharmony_ci-} // namespace mindspore 4600be168c0dSopenharmony_ci\ No newline at end of file 4601be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/src/mindir_tensor.cc b/mindspore/lite/mindir/src/mindir_tensor.cc 4602be168c0dSopenharmony_ciindex 2db4ce8b..9575f8c2 100644 4603be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/src/mindir_tensor.cc 4604be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/src/mindir_tensor.cc 4605be168c0dSopenharmony_ci@@ -18,10 +18,6 @@ 4606be168c0dSopenharmony_ci #include "utils.h" 4607be168c0dSopenharmony_ci #include "securec.h" 4608be168c0dSopenharmony_ci #include "mindir_memory_manager.h" 4609be168c0dSopenharmony_ci-#include "nnrt/v1_0/nnrt_types.h" 4610be168c0dSopenharmony_ci-#include "nnrt/v2_0/nnrt_types.h" 4611be168c0dSopenharmony_ci- 4612be168c0dSopenharmony_ci-using namespace OHOS::HDI::Nnrt::V1_0; 4613be168c0dSopenharmony_ci 4614be168c0dSopenharmony_ci namespace mindspore { 4615be168c0dSopenharmony_ci namespace lite { 4616be168c0dSopenharmony_ci@@ -239,82 +235,6 @@ void MindIR_Tensor_SetFormat(TensorPtr *tensor, Format format) { 4617be168c0dSopenharmony_ci } 4618be168c0dSopenharmony_ci } 4619be168c0dSopenharmony_ci 4620be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V1_0::SharedBuffer MindIR_Tensor_GetData(ConstTensorPtr tensor, 4621be168c0dSopenharmony_ci- const OHOS::HDI::Nnrt::V1_0::SharedBuffer &buffer_templete, 4622be168c0dSopenharmony_ci- uint8_t *mmap_ptr, unsigned int offset) { 4623be168c0dSopenharmony_ci- if (tensor != nullptr) { 4624be168c0dSopenharmony_ci- auto value = static_cast<const schema::Tensor *>(tensor); 4625be168c0dSopenharmony_ci- if (value != nullptr) { 4626be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V1_0::SharedBuffer result{}; 4627be168c0dSopenharmony_ci- 4628be168c0dSopenharmony_ci- if (value->data() == nullptr || value->data()->size() == 0) { 4629be168c0dSopenharmony_ci- result.fd = -1; 4630be168c0dSopenharmony_ci- result.bufferSize = buffer_templete.bufferSize; 4631be168c0dSopenharmony_ci- result.offset = offset; 4632be168c0dSopenharmony_ci- result.dataSize = 0; 4633be168c0dSopenharmony_ci- return result; 4634be168c0dSopenharmony_ci- } 4635be168c0dSopenharmony_ci- if (mmap_ptr == nullptr) { 4636be168c0dSopenharmony_ci- MS_LOG(ERROR) << "Tensor GetData failed, mmap pointer should not be nullptr"; 4637be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4638be168c0dSopenharmony_ci- } 4639be168c0dSopenharmony_ci- result.fd = buffer_templete.fd; 4640be168c0dSopenharmony_ci- result.bufferSize = buffer_templete.bufferSize; 4641be168c0dSopenharmony_ci- auto ret = memcpy_s(mmap_ptr + offset, value->data()->size(), value->data()->data(), value->data()->size()); 4642be168c0dSopenharmony_ci- if (ret != EOK) { 4643be168c0dSopenharmony_ci- MS_LOG(ERROR) << "Tensor memcpy failed, ret:" << ret; 4644be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4645be168c0dSopenharmony_ci- } 4646be168c0dSopenharmony_ci- result.offset = offset; 4647be168c0dSopenharmony_ci- result.dataSize = value->data()->size(); 4648be168c0dSopenharmony_ci- return result; 4649be168c0dSopenharmony_ci- } else { 4650be168c0dSopenharmony_ci- MS_LOG(ERROR) << "Tensor GetData failed, mmap pointer should not be nullptr"; 4651be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4652be168c0dSopenharmony_ci- } 4653be168c0dSopenharmony_ci- } else { 4654be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4655be168c0dSopenharmony_ci- } 4656be168c0dSopenharmony_ci-} 4657be168c0dSopenharmony_ci- 4658be168c0dSopenharmony_ci-OHOS::HDI::Nnrt::V2_0::SharedBuffer MindIR_Tensor_GetData_V2_0(ConstTensorPtr tensor, 4659be168c0dSopenharmony_ci- const OHOS::HDI::Nnrt::V2_0::SharedBuffer &buffer_templete, 4660be168c0dSopenharmony_ci- uint8_t *mmap_ptr, unsigned int offset) { 4661be168c0dSopenharmony_ci- if (tensor != nullptr) { 4662be168c0dSopenharmony_ci- auto value = static_cast<const schema::Tensor *>(tensor); 4663be168c0dSopenharmony_ci- if (value != nullptr) { 4664be168c0dSopenharmony_ci- OHOS::HDI::Nnrt::V2_0::SharedBuffer result{}; 4665be168c0dSopenharmony_ci- 4666be168c0dSopenharmony_ci- if (value->data() == nullptr || value->data()->size() == 0) { 4667be168c0dSopenharmony_ci- result.fd = -1; 4668be168c0dSopenharmony_ci- result.bufferSize = buffer_templete.bufferSize; 4669be168c0dSopenharmony_ci- result.offset = offset; 4670be168c0dSopenharmony_ci- result.dataSize = 0; 4671be168c0dSopenharmony_ci- return result; 4672be168c0dSopenharmony_ci- } 4673be168c0dSopenharmony_ci- if (mmap_ptr == nullptr) { 4674be168c0dSopenharmony_ci- MS_LOG(ERROR) << "Tensor GetData failed, mmap pointer should not be nullptr"; 4675be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4676be168c0dSopenharmony_ci- } 4677be168c0dSopenharmony_ci- result.fd = buffer_templete.fd; 4678be168c0dSopenharmony_ci- result.bufferSize = buffer_templete.bufferSize; 4679be168c0dSopenharmony_ci- auto ret = memcpy_s(mmap_ptr + offset, value->data()->size(), value->data()->data(), value->data()->size()); 4680be168c0dSopenharmony_ci- if (ret != EOK) { 4681be168c0dSopenharmony_ci- MS_LOG(ERROR) << "Tensor memcpy failed, ret:" << ret; 4682be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4683be168c0dSopenharmony_ci- } 4684be168c0dSopenharmony_ci- result.offset = offset; 4685be168c0dSopenharmony_ci- result.dataSize = value->data()->size(); 4686be168c0dSopenharmony_ci- return result; 4687be168c0dSopenharmony_ci- } else { 4688be168c0dSopenharmony_ci- MS_LOG(WARNING) << "Tensor GetData failed, mmap pointer should not be nullptr"; 4689be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4690be168c0dSopenharmony_ci- } 4691be168c0dSopenharmony_ci- } else { 4692be168c0dSopenharmony_ci- return {-1, 0, offset, 0}; 4693be168c0dSopenharmony_ci- } 4694be168c0dSopenharmony_ci-} 4695be168c0dSopenharmony_ci- 4696be168c0dSopenharmony_ci std::vector<uint8_t> MindIR_Tensor_GetData(ConstTensorPtr tensor) { 4697be168c0dSopenharmony_ci if (tensor != nullptr) { 4698be168c0dSopenharmony_ci auto value = static_cast<const schema::Tensor *>(tensor); 4699be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/c_api/context_c.cc b/mindspore/lite/src/litert/c_api/context_c.cc 4700be168c0dSopenharmony_ciindex c5f825aa..bde0460c 100644 4701be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/c_api/context_c.cc 4702be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/c_api/context_c.cc 4703be168c0dSopenharmony_ci@@ -324,6 +324,10 @@ NNRTDeviceDesc *OH_AI_GetAllNNRTDeviceDescs(size_t *num) { 4704be168c0dSopenharmony_ci 4705be168c0dSopenharmony_ci const char *name = nullptr; 4706be168c0dSopenharmony_ci (void)OH_NNDevice_GetName(all_device_ids[i], &name); 4707be168c0dSopenharmony_ci+ if (name == nullptr) { 4708be168c0dSopenharmony_ci+ MS_LOG(ERROR) << "OH_NNDevice_GetName error."; 4709be168c0dSopenharmony_ci+ return nullptr; 4710be168c0dSopenharmony_ci+ } 4711be168c0dSopenharmony_ci desc[i].device_name[127] = '\0'; 4712be168c0dSopenharmony_ci strncpy(desc[i].device_name, name, 127); 4713be168c0dSopenharmony_ci } 4714be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.cc b/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.cc 4715be168c0dSopenharmony_ciindex 91094658..91bbd39a 100644 4716be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.cc 4717be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.cc 4718be168c0dSopenharmony_ci@@ -18,6 +18,7 @@ 4719be168c0dSopenharmony_ci #include "src/litert/kernel/cpu/fp32_grad/strided_slice_grad.h" 4720be168c0dSopenharmony_ci #include <vector> 4721be168c0dSopenharmony_ci #include <algorithm> 4722be168c0dSopenharmony_ci+#include <utility> 4723be168c0dSopenharmony_ci #include "schema/model_generated.h" 4724be168c0dSopenharmony_ci #include "src/litert/kernel_registry.h" 4725be168c0dSopenharmony_ci #include "nnacl/fp32_grad/strided_slice_grad.h" 4726be168c0dSopenharmony_ci@@ -55,7 +56,6 @@ void StridedSliceGradCPUKernel::FillEmptyDims() { 4727be168c0dSopenharmony_ci int32_t begins[DIMENSION_8D]; 4728be168c0dSopenharmony_ci int32_t ends[DIMENSION_8D]; 4729be168c0dSopenharmony_ci int32_t strides[DIMENSION_8D]; 4730be168c0dSopenharmony_ci- int32_t input_shape[DIMENSION_8D]; 4731be168c0dSopenharmony_ci int32_t i; 4732be168c0dSopenharmony_ci 4733be168c0dSopenharmony_ci // invert the order of the dimension and fill defout outsize actual ranae 4734be168c0dSopenharmony_ci@@ -63,19 +63,10 @@ void StridedSliceGradCPUKernel::FillEmptyDims() { 4735be168c0dSopenharmony_ci begins[i] = param_->begins_[i]; 4736be168c0dSopenharmony_ci ends[i] = param_->ends_[i]; 4737be168c0dSopenharmony_ci strides[i] = param_->strides_[i]; 4738be168c0dSopenharmony_ci- input_shape[i] = param_->in_shape_[i]; 4739be168c0dSopenharmony_ci } 4740be168c0dSopenharmony_ci 4741be168c0dSopenharmony_ci- int32_t real_index = param_->in_shape_length_ - 1; 4742be168c0dSopenharmony_ci- for (i = DIMENSION_8D - 1; i >= 0; --i) { 4743be168c0dSopenharmony_ci- if (real_index >= 0) { 4744be168c0dSopenharmony_ci- param_->in_shape_[i] = input_shape[real_index--]; 4745be168c0dSopenharmony_ci- } else { 4746be168c0dSopenharmony_ci- param_->in_shape_[i] = 1; 4747be168c0dSopenharmony_ci- } 4748be168c0dSopenharmony_ci- } 4749be168c0dSopenharmony_ci int out_shape_length = in_tensors_.at(1)->shape().at(0); 4750be168c0dSopenharmony_ci- real_index = out_shape_length - 1; 4751be168c0dSopenharmony_ci+ int32_t real_index = out_shape_length - 1; 4752be168c0dSopenharmony_ci for (i = DIMENSION_8D - 1; i >= 0; --i) { 4753be168c0dSopenharmony_ci if (real_index >= 0) { 4754be168c0dSopenharmony_ci param_->begins_[i] = begins[real_index]; 4755be168c0dSopenharmony_ci@@ -87,17 +78,15 @@ void StridedSliceGradCPUKernel::FillEmptyDims() { 4756be168c0dSopenharmony_ci param_->strides_[i] = 1; 4757be168c0dSopenharmony_ci } 4758be168c0dSopenharmony_ci } 4759be168c0dSopenharmony_ci- param_->num_axes_ = DIMENSION_8D; 4760be168c0dSopenharmony_ci- param_->in_shape_length_ = DIMENSION_8D; 4761be168c0dSopenharmony_ci- 4762be168c0dSopenharmony_ci for (i = 0; i < DIMENSION_8D; ++i) { 4763be168c0dSopenharmony_ci- if (param_->begins_[i] < 0) { 4764be168c0dSopenharmony_ci- param_->begins_[i] += param_->in_shape_[i]; 4765be168c0dSopenharmony_ci- } 4766be168c0dSopenharmony_ci- if (param_->ends_[i] < 0) { 4767be168c0dSopenharmony_ci- param_->ends_[i] += param_->in_shape_[i]; 4768be168c0dSopenharmony_ci+ int ax = param_->ends_[i] - param_->begins_[i]; 4769be168c0dSopenharmony_ci+ if (ax < 0) { 4770be168c0dSopenharmony_ci+ ax = 0; 4771be168c0dSopenharmony_ci } 4772be168c0dSopenharmony_ci+ param_->in_shape_[i] = ax; 4773be168c0dSopenharmony_ci } 4774be168c0dSopenharmony_ci+ param_->num_axes_ = DIMENSION_8D; 4775be168c0dSopenharmony_ci+ param_->in_shape_length_ = DIMENSION_8D; 4776be168c0dSopenharmony_ci } 4777be168c0dSopenharmony_ci 4778be168c0dSopenharmony_ci void StridedSliceGradCPUKernel::FillOutputDim() { 4779be168c0dSopenharmony_ci@@ -115,6 +104,24 @@ void StridedSliceGradCPUKernel::FillOutputDim() { 4780be168c0dSopenharmony_ci int StridedSliceGradCPUKernel::ReSize() { 4781be168c0dSopenharmony_ci FillEmptyDims(); 4782be168c0dSopenharmony_ci FillOutputDim(); 4783be168c0dSopenharmony_ci+ for (int32_t i = 0; i < DIMENSION_8D; ++i) { 4784be168c0dSopenharmony_ci+ if (param_->ends_[i] == 0 && param_->begins_[i] < 0) { 4785be168c0dSopenharmony_ci+ param_->ends_[i] += output_shape_[i]; 4786be168c0dSopenharmony_ci+ } 4787be168c0dSopenharmony_ci+ if (param_->ends_[i] < 0) { 4788be168c0dSopenharmony_ci+ param_->ends_[i] = (param_->ends_[i] + output_shape_[i]) < 0 ? 0 : param_->ends_[i] + output_shape_[i]; 4789be168c0dSopenharmony_ci+ } 4790be168c0dSopenharmony_ci+ if (param_->ends_[i] > output_shape_[i]) { 4791be168c0dSopenharmony_ci+ param_->ends_[i] = output_shape_[i]; 4792be168c0dSopenharmony_ci+ } 4793be168c0dSopenharmony_ci+ if (param_->begins_[i] < 0) { 4794be168c0dSopenharmony_ci+ auto k = param_->begins_[i] + output_shape_[i]; 4795be168c0dSopenharmony_ci+ param_->begins_[i] = k < 0 ? 0 : k; 4796be168c0dSopenharmony_ci+ } 4797be168c0dSopenharmony_ci+ if (param_->begins_[i] > output_shape_[i]) { 4798be168c0dSopenharmony_ci+ param_->begins_[i] = output_shape_[i]; 4799be168c0dSopenharmony_ci+ } 4800be168c0dSopenharmony_ci+ } 4801be168c0dSopenharmony_ci return RET_OK; 4802be168c0dSopenharmony_ci } 4803be168c0dSopenharmony_ci 4804be168c0dSopenharmony_ci@@ -142,20 +149,81 @@ int StridedSliceGradCPUKernel::DoExecute(int task_id) { 4805be168c0dSopenharmony_ci auto input = in_tensors_.at(0); 4806be168c0dSopenharmony_ci auto output = out_tensors_.at(0); 4807be168c0dSopenharmony_ci 4808be168c0dSopenharmony_ci- int *po = output_shape_.data(); 4809be168c0dSopenharmony_ci- auto dx = reinterpret_cast<float *>(output->MutableData()); 4810be168c0dSopenharmony_ci- auto dy = reinterpret_cast<float *>(input->MutableData()); 4811be168c0dSopenharmony_ci- CHECK_NULL_RETURN(po); 4812be168c0dSopenharmony_ci+ auto *dx = reinterpret_cast<float *>(output->MutableData()); 4813be168c0dSopenharmony_ci+ auto *dy = reinterpret_cast<float *>(input->MutableData()); 4814be168c0dSopenharmony_ci CHECK_NULL_RETURN(dx); 4815be168c0dSopenharmony_ci CHECK_NULL_RETURN(dy); 4816be168c0dSopenharmony_ci- std::fill(dx, dx + output->ElementsNum(), 0.f); 4817be168c0dSopenharmony_ci- auto ret = DoStridedSliceGrad(dy, dx, po, param_); 4818be168c0dSopenharmony_ci- if (ret != RET_OK) { 4819be168c0dSopenharmony_ci- MS_LOG(ERROR) << "StridedSliceGrad error error_code[" << ret << "]"; 4820be168c0dSopenharmony_ci- return RET_ERROR; 4821be168c0dSopenharmony_ci+ return CalStridedSliceGrad(dy, dx); 4822be168c0dSopenharmony_ci+} 4823be168c0dSopenharmony_ci+ 4824be168c0dSopenharmony_ci+int StridedSliceGradCPUKernel::CalStridedSliceGrad(float *input, float *output) { 4825be168c0dSopenharmony_ci+ int input_num = 1; 4826be168c0dSopenharmony_ci+ for (int le = 0; le < DIMENSION_8D; le++) { 4827be168c0dSopenharmony_ci+ input_num = input_num * param_->in_shape_[le]; 4828be168c0dSopenharmony_ci+ } 4829be168c0dSopenharmony_ci+ int output_num = 1; 4830be168c0dSopenharmony_ci+ for (int len = 0; len < DIMENSION_8D; len++) { 4831be168c0dSopenharmony_ci+ output_num = output_num * output_shape_[len]; 4832be168c0dSopenharmony_ci+ } 4833be168c0dSopenharmony_ci+ 4834be168c0dSopenharmony_ci+ if (input_num == 0) { 4835be168c0dSopenharmony_ci+ res_arr_ = reinterpret_cast<float *>(ms_context_->allocator->Malloc(sizeof(float) * output_num)); 4836be168c0dSopenharmony_ci+ for (int res_len = 0; res_len < output_num; res_len++) { 4837be168c0dSopenharmony_ci+ res_arr_[res_len] = static_cast<float>(0); 4838be168c0dSopenharmony_ci+ } 4839be168c0dSopenharmony_ci+ memcpy(output, res_arr_, output_num * sizeof(float)); 4840be168c0dSopenharmony_ci+ FreeRunBuffer(); 4841be168c0dSopenharmony_ci+ return RET_OK; 4842be168c0dSopenharmony_ci } 4843be168c0dSopenharmony_ci+ 4844be168c0dSopenharmony_ci+ int temp_num = input_num; 4845be168c0dSopenharmony_ci+ int max_num = input_num; 4846be168c0dSopenharmony_ci+ int step = 1; 4847be168c0dSopenharmony_ci+ for (int i = DIMENSION_8D - 1; i >= 0; --i) { 4848be168c0dSopenharmony_ci+ temp_num = static_cast<int>(temp_num * output_shape_[i] / param_->in_shape_[i]); 4849be168c0dSopenharmony_ci+ max_num = MSMAX(max_num, temp_num); 4850be168c0dSopenharmony_ci+ } 4851be168c0dSopenharmony_ci+ temp_input_ = reinterpret_cast<float *>(ms_context_->allocator->Malloc(sizeof(float) * max_num)); 4852be168c0dSopenharmony_ci+ memset(temp_input_, 0, max_num * sizeof(float)); 4853be168c0dSopenharmony_ci+ memcpy(temp_input_, input, input_num * sizeof(float)); 4854be168c0dSopenharmony_ci+ temp_ = reinterpret_cast<float *>(ms_context_->allocator->Malloc(max_num * sizeof(float))); 4855be168c0dSopenharmony_ci+ temp_num = input_num; 4856be168c0dSopenharmony_ci+ for (int i = DIMENSION_8D - 1; i >= 0; --i) { 4857be168c0dSopenharmony_ci+ temp_num = static_cast<int>(temp_num * output_shape_[i] / param_->in_shape_[i]); 4858be168c0dSopenharmony_ci+ memset(temp_, 0, sizeof(float) * temp_num); 4859be168c0dSopenharmony_ci+ int start1 = 0; 4860be168c0dSopenharmony_ci+ int start2 = 0; 4861be168c0dSopenharmony_ci+ while (start1 < temp_num) { 4862be168c0dSopenharmony_ci+ int id = 0; 4863be168c0dSopenharmony_ci+ for (int k = param_->begins_[i]; param_->strides_[i] > 0 ? k < param_->ends_[i] : k > param_->ends_[i]; 4864be168c0dSopenharmony_ci+ k += param_->strides_[i], id++) { 4865be168c0dSopenharmony_ci+ memcpy(temp_ + start1 + k * step, temp_input_ + start2 + id * step, step * sizeof(float)); 4866be168c0dSopenharmony_ci+ } 4867be168c0dSopenharmony_ci+ start1 += output_shape_[i] * step; 4868be168c0dSopenharmony_ci+ start2 += param_->in_shape_[i] * step; 4869be168c0dSopenharmony_ci+ } 4870be168c0dSopenharmony_ci+ step *= output_shape_[i]; 4871be168c0dSopenharmony_ci+ std::swap(temp_input_, temp_); 4872be168c0dSopenharmony_ci+ } 4873be168c0dSopenharmony_ci+ memcpy(output, temp_input_, output_num * sizeof(float)); 4874be168c0dSopenharmony_ci+ FreeRunBuffer(); 4875be168c0dSopenharmony_ci return RET_OK; 4876be168c0dSopenharmony_ci } 4877be168c0dSopenharmony_ci 4878be168c0dSopenharmony_ci+void StridedSliceGradCPUKernel::FreeRunBuffer() { 4879be168c0dSopenharmony_ci+ if (res_arr_ != nullptr) { 4880be168c0dSopenharmony_ci+ ms_context_->allocator->Free(res_arr_); 4881be168c0dSopenharmony_ci+ res_arr_ = nullptr; 4882be168c0dSopenharmony_ci+ } 4883be168c0dSopenharmony_ci+ if (temp_input_ != nullptr) { 4884be168c0dSopenharmony_ci+ ms_context_->allocator->Free(temp_input_); 4885be168c0dSopenharmony_ci+ temp_input_ = nullptr; 4886be168c0dSopenharmony_ci+ } 4887be168c0dSopenharmony_ci+ if (temp_ != nullptr) { 4888be168c0dSopenharmony_ci+ ms_context_->allocator->Free(temp_); 4889be168c0dSopenharmony_ci+ temp_ = nullptr; 4890be168c0dSopenharmony_ci+ } 4891be168c0dSopenharmony_ci+} 4892be168c0dSopenharmony_ci+ 4893be168c0dSopenharmony_ci REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_StridedSliceGrad, LiteKernelCreator<StridedSliceGradCPUKernel>) 4894be168c0dSopenharmony_ci } // namespace mindspore::kernel 4895be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.h b/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.h 4896be168c0dSopenharmony_ciindex 25d6f855..f34dd20d 100644 4897be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.h 4898be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/kernel/cpu/fp32_grad/strided_slice_grad.h 4899be168c0dSopenharmony_ci@@ -40,9 +40,14 @@ class StridedSliceGradCPUKernel : public LiteKernel { 4900be168c0dSopenharmony_ci void FillEmptyDims(); 4901be168c0dSopenharmony_ci void FillOutputDim(); 4902be168c0dSopenharmony_ci void ParseMasks(); 4903be168c0dSopenharmony_ci+ int CalStridedSliceGrad(float *input, float *output); 4904be168c0dSopenharmony_ci+ void FreeRunBuffer(); 4905be168c0dSopenharmony_ci 4906be168c0dSopenharmony_ci StridedSliceParameter *param_; 4907be168c0dSopenharmony_ci std::vector<int> output_shape_; 4908be168c0dSopenharmony_ci+ float *res_arr_ = nullptr; 4909be168c0dSopenharmony_ci+ float *temp_input_ = nullptr; 4910be168c0dSopenharmony_ci+ float *temp_ = nullptr; 4911be168c0dSopenharmony_ci }; 4912be168c0dSopenharmony_ci } // namespace mindspore::kernel 4913be168c0dSopenharmony_ci 4914be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/lite_model.cc b/mindspore/lite/src/litert/lite_model.cc 4915be168c0dSopenharmony_ciindex bcb9cb70..af9b1f8d 100644 4916be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/lite_model.cc 4917be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/lite_model.cc 4918be168c0dSopenharmony_ci@@ -66,7 +66,9 @@ void LiteModel::Free() { 4919be168c0dSopenharmony_ci node_bufs_.resize(0); 4920be168c0dSopenharmony_ci 4921be168c0dSopenharmony_ci for (auto *schema_tensor_wrapper : inner_all_tensors_) { 4922be168c0dSopenharmony_ci- delete schema_tensor_wrapper; 4923be168c0dSopenharmony_ci+ if (schema_tensor_wrapper != nullptr) { 4924be168c0dSopenharmony_ci+ delete schema_tensor_wrapper; 4925be168c0dSopenharmony_ci+ } 4926be168c0dSopenharmony_ci } 4927be168c0dSopenharmony_ci inner_all_tensors_.clear(); 4928be168c0dSopenharmony_ci 4929be168c0dSopenharmony_ci-- 4930be168c0dSopenharmony_ci2.17.1 4931be168c0dSopenharmony_ci 4932