2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief This file contains Compiler class to define and run compilation phase
22 #ifndef __ONERT_COMPILER_COMPILE_H_
23 #define __ONERT_COMPILER_COMPILE_H_
26 #include "exec/IExecutor.h"
27 #include "util/TracingCtx.h"
37 CREATED, // Before compilation
38 COMPILED // Success compilation
41 struct ManualSchedulerOptions
43 std::string backend_for_all;
44 std::unordered_map<ir::OpCode, std::string> opcode_to_backend;
45 std::unordered_map<ir::OperationIndex, std::string> index_to_backend;
48 struct CompilerOptions
51 std::vector<std::string> backend_list;
53 // OPTIONS ONLY FOR DEBUGGING/PROFILING
54 std::string trace_filepath; //< File path to save trace records
55 int graph_dump_level; //< Graph dump level, values between 0 and 2 are valid
56 int op_seq_max_node; //< Number of nodes that can be
57 std::string executor; //< Executor name to use
58 ManualSchedulerOptions manual_scheduler_options; //< Options for ManualScheduler
59 bool he_scheduler; //< HEScheduler if true, ManualScheduler otherwise
60 bool he_profiling_mode; //< Whether HEScheduler profiling mode ON/OFF
61 bool disable_compile; //< Run with Interpreter if true, try compilation otherwise
62 bool fp16_enable; //< Whether fp16 mode ON/OFF
64 util::TracingCtx *tracing_ctx; //< Profiling information
67 CompilerOptions fetchCompilerOptionsFromGlobalConfig(const ir::Subgraphs &subgs);
70 * @brief Class to compile graph model
76 * @brief Construct a new Compiler object
77 * @param[in] subgs All subgraphs of a model
78 * @param[in] tracing_ctx Profiling information
80 Compiler(const std::shared_ptr<ir::Subgraphs> &subgs, util::TracingCtx *tracing_ctx);
84 * @brief Do compilation with the options
86 * @return std::shared_ptr<exec::ExecutorMap> Executors as a result of compilation
88 std::shared_ptr<exec::ExecutorMap> compile(void);
90 State state(void) const { return _state; }
93 * @brief Check if model can compile
94 * @return @c true if model can compile, otherwise @c false
95 * @note This method don't check model correctness,\n
96 * so model verification should be done before calling this method
98 bool checkCompilable();
99 CompilerOptions &options() { return _options; }
102 * @brief Allow to compute float32 using float16 data type
107 void checkProfilerConditions();
108 std::shared_ptr<ir::Graph> &primary_subgraph() { return _subgraphs->at(ir::SubgraphIndex{0}); }
111 std::shared_ptr<ir::Subgraphs> _subgraphs;
112 // NOTE These executors does not have duplicated subgraph. This mean they do not allow support
113 // subgraphs being called recursively because data of non-constant tensor of parent executor will
114 // be updated by child executor. If you want to support subgraphs being called recursively, you
115 // have to add allocate non-constant tensor memory of executors in execution time when each
116 // subgraph is called.
118 CompilerOptions _options;
121 } // namespace compiler
125 #endif // __ONERT_COMPILER_COMPILE_H_