From fb3addf4c527f207d534fdacf9c14ee9ae3a1d11 Mon Sep 17 00:00:00 2001 From: zhengyuanhua Date: Fri, 26 Aug 2022 09:51:00 +0800 Subject: [PATCH] ascend infer code review --- mindspore/lite/src/extendrt/cxx_api/model/model_impl.cc | 3 +++ mindspore/lite/src/extendrt/infer_session.cc | 1 + .../src/extendrt/kernel/ascend/src/custom_ascend_kernel.cc | 4 ++++ mindspore/lite/src/extendrt/single_op_session.cc | 4 ++++ mindspore/lite/test/st/scripts/base_functions.sh | 2 +- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mindspore/lite/src/extendrt/cxx_api/model/model_impl.cc b/mindspore/lite/src/extendrt/cxx_api/model/model_impl.cc index 893457a263f..778773f4429 100644 --- a/mindspore/lite/src/extendrt/cxx_api/model/model_impl.cc +++ b/mindspore/lite/src/extendrt/cxx_api/model/model_impl.cc @@ -28,14 +28,17 @@ Status ModelImpl::Build(const void *model_data, size_t data_size, ModelType mode graph_ = std::make_shared(); auto ret = Serialization::Load(model_data, data_size, model_type, graph_.get()); if (ret != kSuccess) { + MS_LOG(ERROR) << "Serialization::Load model failed."; return ret; } session_ = InferSession::CreateSession(model_context); if (session_ == nullptr) { + MS_LOG(ERROR) << "Create session failed."; return kLiteNullptr; } ret = session_->Init(model_context); if (ret != kSuccess) { + MS_LOG(ERROR) << "Init session failed."; return ret; } if (MsContext::GetInstance() == nullptr) { diff --git a/mindspore/lite/src/extendrt/infer_session.cc b/mindspore/lite/src/extendrt/infer_session.cc index 3f8f706a97c..e902b4d0dbd 100644 --- a/mindspore/lite/src/extendrt/infer_session.cc +++ b/mindspore/lite/src/extendrt/infer_session.cc @@ -88,6 +88,7 @@ tensor::TensorPtr DefaultInferSession::GetInputByTensorName(const std::string &n std::shared_ptr InferSession::CreateSession(const std::shared_ptr context) { HandleGPUContext(context); auto config = SelectSessionArg(context); + MS_LOG(DEBUG) << "Session type " << static_cast(config.type_); return SessionRegistry::GetInstance().GetSession(config.type_, config); } diff --git a/mindspore/lite/src/extendrt/kernel/ascend/src/custom_ascend_kernel.cc b/mindspore/lite/src/extendrt/kernel/ascend/src/custom_ascend_kernel.cc index a25e9cc82f7..e020ebf34bc 100644 --- a/mindspore/lite/src/extendrt/kernel/ascend/src/custom_ascend_kernel.cc +++ b/mindspore/lite/src/extendrt/kernel/ascend/src/custom_ascend_kernel.cc @@ -163,6 +163,10 @@ int CustomAscendKernelMod::Resize(const BaseOperatorPtr &base_operator, const st return lite::RET_ERROR; } } + if (inputs.size() < 1) { + MS_LOG(ERROR) << "inputs size is less than one."; + return lite::RET_ERROR; + } inputs_.assign(inputs.begin(), inputs.end() - 1); return lite::RET_OK; } diff --git a/mindspore/lite/src/extendrt/single_op_session.cc b/mindspore/lite/src/extendrt/single_op_session.cc index 6abfd005ad7..3b4236a7aac 100644 --- a/mindspore/lite/src/extendrt/single_op_session.cc +++ b/mindspore/lite/src/extendrt/single_op_session.cc @@ -219,6 +219,10 @@ Status SingleOpInferSession::ResizeGraphInputs(const std::vectorset_shape(dims[i]); auto abstract = std::make_shared(TypeIdToType(type_id), dims[i]); + if (abstract == nullptr) { + MS_LOG(ERROR) << "Abstract is nullptr."; + return kLiteError; + } graph_input->set_abstract(abstract); } return kSuccess; diff --git a/mindspore/lite/test/st/scripts/base_functions.sh b/mindspore/lite/test/st/scripts/base_functions.sh index 67a6a141636..46a9d727340 100644 --- a/mindspore/lite/test/st/scripts/base_functions.sh +++ b/mindspore/lite/test/st/scripts/base_functions.sh @@ -132,7 +132,7 @@ function Convert() { if [ $? = 0 ]; then converter_result='converter '${model_type}''${quant_type}' '${model_name}' pass';echo ${converter_result} >> $5 local model_size - if [[ ${export_mindir} =~ "MINDIR" ]]; then + if [ "${export_mindir}"x == "MINDIR"x ]; then model_size=`ls ${output_file}.mindir -l|awk -F ' ' '{print $5}'` else model_size=`ls ${output_file}.ms -l|awk -F ' ' '{print $5}'`