20 #include <unordered_map> 23 #include "poros_module.h" 24 #include "torch/script.h" 39 std::unique_ptr<PorosModule>
40 Compile(
const torch::jit::Module& module,
41 const std::vector<std::vector<c10::IValue>>& prewarm_datas,
42 const PorosOptions& options);
46 typedef std::unordered_map<const torch::jit::Node*, IEngine*> engine_map_t;
47 typedef std::vector<std::vector<c10::IValue>> ivalue_vec_t;
49 Compiler() : _origin_module(NULL) {}
59 int init(
const PorosOptions& options);
70 int compile(
const torch::jit::Module& origin_module,
71 const ivalue_vec_t& prewarm_datas,
72 torch::jit::Module* optimized_module);
83 int preprocess_graph(
const ivalue_vec_t& prewarm_datas,
84 std::shared_ptr<torch::jit::Graph>& graph);
93 int segment_graph(std::shared_ptr<torch::jit::Graph>& graph);
97 int segment_block(torch::jit::Block& block, IEngine* engine,
110 int optimize_subgraph(
const ivalue_vec_t& prewarm_datas,
111 const std::shared_ptr<torch::jit::Graph>& opt_graph,
112 torch::jit::Module* optimized_module);
115 int optimize_subblock(torch::jit::Block* block,
116 torch::jit::Module* optimized_module);
126 int transform(IEngine* engine, torch::jit::Node& subgraph_node,
127 torch::jit::Module& module);
136 IEngine* select_engine(
const torch::jit::Node* n);
146 int _max_segment_depth{5};
147 ivalue_vec_t _prewarm_datas;
148 PorosOptions _options;
149 engine_map_t _engine_map;
150 const torch::jit::Module* _origin_module;
151 std::atomic<int> _engine_index = {0};
163 std::unique_ptr<torch::jit::Module>
164 CompileGraph(
const torch::jit::Module& module,
165 const std::vector<std::vector<c10::IValue>>& prewarm_datas,
166 const PorosOptions& options);