blob: 5fa155efc80a496922f1171642539932deeee8d5 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitasd8734b52017-12-22 15:27:52 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_TENSOR_DESCRIPTOR_H
25#define ARM_COMPUTE_GRAPH_TENSOR_DESCRIPTOR_H
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/Types.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000028
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010029#include "support/ICloneable.h"
Georgios Pinitascac13b12018-04-27 19:07:19 +010030
31#include <memory>
32
Georgios Pinitasd8734b52017-12-22 15:27:52 +000033namespace arm_compute
34{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010035namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000036{
37/** Tensor metadata class */
Georgios Pinitascac13b12018-04-27 19:07:19 +010038struct TensorDescriptor final : public misc::ICloneable<TensorDescriptor>
Georgios Pinitasd8734b52017-12-22 15:27:52 +000039{
40 /** Default Constructor **/
41 TensorDescriptor() = default;
42 /** Constructor
43 *
Georgios Pinitascac13b12018-04-27 19:07:19 +010044 * @param[in] tensor_shape Tensor shape
45 * @param[in] tensor_data_type Tensor data type
46 * @param[in] tensor_quant_info Tensor quantization info
47 * @param[in] tensor_data_layout Tensor data layout
48 * @param[in] tensor_target Target to allocate the tensor for
Georgios Pinitasd8734b52017-12-22 15:27:52 +000049 */
Georgios Pinitascac13b12018-04-27 19:07:19 +010050 TensorDescriptor(TensorShape tensor_shape,
51 DataType tensor_data_type,
52 QuantizationInfo tensor_quant_info = QuantizationInfo(),
53 DataLayout tensor_data_layout = DataLayout::NCHW,
54 Target tensor_target = Target::UNSPECIFIED)
55 : shape(tensor_shape), data_type(tensor_data_type), layout(tensor_data_layout), quant_info(tensor_quant_info), target(tensor_target)
Georgios Pinitasd8734b52017-12-22 15:27:52 +000056 {
57 }
Georgios Pinitascac13b12018-04-27 19:07:19 +010058 /** Sets tensor descriptor shape
59 *
60 * @param[in] tensor_shape Tensor shape to set
61 *
62 * @return This tensor descriptor
63 */
64 TensorDescriptor &set_shape(TensorShape &tensor_shape)
65 {
66 shape = tensor_shape;
67 return *this;
68 }
69 /** Sets tensor descriptor data type
70 *
71 * @param[in] tensor_data_type Data type
72 *
73 * @return This tensor descriptor
74 */
75 TensorDescriptor &set_data_type(DataType tensor_data_type)
76 {
77 data_type = tensor_data_type;
78 return *this;
79 }
80 /** Sets tensor descriptor data layout
81 *
82 * @param[in] data_layout Data layout
83 *
84 * @return This tensor descriptor
85 */
86 TensorDescriptor &set_layout(DataLayout data_layout)
87 {
88 layout = data_layout;
89 return *this;
90 }
91 /** Sets tensor descriptor quantization info
92 *
93 * @param[in] tensor_quant_info Quantization information
94 *
95 * @return This tensor descriptor
96 */
97 TensorDescriptor &set_quantization_info(QuantizationInfo tensor_quant_info)
98 {
99 quant_info = tensor_quant_info;
100 return *this;
101 }
102
103 // Inherited methods overridden:
104 std::unique_ptr<TensorDescriptor> clone() const override
105 {
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000106 return std::make_unique<TensorDescriptor>(*this);
Georgios Pinitascac13b12018-04-27 19:07:19 +0100107 }
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000108
Giorgio Arenabb54e4e2018-04-05 17:20:34 +0100109 TensorShape shape{}; /**< Tensor shape */
110 DataType data_type{ DataType::UNKNOWN }; /**< Data type */
Georgios Pinitascac13b12018-04-27 19:07:19 +0100111 DataLayout layout{ DataLayout::NCHW }; /**< Data layout */
Giorgio Arenabb54e4e2018-04-05 17:20:34 +0100112 QuantizationInfo quant_info{}; /**< Quantization info */
113 Target target{ Target::UNSPECIFIED }; /**< Target */
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000114};
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100115} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000116} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000117#endif /* ARM_COMPUTE_GRAPH_TENSOR_DESCRIPTOR_H */