You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

optimizer.h 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_LITE_TOOLS_CONVERTER_OPTIMIZER_H
  17. #define MINDSPORE_LITE_TOOLS_CONVERTER_OPTIMIZER_H
  18. #include <vector>
  19. #include "schema/inner/model_generated.h"
  20. #include "include/errorcode.h"
  21. namespace mindspore {
  22. namespace lite {
  23. using namespace schema;
  24. template <typename T>
  25. class Pass {
  26. public:
  27. Pass() = default;
  28. virtual ~Pass() = default;
  29. virtual STATUS Run(T *t) = 0;
  30. };
  31. class GraphPass : public Pass<schema::MetaGraphT> {
  32. public:
  33. GraphPass() = default;
  34. ~GraphPass() override = default;
  35. STATUS Run(schema::MetaGraphT *graph) override = 0;
  36. };
  37. struct GraphNode {
  38. GraphNode(schema::MetaGraphT *subGraph, schema::CNodeT *opDefT) : subGraph(subGraph), opDef(opDefT) {}
  39. ~GraphNode() = default;
  40. schema::MetaGraphT *subGraph = nullptr;
  41. schema::CNodeT *opDef = nullptr;
  42. };
  43. class NodePass : public Pass<GraphNode> {
  44. public:
  45. NodePass() = default;
  46. ~NodePass() override = default;
  47. STATUS Run(GraphNode *graphNode) override = 0;
  48. // protected:
  49. // GraphNode *graphNode = nullptr;
  50. };
  51. class Optimizer {
  52. public:
  53. Optimizer() = default;
  54. virtual ~Optimizer();
  55. void AddPass(GraphPass *graphPass);
  56. void AddPass(NodePass *nodePass);
  57. STATUS Run(schema::MetaGraphT *graphDefT);
  58. private:
  59. std::vector<GraphPass *> graphPasses;
  60. std::vector<NodePass *> nodePasses;
  61. };
  62. } // namespace lite
  63. } // namespace mindspore
  64. #endif