1be168c0dSopenharmony_ciFrom e101f6e61047ccd0a7531f426de7ba837800da0a Mon Sep 17 00:00:00 2001 2be168c0dSopenharmony_ciFrom: rabbit-fgh <2955722401@qq.com> 3be168c0dSopenharmony_ciDate: Mon, 26 Aug 2024 11:55:13 +0800 4be168c0dSopenharmony_ciSubject: [PATCH] nullptr1 5be168c0dSopenharmony_ci 6be168c0dSopenharmony_cifix nullptr2 7be168c0dSopenharmony_ci--- 8be168c0dSopenharmony_ci mindspore/lite/mindir/src/mindir.cc | 163 ++++++++++-------- 9be168c0dSopenharmony_ci mindspore/lite/mindir/src/mindir_tensor.cc | 3 +- 10be168c0dSopenharmony_ci .../control_flow/kernel/identity_kernel.cc | 11 +- 11be168c0dSopenharmony_ci mindspore/lite/src/litert/c_api/model_c.cc | 11 ++ 12be168c0dSopenharmony_ci mindspore/lite/src/litert/cache_session.cc | 4 + 13be168c0dSopenharmony_ci .../lite/src/litert/cxx_api/model/model.cc | 12 +- 14be168c0dSopenharmony_ci mindspore/lite/src/litert/lite_mindrt.cc | 4 + 15be168c0dSopenharmony_ci .../lite/src/litert/pack_weight_manager.cc | 3 + 16be168c0dSopenharmony_ci .../cast_gather_reduce_fusion_pass.cc | 1 + 17be168c0dSopenharmony_ci .../reduce_concat_fusion_pass.cc | 1 + 18be168c0dSopenharmony_ci .../split_reduce_concat_fusion_pass.cc | 1 + 19be168c0dSopenharmony_ci mindspore/lite/src/litert/weight_decoder.cc | 2 + 20be168c0dSopenharmony_ci 12 files changed, 134 insertions(+), 82 deletions(-) 21be168c0dSopenharmony_ci 22be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/src/mindir.cc b/mindspore/lite/mindir/src/mindir.cc 23be168c0dSopenharmony_ciindex 39600e4d..93204fb8 100644 24be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/src/mindir.cc 25be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/src/mindir.cc 26be168c0dSopenharmony_ci@@ -37,13 +37,16 @@ PrimitivePtr MindIR_Activation_CreatePrimitive(ActivationType activation_type, f 27be168c0dSopenharmony_ci ActivationType MindIR_Activation_GetActivationType(ConstPrimitivePtr primitive) { 28be168c0dSopenharmony_ci if (primitive != nullptr) { 29be168c0dSopenharmony_ci auto prim = static_cast<const schema::Primitive *>(primitive); 30be168c0dSopenharmony_ci+ if (prim == nullptr) { 31be168c0dSopenharmony_ci+ ActivationType en = static_cast<ActivationType>(0); 32be168c0dSopenharmony_ci+ return en; 33be168c0dSopenharmony_ci+ } 34be168c0dSopenharmony_ci auto value = prim->value_as_Activation(); 35be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 36be168c0dSopenharmony_ci- return static_cast<ActivationType>(value->activation_type()); 37be168c0dSopenharmony_ci- } else { 38be168c0dSopenharmony_ci+ if (value == nullptr) { 39be168c0dSopenharmony_ci ActivationType en = static_cast<ActivationType>(0); 40be168c0dSopenharmony_ci return en; 41be168c0dSopenharmony_ci } 42be168c0dSopenharmony_ci+ return static_cast<ActivationType>(value->activation_type()); 43be168c0dSopenharmony_ci } else { 44be168c0dSopenharmony_ci ActivationType en = static_cast<ActivationType>(0); 45be168c0dSopenharmony_ci return en; 46be168c0dSopenharmony_ci@@ -53,30 +56,34 @@ ActivationType MindIR_Activation_GetActivationType(ConstPrimitivePtr primitive) 47be168c0dSopenharmony_ci void MindIR_Activation_SetActivationType(PrimitivePtr *primitive, ActivationType activation_type) { 48be168c0dSopenharmony_ci if (primitive != nullptr && *primitive != nullptr) { 49be168c0dSopenharmony_ci auto prim = static_cast<schema::Primitive *>(*primitive); 50be168c0dSopenharmony_ci- auto value = prim->value_as_Activation(); 51be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 52be168c0dSopenharmony_ci- flatbuffers::FlatBufferBuilder fbb; 53be168c0dSopenharmony_ci- auto ops_offset = 54be168c0dSopenharmony_ci- schema::CreateActivation(fbb, static_cast<schema::ActivationType>(activation_type), value->alpha(), 55be168c0dSopenharmony_ci- value->min_val(), value->max_val(), value->approximate()); 56be168c0dSopenharmony_ci- auto prim_offset = 57be168c0dSopenharmony_ci- schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 58be168c0dSopenharmony_ci- fbb.Finish(prim_offset); 59be168c0dSopenharmony_ci- auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 60be168c0dSopenharmony_ci- auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 61be168c0dSopenharmony_ci- *primitive = ret_value; 62be168c0dSopenharmony_ci+ if(prim != nullptr){ 63be168c0dSopenharmony_ci+ auto value = prim->value_as_Activation(); 64be168c0dSopenharmony_ci+ if (value != nullptr) { 65be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 66be168c0dSopenharmony_ci+ auto ops_offset = 67be168c0dSopenharmony_ci+ schema::CreateActivation(fbb, static_cast<schema::ActivationType>(activation_type), value->alpha(), 68be168c0dSopenharmony_ci+ value->min_val(), value->max_val(), value->approximate()); 69be168c0dSopenharmony_ci+ auto prim_offset = 70be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 71be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 72be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 73be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 74be168c0dSopenharmony_ci+ *primitive = ret_value; 75be168c0dSopenharmony_ci+ } 76be168c0dSopenharmony_ci } 77be168c0dSopenharmony_ci } 78be168c0dSopenharmony_ci } 79be168c0dSopenharmony_ci float MindIR_Activation_GetAlpha(ConstPrimitivePtr primitive) { 80be168c0dSopenharmony_ci if (primitive != nullptr) { 81be168c0dSopenharmony_ci auto prim = static_cast<const schema::Primitive *>(primitive); 82be168c0dSopenharmony_ci+ if(prim == nullptr){ 83be168c0dSopenharmony_ci+ return .0; 84be168c0dSopenharmony_ci+ } 85be168c0dSopenharmony_ci auto value = prim->value_as_Activation(); 86be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 87be168c0dSopenharmony_ci- return value->alpha(); 88be168c0dSopenharmony_ci- } else { 89be168c0dSopenharmony_ci+ if(value == nullptr){ 90be168c0dSopenharmony_ci return .0; 91be168c0dSopenharmony_ci } 92be168c0dSopenharmony_ci+ return value->alpha(); 93be168c0dSopenharmony_ci } else { 94be168c0dSopenharmony_ci return .0; 95be168c0dSopenharmony_ci } 96be168c0dSopenharmony_ci@@ -85,29 +92,33 @@ float MindIR_Activation_GetAlpha(ConstPrimitivePtr primitive) { 97be168c0dSopenharmony_ci void MindIR_Activation_SetAlpha(PrimitivePtr *primitive, float alpha) { 98be168c0dSopenharmony_ci if (primitive != nullptr && *primitive != nullptr) { 99be168c0dSopenharmony_ci auto prim = static_cast<schema::Primitive *>(*primitive); 100be168c0dSopenharmony_ci- auto value = prim->value_as_Activation(); 101be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 102be168c0dSopenharmony_ci- flatbuffers::FlatBufferBuilder fbb; 103be168c0dSopenharmony_ci- auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 104be168c0dSopenharmony_ci- alpha, value->min_val(), value->max_val(), value->approximate()); 105be168c0dSopenharmony_ci- auto prim_offset = 106be168c0dSopenharmony_ci- schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 107be168c0dSopenharmony_ci- fbb.Finish(prim_offset); 108be168c0dSopenharmony_ci- auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 109be168c0dSopenharmony_ci- auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 110be168c0dSopenharmony_ci- *primitive = ret_value; 111be168c0dSopenharmony_ci+ if(prim != nullptr){ 112be168c0dSopenharmony_ci+ auto value = prim->value_as_Activation(); 113be168c0dSopenharmony_ci+ if (value != nullptr) { 114be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 115be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 116be168c0dSopenharmony_ci+ alpha, value->min_val(), value->max_val(), value->approximate()); 117be168c0dSopenharmony_ci+ auto prim_offset = 118be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 119be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 120be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 121be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 122be168c0dSopenharmony_ci+ *primitive = ret_value; 123be168c0dSopenharmony_ci+ } 124be168c0dSopenharmony_ci } 125be168c0dSopenharmony_ci } 126be168c0dSopenharmony_ci } 127be168c0dSopenharmony_ci float MindIR_Activation_GetMinVal(ConstPrimitivePtr primitive) { 128be168c0dSopenharmony_ci if (primitive != nullptr) { 129be168c0dSopenharmony_ci auto prim = static_cast<const schema::Primitive *>(primitive); 130be168c0dSopenharmony_ci+ if(prim == nullptr){ 131be168c0dSopenharmony_ci+ return .0; 132be168c0dSopenharmony_ci+ } 133be168c0dSopenharmony_ci auto value = prim->value_as_Activation(); 134be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 135be168c0dSopenharmony_ci- return value->min_val(); 136be168c0dSopenharmony_ci- } else { 137be168c0dSopenharmony_ci+ if(value == nullptr){ 138be168c0dSopenharmony_ci return .0; 139be168c0dSopenharmony_ci } 140be168c0dSopenharmony_ci+ return value->min_val(); 141be168c0dSopenharmony_ci } else { 142be168c0dSopenharmony_ci return .0; 143be168c0dSopenharmony_ci } 144be168c0dSopenharmony_ci@@ -116,29 +127,33 @@ float MindIR_Activation_GetMinVal(ConstPrimitivePtr primitive) { 145be168c0dSopenharmony_ci void MindIR_Activation_SetMinVal(PrimitivePtr *primitive, float min_val) { 146be168c0dSopenharmony_ci if (primitive != nullptr && *primitive != nullptr) { 147be168c0dSopenharmony_ci auto prim = static_cast<schema::Primitive *>(*primitive); 148be168c0dSopenharmony_ci- auto value = prim->value_as_Activation(); 149be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 150be168c0dSopenharmony_ci- flatbuffers::FlatBufferBuilder fbb; 151be168c0dSopenharmony_ci- auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 152be168c0dSopenharmony_ci- value->alpha(), min_val, value->max_val(), value->approximate()); 153be168c0dSopenharmony_ci- auto prim_offset = 154be168c0dSopenharmony_ci- schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 155be168c0dSopenharmony_ci- fbb.Finish(prim_offset); 156be168c0dSopenharmony_ci- auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 157be168c0dSopenharmony_ci- auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 158be168c0dSopenharmony_ci- *primitive = ret_value; 159be168c0dSopenharmony_ci+ if(prim != nullptr){ 160be168c0dSopenharmony_ci+ auto value = prim->value_as_Activation(); 161be168c0dSopenharmony_ci+ if (value != nullptr) { 162be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 163be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 164be168c0dSopenharmony_ci+ value->alpha(), min_val, value->max_val(), value->approximate()); 165be168c0dSopenharmony_ci+ auto prim_offset = 166be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 167be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 168be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 169be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 170be168c0dSopenharmony_ci+ *primitive = ret_value; 171be168c0dSopenharmony_ci+ } 172be168c0dSopenharmony_ci } 173be168c0dSopenharmony_ci } 174be168c0dSopenharmony_ci } 175be168c0dSopenharmony_ci float MindIR_Activation_GetMaxVal(ConstPrimitivePtr primitive) { 176be168c0dSopenharmony_ci if (primitive != nullptr) { 177be168c0dSopenharmony_ci auto prim = static_cast<const schema::Primitive *>(primitive); 178be168c0dSopenharmony_ci+ if(prim == nullptr){ 179be168c0dSopenharmony_ci+ return .0; 180be168c0dSopenharmony_ci+ } 181be168c0dSopenharmony_ci auto value = prim->value_as_Activation(); 182be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 183be168c0dSopenharmony_ci- return value->max_val(); 184be168c0dSopenharmony_ci- } else { 185be168c0dSopenharmony_ci+ if(value == nullptr){ 186be168c0dSopenharmony_ci return .0; 187be168c0dSopenharmony_ci } 188be168c0dSopenharmony_ci+ return value->max_val(); 189be168c0dSopenharmony_ci } else { 190be168c0dSopenharmony_ci return .0; 191be168c0dSopenharmony_ci } 192be168c0dSopenharmony_ci@@ -147,29 +162,33 @@ float MindIR_Activation_GetMaxVal(ConstPrimitivePtr primitive) { 193be168c0dSopenharmony_ci void MindIR_Activation_SetMaxVal(PrimitivePtr *primitive, float max_val) { 194be168c0dSopenharmony_ci if (primitive != nullptr && *primitive != nullptr) { 195be168c0dSopenharmony_ci auto prim = static_cast<schema::Primitive *>(*primitive); 196be168c0dSopenharmony_ci- auto value = prim->value_as_Activation(); 197be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 198be168c0dSopenharmony_ci- flatbuffers::FlatBufferBuilder fbb; 199be168c0dSopenharmony_ci- auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 200be168c0dSopenharmony_ci- value->alpha(), value->min_val(), max_val, value->approximate()); 201be168c0dSopenharmony_ci- auto prim_offset = 202be168c0dSopenharmony_ci- schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 203be168c0dSopenharmony_ci- fbb.Finish(prim_offset); 204be168c0dSopenharmony_ci- auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 205be168c0dSopenharmony_ci- auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 206be168c0dSopenharmony_ci- *primitive = ret_value; 207be168c0dSopenharmony_ci+ if(prim != nullptr){ 208be168c0dSopenharmony_ci+ auto value = prim->value_as_Activation(); 209be168c0dSopenharmony_ci+ if (value != nullptr) { 210be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 211be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 212be168c0dSopenharmony_ci+ value->alpha(), value->min_val(), max_val, value->approximate()); 213be168c0dSopenharmony_ci+ auto prim_offset = 214be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 215be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 216be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 217be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 218be168c0dSopenharmony_ci+ *primitive = ret_value; 219be168c0dSopenharmony_ci+ } 220be168c0dSopenharmony_ci } 221be168c0dSopenharmony_ci } 222be168c0dSopenharmony_ci } 223be168c0dSopenharmony_ci bool MindIR_Activation_GetApproximate(ConstPrimitivePtr primitive) { 224be168c0dSopenharmony_ci if (primitive != nullptr) { 225be168c0dSopenharmony_ci auto prim = static_cast<const schema::Primitive *>(primitive); 226be168c0dSopenharmony_ci+ if(prim == nullptr){ 227be168c0dSopenharmony_ci+ return false; 228be168c0dSopenharmony_ci+ } 229be168c0dSopenharmony_ci auto value = prim->value_as_Activation(); 230be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 231be168c0dSopenharmony_ci- return value->approximate(); 232be168c0dSopenharmony_ci- } else { 233be168c0dSopenharmony_ci+ if(value == nullptr){ 234be168c0dSopenharmony_ci return false; 235be168c0dSopenharmony_ci } 236be168c0dSopenharmony_ci+ return value->approximate(); 237be168c0dSopenharmony_ci } else { 238be168c0dSopenharmony_ci return false; 239be168c0dSopenharmony_ci } 240be168c0dSopenharmony_ci@@ -178,17 +197,19 @@ bool MindIR_Activation_GetApproximate(ConstPrimitivePtr primitive) { 241be168c0dSopenharmony_ci void MindIR_Activation_SetApproximate(PrimitivePtr *primitive, bool approximate) { 242be168c0dSopenharmony_ci if (primitive != nullptr && *primitive != nullptr) { 243be168c0dSopenharmony_ci auto prim = static_cast<schema::Primitive *>(*primitive); 244be168c0dSopenharmony_ci- auto value = prim->value_as_Activation(); 245be168c0dSopenharmony_ci- if (prim != nullptr && value != nullptr) { 246be168c0dSopenharmony_ci- flatbuffers::FlatBufferBuilder fbb; 247be168c0dSopenharmony_ci- auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 248be168c0dSopenharmony_ci- value->alpha(), value->min_val(), value->max_val(), approximate); 249be168c0dSopenharmony_ci- auto prim_offset = 250be168c0dSopenharmony_ci- schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 251be168c0dSopenharmony_ci- fbb.Finish(prim_offset); 252be168c0dSopenharmony_ci- auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 253be168c0dSopenharmony_ci- auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 254be168c0dSopenharmony_ci- *primitive = ret_value; 255be168c0dSopenharmony_ci+ if(prim != nullptr){ 256be168c0dSopenharmony_ci+ auto value = prim->value_as_Activation(); 257be168c0dSopenharmony_ci+ if (value != nullptr) { 258be168c0dSopenharmony_ci+ flatbuffers::FlatBufferBuilder fbb; 259be168c0dSopenharmony_ci+ auto ops_offset = schema::CreateActivation(fbb, static_cast<schema::ActivationType>(value->activation_type()), 260be168c0dSopenharmony_ci+ value->alpha(), value->min_val(), value->max_val(), approximate); 261be168c0dSopenharmony_ci+ auto prim_offset = 262be168c0dSopenharmony_ci+ schema::CreatePrimitive(fbb, static_cast<schema::PrimitiveType>(NODE_TYPE_ACTIVATION), ops_offset.o); 263be168c0dSopenharmony_ci+ fbb.Finish(prim_offset); 264be168c0dSopenharmony_ci+ auto new_addr = MindIRMemoryManager::GetInstance()->CreatePrimitiveFromBuilder(fbb, prim); 265be168c0dSopenharmony_ci+ auto ret_value = flatbuffers::GetMutableRoot<schema::Primitive>(new_addr); 266be168c0dSopenharmony_ci+ *primitive = ret_value; 267be168c0dSopenharmony_ci+ } 268be168c0dSopenharmony_ci } 269be168c0dSopenharmony_ci } 270be168c0dSopenharmony_ci } 271be168c0dSopenharmony_cidiff --git a/mindspore/lite/mindir/src/mindir_tensor.cc b/mindspore/lite/mindir/src/mindir_tensor.cc 272be168c0dSopenharmony_ciindex 0e6a631e..c7dd19b2 100644 273be168c0dSopenharmony_ci--- a/mindspore/lite/mindir/src/mindir_tensor.cc 274be168c0dSopenharmony_ci+++ b/mindspore/lite/mindir/src/mindir_tensor.cc 275be168c0dSopenharmony_ci@@ -54,7 +54,7 @@ TensorPtr MindIR_Tensor_Create(const char *name, DataType data_type, const int32 276be168c0dSopenharmony_ci std::string MindIR_Tensor_GetName(ConstTensorPtr tensor) { 277be168c0dSopenharmony_ci if (tensor != nullptr) { 278be168c0dSopenharmony_ci auto value = static_cast<const schema::Tensor *>(tensor); 279be168c0dSopenharmony_ci- if (value != nullptr) { 280be168c0dSopenharmony_ci+ if (value != nullptr && value->name() != nullptr) { 281be168c0dSopenharmony_ci return value->name()->str(); 282be168c0dSopenharmony_ci } else { 283be168c0dSopenharmony_ci return ""; 284be168c0dSopenharmony_ci@@ -360,7 +360,6 @@ void MindIR_Tensor_Destroy(TensorPtr *tensor) { 285be168c0dSopenharmony_ci MindIRMemoryManager::GetInstance()->DeleteTensor(schema); 286be168c0dSopenharmony_ci *tensor = nullptr; 287be168c0dSopenharmony_ci } 288be168c0dSopenharmony_ci- *tensor = nullptr; 289be168c0dSopenharmony_ci } 290be168c0dSopenharmony_ci } // namespace lite 291be168c0dSopenharmony_ci } // namespace mindspore 292be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/control_flow/kernel/identity_kernel.cc b/mindspore/lite/src/control_flow/kernel/identity_kernel.cc 293be168c0dSopenharmony_ciindex a43a5caf..21ef3808 100644 294be168c0dSopenharmony_ci--- a/mindspore/lite/src/control_flow/kernel/identity_kernel.cc 295be168c0dSopenharmony_ci+++ b/mindspore/lite/src/control_flow/kernel/identity_kernel.cc 296be168c0dSopenharmony_ci@@ -99,8 +99,13 @@ KernelExec *IdentityKernel::Create(std::vector<lite::Tensor *> in_tensors, std:: 297be168c0dSopenharmony_ci auto lite_kernel = new IdentityKernel(param, in_tensors, out_tensors, ctx); 298be168c0dSopenharmony_ci MS_CHECK_TRUE_MSG(lite_kernel != nullptr, nullptr, "new inner kernel failed."); 299be168c0dSopenharmony_ci std::shared_ptr<kernel::Kernel> shared_kernel(lite_kernel); 300be168c0dSopenharmony_ci- auto *kernel_exec = new KernelExec(shared_kernel); 301be168c0dSopenharmony_ci- kernel_exec->set_context(ctx); 302be168c0dSopenharmony_ci- return kernel_exec; 303be168c0dSopenharmony_ci+ if(shared_kernel != nullptr){ 304be168c0dSopenharmony_ci+ auto *kernel_exec = new KernelExec(shared_kernel); 305be168c0dSopenharmony_ci+ kernel_exec->set_context(ctx); 306be168c0dSopenharmony_ci+ return kernel_exec; 307be168c0dSopenharmony_ci+ } else { 308be168c0dSopenharmony_ci+ MS_LOG(ERROR) << "malloc shared_kernel failed."; 309be168c0dSopenharmony_ci+ return nullptr; 310be168c0dSopenharmony_ci+ } 311be168c0dSopenharmony_ci } 312be168c0dSopenharmony_ci } // namespace mindspore::kernel 313be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/c_api/model_c.cc b/mindspore/lite/src/litert/c_api/model_c.cc 314be168c0dSopenharmony_ciindex 4f40b3d3..661a8d06 100644 315be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/c_api/model_c.cc 316be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/c_api/model_c.cc 317be168c0dSopenharmony_ci@@ -385,6 +385,13 @@ char **OH_AI_TrainCfgGetLossName(OH_AI_TrainCfgHandle train_cfg, size_t *num) { 318be168c0dSopenharmony_ci } 319be168c0dSopenharmony_ci for (size_t i = 0; i < loss_name.size(); i++) { 320be168c0dSopenharmony_ci name[i] = static_cast<char *>(malloc(loss_name[i].size() + 1)); 321be168c0dSopenharmony_ci+ if (name[i] == nullptr) { 322be168c0dSopenharmony_ci+ for(size_t j = 0; j < i; j++){ 323be168c0dSopenharmony_ci+ free(name[j]); 324be168c0dSopenharmony_ci+ } 325be168c0dSopenharmony_ci+ MS_LOG(ERROR) << "Failed to malloc name."; 326be168c0dSopenharmony_ci+ return nullptr; 327be168c0dSopenharmony_ci+ } 328be168c0dSopenharmony_ci strcpy(name[i], loss_name[i].c_str()); 329be168c0dSopenharmony_ci } 330be168c0dSopenharmony_ci return name; 331be168c0dSopenharmony_ci@@ -618,6 +625,10 @@ OH_AI_Status OH_AI_ExportModelBuffer(OH_AI_ModelHandle model, OH_AI_ModelType mo 332be168c0dSopenharmony_ci export_inference_only, tensor_name); 333be168c0dSopenharmony_ci auto data = static_cast<char *>(buffer.MutableData()); 334be168c0dSopenharmony_ci *model_data = (char *) malloc(buffer.DataSize()); 335be168c0dSopenharmony_ci+ if (*model_data == nullptr) { 336be168c0dSopenharmony_ci+ MS_LOG(ERROR) << "*model_data is nullptr."; 337be168c0dSopenharmony_ci+ return OH_AI_STATUS_LITE_NULLPTR; 338be168c0dSopenharmony_ci+ } 339be168c0dSopenharmony_ci *data_size = buffer.DataSize(); 340be168c0dSopenharmony_ci memcpy(*model_data, data, buffer.DataSize()); 341be168c0dSopenharmony_ci if (!ret.IsOk()) { 342be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/cache_session.cc b/mindspore/lite/src/litert/cache_session.cc 343be168c0dSopenharmony_ciindex 7bafe3f7..e128c933 100644 344be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/cache_session.cc 345be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/cache_session.cc 346be168c0dSopenharmony_ci@@ -209,6 +209,10 @@ int CacheSession::LoadModelAndCompileByPath(const std::string &model_path, minds 347be168c0dSopenharmony_ci return RET_ERROR; 348be168c0dSopenharmony_ci } else { 349be168c0dSopenharmony_ci model = ImportInOutFromBuffer(model_buf, model_size, true, model_type, model_path); 350be168c0dSopenharmony_ci+ if (model == nullptr) { 351be168c0dSopenharmony_ci+ MS_LOG(ERROR) << "Import model failed"; 352be168c0dSopenharmony_ci+ return RET_ERROR; 353be168c0dSopenharmony_ci+ } 354be168c0dSopenharmony_ci dynamic_cast<LiteModel *>(model)->PrepareInnerTensors(); 355be168c0dSopenharmony_ci } 356be168c0dSopenharmony_ci if (model == nullptr) { 357be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/cxx_api/model/model.cc b/mindspore/lite/src/litert/cxx_api/model/model.cc 358be168c0dSopenharmony_ciindex 2814da41..282c752e 100644 359be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/cxx_api/model/model.cc 360be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/cxx_api/model/model.cc 361be168c0dSopenharmony_ci@@ -297,6 +297,12 @@ Status Model::Build(const std::vector<char> &model_path, ModelType model_type, 362be168c0dSopenharmony_ci 363be168c0dSopenharmony_ci Status Model::Build(GraphCell graph, const std::shared_ptr<Context> &model_context, 364be168c0dSopenharmony_ci const std::shared_ptr<TrainCfg> &train_cfg) { 365be168c0dSopenharmony_ci+std::stringstream err_msg; 366be168c0dSopenharmony_ci+if (model_context == nullptr) { 367be168c0dSopenharmony_ci+ err_msg << "Invalid null context."; 368be168c0dSopenharmony_ci+ MS_LOG(ERROR) << err_msg.str(); 369be168c0dSopenharmony_ci+ return Status(kLiteNullptr, err_msg.str()); 370be168c0dSopenharmony_ci+} 371be168c0dSopenharmony_ci #ifdef ENABLE_HI_APP_EVENT 372be168c0dSopenharmony_ci uint64_t begin_time = mindspore::lite::HiAppEventConfig::GetInstance()->GetTimeMs(); 373be168c0dSopenharmony_ci std::string devices; 374be168c0dSopenharmony_ci@@ -304,7 +310,6 @@ Status Model::Build(GraphCell graph, const std::shared_ptr<Context> &model_conte 375be168c0dSopenharmony_ci devices += std::to_string(device->GetDeviceType()) + " "; 376be168c0dSopenharmony_ci } 377be168c0dSopenharmony_ci #endif 378be168c0dSopenharmony_ci- std::stringstream err_msg; 379be168c0dSopenharmony_ci if (impl_ == nullptr) { 380be168c0dSopenharmony_ci MS_LOG(ERROR) << "Model implement is null."; 381be168c0dSopenharmony_ci return kLiteNullptr; 382be168c0dSopenharmony_ci@@ -315,11 +320,6 @@ Status Model::Build(GraphCell graph, const std::shared_ptr<Context> &model_conte 383be168c0dSopenharmony_ci MS_LOG(ERROR) << err_msg.str(); 384be168c0dSopenharmony_ci return Status(kLiteNullptr, err_msg.str()); 385be168c0dSopenharmony_ci } 386be168c0dSopenharmony_ci- if (model_context == nullptr) { 387be168c0dSopenharmony_ci- err_msg << "Invalid null context."; 388be168c0dSopenharmony_ci- MS_LOG(ERROR) << err_msg.str(); 389be168c0dSopenharmony_ci- return Status(kLiteNullptr, err_msg.str()); 390be168c0dSopenharmony_ci- } 391be168c0dSopenharmony_ci #if defined(ENABLE_PRE_INFERENCE) && defined(__linux__) && !defined(Debug) 392be168c0dSopenharmony_ci if (lite::GetNumThreads() == lite::kSingleThread && impl_->IsEnablePreInference()) { 393be168c0dSopenharmony_ci pid_t pid = fork(); 394be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/lite_mindrt.cc b/mindspore/lite/src/litert/lite_mindrt.cc 395be168c0dSopenharmony_ciindex fe7b64f2..4d1b4ba6 100644 396be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/lite_mindrt.cc 397be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/lite_mindrt.cc 398be168c0dSopenharmony_ci@@ -106,6 +106,10 @@ int LiteOpActor::IsolateInputData(std::vector<std::shared_ptr<LiteOpActor>> *act 399be168c0dSopenharmony_ci old_tensor->set_data_type(kernel_->desc().data_type); 400be168c0dSopenharmony_ci } 401be168c0dSopenharmony_ci SetTensorListTensorDataType(kernel_->desc().data_type, old_tensor); 402be168c0dSopenharmony_ci+ if (kernel_->Context() == nullptr) { 403be168c0dSopenharmony_ci+ MS_LOG(ERROR) << "kernel_->Context() is nullptr."; 404be168c0dSopenharmony_ci+ return RET_NULL_PTR; 405be168c0dSopenharmony_ci+ } 406be168c0dSopenharmony_ci old_tensor->set_allocator(kernel_->Context()->allocator); 407be168c0dSopenharmony_ci continue; 408be168c0dSopenharmony_ci } 409be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/pack_weight_manager.cc b/mindspore/lite/src/litert/pack_weight_manager.cc 410be168c0dSopenharmony_ciindex 09f4e4b4..554bf4dc 100644 411be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/pack_weight_manager.cc 412be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/pack_weight_manager.cc 413be168c0dSopenharmony_ci@@ -264,6 +264,9 @@ void PackWeightManager::FreePackWeight(std::string runner_id, std::string model_ 414be168c0dSopenharmony_ci MS_LOG(INFO) << "free pack weight of runner id: " << runner_id; 415be168c0dSopenharmony_ci pack_weight_->FreePackWeight(runner_id); 416be168c0dSopenharmony_ci } 417be168c0dSopenharmony_ci+ } else { 418be168c0dSopenharmony_ci+ MS_LOG(INFO) << "pack_weight_ is nullptr."; 419be168c0dSopenharmony_ci+ return; 420be168c0dSopenharmony_ci } 421be168c0dSopenharmony_ci if (model_id.empty()) { 422be168c0dSopenharmony_ci MS_LOG(INFO) << "model id is empty."; 423be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/pass/online_fusion/cast_gather_reduce_fusion_pass.cc b/mindspore/lite/src/litert/pass/online_fusion/cast_gather_reduce_fusion_pass.cc 424be168c0dSopenharmony_ciindex 4892292c..00186dc7 100644 425be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/pass/online_fusion/cast_gather_reduce_fusion_pass.cc 426be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/pass/online_fusion/cast_gather_reduce_fusion_pass.cc 427be168c0dSopenharmony_ci@@ -127,6 +127,7 @@ int CastGatherReduceOnlineFusionPass::CreateCastGatherReduceCustomNode(LiteGraph 428be168c0dSopenharmony_ci (void)memcpy(prim, fbb.GetBufferPointer(), fbb.GetSize()); 429be168c0dSopenharmony_ci auto online_fusion_prim = flatbuffers::GetRoot<schema::Primitive>(prim); 430be168c0dSopenharmony_ci if (online_fusion_prim == nullptr) { 431be168c0dSopenharmony_ci+ free(prim) 432be168c0dSopenharmony_ci MS_LOG(ERROR) << "GetRoot CastGatherReduceFusion primitive failed."; 433be168c0dSopenharmony_ci return RET_ERROR; 434be168c0dSopenharmony_ci } 435be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/pass/online_fusion/reduce_concat_fusion_pass.cc b/mindspore/lite/src/litert/pass/online_fusion/reduce_concat_fusion_pass.cc 436be168c0dSopenharmony_ciindex 5cfec79b..21115cc5 100644 437be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/pass/online_fusion/reduce_concat_fusion_pass.cc 438be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/pass/online_fusion/reduce_concat_fusion_pass.cc 439be168c0dSopenharmony_ci@@ -135,6 +135,7 @@ int ReduceConcatOnlineFusionPass::CreateReduceConcatCustomNode(LiteGraph::Node * 440be168c0dSopenharmony_ci (void)memcpy(prim, fbb.GetBufferPointer(), fbb.GetSize()); 441be168c0dSopenharmony_ci auto online_fusion_prim = flatbuffers::GetRoot<schema::Primitive>(prim); 442be168c0dSopenharmony_ci if (online_fusion_prim == nullptr) { 443be168c0dSopenharmony_ci+ free(prim) 444be168c0dSopenharmony_ci MS_LOG(ERROR) << "GetRoot ReduceConcatFusion primitive failed."; 445be168c0dSopenharmony_ci return RET_ERROR; 446be168c0dSopenharmony_ci } 447be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/pass/online_fusion/split_reduce_concat_fusion_pass.cc b/mindspore/lite/src/litert/pass/online_fusion/split_reduce_concat_fusion_pass.cc 448be168c0dSopenharmony_ciindex e6f1353f..f9a08a04 100644 449be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/pass/online_fusion/split_reduce_concat_fusion_pass.cc 450be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/pass/online_fusion/split_reduce_concat_fusion_pass.cc 451be168c0dSopenharmony_ci@@ -233,6 +233,7 @@ int SplitReduceConcatOnlineFusionPass::CreateCustomNode(LiteGraph::Node *node, S 452be168c0dSopenharmony_ci (void)memcpy(prim, fbb.GetBufferPointer(), fbb.GetSize()); 453be168c0dSopenharmony_ci auto online_fusion_prim = flatbuffers::GetRoot<schema::Primitive>(prim); 454be168c0dSopenharmony_ci if (online_fusion_prim == nullptr) { 455be168c0dSopenharmony_ci+ free(prim) 456be168c0dSopenharmony_ci MS_LOG(ERROR) << "GetRoot SplitReduceConcatFusion primitive failed."; 457be168c0dSopenharmony_ci return RET_ERROR; 458be168c0dSopenharmony_ci } 459be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/weight_decoder.cc b/mindspore/lite/src/litert/weight_decoder.cc 460be168c0dSopenharmony_ciindex d851ea1f..7872b83f 100644 461be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/weight_decoder.cc 462be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/weight_decoder.cc 463be168c0dSopenharmony_ci@@ -177,6 +177,8 @@ int WeightDecoder::UnPackToInt(const SchemaTensorWrapper &src_tensor, lite::Tens 464be168c0dSopenharmony_ci int WeightDecoder::UnPack(const SchemaTensorWrapper &src_tensor, lite::Tensor *dst_tensor) { 465be168c0dSopenharmony_ci MS_ASSERT(src_tensor.handler() != nullptr); 466be168c0dSopenharmony_ci MS_ASSERT(src_tensor.data() != nullptr); 467be168c0dSopenharmony_ci+ MS_CHECK_TRUE_MSG(src_tensor.handler()->dims() != nullptr, RET_ERROR, "dims is nullptr"); 468be168c0dSopenharmony_ci+ MS_CHECK_TRUE_MSG(src_tensor.handler()->name() != nullptr, RET_ERROR, "name is nullptr"); 469be168c0dSopenharmony_ci STATUS ret = RET_OK; 470be168c0dSopenharmony_ci if (src_tensor.handler()->enableHuffmanCode()) { 471be168c0dSopenharmony_ci ret = WeightDecoder::DecodeHuffmanCode(src_tensor, dst_tensor); 472be168c0dSopenharmony_ci-- 473be168c0dSopenharmony_ci2.45.1.windows.1 474be168c0dSopenharmony_ci 475