diff options
Diffstat (limited to 'runtime/neurun/core/include/compiler/Compiler.h')
-rw-r--r-- | runtime/neurun/core/include/compiler/Compiler.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/runtime/neurun/core/include/compiler/Compiler.h b/runtime/neurun/core/include/compiler/Compiler.h new file mode 100644 index 000000000..797fc77ad --- /dev/null +++ b/runtime/neurun/core/include/compiler/Compiler.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file Compiler.h + * @brief This file contains Compiler class to define and run compilation phase + */ + +#ifndef __NEURUN_COMPILER_COMPILE_H_ +#define __NEURUN_COMPILER_COMPILE_H_ + +#include "ir/Graph.h" +#include "exec/IExecutor.h" + +namespace neurun +{ + +namespace compiler +{ + +enum class State +{ + CREATED, // Before compilation + STARTED, // Compile is started + LOWERED, // Backend is decided + COMPILED // Success compilation +}; + +/** + * @brief Class to compile graph model + */ +class Compiler +{ +public: + /** + * @brief Construct a new Compiler object + * @param[in] model Graph model + */ + Compiler(const std::shared_ptr<ir::Graph> &graph) + : _graph{graph}, _executor{nullptr}, _state{State::CREATED} + { + // DO NOTHING + } + +public: + /** + * @brief Run compilation. Compilation result will be saved in _plan + */ + void compile(void); + /** + * @brief Pass plan reference + * @param[out] plan Plan reference to return\n + * Set nullptr if compile is not run yet + */ + void release(std::shared_ptr<exec::IExecutor> &executor) { executor = _executor; } + + void state(State state) { _state = state; } + State state(void) const { return _state; } + + /** + * @brief Check if model can compile + * @return @c true if model can compile, otherwise @c false + * @note This method don't check model correctness,\n + * so model verification should be done before calling this method + */ + bool checkCompilable(); + +private: + std::shared_ptr<ir::Graph> _graph; + std::shared_ptr<exec::IExecutor> _executor; + State _state; +}; + +} // namespace compiler + +} // namespace neurun + +#endif // __NEURUN_COMPILER_COMPILE_H_ |