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.

context.h 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_CODER_CONTEXT_H_
  17. #define MINDSPORE_LITE_MICRO_CODER_CODER_CONTEXT_H_
  18. #include <map>
  19. #include <memory>
  20. #include <set>
  21. #include <stack>
  22. #include <string>
  23. #include <utility>
  24. #include <vector>
  25. #include "src/tensor.h"
  26. namespace mindspore::lite::micro {
  27. class CoderContext {
  28. public:
  29. CoderContext();
  30. ~CoderContext() = default;
  31. std::vector<std::string> init_contents() const { return initialContent_; }
  32. void set_code_blocks(const std::vector<std::string> &code_block) { code_blocks_ = code_block; }
  33. std::vector<std::string> code_blocks() const { return code_blocks_; }
  34. void set_inference_blocks(const std::vector<std::string> &inference_blocks) { inference_blocks_ = inference_blocks; }
  35. std::vector<std::string> inference_blocks() const { return inference_blocks_; }
  36. void set_train_blocks(const std::vector<std::string> &train_blocks) { train_blocks_ = train_blocks; }
  37. std::vector<std::string> train_blocks() const { return train_blocks_; }
  38. void set_tensor_map(const std::map<Tensor *, std::string> &tensor_map) {
  39. tensors_map_.insert(tensor_map.begin(), tensor_map.end());
  40. }
  41. std::map<Tensor *, std::string> tensors_map() const { return tensors_map_; }
  42. void set_saved_weights(const std::map<std::string, Tensor *> &saved_weights) { saved_weights_ = saved_weights; }
  43. std::map<std::string, Tensor *> saved_weights() const { return saved_weights_; }
  44. void set_total_buffer_size(size_t size) { total_buffer_size_ = size; }
  45. size_t total_buffer_size() const { return total_buffer_size_; }
  46. void set_graph_inputs(const std::vector<Tensor *> &graph_inputs) { graph_inputs_ = graph_inputs; }
  47. void set_graph_outputs(const std::vector<Tensor *> &graph_outputs) { graph_outputs_ = graph_outputs; }
  48. std::vector<Tensor *> graph_inputs() const { return graph_inputs_; }
  49. std::vector<Tensor *> graph_outputs() const { return graph_outputs_; }
  50. std::string input_name() { return input_name_; }
  51. std::string output_name() { return output_name_; }
  52. std::string buffer_name() { return buffer_name_; }
  53. std::string weight_name() { return weight_name_; }
  54. void AppendCode(const std::string &codeBlock);
  55. void AppendInitCode(const std::string &codeBlock);
  56. std::set<std::string> c_files() const { return c_files_; }
  57. void set_c_files(const std::set<std::string> &files) { c_files_.insert(files.begin(), files.end()); }
  58. std::set<std::string> h_files() const { return h_files_; }
  59. void set_h_files(const std::set<std::string> &files) { h_files_.insert(files.begin(), files.end()); }
  60. std::set<std::string> asm_files() const { return asm_files_; }
  61. void set_asm_files(const std::set<std::string> &files) { asm_files_.insert(files.begin(), files.end()); }
  62. private:
  63. std::vector<Tensor *> graph_inputs_;
  64. std::vector<Tensor *> graph_outputs_;
  65. // primitive const tensors, parsed from model, without packed.
  66. std::map<std::string, Tensor *> saved_weights_;
  67. // all tensors, include parsed from model and packed tensors.
  68. std::map<Tensor *, std::string> tensors_map_;
  69. // workspace's size.
  70. size_t total_buffer_size_{0};
  71. // model's input tensor data's address.
  72. std::string input_name_;
  73. // model's output tensor's address
  74. std::string output_name_;
  75. // the address of workspace, use for inference or train.
  76. std::string buffer_name_;
  77. // model's weight tensors' address.
  78. std::string weight_name_;
  79. // code blocks store the tensor will be packed runtime
  80. std::vector<std::string> initialContent_;
  81. // operator C Lang files list, depended by the net.c. it will be add to CMakeLists.txt
  82. std::set<std::string> c_files_;
  83. // when codegen generate the code for ARM64 OR ARM32, we provide server optimized artimetic used the assembly
  84. // instructions. asm_files store the assembly file names
  85. std::set<std::string> asm_files_;
  86. // operator header files
  87. std::set<std::string> h_files_;
  88. // net.c's content, include the Inference and Training implementation
  89. std::vector<std::string> code_blocks_;
  90. std::vector<std::string> train_blocks_;
  91. std::vector<std::string> inference_blocks_;
  92. };
  93. } // namespace mindspore::lite::micro
  94. #endif // MINDSPORE_LITE_MICRO_CODER_CONTEXT_H_