From e9a9786e9619b6fcb8637eaf1331829793ccc351 Mon Sep 17 00:00:00 2001 From: chengfeng27 Date: Thu, 12 Sep 2024 10:38:08 +0800 Subject: [PATCH] context nullptr return, remote std::cout --- .../nnacl/infer/sparse_segment_sum_infer.c | 1 - .../src/common/hi_app_event/handler_thread.cc | 5 ++-- mindspore/lite/src/litert/c_api/context_c.cc | 5 ++-- .../delegate/nnrt/extension_options_parser.cc | 3 ++- mindspore/lite/src/litert/inner_allocator.cc | 2 +- .../kernel/cpu/base/scatter_nd_binary.cc | 24 +++++++++++++++++-- mindspore/lite/src/litert/lite_session.cc | 1 - 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/infer/sparse_segment_sum_infer.c b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/infer/sparse_segment_sum_infer.c index 34069304..c8160bf6 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/infer/sparse_segment_sum_infer.c +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/infer/sparse_segment_sum_infer.c @@ -32,7 +32,6 @@ int SparseSegmentSumInferShape(const TensorC *const *inputs, size_t inputs_size, } return NNACL_INFER_INVALID; - // return NNACL_OK; } REG_INFER(SparseSegmentSum, PrimType_SparseSegmentSum, SparseSegmentSumInferShape) diff --git a/mindspore/lite/src/common/hi_app_event/handler_thread.cc b/mindspore/lite/src/common/hi_app_event/handler_thread.cc index a84504c0..1cf32bca 100644 --- a/mindspore/lite/src/common/hi_app_event/handler_thread.cc +++ b/mindspore/lite/src/common/hi_app_event/handler_thread.cc @@ -15,6 +15,7 @@ */ #include "handler_thread.h" +#include "src/common/log.h" namespace mindspore { namespace lite { @@ -121,8 +122,8 @@ public: bool HandlerThread::Post(std::string key, Runnable && aRunnable) { - if (not Running()) { - std::cout << "Denying insertion, as the looper is not running.\n"; + if (!Running()) { + MS_LOG(ERROR) << "Denying insertion, as the looper is not running."; return false; } diff --git a/mindspore/lite/src/litert/c_api/context_c.cc b/mindspore/lite/src/litert/c_api/context_c.cc index 5418c46a..92085960 100644 --- a/mindspore/lite/src/litert/c_api/context_c.cc +++ b/mindspore/lite/src/litert/c_api/context_c.cc @@ -41,6 +41,7 @@ OH_AI_ContextHandle OH_AI_ContextCreate() { if (impl->context_ == nullptr) { MS_LOG(ERROR) << "memory allocation failed."; delete impl; + return nullptr; } impl->owned_by_model_ = false; return static_cast(impl); @@ -536,8 +537,8 @@ OH_AI_API OH_AI_Status OH_AI_DeviceInfoAddExtension(OH_AI_DeviceInfoHandle devic return OH_AI_STATUS_LITE_ERROR; } static std::vector extension_keys = {"CachePath", "CacheVersion", "ModelName", "QuantBuffer", - "isProfiling", "opLayout", "InputDims", "DynamicDims", "BandMode", - "NPU_FM_SHARED"}; + "QuantConfigData", "isProfiling", "opLayout", "InputDims", + "DynamicDims", "BandMode", "NPU_FM_SHARED"}; auto it = std::find(extension_keys.begin(), extension_keys.end(), std::string(name)); if (it == extension_keys.end()) { MS_LOG(ERROR) << "The name of the extension is not allowable, only can be one of {CachePath, CacheVersion," diff --git a/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc b/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc index 6e4c57a4..b2a01592 100644 --- a/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc +++ b/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc @@ -30,6 +30,7 @@ const std::string kCachePath = "CachePath"; const std::string kCacheVersion = "CacheVersion"; const std::string kBandMode = "BandMode"; const std::string kQuantBuffer = "QuantBuffer"; +const std::string kQuantConfigData = "QuantConfigData"; const std::string kModelName = "ModelName"; } // namespace @@ -83,7 +84,7 @@ void ExtensionOptionsParser::DoParseQuantConfig(const std::vector &ex MS_CHECK_TRUE_RET_VOID(quant_config != nullptr); MS_CHECK_TRUE_RET_VOID(num != nullptr); auto iter_config = std::find_if(extensions.begin(), extensions.end(), [](const Extension &extension) { - return extension.name == kQuantBuffer; + return extension.name == kQuantBuffer || extension.name == kQuantConfigData; }); if (iter_config != extensions.end()) { *quant_config = static_cast(const_cast(iter_config->value.data())); diff --git a/mindspore/lite/src/litert/inner_allocator.cc b/mindspore/lite/src/litert/inner_allocator.cc index 9bd0c017..c80c7de9 100644 --- a/mindspore/lite/src/litert/inner_allocator.cc +++ b/mindspore/lite/src/litert/inner_allocator.cc @@ -54,11 +54,11 @@ void *DefaultAllocator::Malloc(size_t size) { MS_LOG(ERROR) << "MallocData out of max_size, size: " << size; return nullptr; } + Lock(); if (this->total_size_ >= max_malloc_size_) { MS_LOG(ERROR) << "Memory pool is exhausted"; return nullptr; } - Lock(); auto iter = freeList_.lower_bound(size); if (iter != freeList_.end() && ReuseMemory(iter->second->size, size)) { auto membuf = iter->second; diff --git a/mindspore/lite/src/litert/kernel/cpu/base/scatter_nd_binary.cc b/mindspore/lite/src/litert/kernel/cpu/base/scatter_nd_binary.cc index 0c98fedc..23e6b4cd 100644 --- a/mindspore/lite/src/litert/kernel/cpu/base/scatter_nd_binary.cc +++ b/mindspore/lite/src/litert/kernel/cpu/base/scatter_nd_binary.cc @@ -31,6 +31,14 @@ int ScatterNDBinaryCPUKernel::Prepare() { return ReSize(); } +/** + * ScatterND equation is like follows: + * + * output = np.copy(input) + * update_indices = indices.shape[:-1] + * for idx in np.ndindex(update_indices): + * output[indices[idx]] = updates[idx] + */ int ScatterNDBinaryCPUKernel::ReSize() { auto input = in_tensors_.at(kScatterUpdateInputIndex); auto indices = in_tensors_.at(kScatterIndicesIndex); @@ -90,7 +98,13 @@ int ScatterNDBinaryCPUKernel::ReSize() { for (int i = 0; i < param_->num_unit; i++) { int tmp_stride = 0; for (int j = 0; j < indices_unit_rank; j++) { - tmp_stride += indices_data[i * indices_unit_rank + j] * out_strides.at(j) * param_->unit_size; + int index = indices_data[i * indices_unit_rank + j]; + if ((index < -input_shape[j]) || (index >= input_shape[j])) { + MS_LOG(ERROR) << "illegal index: " << index << ", should in [" << -input_shape[j] << ", " << input_shape[j] + << ")"; + return RET_ERROR; + } + tmp_stride += index * out_strides.at(j) * param_->unit_size; } output_unit_offsets_.push_back(tmp_stride); } @@ -99,7 +113,13 @@ int ScatterNDBinaryCPUKernel::ReSize() { for (int i = 0; i < param_->num_unit; i++) { int tmp_stride = 0; for (int j = 0; j < indices_unit_rank; j++) { - tmp_stride += indices_data[i * indices_unit_rank + j] * out_strides.at(j) * param_->unit_size; + int64_t index = indices_data[i * indices_unit_rank + j]; + if ((index < -input_shape[j]) || (index >= input_shape[j])) { + MS_LOG(ERROR) << "illegal index: " << index << ", should in [" << -input_shape[j] << ", " << input_shape[j] + << ")"; + return RET_ERROR; + } + tmp_stride += index * out_strides.at(j) * param_->unit_size; } output_unit_offsets_.push_back(tmp_stride); } diff --git a/mindspore/lite/src/litert/lite_session.cc b/mindspore/lite/src/litert/lite_session.cc index 7502ec27..69c292e9 100644 --- a/mindspore/lite/src/litert/lite_session.cc +++ b/mindspore/lite/src/litert/lite_session.cc @@ -1104,7 +1104,6 @@ int LiteSession::CreateNNRTDelegate() { MS_LOG(ERROR) << "New NNRT delegate failed"; return RET_ERROR; } -// ((NNRTDelegate *)(delegate_.get()))->SetMetaGraph(this->model_->buf); delegate_device_type_ = DT_NNRT; this->context_->delegate = delegate_; #endif -- 2.17.1