blob: ece45a4dc41af0bd1bfd754842740cc64f8d3ea7 [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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010031
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010032#include "src/ITile.h"
33
34#include <string>
35#include <vector>
36
37namespace ckw
38{
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010039
40class ITensorComponent;
41
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010042/** Tensor storage variable */
43struct TensorStorageVariable
44{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010045 std::string val{""}; /** Tensor storage as a string */
46 TensorStorageType type{TensorStorageType::Unknown}; /** Tensor storage type */
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010047};
48
49/** Tensor argument base class.
50 * A tensor is a multidimensional array used to store data. To access an element (or multiple elements) from a tensor,
51 * the following information are required:
52 * -# The data memory object. For example, the pointer to the array
53 * -# 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")
54 */
55class ITensorArgument
56{
57public:
58 virtual ~ITensorArgument() = default;
59 /** Method to get the name of the tensor argument.
60 *
61 * @return the name of the tensor argument
62 */
63 std::string name() const
64 {
65 return _basename;
66 }
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010067
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010068 /** Method to get the tensor info
69 *
70 * @return the @ref TensorInfo
71 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010072 TensorInfo &info()
73 {
74 return _info;
75 }
76
77 /** Method to get the tensor info
78 *
79 * @return the @ref TensorInfo
80 */
81 const TensorInfo &info() const
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010082 {
83 return _info;
84 }
85
86protected:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 TensorInfo _info{}; // Tensor info
88 std::string _basename{""}; // Tensor name
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010089};
90
91/** Tensor component argument base class */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010092class ITensorComponentAccess
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010093{
94public:
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010095 virtual ~ITensorComponentAccess() = default;
96 /** Method to get the tensor component variable as a tile.
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010097 *
98 * @param[in] x The tensor component to query
99 *
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100100 * @return the tensor component variable as a @ref ITile.
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100101 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100102 virtual ITile &component(TensorComponentType x) = 0;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100103 /** Method to get all tensor components needed to access the data in the tensor
104 *
105 * The tensor components returned by this method must be all passed as kernel argument
106 *
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100107 * @return a vector containing all the tensor components as pointers to @ref ITensorComponent objects.
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100108 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100109 virtual std::vector<const ITensorComponent *> components() const = 0;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100110};
111
112/** Tensor storage argument base class */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100113class ITensorStorageAccess
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100114{
115public:
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100116 virtual ~ITensorStorageAccess() = default;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100117 /** Method to get the tensor storage as a string
118 *
119 * @param[in] x The tensor storage to query
120 *
121 * @return the tensor storage as a @ref TensorStorageVariable
122 */
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100123 virtual TensorStorageVariable &storage(TensorStorageType x) = 0;
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100124 /** Method to get all tensor storages needed to access the data in the tensor
125 *
126 * The tensor storages returned by this method must be all passed as kernel argument
127 *
128 * @return a vector containing all the tensor storages as @ref TensorStorageVariable objects
129 */
130 virtual std::vector<TensorStorageVariable> storages() const = 0;
131};
132
133} // namespace ckw
134
135#endif // CKW_SRC_ITENSORARGUMENT_H