ONE - On-device Neural Engine
Loading...
Searching...
No Matches
TensorRegistry.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_TENSOR_REGISTRY_H__
18#define __ONERT_BACKEND_BUILTIN_TENSOR_REGISTRY_H__
19
22#include "Tensor.h"
23#include "IOTensor.h"
24#include <assert.h>
25
27{
28
44{
45public:
46 TensorRegistry() : _base_reg{new basic::TensorRegistry} {}
47
48 ITensor *getITensor(const ir::OperandIndex &ind) override
49 {
50 auto base_tensor = _base_reg->getITensor(ind);
51 if (base_tensor)
52 return base_tensor;
53 return getNativeIOTensor(ind);
54 }
55
57 {
58 auto base_tensor = _base_reg->getNativeITensor(ind);
59 if (base_tensor)
60 return base_tensor;
61 return getNativeIOTensor(ind);
62 }
63
65 {
66 auto base_tensor = _base_reg->getPortableTensor(ind);
67 if (base_tensor)
68 return base_tensor;
69 return getNativeIOTensor(ind);
70 }
71
73 {
74 auto base_tensor = _base_reg->getNativeTensor(ind);
75 if (base_tensor)
76 return base_tensor;
77 return getNativeIOTensor(ind);
78 }
79
81 {
82 return _base_reg->getNativeTensor(ind);
83 }
84
86 {
87 auto tensor = _native_io_tensors.find(ind);
88 if (tensor != _native_io_tensors.end())
89 return tensor->second.get();
90 return nullptr;
91 }
92
93 bool setMigrantTensor(const ir::OperandIndex &ind, IPortableTensor *tensor) override
94 {
95 assert(tensor);
96 assert(!getITensor(ind)); // For the ind, tensor is not registered yet
97 _base_reg->setMigrantTensor(ind, tensor);
98 return true;
99 }
100
101 void setNativeOwnTensor(ir::OperandIndex ind, std::unique_ptr<Tensor> &&tensor)
102 {
103 assert(tensor);
104 assert(!getITensor(ind)); // For the ind, tensor is not registered yet
105 _base_reg->setNativeTensor(ind, std::move(tensor));
106 }
107
108 void setNativeIOTensor(ir::OperandIndex ind, std::unique_ptr<IOTensor> &&tensor)
109 {
110 assert(tensor);
111 assert(!getITensor(ind)); // For the ind, tensor is not registered yet
112 _native_io_tensors[ind] = std::move(tensor);
113 }
114
116 {
117 return _native_io_tensors;
118 }
119 std::shared_ptr<basic::TensorRegistry> base_reg() { return _base_reg; }
120
121private:
122 std::shared_ptr<basic::TensorRegistry> _base_reg;
124};
125
126} // namespace onert::backend::builtin
127
128#endif // ifndef __ONERT_BACKEND_BUILTIN_TENSOR_REGISTRY_H__
A tensor class that is portable for other backends.
Tensor object that indirects to the tensor it is pointing to.
Definition IOTensor.h:46
Tensor registry class for builtin backend.
IOTensor * getNativeIOTensor(const ir::OperandIndex &ind)
void setNativeIOTensor(ir::OperandIndex ind, std::unique_ptr< IOTensor > &&tensor)
bool setMigrantTensor(const ir::OperandIndex &ind, IPortableTensor *tensor) override
Set the Migrant Tensor which are from other backends.
ITensor * getNativeITensor(const ir::OperandIndex &ind) override
Returns pointer of ITensor among native tensors.
Tensor * getNativeOwnTensor(const ir::OperandIndex &ind)
std::shared_ptr< basic::TensorRegistry > base_reg()
ITensor * getITensor(const ir::OperandIndex &ind) override
Returns pointer of ITensor among native and migrant tensors.
IPortableTensor * getNativeTensor(const ir::OperandIndex &ind)
void setNativeOwnTensor(ir::OperandIndex ind, std::unique_ptr< Tensor > &&tensor)
IPortableTensor * getPortableTensor(const ir::OperandIndex &ind)
const ir::OperandIndexMap< std::unique_ptr< IOTensor > > & native_io_tensors()
std::unordered_map< OperandIndex, T > OperandIndexMap