Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / compiler / CompilerFactory.cc
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
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
17 #include "compiler/CompilerFactory.h"
18
19 #include "MultiModelCompiler.h"
20 #ifdef ONERT_TRAIN
21 #include "train/TrainingCompiler.h"
22 #endif // ONERT_TRAIN
23
24 #include "compiler/Compiler.h"
25
26 namespace onert
27 {
28 namespace compiler
29 {
30
31 CompilerFactory &CompilerFactory::get()
32 {
33   static CompilerFactory singleton;
34   return singleton;
35 }
36
37 std::unique_ptr<ICompiler>
38 CompilerFactory::create(const std::shared_ptr<ir::NNPkg> &nnpkg,
39                         std::vector<std::unique_ptr<CompilerOptions>> &copts,
40                         const compiler::train::TrainingInfo *training_info)
41 {
42 #ifdef ONERT_TRAIN
43   // Returing compiler for training
44   if (training_info)
45     return std::make_unique<train::TrainingCompiler>(nnpkg, copts, *training_info);
46 #else  // ONERT_TRAIN
47   (void)training_info;
48 #endif // ONERT_TRAIN
49
50   // Returing compiler for inference
51   if (nnpkg->model_count() == 1)
52     return std::make_unique<Compiler>(nnpkg, copts);
53
54   return std::make_unique<MultiModelCompiler>(nnpkg, copts);
55 }
56
57 } // namespace compiler
58 } // namespace onert