Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 36 | namespace ckw |
| 37 | { |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 38 | |
| 39 | class ITensorComponent; |
| 40 | |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 41 | /** Tensor storage variable */ |
| 42 | struct TensorStorageVariable |
| 43 | { |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 44 | std::string val{ "" }; /** Tensor storage as a string */ |
| 45 | TensorStorageType type{ TensorStorageType::Unknown }; /** Tensor storage type */ |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 46 | }; |
| 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 | */ |
| 54 | class ITensorArgument |
| 55 | { |
| 56 | public: |
| 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 Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 66 | |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 67 | /** Method to get the tensor info |
| 68 | * |
| 69 | * @return the @ref TensorInfo |
| 70 | */ |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 71 | 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 Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 81 | { |
| 82 | return _info; |
| 83 | } |
| 84 | |
| 85 | protected: |
| 86 | TensorInfo _info{}; // Tensor info |
| 87 | std::string _basename{ "" }; // Tensor name |
| 88 | }; |
| 89 | |
| 90 | /** Tensor component argument base class */ |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 91 | class ITensorComponentAccess |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 92 | { |
| 93 | public: |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 94 | virtual ~ITensorComponentAccess() = default; |
| 95 | /** Method to get the tensor component variable as a tile. |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 96 | * |
| 97 | * @param[in] x The tensor component to query |
| 98 | * |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 99 | * @return the tensor component variable as a @ref ITile. |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 100 | */ |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 101 | virtual ITile &component(TensorComponentType x) = 0; |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 102 | /** 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 Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 106 | * @return a vector containing all the tensor components as pointers to @ref ITensorComponent objects. |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 107 | */ |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 108 | virtual std::vector<const ITensorComponent *> components() const = 0; |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | /** Tensor storage argument base class */ |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 112 | class ITensorStorageAccess |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 113 | { |
| 114 | public: |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 115 | virtual ~ITensorStorageAccess() = default; |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 116 | /** 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 Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 122 | virtual TensorStorageVariable &storage(TensorStorageType x) = 0; |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 123 | /** 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 |