blob: 40ad69fdc04cc36d8dfb5087b632e9f03a65e4d9 [file] [log] [blame]
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +01001/*
2 * Copyright (c) 2023 Arm Limited.
3 *
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 */
24
25#ifndef CKW_SRC_ITENSORARGUMENT_H
26#define CKW_SRC_ITENSORARGUMENT_H
27
28#include "ckw/TensorInfo.h"
29#include "ckw/types/TensorComponentType.h"
30#include "ckw/types/TensorStorageType.h"
31#include "src/ITile.h"
32
33#include <string>
34#include <vector>
35
36namespace ckw
37{
38/** Tensor storage variable */
39struct TensorStorageVariable
40{
41 std::string val{ "" }; /** Tensor storage as a string */
42 std::string type{ "" }; /** Tensor storage type as a string */
43};
44
45/** Tensor argument base class.
46 * A tensor is a multidimensional array used to store data. To access an element (or multiple elements) from a tensor,
47 * the following information are required:
48 * -# The data memory object. For example, the pointer to the array
49 * -# The tensor components, such as the size of each tensor dimension, or the number of elements in bytes contained in each dimension (also known as the "stride")
50 */
51class ITensorArgument
52{
53public:
54 virtual ~ITensorArgument() = default;
55 /** Method to get the name of the tensor argument.
56 *
57 * @return the name of the tensor argument
58 */
59 std::string name() const
60 {
61 return _basename;
62 }
63 /** Method to get the tensor info
64 *
65 * @return the @ref TensorInfo
66 */
67 TensorInfo info() const
68 {
69 return _info;
70 }
71
72protected:
73 TensorInfo _info{}; // Tensor info
74 std::string _basename{ "" }; // Tensor name
75};
76
77/** Tensor component argument base class */
78class ITensorComponentArgument
79{
80public:
81 virtual ~ITensorComponentArgument() = default;
82 /** Method to get the tensor component variable as a string
83 *
84 * @param[in] x The tensor component to query
85 *
86 * @return the tensor component variable as a @ref TileVariable
87 */
88 virtual TileVariable component(TensorComponentType x) = 0;
89 /** Method to get all tensor components needed to access the data in the tensor
90 *
91 * The tensor components returned by this method must be all passed as kernel argument
92 *
93 * @return a vector containing all the tensor components as @ref TileVariable objects
94 */
95 virtual std::vector<TileVariable> components() const = 0;
96};
97
98/** Tensor storage argument base class */
99class ITensorStorageArgument
100{
101public:
102 virtual ~ITensorStorageArgument() = default;
103 /** Method to get the tensor storage as a string
104 *
105 * @param[in] x The tensor storage to query
106 *
107 * @return the tensor storage as a @ref TensorStorageVariable
108 */
109 virtual TensorStorageVariable storage(TensorStorageType x) = 0;
110 /** Method to get all tensor storages needed to access the data in the tensor
111 *
112 * The tensor storages returned by this method must be all passed as kernel argument
113 *
114 * @return a vector containing all the tensor storages as @ref TensorStorageVariable objects
115 */
116 virtual std::vector<TensorStorageVariable> storages() const = 0;
117};
118
119} // namespace ckw
120
121#endif // CKW_SRC_ITENSORARGUMENT_H