diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 3dadbe2f582..4f7a9b2226d 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -81,7 +81,6 @@ include_directories(${CCSRC_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm) include_directories(${TOP_DIR}/third_party) -include_directories(${TOP_DIR}/third_party/flatbuffers/include) include_directories(${CMAKE_BINARY_DIR}) include(${TOP_DIR}/cmake/utils.cmake) diff --git a/mindspore/lite/include/lite_session.h b/mindspore/lite/include/lite_session.h index 515c4b27327..2139fb9e1e0 100644 --- a/mindspore/lite/include/lite_session.h +++ b/mindspore/lite/include/lite_session.h @@ -27,16 +27,6 @@ namespace mindspore { namespace session { -/// \brief CallBackParam defined input arguments for callBack function. -struct CallBackParam { - std::string node_name; /**< node name argument */ - std::string node_type; /**< node type argument */ -}; - -/// \brief KernelCallBack defined the function pointer for callBack. -using KernelCallBack = std::function inputs, - std::vector outputs, const CallBackParam &opInfo)>; - /// \brief LiteSession defined session in MindSpore Lite for compiling Model and forwarding model. class MS_API LiteSession { public: diff --git a/mindspore/lite/include/ms_tensor.h b/mindspore/lite/include/ms_tensor.h index 63520e09a92..cf762cbe0be 100644 --- a/mindspore/lite/include/ms_tensor.h +++ b/mindspore/lite/include/ms_tensor.h @@ -17,9 +17,11 @@ #ifndef MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_ #define MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_ +#include +#include +#include #include #include -#include #include "ir/dtype/type_id.h" namespace mindspore { @@ -74,5 +76,14 @@ class MS_API MSTensor { virtual void *MutableData() = 0; }; } // namespace tensor +/// \brief CallBackParam defined input arguments for callBack function. +struct CallBackParam { + std::string node_name; /**< node name argument */ + std::string node_type; /**< node type argument */ +}; + +/// \brief KernelCallBack defined the function pointer for callBack. +using KernelCallBack = std::function inputs, + std::vector outputs, const CallBackParam &opInfo)>; } // namespace mindspore #endif // MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_ diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index e9e1d43f0cf..dd815f6a012 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -29,6 +29,7 @@ set(LITE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/inner_context.cc ${CMAKE_CURRENT_SOURCE_DIR}/kernel_registry.cc ${CMAKE_CURRENT_SOURCE_DIR}/lite_kernel.cc + ${CMAKE_CURRENT_SOURCE_DIR}/sub_graph_kernel.cc ${CMAKE_CURRENT_SOURCE_DIR}/populate_parameter.cc ${CMAKE_CURRENT_SOURCE_DIR}/scheduler.cc ${CMAKE_CURRENT_SOURCE_DIR}/lite_session.cc diff --git a/mindspore/lite/src/common/file_utils.cc b/mindspore/lite/src/common/file_utils.cc index 3f8c565e3b9..5ec3d534987 100644 --- a/mindspore/lite/src/common/file_utils.cc +++ b/mindspore/lite/src/common/file_utils.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include +#include "src/common/file_utils.h" #include +#include #include #include -#include "src/common/file_utils.h" #include "securec/include/securec.h" namespace mindspore { @@ -78,7 +78,7 @@ std::string RealPath(const char *path) { char *real_path = realpath(path, resolvedPath.get()); #endif if (real_path == nullptr || strlen(real_path) == 0) { - MS_LOG(ERROR) << "Proto file path is not valid"; + MS_LOG(ERROR) << "file path is not valid : " << path; return ""; } std::string res = resolvedPath.get(); diff --git a/mindspore/lite/src/executor.cc b/mindspore/lite/src/executor.cc index 93efdcfaf8b..d48df63c8f2 100644 --- a/mindspore/lite/src/executor.cc +++ b/mindspore/lite/src/executor.cc @@ -19,10 +19,7 @@ #include "include/errorcode.h" namespace mindspore::lite { -int Executor::Run(std::vector &in_tensors, std::vector &out_tensors, - std::vector &kernels, Allocator *allocator, - const session::KernelCallBack &before, const session::KernelCallBack &after) { - MS_ASSERT(nullptr != allocator); +int Executor::CheckInputs(std::vector &in_tensors) { for (auto &inTensor : in_tensors) { if (inTensor == nullptr) { MS_LOG(ERROR) << "Graph input tensor is nullptr"; @@ -32,10 +29,18 @@ int Executor::Run(std::vector &in_tensors, std::vector &out_ MS_LOG(ERROR) << "Graph input tensor data is nullptr"; return RET_ERROR; } - if (inTensor->GetFormat() != schema::Format::Format_NHWC) { - MS_LOG(ERROR) << "Model input tensor should be NHWC"; - return RET_ERROR; - } + } + return RET_OK; +} + +int Executor::Run(std::vector &in_tensors, std::vector &out_tensors, + std::vector &kernels, Allocator *allocator, const KernelCallBack &before, + const KernelCallBack &after) { + MS_ASSERT(nullptr != allocator); + auto ret = this->CheckInputs(in_tensors); + if (RET_OK != ret) { + MS_LOG(ERROR) << "CheckInputs failed"; + return ret; } kernel::LiteKernelUtil::InitTensorRefCount(kernels); for (auto out_tensor : out_tensors) { // increase RefCount of output tensors, such that Run will not free them @@ -44,34 +49,20 @@ int Executor::Run(std::vector &in_tensors, std::vector &out_ for (auto *kernel : kernels) { MS_ASSERT(nullptr != kernel); - - if (before != nullptr) { - if (!before(TensorVectorCast(kernel->in_tensors()), TensorVectorCast(kernel->out_tensors()), - {kernel->name(), kernel->type_str()})) { - MS_LOG(ERROR) << "run kernel before_callback failed, name: " << kernel->name(); - } + ret = kernel->PreProcess(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "PreProcess kernel failed, name: " << kernel->name(); + return ret; } - - auto ret = kernel->Run(); - if (0 != ret) { + ret = kernel->Run(before, after); + if (RET_OK != ret) { MS_LOG(ERROR) << "run kernel failed, name: " << kernel->name(); return ret; } - if (after != nullptr) { - if (!after(TensorVectorCast(kernel->in_tensors()), TensorVectorCast(kernel->out_tensors()), - {kernel->name(), kernel->type_str()})) { - MS_LOG(ERROR) << "run kernel after_callback failed, name: " << kernel->name(); - } - } - for (auto input_kernel : kernel->in_kernels()) { - MS_ASSERT(input_kernel != nullptr); - if (input_kernel->is_model_output()) { - continue; - } - ret = input_kernel->DecOutTensorRefCount(); - if (0 != ret) { - MS_LOG(WARNING) << "DecOutTensorRefCount for kernel" << kernel->name() << " failed"; - } + ret = kernel->PostProcess(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "PostProcess kernel failed, name: " << kernel->name(); + return ret; } } return RET_OK; @@ -99,9 +90,9 @@ int Executor::TransformTensorLayoutFp32(Tensor *tensor, schema::Format dst_forma MS_ASSERT(4 == tensor->shape().size()); auto src_format = tensor->GetFormat(); if (src_format == schema::Format::Format_NC4HW4 && dst_format == schema::Format::Format_NHWC) { - auto *src_data = tensor->MutableData(); + auto *src_data = tensor->data_c(); if (src_data == nullptr) { - MS_LOG(ERROR) << "MutableData return nullptr"; + MS_LOG(ERROR) << "data of tensor is nullptr"; return RET_ERROR; } auto *dst_data = allocator->Malloc(tensor->Size()); diff --git a/mindspore/lite/src/executor.h b/mindspore/lite/src/executor.h index 9f89f6d804c..c1b073a8a0c 100644 --- a/mindspore/lite/src/executor.h +++ b/mindspore/lite/src/executor.h @@ -28,13 +28,15 @@ class Executor { Executor() = default; virtual ~Executor() = default; - virtual int Prepare(std::vector &kernels) { return 0; } + virtual int Prepare(const std::vector &kernels) { return 0; } virtual int Run(std::vector &in_tensors, std::vector &out_tensors, std::vector &kernels, Allocator *allocator = nullptr, - const session::KernelCallBack &before = nullptr, const session::KernelCallBack &after = nullptr); + const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); protected: + int CheckInputs(std::vector &in_tensors); + int TransformTensorLayoutFp32(Tensor *tensor, schema::Format dst_format, Allocator *allocator = nullptr); int TransformTensorLayoutUint8(Tensor *tensor, schema::Format dst_format, Allocator *allocator = nullptr); diff --git a/mindspore/lite/src/inner_context.cc b/mindspore/lite/src/inner_context.cc index 7650f3aac6a..01481824391 100644 --- a/mindspore/lite/src/inner_context.cc +++ b/mindspore/lite/src/inner_context.cc @@ -19,12 +19,21 @@ #include "src/common/log_adapter.h" namespace mindspore::lite { +InnerContext::InnerContext(const Context *context) { + this->allocator = context->allocator; + this->thread_num_ = context->thread_num_; + this->device_list_.clear(); + for (auto &device_ctx : context->device_list_) { + this->device_list_.push_back(device_ctx); + } +} + int InnerContext::Init() { - if (this->device_list_.empty()) { - MS_LOG(ERROR) << "Device list is empty."; + if (RET_OK != this->IsValid()) { + MS_LOG(ERROR) << "Context is not valid"; return RET_NOT_SUPPORT; } - if (this->thread_pool_ == nullptr && this->device_list_[0].device_type_ == DT_CPU) { + if (this->thread_pool_ == nullptr && this->IsCpuEnabled()) { this->thread_pool_ = CreateLiteThreadPool(this->thread_num_, this->device_list_[0].device_info_.cpu_device_info_.cpu_bind_mode_); if (this->thread_pool_ == nullptr) { @@ -49,4 +58,74 @@ InnerContext::~InnerContext() { this->thread_pool_ = NULL; } } + +int InnerContext::IsValid() { + if (this->device_list_.empty()) { + MS_LOG(ERROR) << "Device list is empty."; + return RET_NOT_SUPPORT; + } +#ifndef SUPPORT_GPU + if (IsGpuEnabled()) { + MS_LOG(ERROR) << "GPU is not supported."; + return RET_NOT_SUPPORT; + } +#endif + if (IsNpuEnabled()) { + MS_LOG(ERROR) << "NPU is not supported."; + return RET_NOT_SUPPORT; + } + return RET_OK; +} + +bool InnerContext::IsCpuFloat16Enabled() { + if (!IsCpuEnabled()) { + return false; + } + return GetCpuInfo().enable_float16_; +} + +bool InnerContext::IsGpuFloat16Enabled() { + if (!IsGpuEnabled()) { + return false; + } + return GetGpuInfo().enable_float16_; +} + +bool InnerContext::IsCpuEnabled() { + return this->device_list_.end() != + std::find_if(this->device_list_.begin(), this->device_list_.end(), + [](const DeviceContext &device) { return device.device_type_ == DT_CPU; }); +} + +bool InnerContext::IsGpuEnabled() { + return this->device_list_.end() != + std::find_if(this->device_list_.begin(), this->device_list_.end(), + [](const DeviceContext &device) { return device.device_type_ == DT_GPU; }); +} + +bool InnerContext::IsNpuEnabled() { + return this->device_list_.end() != + std::find_if(this->device_list_.begin(), this->device_list_.end(), + [](const DeviceContext &device) { return device.device_type_ == DT_NPU; }); +} + +CpuDeviceInfo InnerContext::GetCpuInfo() { + auto iter = std::find_if(this->device_list_.begin(), this->device_list_.end(), + [](const DeviceContext &device) { return device.device_type_ == DT_CPU; }); + if (iter == this->device_list_.end()) { + return {}; + } else { + return iter->device_info_.cpu_device_info_; + } +} + +GpuDeviceInfo InnerContext::GetGpuInfo() { + auto iter = std::find_if(this->device_list_.begin(), this->device_list_.end(), + [](const DeviceContext &device) { return device.device_type_ == DT_GPU; }); + if (iter == this->device_list_.end()) { + return {}; + } else { + return iter->device_info_.gpu_device_info_; + } +} } // namespace mindspore::lite diff --git a/mindspore/lite/src/inner_context.h b/mindspore/lite/src/inner_context.h index 1d6f0d3be82..9514e313be8 100644 --- a/mindspore/lite/src/inner_context.h +++ b/mindspore/lite/src/inner_context.h @@ -27,8 +27,28 @@ struct InnerContext : public Context { struct ThreadPool *thread_pool_ = nullptr; public: + InnerContext() = default; + + explicit InnerContext(const Context *context); + int Init(); + bool IsCpuFloat16Enabled(); + + bool IsGpuFloat16Enabled(); + + bool IsCpuEnabled(); + + bool IsGpuEnabled(); + + bool IsNpuEnabled(); + + CpuDeviceInfo GetCpuInfo(); + + GpuDeviceInfo GetGpuInfo(); + + int IsValid(); + virtual ~InnerContext(); }; } // namespace mindspore::lite diff --git a/mindspore/lite/src/kernel_registry.cc b/mindspore/lite/src/kernel_registry.cc index 44fa6c35d7c..6744a804f6d 100644 --- a/mindspore/lite/src/kernel_registry.cc +++ b/mindspore/lite/src/kernel_registry.cc @@ -117,8 +117,9 @@ kernel::LiteKernel *KernelRegistry::GetKernel(const std::vector &in_te if (creator != nullptr) { auto kernel = creator(in_tensors, out_tensors, parameter, ctx, key, primitive); if (kernel != nullptr) { - return kernel; + kernel->set_desc(key); } + return kernel; } return nullptr; } diff --git a/mindspore/lite/src/lite_kernel.cc b/mindspore/lite/src/lite_kernel.cc index b50a518be2a..957054cbf45 100644 --- a/mindspore/lite/src/lite_kernel.cc +++ b/mindspore/lite/src/lite_kernel.cc @@ -16,8 +16,11 @@ #include "src/lite_kernel.h" #include +#include "src/tensor.h" namespace mindspore::kernel { +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; void *LiteKernel::workspace_ = nullptr; @@ -54,7 +57,21 @@ int LiteKernel::DecOutTensorRefCount() { return 0; } -int LiteKernel::Prepare() { +int LiteKernel::FreeWorkTensor() const { + for (auto input_kernel : this->in_kernels()) { + MS_ASSERT(input_kernel != nullptr); + if (input_kernel->is_model_output()) { + continue; + } + auto ret = input_kernel->DecOutTensorRefCount(); + if (0 != ret) { + MS_LOG(WARNING) << "DecOutTensorRefCount for kernel" << this->name() << " failed"; + } + } + return RET_OK; +} + +int LiteKernel::PreProcess() { if (!InferShapeDone()) { (const_cast(primitive_))->SetInferFlag(true); auto ret = (const_cast(primitive_))->InferShape(in_tensors_, out_tensors_); @@ -70,7 +87,7 @@ int LiteKernel::Prepare() { } } - auto &outputs = this->out_tensors(); + auto outputs = this->out_tensors(); for (auto *output : outputs) { MS_ASSERT(output != nullptr); output->MallocData(); @@ -78,6 +95,50 @@ int LiteKernel::Prepare() { return RET_OK; } +int LiteKernel::Run(const KernelCallBack &before, const KernelCallBack &after) { + if (before != nullptr) { + if (!before(TensorVectorCast(this->in_tensors_), TensorVectorCast(this->out_tensors_), + {this->name_, this->type_str()})) { + MS_LOG(WARNING) << "run kernel before_callback failed, name: " << this->name_; + } + } + auto ret = Run(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "run kernel failed, name: " << this->name_; + return ret; + } + if (after != nullptr) { + if (!after(TensorVectorCast(this->in_tensors_), TensorVectorCast(this->out_tensors_), + {this->name_, this->type_str()})) { + MS_LOG(ERROR) << "run kernel after_callback failed, name: " << this->name_; + } + } + return RET_OK; +} + +std::string LiteKernel::ToString() const { + std::ostringstream oss; + oss << "LiteKernel: " << this->name_; + oss << ", Type: " << this->type_str(); + oss << std::endl << this->in_tensors_.size() << " InputTensors:"; + for (auto tensor : in_tensors_) { + oss << " " << tensor << ":" << tensor->ToString(); + } + oss << std::endl << this->out_tensors_.size() << " OutputTensors:"; + for (auto tensor : out_tensors_) { + oss << " " << tensor << ":" << tensor->ToString(); + } + oss << std::endl << this->in_kernels_.size() << " InputKernels:"; + for (auto in_kernel : in_kernels_) { + oss << " " << in_kernel->name_; + } + oss << std::endl << this->out_kernels_.size() << " OutputKernels:"; + for (auto out_kernel : out_kernels_) { + oss << " " << out_kernel->name_; + } + return oss.str(); +} + std::vector LiteKernelUtil::SubgraphInputKernels( const std::vector &kernels) { std::vector input_kernels; @@ -87,10 +148,11 @@ std::vector LiteKernelUtil::SubgraphInputKernels( continue; } for (const auto &input : kernel->in_kernels()) { - auto iter = std::find(kernels.begin(), kernels.end(), input); - auto item = std::find(input_kernels.begin(), input_kernels.end(), kernel); - if (iter == kernels.end() && item == input_kernels.end()) { + auto in_kernel_in_graph = std::find(kernels.begin(), kernels.end(), input); + auto in_kernel_in_ret = std::find(input_kernels.begin(), input_kernels.end(), kernel); + if (in_kernel_in_graph == kernels.end() && in_kernel_in_ret == input_kernels.end()) { input_kernels.emplace_back(kernel); + break; } } } @@ -106,10 +168,11 @@ std::vector LiteKernelUtil::SubgraphOutputKernels( continue; } for (const auto &output : kernel->out_kernels()) { - auto iter = std::find(kernels.begin(), kernels.end(), output); - auto item = std::find(output_kernels.begin(), output_kernels.end(), kernel); - if (iter == kernels.end() && item == output_kernels.end()) { + auto out_kernel_in_graph = std::find(kernels.begin(), kernels.end(), output); + auto out_kernel_in_ret = std::find(output_kernels.begin(), output_kernels.end(), kernel); + if (out_kernel_in_graph == kernels.end() && out_kernel_in_ret == output_kernels.end()) { output_kernels.emplace_back(kernel); + break; } } } @@ -120,7 +183,8 @@ std::vector LiteKernelUtil::SubgraphInputTensors(const std::vect std::vector input_tensors; std::vector all_output_tensors; for (const auto &kernel : kernels) { - all_output_tensors.insert(all_output_tensors.end(), kernel->out_tensors().begin(), kernel->out_tensors().end()); + auto kernel_out_tensors = kernel->out_tensors(); + all_output_tensors.insert(all_output_tensors.end(), kernel_out_tensors.begin(), kernel_out_tensors.end()); } std::vector input_kernels = SubgraphInputKernels(kernels); for (const auto &kernel : input_kernels) { @@ -139,7 +203,8 @@ std::vector LiteKernelUtil::SubgraphOutputTensors(const std::vec std::vector output_tensors; std::vector all_input_tensors; for (const auto &kernel : kernels) { - all_input_tensors.insert(all_input_tensors.end(), kernel->in_tensors().begin(), kernel->in_tensors().end()); + auto kernel_in_tensors = kernel->in_tensors(); + all_input_tensors.insert(all_input_tensors.end(), kernel_in_tensors.begin(), kernel_in_tensors.end()); } std::vector output_kernels = SubgraphOutputKernels(kernels); for (const auto &kernel : output_kernels) { @@ -153,8 +218,12 @@ std::vector LiteKernelUtil::SubgraphOutputTensors(const std::vec return output_tensors; } -void LiteKernelUtil::TopologicalSortKernels(std::vector &kernels) { +void LiteKernelUtil::InitIOKernels(std::vector &kernels) { for (auto *kernel : kernels) { + // clean io kernels + kernel->SetInKernel({}); + kernel->SetOutKernel({}); + // find io kernels for (auto *search_kernel : kernels) { if (search_kernel == kernel) { continue; diff --git a/mindspore/lite/src/lite_kernel.h b/mindspore/lite/src/lite_kernel.h index ec7865d645a..8f81cada97d 100644 --- a/mindspore/lite/src/lite_kernel.h +++ b/mindspore/lite/src/lite_kernel.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "src/ops/primitive_c.h" #include "src/common/utils.h" #ifdef ENABLE_ARM @@ -32,9 +33,7 @@ static constexpr int kPerTensor = 1; namespace mindspore::kernel { -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -enum KERNEL_ARCH { kCPU, kGPU, kNPU, kKernelArch_MIN = kCPU, kKernelArch_MAX = kNPU }; +enum KERNEL_ARCH { kCPU, kGPU, kAPU, kNPU, kKernelArch_MIN = kCPU, kKernelArch_MAX = kNPU }; struct KernelKey { KERNEL_ARCH arch; TypeId data_type; @@ -51,16 +50,17 @@ struct KernelKey { } }; +enum SubGraphType { kNotSubGraph = 0, kCpuFP32SubGraph, kCpuFP16SubGraph, kGpuSubGraph, kNpuSubGraph, kApuSubGraph }; + class LiteKernel { public: LiteKernel() = default; // parameter should be deleted or freed by caller, and should be deleted or freed after LiteKernel is deleted - LiteKernel(OpParameter *parameter, const std::vector &in_tensors, - const std::vector &out_tensors, const lite::InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) + LiteKernel(OpParameter *parameter, std::vector in_tensors, std::vector out_tensors, + const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) : op_parameter_(parameter), - in_tensors_(in_tensors), - out_tensors_(out_tensors), + in_tensors_(std::move(in_tensors)), + out_tensors_(std::move(out_tensors)), primitive_(primitive), context_(ctx) { if (op_parameter_ != nullptr && ctx != nullptr) { @@ -77,15 +77,22 @@ class LiteKernel { } } - virtual int Prepare(); + // called while compiling graph + virtual int Prepare() { return mindspore::lite::RET_OK; } + // called before Run + virtual int PreProcess(); - virtual int Init() { return -1; } + virtual int Run() { return mindspore::lite::RET_ERROR; } - virtual int ReSize() { return -1; } + virtual int Run(const KernelCallBack &before, const KernelCallBack &after); + // called after Run + virtual int PostProcess() { return FreeWorkTensor(); } - virtual int Run() { return -1; } + virtual int ReSize() { return mindspore::lite::RET_ERROR; } - std::string name() { return this->name_; } + virtual int Init() { return mindspore::lite::RET_ERROR; } + + std::string name() const { return this->name_; } virtual void train() { train_mode_ = true; } @@ -101,20 +108,20 @@ class LiteKernel { bool is_model_output() const { return this->is_model_output_; } - schema::PrimitiveType Type() { + schema::PrimitiveType Type() const { return (this->op_parameter_ != nullptr) ? schema::PrimitiveType(this->op_parameter_->type_) : schema::PrimitiveType_NONE; } - std::string type_str() { return schema::EnumNamePrimitiveType(this->Type()); } + std::string type_str() const { return schema::EnumNamePrimitiveType(this->Type()); } void set_in_tensors(const std::vector &in_tensors) { this->in_tensors_ = in_tensors; } void set_out_tensors(const std::vector &out_tensors) { this->out_tensors_ = out_tensors; } - std::vector &in_tensors() { return this->in_tensors_; } + std::vector in_tensors() const { return this->in_tensors_; } - std::vector &out_tensors() { return this->out_tensors_; } + std::vector out_tensors() const { return this->out_tensors_; } void AddInKernel(LiteKernel *kernel) { if (!lite::IsContain(this->in_kernels_, kernel)) { @@ -132,14 +139,16 @@ class LiteKernel { void SetOutKernel(const std::vector &kernel) { this->out_kernels_ = kernel; } - std::vector &in_kernels() { return this->in_kernels_; } + std::vector in_kernels() const { return this->in_kernels_; } - std::vector &out_kernels() { return this->out_kernels_; } + std::vector out_kernels() const { return this->out_kernels_; } void InitOutTensorRefCount(); int DecOutTensorRefCount(); + int FreeWorkTensor() const; + KernelKey desc() const { return desc_; } void set_desc(const KernelKey kernel_key) { desc_ = kernel_key; } @@ -151,10 +160,14 @@ class LiteKernel { static void FreeWorkspace(); void *GetWorkspace() { return workspace_; } - protected: - bool InferShapeDone() { return !(primitive_ != nullptr && !primitive_->GetInferFlag()) && true; } + SubGraphType subgraph_type() const { return this->subgraph_type_; } - KernelKey desc_; + virtual std::string ToString() const; + + protected: + bool InferShapeDone() { return !(primitive_ != nullptr && !primitive_->GetInferFlag()); } + + KernelKey desc_{}; std::string name_; OpParameter *op_parameter_ = nullptr; // tensor will free in ~lite_session() @@ -168,27 +181,7 @@ class LiteKernel { bool is_model_output_ = false; size_t workspace_size_ = 0; static void *workspace_; -}; - -class SubGraphKernel : public LiteKernel { - public: - explicit SubGraphKernel(const std::vector &inputs, const std::vector &outputs, - const std::vector &in_kernels, - const std::vector &out_kernels, - const std::vector &nodes, const lite::InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(nullptr, inputs, outputs, ctx, primitive), nodes_(nodes) { - in_kernels_ = in_kernels; - out_kernels_ = out_kernels; - } - - virtual int Init() { return -1; } - virtual int InferShape() { return -1; } - virtual int ReSize() { return -1; } - virtual int Run() { return -1; } - - protected: - std::vector nodes_; + SubGraphType subgraph_type_ = kNotSubGraph; }; typedef LiteKernel *(*KernelCreator)(const std::vector &inputs, @@ -198,7 +191,7 @@ typedef LiteKernel *(*KernelCreator)(const std::vector &inputs, class LiteKernelUtil { public: - static void TopologicalSortKernels(std::vector &kernels); + static void InitIOKernels(std::vector &kernels); static std::vector SubgraphInputKernels(const std::vector &kernels); diff --git a/mindspore/lite/src/lite_session.cc b/mindspore/lite/src/lite_session.cc index d68200d6e3d..d0ace7304af 100644 --- a/mindspore/lite/src/lite_session.cc +++ b/mindspore/lite/src/lite_session.cc @@ -295,13 +295,13 @@ int LiteSession::CompileGraph(Model *model) { std::vector LiteSession::GetInputs() const { return this->input_vec_; } -int LiteSession::RunGraph(const session::KernelCallBack &before, const session::KernelCallBack &after) { +int LiteSession::RunGraph(const KernelCallBack &before, const KernelCallBack &after) { bool expected = false; if (!is_running_.compare_exchange_strong(expected, true)) { MS_LOG(ERROR) << "Not support multi-threading"; return RET_ERROR; } - STATUS ret = RET_ERROR; + STATUS ret; MS_ASSERT(this->context_); if (before == nullptr && after == nullptr) { ret = executor->Run(this->inputs_, this->outputs_, this->kernels_, this->context_->allocator.get()); @@ -325,39 +325,12 @@ int LiteSession::Init(Context *context) { return RET_NULL_PTR; } - if (context->device_list_.empty()) { - MS_LOG(ERROR) << "Device list is empty."; - is_running_.store(false); - return RET_NOT_SUPPORT; - } - - auto &device_type = context->device_list_[0].device_type_; - - if (device_type == DT_NPU) { - MS_LOG(ERROR) << "NPU is not supported."; - is_running_.store(false); - return RET_NOT_SUPPORT; - } -#ifndef SUPPORT_GPU - if (device_type == DT_GPU) { - MS_LOG(ERROR) << "GPU is not supported."; - is_running_.store(false); - return RET_NOT_SUPPORT; - } -#endif - - this->context_ = new (std::nothrow) InnerContext(); + this->context_ = new (std::nothrow) InnerContext(context); if (this->context_ == nullptr) { MS_LOG(ERROR) << "New Context failed"; is_running_.store(false); return RET_MEMORY_FAILED; } - this->context_->allocator = context->allocator; - this->context_->thread_num_ = context->thread_num_; - this->context_->device_list_.clear(); - for (auto &device_ctx : context->device_list_) { - this->context_->device_list_.push_back(device_ctx); - } auto ret = this->context_->Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init Context failed"; @@ -371,12 +344,11 @@ int LiteSession::Init(Context *context) { return ret; } #if SUPPORT_GPU - if (device_type == DT_GPU) { - auto gpu_device_info = this->context_->device_list_[0].device_info_.gpu_device_info_; + if (this->context_->IsGpuEnabled()) { + auto gpu_device_info = this->context_->GetGpuInfo(); auto opencl_runtime = ocl_runtime_wrap_.GetInstance(); opencl_runtime->SetFp16Enable(gpu_device_info.enable_float16_); if (opencl_runtime->Init() != RET_OK) { - device_type = DT_CPU; MS_LOG(WARNING) << "Init OpenCL runtime failed, change to CPU mode."; } else { MS_LOG(INFO) << "Init OpenCL runtime success."; @@ -398,14 +370,13 @@ void LiteSession::BindThread(bool if_bind) { MS_LOG(ERROR) << "Device list is empty."; return; } - auto &device_ctx = this->context_->device_list_[0]; - if (device_ctx.device_type_ != DT_CPU) { - MS_LOG(ERROR) << "Device is not CPU."; + if (this->context_->IsCpuEnabled()) { return; } - if (device_ctx.device_info_.cpu_device_info_.cpu_bind_mode_ != NO_BIND) { + auto cpu_device_info = this->context_->GetCpuInfo(); + if (cpu_device_info.cpu_bind_mode_ != NO_BIND) { MS_ASSERT(this->context_->thread_pool_ != NULL); - BindThreads(this->context_->thread_pool_, if_bind, device_ctx.device_info_.cpu_device_info_.cpu_bind_mode_); + BindThreads(this->context_->thread_pool_, if_bind, cpu_device_info.cpu_bind_mode_); } } diff --git a/mindspore/lite/src/lite_session.h b/mindspore/lite/src/lite_session.h index 6916f2534ad..a213305c546 100644 --- a/mindspore/lite/src/lite_session.h +++ b/mindspore/lite/src/lite_session.h @@ -52,8 +52,7 @@ class LiteSession : public session::LiteSession { mindspore::tensor::MSTensor *GetInputsByTensorName(const std::string &name) const override; - int RunGraph(const session::KernelCallBack &before = nullptr, - const session::KernelCallBack &after = nullptr) override; + int RunGraph(const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; std::vector GetOutputsByNodeName(const std::string &node_name) const override; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc index a7e97d8e6ba..e7a10d877a9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc @@ -163,11 +163,6 @@ int RunPriorBox(void *cdata, int task_id) { } int PriorBoxCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! Ret error code[" << prepare_ret << "]"; - return prepare_ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, RunPriorBox, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "PriorBox run error, error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc index b5212b9b30a..1562c37d7f7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc @@ -140,12 +140,6 @@ int QuantDTypeCastRun(void *cdata, int task_id) { } int QuantDTypeCastCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - if (in_tensors_[0]->data_type() == TypeId::kNumberTypeInt8 && out_tensors_[0]->data_type() == TypeId::kNumberTypeFloat32) { int8_ptr_ = reinterpret_cast(in_tensors_[0]->data_c()); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc index f7193ca2682..e1903f7dfb3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc @@ -91,24 +91,18 @@ int StridedSliceCPUKernel::HandleMultiInputs() { } int StridedSliceCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - auto input = in_tensors_.at(0); auto output = out_tensors_.at(0); MS_ASSERT(input); MS_ASSERT(output); if (in_tensors().size() == kMultiInputsSize) { - ret = HandleMultiInputs(); + auto ret = HandleMultiInputs(); if (ret != RET_OK) { return ret; } } - ret = DoStridedSlice(input->MutableData(), output->MutableData(), - reinterpret_cast(op_parameter_)); + auto ret = DoStridedSlice(input->MutableData(), output->MutableData(), + reinterpret_cast(op_parameter_)); if (ret != RET_OK) { MS_LOG(ERROR) << "StridedSlice error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc index 581ff5e66a5..99534f40b5c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc @@ -103,9 +103,9 @@ int ActivationFp16Run(void *cdata, int task_id) { } int ActivationFp16CPUKernel::Run() { - auto ret = Prepare(); + auto ret = MallocTmpBuffer(); if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; + MS_LOG(ERROR) << "MallocTmpBuffer failed."; return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc index aa8cd3b656a..0ff67245dd6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc @@ -185,11 +185,6 @@ static int ArithmeticsRunFp16(void *cdata, int task_id) { } int ArithmeticFP16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto output_tensor = out_tensors_.at(0); is_input0_fp32_ = in_tensors_.at(0)->data_type() == kNumberTypeFloat32; is_input1_fp32_ = in_tensors_.at(1)->data_type() == kNumberTypeFloat32; @@ -203,7 +198,7 @@ int ArithmeticFP16CPUKernel::Run() { FreeTmpBuffer(); return RET_ERROR; } - ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticsRunFp16, this, context_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticsRunFp16, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticsRunFp16 run error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc index f6de91b42cc..5ac00097f06 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc @@ -20,6 +20,8 @@ #include "nnacl/fp16/arithmetic_self_fp16.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; namespace mindspore::kernel { namespace { @@ -81,11 +83,6 @@ void ArithmeticSelfFp16CPUKernel::FreeInputAndOutput() { } int ArithmeticSelfFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! ret: " << ret; - return ret; - } auto input_tensor = in_tensors_.at(0); auto output_tensor = out_tensors_.at(0); input_fp16_ptr_ = ConvertInputFp32toFp16(input_tensor, context_); @@ -95,7 +92,7 @@ int ArithmeticSelfFp16CPUKernel::Run() { MS_LOG(ERROR) << "input or output is nullptr"; return RET_ERROR; } - ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticSelfRun, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticSelfRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc index 9b91cf37948..d30c761cc5f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc @@ -21,6 +21,8 @@ #include "src/kernel_registry.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchNorm; namespace mindspore::kernel { @@ -47,11 +49,6 @@ int BatchnormFp16CPUKernel::InitConstTensor() { } int BatchnormFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! Ret error code: " << ret; - return ret; - } auto input_tensor = in_tensors_.at(0); auto output_tensor = out_tensors_.at(0); input_ = ConvertInputFp32toFp16(input_tensor, context_); @@ -62,7 +59,7 @@ int BatchnormFp16CPUKernel::Run() { return RET_ERROR; } - ret = ParallelLaunch(this->context_->thread_pool_, BatchNormRun, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, BatchNormRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } @@ -76,7 +73,7 @@ int BatchnormFp16CPUKernel::Run() { int BatchnormFp16CPUKernel::DoExecute(int task_id) { auto param = reinterpret_cast(op_parameter_); BatchNormFp16(input_, mean_, variance_, param, task_id, output_); - return mindspore::lite::RET_OK; + return RET_OK; } void BatchnormFp16CPUKernel::FreeInputAndOutput() { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc index 0280f751418..4b21b42bed2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc @@ -83,11 +83,6 @@ int CastFp16CPUKernel::DoCast(int thread_id) { } int CastFp16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } if (data_num_ == 0) { return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc index 5fa547e8287..24642652949 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc @@ -91,12 +91,6 @@ void ConcatFp16CPUKernel::FreeTmpBuffer() { } int ConcatFp16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - auto ret = MallocTmpBuffer(); if (ret != RET_OK) { FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc index e5f62f8a466..69045f5e2ad 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc @@ -218,13 +218,7 @@ static int Convolution1x1Fp16RunHw(void *cdata, int task_id) { } int Convolution1x1FP16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - - ret = ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); + auto ret = ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); if (ret != RET_OK) { MS_LOG(ERROR) << "Get executor tensor failed."; return ret; @@ -248,10 +242,14 @@ int Convolution1x1FP16CPUKernel::Run() { } if (multi_thread_by_hw_) { - ParallelLaunch(this->context_->thread_pool_, Convolution1x1Fp16RunHw, this, thread_count_); + ret = ParallelLaunch(this->context_->thread_pool_, Convolution1x1Fp16RunHw, this, thread_count_); } else { RowMajor2Col16MajorFp16Opt(input_ptr_, pack_input_, matmul_param_->row_, matmul_param_->deep_); - ParallelLaunch(this->context_->thread_pool_, Convolution1x1Fp16RunOc, this, thread_count_); + ret = ParallelLaunch(this->context_->thread_pool_, Convolution1x1Fp16RunOc, this, thread_count_); + } + if (ret != RET_OK) { + MS_LOG(ERROR) << "ParallelLaunch failed."; + return ret; } } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.cc index 22f71430463..13004b77482 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.cc @@ -23,7 +23,8 @@ #include "src/runtime/runtime_api.h" namespace mindspore::kernel { - +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; ConvolutionBaseFP16CPUKernel::~ConvolutionBaseFP16CPUKernel() { if (fp16_weight_ != nullptr) { free(fp16_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.h index 6934b3a6790..ab2d10c155b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_base_fp16.h @@ -32,10 +32,10 @@ class ConvolutionBaseFP16CPUKernel : public ConvolutionBaseCPUKernel { : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionBaseFP16CPUKernel() override; - int Init() override { return RET_OK; } - int ReSize() override { return RET_OK; } - int Run() override { return RET_OK; } - int RunImpl(int task_id) { return RET_OK; } + int Init() override { return mindspore::lite::RET_OK; } + int ReSize() override { return mindspore::lite::RET_OK; } + int Run() override { return mindspore::lite::RET_OK; } + int RunImpl(int task_id) { return mindspore::lite::RET_OK; } virtual int GetExecuteTensor(); virtual int GetExecuteFilter(); virtual void IfCastOutput(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc index e5226f06ef0..936378f4739 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc @@ -110,12 +110,7 @@ static int ConvDwFp16Run(void *cdata, int task_id) { } int ConvolutionDepthwiseFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - ret = ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); + auto ret = ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); if (ret != RET_OK) { MS_LOG(ERROR) << "Get Execute tensor failed."; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc index 4e594820f37..b17dd83e73f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc @@ -140,12 +140,7 @@ static int ConvDwSWFp16Run(void *cdata, int task_id) { } int ConvolutionDepthwiseSWFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - ret = InitBuffer(); + auto ret = InitBuffer(); if (ret != 0) { MS_LOG(ERROR) << "Convolution depthwise fp16 InitBuffer failed."; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc index bf004cf499d..70655f23d5a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc @@ -145,13 +145,7 @@ static int ConvolutionFp16Impl(void *cdata, int task_id) { } int ConvolutionFP16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - - ret = ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); + auto ret = ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); if (ret != RET_OK) { MS_LOG(ERROR) << "Get Execute tensor failed."; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc index 37364467eba..03f5a2eff20 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc @@ -211,12 +211,6 @@ static int ConvolutionWinogradFp16Impl(void *cdata, int task_id) { } int ConvolutionWinogradFP16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - auto ret = ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); if (ret != RET_OK) { MS_LOG(ERROR) << "Get Execute tensor failed."; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc index 64cb3513508..8dd153dd0cd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc @@ -61,11 +61,6 @@ static int CropFp16Run(void *cdata, int task_id) { } int CropFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } input_ptr_ = ConvertInputFp32toFp16(in_tensors_.at(kInputIndex), context_); if (input_ptr_ == nullptr) { MS_LOG(ERROR) << "input or output is nullptr"; @@ -79,8 +74,11 @@ int CropFp16CPUKernel::Run() { return RET_ERROR; } - ret = ParallelLaunch(this->context_->thread_pool_, CropFp16Run, this, thread_count_); - + auto ret = ParallelLaunch(this->context_->thread_pool_, CropFp16Run, this, thread_count_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "ParallelLaunch failed: " << ret; + return ret; + } if (out_tensors_.at(kOutputIndex)->data_type() == kNumberTypeFloat32) { Float16ToFloat32(output_ptr_, reinterpret_cast(out_tensors_.at(kOutputIndex)->MutableData()), out_tensors_.at(kOutputIndex)->ElementsNum()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc index 02833d92b3d..0a34c236cae 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc @@ -156,12 +156,7 @@ int DeconvolutionDepthwiseFp16CPUKernel::Run() { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; } - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - ret = InitBuffer(); + auto ret = InitBuffer(); if (ret != 0) { MS_LOG(ERROR) << "Deconvolution depthwise fp16 InitBuffer failed."; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc index 2059f8136ee..dafa3e08ffe 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc @@ -179,11 +179,6 @@ int DeConvolutionFp16CPUKernel::Init() { } int DeConvolutionFp16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } ConvolutionBaseFP16CPUKernel::GetExecuteTensor(); int error_code = InitRunBuf(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fp16_op_handler.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/fp16_op_handler.cc new file mode 100644 index 00000000000..715513b8ba9 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fp16_op_handler.cc @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef ENABLE_ARM64 +extern void Float32ToFloat16(const float *input, float16_t *output, int number); +extern void Float16ToFloat32(const float16_t *input, float *output, int number); + +void Float32ToFloat16_fp16_handler(const void *input, void *output, int number) { + Float32ToFloat16(reinterpret_cast(input), reinterpret_cast(output), number); +} +void Float16ToFloat32_fp16_handler(const void *input, void *output, int number) { + Float16ToFloat32(reinterpret_cast(input), reinterpret_cast(output), number); +} +#endif + +#ifdef __cplusplus +} +#endif diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc index a39db555c36..407a33cd66c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc @@ -179,11 +179,6 @@ int FcFP16Run(void *cdata, int task_id) { } int FullconnectionFP16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto out_tensor = out_tensors_[0]; if (out_tensor->data_type() == kNumberTypeFloat32) { output_ptr_ = output_fp16_; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc index a977e1fe89f..8169b0854b2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc @@ -20,6 +20,8 @@ #include "src/kernel_registry.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_FusedBatchNorm; namespace mindspore::kernel { @@ -70,11 +72,11 @@ int FusedBatchnormFp16CPUKernel::DoExecute(int task_id) { context_->allocator->Free(mean_fp16); context_->allocator->Free(variance_fp16); context_->allocator->Free(output_fp16); - return mindspore::lite::RET_OK; + return RET_OK; } FusedBatchNormFp16(in_tensors_.at(0)->MutableData(), scale_, offset_, mean_, variance_, param, task_id, out_tensors_.at(0)->MutableData()); - return mindspore::lite::RET_OK; + return RET_OK; } kernel::LiteKernel *CpuFusedBatchnormFp16KernelCreator(const std::vector &inputs, diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc index 5883d372ab4..3f7a3570fd4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc @@ -210,11 +210,6 @@ int MatmulFP16Run(void *cdata, int task_id) { } int MatmulFP16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto out_tensor = out_tensors_[0]; float16_t *c_ptr = nullptr; if (out_tensor->data_type() == kNumberTypeFloat32) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc index 68135d8cccf..a3fe9404b9e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc @@ -33,11 +33,6 @@ int PadFp16CPUKernel::RunImpl(int task_id) { } int PadFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input_tensor = in_tensors_.at(0); auto output_tensor = out_tensors_.at(0); is_input_fp32_ = input_tensor->data_type() == kNumberTypeFloat32; @@ -58,7 +53,7 @@ int PadFp16CPUKernel::Run() { output_[i] = pad_param_->constant_value_; } } - ret = ParallelLaunch(this->context_->thread_pool_, PadImpl, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, PadImpl, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc index 79d436f5077..71e89c5334f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc @@ -84,12 +84,6 @@ static int PoolingFp16Impl(void *cdata, int task_id) { } int PoolingFp16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - auto input_tensor = in_tensors_.at(kInputIndex); auto in_data_type_ = input_tensor->data_type(); MS_ASSERT(in_data_type_ == kNumberTypeFloat32 || in_data_type_ == kNumberTypeFloat16); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc index 6e36b6e470b..3edbd69b6ae 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc @@ -76,12 +76,6 @@ static int ReduceFp16Impl(void *cdata, int task_id) { } int ReduceFp16CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - auto ret = MallocTmpBuffer(); if (ret != RET_OK) { FreeTmpBuffer(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc index c1c89626f60..b0c4cbc2f72 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc @@ -31,11 +31,6 @@ using mindspore::schema::PrimitiveType_Reshape; namespace mindspore::kernel { int ReshapeFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto in_tensor = in_tensors_.at(kInputIndex); auto out_tensor = out_tensors_.at(kOutputIndex); auto input_ptr = in_tensor->MutableData(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc index 0caf6a5e599..5bd755a6fef 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc @@ -103,12 +103,7 @@ int ScaleFp16Run(void *cdata, int task_id) { } int ScaleFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - ret = InitScaleOffset(); + auto ret = InitScaleOffset(); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale fp16 InitScaleOffset failed."; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc index 432505e4a1d..3bc1cbc86d0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc @@ -20,6 +20,8 @@ #include "nnacl/fp16/slice_fp16.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Slice; namespace mindspore::kernel { @@ -29,11 +31,6 @@ int SliceFp16CPUKernel::SliceParallelRun(int thread_id) { } int SliceFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } input_fp16_ = ConvertInputFp32toFp16(in_tensors_.at(0), context_); output_fp16_ = MallocOutputFp16(out_tensors_.at(0), context_); if (input_fp16_ == nullptr || output_fp16_ == nullptr) { @@ -45,7 +42,7 @@ int SliceFp16CPUKernel::Run() { DoSliceFp16NoParallel(input_fp16_, output_fp16_, param_); return RET_OK; } - ret = ParallelLaunch(this->context_->thread_pool_, SliceLaunch, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SliceLaunch, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "slice launch fail!ret: " << ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc index 7a7c7914d6b..f7f2b8dff2e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc @@ -104,12 +104,7 @@ void SoftmaxFp16CPUKernel::FreeTmpBuffer() { } int SoftmaxFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return RET_ERROR; - } - ret = MallocTmpBuffer(); + auto ret = MallocTmpBuffer(); if (ret != RET_OK) { FreeTmpBuffer(); MS_LOG(ERROR) << "MallocTmpBuffer failed"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc index f50b8a2d241..d12ff4c7ae2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc @@ -76,11 +76,6 @@ static int SplitFp16Run(void *cdata, int task_id) { } int SplitFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } input_ptr_ = ConvertInputFp32toFp16(in_tensors_.at(0), context_); if (input_ptr_ == nullptr) { MS_LOG(ERROR) << "input or output is nullptr"; @@ -94,7 +89,7 @@ int SplitFp16CPUKernel::Run() { return RET_ERROR; } } - ret = ParallelLaunch(this->context_->thread_pool_, SplitFp16Run, this, thread_n_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SplitFp16Run, this, thread_n_num_); for (int i = 0; i < param->num_split_; i++) { if (out_tensors_.at(i)->data_type() == kNumberTypeFloat32) { Float16ToFloat32(output_ptr_[i], reinterpret_cast(out_tensors_.at(i)->MutableData()), diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc index ba649883225..36bfa973047 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc @@ -76,11 +76,6 @@ void StackFp16CPUKernel::FreeBuffer() { } int StackFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } size_t inputs_num = in_tensors_.size(); auto input0 = in_tensors_[0]; if (inputs_num == 1) { @@ -88,7 +83,7 @@ int StackFp16CPUKernel::Run() { return RET_OK; } InitMallocFlags(); - ret = MallocAssignBuffer(); + auto ret = MallocAssignBuffer(); if (ret != RET_OK) { FreeBuffer(); return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc index 995ca4e28bf..5a96c9a3350 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc @@ -128,11 +128,6 @@ static int TransposeFp16Run(void *cdata, int task_id) { } int TransposeFp16CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } MS_ASSERT(in_tensors_.size() == TransposeInputNum); MS_ASSERT(out_tensors_.size() == TransposeOutputNum); auto &in_tensor = in_tensors_.front(); @@ -143,7 +138,7 @@ int TransposeFp16CPUKernel::Run() { } // malloc when Run - ret = MallocFp16Buffer(); + auto ret = MallocFp16Buffer(); if (ret != RET_OK) { FreeFp16Buffer(); return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc index 71ecc40501d..093374d5853 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc @@ -83,11 +83,6 @@ int ActivationRun(void *cdata, int task_id) { } int ActivationCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, ActivationRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc index d895f05167c..98543bcd934 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc @@ -55,11 +55,6 @@ int AddNCPUKernel::AddNParallelRun(int thread_id) { } int AddNCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } elements_num_ = out_tensors_[0]->ElementsNum(); auto input0_data = reinterpret_cast(in_tensors_[0]->MutableData()); auto input1_data = reinterpret_cast(in_tensors_[1]->MutableData()); @@ -94,7 +89,7 @@ int AddNCPUKernel::Run() { in1_addr_ = input0_data; in2_addr_ = input1_data; out_addr_ = output_data; - ret = ParallelLaunch(this->context_->thread_pool_, AddNLaunch, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, AddNLaunch, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "addn launch fail!ret: " << ret; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc index 725e303635f..ded9a016569 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc @@ -45,12 +45,7 @@ int ArgMinMaxCPUKernel::Init() { int ArgMinMaxCPUKernel::ReSize() { return ArgMinMaxBaseCPUKernel::ReSize(); } int ArgMinMaxCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - ret = ArgMinMaxBaseCPUKernel::Run(); + auto ret = ArgMinMaxBaseCPUKernel::Run(); return ret; } } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc index f3c007746b5..7d07ddc45ba 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc @@ -189,39 +189,38 @@ int ArithmeticCPUKernel::DoArithmetic(int task_id) { int out_count = MSMIN(stride, outside_ - stride * task_id); int out_thread_stride = stride * task_id; if (data_type_ == kDataTypeFloat) { - error_code = - BroadcastRun(reinterpret_cast(in_tensors_[0]->MutableData()), - reinterpret_cast(in_tensors_[1]->MutableData()), - reinterpret_cast(out_tensors_[0]->MutableData()), 0, out_count, out_thread_stride); + error_code = BroadcastRun(reinterpret_cast(in_tensors_[0]->data_c()), + reinterpret_cast(in_tensors_[1]->data_c()), + reinterpret_cast(out_tensors_[0]->data_c()), 0, out_count, out_thread_stride); } else { - error_code = BroadcastRun( - reinterpret_cast(in_tensors_[0]->MutableData()), reinterpret_cast(in_tensors_[1]->MutableData()), - reinterpret_cast(out_tensors_[0]->MutableData()), 0, out_count, out_thread_stride); + error_code = BroadcastRun(reinterpret_cast(in_tensors_[0]->data_c()), + reinterpret_cast(in_tensors_[1]->data_c()), + reinterpret_cast(out_tensors_[0]->data_c()), 0, out_count, out_thread_stride); } } else if (arithmetic_opt_run_ != nullptr) { // no broadcast, one of input is scalar if (arithmeticParameter_->in_elements_num0_ == 1) { if (data_type_ == kDataTypeFloat) { - error_code = arithmetic_opt_run_(reinterpret_cast(in_tensors_[0]->MutableData()), - reinterpret_cast(in_tensors_[1]->MutableData()) + stride * task_id, - reinterpret_cast(out_tensors_[0]->MutableData()) + stride * task_id, - count, arithmeticParameter_); + error_code = arithmetic_opt_run_(reinterpret_cast(in_tensors_[0]->data_c()), + reinterpret_cast(in_tensors_[1]->data_c()) + stride * task_id, + reinterpret_cast(out_tensors_[0]->data_c()) + stride * task_id, count, + arithmeticParameter_); } else { - error_code = arithmetic_opt_run_int_(reinterpret_cast(in_tensors_[0]->MutableData()), - reinterpret_cast(in_tensors_[1]->MutableData()) + stride * task_id, - reinterpret_cast(out_tensors_[0]->MutableData()) + stride * task_id, + error_code = arithmetic_opt_run_int_(reinterpret_cast(in_tensors_[0]->data_c()), + reinterpret_cast(in_tensors_[1]->data_c()) + stride * task_id, + reinterpret_cast(out_tensors_[0]->data_c()) + stride * task_id, count, arithmeticParameter_); } } else if (arithmeticParameter_->in_elements_num1_ == 1) { if (data_type_ == kDataTypeFloat) { - error_code = arithmetic_opt_run_(reinterpret_cast(in_tensors_[0]->MutableData()) + stride * task_id, - reinterpret_cast(in_tensors_[1]->MutableData()), - reinterpret_cast(out_tensors_[0]->MutableData()) + stride * task_id, - count, arithmeticParameter_); + error_code = arithmetic_opt_run_(reinterpret_cast(in_tensors_[0]->data_c()) + stride * task_id, + reinterpret_cast(in_tensors_[1]->data_c()), + reinterpret_cast(out_tensors_[0]->data_c()) + stride * task_id, count, + arithmeticParameter_); } else { - error_code = arithmetic_opt_run_int_(reinterpret_cast(in_tensors_[0]->MutableData()) + stride * task_id, - reinterpret_cast(in_tensors_[1]->MutableData()), - reinterpret_cast(out_tensors_[0]->MutableData()) + stride * task_id, + error_code = arithmetic_opt_run_int_(reinterpret_cast(in_tensors_[0]->data_c()) + stride * task_id, + reinterpret_cast(in_tensors_[1]->data_c()), + reinterpret_cast(out_tensors_[0]->data_c()) + stride * task_id, count, arithmeticParameter_); } } else { @@ -230,14 +229,13 @@ int ArithmeticCPUKernel::DoArithmetic(int task_id) { } } else { // no broadcast, neither is scalar, two same shape if (data_type_ == kDataTypeFloat) { - error_code = arithmetic_run_(reinterpret_cast(in_tensors_[0]->MutableData()) + stride * task_id, - reinterpret_cast(in_tensors_[1]->MutableData()) + stride * task_id, - reinterpret_cast(out_tensors_[0]->MutableData()) + stride * task_id, count); + error_code = arithmetic_run_(reinterpret_cast(in_tensors_[0]->data_c()) + stride * task_id, + reinterpret_cast(in_tensors_[1]->data_c()) + stride * task_id, + reinterpret_cast(out_tensors_[0]->data_c()) + stride * task_id, count); } else { - error_code = - arithmetic_run_int_(reinterpret_cast(in_tensors_[0]->MutableData()) + stride * task_id, - reinterpret_cast(in_tensors_[1]->MutableData()) + stride * task_id, - reinterpret_cast(out_tensors_[0]->MutableData()) + stride * task_id, count); + error_code = arithmetic_run_int_(reinterpret_cast(in_tensors_[0]->data_c()) + stride * task_id, + reinterpret_cast(in_tensors_[1]->data_c()) + stride * task_id, + reinterpret_cast(out_tensors_[0]->data_c()) + stride * task_id, count); } } if (error_code != RET_OK) { @@ -257,11 +255,6 @@ int ArithmeticsRun(void *cdata, int task_id) { } int ArithmeticCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } if (arithmeticParameter_->broadcasting_) { outside_ = 1; for (auto i = arithmeticParameter_->ndim_ - 1; i >= 0; --i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc index 0a086faeb34..cef480bbc1a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc @@ -18,6 +18,8 @@ #include "nnacl/fp32/arithmetic_self.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; namespace mindspore::kernel { namespace { @@ -88,12 +90,7 @@ int ArithmeticSelfRun(void *cdata, int task_id) { } int ArithmeticSelfCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! ret: " << ret; - return ret; - } - ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticSelfRun, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticSelfRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc index a3cf8eebe52..1a9bb76fbe3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc @@ -38,11 +38,6 @@ int BatchToSpaceCPUKernel::Init() { int BatchToSpaceCPUKernel::ReSize() { return BatchToSpaceBaseCPUKernel::ReSize(); } int BatchToSpaceCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input = in_tensors_[0]; auto output = out_tensors_[0]; const float *input_data = reinterpret_cast(input->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc index 67ed41f4225..ff97fc5e7b7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc @@ -18,6 +18,8 @@ #include "src/kernel_registry.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchNorm; namespace mindspore::kernel { @@ -70,12 +72,7 @@ int BatchnormCPUKernel::InitConstTensor() { } int BatchnormCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! Ret error code: " << ret; - return ret; - } - ret = ParallelLaunch(this->context_->thread_pool_, BatchNormRun, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, BatchNormRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } @@ -85,7 +82,7 @@ int BatchnormCPUKernel::Run() { int BatchnormCPUKernel::DoExecute(int task_id) { auto param = reinterpret_cast(op_parameter_); BatchNormFp32(in_tensors_.at(0)->MutableData(), mean_, variance_, param, task_id, out_tensors_.at(0)->MutableData()); - return mindspore::lite::RET_OK; + return RET_OK; } int BatchNormRun(void *cdata, int task_id) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc index b09c87651b8..6c7d54c517b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc @@ -42,11 +42,6 @@ int BiasCPUKernel::ReSize() { } int BiasCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto in = reinterpret_cast(in_tensors_.at(0)->MutableData()); auto bias = reinterpret_cast(in_tensors_.at(1)->MutableData()); auto out = reinterpret_cast(out_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc index 3d23907b910..0fbaf032134 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc @@ -49,11 +49,6 @@ int BroadcastToCPUKernel::Init() { } int BroadcastToCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input_data = reinterpret_cast(in_tensors_.at(0)->MutableData()); auto output_data = reinterpret_cast(out_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc index d96df2689b7..cdab2a9653a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc @@ -66,15 +66,16 @@ int CastCPUKernel::DoCast(int thread_id) { auto offset = thread_id * stride_; auto output = out_tensors_.at(0); - auto output_data = output->MutableData(); + auto output_data = output->data_c(); + MS_ASSERT(output_data != nullptr); auto input_data_type = input->data_type(); auto output_data_type = output->data_type(); if (output_data_type != kNumberTypeFloat32) { if (input_data_type == kNumberTypeFloat32 && output_data_type == kNumberTypeInt32) { - Float32ToInt32(reinterpret_cast(input->MutableData()) + offset, + Float32ToInt32(reinterpret_cast(input->data_c()) + offset, reinterpret_cast(output_data) + offset, data_num); } else if (input_data_type == kNumberTypeFloat32 && output_data_type == kNumberTypeFloat16) { - Float32ToFp16(reinterpret_cast(input->MutableData()) + offset, + Float32ToFp16(reinterpret_cast(input->data_c()) + offset, reinterpret_cast(output_data) + offset, data_num); } else { MS_LOG(ERROR) << "Unsupported datatype from " << input_data_type << " to " << output_data_type; @@ -106,11 +107,6 @@ int CastCPUKernel::DoCast(int thread_id) { } int CastCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } if (data_num_ == 0) { return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc index 9d828819a8b..b4f38d4b965 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc @@ -75,11 +75,6 @@ int ConcatsRun(void *cdata, int task_id) { } int ConcatCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, ConcatsRun, this, thread_count_); return error_code; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc index 51656cd5a24..b025b607d52 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc @@ -52,11 +52,6 @@ int ConstantOfShapeRun(void *cdata, int task_id) { } int ConstantOfShapeCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } param_->element_sz_ = out_tensors_.front()->ElementsNum(); int thread_num = MSMIN(param_->op_parameter_.thread_num_, param_->element_sz_); param_->unit_ = UP_DIV(param_->element_sz_, thread_num); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc index db237d272f3..87c18fbcbf1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc @@ -141,12 +141,6 @@ int ConvolutionImpl(void *cdata, int task_id) { } int ConvolutionCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - auto ret = InitTmpBuffer(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init tmp buffer failed."; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc index d4478d4702a..7f204135a7a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc @@ -194,11 +194,6 @@ int Convolution1x1RunHw(void *cdata, int task_id) { } int Convolution1x1CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto src_in = reinterpret_cast(in_tensors_[0]->MutableData()); auto src_out = reinterpret_cast(out_tensors_[0]->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc index 7f564e163cc..4469fc02ddf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc @@ -101,19 +101,13 @@ int ConvDwRun(void *cdata, int task_id) { } int ConvolutionDepthwiseCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return ret; - } - auto input_tensor = in_tensors_.at(kInputIndex); input_ptr_ = reinterpret_cast(input_tensor->MutableData()); auto output_tensor = out_tensors_.at(kOutputIndex); output_ptr_ = reinterpret_cast(output_tensor->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, ConvDwRun, this, conv_param_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ConvDwRun, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwRun error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc index f337cb9f6c7..c157bd50116 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc @@ -134,12 +134,7 @@ int ConvDwSWRun(void *cdata, int task_id) { } int ConvolutionDepthwiseSWCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return ret; - } - ret = InitBuffer(); + auto ret = InitBuffer(); if (ret != 0) { MS_LOG(ERROR) << "Convolution depthwise fp32 InitBuffer failed."; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc index 60c2cbca392..1b7d0e7f1de 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc @@ -219,12 +219,6 @@ int ConvolutionWinogradImpl(void *cdata, int task_id) { } int ConvolutionWinogradCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - auto ret = InitTmpBuffer(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init tmp buffer failed."; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc index 323b674c91c..52140ae4778 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc @@ -53,11 +53,6 @@ int CropCPUKernel::CropParallelRun(int thread_id) { } int CropCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input = in_tensors_[0]; auto output = out_tensors_[0]; auto param = reinterpret_cast(op_parameter_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc index 584ab0da8a7..bebfd1f5667 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc @@ -196,11 +196,6 @@ int DeConvolutionCPUKernel::InitRunBuf() { } int DeConvolutionCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } float *src_in = reinterpret_cast(in_tensors_[0]->MutableData()); float *src_out = reinterpret_cast(out_tensors_[0]->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc index 36eb98bef79..e80f05f4b37 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc @@ -151,13 +151,7 @@ int DeconvolutionDepthwiseCPUKernel::Run() { return RET_ERROR; } - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - - ret = InitBuffer(); + auto ret = InitBuffer(); if (ret != 0) { MS_LOG(ERROR) << "Deconvolution depthwise fp32 InitBuffer failed.ret: " << ret; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc index 3e49a8d9d6e..b6e50a39c53 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc @@ -47,11 +47,6 @@ int DepthToSpaceCPUKernel::Init() { int DepthToSpaceCPUKernel::ReSize() { return DepthToSpaceBaseCPUKernel::ReSize(); } int DepthToSpaceCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input = in_tensors_[0]; auto output = out_tensors_[0]; const float *input_data = reinterpret_cast(input->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc index 25e6986e457..c2097ae9162 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc @@ -66,11 +66,6 @@ DetectionPostProcessCPUKernel::~DetectionPostProcessCPUKernel() { int DetectionPostProcessCPUKernel::ReSize() { return RET_OK; } int DetectionPostProcessCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input_boxes = reinterpret_cast(in_tensors_.at(0)->MutableData()); auto input_scores = reinterpret_cast(in_tensors_.at(1)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc index 900d07ff468..fd4c55b5df4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc @@ -57,11 +57,6 @@ int EluRun(void *cdata, int task_id) { } int EluCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } input_addr = reinterpret_cast(in_tensors_.front()->MutableData()); output_addr = reinterpret_cast(out_tensors_.front()->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc index 19d76e5eeb6..209aaf39067 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc @@ -72,12 +72,6 @@ int EmbeddingLookupRun(void *cdata, int task_id) { } int EmbeddingLookupCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - MS_ASSERT(context_->allocator != nullptr); input_addr_ = reinterpret_cast(context_->allocator->Malloc( sizeof(float) * embedding_lookup_parameter_->layer_size_ * embedding_lookup_parameter_->layer_num_)); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc index e2559a3daa7..98271d73eba 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc @@ -69,11 +69,6 @@ int ExpRun(void *cdata, int task_id) { } int ExpCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } input_addr_ = reinterpret_cast(in_tensors_.front()->MutableData()); output_addr_ = reinterpret_cast(out_tensors_.front()->MutableData()); exp_parameter_->element_num_ = in_tensors_.front()->ElementsNum(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc index 240438881a6..813b39b75ab 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc @@ -77,11 +77,6 @@ int ExpandDimsRun(void *cdata, int task_id) { } int ExpandDimsCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } in_ptr_ = in_tensors_.at(0)->MutableData(); out_ptr_ = out_tensors_.at(0)->MutableData(); auto ret = ParallelLaunch(this->context_->thread_pool_, ExpandDimsRun, this, thread_sz_count_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc index 3a1cd4697d9..f72fd6bcdbd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc @@ -67,11 +67,6 @@ int FillRun(void *cdata, int task_id) { } int FillCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto fillData = in_tensors_.at(in_tensors_.size() - 1); auto output = out_tensors_.front(); auto fill_data = reinterpret_cast(fillData->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc index 654772e4f00..5137fe9d837 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc @@ -44,11 +44,6 @@ int FlattenCPUKernel::ReSize() { } int FlattenCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input = reinterpret_cast(in_tensors_[0]->MutableData()); auto output = reinterpret_cast(out_tensors_[0]->MutableData()); Flatten(input, output, flatten_param_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc index 53e76b8d155..dfc4f91ccfc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc @@ -162,11 +162,6 @@ int FullconnectionCPUKernel::DoMatmul(int task_id) { } int FullconnectionCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto a_ptr = reinterpret_cast(in_tensors_.at(0)->data_c()); auto b_ptr = reinterpret_cast(in_tensors_.at(1)->data_c()); c_ptr_ = reinterpret_cast(out_tensors_.at(0)->data_c()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc index 1d45d4ba669..69a17850605 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc @@ -18,6 +18,8 @@ #include "src/kernel_registry.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_FusedBatchNorm; namespace mindspore::kernel { @@ -84,11 +86,6 @@ int FusedBatchnormCPUKernel::InitConstTensor() { } int FusedBatchnormCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! Ret error code: " << ret; - return ret; - } auto param = reinterpret_cast(op_parameter_); if (is_train() && in_tensors_.size() >= 5) { float *in = static_cast(in_tensors_[0]->MutableData()); @@ -108,7 +105,7 @@ int FusedBatchnormCPUKernel::Run() { memcpy(offset_, bias, in_tensors_[2]->Size()); trained_ = true; // trained at least once } - ret = ParallelLaunch(this->context_->thread_pool_, BatchNormRun, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, BatchNormRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; } @@ -137,7 +134,7 @@ int FusedBatchnormCPUKernel::DoExecute(int task_id) { auto param = reinterpret_cast(op_parameter_); FusedBatchNormFp32(in_tensors_.at(0)->MutableData(), scale_, offset_, mean_, variance_, param, task_id, out_tensors_.at(0)->MutableData()); - return mindspore::lite::RET_OK; + return RET_OK; } kernel::LiteKernel *CpuFusedBatchnormKernelCreator(const std::vector &inputs, diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc index 96d52426aa4..3b15c00e2b8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc @@ -91,12 +91,6 @@ int GatherRun(void *cdata, int task_id) { } int GatherCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - auto indices_tensor = in_tensors_.at(1); int indices_num = indices_tensor->ElementsNum(); bool isIndicesInt32 = indices_tensor->data_type() == kNumberTypeInt32; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc index 20fd199fefe..ab9e517fc3b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc @@ -116,11 +116,6 @@ int GatherNdRun(void *cdata, int task_id) { } int GatherNdCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } in_ptr_ = reinterpret_cast(in_tensors_.front()->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.front()->MutableData()); auto ret = ParallelLaunch(this->context_->thread_pool_, GatherNdRun, this, thread_sz_count_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc index c081056d083..5b621312170 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc @@ -141,17 +141,12 @@ int L2NormTrailingAxisRun(void *cdata, int task_id) { } int L2NormCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! ret: " << ret; - return ret; - } auto input_shape = in_tensors().at(kInputIndex)->shape(); input_ptr_ = reinterpret_cast(in_tensors_.at(kInputIndex)->MutableData()); output_ptr_ = reinterpret_cast(out_tensors_.at(kOutputIndex)->MutableData()); if (l2_norm_param_->axis_num_ == 0 || l2_norm_param_->axis_num_ == input_shape.size()) { // all axis - ret = ParallelLaunch(this->context_->thread_pool_, SquareSumRun, this, context_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SquareSumRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "L2Norm error: error_code[" << ret << "]"; return RET_ERROR; @@ -167,7 +162,7 @@ int L2NormCPUKernel::Run() { return RET_ERROR; } } else if (l2_norm_param_->axis_num_ == 1 && l2_norm_param_->axis_[0] == static_cast(input_shape.size()) - 1) { - ret = ParallelLaunch(this->context_->thread_pool_, L2NormTrailingAxisRun, this, context_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, L2NormTrailingAxisRun, this, context_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "L2Norm error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc index f5d3870ea55..7f14ffd1214 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc @@ -74,11 +74,6 @@ int LocalResponseNormRun(void *cdata, int task_id) { } int LocalResponseNormCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, LocalResponseNormRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "LocalResponseNorm function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc index 1fff7550c62..4bbe6aa2c56 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc @@ -147,11 +147,6 @@ int LstmCPUKernel::ReSize() { } int LstmCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input = in_tensors_.at(kInputIndex); MS_ASSERT(input != nullptr); auto hidden_state = in_tensors_.at(4); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc index 23add99a658..43da9817302 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc @@ -281,11 +281,6 @@ int MatmulFloatRun(void *cdata, int task_id) { } int MatmulCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto a_src = reinterpret_cast(in_tensors_[0]->data_c()); auto b_src = reinterpret_cast(in_tensors_[1]->data_c()); auto c_src = reinterpret_cast(out_tensors_[0]->data_c()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc index 61cb77a6248..91d158393e1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc @@ -28,11 +28,6 @@ int Nchw2NhwcCPUKernel::Init() { return RET_OK; } int Nchw2NhwcCPUKernel::ReSize() { return RET_OK; } int Nchw2NhwcCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input = in_tensors_[0]; auto output = out_tensors_[0]; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc index 58e048e9b41..666d64f660a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc @@ -28,11 +28,6 @@ int Nhwc2NchwCPUKernel::Init() { return RET_OK; } int Nhwc2NchwCPUKernel::ReSize() { return RET_OK; } int Nhwc2NchwCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto input = in_tensors_[0]; auto output = out_tensors_[0]; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc index ef48273ab69..1aae9499c3d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc @@ -161,11 +161,6 @@ int OneHotCPUKernel::GetParams() { } int OneHotCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, RunOneHot, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "OneHot function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc index c2a025363a9..a8eede6ddf2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc @@ -227,12 +227,6 @@ int PadCPUKernel::HandleMirrorPad() { } int PadCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - int error_code; if (pad_param_->pad_mode_ == static_cast(schema::PaddingMode_CONSTANT)) { auto output = out_tensors_.at(0); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc index 33855c1737a..3649b08e8f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc @@ -84,11 +84,6 @@ int PoolingImpl(void *cdata, int task_id) { } int PoolingCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, PoolingImpl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "pooling error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc index 7fb24f8cdc6..65ca75c8dd7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc @@ -41,11 +41,6 @@ int PowerImpl(void *cdata, int task_id) { } int PowerCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto ret = ParallelLaunch(this->context_->thread_pool_, PowerImpl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "PowerCPUKernel error: " << ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc index 67c9bdd6d5b..d978a251e83 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc @@ -107,11 +107,6 @@ int PReluCPUKernel::ProcessShareChannelInput() { } int PReluCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } MS_ASSERT(in_shape.size() >= 2); auto input_tensor = in_tensors_[0]; ori_input_ = reinterpret_cast(input_tensor->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc index 23c6f6aabd2..a457e165671 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc @@ -32,11 +32,6 @@ int RangeCPUKernel::Init() { return RET_OK; } int RangeCPUKernel::ReSize() { return RET_OK; } int RangeCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } size_t start = (reinterpret_cast(op_parameter_))->start_; size_t limit = (reinterpret_cast(op_parameter_))->limit_; size_t delta = (reinterpret_cast(op_parameter_))->delta_; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc index 636112dbda3..753c1385425 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc @@ -32,11 +32,6 @@ int RankCPUKernel::Init() { return RET_OK; } int RankCPUKernel::ReSize() { return RET_OK; } int RankCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } auto output_ptr = reinterpret_cast(out_tensors_.at(0)->MutableData()); auto in_shape = in_tensors_[0]->shape(); auto rank = in_shape.size(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc index 68857445035..df2565587d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc @@ -113,11 +113,6 @@ int ReduceImpl(void *cdata, int task_id) { } int ReduceCPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } if (in_tensors().at(0)->data_type() == kNumberTypeFloat32) { data_type_ = kDataTypeFloat; } else { @@ -129,8 +124,8 @@ int ReduceCPUKernel::Run() { return ret; } - src_data_ = in_tensors_.at(0)->MutableData(); - PreProcess(); + src_data_ = in_tensors_.at(0)->data_c(); + HandleASumAndSumSquare(); for (size_t i = 0; i < static_cast(num_axes_); ++i) { if (i != static_cast(num_axes_ - 1)) { dst_data_ = data_buffers_[i]; @@ -159,12 +154,12 @@ int ReduceCPUKernel::Run() { return RET_OK; } -void ReduceCPUKernel::PreProcess() { +void ReduceCPUKernel::HandleASumAndSumSquare() { if (data_type_ == kDataTypeInt) { return; } int num = in_tensors_.at(0)->ElementsNum(); - float *data = reinterpret_cast(in_tensors_.at(0)->MutableData()); + float *data = reinterpret_cast(in_tensors_.at(0)->data_c()); if (data == nullptr) { return; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h index dae1e748d14..e7bc495c0fb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h @@ -65,7 +65,7 @@ class ReduceCPUKernel : public ReduceBaseCPUKernel { int MallocTmpBuffer(); void FreeTmpBuffer(); int CalculateCoeffOutput(); - void PreProcess(); + void HandleASumAndSumSquare(); }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc index d3705caa892..edf9022628e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc @@ -36,11 +36,6 @@ int ReshapeCPUKernel::Init() { int ReshapeCPUKernel::ReSize() { return RET_OK; } int ReshapeCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input_ptr = in_tensors_.at(kInputIndex)->MutableData(); auto output_ptr = out_tensors_.at(kOutputIndex)->MutableData(); size_t data_size = in_tensors_.at(kInputIndex)->Size(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc index cff4535ee4e..badc28893de 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc @@ -204,11 +204,6 @@ int ResizeCPUKernel::RunImpl(int task_id) { } int ResizeCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } int error_code = ParallelLaunch(this->context_->thread_pool_, ResizeImpl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Resize run error, error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc index 9734f13cf99..6ecee311895 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc @@ -125,14 +125,9 @@ int ReverseCPUKernel::DoReverse(int task_id) { } int ReverseCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } in_ptr_ = reinterpret_cast(in_tensors_[0]->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_[0]->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, ReverseRun, this, thread_sz_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ReverseRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "Reverse run error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc index df23b8a39ec..ad69092a1b7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc @@ -87,11 +87,6 @@ int ReverseSequenceCPUKernel::ReSize() { } int ReverseSequenceCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } float *input0 = reinterpret_cast(in_tensors_.at(0)->MutableData()); void *input1 = in_tensors_.at(1)->MutableData(); float *output = reinterpret_cast(out_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc index b591cc71050..6815664a934 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc @@ -93,15 +93,10 @@ int ROIPoolingRun(void *cdata, int task_id) { } int ROIPoolingCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! ret: " << ret; - return ret; - } in_ptr_ = reinterpret_cast(in_tensors_.front()->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.front()->MutableData()); roi_ptr_ = reinterpret_cast(in_tensors_.at(1)->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, ROIPoolingRun, this, param_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ROIPoolingRun, this, param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ROIPooling error: error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc index 7dfdcde954e..3554047a815 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc @@ -174,11 +174,6 @@ int ScaleRun(void *cdata, int task_id) { } int ScaleCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto in_tensor = in_tensors_.front(); input_ptr_ = reinterpret_cast(in_tensor->data_c()); if (!scale_param_->const_scale_) { @@ -193,7 +188,7 @@ int ScaleCPUKernel::Run() { auto out_tensor = out_tensors_.front(); output_ptr_ = reinterpret_cast(out_tensor->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, ScaleRun, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ScaleRun, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc index f34d1a220c5..b0c5bdbcd97 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc @@ -148,12 +148,7 @@ int ScatterNDRun(void *cdata, int task_id) { } int ScatterNDCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - ret = ParallelLaunch(this->context_->thread_pool_, ScatterNDRun, this, thread_n_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ScatterNDRun, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ScatterND error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc index d2a511f76ba..b8f1231d551 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc @@ -31,11 +31,6 @@ int ShapeCPUKernel::Init() { return RET_OK; } int ShapeCPUKernel::ReSize() { return RET_OK; } int ShapeCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return RET_ERROR; - } auto out_tensor = out_tensors_.front(); auto in_tensor = in_tensors_.front(); if (in_tensor == nullptr || out_tensor == nullptr) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc index 212116c01a3..55cba92765f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc @@ -19,6 +19,8 @@ #include "src/ops/slice.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Slice; namespace mindspore::kernel { @@ -68,9 +70,9 @@ int SliceCPUKernel::SliceParallelRun(int thread_id) { } int SliceCPUKernel::Run() { - auto ret = Prepare(); + auto ret = PreProcess(); if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; + MS_LOG(ERROR) << "PreProcess fail!ret: " << ret; return ret; } const float *input_data = reinterpret_cast(in_tensors_[0]->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc index 3abff61d56f..47ef0cd1013 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc @@ -71,11 +71,6 @@ int SoftmaxCPUKernel::ReSize() { } int SoftmaxCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return RET_ERROR; - } memset(sum_data_, 0, in_plane_size_ * out_plane_size_ * sizeof(float)); auto input_ptr = reinterpret_cast(in_tensors_.at(kInputIndex)->MutableData()); auto output_ptr = reinterpret_cast(out_tensors_.at(kOutputIndex)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc index c893a467b7d..3bb2f7ca1ab 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc @@ -65,11 +65,6 @@ int SpaceToBatchCPUKernel::ReSize() { } int SpaceToBatchCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input_tensor = in_tensors_.at(0); auto output_tensor = out_tensors_.at(0); auto input_ptr = reinterpret_cast(input_tensor->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc index 42ed11f745f..dc1cb5b1528 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc @@ -85,15 +85,10 @@ int SpaceToDepthRun(void *cdata, int task_id) { } int SpaceToDepthCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } input_ptr_ = reinterpret_cast(in_tensors_[0]->MutableData()); output_ptr_ = reinterpret_cast(out_tensors_[0]->MutableData()); if (in_tensors_[0]->GetFormat() == schema::Format::Format_NHWC) { - ret = ParallelLaunch(this->context_->thread_pool_, SpaceToDepthRun, this, thread_h_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SpaceToDepthRun, this, thread_h_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SpaceToDepth error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc index 24b49d7cc10..909cb64350b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc @@ -152,13 +152,8 @@ int SparseToDenseCPUKernel::IndicesValidCheck() { } int SparseToDenseCPUKernel::Run() { - auto ret = Prepare(); + auto ret = GenerateIndices(); if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - auto ret1 = GenerateIndices(); - if (ret1 != RET_OK) { MS_LOG(ERROR) << "Generate Indices failed."; return RET_ERROR; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc index f9af0c6ebb5..5a2c84244e8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc @@ -73,17 +73,12 @@ int SplitRun(void *cdata, int task_id) { } int SplitCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto in_tensor = in_tensors_.front(); input_ptr_ = reinterpret_cast(in_tensor->MutableData()); for (int i = 0; i < param->num_split_; i++) { output_ptr_[i] = reinterpret_cast(out_tensors_.at(i)->MutableData()); } - ret = ParallelLaunch(this->context_->thread_pool_, SplitRun, this, thread_n_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SplitRun, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc index 6287d76d920..c1df45b99f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc @@ -32,12 +32,7 @@ int SqueezeCPUKernel::Init() { return RET_OK; } int SqueezeCPUKernel::ReSize() { return RET_OK; } int SqueezeCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - + mindspore::lite::STATUS ret = RET_ERROR; size_t data_size = in_tensors_.front()->Size(); if (in_tensors_.front()->data_type() == kNumberTypeInt32) { auto input_ptr = reinterpret_cast(in_tensors_.front()->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc index 97e8bf4566c..006e3561277 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc @@ -43,11 +43,6 @@ int StackCPUKernel::Init() { } int StackCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } size_t inputs_num = in_tensors_.size(); auto input0 = in_tensors_[0]; if (inputs_num == 1) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc index 8bd0a16e67d..82e88bfbf8e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc @@ -51,11 +51,6 @@ int TileCPUKernel::ReSize() { } int TileCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input_addr = reinterpret_cast(in_tensors_.at(0)->MutableData()); auto output_addr = reinterpret_cast(out_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc index c862c7464ea..b3fa29b4ad5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc @@ -45,11 +45,6 @@ int TopKCPUKernel::ReSize() { } int TopKCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto input_data = reinterpret_cast(in_tensors_.at(0)->MutableData()); auto output_data = reinterpret_cast(out_tensors_.at(0)->MutableData()); auto output_index = reinterpret_cast(out_tensors_.at(1)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc index 1aa181a16f6..be9847f50c4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc @@ -110,11 +110,6 @@ int TransposeRun(void *cdata, int task_id) { } int TransposeCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } MS_ASSERT(in_tensors_.size() == TransposeInputNum); MS_ASSERT(out_tensors_.size() == TransposeOutputNum); auto &in_tensor = in_tensors_.front(); @@ -126,7 +121,7 @@ int TransposeCPUKernel::Run() { in_data_ = reinterpret_cast(in_tensor->MutableData()); out_data_ = reinterpret_cast(out_tensor->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, TransposeRun, this, thread_h_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, TransposeRun, this, thread_h_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Tranpose error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc index 11c07fd60f6..7e09f3de137 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc @@ -28,11 +28,6 @@ int UniqueCPUKernel::Init() { return RET_OK; } int UniqueCPUKernel::ReSize() { return RET_OK; } int UniqueCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto input = reinterpret_cast(in_tensors_.at(0)->MutableData()); auto output0 = reinterpret_cast(out_tensors_.at(0)->MutableData()); auto output1 = reinterpret_cast(out_tensors_.at(1)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc index 8bfc148ce7e..6c79b4ef973 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc @@ -66,14 +66,9 @@ int UnsqueezeRun(void *cdata, int task_id) { } int UnsqueezeCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } in_ptr_ = reinterpret_cast(in_tensors_.at(0)->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, UnsqueezeRun, this, thread_sz_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, UnsqueezeRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "UnsqueezeRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc index 0f953b60d59..bc82fa3d472 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc @@ -64,11 +64,6 @@ int UnstackCPUKernel::ReSize() { } int UnstackCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } float *input = reinterpret_cast(in_tensors_.at(0)->MutableData()); size_t out_num = out_tensors_.size(); for (size_t i = 0; i < out_num; i++) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc index b5f0712bd0e..696798bd40e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc @@ -48,11 +48,6 @@ int WhereRun(void *cdata, int task_id) { return RET_OK; } int WhereCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto input = in_tensors_.at(0); auto input1 = in_tensors_.at(1); auto input2 = in_tensors_.at(2); @@ -79,7 +74,7 @@ int WhereCPUKernel::Run() { MS_LOG(ERROR) << "Error, inputs' length are zero !!!"; return RET_ERROR; } - ret = ParallelLaunch(this->context_->thread_pool_, WhereRun, this, where_param_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, WhereRun, this, where_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "WhereDwRun error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc index 2e321530e3e..53a9f8cb045 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc @@ -30,11 +30,6 @@ namespace mindspore::kernel { int ZerosLikeCPUKernel::Init() { return RET_OK; } int ZerosLikeCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto input = in_tensors_.at(0); auto input_data = reinterpret_cast(input->MutableData()); auto output_data = reinterpret_cast(out_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc index cb94fab7a08..73b99be7bdb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc @@ -96,12 +96,6 @@ int ActivationGradRun(void *cdata, int task_id) { } int ActivationGradCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "ActivationGradCPUKernel Prepare failed."; - return ret; - } - int error_code = ParallelLaunch(this->context_->thread_pool_, ActivationGradRun, this, 1); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation Grad function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc index 53dc80c843c..2c533efcb28 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc @@ -82,9 +82,9 @@ int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::GradPostExecute(const int *lab } int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Execute(int task_id) { - auto ins = reinterpret_cast(in_tensors_.at(0)->MutableData()); - auto labels = reinterpret_cast(in_tensors_.at(1)->MutableData()); - float *out = reinterpret_cast(out_tensors_.at(0)->MutableData()); + auto ins = reinterpret_cast(in_tensors_.at(0)->data_c()); + auto labels = reinterpret_cast(in_tensors_.at(1)->data_c()); + float *out = reinterpret_cast(out_tensors_.at(0)->data_c()); float *grads = NULL; if (is_train() && out_tensors_.size() > 1) { grads = reinterpret_cast(out_tensors_.at(1)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc index eed2fd2f7de..21c9f775d70 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc @@ -24,6 +24,7 @@ #include "include/errorcode.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Add; @@ -76,11 +77,6 @@ int QuantizedAddCPUKernel::Init() { int QuantizedAddCPUKernel::ReSize() { return 0; } int QuantizedAddCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } input0_data_ = static_cast(in_tensors_.at(0)->MutableData()); input1_data_ = static_cast(in_tensors_.at(1)->MutableData()); output_data_ = static_cast(out_tensors_.at(0)->MutableData()); @@ -100,13 +96,13 @@ int QuantizedAddCPUKernel::Run() { static_cast(in_tensors_.at(1)->MutableData()), reinterpret_cast(input0_data_), reinterpret_cast(input1_data_), arith_para_); - ret = ParallelLaunch(this->context_->thread_pool_, AddInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, AddInt8Run, this, thread_count_); ctx_->allocator->Free(input0_data_); ctx_->allocator->Free(input1_data_); return ret; } - ret = ParallelLaunch(this->context_->thread_pool_, AddInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, AddInt8Run, this, thread_count_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc index eb5b338a3b0..3cdb0f1d12a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc @@ -49,11 +49,6 @@ int ArgMinMaxInt8CPUKernel::Init() { int ArgMinMaxInt8CPUKernel::ReSize() { return ArgMinMaxBaseCPUKernel::ReSize(); } int ArgMinMaxInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input = in_tensors_.at(0); const int8_t *input_data = reinterpret_cast(in_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc index 50df6da2557..6d4bb031159 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc @@ -130,11 +130,6 @@ int ArithmeticInt8CPUKernel::DoArithmetic(int thread_id) { } int ArithmeticInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto param = reinterpret_cast(op_parameter_); if (param->broadcasting_) { auto input_data0 = reinterpret_cast(in_tensors_[0]->MutableData()); @@ -149,7 +144,7 @@ int ArithmeticInt8CPUKernel::Run() { } TileDimensionsInt8(input_data0, input_data1, tile_data0_, tile_data1_, param); } - ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticsInt8Launch, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticsInt8Launch, this, op_parameter_->thread_num_); if (param->broadcasting_) { context_->allocator->Free(tile_data0_); context_->allocator->Free(tile_data1_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc index 43307f6a43a..dce0fa49e8f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc @@ -95,16 +95,11 @@ int ArithmeticSelfInt8CPUKernel::DoArithmeticSelf(int task_id) { } int ArithmeticSelfInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input_tensor = in_tensors_.at(0); auto out_tensor = out_tensors_.at(0); in_ptr_ = reinterpret_cast(input_tensor->MutableData()); out_ptr_ = reinterpret_cast(out_tensor->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticSelfInt8Runs, this, thread_sz_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ArithmeticSelfInt8Runs, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc index 31c0d14445c..9338b548777 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc @@ -47,11 +47,6 @@ int BatchToSpaceInt8CPUKernel::Init() { int BatchToSpaceInt8CPUKernel::ReSize() { return BatchToSpaceBaseCPUKernel::ReSize(); } int BatchToSpaceInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input = in_tensors_[0]; auto output = out_tensors_[0]; const int8_t *input_data = reinterpret_cast(input->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc index f3c6cc2cf61..fad96cc86a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc @@ -185,15 +185,10 @@ int BatchNormInt8Run(void *cdata, int task_id) { } int BatchnormInt8CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! Ret error code: " << prepare_ret; - return prepare_ret; - } in_addr_ = reinterpret_cast(in_tensors_.at(0)->MutableData()); out_addr_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - int ret = + auto ret = ParallelLaunch(this->context_->thread_pool_, BatchNormInt8Run, this, batchnorm_param_->op_parameter_.thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc index 79fc9fd819f..3ac7e3f93f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc @@ -46,11 +46,6 @@ int BiasAddInt8CPUKernel::ReSize() { } int BiasAddInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto in = reinterpret_cast(in_tensors_.at(0)->MutableData()); auto bias = reinterpret_cast(in_tensors_.at(1)->MutableData()); auto out = reinterpret_cast(out_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc index 8120b3fb9ce..8ea35460aa2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc @@ -108,12 +108,6 @@ int ConcatInt8CPUKernel::ReSize() { } int ConcatInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - auto input_num = concat_param_->input_num_; count_unit_ = thread_count_ > 1 ? UP_DIV(before_axis_size, thread_count_) : before_axis_size; concat_param_->count_unit_ = count_unit_; @@ -123,7 +117,7 @@ int ConcatInt8CPUKernel::Run() { } output_data_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, ConcatInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ConcatInt8Run, this, thread_count_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc index 8882842a041..7b1f38d510c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_1x1_int8.cc @@ -454,12 +454,6 @@ void Convolution1x1Int8CPUKernel::FreeRunBuf() { } int Convolution1x1Int8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - int error_code = InitRunBuf(); if (error_code != RET_OK) { MS_LOG(ERROR) << "conv1x1 int8 InitRunBuf error_code[" << error_code << "]"; @@ -473,7 +467,12 @@ int Convolution1x1Int8CPUKernel::Run() { for (int batch_index = 0; batch_index < conv_param_->input_batch_; batch_index++) { Pre1x1Trans(src_in + batch_index * conv_param_->input_h_ * conv_param_->input_w_ * conv_param_->input_channel_, src_out + batch_index * matmul_param_->row_ * matmul_param_->col_); - ParallelLaunch(this->context_->thread_pool_, Convolution1x1Int8Impl, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, Convolution1x1Int8Impl, this, thread_count_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "ParallelLaunch run error error_code[" << ret << "]"; + FreeRunBuf(); + return ret; + } } FreeRunBuf(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc index 9cdde50671a..81f9de19466 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc @@ -213,13 +213,8 @@ int Convolution3x3Int8Impl(void *cdata, int task_id) { } int Convolution3x3Int8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } // malloc tmp buffer - ret = InitTmpBuffer(); + auto ret = InitTmpBuffer(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init tmp buffer failed."; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc index 8fd16253613..be919fb0b93 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc @@ -140,12 +140,7 @@ int ConvolutionDepthwiseInt8CPUKernel::InitBuffer() { } int ConvolutionDepthwiseInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - ret = InitBuffer(); + auto ret = InitBuffer(); if (ret != RET_OK) { MS_LOG(ERROR) << "Depthwise int8 ReSize error!"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc index 604d604fabb..d625bf619dd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_slidewindow_int8.cc @@ -321,13 +321,7 @@ int ConvDwSWInt8Run(void *cdata, int task_id) { } int ConvolutionDepthwiseSWInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - - ret = InitBuffer(); + auto ret = InitBuffer(); if (ret != RET_OK) { MS_LOG(ERROR) << "Depthwise int8 ReSize error!"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc index 259fbe038d5..c48aafc2d9b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc @@ -15,13 +15,13 @@ */ #include "src/runtime/kernel/arm/int8/convolution_int8.h" -#include "src/runtime/kernel/arm/int8/convolution_3x3_int8.h" -#include "src/runtime/kernel/arm/int8/convolution_1x1_int8.h" +#include "include/errorcode.h" #include "nnacl/int8/conv_int8.h" -#include "src/runtime/kernel/arm/base/layout_transform.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "include/errorcode.h" +#include "src/runtime/kernel/arm/base/layout_transform.h" +#include "src/runtime/kernel/arm/int8/convolution_1x1_int8.h" +#include "src/runtime/kernel/arm/int8/convolution_3x3_int8.h" #include "src/runtime/runtime_api.h" using mindspore::kernel::KERNEL_ARCH::kCPU; @@ -325,20 +325,14 @@ int ConvolutionInt8Impl(void *cdata, int task_id) { } int ConvolutionInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - if (support_optimize_) { - ret = InitTmpBufferOpt(); + auto ret = InitTmpBufferOpt(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init tmp buffer failed."; return RET_ERROR; } } else { - ret = InitTmpBuffer(); + auto ret = InitTmpBuffer(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init tmp buffer failed."; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc index 0d02ee04b74..e3dcfdc6849 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc @@ -65,12 +65,7 @@ CropInt8CPUKernel::~CropInt8CPUKernel() { int CropInt8CPUKernel::ReSize() { return CropBaseCPUKernel::ReSize(); } int CropInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - ret = ParallelLaunch(this->context_->thread_pool_, CropInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, CropInt8Run, this, thread_count_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc index 0b9785c764b..c58ce8d1295 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc @@ -175,11 +175,6 @@ int DeconvDwInt8Run(void *cdata, int task_id) { } int DeconvolutionDepthwiseInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -196,7 +191,7 @@ int DeconvolutionDepthwiseInt8CPUKernel::Run() { packed_output_ = output_addr; } - ret = ParallelLaunch(this->context_->thread_pool_, DeconvDwInt8Run, this, conv_param_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, DeconvDwInt8Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "DeconvDwInt8Run error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc index 83b34cddfd5..eb6d88455f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc @@ -258,11 +258,6 @@ int DeConvInt8CPUKernel::DoDeconv(int task_id) { } int DeConvInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } int8_t *src_in = reinterpret_cast(in_tensors_[0]->MutableData()); int8_t *src_out = reinterpret_cast(out_tensors_[0]->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc index dd37e370be0..8a582f0e4d6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc @@ -51,11 +51,6 @@ int DepthToSpaceInt8CPUKernel::Init() { int DepthToSpaceInt8CPUKernel::ReSize() { return DepthToSpaceBaseCPUKernel::ReSize(); } int DepthToSpaceInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input = in_tensors_[0]; auto output = out_tensors_[0]; const int8_t *input_data = reinterpret_cast(input->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc index 4785f2aae41..c72c63c3928 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc @@ -23,6 +23,7 @@ #include "include/errorcode.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Div; @@ -95,12 +96,6 @@ int DivInt8Run(void *cdata, int task_id) { } int DivInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - if (broadcast_) { ArithmeticParameter tile_para; tile_para.ndim_ = out_tensors_.at(0)->shape().size(); @@ -121,7 +116,7 @@ int DivInt8CPUKernel::Run() { static_cast(in_tensors_.at(1)->MutableData()), reinterpret_cast(tile0_data_), reinterpret_cast(tile1_data_), &tile_para); } - ret = ParallelLaunch(this->context_->thread_pool_, DivInt8Run, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, DivInt8Run, this, op_parameter_->thread_num_); if (broadcast_) { context_->allocator->Free(tile0_data_); context_->allocator->Free(tile1_data_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc index 82e96104ae3..563e1183c93 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc @@ -134,11 +134,6 @@ int FcInt8Run(void *cdata, int task_id) { } int FullconnectionInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto input_ptr = reinterpret_cast(in_tensors_[0]->data_c()); RowMajor2Row16x4MajorInt8(input_ptr, a_r4x16_ptr_, fc_param_->row_, fc_param_->deep_); CalcInputSums(input_ptr, fc_param_->row_, fc_param_->deep_, quant_params_.weight.zp_, input_sums_, RowMajor); @@ -148,7 +143,11 @@ int FullconnectionInt8CPUKernel::Run() { CalcWeightBiasSums(weight_data, fc_param_->deep_, fc_param_->col_, quant_params_.input.zp_, quant_params_.weight.zp_, bias_ptr_, weight_bias_sums_, ColMajor); } - ParallelLaunch(this->context_->thread_pool_, FcInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, FcInt8Run, this, thread_count_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "ParallelLaunch failed"; + return ret; + } return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc index aae2c94dd7b..3a45ae3e327 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc @@ -125,11 +125,6 @@ int GatherNdInt8Run(void *cdata, int task_id) { } int GatherNdInt8CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } in_ptr_ = reinterpret_cast(in_tensors_.front()->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.front()->MutableData()); auto ret = ParallelLaunch(this->context_->thread_pool_, GatherNdInt8Run, this, thread_sz_count_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc index 0867a98d231..57deca7104d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc @@ -105,12 +105,6 @@ int GatherInt8Run(void *cdata, int task_id) { } int GatherInt8CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } - int error_code = ParallelLaunch(this->context_->thread_pool_, GatherInt8Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Gather function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc index ebec77a096c..db2b1da4624 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc @@ -89,11 +89,6 @@ int HswishInt8Run(void *cdata, int task_id) { } int HswishInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } int error_code = ParallelLaunch(this->context_->thread_pool_, HswishInt8Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "HswishInt8Run function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc index ce00925b723..7b33f5c521b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc @@ -115,12 +115,7 @@ int LeakyReluInt8CPUKernel::ReSize() { } int LeakyReluInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } - ret = ParallelLaunch(this->context_->thread_pool_, LeakyReluInt8Run, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, LeakyReluInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "RunPreluParam failed. errorcode: "; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc index 3952c0798b5..1d4e96f8afb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc @@ -149,11 +149,6 @@ int MatmulInt8Run(void *cdata, int task_id) { } int MatmulInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } auto a_ptr = reinterpret_cast(in_tensors_[0]->data_c()); auto c_ptr = reinterpret_cast(out_tensors_[0]->data_c()); auto a_stride = params_->row_ * params_->deep_; @@ -190,7 +185,7 @@ int MatmulInt8CPUKernel::Run() { b_c16x4_ptr_ = b_c16x4_batch_ + i * params_->col_4_ * params_->deep_16_; weight_bias_sums_ = weight_bias_sums_batch_ + i * params_->col_4_; c_ptr_ = c_ptr + i * c_stride; - ret = ParallelLaunch(this->context_->thread_pool_, MatmulInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, MatmulInt8Run, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "MatmulInt8Run error: [" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc index 25809304f25..80bccc5c499 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc @@ -102,11 +102,6 @@ int MulInt8CPUKernel::ReSize() { } int MulInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } input0_data_ = static_cast(in_tensors_.at(0)->MutableData()); input1_data_ = static_cast(in_tensors_.at(1)->MutableData()); output_data_ = static_cast(out_tensors_.at(0)->MutableData()); @@ -122,13 +117,13 @@ int MulInt8CPUKernel::Run() { } TileDimensionsInt8(static_cast(in_tensors_.at(0)->MutableData()), static_cast(in_tensors_.at(1)->MutableData()), input0_data_, input1_data_, tile_para); - ret = ParallelLaunch(this->context_->thread_pool_, MulInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, MulInt8Run, this, thread_count_); ctx_->allocator->Free(input0_data_); ctx_->allocator->Free(input1_data_); return ret; } - ret = ParallelLaunch(this->context_->thread_pool_, MulInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, MulInt8Run, this, thread_count_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc index b5885fb6e5f..9d58af40302 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc @@ -249,11 +249,6 @@ int PadInt8CPUKernel::CopyPaddingFromInput() { } int PadInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } in_data_ = reinterpret_cast(in_tensors_[0]->MutableData()); out_data_ = reinterpret_cast(out_tensors_[0]->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc index 48bcccc9a60..0b171ee81fe 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc @@ -88,11 +88,6 @@ int PoolingInt8Impl(void *cdata, int task_id) { } int PoolingInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } int error_code = ParallelLaunch(this->context_->thread_pool_, PoolingInt8Impl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "poolingInt8 error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc index e5b10c50f0a..ce3966a7fe3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc @@ -98,12 +98,7 @@ int PowerInt8Run(void *cdata, int task_id) { } int PowerInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return ret; - } - ret = ParallelLaunch(this->context_->thread_pool_, PowerInt8Run, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, PowerInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "PowerInt8Run error, error_code[" << ret << "]"; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc index 877d8f009ae..31a34ec03a9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reduce_int8.cc @@ -247,11 +247,6 @@ void ReduceInt8CPUKernel::GetQuantArgs(size_t i) { } int ReduceInt8CPUKernel::Run() { - auto prepare_ret = Prepare(); - if (prepare_ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; - return prepare_ret; - } if (!this->valid_shape_) { auto ret = CalculateQuantArgs(); if (ret != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc index 8b1990142b9..95afe7e96e2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc @@ -69,11 +69,6 @@ int ReluXInt8Run(void *cdata, int task_id) { } int ReluXInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, ReluXInt8Run, this, op_parameter_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "ReluXInt8Run function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc index 590faa70a53..75efecc8cb4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc @@ -47,11 +47,6 @@ int ReshapeInt8CPUKernel::Init() { int ReshapeInt8CPUKernel::ReSize() { return 0; } int ReshapeInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } MS_ASSERT(in_tensors_.size() == 1); MS_ASSERT(out_tensors_.size() == 1); input_data_ = static_cast(in_tensors_.at(kInputIndex)->MutableData()); @@ -60,7 +55,7 @@ int ReshapeInt8CPUKernel::Run() { elements_num_ = in_tensors_.at(kInputIndex)->ElementsNum(); count_unit_ = op_parameter_->thread_num_ > 1 ? UP_DIV(elements_num_, op_parameter_->thread_num_) : elements_num_; - ret = ParallelLaunch(this->context_->thread_pool_, ReshapeInt8Run, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ReshapeInt8Run, this, op_parameter_->thread_num_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc index be9bdb37858..675d103e3b4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc @@ -119,11 +119,6 @@ int ResizeInt8CPUKernel::RunImpl(int task_id) { } int ResizeInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } int error_code = ParallelLaunch(this->context_->thread_pool_, ResizeInt8Impl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Resize run error, error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc index c5980d68f97..a06c821dce5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc @@ -241,11 +241,6 @@ int ScaleRunInt8(void *cdata, int task_id) { } int ScaleInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto in_tensor = in_tensors_.front(); input_ptr_ = reinterpret_cast(in_tensor->data_c()); if (scale_ == nullptr) { @@ -258,7 +253,7 @@ int ScaleInt8CPUKernel::Run() { auto out_tensor = out_tensors_.front(); output_ptr_ = reinterpret_cast(out_tensor->data_c()); - ret = ParallelLaunch(this->context_->thread_pool_, ScaleRunInt8, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ScaleRunInt8, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc index c4ff588c2aa..576ff4fc8c4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc @@ -87,11 +87,6 @@ int SigmoidInt8Run(void *cdata, int task_id) { } int SigmoidInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } int error_code = ParallelLaunch(this->context_->thread_pool_, SigmoidInt8Run, this, op_parameter_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "SigmoidInt8Run function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc index b47819fb583..a83a23a903c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc @@ -71,15 +71,10 @@ int SliceInt8Run(void *cdata, int task_id) { } int SliceInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return ret; - } - const int8_t *input_data = reinterpret_cast(in_tensors_[0]->MutableData()); int8_t *output_data = reinterpret_cast(out_tensors_[0]->MutableData()); + mindspore::lite::STATUS ret = RET_ERROR; if (param_->size_[1] < param_->op_parameter_.thread_num_) { ret = SliceInt8NoParallel(input_data, output_data, param_); } else { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc index f0b6cbb5b7d..fa999539007 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc @@ -103,11 +103,6 @@ int SoftmaxRun(void *cdata, int task_id) { } int SoftmaxInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return RET_ERROR; - } exp_data_ = reinterpret_cast(context_->allocator->Malloc(softmax_param_->element_size_ * sizeof(int))); int inner_size = 1; for (int i = softmax_param_->axis_ + 1; i < softmax_param_->n_dim_; i++) { @@ -120,7 +115,7 @@ int SoftmaxInt8CPUKernel::Run() { context_->allocator->Free(sum_data_); return RET_ERROR; } - ret = ParallelLaunch(this->context_->thread_pool_, SoftmaxRun, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SoftmaxRun, this, thread_count_); context_->allocator->Free(exp_data_); context_->allocator->Free(sum_data_); if (ret != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc index 19a3ecfa6a2..1460f979b49 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc @@ -26,11 +26,6 @@ using mindspore::schema::PrimitiveType_SpaceToBatchND; namespace mindspore::kernel { int SpaceToBatchInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input_tensor = in_tensors_.at(0); auto output_tensor = out_tensors_.at(0); auto input_ptr = reinterpret_cast(input_tensor->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc index 9d685a11269..be906a85f88 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc @@ -82,11 +82,6 @@ int SplitInt8Run(void *cdata, int task_id) { } int SplitInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return ret; - } auto in_tensor = in_tensors_.at(kInputIndex); input_ptr_ = reinterpret_cast(in_tensor->MutableData()); MS_ASSERT(param->num_split_ == outputs_.size()); @@ -94,7 +89,7 @@ int SplitInt8CPUKernel::Run() { output_ptr_.push_back(reinterpret_cast(out_tensors_.at(i)->MutableData())); } - ret = ParallelLaunch(this->context_->thread_pool_, SplitInt8Run, this, thread_n_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SplitInt8Run, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc index 83345e4aee7..b13ff764aa5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc @@ -128,11 +128,6 @@ int SqueezeInt8CPUKernel::ReSize() { } int SqueezeInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } auto input_dim = quant_Squeeze_parm_->input_num_; int8_t **inputs_array = reinterpret_cast(malloc(sizeof(int8_t *) * input_dim)); if (inputs_array == nullptr) { @@ -175,7 +170,7 @@ int SqueezeInt8CPUKernel::Run() { free(*(inputs_array + i)); } - ret = ParallelLaunch(this->context_->thread_pool_, SqueezeInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SqueezeInt8Run, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "RunSqueezeParam failed. errorcode: "; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc index 9d0b11936ae..64ff8017e79 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc @@ -24,6 +24,7 @@ #include "include/errorcode.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Sub; @@ -119,12 +120,6 @@ int SubInt8Run(void *cdata, int task_id) { } int SubInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return RET_ERROR; - } - if (broadcast_) { ArithmeticParameter tile_para; tile_para.ndim_ = out_tensors_.at(0)->shape().size(); @@ -145,7 +140,7 @@ int SubInt8CPUKernel::Run() { static_cast(in_tensors_.at(1)->MutableData()), reinterpret_cast(tile0_data_), reinterpret_cast(tile1_data_), &tile_para); } - ret = ParallelLaunch(this->context_->thread_pool_, SubInt8Run, this, op_parameter_->thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SubInt8Run, this, op_parameter_->thread_num_); if (broadcast_) { context_->allocator->Free(tile0_data_); context_->allocator->Free(tile1_data_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc index 8125ba80f29..530a7896998 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc @@ -47,11 +47,6 @@ int TopKInt8CPUKernel::ReSize() { } int TopKInt8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare failed."; - return ret; - } int8_t *input_data = reinterpret_cast(in_tensors_.at(0)->MutableData()); int8_t *output_data = reinterpret_cast(out_tensors_.at(0)->MutableData()); int32_t *output_index = reinterpret_cast(out_tensors_.at(1)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc index 363d45d07e5..23ecb7909b3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc @@ -81,14 +81,9 @@ int UnsqueezeIn8Run(void *cdata, int task_id) { } int Unsqueezeint8CPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail!ret: " << ret; - return ret; - } in_ptr_ = reinterpret_cast(in_tensors_.at(0)->MutableData()); out_ptr_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - ret = ParallelLaunch(this->context_->thread_pool_, UnsqueezeIn8Run, this, thread_sz_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, UnsqueezeIn8Run, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "UnsqueezeRun error error_code[" << ret << "]"; return ret; diff --git a/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc b/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc index 4215e8f5b0e..9d6bc8cbbf0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc @@ -18,6 +18,8 @@ #include "src/kernel_registry.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_CustomExtractFeatures; namespace mindspore::kernel { @@ -44,11 +46,6 @@ bool ExtractFeatureCPUKernel::IsInBlacklist(const lite::StringPack &str) { } int ExtractFeatureCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! Ret error code: " << ret; - return ret; - } const int kMaxDimension = 1000000; auto input_tensor = in_tensors_.at(0); auto label_data = reinterpret_cast(out_tensors_.at(0)->MutableData()); diff --git a/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc b/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc index 596aa90c199..3e48c54aee0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc @@ -20,6 +20,8 @@ #include "src/common/string_util.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_HashtableLookup; namespace mindspore::kernel { @@ -37,11 +39,6 @@ static int CmpKeyFunc(const void *lhs, const void *rhs) { } int HashtableLookupCPUKernel::Run() { - auto ret = Prepare(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Prepare fail! Ret error code: " << ret; - return ret; - } auto input_tensor = in_tensors_.at(0); auto keys_tensor = in_tensors_.at(1); auto values_tensor = in_tensors_.at(2); diff --git a/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc b/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc index 70bfeb0e7ce..35c158647d6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc @@ -21,6 +21,8 @@ #include "src/kernel_registry.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_CustomNormalize; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/arm/string/predict.cc b/mindspore/lite/src/runtime/kernel/arm/string/predict.cc index 15c2fc9085b..4f9b30ba409 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/predict.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/predict.cc @@ -19,6 +19,8 @@ #include "src/kernel_registry.h" using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_CustomPredict; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc index 7d13d141640..a6f05a04900 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc @@ -59,7 +59,7 @@ int ActivationOpenClKernel::Init() { fp_size = enable_fp16_ ? sizeof(uint16_t) : sizeof(float); if (in_size_ != 2 && in_size_ != 4) { MS_LOG(ERROR) << "Activate fun only support dim=4 or 2, but your dim=" << in_size_; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } std::map Program_Kernel{{ActivationType_LEAKY_RELU, "LeakyRelu"}, {ActivationType_RELU, "Relu"}, @@ -68,7 +68,7 @@ int ActivationOpenClKernel::Init() { {ActivationType_TANH, "Tanh"}}; if (Program_Kernel.count(type_) == 0) { MS_LOG(ERROR) << "schema::ActivationType:" << type_ << "not found"; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } std::string source = activation_source; @@ -82,7 +82,7 @@ int ActivationOpenClKernel::Init() { in_tensors_[0]->SetFormat(op_format_); out_tensors_[0]->SetFormat(op_format_); MS_LOG(DEBUG) << op_parameter_->name_ << " init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } int ActivationOpenClKernel::Run() { @@ -98,11 +98,11 @@ int ActivationOpenClKernel::Run() { std::vector local = {}; std::vector global = {static_cast(img2d_shape.s[1]), static_cast(img2d_shape.s[2])}; auto ret = ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Run kernel:" << op_parameter_->name_ << " fail."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } - return RET_OK; + return mindspore::lite::RET_OK; } cl_int4 ActivationOpenClKernel::GetImg2dShape() { @@ -130,7 +130,7 @@ int ActivationOpenClKernel::GetImageSize(size_t idx, std::vector *img_si img_size->push_back(img_shape.s[2]); img_size->push_back(img_shape.s[1]); img_size->push_back(img_dtype); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenClActivationKernelCreator(const std::vector &inputs, @@ -154,7 +154,7 @@ kernel::LiteKernel *OpenClActivationKernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Init activation kernel:" << opParameter->name_ << " failed!"; delete kernel; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc index 456f3714f66..fc8cfb4defc 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc @@ -28,6 +28,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Eltwise; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc index 13c6c2256d2..c99cd2b9fd9 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc @@ -23,6 +23,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Abs; using mindspore::schema::PrimitiveType_Ceil; using mindspore::schema::PrimitiveType_Cos; @@ -68,7 +70,7 @@ int ArithmeticSelfOpenCLKernel::GetImageSize(size_t idx, std::vector *im img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } void ArithmeticSelfOpenCLKernel::GetKernelName(std::string *kernel_name, ArithmeticSelfParameter *param) { @@ -128,7 +130,7 @@ int ArithmeticSelfOpenCLKernel::Init() { if (in_format != schema::Format_NHWC4 && in_format != schema::Format_NC4HW4 && in_format != schema::Format_NC4) { MS_LOG(ERROR) << "input format(" << in_format << ") " << "format not support!"; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } in_ori_format_ = in_tensors_[0]->GetFormat(); in_tensors_[0]->SetFormat(op_format_); @@ -149,10 +151,10 @@ int ArithmeticSelfOpenCLKernel::Init() { ocl_runtime_->LoadSource(program_name, source); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options); - return RET_OK; + return mindspore::lite::RET_OK; } -int ArithmeticSelfOpenCLKernel::ReSize() { return RET_OK; } +int ArithmeticSelfOpenCLKernel::ReSize() { return mindspore::lite::RET_OK; } void ArithmeticSelfGetWorkGroup(const std::vector &global, std::vector *local, int max_size) { const int max_divider = 8; @@ -197,7 +199,7 @@ int ArithmeticSelfOpenCLKernel::Run() { ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLArithmeticSelfKernelCreator(const std::vector &inputs, @@ -212,7 +214,7 @@ kernel::LiteKernel *OpenCLArithmeticSelfKernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << " Init kernel failed, name: ArithmeticSelf "; delete kernel; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc index 2ed5c44b40d..3f23ddc3286 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc @@ -24,6 +24,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchToSpace; using mindspore::schema::PrimitiveType_BatchToSpaceND; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc index cf8d76b7cc0..157891bbae7 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc @@ -24,6 +24,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchNorm; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc index 0e00d6e2579..67ed3b19ea9 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc @@ -61,13 +61,13 @@ int BiasAddOpenCLKernel::Init() { fp_size = enable_fp16_ ? sizeof(uint16_t) : sizeof(float); if (in_size_ != 4 && in_size_ != 2) { MS_LOG(ERROR) << "BiasAdd only support dim=4 or 2, but your dim=" << in_size_; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } int C = in_tensors_[0]->shape()[3]; int Bias_Size = in_tensors_[1]->shape()[0]; if (UP_DIV(Bias_Size, C4NUM) != UP_DIV(C, C4NUM)) { MS_LOG(ERROR) << "BiasAdd weight channel size:" << Bias_Size << " must be equal with in_teneors channel size:" << C; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } InitBuffer(); std::set build_options; @@ -82,7 +82,7 @@ int BiasAddOpenCLKernel::Init() { in_tensors_[0]->SetFormat(op_format_); out_tensors_[0]->SetFormat(op_format_); MS_LOG(DEBUG) << program_name << " Init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } int BiasAddOpenCLKernel::Run() { @@ -99,11 +99,11 @@ int BiasAddOpenCLKernel::Run() { std::vector local = {1, 1}; std::vector global = {static_cast(global_size.s[1]), static_cast(global_size.s[2])}; auto ret = ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Run kernel " << op_parameter_->name_ << " error."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } - return RET_OK; + return mindspore::lite::RET_OK; } cl_int4 BiasAddOpenCLKernel::GetGlobalshape() { @@ -131,7 +131,7 @@ int BiasAddOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) img_size->push_back(img_shape.s[2]); img_size->push_back(img_shape.s[1]); img_size->push_back(img_dtype); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLBiasAddKernelCreator(const std::vector &inputs, @@ -156,7 +156,7 @@ kernel::LiteKernel *OpenCLBiasAddKernelCreator(const std::vector } auto ret = kernel->Init(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Init BiasAdd kernel failed!"; delete kernel; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc index b071947d7c2..d09e1cd1c17 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc @@ -24,6 +24,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Cast; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc index e8808cb505f..8c80d2d18af 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc @@ -25,6 +25,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Concat; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc index 31d273b1865..e77f7e74419 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc @@ -25,6 +25,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_DeConv2D; namespace mindspore::kernel { @@ -54,10 +56,10 @@ int Conv2dTransposeOpenCLKernel::Init() { out_ori_format_ = out_tensors_[0]->GetFormat(); out_tensors_[0]->SetFormat(op_format_); MS_LOG(DEBUG) << kernel_name << " Init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } -int Conv2dTransposeOpenCLKernel::ReSize() { return RET_OK; } +int Conv2dTransposeOpenCLKernel::ReSize() { return mindspore::lite::RET_OK; } void Conv2dTransposeOpenCLKernel::PadWeight() { ConvParameter *param = reinterpret_cast(op_parameter_); @@ -159,7 +161,7 @@ int Conv2dTransposeOpenCLKernel::GetImageSize(size_t idx, std::vector *i im_dst_y = n * UP_DIV(c, C4NUM) * h; } else { MS_LOG(ERROR) << "not support op format:" << EnumNameFormat(op_format_); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } size_t img_dtype = CL_FLOAT; if (enable_fp16_) { @@ -168,7 +170,7 @@ int Conv2dTransposeOpenCLKernel::GetImageSize(size_t idx, std::vector *i img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } int Conv2dTransposeOpenCLKernel::Run() { @@ -207,7 +209,7 @@ int Conv2dTransposeOpenCLKernel::Run() { ocl_runtime_->SetKernelArg(kernel_, arg_cnt++, src_size); ocl_runtime_->SetKernelArg(kernel_, arg_cnt++, dst_size); ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLConv2dTransposeKernelCreator(const std::vector &inputs, @@ -223,7 +225,7 @@ kernel::LiteKernel *OpenCLConv2dTransposeKernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { delete kernel; return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc index bddb03a6f82..6673d6f2119 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc @@ -25,6 +25,7 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Conv2D; using mindspore::schema::Format::Format_NC4HW4; @@ -892,7 +893,7 @@ int ConvolutionOpenCLKernel::SetGlobalLocalConv(std::vector *global, std size_t local_c = GetMaxDivisor(global_c, max_z_size); if (local_c == 0) { MS_LOG(ERROR) << "Divide by zero"; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } size_t local_hw_size = std::min(256, max_work_group_size) / local_c; size_t local_w = std::min(global_w, local_hw_size); @@ -938,7 +939,7 @@ kernel::LiteKernel *OpenCLConvolutionKernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Init kernel failed, name: Convolution"; delete kernel; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc index 5f1d24243ae..7df0b90a236 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc @@ -48,7 +48,7 @@ int DepthwiseConv2dOpenCLKernel::Init() { if (in_format != schema::Format::Format_NHWC4 && in_format != schema::Format::Format_NC4HW4) { MS_LOG(ERROR) << "input format(" << in_format << ") " << "format not support!"; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } in_tensors_[0]->SetFormat(in_format); out_tensors_[0]->SetFormat(in_format); @@ -77,7 +77,7 @@ int DepthwiseConv2dOpenCLKernel::Init() { #endif this->InitBuffer(); MS_LOG(DEBUG) << kernel_name << " Init Done! mem type=" << static_cast(out_mem_type_); - return RET_OK; + return mindspore::lite::RET_OK; } int DepthwiseConv2dOpenCLKernel::InitBuffer() { @@ -102,7 +102,7 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() { PackNCHWToNC4HW4(origin_weight, packed_weight_, 1, plane, out_tensors_[0]->Channel(), to_dtype); } else { MS_LOG(ERROR) << "Only support float16/float32, actual data type " << in_tensors_.at(kWeightIndex)->data_type(); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } } else { packed_weight_ = allocator->Malloc(pack_weight_size * sizeof(float)); @@ -115,7 +115,7 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() { PackNCHWToNC4HW4(origin_weight, packed_weight_, 1, plane, out_tensors_[0]->Channel(), to_dtype); } else { MS_LOG(ERROR) << "Only support float16/float32, actual data type " << in_tensors_.at(kWeightIndex)->data_type(); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } } @@ -143,10 +143,10 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() { } else { MS_ASSERT(in_tensors_.size() == kInputSize1); } - return RET_OK; + return mindspore::lite::RET_OK; } -int DepthwiseConv2dOpenCLKernel::ReSize() { return RET_OK; } +int DepthwiseConv2dOpenCLKernel::ReSize() { return mindspore::lite::RET_OK; } int DepthwiseConv2dOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { size_t CO4 = UP_DIV(out_tensors_[0]->Channel(), C4NUM); @@ -165,14 +165,14 @@ int DepthwiseConv2dOpenCLKernel::GetImageSize(size_t idx, std::vector *i img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } int DepthwiseConv2dOpenCLKernel::GetGlobalSize(size_t idx, std::vector *global_size) { size_t CO4 = UP_DIV(out_tensors_[0]->Channel(), C4NUM); std::vector global = {(size_t)out_tensors_[0]->Width(), (size_t)out_tensors_[0]->Height(), CO4}; *global_size = std::move(global); - return RET_OK; + return mindspore::lite::RET_OK; } int DepthwiseConv2dOpenCLKernel::GetLocalSize(size_t idx, const std::vector &global_size, @@ -180,7 +180,7 @@ int DepthwiseConv2dOpenCLKernel::GetLocalSize(size_t idx, const std::vectorChannel(), C4NUM); std::vector local = {1, 1, CO4}; *local_size = std::move(local); - return RET_OK; + return mindspore::lite::RET_OK; } int DepthwiseConv2dOpenCLKernel::Run() { @@ -216,7 +216,7 @@ int DepthwiseConv2dOpenCLKernel::Run() { ocl_runtime_->SetKernelArg(kernel_, arg_cnt++, relu_clips[parameter->act_type_].first); ocl_runtime_->SetKernelArg(kernel_, arg_cnt++, relu_clips[parameter->act_type_].second); ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLDepthwiseConv2dKernelCreator(const std::vector &inputs, @@ -232,7 +232,7 @@ kernel::LiteKernel *OpenCLDepthwiseConv2dKernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { delete kernel; MS_LOG(ERROR) << "Init DepthwiseConv2dOpenCLKernel failed!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc index a2d16c0c5cc..89daa60da3a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc @@ -26,6 +26,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_FullConnection; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc index 7aff36bcf2d..e2cd2e2b64c 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc @@ -24,6 +24,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Gather; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc index 59384a9b10d..c4b69ed6c2e 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc @@ -37,14 +37,14 @@ int MatMulOpenCLKernel::Init() { transposeA = param->a_transpose_; if (transposeA) { MS_LOG(ERROR) << "matmul only support a_transpose_=false yet."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } transposeB = param->b_transpose_; enable_fp16_ = ocl_runtime_->GetFp16Enable(); if (in_tensors_[0]->shape().size() != out_tensors_[0]->shape().size() || (in_tensors_[0]->shape().size() != 2 && in_tensors_[0]->shape().size() != 4)) { MS_LOG(ERROR) << "matmul only support input shape size=2 or 4."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } dims = in_tensors_[0]->shape().size(); for (int i = 0; i < dims; i++) { @@ -69,10 +69,10 @@ int MatMulOpenCLKernel::Init() { in_tensors_[0]->SetFormat(op_format_); out_tensors_[0]->SetFormat(op_format_); MS_LOG(DEBUG) << kernel_name << " Init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } -int MatMulOpenCLKernel::ReSize() { return RET_OK; } +int MatMulOpenCLKernel::ReSize() { return mindspore::lite::RET_OK; } void MatMulOpenCLKernel::PadWeight() { // ABMCI @ ABCICO = ABMCO @@ -158,7 +158,7 @@ int MatMulOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) im_dst_y = n * UP_DIV(c, C4NUM) * h; } else { MS_LOG(ERROR) << "not support op format:" << EnumNameFormat(op_format_); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } size_t img_dtype = CL_FLOAT; if (enable_fp16_) { @@ -167,7 +167,7 @@ int MatMulOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } int MatMulOpenCLKernel::Run() { @@ -186,7 +186,7 @@ int MatMulOpenCLKernel::Run() { ocl_runtime_->SetKernelArg(kernel_, arg_count++, in_shape); ocl_runtime_->SetKernelArg(kernel_, arg_count++, out_shape); ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLMatMulKernelCreator(const std::vector &inputs, @@ -200,7 +200,7 @@ kernel::LiteKernel *OpenCLMatMulKernelCreator(const std::vector return nullptr; } auto ret = kernel->Init(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { delete kernel; return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc index cf59e9e9a44..6d28ddf090a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc @@ -28,6 +28,7 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; using mindspore::lite::RET_INVALID_OP_NAME; using mindspore::lite::RET_MEMORY_FAILED; using mindspore::lite::RET_OK; @@ -74,7 +75,7 @@ int PoolingOpenCLKernel::Init() { kernel_name += "_" + std::string(EnumNameFormat(op_format_)); if (out_mem_type_ == OpenCLMemType::BUF) { MS_LOG(ERROR) << "buffer output not support yet."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } else { kernel_name += "_IMG"; } @@ -88,7 +89,7 @@ int PoolingOpenCLKernel::Init() { out_tensors_[0]->SetFormat(op_format_); MS_LOG(DEBUG) << kernel_name << " Init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } std::vector PoolingOpenCLKernel::InitGlobalSize() const { @@ -113,7 +114,7 @@ int PoolingOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) im_dst_y = n * UP_DIV(c, C4NUM) * h; } else { MS_LOG(ERROR) << "not support op format:" << EnumNameFormat(op_format_); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } size_t img_dtype = CL_FLOAT; if (enable_fp16_) { @@ -122,12 +123,12 @@ int PoolingOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } -int PoolingOpenCLKernel::InitBuffer() { return RET_OK; } +int PoolingOpenCLKernel::InitBuffer() { return mindspore::lite::RET_OK; } -int PoolingOpenCLKernel::ReSize() { return RET_OK; } +int PoolingOpenCLKernel::ReSize() { return mindspore::lite::RET_OK; } int PoolingOpenCLKernel::Run() { MS_LOG(DEBUG) << this->name() << " Running!"; @@ -156,7 +157,7 @@ int PoolingOpenCLKernel::Run() { global_size = GetCommonGlobalSize(local_size, global_size); ocl_runtime_->RunKernel(kernel_, global_size, local_size, nullptr); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLPooling2dKernelCreator(const std::vector &inputs, diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc index 3501f4e6d5e..552273bfcb6 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc @@ -78,7 +78,7 @@ int PReluOpenCLKernel::Init() { auto weight_tensor = in_tensors_[1]; if (input_tensor->shape().size() != 4) { MS_LOG(ERROR) << "PRelu only support dim=4, but your dim=" << input_tensor->shape().size(); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } batch_size_ = input_tensor->Batch(); C_ = input_tensor->Channel(); @@ -86,7 +86,7 @@ int PReluOpenCLKernel::Init() { W_ = input_tensor->Width(); if (input_tensor->GetFormat() != schema::Format_NC4HW4 && input_tensor->GetFormat() != schema::Format_NHWC4) { MS_LOG(ERROR) << "PRelu only support Format_NC4HW4 and Format_NHWC4"; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } if (batch_size_ != 1) { MS_LOG(ERROR) << "Init PRelu kernel failed: Unsupported multi-batch."; @@ -97,7 +97,7 @@ int PReluOpenCLKernel::Init() { MS_LOG(ERROR) << "PRelu weight channel size must be 1 or must be equal with in_teneors channel size, but your weight size is " << weight_channel << " and your input channel size is " << C_; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } weight_is_scalar = weight_channel == 1; if (weight_tensor->data_type() != kNumberTypeFloat16 && weight_tensor->data_type() != kNumberTypeFloat32) { @@ -120,7 +120,7 @@ int PReluOpenCLKernel::Init() { InitBuffer(); MS_LOG(DEBUG) << program_name << " init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } int PReluOpenCLKernel::Run() { @@ -146,11 +146,11 @@ int PReluOpenCLKernel::Run() { std::vector local = {4, 4, 1}; std::vector global = {static_cast(H_), static_cast(W_), static_cast(CO_SLICES_)}; auto ret = ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Run kernel " << op_parameter_->name_ << " error."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } - return RET_OK; + return mindspore::lite::RET_OK; } int PReluOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { @@ -175,7 +175,7 @@ int PReluOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { img_size->push_back(im_dst_x); img_size->push_back(im_dst_y); img_size->push_back(img_dtype); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLPReluKernelCreator(const std::vector &inputs, @@ -194,7 +194,7 @@ kernel::LiteKernel *OpenCLPReluKernelCreator(const std::vector & return nullptr; } auto ret = kernel->Init(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Init PRelu kernel failed!"; delete kernel; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc index 3e8f67c5a41..7f2054c90f3 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc @@ -63,7 +63,7 @@ int ReduceOpenCLKernel::Init() { if (in_tensors_[0]->shape().back() != out_tensors_[0]->shape().back()) { MS_LOG(ERROR) << "Reduce input channel " << in_tensors_[0]->shape().back() << " should equal output channel" << out_tensors_[0]->shape().back(); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } #ifdef PROGRAM_WITH_IL kernel_ = ocl_runtime_->GetKernelFromBinary(kernel_name); @@ -79,7 +79,7 @@ int ReduceOpenCLKernel::Init() { in_tensors_[0]->SetFormat(op_format_); out_tensors_[0]->SetFormat(op_format_); MS_LOG(DEBUG) << kernel_name << " Init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } void ReduceOpenCLKernel::InitNHWCShape() { @@ -97,7 +97,7 @@ void ReduceOpenCLKernel::InitNHWCShape() { nhwc_shape_ = {n, h, w, c}; } -int ReduceOpenCLKernel::ReSize() { return RET_OK; } +int ReduceOpenCLKernel::ReSize() { return mindspore::lite::RET_OK; } int ReduceOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { size_t im_dst_x, im_dst_y; @@ -110,7 +110,7 @@ int ReduceOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) im_dst_y = nhwc_shape_[0] * UP_DIV(nhwc_shape_[3], C4NUM) * nhwc_shape_[1]; } else { MS_LOG(ERROR) << "not support op format:" << EnumNameFormat(op_format_); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } size_t img_dtype = CL_FLOAT; if (enable_fp16_) { @@ -119,7 +119,7 @@ int ReduceOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } int ReduceOpenCLKernel::Run() { @@ -137,7 +137,7 @@ int ReduceOpenCLKernel::Run() { ocl_runtime_->SetKernelArg(kernel_, arg_idx++, out_tensors_[0]->data_c()); ocl_runtime_->SetKernelArg(kernel_, arg_idx++, size); ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLReduceKernelCreator(const std::vector &inputs, @@ -151,7 +151,7 @@ kernel::LiteKernel *OpenCLReduceKernelCreator(const std::vector return nullptr; } auto ret = kernel->Init(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { delete kernel; return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc index 52d24a8d21d..e0dcd61754b 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc @@ -28,6 +28,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Scale; namespace mindspore::kernel { @@ -277,7 +279,7 @@ int ScaleOpenCLKernel::Init() { element_flag_ = true; kernel_name = "Scale"; } - lite::STATUS error_code = RET_OK; + lite::STATUS error_code; #ifdef PROGRAM_WITH_IL kernel_ = ocl_runtime_->GetKernelFromBinary(kernel_name); #else diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc index c88abc63f9c..a50cda01f73 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc @@ -24,6 +24,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Slice; namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc index d7d209384b8..469e8db72ab 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc @@ -27,6 +27,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_SoftMax; namespace mindspore::kernel { @@ -87,7 +89,7 @@ int SoftmaxOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) im_dst_y = n * UP_DIV(c, C4NUM) * h; } else { MS_LOG(ERROR) << "not support op format:" << EnumNameFormat(op_format_); - return RET_ERROR; + return mindspore::lite::RET_ERROR; } size_t img_dtype = CL_FLOAT; if (enable_fp16_) { @@ -96,7 +98,7 @@ int SoftmaxOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } int SoftmaxOpenCLKernel::Init() { @@ -186,7 +188,7 @@ kernel::LiteKernel *OpenCLSoftMaxKernelCreator(const std::vector return nullptr; } auto ret = kernel->Init(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { MS_LOG(ERROR) << "Init `Softmax` kernel failed!"; delete kernel; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc index 4ad0d11ce7a..4661e8d2922 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc @@ -24,6 +24,8 @@ using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_SpaceToBatch; using mindspore::schema::PrimitiveType_SpaceToBatchND; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc index a3e2c4c656e..f64d942a27a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc @@ -120,7 +120,7 @@ kernel::LiteKernel *OpenCLToFormatKernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { delete kernel; return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.h index 5db1b83cbf2..bb7b6be9452 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.h @@ -31,7 +31,7 @@ class ToFormatOpenCLKernel : public OpenCLKernel { ~ToFormatOpenCLKernel() override{}; int Init() override; - int ReSize() override { return RET_OK; }; + int ReSize() override { return mindspore::lite::RET_OK; }; int Run() override; int GetImageSize(size_t idx, std::vector *img_size) override; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc index cca38b6aee3..b2f9c4f71ca 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc @@ -39,7 +39,7 @@ int TransposeOpenCLKernel::Init() { auto param = reinterpret_cast(op_parameter_); if (in_tensors_[0]->shape().size() != 4 || in_tensors_[0]->shape()[0] > 1) { MS_LOG(ERROR) << "Transpose only support 4d tensor and n = 1 yet."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } if (param->num_axes_ == 4 && param->perm_[0] == 0 && param->perm_[1] == 3 && param->perm_[2] == 1 && param->perm_[3] == 2) { @@ -51,7 +51,7 @@ int TransposeOpenCLKernel::Init() { type = TransposeType::AXIS0231; } else { MS_LOG(ERROR) << "unsupported transpose axes."; - return RET_ERROR; + return mindspore::lite::RET_ERROR; } if (in_tensors_[0]->shape()[2] * UP_DIV(in_tensors_[0]->shape()[3], C4NUM) > MAX_IMAGE2D_SIZE) { // just for input @@ -73,10 +73,10 @@ int TransposeOpenCLKernel::Init() { out_tensors_[0]->SetFormat(op_format_); MS_LOG(DEBUG) << kernel_name << " Init Done!"; - return RET_OK; + return mindspore::lite::RET_OK; } -int TransposeOpenCLKernel::ReSize() { return RET_OK; } +int TransposeOpenCLKernel::ReSize() { return mindspore::lite::RET_OK; } int TransposeOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { size_t im_dst_x = 1, im_dst_y = 1; @@ -95,7 +95,7 @@ int TransposeOpenCLKernel::GetImageSize(size_t idx, std::vector *img_siz img_size->clear(); std::vector vec{im_dst_x, im_dst_y, img_dtype}; *img_size = vec; - return RET_OK; + return mindspore::lite::RET_OK; } int TransposeOpenCLKernel::Run() { @@ -120,7 +120,7 @@ int TransposeOpenCLKernel::Run() { ocl_runtime_->SetKernelArg(kernel_, arg_idx++, out_tensors_[0]->data_c()); ocl_runtime_->SetKernelArg(kernel_, arg_idx++, shape); ocl_runtime_->RunKernel(kernel_, global, local, nullptr); - return RET_OK; + return mindspore::lite::RET_OK; } kernel::LiteKernel *OpenCLTransposeKernelCreator(const std::vector &inputs, @@ -135,7 +135,7 @@ kernel::LiteKernel *OpenCLTransposeKernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != mindspore::lite::RET_OK) { delete kernel; return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h b/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h index 17519d547ea..d5defc0a7ef 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h +++ b/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h @@ -44,15 +44,15 @@ class OpenCLKernel : public LiteKernel { ~OpenCLKernel() {} - virtual int Init() { return RET_ERROR; } - virtual int Prepare() { return RET_ERROR; } - virtual int InferShape() { return RET_ERROR; } - virtual int ReSize() { return RET_ERROR; } - virtual int Run() { return RET_ERROR; } - virtual int GetImageSize(size_t idx, std::vector *img_size) { return RET_ERROR; } - virtual int GetGlobalSize(size_t idx, std::vector *global_size) { return RET_ERROR; } + virtual int Init() { return mindspore::lite::RET_ERROR; } + virtual int PreProcess() { return mindspore::lite::RET_ERROR; } + virtual int InferShape() { return mindspore::lite::RET_ERROR; } + virtual int ReSize() { return mindspore::lite::RET_ERROR; } + virtual int Run() { return mindspore::lite::RET_ERROR; } + virtual int GetImageSize(size_t idx, std::vector *img_size) { return mindspore::lite::RET_ERROR; } + virtual int GetGlobalSize(size_t idx, std::vector *global_size) { return mindspore::lite::RET_ERROR; } virtual int GetLocalSize(size_t idx, const std::vector &global_size, std::vector *local_size) { - return RET_ERROR; + return mindspore::lite::RET_ERROR; } OpenCLMemType GetMemType() { return out_mem_type_; } void SetMemType(OpenCLMemType mem_type) { out_mem_type_ = mem_type; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc index 0789a6a975c..34b726d8d79 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc @@ -22,7 +22,8 @@ #include "src/common/utils.h" namespace mindspore::kernel { - +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; SubGraphOpenCLKernel::~SubGraphOpenCLKernel() { UnInit(); } int SubGraphOpenCLKernel::GenToFormatOp(const std::vector &in_tensors, @@ -200,7 +201,7 @@ int SubGraphOpenCLKernel::MallocTensorWithReuse() { for (auto *kernel : nodes_) { MS_ASSERT(nullptr != kernel); kernel::OpenCLKernel *op_kernel = reinterpret_cast(kernel); - auto &outputs = kernel->out_tensors(); + auto outputs = kernel->out_tensors(); for (auto i = 0; i < outputs.size(); ++i) { auto *output = outputs.at(i); MS_ASSERT(nullptr != output); @@ -298,6 +299,10 @@ int SubGraphOpenCLKernel::InferShape() { return RET_OK; } int SubGraphOpenCLKernel::ReSize() { return RET_OK; } int SubGraphOpenCLKernel::Run() { + if (executor_ == nullptr) { + MS_LOG(ERROR) << "executor is nullptr"; + return RET_ERROR; + } for (auto &tensor : in_tensors_) { if (tensor->data_c() == nullptr) { MS_LOG(ERROR) << "OpenCL subgraph input tensor data is null"; @@ -306,8 +311,7 @@ int SubGraphOpenCLKernel::Run() { allocator_->UnmapBuffer(tensor->data_c()); } - lite::opencl::OpenCLExecutor executor; - executor.Run(in_tensors_, out_tensors_, nodes_, allocator_); + executor_->Run(in_tensors_, out_tensors_, nodes_, allocator_); ocl_runtime_->SyncCommandQueue(); return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h index 6d233e2db4c..6875da3e5f5 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h +++ b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h @@ -20,9 +20,10 @@ #include #include "src/runtime/kernel/opencl/opencl_kernel.h" #include "src/runtime/opencl/opencl_allocator.h" +#include "src/runtime/opencl/opencl_executor.h" +#include "src/sub_graph_kernel.h" namespace mindspore::kernel { - struct SubGraphOpenCLParameter { OpParameter op_parameter; int input_size; @@ -34,17 +35,21 @@ class SubGraphOpenCLKernel : public SubGraphKernel { explicit SubGraphOpenCLKernel(const std::vector inputs, const std::vector outputs, const std::vector inKernels, const std::vector outKernels, - const std::vector nodes, const lite::InnerContext *ctx = nullptr, - const mindspore::lite::PrimitiveC *primitive = nullptr) - : SubGraphKernel(inputs, outputs, inKernels, outKernels, nodes, ctx, primitive) { + const std::vector nodes, const lite::InnerContext *ctx = nullptr) + : SubGraphKernel(inputs, outputs, inKernels, outKernels, nodes, ctx) { ocl_runtime_ = ocl_runtime_wrap_.GetInstance(); + subgraph_type_ = kGpuSubGraph; + this->executor_ = new lite::opencl::OpenCLExecutor(); } ~SubGraphOpenCLKernel() override; + int PreProcess() override { return mindspore::lite::RET_OK; } + int PostProcess() override { return mindspore::lite::RET_OK; } int Init() override; - int InferShape() override; + int InferShape(); int ReSize() override; int Run() override; + int Run(const KernelCallBack &before, const KernelCallBack &after) override { return this->Run(); }; int UnInit(); protected: diff --git a/mindspore/lite/src/runtime/opencl/opencl_executor.cc b/mindspore/lite/src/runtime/opencl/opencl_executor.cc index b73f8adefbd..57d4f508b08 100644 --- a/mindspore/lite/src/runtime/opencl/opencl_executor.cc +++ b/mindspore/lite/src/runtime/opencl/opencl_executor.cc @@ -24,12 +24,12 @@ namespace mindspore::lite::opencl { int OpenCLExecutor::Prepare(const std::vector &kernels) { return RET_OK; } int OpenCLExecutor::Run(std::vector &inputs, std::vector &outputs, - std::vector &kernels, Allocator *allocator, - const session::KernelCallBack &before, const session::KernelCallBack &after) { + std::vector &kernels, Allocator *allocator, const KernelCallBack &before, + const KernelCallBack &after) { kernel::LiteKernelUtil::InitTensorRefCount(kernels); for (auto *kernel : kernels) { MS_ASSERT(nullptr != kernel); - session::CallBackParam callbackParam; + CallBackParam callbackParam; callbackParam.node_name = kernel->name(); if (before != nullptr) { @@ -38,7 +38,7 @@ int OpenCLExecutor::Run(std::vector &inputs, std::vector &ou } } kernel::OpenCLKernel *op_kernel = reinterpret_cast(kernel); - auto &cur_outputs = kernel->out_tensors(); + auto cur_outputs = kernel->out_tensors(); for (auto i = 0; i < cur_outputs.size(); ++i) { auto *output = cur_outputs.at(i); MS_ASSERT(nullptr != output); diff --git a/mindspore/lite/src/runtime/opencl/opencl_executor.h b/mindspore/lite/src/runtime/opencl/opencl_executor.h index 9ada5741a8b..58d4e067334 100644 --- a/mindspore/lite/src/runtime/opencl/opencl_executor.h +++ b/mindspore/lite/src/runtime/opencl/opencl_executor.h @@ -25,19 +25,19 @@ #include "include/lite_session.h" namespace mindspore::lite::opencl { -class OpenCLExecutor : Executor { +class OpenCLExecutor : public Executor { public: OpenCLExecutor() : Executor() { allocator_ = ocl_runtime.GetInstance()->GetAllocator(); } - int Prepare(const std::vector &kernels); + int Prepare(const std::vector &kernels) override; int Run(std::vector &inputs, std::vector &outputs, std::vector &kernels, - Allocator *allocator = nullptr, const session::KernelCallBack &before = nullptr, - const session::KernelCallBack &after = nullptr); + Allocator *allocator = nullptr, const KernelCallBack &before = nullptr, + const KernelCallBack &after = nullptr) override; protected: InnerContext *context = nullptr; - OpenCLAllocator *allocator_; + OpenCLAllocator *allocator_ = nullptr; OpenCLRuntimeWrapper ocl_runtime; }; } // namespace mindspore::lite::opencl diff --git a/mindspore/lite/src/runtime/parallel_executor.cc b/mindspore/lite/src/runtime/parallel_executor.cc index 0d13a9dbf93..8030ff86850 100644 --- a/mindspore/lite/src/runtime/parallel_executor.cc +++ b/mindspore/lite/src/runtime/parallel_executor.cc @@ -21,7 +21,7 @@ #define MAX_THREAD_NUM 8 namespace mindspore::lite { ParallelExecutor::~ParallelExecutor() { DestroyThreadPool(thread_pool_); } -int ParallelExecutor::Prepare(std::vector &kernels) { +int ParallelExecutor::Prepare(const std::vector &kernels) { thread_pool_ = CreateLiteThreadPool(MAX_THREAD_NUM, NO_BIND); if (thread_pool_ == nullptr) { MS_LOG(ERROR) << "Memory error: fail to new ThreadPool"; @@ -40,22 +40,17 @@ static int RunKernel(void *data, int index) { return 0; } - for (auto input_kernel : kernel->in_kernels()) { - MS_ASSERT(input_kernel != nullptr); - if (input_kernel->is_model_output()) { - continue; - } - ret = input_kernel->DecOutTensorRefCount(); - if (0 != ret) { - MS_LOG(WARNING) << "DecOutTensorRefCount for kernel" << kernel->name() << " failed"; - } + ret = kernel->FreeWorkTensor(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "FreeWorkTensor failed, name: " << kernel->name(); + return ret; } return 0; } int ParallelExecutor::Run(std::vector &in_tensors, std::vector &out_tensors, std::vector &kernels, Allocator *allocator, - const session::KernelCallBack &before, const session::KernelCallBack &after) { + const KernelCallBack &before, const KernelCallBack &after) { MS_ASSERT(nullptr != allocator); for (auto &inTensor : in_tensors) { if (inTensor == nullptr) { @@ -98,16 +93,10 @@ int ParallelExecutor::Run(std::vector &in_tensors, std::vectorin_kernels()) { - MS_ASSERT(input_kernel != nullptr); - if (input_kernel->is_model_output()) { - continue; - } - auto ret = input_kernel->DecOutTensorRefCount(); - if (0 != ret) { - MS_LOG(WARNING) << "DecOutTensorRefCount for kernel" << completed->name() << " failed"; - return -1; - } + auto ret = completed->FreeWorkTensor(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "FreeWorkTensor failed, name: " << completed->name(); + return ret; } } readyKernels.clear(); diff --git a/mindspore/lite/src/runtime/parallel_executor.h b/mindspore/lite/src/runtime/parallel_executor.h index f6872be4f6f..ef6ab881924 100644 --- a/mindspore/lite/src/runtime/parallel_executor.h +++ b/mindspore/lite/src/runtime/parallel_executor.h @@ -30,11 +30,11 @@ class ParallelExecutor : public Executor { ParallelExecutor() = default; virtual ~ParallelExecutor(); - int Prepare(std::vector &kernels) override; + int Prepare(const std::vector &kernels) override; int Run(std::vector &in_tensors, std::vector &out_tensors, std::vector &kernels, Allocator *allocator = nullptr, - const session::KernelCallBack &before = nullptr, const session::KernelCallBack &after = nullptr) override; + const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; inline kernel::LiteKernel *GetReadyKernel(const int index) { return readyKernels.at(index); } inline void SetResult(const int index, const int result) { results.at(index) = result; } diff --git a/mindspore/lite/src/scheduler.cc b/mindspore/lite/src/scheduler.cc index 45e15d32867..c203d802b17 100644 --- a/mindspore/lite/src/scheduler.cc +++ b/mindspore/lite/src/scheduler.cc @@ -15,19 +15,24 @@ */ #include "src/scheduler.h" -#include +#include +#include #include -#include +#include #include "include/errorcode.h" -#include "src/kernel_registry.h" #include "src/common/graph_util.h" #include "src/common/utils.h" +#include "src/kernel_registry.h" +#include "src/sub_graph_kernel.h" #if SUPPORT_GPU #include "src/runtime/kernel/opencl/subgraph_opencl_kernel.h" #include "src/runtime/opencl/opencl_runtime.h" #endif namespace mindspore::lite { +using kernel::KERNEL_ARCH::kCPU; +using kernel::KERNEL_ARCH::kGPU; + int Scheduler::Schedule(const lite::Model *model, std::vector *tensors, std::vector *kernels) { // 1. op ---> kernel @@ -44,9 +49,11 @@ int Scheduler::Schedule(const lite::Model *model, std::vector *tensors return RET_ERROR; } - kernel::LiteKernelUtil::TopologicalSortKernels(*kernels); + kernel::LiteKernelUtil::InitIOKernels(*kernels); - ConstructSubgraphs(kernels); + ConstructSubGraphs(kernels); + + kernel::LiteKernelUtil::InitIOKernels(*kernels); MS_LOG(DEBUG) << "schedule kernels success."; return RET_OK; @@ -54,40 +61,29 @@ int Scheduler::Schedule(const lite::Model *model, std::vector *tensors int Scheduler::ReSizeKernels(const std::vector &kernels) { bool infer_shape_interrupt = false; - for (size_t i = 0; i < kernels.size(); ++i) { - if (kernels[i] == nullptr) { + for (auto kernel : kernels) { + if (kernel == nullptr) { MS_LOG(ERROR) << "input kernel is nullptr!"; return RET_ERROR; } - auto primitive = const_cast(kernels[i]->GetPrimitive()); - if (primitive == nullptr) { - MS_LOG(ERROR) << "kernel(" << kernels[i]->name() << ")'s primitive is nullptr!"; + if (kernel->subgraph_type() == kernel::kNotSubGraph) { + MS_LOG(ERROR) << "All node in graph should be sub_graph"; return RET_ERROR; } - std::vector &inputs = kernels[i]->in_tensors(); - std::vector &outputs = kernels[i]->out_tensors(); - for (size_t j = 0; j < outputs.size(); j++) { - outputs[j]->FreeData(); + auto sub_graph = reinterpret_cast(kernel); + if (sub_graph == nullptr) { + MS_LOG(ERROR) << "node " << kernel->name() << " is neither a kernel or a sub_graph"; + return RET_ERROR; } - primitive->SetInferFlag(!infer_shape_interrupt); - auto ret = primitive->InferShape(inputs, outputs); + auto ret = sub_graph->ReSize(infer_shape_interrupt); if (ret == RET_INFER_INVALID) { - MS_LOG(INFO) << "InferShape shouldn't be done before runtime, type:" - << schema::EnumNamePrimitiveType(static_cast(primitive->Type())) - << "flag set to false."; - primitive->SetInferFlag(false); + MS_LOG(INFO) << "InferShape is interrupted"; infer_shape_interrupt = true; - } else if (ret != RET_OK) { - MS_LOG(ERROR) << "InferShape failed, type: " - << schema::EnumNamePrimitiveType(static_cast(primitive->Type())); - return RET_INFER_ERR; + continue; } - if (!infer_shape_interrupt) { - ret = kernels[i]->ReSize(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "kernel " << kernels[i]->name() << " resize fail!ret = " << ret; - return ret; - } + if (ret != RET_OK) { + MS_LOG(ERROR) << "ReSize node " << kernel->name() << " failed"; + return RET_ERROR; } } return RET_OK; @@ -104,10 +100,12 @@ int Scheduler::InferShape(const lite::Model *model, std::vector *tenso std::vector inputs; std::vector outputs; auto in_size = node->input_indices_.size(); + inputs.reserve(in_size); for (size_t j = 0; j < in_size; ++j) { inputs.emplace_back(tensors->at(node->input_indices_[j])); } auto out_size = node->output_indices_.size(); + outputs.reserve(out_size); for (size_t j = 0; j < out_size; ++j) { outputs.emplace_back(tensors->at(node->output_indices_[j])); } @@ -146,10 +144,12 @@ int Scheduler::InitOp2Kernel(const lite::Model *model, std::vector *te std::vector inputs; std::vector outputs; auto in_size = node->input_indices_.size(); + inputs.reserve(in_size); for (size_t j = 0; j < in_size; ++j) { inputs.emplace_back(tensors->at(node->input_indices_[j])); } auto out_size = node->output_indices_.size(); + outputs.reserve(out_size); for (size_t j = 0; j < out_size; ++j) { outputs.emplace_back(tensors->at(node->output_indices_[j])); } @@ -170,76 +170,90 @@ int Scheduler::InitOp2Kernel(const lite::Model *model, std::vector *te return RET_OK; } -void Scheduler::ConstructSubgraphs(std::vector *kernels) { - uint32_t kernel_count = kernels->size(); - std::vector sub_kernels; - std::vector> sub_kernels_list; - - kernel::KERNEL_ARCH prev_arch = kernels->front()->desc().arch; - for (uint32_t i = 0; i < kernel_count; ++i) { - auto curr_kernel = kernels->at(i); - auto curr_arch = curr_kernel->desc().arch; - if (curr_arch == prev_arch) { - sub_kernels.emplace_back(curr_kernel); - } - if ((curr_arch != prev_arch) || (i == kernel_count - 1)) { - sub_kernels_list.emplace_back(sub_kernels); - sub_kernels.clear(); - sub_kernels.emplace_back(curr_kernel); - } - prev_arch = curr_arch; +int Scheduler::ConstructSubGraphs(std::vector *kernels) { + auto old_kernels = *kernels; + kernels->clear(); + std::map is_kernel_sinked; + for (auto kernel : old_kernels) { + is_kernel_sinked[kernel] = false; } - std::vector subgraph_kernels; - size_t sub_cnt{0}; - auto &device_ctx = context_->device_list_[0]; - for (auto temp_kernels : sub_kernels_list) { - std::vector output_tensor = kernel::LiteKernelUtil::SubgraphOutputTensors(temp_kernels); - for (auto tensor : output_tensor) { - if (device_ctx.device_type_ == DT_CPU && device_ctx.device_info_.cpu_device_info_.enable_float16_ && - tensor->data_type() == kNumberTypeFloat16) { - tensor->set_data_type(kNumberTypeFloat32); - } + while (true) { + auto head_kernel_iter = std::find_if(old_kernels.begin(), old_kernels.end(), [&](const kernel::LiteKernel *kernel) { + auto kernel_inputs = kernel->in_kernels(); + return !is_kernel_sinked[kernel] && + std::all_of(kernel_inputs.begin(), kernel_inputs.end(), + [&](kernel::LiteKernel *kernel) { return is_kernel_sinked[kernel]; }); + }); + if (head_kernel_iter == old_kernels.end()) { + break; } - kernel::KERNEL_ARCH arch = temp_kernels.front()->desc().arch; - if (arch == kernel::KERNEL_ARCH::kCPU) { - for (auto kernel : temp_kernels) { - for (auto tensor : kernel->out_tensors()) { - tensor->set_allocator(context_->allocator.get()); + auto head_kernel = *head_kernel_iter; + if (head_kernel->desc().arch == mindspore::kernel::kNPU || head_kernel->desc().arch == mindspore::kernel::kAPU) { + MS_LOG(ERROR) << "Not support NPU and APU now"; + return RET_NOT_SUPPORT; + } + + std::vector sub_kernels; + std::queue kernel_queue; + kernel_queue.emplace(head_kernel); + auto cur_sub_graph_type = this->GetKernelSubGraphType(head_kernel); + while (!kernel_queue.empty()) { + auto cur_kernel = kernel_queue.front(); + kernel_queue.pop(); + is_kernel_sinked[cur_kernel] = true; + sub_kernels.emplace_back(cur_kernel); + auto post_kernels = cur_kernel->out_kernels(); + for (auto post_kernel : post_kernels) { + if (cur_sub_graph_type == this->GetKernelSubGraphType(post_kernel)) { + auto post_kernel_inputs = post_kernel->in_kernels(); + if (std::all_of(post_kernel_inputs.begin(), post_kernel_inputs.end(), + [&](kernel::LiteKernel *kernel) { return is_kernel_sinked[kernel]; })) { + kernel_queue.emplace(post_kernel); + } } } - std::copy(temp_kernels.begin(), temp_kernels.end(), std::back_inserter(subgraph_kernels)); - } else { - auto subgraph_kernel = CreateSubKernel(temp_kernels, arch); - subgraph_kernels.emplace_back(subgraph_kernel); - std::string arch_name = (arch == kernel::KERNEL_ARCH::kGPU) ? "GPU" : "NPU"; - MS_LOG(INFO) << arch_name << " subgraph id" << sub_cnt << " created."; } - ++sub_cnt; + auto subgraph = CreateSubGraphKernel(sub_kernels, cur_sub_graph_type); + if (subgraph == nullptr) { + MS_LOG(ERROR) << "Create SubGraphKernel failed"; + return RET_ERROR; + } + kernels->emplace_back(subgraph); } - kernels->clear(); - kernels->insert(kernels->begin(), subgraph_kernels.begin(), subgraph_kernels.end()); + return RET_OK; } -kernel::LiteKernel *Scheduler::CreateSubKernel(const std::vector &kernels, - kernel::KERNEL_ARCH arch) { - kernel::LiteKernel *sub_kernel = nullptr; -#if SUPPORT_GPU - if (arch == kernel::KERNEL_ARCH::kGPU) { - std::vector input_tensors = kernel::LiteKernelUtil::SubgraphInputTensors(kernels); - std::vector output_tensors = kernel::LiteKernelUtil::SubgraphOutputTensors(kernels); - std::vector input_kernels = kernel::LiteKernelUtil::SubgraphInputKernels(kernels); - std::vector output_kernels = kernel::LiteKernelUtil::SubgraphOutputKernels(kernels); - sub_kernel = new kernel::SubGraphOpenCLKernel(input_tensors, output_tensors, input_kernels, output_kernels, kernels, - context_, nullptr); - sub_kernel->Init(); - } else if (arch == kernel::KERNEL_ARCH::kNPU) { - MS_LOG(ERROR) << "NPU kernel is not supported"; - } else { - MS_LOG(ERROR) << "unsupported kernel arch: " << arch; +kernel::SubGraphKernel *Scheduler::CreateSubGraphKernel(const std::vector &kernels, + kernel::SubGraphType type) { + if (type == kernel::kApuSubGraph || type == kernel::kNpuSubGraph) { + return nullptr; } + std::vector input_tensors = kernel::LiteKernelUtil::SubgraphInputTensors(kernels); + std::vector output_tensors = kernel::LiteKernelUtil::SubgraphOutputTensors(kernels); + std::vector input_kernels = kernel::LiteKernelUtil::SubgraphInputKernels(kernels); + std::vector output_kernels = kernel::LiteKernelUtil::SubgraphOutputKernels(kernels); + if (type == kernel::kGpuSubGraph) { +#if SUPPORT_GPU + auto sub_kernel = + new kernel::SubGraphOpenCLKernel(input_tensors, output_tensors, input_kernels, output_kernels, kernels, context_); + sub_kernel->Init(); + return sub_kernel; +#else + return nullptr; #endif - return sub_kernel; + } + if (type == kernel::kCpuFP16SubGraph) { + auto sub_kernel = + new kernel::CpuFp16SubGraph(input_tensors, output_tensors, input_kernels, output_kernels, kernels, context_); + return sub_kernel; + } + if (type == kernel::kCpuFP32SubGraph) { + auto sub_kernel = + new kernel::CpuFp32SubGraph(input_tensors, output_tensors, input_kernels, output_kernels, kernels, context_); + return sub_kernel; + } + return nullptr; } kernel::LiteKernel *Scheduler::ScheduleNode(const std::vector &in_tensors, @@ -247,44 +261,36 @@ kernel::LiteKernel *Scheduler::ScheduleNode(const std::vector &in_tens const mindspore::lite::PrimitiveC *primitive, const Model::Node *node) { MS_ASSERT(primitive != nullptr); TypeId data_type = GetFirstFp32Fp16OrInt8Type(in_tensors); - kernel::KernelKey desc{kernel::KERNEL_ARCH::kCPU, data_type, static_cast(primitive->Type())}; - auto &device_ctx = context_->device_list_[0]; + kernel::KernelKey desc{kCPU, data_type, static_cast(primitive->Type())}; #if SUPPORT_GPU - if (device_ctx.device_type_ == DT_GPU) { - desc.arch = kernel::KERNEL_ARCH::kGPU; - auto *kernel = KernelRegistry::GetInstance()->GetKernel(in_tensors, out_tensors, primitive, context_, desc); + if (context_->IsGpuEnabled()) { + kernel::KernelKey gpu_desc{kGPU, desc.data_type, desc.type}; + auto *kernel = KernelRegistry::GetInstance()->GetKernel(in_tensors, out_tensors, primitive, context_, gpu_desc); if (kernel != nullptr) { - kernel->set_desc(desc); + MS_LOG(DEBUG) << "Get gpu op success: " << schema::EnumNamePrimitiveType(gpu_desc.type) << " " << node->name_; return kernel; } else { - MS_LOG(ERROR) << "Not supported GPU Op " - << schema::EnumNamePrimitiveType(static_cast(primitive->Type())) << " " + MS_LOG(DEBUG) << "Get gpu op failed, scheduler to cpu: " << schema::EnumNamePrimitiveType(gpu_desc.type) << " " << node->name_; } } #endif - desc.arch = kernel::KERNEL_ARCH::kCPU; - kernel::LiteKernel *kernel = nullptr; - if ((device_ctx.device_info_.cpu_device_info_.enable_float16_ && data_type == kNumberTypeFloat32) || - data_type == kNumberTypeFloat16) { - // check if support fp16 - kernel::KernelKey key{desc.arch, kNumberTypeFloat16, desc.type}; - kernel = KernelRegistry::GetInstance()->GetKernel(in_tensors, out_tensors, primitive, context_, key); + if ((context_->IsCpuFloat16Enabled() && data_type == kNumberTypeFloat32) || data_type == kNumberTypeFloat16) { + kernel::KernelKey fp16_cpu_desc{desc.arch, kNumberTypeFloat16, desc.type}; + auto *kernel = + KernelRegistry::GetInstance()->GetKernel(in_tensors, out_tensors, primitive, context_, fp16_cpu_desc); if (kernel != nullptr) { - MS_LOG(INFO) << "Get fp16 op success. type:" - << schema::EnumNamePrimitiveType(static_cast(primitive->Type())); - desc.data_type = kNumberTypeFloat16; - kernel->set_desc(desc); + MS_LOG(DEBUG) << "Get fp16 op success: " << schema::EnumNamePrimitiveType(fp16_cpu_desc.type) << " " + << node->name_; return kernel; } - MS_LOG(DEBUG) << "Get fp16 op failed, back to fp32 op."; } if (data_type == kNumberTypeFloat16) { + MS_LOG(DEBUG) << "Get fp16 op failed, back to fp32 op."; desc.data_type = kNumberTypeFloat32; } - kernel = KernelRegistry::GetInstance()->GetKernel(in_tensors, out_tensors, primitive, context_, desc); + auto *kernel = KernelRegistry::GetInstance()->GetKernel(in_tensors, out_tensors, primitive, context_, desc); if (kernel != nullptr) { - kernel->set_desc(desc); return kernel; } return nullptr; @@ -324,4 +330,24 @@ void Scheduler::SetKernelTensorDataType(kernel::LiteKernel *kernel) { } } +kernel::SubGraphType Scheduler::GetKernelSubGraphType(kernel::LiteKernel *kernel) { + if (kernel == nullptr) { + return kernel::kNotSubGraph; + } + auto desc = kernel->desc(); + if (desc.arch == kernel::KERNEL_ARCH::kGPU) { + return kernel::kGpuSubGraph; + } else if (desc.arch == kernel::KERNEL_ARCH::kNPU) { + return kernel::kNpuSubGraph; + } else if (desc.arch == kernel::KERNEL_ARCH::kAPU) { + return kernel::kApuSubGraph; + } else if (desc.arch == kernel::KERNEL_ARCH::kCPU) { + if (desc.data_type == kNumberTypeFloat16) { + return kernel::kCpuFP16SubGraph; + } else if (desc.data_type == kNumberTypeFloat32 || desc.data_type == kNumberTypeInt8) { + return kernel::kCpuFP32SubGraph; + } + } + return kernel::kNotSubGraph; +} } // namespace mindspore::lite diff --git a/mindspore/lite/src/scheduler.h b/mindspore/lite/src/scheduler.h index 1d0f73ffa60..d653c93907d 100644 --- a/mindspore/lite/src/scheduler.h +++ b/mindspore/lite/src/scheduler.h @@ -18,7 +18,7 @@ #define MINDSPORE_LITE_SRC_SCHEDULER_H_ #include -#include "src/lite_kernel.h" +#include "src/sub_graph_kernel.h" #include "src/inner_context.h" #include "include/model.h" #include "src/ops/primitive_c.h" @@ -27,25 +27,30 @@ namespace mindspore::lite { class Scheduler { public: explicit Scheduler(const InnerContext *ctx) { context_ = const_cast(ctx); } + int Schedule(const lite::Model *model, std::vector *tensors, std::vector *kernels); - int ReSizeKernels(const std::vector &kernels); + static int ReSizeKernels(const std::vector &kernels); protected: kernel::LiteKernel *ScheduleNode(const std::vector &in_tensors, const std::vector &out_tensors, const mindspore::lite::PrimitiveC *primitive, const Model::Node *cnode); - private: int InitOp2Kernel(const lite::Model *model, std::vector *tensors, std::vector *kernels); - int InferShape(const lite::Model *model, std::vector *tensors); - // construct SubGraphKernel for each kernel-group in markedKernelGroup - void ConstructSubgraphs(std::vector *kernels); + static int InferShape(const lite::Model *model, std::vector *tensors); - kernel::LiteKernel *CreateSubKernel(const std::vector &kernels, kernel::KERNEL_ARCH arch); - TypeId GetFirstFp32Fp16OrInt8Type(const std::vector &in_tensors); - void SetKernelTensorDataType(kernel::LiteKernel *kernel); + int ConstructSubGraphs(std::vector *kernels); + + kernel::SubGraphKernel *CreateSubGraphKernel(const std::vector &kernels, + kernel::SubGraphType type); + + static TypeId GetFirstFp32Fp16OrInt8Type(const std::vector &in_tensors); + + static void SetKernelTensorDataType(kernel::LiteKernel *kernel); + + static kernel::SubGraphType GetKernelSubGraphType(kernel::LiteKernel *kernel); protected: InnerContext *context_ = nullptr; diff --git a/mindspore/lite/src/sub_graph_kernel.cc b/mindspore/lite/src/sub_graph_kernel.cc new file mode 100644 index 00000000000..33f36c0283f --- /dev/null +++ b/mindspore/lite/src/sub_graph_kernel.cc @@ -0,0 +1,236 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "src/sub_graph_kernel.h" +#include "src/tensor.h" +#ifdef ENABLE_ARM64 +#include "nnacl/optimized_kernel.h" +#endif + +namespace mindspore::kernel { +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_INFER_ERR; +using mindspore::lite::RET_INFER_INVALID; +using mindspore::lite::RET_OK; +using Float16CastFunc = void (*)(const void *, void *, int); + +class Float16CastUtil { + public: + static Float16CastUtil *GetInstance() { + static Float16CastUtil float16_cast_util; + return &float16_cast_util; + } + + private: + Float16CastUtil() { +#ifdef ENABLE_ARM64 + void *fp16_op_handler = Float16Module::GetInstance()->float16_op_handler_; + if (fp16_op_handler != nullptr) { + dlerror(); + *(reinterpret_cast(&float16_to_float32_func_)) = dlsym(fp16_op_handler, "Float16ToFloat32_fp16_handler"); + *(reinterpret_cast(&float32_to_float16_func_)) = dlsym(fp16_op_handler, "Float32ToFloat16_fp16_handler"); + auto dlopen_error = dlerror(); + if (dlopen_error != nullptr) { + MS_LOG(ERROR) << "load float16 cast func failed! " << dlopen_error << "."; + } + } +#endif + } + ~Float16CastUtil() = default; + + public: + Float16CastFunc float16_to_float32_func_ = nullptr; + Float16CastFunc float32_to_float16_func_ = nullptr; +}; + +int SubGraphKernel::Prepare() { + for (auto node : this->nodes_) { + if (node == nullptr) { + MS_LOG(ERROR) << "node in Subgraph is nullptr"; + return mindspore::lite::RET_NULL_PTR; + } + auto ret = node->Prepare(); + if (ret == RET_OK) { + MS_LOG(ERROR) << "prepare node " << node->name() << " failed"; + return ret; + } + } + return RET_OK; +} + +std::string SubGraphKernel::ToString() const { + std::ostringstream oss; + oss << "===============================================" << std::endl << "Subgraph type : " << this->subgraph_type_; + oss << std::endl << this->in_tensors_.size() << " InputTensors:"; + for (auto tensor : in_tensors_) { + oss << " " << tensor << ":" << tensor->ToString(); + } + oss << std::endl << this->out_tensors_.size() << " OutputTensors:"; + for (auto tensor : out_tensors_) { + oss << " " << tensor << ":" << tensor->ToString(); + } + oss << std::endl << "input kernels :"; + for (auto kernel : this->in_kernels_) { + oss << " " << kernel->ToString(); + } + oss << std::endl << "output kernels :"; + for (auto kernel : this->out_kernels_) { + oss << " " << kernel->ToString(); + } + oss << std::endl << nodes_.size() << " nodes :"; + for (auto kernel : this->nodes_) { + oss << " " << kernel->name(); + } + return oss.str(); +} + +int SubGraphKernel::Run() { + if (this->executor_ == nullptr) { + MS_LOG(ERROR) << "executor is nullptr"; + return RET_ERROR; + } + auto ret = executor_->Prepare(this->nodes_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed: " << ret; + return ret; + } + ret = executor_->Run(this->in_tensors_, this->out_tensors_, this->nodes_, this->context_->allocator.get()); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Run sub graph failed: " << ret; + return ret; + } + return RET_OK; +} + +int SubGraphKernel::Run(const KernelCallBack &before, const KernelCallBack &after) { + if (this->executor_ == nullptr) { + MS_LOG(ERROR) << "executor is nullptr"; + return RET_ERROR; + } + auto ret = executor_->Prepare(this->nodes_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed: " << ret; + return ret; + } + ret = + executor_->Run(this->in_tensors_, this->out_tensors_, this->nodes_, this->context_->allocator.get(), before, after); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Run sub graph failed: " << ret; + return ret; + } + return RET_OK; +} + +int SubGraphKernel::ReSize() { return ReSize(false); } + +int SubGraphKernel::ReSize(bool is_interrupt) { + for (auto kernel : nodes_) { + if (kernel == nullptr) { + MS_LOG(ERROR) << "input kernel is nullptr!"; + return RET_ERROR; + } + if (kernel->subgraph_type() != kernel::kNotSubGraph) { + MS_LOG(ERROR) << "all nodes in should be kernel"; + return RET_ERROR; + } + auto primitive = const_cast(kernel->GetPrimitive()); + if (primitive == nullptr) { + MS_LOG(ERROR) << "kernel(" << kernel->name() << ")'s primitive is nullptr!"; + return RET_ERROR; + } + std::vector inputs = kernel->in_tensors(); + std::vector outputs = kernel->out_tensors(); + for (auto &output : outputs) { + output->FreeData(); + } + primitive->SetInferFlag(!is_interrupt); + auto ret = primitive->InferShape(inputs, outputs); + if (ret == RET_INFER_INVALID) { + MS_LOG(INFO) << "InferShape shouldn't be done before runtime, type:" + << schema::EnumNamePrimitiveType(static_cast(primitive->Type())) + << "flag set to false."; + primitive->SetInferFlag(false); + is_interrupt = true; + } else if (ret != RET_OK) { + MS_LOG(ERROR) << "InferShape failed, type: " + << schema::EnumNamePrimitiveType(static_cast(primitive->Type())); + return RET_INFER_ERR; + } + if (!is_interrupt) { + ret = kernel->ReSize(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "kernel " << kernel->name() << " resize fail!ret = " << ret; + return ret; + } + } + } + return RET_OK; +} + +int CpuFp32SubGraph::PreProcess() { return RET_OK; } + +int CpuFp16SubGraph::PreProcess() { + for (auto kernel : this->nodes_) { + for (auto tensor : kernel->out_tensors()) { + if (tensor->data_type() == kNumberTypeFloat32) { + tensor->set_data_type(kNumberTypeFloat16); + } + } + } + return RET_OK; +} + +int CpuFp16SubGraph::PostProcess() { + auto fp16_to_fp32_cast_func = Float16CastUtil::GetInstance()->float16_to_float32_func_; + if (fp16_to_fp32_cast_func == nullptr) { + MS_LOG(ERROR) << "Can not find cast fp16 to fp32 func"; + return RET_ERROR; + } + for (auto tensor : this->out_tensors_) { + if (tensor->data_type() == kNumberTypeFloat16) { + void *float16_data = nullptr; + if (this->context_ != nullptr && this->context_->allocator != nullptr) { + float16_data = this->context_->allocator->Malloc(tensor->Size()); + } else { + float16_data = malloc(tensor->Size()); + } + if (float16_data == nullptr) { + MS_LOG(ERROR) << "malloc data failed"; + return RET_ERROR; + } + memcpy(float16_data, tensor->data_c(), tensor->Size()); + auto ret = tensor->FreeData(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "free data failed"; + return RET_ERROR; + } + tensor->set_data_type(TypeId::kNumberTypeFloat32); + ret = tensor->MallocData(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "malloc data failed"; + return RET_ERROR; + } + fp16_to_fp32_cast_func(float16_data, tensor->data_c(), tensor->ElementsNum()); + if (this->context_ != nullptr && this->context_->allocator != nullptr) { + this->context_->allocator->Free(float16_data); + } else { + free(float16_data); + } + } + } + return RET_OK; +} +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/sub_graph_kernel.h b/mindspore/lite/src/sub_graph_kernel.h new file mode 100644 index 00000000000..8614d4b0412 --- /dev/null +++ b/mindspore/lite/src/sub_graph_kernel.h @@ -0,0 +1,104 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_LITE_SRC_SUB_GRAPH_H +#define MINDSPORE_LITE_SRC_SUB_GRAPH_H + +#include +#include +#include +#include "src/lite_kernel.h" +#include "src/executor.h" + +namespace mindspore::kernel { +class SubGraphKernel : public LiteKernel { + public: + explicit SubGraphKernel(const std::vector &inputs, const std::vector &outputs, + const std::vector &in_kernels, const std::vector &out_kernels, + std::vector nodes, const lite::InnerContext *ctx) + : LiteKernel(nullptr, inputs, outputs, ctx, nullptr), nodes_(std::move(nodes)) { + in_kernels_ = in_kernels; + out_kernels_ = out_kernels; + subgraph_type_ = kCpuFP32SubGraph; + } + + ~SubGraphKernel() override { delete (executor_); } + + // called while compiling graph. Call node->Prepare() by default. + int Prepare() override; + // called before Run + int PreProcess() override { return mindspore::lite::RET_OK; } + + int Run() override; + + int Run(const KernelCallBack &before, const KernelCallBack &after) override; + // called after Run + int PostProcess() override { return mindspore::lite::RET_OK; } + + int ReSize() override; + + int ReSize(bool is_interrupt); + + std::string ToString() const override; + + std::vector nodes() { return this->nodes_; } + + protected: + std::vector nodes_; + mindspore::lite::Executor *executor_ = nullptr; +}; + +class CpuFp32SubGraph : public SubGraphKernel { + public: + explicit CpuFp32SubGraph(const std::vector &inputs, const std::vector &outputs, + const std::vector &in_kernels, const std::vector &out_kernels, + const std::vector &nodes, const lite::InnerContext *ctx) + : SubGraphKernel(inputs, outputs, in_kernels, out_kernels, nodes, ctx) { + subgraph_type_ = kCpuFP32SubGraph; + this->executor_ = new mindspore::lite::Executor; + } + + ~CpuFp32SubGraph() override = default; + int Init() override { return mindspore::lite::RET_ERROR; } + int PreProcess() override; + int Run() override { return SubGraphKernel::Run(); } + int Run(const KernelCallBack &before, const KernelCallBack &after) override { + return SubGraphKernel::Run(before, after); + }; + int PostProcess() override { return mindspore::lite::RET_OK; } +}; + +class CpuFp16SubGraph : public SubGraphKernel { + public: + explicit CpuFp16SubGraph(const std::vector &inputs, const std::vector &outputs, + const std::vector &in_kernels, const std::vector &out_kernels, + const std::vector &nodes, const lite::InnerContext *ctx) + : SubGraphKernel(inputs, outputs, in_kernels, out_kernels, nodes, ctx) { + subgraph_type_ = kCpuFP16SubGraph; + this->executor_ = new mindspore::lite::Executor; + } + + ~CpuFp16SubGraph() override = default; + int Init() override { return mindspore::lite::RET_ERROR; } + int PreProcess() override; + int Run() override { return SubGraphKernel::Run(); } + int Run(const KernelCallBack &before, const KernelCallBack &after) override { + return SubGraphKernel::Run(before, after); + }; + int PostProcess() override; +}; +} // namespace mindspore::kernel +#endif // MINDSPORE_LITE_SRC_SUB_GRAPH_H diff --git a/mindspore/lite/src/tensor.cc b/mindspore/lite/src/tensor.cc index dff7ba2bec0..892289f10f1 100644 --- a/mindspore/lite/src/tensor.cc +++ b/mindspore/lite/src/tensor.cc @@ -238,10 +238,30 @@ std::string Tensor::ToString() const { } } } break; + case kNumberTypeFloat16: { + auto data = static_cast(this->data_); + if (data == nullptr) { + oss << " Data of tensor is nullptr"; + } else { + for (int i = 0; i < 40 && i < this->ElementsNum(); i++) { + oss << " " << data[i]; + } + } + } break; case kNumberTypeInt32: { auto data = static_cast(this->data_); if (data == nullptr) { - return "Data of tensor is nullptr"; + oss << " Data of tensor is nullptr"; + } else { + for (int i = 0; i < 40 && i < this->ElementsNum(); i++) { + oss << " " << data[i]; + } + } + } break; + case kNumberTypeInt16: { + auto data = static_cast(this->data_); + if (data == nullptr) { + oss << " Data of tensor is nullptr"; } else { for (int i = 0; i < 40 && i < this->ElementsNum(); i++) { oss << " " << data[i]; @@ -251,7 +271,7 @@ std::string Tensor::ToString() const { case kNumberTypeInt8: { auto data = static_cast(this->data_); if (data == nullptr) { - return "Data of tensor is nullptr"; + oss << " Data of tensor is nullptr"; } else { for (int i = 0; i < 40 && i < this->ElementsNum(); i++) { oss << " " << static_cast(data[i]); diff --git a/mindspore/lite/src/tensor.h b/mindspore/lite/src/tensor.h index a03c0c91a07..97b2af97b20 100644 --- a/mindspore/lite/src/tensor.h +++ b/mindspore/lite/src/tensor.h @@ -178,7 +178,6 @@ class Tensor : public mindspore::tensor::MSTensor { allocator_->Free(this->data_); this->data_ = nullptr; } - return 0; } diff --git a/mindspore/lite/src/train/train_session.cc b/mindspore/lite/src/train/train_session.cc index de4cb9200c6..a4df395a78a 100644 --- a/mindspore/lite/src/train/train_session.cc +++ b/mindspore/lite/src/train/train_session.cc @@ -23,6 +23,7 @@ #include "src/common/utils.h" #include "src/tensor.h" #include "src/train/loss_kernel.h" +#include "src/sub_graph_kernel.h" #include "src/train/train_populate_parameter.h" #include "src/runtime/runtime_api.h" #include "src/executor.h" @@ -68,9 +69,18 @@ void TrainSession::RestoreOps(const std::vector &restore) { void TrainSession::AllocWorkSpace() { size_t workspace_size = 0; - for (auto k : kernels_) { - if (workspace_size < k->GetWorkspaceSize()) { - workspace_size = k->GetWorkspaceSize(); + for (auto ori_kernel : kernels_) { + if (ori_kernel->subgraph_type() == kernel::kNotSubGraph) { + if (workspace_size < ori_kernel->GetWorkspaceSize()) { + workspace_size = ori_kernel->GetWorkspaceSize(); + } + } else { + auto sub_graph = reinterpret_cast(ori_kernel); + for (auto kernel : sub_graph->nodes()) { + if (workspace_size < kernel->GetWorkspaceSize()) { + workspace_size = kernel->GetWorkspaceSize(); + } + } } } mindspore::kernel::LiteKernel::AllocWorkspace(workspace_size); @@ -98,7 +108,7 @@ TrainSession::~TrainSession() { void *TrainSession::ExportToBuf(char *buf, size_t *len) const { return model_->ExportBuf(buf, len); } -int TrainSession::RunGraph(const session::KernelCallBack &before, const session::KernelCallBack &after) { +int TrainSession::RunGraph(const KernelCallBack &before, const KernelCallBack &after) { this->outputs_.clear(); for (auto ms_tensors : output_node_map_) for (auto ms_tensor : ms_tensors.second) this->outputs_.push_back((static_cast(ms_tensor))); @@ -118,22 +128,62 @@ int TrainSession::RunGraph(const session::KernelCallBack &before, const session: } void TrainSession::Train() { - for (auto *kernel : kernels_) { - MS_ASSERT(nullptr != kernel); - kernel->train(); + for (auto ori_kernel : kernels_) { + MS_ASSERT(nullptr != ori_kernel); + if (ori_kernel->subgraph_type() == kernel::kNotSubGraph) { + ori_kernel->train(); + } else { + auto sub_graph = reinterpret_cast(ori_kernel); + MS_ASSERT(nullptr != sub_graph); + for (auto kernel : sub_graph->nodes()) { + MS_ASSERT(nullptr != kernel); + kernel->train(); + } + } } output_node_map_.clear(); output_tensor_map_.clear(); train_mode_ = true; - for (auto kernel : this->kernels_) { - if (IsLossKernel(kernel)) { - auto *ms_tensor = kernel->out_tensors().at(0); - if (ms_tensor != nullptr) { - ms_tensor->MutableData(); - output_node_map_[kernel->name()].emplace_back(ms_tensor); - auto index = TSFindTensor(tensors_, ms_tensor); - if (index != tensors_.size()) { - output_tensor_map_.insert(std::make_pair(std::to_string(index), ms_tensor)); + for (auto ori_kernel : kernels_) { + MS_ASSERT(nullptr != ori_kernel); + if (ori_kernel->subgraph_type() == kernel::kNotSubGraph) { + UpdateOutputMapByLossKernel(ori_kernel); + } else { + auto sub_graph = reinterpret_cast(ori_kernel); + MS_ASSERT(nullptr != sub_graph); + for (auto kernel : sub_graph->nodes()) { + MS_ASSERT(nullptr != kernel); + UpdateOutputMapByLossKernel(kernel); + } + } + } +} + +void TrainSession::UpdateOutputMapByLossKernel(const kernel::LiteKernel *kernel) { + if (IsLossKernel(kernel)) { + auto *ms_tensor = kernel->out_tensors().at(0); + if (ms_tensor != nullptr) { + (void)ms_tensor->MutableData(); + output_node_map_[kernel->name()].emplace_back(ms_tensor); + auto index = TSFindTensor(tensors_, ms_tensor); + if (index != tensors_.size()) { + output_tensor_map_.insert(std::make_pair(std::to_string(index), ms_tensor)); + } + } + } +} + +void TrainSession::UpdateOutputMapByInKernel(const kernel::LiteKernel *kernel) { + if (IsLossKernel(kernel)) { + for (auto in_kernel : kernel->in_kernels()) { + if (output_node_map_.find(in_kernel->name()) == output_node_map_.end()) { + auto *ms_tensor = in_kernel->out_tensors().at(0); + if (ms_tensor != nullptr) { + output_node_map_[in_kernel->name()].emplace_back(ms_tensor); + auto index = TSFindTensor(tensors_, ms_tensor); + if (index != tensors_.size()) { + output_tensor_map_.insert(std::make_pair(std::to_string(index), ms_tensor)); + } } } } @@ -141,27 +191,30 @@ void TrainSession::Train() { } void TrainSession::Eval() { - for (auto *kernel : this->kernels_) { - MS_ASSERT(nullptr != kernel); - kernel->eval(); + for (auto ori_kernel : kernels_) { + MS_ASSERT(nullptr != ori_kernel); + if (ori_kernel->subgraph_type() == kernel::kNotSubGraph) { + ori_kernel->eval(); + } else { + auto sub_graph = reinterpret_cast(ori_kernel); + MS_ASSERT(nullptr != sub_graph); + for (auto kernel : sub_graph->nodes()) { + MS_ASSERT(nullptr != kernel); + kernel->eval(); + } + } } output_node_map_ = orig_output_map_; output_tensor_map_ = orig_output_tensor_map_; train_mode_ = false; - for (auto kernel : this->kernels_) { - if (IsLossKernel(kernel)) { - for (auto in_kernel : kernel->in_kernels()) { - if (output_node_map_.find(in_kernel->name()) == output_node_map_.end()) { - auto *ms_tensor = in_kernel->out_tensors().at(0); - if (ms_tensor != nullptr) { - output_node_map_[in_kernel->name()].emplace_back(ms_tensor); - auto index = TSFindTensor(tensors_, ms_tensor); - if (index != tensors_.size()) { - output_tensor_map_.insert(std::make_pair(std::to_string(index), ms_tensor)); - } - } - } + for (auto ori_kernel : kernels_) { + if (ori_kernel->subgraph_type() == kernel::kNotSubGraph) { + UpdateOutputMapByInKernel(ori_kernel); + } else { + auto sub_graph = reinterpret_cast(ori_kernel); + for (auto kernel : sub_graph->nodes()) { + UpdateOutputMapByInKernel(kernel); } } } @@ -181,17 +234,37 @@ void TrainSession::BuildInferenceKernelsRecursive(kernel::LiteKernel *kernel, st void TrainSession::BuildInferenceKernelsMap() { std::vector req_kernels; - for (auto kernel : this->kernels_) { - if (IsLossKernel(kernel)) { // For each loss in the system add backward tree - for (auto in_node : kernel->in_kernels()) { - BuildInferenceKernelsRecursive(in_node, &req_kernels); + for (auto ori_kernel : kernels_) { + if (ori_kernel->subgraph_type() == kernel::kNotSubGraph) { + if (IsLossKernel(ori_kernel)) { // For each loss in the system add backward tree + for (auto in_node : ori_kernel->in_kernels()) { + BuildInferenceKernelsRecursive(in_node, &req_kernels); + } + } + } else { + auto sub_graph = reinterpret_cast(ori_kernel); + for (auto kernel : sub_graph->nodes()) { + if (IsLossKernel(kernel)) { // For each loss in the system add backward tree + for (auto in_node : kernel->in_kernels()) { + BuildInferenceKernelsRecursive(in_node, &req_kernels); + } + } } } } inference_kernels_.clear(); - for (auto kernel : this->kernels_) { - if (std::find(req_kernels.begin(), req_kernels.end(), kernel) != req_kernels.end()) { - inference_kernels_.push_back(kernel); + for (auto ori_kernel : kernels_) { + if (ori_kernel->subgraph_type() == kernel::kNotSubGraph) { + if (std::find(req_kernels.begin(), req_kernels.end(), ori_kernel) != req_kernels.end()) { + inference_kernels_.push_back(ori_kernel); + } + } else { + auto sub_graph = reinterpret_cast(ori_kernel); + for (auto kernel : sub_graph->nodes()) { + if (std::find(req_kernels.begin(), req_kernels.end(), kernel) != req_kernels.end()) { + inference_kernels_.push_back(kernel); + } + } } } if (inference_kernels_.size() == 0) { @@ -199,7 +272,7 @@ void TrainSession::BuildInferenceKernelsMap() { } } -bool TrainSession::IsLossKernel(kernel::LiteKernel *kernel) { +bool TrainSession::IsLossKernel(const kernel::LiteKernel *kernel) { return (kernel->Type() == schema::PrimitiveType_SoftmaxCrossEntropy); } diff --git a/mindspore/lite/src/train/train_session.h b/mindspore/lite/src/train/train_session.h index 6cd4c68d53d..6e676a39577 100644 --- a/mindspore/lite/src/train/train_session.h +++ b/mindspore/lite/src/train/train_session.h @@ -49,8 +49,7 @@ class TrainSession : virtual public session::TrainSession, virtual public lite:: TrainSession(); ~TrainSession(); - int RunGraph(const session::KernelCallBack &before = nullptr, - const session::KernelCallBack &after = nullptr) override; + int RunGraph(const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; int CompileGraph(lite::Model *model) override; int CompileTrainGraph(lite::TrainModel *model) override; @@ -80,9 +79,12 @@ class TrainSession : virtual public session::TrainSession, virtual public lite:: return lite::LiteSession::Resize(inputs, dims); } + void UpdateOutputMapByInKernel(const kernel::LiteKernel *kernel); + void UpdateOutputMapByLossKernel(const kernel::LiteKernel *kernel); + protected: void AllocWorkSpace(); - bool IsLossKernel(kernel::LiteKernel *kernel); + bool IsLossKernel(const kernel::LiteKernel *kernel); virtual std::vector ReplaceOps(); virtual void RestoreOps(const std::vector &restore); virtual void BuildInferenceKernelsMap(); diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 863f61e8629..2153728beae 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -118,6 +118,7 @@ set(TEST_LITE_SRC ${LITE_DIR}/src/kernel_registry.cc ${LITE_DIR}/src/lite_kernel.cc ${LITE_DIR}/src/lite_session.cc + ${LITE_DIR}/src/sub_graph_kernel.cc ${LITE_DIR}/src/model.cc ${LITE_DIR}/src/populate_parameter.cc ${LITE_DIR}/src/scheduler.cc @@ -166,12 +167,6 @@ if(ENABLE_CONVERTER) ${LITE_DIR}/tools/converter/graphdef_transform.cc ${LITE_DIR}/tools/converter/converter_flags.cc ${LITE_DIR}/tools/converter/converter.cc - ${LITE_DIR}/test/st/converter_test.cc - ${LITE_DIR}/test/ut/tools/optimizer/fusion/conv_activation_fusion_test.cc - ${LITE_DIR}/test/ut/tools/optimizer/fusion/conv_biasadd_fusion_test.cc - ${LITE_DIR}/test/ut/tools/optimizer/fusion/conv_bn_fusion_test.cc - ${LITE_DIR}/test/ut/tools/optimizer/fusion/conv_scale_fusion_test.cc - ${LITE_DIR}/test/ut/tools/optimizer/fusion/constant_folding_fusion_test.cc ${LITE_DIR}/tools/optimizer/common/node_pass_extends.cc ${LITE_DIR}/tools/optimizer/common/pass_manager_extends.cc ${LITE_DIR}/tools/optimizer/common/gllo_utils.cc @@ -218,17 +213,28 @@ file(GLOB_RECURSE TEST_CASE_KERNEL_TRAIN_SRC ) set(TEST_SRC - ${TEST_LITE_SRC} - ${TEST_MINDDATA_SRC} - ${TEST_CASE_KERNEL_SRC} - ${TEST_DIR}/common/common_test.cc - ${TEST_DIR}/main.cc - ${TEST_DIR}/ut/src/runtime/kernel/arm/common/pack_tests.cc - ${TEST_DIR}/ut/src/infer_test.cc - ${TEST_DIR}/ut/src/utils_test.cc - #${TEST_DIR}/ut/internal/infer_test.cc + ${TEST_LITE_SRC} + ${TEST_MINDDATA_SRC} + ${TEST_CASE_KERNEL_SRC} + ${TEST_DIR}/main.cc + ${TEST_DIR}/common/common_test.cc + ${TEST_DIR}/ut/src/infer_test.cc + ${TEST_DIR}/ut/src/utils_test.cc + ${TEST_DIR}/ut/src/scheduler_test.cc ) +if (ENABLE_CONVERTER) + set(TEST_SRC + ${TEST_SRC} + ${TEST_DIR}/st/converter_test.cc + ${TEST_DIR}/ut/tools/optimizer/fusion/conv_biasadd_fusion_test.cc + ${TEST_DIR}/ut/tools/optimizer/fusion/conv_bn_fusion_test.cc + ${TEST_DIR}/ut/tools/optimizer/fusion/conv_scale_fusion_test.cc + ${TEST_DIR}/ut/tools/optimizer/fusion/conv_activation_fusion_test.cc + ${TEST_DIR}/ut/tools/optimizer/fusion/constant_folding_fusion_test.cc + ) +endif() + if (SUPPORT_TRAIN) set(TEST_SRC ${TEST_SRC} @@ -266,7 +272,7 @@ if (PLATFORM_ARM64) target_link_libraries(lite-test mslite_internal) endif() -if (PLATFORM_ARM32 OR PLATFORM_ARM64) +if (PLATFORM_ARM) target_link_libraries(lite-test log) endif() diff --git a/mindspore/lite/test/run_train_ut.sh b/mindspore/lite/test/run_train_ut.sh index 777488acf6b..669373b9500 100755 --- a/mindspore/lite/test/run_train_ut.sh +++ b/mindspore/lite/test/run_train_ut.sh @@ -2,4 +2,4 @@ cd ./ut/src/runtime/kernel/arm || exit 1 ../../../../../../build/test/lite-test --gtest_filter=NetworkTest.efficient_net ../../../../../../build/test/lite-test --gtest_filter=NetworkTest.tuning_layer -../../../../../../build/test/lite-test --gtest_filter=NetworkTest.lenetnet +../../../../../../build/test/lite-test --gtest_filter=NetworkTest.lenetnet \ No newline at end of file diff --git a/mindspore/lite/test/ut/src/scheduler_test.cc b/mindspore/lite/test/ut/src/scheduler_test.cc new file mode 100644 index 00000000000..1adc4d85a82 --- /dev/null +++ b/mindspore/lite/test/ut/src/scheduler_test.cc @@ -0,0 +1,362 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common/common_test.h" +#include "schema/inner/model_generated.h" +#include "src/lite_session.h" +#include "ir/dtype/type_id.h" +#include "include/version.h" + +using mindspore::kernel::KernelKey; +using mindspore::kernel::LiteKernel; +using mindspore::lite::InnerContext; +using mindspore::lite::LiteSession; +using mindspore::lite::PrimitiveC; +using mindspore::lite::Tensor; +using mindspore::schema::PrimitiveType_Abs; +using mindspore::TypeId::kNumberTypeFloat32; + +class SchedulerTest : public mindspore::CommonTest { + public: + SchedulerTest() = default; +}; + +TEST_F(SchedulerTest, TestConstructSubGraphsTwoBranch) { + auto meta_graph = std::make_shared(); + meta_graph->name = "graph"; + meta_graph->version = mindspore::lite::Version(); + + auto split = std::make_unique(); + split->inputIndex = {0}; + split->outputIndex = {1, 2}; + split->primitive = std::make_unique(); + split->primitive->value.type = mindspore::schema::PrimitiveType_Split; + auto primitive = new mindspore::schema::SplitT; + primitive->numberSplit = 2; + primitive->splitDim = 3; + split->primitive->value.value = primitive; + split->name = "split"; + + auto abs1 = std::make_unique(); + abs1->inputIndex = {1}; + abs1->outputIndex = {3}; + abs1->primitive = std::make_unique(); + abs1->primitive->value.type = mindspore::schema::PrimitiveType_Abs; + auto abs1_primitive = new mindspore::schema::AbsT; + abs1->primitive->value.value = abs1_primitive; + abs1->name = "gpu1"; + + auto cons1 = std::make_unique(); + cons1->inputIndex = {2}; + cons1->outputIndex = {4}; + cons1->primitive = std::make_unique(); + cons1->primitive->value.type = mindspore::schema::PrimitiveType_Cos; + auto cons1_primitive = new mindspore::schema::AsinT; + cons1->primitive->value.value = cons1_primitive; + cons1->name = "cpu1"; + + auto abs2 = std::make_unique(); + abs2->inputIndex = {3}; + abs2->outputIndex = {5}; + abs2->primitive = std::make_unique(); + abs2->primitive->value.type = mindspore::schema::PrimitiveType_Abs; + auto abs2_primitive = new mindspore::schema::AbsT; + abs2->primitive->value.value = abs2_primitive; + abs2->name = "gpu2"; + + auto cons2 = std::make_unique(); + cons2->inputIndex = {4}; + cons2->outputIndex = {6}; + cons2->primitive = std::make_unique(); + cons2->primitive->value.type = mindspore::schema::PrimitiveType_Cos; + auto cons2_primitive = new mindspore::schema::AsinT; + cons2->primitive->value.value = cons2_primitive; + cons2->name = "cpu2"; + + auto concat = std::make_unique(); + concat->inputIndex = {5, 6}; + concat->outputIndex = {7}; + concat->primitive = std::make_unique(); + concat->primitive->value.type = mindspore::schema::PrimitiveType_Concat; + auto concat_primitive = new mindspore::schema::ConcatT; + concat_primitive->axis = 3; + concat_primitive->n = 2; + concat->primitive->value.value = concat_primitive; + concat->name = "concat"; + + auto tensor0 = std::make_unique(); + tensor0->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor0->format = mindspore::schema::Format_NHWC; + tensor0->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor0->dims = {1, 16, 16, 4}; + tensor0->offset = -1; + auto tensor1 = std::make_unique(); + tensor1->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor1->format = mindspore::schema::Format_NHWC; + tensor1->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor1->dims = {1, 16, 16, 2}; + tensor1->offset = -1; + auto tensor2 = std::make_unique(); + tensor2->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor2->format = mindspore::schema::Format_NHWC; + tensor2->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor2->dims = {1, 16, 16, 2}; + tensor2->offset = -1; + auto tensor3 = std::make_unique(); + tensor3->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor3->format = mindspore::schema::Format_NHWC; + tensor3->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor3->dims = {1, 16, 16, 2}; + tensor3->offset = -1; + auto tensor4 = std::make_unique(); + tensor4->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor4->format = mindspore::schema::Format_NHWC; + tensor4->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor4->dims = {1, 16, 16, 2}; + tensor4->offset = -1; + auto tensor5 = std::make_unique(); + tensor5->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor5->format = mindspore::schema::Format_NHWC; + tensor5->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor5->dims = {1, 16, 16, 2}; + tensor5->offset = -1; + auto tensor6 = std::make_unique(); + tensor6->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor6->format = mindspore::schema::Format_NHWC; + tensor6->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor6->dims = {1, 16, 16, 2}; + tensor6->offset = -1; + auto tensor7 = std::make_unique(); + tensor7->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor7->format = mindspore::schema::Format_NHWC; + tensor7->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor7->dims = {1, 16, 16, 4}; + tensor7->offset = -1; + + meta_graph->nodes.emplace_back(std::move(split)); + meta_graph->nodes.emplace_back(std::move(abs1)); + meta_graph->nodes.emplace_back(std::move(cons1)); + meta_graph->nodes.emplace_back(std::move(abs2)); + meta_graph->nodes.emplace_back(std::move(cons2)); + meta_graph->nodes.emplace_back(std::move(concat)); + meta_graph->allTensors.emplace_back(std::move(tensor0)); + meta_graph->allTensors.emplace_back(std::move(tensor1)); + meta_graph->allTensors.emplace_back(std::move(tensor2)); + meta_graph->allTensors.emplace_back(std::move(tensor3)); + meta_graph->allTensors.emplace_back(std::move(tensor4)); + meta_graph->allTensors.emplace_back(std::move(tensor5)); + meta_graph->allTensors.emplace_back(std::move(tensor6)); + meta_graph->allTensors.emplace_back(std::move(tensor7)); + meta_graph->inputIndex = {0}; + meta_graph->outputIndex = {7}; + flatbuffers::FlatBufferBuilder builder(1024); + auto offset = mindspore::schema::MetaGraph::Pack(builder, meta_graph.get()); + builder.Finish(offset); + size_t size = builder.GetSize(); + const char *content = reinterpret_cast(builder.GetBufferPointer()); + auto model = mindspore::lite::Model::Import(content, size); + auto context = new InnerContext(); + context->Init(); + mindspore::lite::DeviceContext gpu_device_ctx = {mindspore::lite::DT_GPU, {false}}; + context->device_list_.emplace_back(gpu_device_ctx); + auto lite_session = new LiteSession(); + lite_session->Init(context); + ASSERT_EQ(mindspore::lite::RET_OK, lite_session->CompileGraph(model)); +} + +TEST_F(SchedulerTest, TestConstructSubGraphsThreeBranch) { + auto meta_graph = std::make_shared(); + meta_graph->name = "graph"; + meta_graph->version = mindspore::lite::Version(); + + auto split = std::make_unique(); + split->inputIndex = {0}; + split->outputIndex = {1, 2, 3}; + split->primitive = std::make_unique(); + split->primitive->value.type = mindspore::schema::PrimitiveType_Split; + auto primitive = new mindspore::schema::SplitT; + primitive->numberSplit = 3; + primitive->splitDim = 3; + split->primitive->value.value = primitive; + split->name = "split"; + + auto abs1 = std::make_unique(); + abs1->inputIndex = {1}; + abs1->outputIndex = {4}; + abs1->primitive = std::make_unique(); + abs1->primitive->value.type = mindspore::schema::PrimitiveType_Abs; + auto abs1_primitive = new mindspore::schema::AbsT; + abs1->primitive->value.value = abs1_primitive; + abs1->name = "gpu1"; + + auto abs2 = std::make_unique(); + abs2->inputIndex = {2}; + abs2->outputIndex = {5}; + abs2->primitive = std::make_unique(); + abs2->primitive->value.type = mindspore::schema::PrimitiveType_Abs; + auto abs2_primitive = new mindspore::schema::AbsT; + abs2->primitive->value.value = abs2_primitive; + abs2->name = "gpu2"; + + auto cons1 = std::make_unique(); + cons1->inputIndex = {3}; + cons1->outputIndex = {6}; + cons1->primitive = std::make_unique(); + cons1->primitive->value.type = mindspore::schema::PrimitiveType_Cos; + auto cons1_primitive = new mindspore::schema::AsinT; + cons1->primitive->value.value = cons1_primitive; + cons1->name = "cpu1"; + + auto abs3 = std::make_unique(); + abs3->inputIndex = {4}; + abs3->outputIndex = {7}; + abs3->primitive = std::make_unique(); + abs3->primitive->value.type = mindspore::schema::PrimitiveType_Abs; + auto abs3_primitive = new mindspore::schema::AbsT; + abs3->primitive->value.value = abs3_primitive; + abs3->name = "gpu3"; + + auto abs4 = std::make_unique(); + abs4->inputIndex = {5}; + abs4->outputIndex = {8}; + abs4->primitive = std::make_unique(); + abs4->primitive->value.type = mindspore::schema::PrimitiveType_Abs; + auto abs4_primitive = new mindspore::schema::AbsT; + abs4->primitive->value.value = abs4_primitive; + abs4->name = "gpu4"; + + auto cons2 = std::make_unique(); + cons2->inputIndex = {6}; + cons2->outputIndex = {9}; + cons2->primitive = std::make_unique(); + cons2->primitive->value.type = mindspore::schema::PrimitiveType_Cos; + auto cons2_primitive = new mindspore::schema::AsinT; + cons2->primitive->value.value = cons2_primitive; + cons2->name = "cpu2"; + + auto concat = std::make_unique(); + concat->inputIndex = {7, 8, 8}; + concat->outputIndex = {10}; + concat->primitive = std::make_unique(); + concat->primitive->value.type = mindspore::schema::PrimitiveType_Concat; + auto concat_primitive = new mindspore::schema::ConcatT; + concat_primitive->axis = 3; + concat_primitive->n = 2; + concat->primitive->value.value = concat_primitive; + concat->name = "concat"; + + auto tensor0 = std::make_unique(); + tensor0->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor0->format = mindspore::schema::Format_NHWC; + tensor0->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor0->dims = {1, 16, 16, 3}; + tensor0->offset = -1; + auto tensor1 = std::make_unique(); + tensor1->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor1->format = mindspore::schema::Format_NHWC; + tensor1->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor1->dims = {1, 16, 16, 1}; + tensor1->offset = -1; + auto tensor2 = std::make_unique(); + tensor2->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor2->format = mindspore::schema::Format_NHWC; + tensor2->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor2->dims = {1, 16, 16, 1}; + tensor2->offset = -1; + auto tensor3 = std::make_unique(); + tensor3->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor3->format = mindspore::schema::Format_NHWC; + tensor3->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor3->dims = {1, 16, 16, 1}; + tensor3->offset = -1; + auto tensor4 = std::make_unique(); + tensor4->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor4->format = mindspore::schema::Format_NHWC; + tensor4->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor4->dims = {1, 16, 16, 1}; + tensor4->offset = -1; + auto tensor5 = std::make_unique(); + tensor5->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor5->format = mindspore::schema::Format_NHWC; + tensor5->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor5->dims = {1, 16, 16, 1}; + tensor5->offset = -1; + auto tensor6 = std::make_unique(); + tensor6->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor6->format = mindspore::schema::Format_NHWC; + tensor6->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor6->dims = {1, 16, 16, 1}; + tensor6->offset = -1; + auto tensor7 = std::make_unique(); + tensor7->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor7->format = mindspore::schema::Format_NHWC; + tensor7->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor7->dims = {1, 16, 16, 1}; + tensor7->offset = -1; + auto tensor8 = std::make_unique(); + tensor8->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor8->format = mindspore::schema::Format_NHWC; + tensor8->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor8->dims = {1, 16, 16, 1}; + tensor8->offset = -1; + auto tensor9 = std::make_unique(); + tensor9->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor9->format = mindspore::schema::Format_NHWC; + tensor9->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor9->dims = {1, 16, 16, 1}; + tensor9->offset = -1; + auto tensor10 = std::make_unique(); + tensor10->nodeType = mindspore::schema::NodeType::NodeType_ValueNode; + tensor10->format = mindspore::schema::Format_NHWC; + tensor10->dataType = mindspore::TypeId::kNumberTypeFloat32; + tensor10->dims = {1, 16, 16, 3}; + tensor10->offset = -1; + + meta_graph->nodes.emplace_back(std::move(split)); + meta_graph->nodes.emplace_back(std::move(abs1)); + meta_graph->nodes.emplace_back(std::move(abs2)); + meta_graph->nodes.emplace_back(std::move(cons1)); + meta_graph->nodes.emplace_back(std::move(abs3)); + meta_graph->nodes.emplace_back(std::move(abs4)); + meta_graph->nodes.emplace_back(std::move(cons2)); + meta_graph->nodes.emplace_back(std::move(concat)); + meta_graph->allTensors.emplace_back(std::move(tensor0)); + meta_graph->allTensors.emplace_back(std::move(tensor1)); + meta_graph->allTensors.emplace_back(std::move(tensor2)); + meta_graph->allTensors.emplace_back(std::move(tensor3)); + meta_graph->allTensors.emplace_back(std::move(tensor4)); + meta_graph->allTensors.emplace_back(std::move(tensor5)); + meta_graph->allTensors.emplace_back(std::move(tensor6)); + meta_graph->allTensors.emplace_back(std::move(tensor7)); + meta_graph->allTensors.emplace_back(std::move(tensor8)); + meta_graph->allTensors.emplace_back(std::move(tensor9)); + meta_graph->allTensors.emplace_back(std::move(tensor10)); + meta_graph->inputIndex = {0}; + meta_graph->outputIndex = {10}; + flatbuffers::FlatBufferBuilder builder(1024); + auto offset = mindspore::schema::MetaGraph::Pack(builder, meta_graph.get()); + builder.Finish(offset); + size_t size = builder.GetSize(); + const char *content = reinterpret_cast(builder.GetBufferPointer()); + auto model = mindspore::lite::Model::Import(content, size); + auto context = new InnerContext(); + context->Init(); + mindspore::lite::DeviceContext gpu_device_ctx = {mindspore::lite::DT_GPU, {false}}; + context->device_list_.emplace_back(gpu_device_ctx); + auto lite_session = new LiteSession(); + lite_session->Init(context); + ASSERT_EQ(mindspore::lite::RET_OK, lite_session->CompileGraph(model)); +} diff --git a/mindspore/lite/tools/benchmark/benchmark.cc b/mindspore/lite/tools/benchmark/benchmark.cc index c4bcf0f8069..276559c68bd 100644 --- a/mindspore/lite/tools/benchmark/benchmark.cc +++ b/mindspore/lite/tools/benchmark/benchmark.cc @@ -505,7 +505,7 @@ int Benchmark::InitCallbackParameter() { // before callback before_call_back_ = [&](const std::vector &before_inputs, const std::vector &before_outputs, - const session::CallBackParam &callParam) { + const CallBackParam &callParam) { if (before_inputs.empty()) { MS_LOG(INFO) << "The num of beforeInputs is empty"; } @@ -527,7 +527,7 @@ int Benchmark::InitCallbackParameter() { // after callback after_call_back_ = [&](const std::vector &after_inputs, const std::vector &after_outputs, - const session::CallBackParam &call_param) { + const CallBackParam &call_param) { uint64_t opEnd = GetTimeUs(); if (after_inputs.empty()) { diff --git a/mindspore/lite/tools/benchmark/benchmark.h b/mindspore/lite/tools/benchmark/benchmark.h index 1cf533d42ce..198cc384912 100644 --- a/mindspore/lite/tools/benchmark/benchmark.h +++ b/mindspore/lite/tools/benchmark/benchmark.h @@ -245,8 +245,8 @@ class MS_API Benchmark { std::map> op_times_by_type_; std::map> op_times_by_name_; - session::KernelCallBack before_call_back_; - session::KernelCallBack after_call_back_; + KernelCallBack before_call_back_; + KernelCallBack after_call_back_; }; int MS_API RunBenchmark(int argc, const char **argv); diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index 4ab8376ac6a..3d627986c64 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -68,6 +68,7 @@ set(LITE_SRC ${SRC_DIR}/lite_kernel.cc ${SRC_DIR}/populate_parameter.cc ${SRC_DIR}/scheduler.cc + ${SRC_DIR}/sub_graph_kernel.cc ${SRC_DIR}/lite_session.cc ${SRC_DIR}/executor.cc ${SRC_DIR}/model.cc @@ -121,6 +122,7 @@ add_executable(converter_lite ${LITE_SRC} ) add_dependencies(converter_lite tflite_fbs_src) +add_dependencies(converter_lite fbs_src) add_dependencies(converter_lite fbs_inner_src) target_link_libraries(converter_lite PRIVATE diff --git a/mindspore/lite/tools/converter/optimizer.h b/mindspore/lite/tools/converter/optimizer.h index 2455eb3d676..441fcf7681d 100644 --- a/mindspore/lite/tools/converter/optimizer.h +++ b/mindspore/lite/tools/converter/optimizer.h @@ -38,9 +38,6 @@ class GraphPass : public Pass { ~GraphPass() override = default; STATUS Run(schema::MetaGraphT *graph) override = 0; - - // protected: - // GraphDefT *graphDefT = nullptr; }; struct GraphNode { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc index 635f09e77c4..da59b6768dc 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc @@ -188,7 +188,7 @@ size_t GetDataTypeSize(const TypeId &data_type) { return sizeof(int64_t); default: MS_LOG(ERROR) << data_type << " is Unsupported datatype"; - return RET_ERROR; + return TypeId::kTypeUnknown; } } diff --git a/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc b/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc index bdea28319eb..3f5b68fbf1c 100644 --- a/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc +++ b/mindspore/lite/tools/converter/quantizer/post_training_quantizer.cc @@ -914,10 +914,9 @@ STATUS PostTrainingQuantizer::DoInference() { } } - mindspore::session::KernelCallBack beforeCallBack = - [&](const std::vector &beforeInputs, - const std::vector &beforeOutputs, - const mindspore::session::CallBackParam &callParam) -> bool { + KernelCallBack beforeCallBack = [&](const std::vector &beforeInputs, + const std::vector &beforeOutputs, + const CallBackParam &callParam) -> bool { if (PostTrainingQuantizer::CheckFp32TensorVec(callParam.node_name, beforeInputs) != RET_OK) { return false; } @@ -929,10 +928,9 @@ STATUS PostTrainingQuantizer::DoInference() { return true; }; // func - mindspore::session::KernelCallBack afterCallBack = [&]( - const std::vector &afterInputs, - const std::vector &afterOutputs, - const mindspore::session::CallBackParam &callParam) -> bool { + KernelCallBack afterCallBack = [&](const std::vector &afterInputs, + const std::vector &afterOutputs, + const CallBackParam &callParam) -> bool { if (PostTrainingQuantizer::CheckFp32TensorVec(callParam.node_name, afterOutputs) != RET_OK) { return false; } @@ -969,10 +967,9 @@ STATUS PostTrainingQuantizer::Int8Inference() { } for (size_t i = 0; i < calibrator_->GetBatchNum(); i++) { - mindspore::session::KernelCallBack beforeCallBack = - [this](const std::vector &beforeInputs, - const std::vector &beforeOutputs, - const mindspore::session::CallBackParam &callParam) -> bool { + KernelCallBack beforeCallBack = [this](const std::vector &beforeInputs, + const std::vector &beforeOutputs, + const CallBackParam &callParam) -> bool { if (callParam.node_type == kTypeConv2D || callParam.node_type == kTypeDepthwiseConv2D) { vector fp32_op_input; while (!OpInputDataHandle(FETCH, callParam.node_name, &fp32_op_input)) { @@ -1017,10 +1014,9 @@ STATUS PostTrainingQuantizer::Int8Inference() { return true; }; // func - mindspore::session::KernelCallBack afterCallBack = [this]( - const std::vector &afterInputs, - const std::vector &afterOutputs, - const mindspore::session::CallBackParam &callParam) -> bool { + KernelCallBack afterCallBack = [this](const std::vector &afterInputs, + const std::vector &afterOutputs, + const CallBackParam &callParam) -> bool { if (callParam.node_type == kTypeConv2D || callParam.node_type == kTypeDepthwiseConv2D) { vector fp32_op_output_ch_mean; while (!OpOutputChMeanDataHandle(FETCH, callParam.node_name, &fp32_op_output_ch_mean)) { @@ -1112,10 +1108,9 @@ STATUS PostTrainingQuantizer::BiasCorrection(FuncGraphPtr func_graph) { return RET_ERROR; } } - mindspore::session::KernelCallBack beforeCallBack = - [this](const std::vector &beforeInputs, - const std::vector &beforeOutputs, - const mindspore::session::CallBackParam &callParam) -> bool { + KernelCallBack beforeCallBack = [this](const std::vector &beforeInputs, + const std::vector &beforeOutputs, + const CallBackParam &callParam) -> bool { if (callParam.node_type == kTypeConv2D || callParam.node_type == kTypeDepthwiseConv2D) { if (PostTrainingQuantizer::CheckFp32TensorVec(callParam.node_name, beforeInputs) != RET_OK) { return false; @@ -1136,10 +1131,9 @@ STATUS PostTrainingQuantizer::BiasCorrection(FuncGraphPtr func_graph) { return true; }; // func - mindspore::session::KernelCallBack afterCallBack = [this]( - const std::vector &afterInputs, - const std::vector &afterOutputs, - const mindspore::session::CallBackParam &callParam) -> bool { + KernelCallBack afterCallBack = [this](const std::vector &afterInputs, + const std::vector &afterOutputs, + const CallBackParam &callParam) -> bool { if (callParam.node_type == kTypeConv2D || callParam.node_type == kTypeDepthwiseConv2D) { if (PostTrainingQuantizer::CheckFp32TensorVec(callParam.node_name, afterOutputs) != RET_OK) { return false; @@ -1320,35 +1314,33 @@ STATUS PostTrainingQuantizer::CollectDataFrequency() { } } - mindspore::session::KernelCallBack beforeCallBack = - [&](const std::vector &beforeInputs, - const std::vector &beforeOutputs, - const mindspore::session::CallBackParam &callParam) { - if (PostTrainingQuantizer::CheckFp32TensorVec(callParam.node_name, beforeInputs) != RET_OK) { - return false; - } - auto tensor = beforeInputs[0]; - const float *tensor_data = static_cast(tensor->MutableData()); - size_t shape_size = tensor->ElementsNum(); - vector data(tensor_data, tensor_data + shape_size); - this->calibrator_->UpdateDataFrequency(callParam.node_name, data, this->calibrator_->GetInputDivergInfo()); - return true; - }; + KernelCallBack beforeCallBack = [&](const std::vector &beforeInputs, + const std::vector &beforeOutputs, + const CallBackParam &callParam) { + if (PostTrainingQuantizer::CheckFp32TensorVec(callParam.node_name, beforeInputs) != RET_OK) { + return false; + } + auto tensor = beforeInputs[0]; + const float *tensor_data = static_cast(tensor->MutableData()); + size_t shape_size = tensor->ElementsNum(); + vector data(tensor_data, tensor_data + shape_size); + this->calibrator_->UpdateDataFrequency(callParam.node_name, data, this->calibrator_->GetInputDivergInfo()); + return true; + }; - mindspore::session::KernelCallBack afterCallBack = - [&](const std::vector &after_inputs, - const std::vector &after_outputs, - const mindspore::session::CallBackParam &call_param) { - if (PostTrainingQuantizer::CheckFp32TensorVec(call_param.node_name, after_outputs) != RET_OK) { - return false; - } - auto tensor = after_outputs[0]; - const float *tenosr_data = static_cast(tensor->MutableData()); - size_t shape_size = tensor->ElementsNum(); - vector data(tenosr_data, tenosr_data + shape_size); - this->calibrator_->UpdateDataFrequency(call_param.node_name, data, this->calibrator_->GetOutputDivergInfo()); - return true; - }; + KernelCallBack afterCallBack = [&](const std::vector &after_inputs, + const std::vector &after_outputs, + const CallBackParam &call_param) { + if (PostTrainingQuantizer::CheckFp32TensorVec(call_param.node_name, after_outputs) != RET_OK) { + return false; + } + auto tensor = after_outputs[0]; + const float *tenosr_data = static_cast(tensor->MutableData()); + size_t shape_size = tensor->ElementsNum(); + vector data(tenosr_data, tenosr_data + shape_size); + this->calibrator_->UpdateDataFrequency(call_param.node_name, data, this->calibrator_->GetOutputDivergInfo()); + return true; + }; auto status = fp32_session_->RunGraph(beforeCallBack, afterCallBack); if (status != RET_OK) { MS_LOG(ERROR) << "run model failed!"; diff --git a/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc b/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc index a116b2667b7..1d3631beb04 100644 --- a/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc @@ -245,6 +245,14 @@ const AnfNodePtr ConstFoldPass::Process(const FuncGraphPtr &func_graph, const An FreeTensors(&input_tensors, &output_tensors); return nullptr; } + for (auto output_tensor : output_tensors) { + auto ret = output_tensor->MallocData(); + if (RET_OK != ret) { + MS_LOG(ERROR) << "MallocData failed"; + FreeTensors(&input_tensors, &output_tensors); + return nullptr; + } + } auto ret = lite_kernel->Run(); if (0 != ret) { FreeTensors(&input_tensors, &output_tensors);