From 551353a01bc269ac3a509b916bfe28499d1db714 Mon Sep 17 00:00:00 2001 From: chengfeng27 Date: Thu, 1 Aug 2024 20:49:49 +0800 Subject: [PATCH] remove recursive lock, which conflict with ffrt --- .../src/litert/cxx_api/model/model_impl.cc | 26 ------------------- .../src/litert/cxx_api/model/model_impl.h | 1 - 2 files changed, 27 deletions(-) diff --git a/mindspore/lite/src/litert/cxx_api/model/model_impl.cc b/mindspore/lite/src/litert/cxx_api/model/model_impl.cc index cacbf86e..6a73a927 100644 --- a/mindspore/lite/src/litert/cxx_api/model/model_impl.cc +++ b/mindspore/lite/src/litert/cxx_api/model/model_impl.cc @@ -161,7 +161,6 @@ bool ModelImpl::IsEnablePreInference() { #endif Status ModelImpl::Build(const void *model_data, size_t data_size, ModelType model_type, const std::shared_ptr &ms_context) { - std::lock_guard lock(mutex_); if (session_ != nullptr) { MS_LOG(ERROR) << "Model has been called Build"; return kLiteModelRebuild; @@ -207,7 +206,6 @@ Status ModelImpl::Build(const void *model_data, size_t data_size, ModelType mode Status ModelImpl::Build(const std::string &model_path, ModelType model_type, const std::shared_ptr &ms_context) { - std::lock_guard lock(mutex_); if (session_ != nullptr) { MS_LOG(ERROR) << "Model has been called Build"; return kLiteModelRebuild; @@ -243,7 +241,6 @@ Status ModelImpl::Build(const std::string &model_path, ModelType model_type, } Status ModelImpl::Build() { - std::lock_guard lock(mutex_); if (session_ != nullptr) { MS_LOG(ERROR) << "Model has been called Build"; return kLiteModelRebuild; @@ -357,7 +354,6 @@ Status ModelImpl::RunGraph(const MSKernelCallBack &before, const MSKernelCallBac bool ModelImpl::IsTrainModel() { return (graph_ && graph_->graph_data_ && graph_->graph_data_->IsTrainModel()); } Status ModelImpl::LoadConfig(const std::string &config_path) { - std::lock_guard lock(mutex_); if (session_ != nullptr) { MS_LOG(ERROR) << "Model has been called Build, please call LoadConfig before Build."; return kLiteError; @@ -380,7 +376,6 @@ Status ModelImpl::LoadConfig(const std::string &config_path) { } Status ModelImpl::UpdateConfig(const std::string §ion, const std::pair &config) { - std::lock_guard lock(mutex_); auto iter = config_info_.find(section); if (iter == config_info_.end()) { if (config_info_.size() >= kMaxSectionNum) { @@ -400,7 +395,6 @@ Status ModelImpl::UpdateConfig(const std::string §ion, const std::pair &inputs, std::vector *outputs, const MSKernelCallBack &before, const MSKernelCallBack &after) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -565,7 +559,6 @@ Status ModelImpl::Predict(const std::vector &inputs, std::vector lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -592,7 +585,6 @@ Status ModelImpl::Predict(const MSKernelCallBack &before, const MSKernelCallBack } std::vector ModelImpl::GetInputs() { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -617,7 +609,6 @@ std::vector ModelImpl::GetInputs() { } std::vector ModelImpl::GetOutputs() { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -655,7 +646,6 @@ std::vector ModelImpl::GetOutputs() { } std::vector ModelImpl::GetGradients() const { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -670,7 +660,6 @@ std::vector ModelImpl::GetGradients() const { } Status ModelImpl::ApplyGradients(const std::vector &gradients) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -699,7 +688,6 @@ Status ModelImpl::ApplyGradients(const std::vector &gradients) { } std::vector ModelImpl::GetFeatureMaps() const { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -714,7 +702,6 @@ std::vector ModelImpl::GetFeatureMaps() const { } std::vector ModelImpl::GetTrainableParams() const { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -729,7 +716,6 @@ std::vector ModelImpl::GetTrainableParams() const { } Status ModelImpl::UpdateFeatureMaps(const std::vector &new_weights) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -758,7 +744,6 @@ Status ModelImpl::UpdateFeatureMaps(const std::vector &new_weights) { } std::vector ModelImpl::GetOptimizerParams() const { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -773,7 +758,6 @@ std::vector ModelImpl::GetOptimizerParams() const { } Status ModelImpl::SetOptimizerParams(const std::vector ¶ms) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -802,7 +786,6 @@ Status ModelImpl::SetOptimizerParams(const std::vector ¶ms) { } MSTensor ModelImpl::GetInputByTensorName(const std::string &name) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return MSTensor(nullptr); @@ -822,7 +805,6 @@ MSTensor ModelImpl::GetInputByTensorName(const std::string &name) { } std::vector ModelImpl::GetOutputTensorNames() { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -831,7 +813,6 @@ std::vector ModelImpl::GetOutputTensorNames() { } MSTensor ModelImpl::GetOutputByTensorName(const std::string &name) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return MSTensor(nullptr); @@ -851,7 +832,6 @@ MSTensor ModelImpl::GetOutputByTensorName(const std::string &name) { } std::vector ModelImpl::GetOutputsByNodeName(const std::string &name) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return {}; @@ -881,7 +861,6 @@ std::vector ModelImpl::GetOutputsByNodeName(const std::string &name) { Status ModelImpl::BindGLTexture2DMemory(const std::map &inputGLTexture, std::map *outputGLTexture) { - std::lock_guard lock(mutex_); MS_LOG(INFO) << "Bind GLTexture2D to Input MsTensors and Output MsTensors"; if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; @@ -896,7 +875,6 @@ Status ModelImpl::BindGLTexture2DMemory(const std::map &inputs, const std::vector> &dims) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -950,7 +928,6 @@ Status ModelImpl::Resize(const std::vector &inputs, const std::vector< } Status ModelImpl::UpdateWeights(const std::vector &new_weights) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -982,7 +959,6 @@ Status ModelImpl::UpdateWeights(const std::vector &new_weights) { } Status ModelImpl::SetupVirtualBatch(int virtual_batch_multiplier, float lr, float momentum) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -992,7 +968,6 @@ Status ModelImpl::SetupVirtualBatch(int virtual_batch_multiplier, float lr, floa } Status ModelImpl::SetLearningRate(float learning_rate) { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(ERROR) << "Model has not been called Build, or Model Build has failed"; return kLiteNullptr; @@ -1002,7 +977,6 @@ Status ModelImpl::SetLearningRate(float learning_rate) { } float ModelImpl::GetLearningRate() { - std::lock_guard lock(mutex_); if (session_ == nullptr) { MS_LOG(WARNING) << "Model has not been called Build, or Model Build has failed"; return 0.0; diff --git a/mindspore/lite/src/litert/cxx_api/model/model_impl.h b/mindspore/lite/src/litert/cxx_api/model/model_impl.h index 8e11ee55..17cafba8 100644 --- a/mindspore/lite/src/litert/cxx_api/model/model_impl.h +++ b/mindspore/lite/src/litert/cxx_api/model/model_impl.h @@ -131,7 +131,6 @@ class ModelImpl { std::shared_ptr context_ = nullptr; std::shared_ptr cfg_ = nullptr; std::vector metrics_; - mutable std::recursive_mutex mutex_; void SetGraph(const std::shared_ptr &graph) { graph_ = graph; } void SetContext(const std::shared_ptr &context) { context_ = context; } void SetConfig(const std::shared_ptr cfg) { cfg_ = cfg; } -- 2.17.1