fc8574b26d950b127fd1f87b492cfdb41fb4de72
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / Backend.h
1 /*
2  * Copyright (c) 2019 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 #ifndef __ONERT_BACKEND_CPU_BACKEND_H__
18 #define __ONERT_BACKEND_CPU_BACKEND_H__
19
20 #include "BackendContext.h"
21 #include "Config.h"
22 #include "ConstantInitializer.h"
23 #include "KernelGenerator.h"
24
25 #include <backend/Backend.h>
26
27 #include <memory>
28
29 namespace onert
30 {
31 namespace backend
32 {
33 namespace cpu
34 {
35
36 class Backend : public ::onert::backend::Backend
37 {
38 public:
39   Backend() : _config{std::make_shared<Config>()} {}
40
41   std::shared_ptr<IConfig> config() const override { return _config; }
42
43   std::unique_ptr<onert::backend::BackendContext>
44   newContext(const ir::Graph &graph, const std::shared_ptr<custom::IKernelBuilder> &kb,
45              bool) const override
46   {
47     const auto &operands = graph.operands();
48     const auto &operations = graph.operations();
49     auto context = std::make_unique<BackendContext>(this, &graph);
50     auto tr = std::make_shared<cpu_common::TensorRegistry>();
51     auto tb = std::make_shared<TensorBuilder>(tr);
52     context->tensor_registry = tr;
53     context->tensor_builder = tb;
54     context->constant_initializer = std::make_shared<ConstantInitializer>(operands, tr);
55     context->kernel_gen = std::make_shared<KernelGenerator>(operands, operations, tb, tr, kb,
56                                                             context->external_context());
57     context->tensor_register = nullptr;
58     context->optimizer = nullptr;
59     return context;
60   }
61
62 private:
63   std::shared_ptr<IConfig> _config;
64 };
65
66 } // namespace cpu
67 } // namespace backend
68 } // namespace onert
69
70 #endif // __ONERT_BACKEND_CPU_BACKEND_H__