ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BackendContext.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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_BUILTIN_BACKEND_CONTEXT_H__
18#define __ONERT_BACKEND_BUILTIN_BACKEND_CONTEXT_H__
19
20#include "ExternalContext.h"
21#include "KernelGenerator.h"
22#include "TensorBuilder.h"
25
27{
28
30{
31public:
33 std::shared_ptr<ITensorRegistry> tensor_registry = nullptr,
34 std::shared_ptr<TensorBuilder> tensor_builder = nullptr,
35 std::shared_ptr<KernelGenerator> kernel_gen = nullptr)
38 _external_context(std::make_shared<ExternalContext>())
39 {
40 }
41
42 ITensorRegistry *genTensors() override;
43
44 FunctionMap genKernels() override;
45
46 std::shared_ptr<ExternalContext> external_context() { return _external_context; }
47
48private:
49 void planTensors(const std::vector<onert::ir::OperationIndex> &order,
50 const compiler::GraphLowerInfo &lower_info);
51
52public:
53 // TODO Make it private
54 std::shared_ptr<TensorBuilder> tensor_builder;
55 std::shared_ptr<KernelGenerator> kernel_gen;
56
57private:
58 // NOTE ruy context has a thread pool, and when multiple ruy contexts are created,
59 // the thread pool is also created in duplicate
60 // TODO Create one ruy context for session
61 std::shared_ptr<ExternalContext> _external_context;
62};
63
64} // namespace onert::backend::builtin
65
66#endif // __ONERT_BACKEND_BUILTIN_BACKEND_CONTEXT_H__
std::shared_ptr< ITensorRegistry > tensor_registry
const ContextData & data() const
const Backend * backend() const
std::shared_ptr< KernelGenerator > kernel_gen
std::shared_ptr< TensorBuilder > tensor_builder
ITensorRegistry * genTensors() override
BackendContext(const Backend *backend, ContextData &&data, std::shared_ptr< ITensorRegistry > tensor_registry=nullptr, std::shared_ptr< TensorBuilder > tensor_builder=nullptr, std::shared_ptr< KernelGenerator > kernel_gen=nullptr)
std::shared_ptr< ExternalContext > external_context()
std::unordered_map< ir::OperationIndex, std::unique_ptr< exec::FunctionSequence > > FunctionMap