ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
28{
29namespace backend
30{
31
32class Backend;
33struct ITensorRegistry;
34
35using FunctionMap = std::unordered_map<ir::OperationIndex, std::unique_ptr<exec::FunctionSequence>>;
36
38{
39 /* A partial graph that only includes used operand/operations of the original graph */
40 std::unique_ptr<ir::Graph> graph;
41 /* A linear order of operations. This is neccessary for when a graph is not fully connected */
42 std::vector<onert::ir::OperationIndex> op_order;
43 /* Operands that are defined by other backends */
45 /* Custom kernel builder */
46 std::shared_ptr<custom::IKernelBuilder> custom_kernel_builder;
47 /* Is linear executor or not */
49};
50
52{
53public:
55 std::shared_ptr<ITensorRegistry> tensor_registry = nullptr)
57 {
58 }
59
60 virtual ~BackendContext() = default;
61
62 const Backend *backend() const { return _backend; }
63 const ir::Graph *graph() const { return _data.graph.get(); }
65 const ContextData &data() const { return _data; }
66
68 virtual FunctionMap genKernels() = 0;
69
70protected:
71 const Backend *_backend{nullptr};
73
74public:
75 std::shared_ptr<ITensorRegistry> tensor_registry;
76};
77
78using BackendContexts = std::unordered_map<const Backend *, std::unique_ptr<BackendContext>>;
79
80} // namespace backend
81} // namespace onert
82
83#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:39
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