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"
36 CREATED, // Before compilation
37 COMPILED // Success compilation
40 struct ManualSchedulerOptions
42 std::string backend_for_all;
43 std::unordered_map<ir::OpCode, std::string> opcode_to_backend;
44 std::unordered_map<ir::OperationIndex, std::string> index_to_backend;
47 struct CompilerOptions
50 std::vector<std::string> backend_list;
51 bool is_primary_subgraph; // TODO Remove this out of this struct as it is not user-given option
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
65 CompilerOptions fetchCompilerOptionsFromGlobalConfig(const ir::Subgraphs &subgs);
68 * @brief Class to compile graph model
74 * @brief Construct a new Compiler object
75 * @param[in] subgs All subgraphs of a model
77 Compiler(const std::shared_ptr<ir::Subgraphs> &subgs);
81 * @brief Do compilation with the options
83 * @return std::shared_ptr<exec::ExecutorMap> Executors as a result of compilation
85 std::shared_ptr<exec::ExecutorMap> compile(void);
87 State state(void) const { return _state; }
90 * @brief Check if model can compile
91 * @return @c true if model can compile, otherwise @c false
92 * @note This method don't check model correctness,\n
93 * so model verification should be done before calling this method
95 bool checkCompilable();
96 CompilerOptions &options() { return _options; }
99 * @brief Allow to compute float32 using float16 data type
104 void checkProfilerConditions();
105 std::shared_ptr<ir::Graph> &primary_subgraph() { return _subgraphs->at(ir::SubgraphIndex{0}); }
108 std::shared_ptr<ir::Subgraphs> _subgraphs;
109 // NOTE These executors does not have duplicated subgraph. This mean they do not allow support
110 // subgraphs being called recursively because data of non-constant tensor of parent executor will
111 // be updated by child executor. If you want to support subgraphs being called recursively, you
112 // have to add allocate non-constant tensor memory of executors in execution time when each
113 // subgraph is called.
115 CompilerOptions _options;
118 } // namespace compiler
122 #endif // __ONERT_COMPILER_COMPILE_H_