blob: 838bd40f85b5d812df07072e4d659f8ee9da7342 [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{
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010038
39class ITensorComponent;
40
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010041/** Tensor storage variable */
42struct TensorStorageVariable
43{
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010044 std::string val{ "" }; /** Tensor storage as a string */
45 TensorStorageType type{ TensorStorageType::Unknown }; /** Tensor storage type */
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010046};
47
48/** Tensor argument base class.
49 * A tensor is a multidimensional array used to store data. To access an element (or multiple elements) from a tensor,
50 * the following information are required:
51 * -# The data memory object. For example, the pointer to the array
52 * -# 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")
53 */
54class ITensorArgument
55{
56public:
57 virtual ~ITensorArgument() = default;
58 /** Method to get the name of the tensor argument.
59 *
60 * @return the name of the tensor argument
61 */
62 std::string name() const
63 {
64 return _basename;
65 }
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010066
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010067 /** Method to get the tensor info
68 *
69 * @return the @ref TensorInfo
70 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010071 TensorInfo &info()
72 {
73 return _info;
74 }
75
76 /** Method to get the tensor info
77 *
78 * @return the @ref TensorInfo
79 */
80 const TensorInfo &info() const
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010081 {
82 return _info;
83 }
84
85protected:
86 TensorInfo _info{}; // Tensor info
87 std::string _basename{ "" }; // Tensor name
88};
89
90/** Tensor component argument base class */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010091class ITensorComponentAccess
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010092{
93public:
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010094 virtual ~ITensorComponentAccess() = default;
95 /** Method to get the tensor component variable as a tile.
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010096 *
97 * @param[in] x The tensor component to query
98 *
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010099 * @return the tensor component variable as a @ref ITile.
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100100 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100101 virtual ITile &component(TensorComponentType x) = 0;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100102 /** Method to get all tensor components needed to access the data in the tensor
103 *
104 * The tensor components returned by this method must be all passed as kernel argument
105 *
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100106 * @return a vector containing all the tensor components as pointers to @ref ITensorComponent objects.
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100107 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100108 virtual std::vector<const ITensorComponent *> components() const = 0;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100109};
110
111/** Tensor storage argument base class */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100112class ITensorStorageAccess
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100113{
114public:
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100115 virtual ~ITensorStorageAccess() = default;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100116 /** Method to get the tensor storage as a string
117 *
118 * @param[in] x The tensor storage to query
119 *
120 * @return the tensor storage as a @ref TensorStorageVariable
121 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100122 virtual TensorStorageVariable &storage(TensorStorageType x) = 0;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100123 /** Method to get all tensor storages needed to access the data in the tensor
124 *
125 * The tensor storages returned by this method must be all passed as kernel argument
126 *
127 * @return a vector containing all the tensor storages as @ref TensorStorageVariable objects
128 */
129 virtual std::vector<TensorStorageVariable> storages() const = 0;
130};
131
132} // namespace ckw
133
134#endif // CKW_SRC_ITENSORARGUMENT_H