From e588be429138c27a08ec0434c539ae6f9c2ab357 Mon Sep 17 00:00:00 2001 From: zhaizhiqiang Date: Sat, 2 Apr 2022 14:39:37 +0800 Subject: [PATCH] remove unuseful api --- include/api/cell.h | 45 ------------ include/api/model.h | 106 ++++++++++++++--------------- include/api/ops/ops.h | 48 ------------- mindspore/ccsrc/cxx_api/cell.cc | 54 --------------- mindspore/ccsrc/cxx_api/ops/ops.cc | 38 ----------- mindspore/lite/src/cxx_api/cell.cc | 30 -------- 6 files changed, 53 insertions(+), 268 deletions(-) delete mode 100644 include/api/ops/ops.h delete mode 100644 mindspore/ccsrc/cxx_api/ops/ops.cc diff --git a/include/api/cell.h b/include/api/cell.h index 8f33aa54ee2..e0813467666 100644 --- a/include/api/cell.h +++ b/include/api/cell.h @@ -46,47 +46,6 @@ class MS_API Cell : public CellBase { std::shared_ptr Clone() const override { return std::make_shared(static_cast(*this)); } }; -class MS_API ParameterCell final : public Cell { - public: - ParameterCell() = default; - ~ParameterCell() override = default; - - ParameterCell(const ParameterCell &); - ParameterCell &operator=(const ParameterCell &); - - ParameterCell(ParameterCell &&); - ParameterCell &operator=(ParameterCell &&); - - explicit ParameterCell(const MSTensor &); - ParameterCell &operator=(const MSTensor &); - - explicit ParameterCell(MSTensor &&); - ParameterCell &operator=(MSTensor &&); - - MSTensor GetTensor() const { return tensor_; } - - private: - MSTensor tensor_; -}; - -class MS_API OpCellBase : public CellBase { - public: - explicit OpCellBase(const std::string &name) : name_(name) {} - ~OpCellBase() override = default; - const std::string &GetOpType() const { return name_; } - - protected: - std::string name_; -}; - -template -class MS_API OpCell : public OpCellBase, public std::enable_shared_from_this { - public: - explicit OpCell(const std::string &name) : OpCellBase(name) {} - ~OpCell() override = default; - std::shared_ptr Clone() const override { return std::make_shared(static_cast(*this)); } -}; - class MS_API GraphCell final : public Cell { public: class GraphImpl; @@ -117,10 +76,6 @@ class MS_API InputAndOutput { InputAndOutput(); ~InputAndOutput() = default; - // no explicit - InputAndOutput(const MSTensor &); // NOLINT(runtime/explicit) - InputAndOutput(MSTensor &&); // NOLINT(runtime/explicit) - InputAndOutput(const std::shared_ptr &, const std::vector &, int32_t index); int32_t GetIndex() const { return index_; } diff --git a/include/api/model.h b/include/api/model.h index ba682550579..b0ac1fff379 100644 --- a/include/api/model.h +++ b/include/api/model.h @@ -45,6 +45,59 @@ class MS_API Model { Model(const Model &) = delete; void operator=(const Model &) = delete; + /// \brief Build a model from model buffer so that it can run on a device. Only valid for Lite. + /// + /// \param[in] model_data Define the buffer read from a model file. + /// \param[in] data_size Define bytes number of model buffer. + /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only + /// ModelType::kMindIR is valid for Lite. + /// \param[in] model_context Define the context used to store options during execution. + /// + /// \return Status. + Status Build(const void *model_data, size_t data_size, ModelType model_type, + const std::shared_ptr &model_context = nullptr); + + /// \brief Load and build a model from model buffer so that it can run on a device. Only valid for Lite. + /// + /// \param[in] model_path Define the model path. + /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only + /// ModelType::kMindIR is valid for Lite. + /// \param[in] model_context Define the context used to store options during execution. + /// + /// \return Status. + Status Build(const std::string &model_path, ModelType model_type, + const std::shared_ptr &model_context = nullptr); + + /// \brief Build a model from model buffer so that it can run on a device. Only valid for Lite. + /// + /// \param[in] model_data Define the buffer read from a model file. + /// \param[in] data_size Define bytes number of model buffer. + /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only + /// ModelType::kMindIR is valid for Lite. + /// \param[in] model_context Define the context used to store options during execution. + /// \param[in] dec_key Define the key used to decrypt the ciphertext model. The key length is 16. + /// \param[in] dec_mode Define the decryption mode. Options: AES-GCM. + /// \param[in] cropto_lib_path Define the openssl library path. + /// + /// \return Status. + Status Build(const void *model_data, size_t data_size, ModelType model_type, + const std::shared_ptr &model_context, const Key &dec_key, const std::string &dec_mode, + const std::string &cropto_lib_path); + + /// \brief Load and build a model from model buffer so that it can run on a device. Only valid for Lite. + /// + /// \param[in] model_path Define the model path. + /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only + /// ModelType::kMindIR is valid for Lite. + /// \param[in] model_context Define the context used to store options during execution. + /// \param[in] dec_key Define the key used to decrypt the ciphertext model. The key length is 16. + /// \param[in] dec_mode Define the decryption mode. Options: AES-GCM. + /// \param[in] cropto_lib_path Define the openssl library path. + /// + /// \return Status. + Status Build(const std::string &model_path, ModelType model_type, const std::shared_ptr &model_context, + const Key &dec_key, const std::string &dec_mode, const std::string &cropto_lib_path); + /// \brief Builds a model /// /// \param[in] graph GraphCell is a derivative of Cell. Cell is not available currently. GraphCell can be constructed @@ -253,59 +306,6 @@ class MS_API Model { Status Train(int epochs, std::shared_ptr ds, std::vector cbs); Status Evaluate(std::shared_ptr ds, std::vector cbs); - /// \brief Build a model from model buffer so that it can run on a device. Only valid for Lite. - /// - /// \param[in] model_data Define the buffer read from a model file. - /// \param[in] data_size Define bytes number of model buffer. - /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only - /// ModelType::kMindIR is valid for Lite. - /// \param[in] model_context Define the context used to store options during execution. - /// - /// \return Status. - Status Build(const void *model_data, size_t data_size, ModelType model_type, - const std::shared_ptr &model_context = nullptr); - - /// \brief Load and build a model from model buffer so that it can run on a device. Only valid for Lite. - /// - /// \param[in] model_path Define the model path. - /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only - /// ModelType::kMindIR is valid for Lite. - /// \param[in] model_context Define the context used to store options during execution. - /// - /// \return Status. - Status Build(const std::string &model_path, ModelType model_type, - const std::shared_ptr &model_context = nullptr); - - /// \brief Build a model from model buffer so that it can run on a device. Only valid for Lite. - /// - /// \param[in] model_data Define the buffer read from a model file. - /// \param[in] data_size Define bytes number of model buffer. - /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only - /// ModelType::kMindIR is valid for Lite. - /// \param[in] model_context Define the context used to store options during execution. - /// \param[in] dec_key Define the key used to decrypt the ciphertext model. The key length is 16. - /// \param[in] dec_mode Define the decryption mode. Options: AES-GCM. - /// \param[in] cropto_lib_path Define the openssl library path. - /// - /// \return Status. - Status Build(const void *model_data, size_t data_size, ModelType model_type, - const std::shared_ptr &model_context, const Key &dec_key, const std::string &dec_mode, - const std::string &cropto_lib_path); - - /// \brief Load and build a model from model buffer so that it can run on a device. Only valid for Lite. - /// - /// \param[in] model_path Define the model path. - /// \param[in] model_type Define The type of model file. Options: ModelType::kMindIR, ModelType::kOM. Only - /// ModelType::kMindIR is valid for Lite. - /// \param[in] model_context Define the context used to store options during execution. - /// \param[in] dec_key Define the key used to decrypt the ciphertext model. The key length is 16. - /// \param[in] dec_mode Define the decryption mode. Options: AES-GCM. - /// \param[in] cropto_lib_path Define the openssl library path. - /// - /// \return Status. - Status Build(const std::string &model_path, ModelType model_type, const std::shared_ptr &model_context, - const Key &dec_key, const std::string &dec_mode, const std::string &cropto_lib_path); - private: friend class Serialization; // api without std::string diff --git a/include/api/ops/ops.h b/include/api/ops/ops.h deleted file mode 100644 index 02d88be0e48..00000000000 --- a/include/api/ops/ops.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2020-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_INCLUDE_API_OPS_OPS_H -#define MINDSPORE_INCLUDE_API_OPS_OPS_H - -#include -#include -#include -#include -#include "include/api/status.h" -#include "include/api/types.h" -#include "include/api/cell.h" - -namespace mindspore { -struct MS_API Conv2D : public OpCell { - Conv2D() : OpCell("Conv2D") {} - ~Conv2D() override = default; - std::vector Construct(const std::vector &inputs) override; - Conv2D(int out_channel, const std::vector &kernel_size, int mode = 1, const std::string &pad_mode = "valid", - const std::vector &pad = {0, 0, 0, 0}, const std::vector &stride = {1, 1, 1, 1}, - const std::vector &dilation = {1, 1, 1, 1}, int group = 1); - - Output operator()(const Input &, const Input &) const; - - int out_channel = 0; - std::vector kernel_size; - int mode = 1; - std::string pad_mode = "valid"; - std::vector pad = {0, 0, 0, 0}; - std::vector stride = {1, 1, 1, 1}; - std::vector dilation = {1, 1, 1, 1}; - int group = 1; -}; -} // namespace mindspore -#endif // MINDSPORE_INCLUDE_API_OPS_OPS_H diff --git a/mindspore/ccsrc/cxx_api/cell.cc b/mindspore/ccsrc/cxx_api/cell.cc index 5f15efdaf8f..f910122e851 100644 --- a/mindspore/ccsrc/cxx_api/cell.cc +++ b/mindspore/ccsrc/cxx_api/cell.cc @@ -21,52 +21,6 @@ namespace mindspore { std::vector CellBase::operator()(const std::vector &inputs) const { return Clone()->Construct(inputs); } -ParameterCell::ParameterCell(const ParameterCell &cell) : Cell(cell) { - auto tmp_ptr = cell.tensor_.Clone(); - tensor_ = *tmp_ptr; - MSTensor::DestroyTensorPtr(tmp_ptr); -} - -ParameterCell &ParameterCell::operator=(const ParameterCell &cell) { - if (&cell == this) { - return *this; - } - auto tmp_ptr = cell.tensor_.Clone(); - tensor_ = *tmp_ptr; - MSTensor::DestroyTensorPtr(tmp_ptr); - return *this; -} - -ParameterCell::ParameterCell(ParameterCell &&cell) : Cell(std::move(cell)), tensor_(cell.tensor_) {} - -ParameterCell &ParameterCell::operator=(ParameterCell &&cell) { - if (&cell == this) { - return *this; - } - tensor_ = cell.tensor_; - return *this; -} - -ParameterCell::ParameterCell(const MSTensor &tensor) { - auto tmp_ptr = tensor.Clone(); - tensor_ = *tmp_ptr; - MSTensor::DestroyTensorPtr(tmp_ptr); -} - -ParameterCell &ParameterCell::operator=(const MSTensor &tensor) { - auto tmp_ptr = tensor.Clone(); - tensor_ = *tmp_ptr; - MSTensor::DestroyTensorPtr(tmp_ptr); - return *this; -} - -ParameterCell::ParameterCell(MSTensor &&tensor) : tensor_(tensor) {} - -ParameterCell &ParameterCell::operator=(MSTensor &&tensor) { - tensor_ = tensor; - return *this; -} - GraphCell::GraphCell(const Graph &graph) : graph_(std::make_shared(graph)) { MS_EXCEPTION_IF_NULL(graph_); } GraphCell::GraphCell(const std::shared_ptr &graph) : graph_(graph) { MS_EXCEPTION_IF_NULL(graph_); } @@ -135,14 +89,6 @@ std::vector GraphCell::GetOutputs() { InputAndOutput::InputAndOutput() : cell_(nullptr), prev_(), index_(-1) {} -InputAndOutput::InputAndOutput(const MSTensor &tensor) : prev_(), index_(-1) { - auto tmp_ptr = tensor.Clone(); - cell_ = std::make_shared(*tmp_ptr); - MSTensor::DestroyTensorPtr(tmp_ptr); -} -InputAndOutput::InputAndOutput(MSTensor &&tensor) - : cell_(std::make_shared(tensor)), prev_(), index_(-1) {} - InputAndOutput::InputAndOutput(const std::shared_ptr &cell, const std::vector &prev, int32_t index) : cell_(cell), prev_(prev), index_(index) {} diff --git a/mindspore/ccsrc/cxx_api/ops/ops.cc b/mindspore/ccsrc/cxx_api/ops/ops.cc deleted file mode 100644 index 6fe3171af95..00000000000 --- a/mindspore/ccsrc/cxx_api/ops/ops.cc +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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 "include/api/ops/ops.h" - -namespace mindspore { -Conv2D::Conv2D(int out_channel, const std::vector &kernel_size, int mode, const std::string &pad_mode, - const std::vector &pad, const std::vector &stride, const std::vector &dilation, int group) - : OpCell("Conv2D"), - out_channel(out_channel), - kernel_size(kernel_size), - mode(mode), - pad_mode(pad_mode), - pad(pad), - stride(stride), - dilation(dilation), - group(group) {} - -Output Conv2D::operator()(const Input &input1, const Input &input2) const { - return CellBase::operator()({input1, input2})[0]; -} - -std::vector Conv2D::Construct(const std::vector &inputs) { - return {Output(shared_from_this(), inputs, 1)}; -} -} // namespace mindspore diff --git a/mindspore/lite/src/cxx_api/cell.cc b/mindspore/lite/src/cxx_api/cell.cc index 92a1a026642..d392a70e491 100644 --- a/mindspore/lite/src/cxx_api/cell.cc +++ b/mindspore/lite/src/cxx_api/cell.cc @@ -24,33 +24,6 @@ std::vector CellBase::operator()(const std::vector &inputs) const return empty; } -ParameterCell::ParameterCell(const ParameterCell &cell) { MS_LOG(ERROR) << "Unsupported feature."; } -ParameterCell &ParameterCell::operator=(const ParameterCell &cell) { - MS_LOG(ERROR) << "Unsupported feature."; - return *this; -} - -ParameterCell::ParameterCell(ParameterCell &&cell) { MS_LOG(ERROR) << "Unsupported feature."; } - -ParameterCell &ParameterCell::operator=(ParameterCell &&cell) { - MS_LOG(ERROR) << "Unsupported feature."; - return *this; -} - -ParameterCell::ParameterCell(const MSTensor &tensor) { MS_LOG(ERROR) << "Unsupported feature."; } - -ParameterCell &ParameterCell::operator=(const MSTensor &tensor) { - MS_LOG(ERROR) << "Unsupported feature."; - return *this; -} - -ParameterCell::ParameterCell(MSTensor &&tensor) : tensor_(tensor) { MS_LOG(ERROR) << "Unsupported feature."; } - -ParameterCell &ParameterCell::operator=(MSTensor &&tensor) { - MS_LOG(ERROR) << "Unsupported feature."; - return *this; -} - GraphCell::GraphCell(const Graph &graph) : graph_(std::shared_ptr(new (std::nothrow) Graph(graph))) { if (graph_ == nullptr) { MS_LOG(ERROR) << "Invalid graph."; @@ -81,9 +54,6 @@ Status GraphCell::Load(uint32_t device_id) { InputAndOutput::InputAndOutput() { MS_LOG(ERROR) << "Unsupported feature."; } -InputAndOutput::InputAndOutput(const MSTensor &tensor) { MS_LOG(ERROR) << "Unsupported feature."; } -InputAndOutput::InputAndOutput(MSTensor &&tensor) { MS_LOG(ERROR) << "Unsupported feature."; } - InputAndOutput::InputAndOutput(const std::shared_ptr &cell, const std::vector &prev, int32_t index) { MS_LOG(ERROR) << "Unsupported feature.";