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.

graph.h 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Copyright 2021 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_MICRO_CODER_GRAPH_H_
  17. #define MINDSPORE_LITE_MICRO_CODER_GRAPH_H_
  18. #include <map>
  19. #include <memory>
  20. #include <unordered_map>
  21. #include <vector>
  22. #include <string>
  23. #include "coder/config.h"
  24. #include "include/context.h"
  25. #include "include/model.h"
  26. #include "schema/inner/model_generated.h"
  27. #include "src/common/graph_util.h"
  28. #include "src/tensor.h"
  29. namespace mindspore::lite::micro {
  30. class CoderGraph {
  31. public:
  32. explicit CoderGraph(Model *model) : model_(model) {}
  33. ~CoderGraph();
  34. int ConvertTensors();
  35. int InitGraphInOutTensors();
  36. void SetAllTensors(const std::vector<Tensor *> &all_tensors);
  37. void InitInputs();
  38. void InitOutputs();
  39. void SetInputIndices(const std::vector<uint32_t> &input_indices);
  40. void SetOutputIndices(const std::vector<uint32_t> &output_indices);
  41. void AddInputMap(const std::string &node_id, Tensor *input_tensor);
  42. void AddOutputMap(const std::string &node_id, Tensor *output_tensor);
  43. std::vector<uint32_t> input_indices() const;
  44. std::vector<uint32_t> output_indices() const;
  45. std::vector<Tensor *> input_tensors() const;
  46. std::vector<Tensor *> output_tensors() const;
  47. std::vector<Tensor *> all_tensors() const;
  48. const std::map<NODE_ID, std::vector<Tensor *>> &GetOutputsMap() const;
  49. const Model *model() const { return this->model_; }
  50. void DumpUnSupportLayer(Target target);
  51. private:
  52. // graph_inputs && weight && bias is value_node
  53. // others are parameter_node
  54. std::vector<Tensor *> all_tensors_;
  55. std::vector<Tensor *> input_tensors_;
  56. std::vector<Tensor *> output_tensors_;
  57. std::vector<uint32_t> input_indices_;
  58. std::vector<uint32_t> output_indices_;
  59. std::map<std::string, std::vector<Tensor *>> inputs_map_;
  60. std::map<std::string, std::vector<Tensor *>> outputs_map_;
  61. Model *model_{nullptr};
  62. };
  63. } // namespace mindspore::lite::micro
  64. #endif // MINDSPORE_LITE_MICRO_CODER_GRAPH_H_