Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / acl_neon / 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_ACL_NEON_BACKEND_H__
18 #define __ONERT_BACKEND_ACL_NEON_BACKEND_H__
19
20 #include <memory>
21 #include <backend/Backend.h>
22 #include <ir/Operands.h>
23
24 #include "BackendContext.h"
25 #include "Config.h"
26 #include "ConstantInitializer.h"
27 #include "KernelGenerator.h"
28 #include "TensorManager.h"
29 #include "Optimizer.h"
30
31 namespace onert
32 {
33 namespace backend
34 {
35 namespace acl_neon
36 {
37
38 class Backend : public ::onert::backend::Backend
39 {
40 public:
41   Backend() : _config{std::make_shared<Config>()} {}
42
43   std::shared_ptr<IConfig> config() const override { return _config; }
44
45   std::unique_ptr<backend::BackendContext>
46   newContext(const ir::Graph &graph, const std::shared_ptr<custom::IKernelBuilder> &,
47              bool is_linear_executor) const override
48   {
49     const auto &operands = graph.operands();
50     const auto &operations = graph.operations();
51     auto context = std::make_unique<acl_neon::BackendContext>(this, &graph);
52     auto tm = createTensorManager(is_linear_executor);
53     auto tr = std::make_shared<acl_common::AclTensorRegistry<TensorManager>>(tm);
54     auto tb = std::make_shared<TensorBuilder>(operands, tm);
55     context->tensor_registry = tr;
56     context->tensor_builder = tb;
57     context->constant_initializer = std::make_shared<ConstantInitializer>(operands, tr);
58     context->kernel_gen = std::make_shared<KernelGenerator>(operands, operations, tb, tr);
59     context->optimizer = std::make_shared<Optimizer>(context.get());
60     return context;
61   }
62
63 private:
64   std::shared_ptr<IConfig> _config;
65 };
66
67 } // namespace acl_neon
68 } // namespace backend
69 } // namespace onert
70
71 #endif // __ONERT_BACKEND_ACL_NEON_BACKEND_H__