2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_BACKEND_CONTROLFLOW_USER_TENSOR_H__
18 #define __ONERT_BACKEND_CONTROLFLOW_USER_TENSOR_H__
20 #include "ir/OperandInfo.h"
21 #include "backend/IPortableTensor.h"
31 * @brief Tensor object that is for Input and Output tensors from the user.
33 * This class is a wrapped buffer that is allocated by the user. So it does not have resposibility
34 * on allocation nor deallocation. All the model input/output tensors are wrapped with this class
38 class UserTensor : public IPortableTensor
41 UserTensor(const ir::OperandInfo &info, ir::Layout layout, uint8_t *buffer, size_t size)
42 : _info{info}, _layout{layout}, _buffer{buffer}, _size{size}, _dynamic{false}
46 UserTensor(const ir::OperandInfo &info, ir::Layout layout) : UserTensor{info, layout, nullptr, 0}
51 void setBuffer(uint8_t *buffer, size_t size)
58 uint8_t *buffer() const override { return _buffer; }
59 size_t total_size() const override { return _size; }
60 size_t dimension(size_t index) const override { return _info.shape().dim(index); }
61 size_t num_dimensions() const override { return _info.shape().rank(); }
62 size_t calcOffset(const ir::Coordinates &coords) const override;
63 ir::Layout layout() const override { return _layout; }
64 ir::DataType data_type() const override { return _info.typeInfo().type(); }
65 float data_scale() const override { return _info.typeInfo().scale(); }
66 int32_t data_offset() const override { return _info.typeInfo().offset(); }
67 bool is_dynamic() const override { return _dynamic; }
68 void set_dynamic() override { _dynamic = true; }
69 ir::Shape getShape() const override { return _info.shape(); }
70 void setShape(const ir::Shape &new_shape) override { _info.shape(new_shape); }
73 ir::OperandInfo _info;
80 } // namespace controlflow
81 } // namespace backend
84 #endif // __ONERT_BACKEND_CONTROLFLOW_USER_TENSOR_H__