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_BACKEND_CONTEXT_H__
18#define __ONERT_BACKEND_BACKEND_CONTEXT_H__
19
20#include <memory>
21#include "ir/Graph.h"
23#include "ir/OperandIndexMap.h"
25#include "util/Set.h"
26
27namespace onert::backend
28{
29
30class Backend;
31struct ITensorRegistry;
32
33using FunctionMap = std::unordered_map<ir::OperationIndex, std::unique_ptr<exec::FunctionSequence>>;
34
36{
37 /* A partial graph that only includes used operand/operations of the original graph */
38 std::unique_ptr<ir::Graph> graph;
39 /* A linear order of operations. This is neccessary for when a graph is not fully connected */
40 std::vector<onert::ir::OperationIndex> op_order;
41 /* Operands that are defined by other backends */
43 /* Custom kernel builder */
44 std::shared_ptr<custom::IKernelBuilder> custom_kernel_builder;
45 /* Is linear executor or not */
47};
48
50{
51public:
53 std::shared_ptr<ITensorRegistry> tensor_registry = nullptr)
55 {
56 }
57
58 virtual ~BackendContext() = default;
59
60 const Backend *backend() const { return _backend; }
61 const ir::Graph *graph() const { return _data.graph.get(); }
63 const ContextData &data() const { return _data; }
64
66 virtual FunctionMap genKernels() = 0;
67
68protected:
69 const Backend *_backend{nullptr};
71
72public:
73 std::shared_ptr<ITensorRegistry> tensor_registry;
74};
75
76using BackendContexts = std::unordered_map<const Backend *, std::unique_ptr<BackendContext>>;
77
78} // namespace onert::backend
79
80#endif // __ONERT_BACKEND_BACKEND_CONTEXT_H__
This file contains onert::util::Set class.
BackendContext(const Backend *backend, ContextData &&data, std::shared_ptr< ITensorRegistry > tensor_registry=nullptr)
std::shared_ptr< ITensorRegistry > tensor_registry
virtual ~BackendContext()=default
virtual FunctionMap genKernels()=0
const ContextData & data() const
const ir::Graph * graph() const
virtual ITensorRegistry * genTensors()=0
const Backend * backend() const
const util::Set< ir::OperandIndex > & external_operands() const
Class for set of custom element &.
Definition Set.h:37
std::unordered_map< ir::OperationIndex, std::unique_ptr< exec::FunctionSequence > > FunctionMap
std::unordered_map< const Backend *, std::unique_ptr< BackendContext > > BackendContexts
std::vector< onert::ir::OperationIndex > op_order
std::unique_ptr< ir::Graph > graph
util::Set< ir::OperandIndex > external_operands
std::shared_ptr< custom::IKernelBuilder > custom_kernel_builder