diff --git a/mindspore-lite/providers/dpico/common/infer_util.h b/mindspore-lite/providers/dpico/common/infer_util.h deleted file mode 100644 index db910eb2c1b1ae471c193887c014a179c4603084..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/dpico/common/infer_util.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_COMMON_INFER_UTIL_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_INFER_UTIL_H_ - -#include -#include -#include -#include -#include "include/cxx_api/status.h" -#include "include/cxx_api/types.h" -#include "schema/model_generated.h" - -namespace mindspore { -namespace lite { -Status FetchAttrs(const schema::Primitive &primitive, std::map *attrs); -int CheckCustomInputOutput(const std::vector *inputs, - const std::vector *outputs, const schema::Primitive *primitive); -int CheckCustomParam(const schema::Custom *param, const std::string ¶m_name); -class DpicoAicpuThreadManager { - public: - DpicoAicpuThreadManager() = default; - ~DpicoAicpuThreadManager() = default; - int CreateAicpuThread(uint32_t model_id); - int DestroyAicpuThread(); - bool g_threadExitFlag_{true}; - - private: - uint32_t all_aicpu_task_num_{0}; - bool is_aicpu_thread_activity_{false}; - std::thread aicpu_thread_; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_INFER_UTIL_H_ diff --git a/mindspore-lite/providers/dpico/manager/acl_model_helper.h b/mindspore-lite/providers/dpico/manager/acl_model_helper.h deleted file mode 100644 index 10e18e698108078dca026ad6f72ec1fd4117c170..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/dpico/manager/acl_model_helper.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_MANAGER_ACL_MODEL_HELPER_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_HELPER_H_ - -#include -#include -#include "include/svp_acl_mdl.h" -#include "include/cxx_api/types.h" -#include "include/schema/model_generated.h" -#include "common/custom_enum.h" -#include "include/lite_types.h" - -namespace mindspore { -namespace lite { -struct AclDataInfo { - enum DataMode { Input = 0, Output = 1 }; - DataMode data_mode{Input}; - size_t stride{0}; - size_t data_size{0}; - svp_acl_mdl_io_dims dim_info{}; - explicit AclDataInfo(DataMode input_mode) : data_mode(input_mode) {} -}; -int GetAclModelType(const schema::Primitive *primitive, AclModelType *acl_model_type); -int GetAclDataInfo(struct AclDataInfo *acl_data_info, svp_acl_mdl_desc *acl_mdl_desc, int index); -int AddDatasetBuffer(svp_acl_mdl_dataset *acl_mdl_dataset, size_t data_buffer_size, size_t stride, void *data); -int DestroyAclDataset(svp_acl_mdl_dataset **acl_mdl_dataset, - const std::unordered_map &mem_managed_by_tensor, const AllocatorPtr &allocator_ptr); -size_t GetDataTypeSize(svp_acl_mdl_desc *acl_mdl_desc, size_t index, AclDataInfo::DataMode data_mode); -int ComputeValidDetectBoxes(svp_acl_mdl_desc *acl_mdl_desc, svp_acl_mdl_dataset *acl_outputs, - std::vector> *boxes); -int WriteDetBoxesToTensorData(const std::vector> &det_boxes, - mindspore::MSTensor *detect_boxes_tensor); - -int AclMalloc(void **buf, size_t size); -int AclFree(void **buf); -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_HELPER_H_ diff --git a/mindspore-lite/providers/dpico/manager/acl_model_manager.h b/mindspore-lite/providers/dpico/manager/acl_model_manager.h deleted file mode 100644 index 2414ac5ce60ac072ad0c42d38ceca9438775d3e9..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/dpico/manager/acl_model_manager.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_MANAGER_ACL_MODEL_MANAGER_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_MANAGER_H_ - -#include -#include -#include -#include -#include -#include "include/cxx_api/types.h" -#include "include/svp_acl_base.h" -#include "include/svp_acl_mdl.h" -#include "manager/acl_context_manager.h" -#include "manager/custom_config_manager.h" -#include "common/custom_enum.h" -#include "include/schema/model_generated.h" -#include "include/lite_types.h" - -namespace mindspore { -namespace lite { -class AclModelManager { - public: - AclModelManager() = default; - ~AclModelManager(); - - int Init(const std::map &dpico_config, - const std::map &model_share_config, const schema::Primitive *primitive, - const std::vector &input_tensors, - const std::vector &output_tensors); - int UpdateBatchSize(const std::vector &input_tensors); - int PrepareAclInputs(std::vector *input_tensors); - int PrepareAclOutputs(std::vector *output_tensors); - int UpdateKernelConfig(const std::map &dpico_config); - int UpdateAclInputs(std::vector *input_tensors); - int UpdateAclOutputs(std::vector *output_tensors); - int Execute(const std::vector &input_tensors, - const std::vector &output_tensors, - const std::map &model_share_config); - - private: - int LoadModel(const std::vector &input_tensors); - int CreateModelDesc(); - int SetDetectParams(void *data); - int AddDetectParamInput(); - int DetectPostProcess(mindspore::MSTensor *output_tensors); - int CreateTaskBufAndWorkBuf(); - int CreateNoShareTaskBufAndWorkBuf(); - int GetMaxTaskAndWorkBufSize(); - int CopyTensorDataToAclInputs(const std::vector &input_tensors); - int CopyAclOutputsToTensorData(const std::vector &output_tensors); - int FlushAclInputsAndOutputs(); - int AclModelRun(const std::vector &input_tensors); - int UnloadModel(); - - private: - static AllocatorPtr custom_allocator_; - static CustomConfigManagerPtr custom_config_manager_ptr_; - static AclContextManagerPtr acl_context_manager_; - - std::unordered_map inputs_mem_managed_by_tensor; // - std::unordered_map outputs_mem_managed_by_tensor; // - - size_t actual_batch_size_{1}; - /** acl related variables */ - uint32_t acl_model_id_{0}; - int32_t acl_device_id_{0}; - size_t stride_align_size_{16}; - AclModelType acl_model_type_{kCnn}; - void *acl_model_ptr_{nullptr}; - svp_acl_mdl_desc *acl_model_desc_{nullptr}; - svp_acl_mdl_dataset *acl_inputs_{nullptr}; - svp_acl_mdl_dataset *acl_outputs_{nullptr}; -}; -using AclModelManagerPtr = std::shared_ptr; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_MANAGER_H_ diff --git a/mindspore-lite/providers/dpico/src/custom_allocator.h b/mindspore-lite/providers/dpico/src/custom_allocator.h deleted file mode 100644 index 036c5528dc4b53e2259b566bfe1018a05ed97889..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/dpico/src/custom_allocator.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright 2021-2022 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_PROVIDERS_DPICO_SRC_CUSTOM_ALLOCATOR_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_ALLOCATOR_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "include/cxx_api/allocator.h" - -namespace mindspore { -namespace lite { -struct AllocatorContext { - int shiftFactor; - bool lockFlag; -}; - -class CustomAllocator : public Allocator { - public: - explicit CustomAllocator(size_t aligned_size = 32); - ~CustomAllocator() override; - void SetContext(const AllocatorContext &ctx); - void *Malloc(size_t size) override; - void Free(void *ptr) override; - int RefCount(void *ptr) override; - int SetRefCount(void *ptr, int ref_count) override; - int DecRefCount(void *ptr, int ref_count) override; - int IncRefCount(void *ptr, int ref_count) override; - size_t total_size() const { return this->total_size_; } - void Clear(); - - private: - void Lock(); - void UnLock(); - bool ReuseMemory(size_t free_size, size_t size) const; - struct MemBuf { - std::atomic_int ref_count_ = {0}; - size_t size = 0; - void *buf = nullptr; - }; - - std::mutex lock_; - size_t total_size_ = 0; - // buf, membuf> - std::unordered_map allocated_list_; - std::multimap free_list_; - // 6 is empirical value - unsigned shift_factor_ = 6; - bool lock_flag_ = true; - size_t max_malloc_size_ = 0; -}; -using CustomAllocatorPtr = std::shared_ptr; -constexpr int64_t MAX_MALLOC_SIZE = static_cast(2000) * 1024 * 1024; -constexpr int64_t MAX_THREAD_POOL_SIZE = static_cast(3000) * 1024 * 1024; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_ALLOCATOR_H_ diff --git a/mindspore-lite/providers/dpico/src/custom_fp32.cc b/mindspore-lite/providers/dpico/src/custom_fp32.cc deleted file mode 100644 index 15fd791e452e9d03c5198998fc73e969785dd3ce..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/dpico/src/custom_fp32.cc +++ /dev/null @@ -1,297 +0,0 @@ -/** - * Copyright 2021-2023 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/custom_fp32.h" -#include -#include -#include -#include -#include "common/check_base.h" -#include "common/infer_util.h" -#include "common/op_attr.h" -#include "include/cxx_api/data_type.h" -#include "include/registry/register_kernel.h" -#include "include/registry/register_kernel_interface.h" - -namespace mindspore { -namespace lite { -constexpr size_t kNumOfInputOm = 1; - -bool CustomCPUKernel::InferShapeDone() const { - if (std::any_of(inputs_.begin(), inputs_.end(), [](const MSTensor &input) { - return input.DataType() == mindspore::DataType::kObjectTypeTensorType; - })) { - return false; - } - auto shape = outputs_.front().Shape(); - return !(std::find(shape.begin(), shape.end(), -1) != shape.end()); -} - -size_t DataTypeSize(mindspore::DataType data_type) { - switch (data_type) { - case mindspore::DataType::kNumberTypeFloat64: - return sizeof(double); - case mindspore::DataType::kNumberTypeFloat32: - return sizeof(float); - case mindspore::DataType::kNumberTypeInt8: - return sizeof(int8_t); - case mindspore::DataType::kNumberTypeUInt8: - return sizeof(uint8_t); - case mindspore::DataType::kNumberTypeFloat16: - case mindspore::DataType::kNumberTypeInt16: - return sizeof(int16_t); - case mindspore::DataType::kNumberTypeInt32: - return sizeof(int32_t); - case mindspore::DataType::kNumberTypeInt64: - return sizeof(int64_t); - case mindspore::DataType::kNumberTypeUInt16: - return sizeof(uint16_t); - case mindspore::DataType::kNumberTypeUInt32: - return sizeof(uint32_t); - case mindspore::DataType::kNumberTypeUInt64: - return sizeof(uint64_t); - case mindspore::DataType::kNumberTypeBool: - return sizeof(bool); - case mindspore::DataType::kObjectTypeString: - return sizeof(char); - case mindspore::DataType::kObjectTypeTensorType: - return 0; - default: - MS_LOG(ERROR) << "Not support the type: " << static_cast(data_type); - return 0; - } -} - -void CustomCPUKernel::UpdateInputOutputTensor() { - if (custom_id_ == 0) { - for (size_t i = 0; i < inputs_.size() - kNumOfInputOm; i++) { - std::vector shape = inputs_[i].Shape(); - if (shape.empty()) { - MS_LOG(ERROR) << "Input[" << i << "]`s shape is empty."; - return; - } - size_t shape_len = shape.size(); - size_t data_type_size = DataTypeSize(inputs_[i].DataType()); - if (data_type_size == 0) { - MS_LOG(ERROR) << "data type size is 0."; - return; - } - int64_t last_dim_size = shape[shape_len - 1] * data_type_size; - MS_LOG(DEBUG) << "Input last_dim = " << shape[shape_len - 1]; - if (last_dim_size % stride_align_size_ != 0) { - last_dim_size = (last_dim_size + stride_align_size_ - 1) & (~(stride_align_size_ - 1)); - int64_t last_dim_new = last_dim_size / data_type_size; - MS_LOG(DEBUG) << "Input new last_dim = " << last_dim_new; - shape[shape_len - 1] = last_dim_new; - inputs_[i].SetShape(shape); - } - } - } - if (custom_id_ == custom_num_ - 1) { - for (size_t i = 0; i < outputs_.size(); i++) { - auto shape = outputs_[i].Shape(); - if (shape.empty()) { - MS_LOG(ERROR) << "Output[" << i << "]`s shape is empty."; - return; - } - size_t shape_len = shape.size(); - size_t data_type_size = DataTypeSize(outputs_[i].DataType()); - if (data_type_size == 0) { - MS_LOG(ERROR) << "data type size is 0."; - return; - } - int64_t last_dim_size = shape[shape_len - 1] * data_type_size; - MS_LOG(DEBUG) << "Output last_dim = " << shape[shape_len - 1]; - if (last_dim_size % stride_align_size_ != 0) { - last_dim_size = (last_dim_size + stride_align_size_ - 1) & (~(stride_align_size_ - 1)); - int64_t last_dim_new = last_dim_size / data_type_size; - MS_LOG(DEBUG) << "Output new last_dim = " << last_dim_new; - shape[shape_len - 1] = last_dim_new; - outputs_[i].SetShape(shape); - } - } - } -} - -int CustomCPUKernel::ParseAttrs() { - std::map attrs; - std::string internal_stride; - std::string custom_id; - std::string custom_num; - std::string head_tail_op_is_custom; - - if (FetchAttrs(*primitive_, &attrs) == kSuccess) { - if (attrs.find("head_tail_op_is_custom") != attrs.end()) { - head_tail_op_is_custom = attrs.at("head_tail_op_is_custom"); - if (head_tail_op_is_custom != "1") { - MS_LOG(ERROR) << "When setting 'SupportZeroCopy=on', " - << "you must ensure that the first and last operators are custom operators."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "Get head_tail_op_is_custom failed."; - return RET_ERROR; - } - if (attrs.find(kLastDimStride) != attrs.end()) { - internal_stride = attrs.at(kLastDimStride); - } else { - MS_LOG(ERROR) << "Get internal_stride failed."; - return RET_ERROR; - } - if (attrs.find("custom_id") != attrs.end()) { - custom_id = attrs.at("custom_id"); - } else { - MS_LOG(ERROR) << "Get custom_id failed."; - return RET_ERROR; - } - if (attrs.find("custom_num") != attrs.end()) { - custom_num = attrs.at("custom_num"); - } else { - MS_LOG(ERROR) << "Get custom_num failed."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "Fetch attrs failed."; - return RET_ERROR; - } - - stride_align_size_ = static_cast(stoi(internal_stride)); - custom_id_ = static_cast(stoi(custom_id)); - custom_num_ = static_cast(stoi(custom_num)); - return RET_OK; -} - -int CustomCPUKernel::Prepare() { - CHECK_LESS_RETURN(inputs_.size(), kInputSize2); - CHECK_LESS_RETURN(outputs_.size(), 1); - if (acl_model_manager_ == nullptr) { - acl_model_manager_ = std::make_shared(); - MS_CHECK_TRUE_MSG(acl_model_manager_ != nullptr, RET_ERROR, "Acl_model_manager_ is nullptr"); - } - - std::map config_info = this->GetConfig(kDpico); - // init model manager - if (acl_model_manager_->Init(config_info, this->GetConfig(kModelSharingSection), primitive_, inputs_, outputs_) != - RET_OK) { - MS_LOG(ERROR) << "Init acl model manager failed."; - return RET_ERROR; - } - - if (!InferShapeDone()) { - MS_LOG(INFO) << "Infershape isn't done, skip this procedure"; - return RET_OK; - } - - if (config_info.find(kSupportZeroCopy) != config_info.end()) { - if (config_info[kSupportZeroCopy] == "on") { - support_zero_copy_ = "on"; - MS_LOG(INFO) << "Set 'SupportZeroCopy=on', will support zero copy."; - } else { - MS_LOG(INFO) << "Do not set 'SupportZeroCopy=on', will not support zero copy."; - } - } else { - MS_LOG(INFO) << "Do not set 'SupportZeroCopy', will not support zero copy."; - } - - if (support_zero_copy_ == "on") { - if (ParseAttrs() != RET_OK) { - MS_LOG(ERROR) << "Parse attrs failed or the attr is invalid."; - return RET_ERROR; - } - UpdateInputOutputTensor(); - } - if (acl_model_manager_->UpdateBatchSize(inputs_) != RET_OK) { - MS_LOG(ERROR) << "Update batch size for acl model manager failed."; - return RET_ERROR; - } - if (acl_model_manager_->PrepareAclInputs(&inputs_) != RET_OK) { - MS_LOG(ERROR) << "Prepare inputs for acl model manager failed."; - return RET_ERROR; - } - if (acl_model_manager_->PrepareAclOutputs(&outputs_) != RET_OK) { - MS_LOG(ERROR) << "Prepare outputs for acl model manager failed."; - return RET_ERROR; - } - return RET_OK; -} - -int CustomCPUKernel::ReSize() { - if (!InferShapeDone()) { - auto custom_kernel_interface = registry::RegisterKernelInterface::GetKernelInterface("", primitive_, this); - MS_CHECK_TRUE_MSG(custom_kernel_interface != nullptr, RET_ERROR, "Get custom kernel interface failed."); - auto status = custom_kernel_interface->Infer(&inputs_, &outputs_, primitive_, this); - MS_CHECK_TRUE_MSG(status == kSuccess, RET_ERROR, "Custom op infershape failed. " << this->name()); - } - if (support_zero_copy_ == "on") { - UpdateInputOutputTensor(); - } - if (acl_model_manager_->UpdateBatchSize(inputs_) != RET_OK) { - MS_LOG(ERROR) << "Update batch size for acl model manager failed."; - return RET_ERROR; - } - - auto ret = acl_model_manager_->UpdateKernelConfig(this->GetConfig(kDpico)); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "Acl model manager update kernel config failed."); - ret = acl_model_manager_->UpdateAclInputs(&inputs_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "Acl model manager update inputs failed."); - ret = acl_model_manager_->UpdateAclOutputs(&outputs_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "Acl model manager update outputs failed."); - return RET_OK; -} - -int CustomCPUKernel::Execute() { - // reallocate memory for output data - for (auto output : outputs_) { - auto data = output.MutableData(); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "Output tensor data is nullptr. " << output.Name()); - } - if (acl_model_manager_->Execute(inputs_, outputs_, this->GetConfig(kModelSharingSection)) != RET_OK) { - MS_LOG(ERROR) << "Acl model manager execute failed."; - return RET_ERROR; - } - return RET_OK; -} - -std::shared_ptr CustomCreateKernel(const std::vector &inputs, - const std::vector &outputs, - const mindspore::schema::Primitive *primitive, - const mindspore::Context *ctx) { - MS_CHECK_TRUE_MSG(primitive != nullptr, nullptr, "Primitive is nullptr"); - MS_CHECK_TRUE_MSG(ctx != nullptr, nullptr, "Ctx is nullptr"); - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - MS_LOG(ERROR) << "Primitive type is not PrimitiveType_Custom"; - return nullptr; - } - - auto op = primitive->value_as_Custom(); - MS_CHECK_TRUE_MSG(op != nullptr, nullptr, "Op is nullptr"); - MS_CHECK_TRUE_MSG(op->attr() != nullptr, nullptr, "Op attr is nullptr"); - MS_CHECK_TRUE_MSG(op->attr()->size() >= 1, nullptr, "There should be at least 1 attribute of Custom"); - auto kernel = std::make_shared(inputs, outputs, primitive, ctx); - MS_CHECK_TRUE_MSG(kernel != nullptr, nullptr, "New custom kernel is nullptr"); - return kernel; -} - -namespace { -const auto kFloat32 = DataType::kNumberTypeFloat32; -const auto kInt8 = DataType::kNumberTypeInt8; -const auto kUInt8 = DataType::kNumberTypeUInt8; -} // namespace -REGISTER_CUSTOM_KERNEL(CPU, DPICO, kFloat32, DPICO, CustomCreateKernel) -REGISTER_CUSTOM_KERNEL(CPU, DPICO, kInt8, DPICO, CustomCreateKernel) -REGISTER_CUSTOM_KERNEL(CPU, DPICO, kUInt8, DPICO, CustomCreateKernel) -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/src/custom_fp32.h b/mindspore-lite/providers/dpico/src/custom_fp32.h deleted file mode 100644 index bd5d605e1e9110f80288953c56473f8b7df0d2c4..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/dpico/src/custom_fp32.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2021-2022 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_PROVIDERS_DPICO_SRC_CUSTOM_FP32_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_FP32_H_ - -#include -#include -#include "include/cxx_api/kernel.h" -#include "include/errorcode.h" -#include "manager/acl_model_manager.h" - -using mindspore::kernel::Kernel; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace lite { -class CustomCPUKernel : public Kernel { - public: - CustomCPUKernel(const std::vector &inputs, const std::vector &outputs, - const mindspore::schema::Primitive *primitive, const mindspore::Context *ctx) - : Kernel(inputs, outputs, primitive, ctx) {} - - ~CustomCPUKernel() = default; - - int Prepare() override; - int ReSize() override; - int Execute() override; - - private: - int ParseAttrs(); - bool InferShapeDone() const; - int PreProcess(); - void UpdateInputOutputTensor(); - - private: - AclModelManagerPtr acl_model_manager_{nullptr}; - std::string support_zero_copy_{"off"}; - size_t stride_align_size_{16}; - size_t custom_id_{0}; - size_t custom_num_{0}; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_FP32_H_ diff --git a/mindspore-lite/providers/nnie/src/custom_allocator.h b/mindspore-lite/providers/nnie/src/custom_allocator.h deleted file mode 100644 index 8d01ce95106a591698df0ac1fe326d3d8cf31f18..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie/src/custom_allocator.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_NNIE_SRC_CUSTOM_ALLOCATOR_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_ALLOCATOR_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "include/cxx_api/allocator.h" -#include "include/hi_type.h" - -namespace mindspore { -namespace nnie { -class CustomAllocator : public Allocator { - public: - CustomAllocator() {} - ~CustomAllocator() override{}; - void *Malloc(size_t size) override { return nullptr; } - void Free(void *ptr) override {} - int RefCount(void *ptr) override { return 1; } - int SetRefCount(void *ptr, int ref_count) override { return ref_count; } - int DecRefCount(void *ptr, int ref_count) override { return 1; } - int IncRefCount(void *ptr, int ref_count) override { return 1; } -}; -} // namespace nnie -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_ALLOCATOR_H_ diff --git a/mindspore-lite/providers/nnie/src/custom_fp32.h b/mindspore-lite/providers/nnie/src/custom_fp32.h deleted file mode 100644 index 1933ab5abf203754572f7310aeb81f73a1fbdea9..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie/src/custom_fp32.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright 2021 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_PROVIDERS_NNIE_SRC_CUSTOM_FP32_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_FP32_H_ - -#include -#include -#include -#include "include/schema/model_generated.h" -#include "include/cxx_api/kernel.h" -#include "src/custom_infer.h" -#include "include/hi_type.h" -#include "src/nnie_cfg_parser.h" -#include "src/nnie_manager.h" -#include "src/nnie_print.h" -#include "src/custom_allocator.h" - -using mindspore::MSTensor; -using mindspore::kernel::Kernel; -namespace mindspore { -namespace nnie { -class CustomCPUKernel : public Kernel { - public: - CustomCPUKernel(nnie::NNIEManager *manager, int seg_id, bool forward_bbox, const std::vector &inputs, - const std::vector &outputs, const mindspore::schema::Primitive *primitive, - const mindspore::Context *ctx) - : Kernel(inputs, outputs, primitive, ctx), manager_(manager), seg_id_(seg_id), forward_bbox_(forward_bbox) { - if ((manager_) == nullptr) { - LOGE("manager_ is nullptr."); - } else { - manager_->SetMaxSegId(seg_id); - } - } - - ~CustomCPUKernel() override; - - int Prepare() override; - int ReSize() override; - int Execute() override; - - int seg_id(void) const { return seg_id_; } - - void set_seg_id(int id) { seg_id_ = id; } - - int forward_bbox(void) const { return forward_bbox_; } - - void set_forward_bbox(bool flag) { forward_bbox_ = flag; } - - private: - nnie::NNIEManager *manager_ = nullptr; - int seg_id_ = 0; - bool forward_bbox_ = false; - std::vector> outputs_shapes_; -}; -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_FP32_H_ diff --git a/mindspore-lite/providers/nnie/src/custom_infer.cc b/mindspore-lite/providers/nnie/src/custom_infer.cc deleted file mode 100644 index da789bedc1dbd6e2b6d3502162d160b02bc2e0e6..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie/src/custom_infer.cc +++ /dev/null @@ -1,166 +0,0 @@ -/** - * Copyright 2021 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/custom_infer.h" -#include -#include -#include "include/errorcode.h" -#include "src/nnie_print.h" -#include "include/cxx_api/format.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace nnie { -std::shared_ptr CustomInferCreater() { - auto infer = new (std::nothrow) CustomInterface(); - if (infer == nullptr) { - LOGE("new custom infer is nullptr"); - return nullptr; - } - return std::shared_ptr(infer); -} - -int GetCustomShape(const mindspore::schema::Custom *op, const std::string &attr, - std::vector> *shapes) { - char buf[kMaxSize]; - bool has_outputs_shape = false; - - for (size_t i = 0; i < op->attr()->size(); i++) { - if (op->attr()->Get(i)->name()->str() == attr) { - auto output_info = op->attr()->Get(i)->data(); - int attr_size = static_cast(output_info->size()); - if (attr_size >= kMaxSize) { - LOGE("attr size too big"); - return RET_ERROR; - } - for (int j = 0; j < attr_size; j++) { - buf[j] = static_cast(output_info->Get(j)); - } - buf[attr_size] = 0; - has_outputs_shape = true; - break; - } - } - - if (!has_outputs_shape) { - LOGE("Custom op don't have %s attr.", attr.c_str()); - return RET_ERROR; - } - - char delims[] = ","; - char *res = nullptr; - char *save_ptr = nullptr; - res = strtok_r(buf, delims, &save_ptr); - while (res != nullptr) { - int64_t ndims = strtol(res, &res, kDecimal); - int j = 0; - std::vector shape; - shape.resize(ndims); - for (; j < ndims; j++) { - res = strtok_r(NULL, delims, &save_ptr); - shape[j] = static_cast(strtol(res, &res, kDecimal)); - } - shapes->push_back(shape); - - res = strtok_r(NULL, delims, &save_ptr); - } - return RET_OK; -} - -Status CustomInterface::Infer(std::vector *inputs, std::vector *outputs, - const mindspore::schema::Primitive *primitive) { - auto check_param = inputs != nullptr && outputs != nullptr && primitive != nullptr; - if (!check_param) { - LOGE("inputs, outputs or primitive is null"); - return kLiteError; - } - if (inputs->empty()) { - LOGE("Inputs size 0"); - return kLiteError; - } - if (outputs->empty()) { - LOGE("Outputs size 0"); - return kLiteError; - } - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - LOGE("Primitive type is not PrimitiveType_Custom"); - return kLiteError; - } - - auto op = primitive->value_as_Custom(); - if ((op == nullptr) || (op->attr() == nullptr)) { - LOGE("op or its attr is null"); - return kLiteError; - } - if (op->attr()->size() < 1) { - LOGE("There are at least 1 attribute of Custom"); - return kLiteError; - } - std::vector> inputs_shape; - if (GetCustomShape(op, "inputs_shape", &inputs_shape) != RET_OK) { - LOGE("parser inputs_shape attribute err."); - return kLiteError; - } - std::vector> outputs_shape; - if (GetCustomShape(op, "outputs_shape", &outputs_shape) != RET_OK) { - LOGE("parser outputs_shape attribute err."); - return kLiteError; - } - if (inputs_shape.size() != (inputs->size() - 1)) { - LOGE("inputs num diff inputs_shape num."); - return kLiteError; - } - if (inputs_shape[0].size() != (*inputs)[0].Shape().size()) { - LOGE("shape size err."); - return kLiteError; - } - bool resize_flag = false; - int resize_num = 1; - for (size_t i = 0; i < inputs_shape[0].size(); i++) { - if (inputs_shape[0][i] != (*inputs)[0].Shape()[i]) { - if (i == 0) { - resize_flag = true; - resize_num = (*inputs)[0].Shape()[i]; - } else { - LOGE("Custom of NNIE only support batch_num resize."); - return kLiteError; - } - } - } - if (resize_flag) { - for (auto &output_shape : outputs_shape) { - output_shape[0] = resize_num; - } - } - for (size_t i = 0; i < outputs->size(); i++) { - (*outputs)[i].SetShape(outputs_shape[i]); - (*outputs)[i].SetDataType(DataType::kNumberTypeFloat32); - (*outputs)[i].SetFormat(Format::NCHW); - } - return kSuccess; -} -} // namespace nnie -} // namespace mindspore -namespace mindspore { -namespace kernel { -REGISTER_CUSTOM_KERNEL_INTERFACE(NNIE, NNIE, nnie::CustomInferCreater); -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/nnie_cfg_parser.h b/mindspore-lite/providers/nnie/src/nnie_cfg_parser.h deleted file mode 100644 index 751fcea1a1fb61d93c3f882fac92e91ccf2fffde..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie/src/nnie_cfg_parser.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2021 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_PROVIDERS_NNIE_SRC_NNIE_CFG_PARSER_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_CFG_PARSER_H_ -#include -#include -#include -#include "include/cxx_api/kernel.h" -#include "include/hi_type.h" - -namespace mindspore { -namespace nnie { -typedef struct { - HI_U64 phy_; - HI_U32 size_; -} MEM_ITEM; -/** - * Flags is a config container. - * Member objects: - * 1.time_step_: step num only for rnn or lstm model. Default is 1. - * 2.max_roi_num_: maximum number of ROI area, which is single picture supports, must be greater than 0.Default is 300. - * 3.core_ids_: running kernels' id, support multi-core, separated by commas when setting, such as {0, 1, 2}. - * each element must be an integer, wch meet such inequality 0 <= val < 8. - * Default is {0}. - */ -class Flags { - public: - Flags() = default; - ~Flags() = default; - int Init(const kernel::Kernel &kernel); - - public: - int time_step_{1}; - int max_roi_num_{300}; - std::vector core_ids_{0}; - bool keep_origin_output_{false}; - - private: - int ParserInt(const std::map &nnie_arg, const std::string key, int *val); - int ParserBool(const std::map &nnie_arg, const std::string key, bool *val); -}; -} // namespace nnie -} // namespace mindspore -#endif diff --git a/mindspore-lite/providers/nnie/src/nnie_manager.h b/mindspore-lite/providers/nnie/src/nnie_manager.h deleted file mode 100644 index 71e13553bbc74f14e752d76f3f4ecaa21313b1de..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie/src/nnie_manager.h +++ /dev/null @@ -1,117 +0,0 @@ -/** - * Copyright 2021 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_PROVIDERS_NNIE_SRC_NNIE_MANAGER_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_MANAGER_H_ -#include -#include -#include -#include -#include "include/errorcode.h" -#include "include/cxx_api/types.h" -#include "include/cxx_api/allocator.h" -#include "src/nnie_common.h" -#include "src/nnie_cfg_parser.h" - -namespace mindspore { -namespace nnie { -class NNIEManager { - public: - static NNIEManager *GetInstance(const void *model_buf) { - static std::map managers_; - auto iter = managers_.find(model_buf); - if (iter != managers_.end()) { - return iter->second; - } else { - auto manager = new (std::nothrow) NNIEManager(); - if (manager == nullptr) { - return manager; - } else { - managers_[model_buf] = manager; - return manager; - } - } - } - - NNIEManager() {} - - ~NNIEManager() {} - - int Init(char *model_buf, int size, const std::vector &inputs); - - int CfgInit(const Flags &flags, int max_seg_id); - - void SetInputNum(int max_input_num); - - int SetAllocatorInputs(std::vector *inputs, bool run_box, std::shared_ptr allocator, - unsigned int seg_id); - - int SetAllocatorOutputs(std::vector *outputs, bool run_box, std::shared_ptr allocator, - unsigned int seg_id); - - int SetAllocator(std::vector *inputs, std::vector *outputs, - std::shared_ptr allocator, unsigned int seg_id); - - int FillData(std::vector *inputs, unsigned int seg_id); - - int Run(std::vector *outputs, unsigned int seg_id, - const std::vector> &outputs_shape); - - void Release(bool resize_flag); - - int LoadInputs(std::vector *inputs, std::shared_ptr allocator); - - int LoadOutputs(std::vector *outputs, std::shared_ptr allocator); - - int SetBlobAddr(SVP_SRC_BLOB_S *blob, HI_U64 virt, mindspore::MSTensor *tensor, std::shared_ptr allocator); - - void SetMaxSegId(int max_id) { - if (max_id > max_seg_id_) { - max_seg_id_ = max_id; - } - } - - inline int GetMaxSegId() { return max_seg_id_; } - - inline Flags *GetFlags() { return &flags_; } - - inline bool GetLoadModel() { return load_model_; } - - void SetLoadModel(bool flag) { load_model_ = flag; } - - private: - int SetAllocatorTensor(mindspore::MSTensor *tensor, SVP_SRC_BLOB_S *blob, std::shared_ptr allocator); - - int GetOutputData(std::vector *outputs, const std::vector> &outputs_shape, - bool run_box = false); - - int MallocBlobData(SVP_SRC_BLOB_S *blob, mindspore::MSTensor *tensor, HI_U32 blob_size); - - int FillRoiPooling(mindspore::MSTensor *input); - char *wk_model_ = nullptr; - - int model_size_ = 0; - - NnieRunCfg nnie_cfg_; - int max_seg_id_ = 0; - Flags flags_; - bool load_model_ = false; - std::vector blobs_; - std::vector tensors_; -}; -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_MANAGER_H_ diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal.h b/mindspore-lite/providers/nnie_proposal/src/proposal.h deleted file mode 100644 index 492048b9bda330cec446ba313d8771ffe6699d6f..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal.h +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright 2021 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_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_H_ -#include -#include "include/cxx_api/types.h" - -#define LOG_TAG1 "Proposal" -#define LOGE(format, ...) \ - do { \ - if (1) { \ - fprintf(stderr, "\n[ERROR] " LOG_TAG1 " [" __FILE__ ":%d] %s] ", __LINE__, __FUNCTION__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - } \ - } while (0) - -#define LOGW(format, ...) \ - do { \ - if (1) { \ - fprintf(stderr, "\n[Warning] " LOG_TAG1 " [" __FILE__ ":%d] %s] ", __LINE__, __FUNCTION__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - } \ - } while (0) - -namespace mindspore { -namespace proposal { -typedef struct { - uint32_t stride_; - void *data_; - uint32_t num_; - uint32_t width_; - uint32_t height_; - uint32_t chn_; -} RpnBoundingBox; - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define HALF_VAL 0.5f // the half value -#define COORDI_NUM 4 // coordinate numbers -#define PROPOSAL_WIDTH 6 // the number of proposal values -#define QUANT_BASE 4096 // the base value -#define SCORE_NUM 2 // the num of RPN scores -#define NUM_SCALE_ANCHORS 9 -#define NUM_NMS 6000 -#define MIN_SIZE 16 - -typedef struct { - uint32_t scales_[9]; - uint32_t ratios_[9]; - uint32_t inputs_height_[2]; - uint32_t inputs_width_[2]; - uint32_t inputs_channel_[2]; - uint32_t inputs_stride_; - uint32_t num_ratio_anchors_; - uint32_t num_scale_anchors_; - uint32_t ori_image_height_; - uint32_t ori_image_width_; - uint32_t min_size_; - uint32_t spatial_scale_; - uint32_t nms_thresh_; - uint32_t filter_thresh_; - uint32_t max_roi_num_; - uint32_t num_before_nms_; - float *inputs_[2]; - void *rpn_tmp_buf_; - RpnBoundingBox rpn_bounding_box_; -} ProposalParam; - -typedef struct { - int32_t min_; - int32_t max_; -} Stack; - -int32_t ProposalInit(ProposalParam *param, uint32_t max_roi_num, uint32_t ori_image_height, uint32_t ori_image_width); -int32_t ProposalRun(ProposalParam *param); -void ProposalDeInit(ProposalParam *param); -} // namespace proposal -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_H_ diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.h b/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.h deleted file mode 100644 index 8512151f6fa4c9aa549a2a109ad3fe98ab5e5eab..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2021 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_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_FP32_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_FP32_H_ - -#include -#include "schema/model_generated.h" -#include "include/cxx_api/kernel.h" -#include "src/proposal.h" - -using mindspore::kernel::Kernel; -namespace mindspore { -namespace proposal { -class ProposalCPUKernel : public Kernel { - public: - ProposalCPUKernel(const std::vector &inputs, const std::vector &outputs, - const mindspore::schema::Primitive *primitive, const mindspore::Context *ctx, int id, - int image_height, int image_width) - : Kernel(inputs, outputs, primitive, ctx), id_(id), image_height_(image_height), image_weight_(image_width) {} - - ~ProposalCPUKernel() override; - - int Prepare() override; - int ReSize() override; - int Execute() override; - - private: - proposal::ProposalParam proposal_param_ = {0}; - int64_t id_; - int64_t image_height_; - int64_t image_weight_; -}; -} // namespace proposal -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_FP32_H_ diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal_infer.cc b/mindspore-lite/providers/nnie_proposal/src/proposal_infer.cc deleted file mode 100644 index 65e4baf85e4c2e8285827e047ce83d0d8164581c..0000000000000000000000000000000000000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal_infer.cc +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2021 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/proposal_infer.h" -#include -#include -#include "include/errorcode.h" -#include "src/proposal.h" -#include "include/cxx_api/format.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace proposal { -std::shared_ptr ProposalInferCreater() { - auto infer = std::make_shared(); - if (infer == nullptr) { - LOGE("new custom infer is nullptr"); - return nullptr; - } - - return infer; -} -Status ProposalInterface::Infer(std::vector *inputs, std::vector *outputs, - const mindspore::schema::Primitive *primitive) { - if (inputs->size() != 2) { - LOGE("Inputs size less 2"); - return kLiteError; - } - if (outputs->size() == 0) { - LOGE("Outputs size 0"); - return kLiteError; - } - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - LOGE("Primitive type is not PrimitiveType_Custom"); - return kLiteError; - } - - size_t id = 0; - while (id < outputs->size()) { - std::vector shape{-1, COORDI_NUM}; - (*outputs)[id].SetShape(shape); - (*outputs)[id].SetDataType(DataType::kNumberTypeFloat32); - (*outputs)[id].SetFormat(Format::NCHW); - id++; - } - return kSuccess; -} -} // namespace proposal -} // namespace mindspore -namespace mindspore { -namespace kernel { -REGISTER_CUSTOM_KERNEL_INTERFACE(NNIE, Proposal, proposal::ProposalInferCreater); -} // namespace kernel -} // namespace mindspore