Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [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 COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TENSORINFO_H |
| 26 | #define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TENSORINFO_H |
| 27 | |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 28 | #include "ckw/types/DataType.h" |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 29 | #include "ckw/types/TensorDataLayout.h" |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 30 | #include <array> |
| 31 | #include <cstdint> |
| 32 | |
| 33 | namespace ckw |
| 34 | { |
Jakub Sujak | 8c49f16 | 2023-06-16 09:52:50 +0100 | [diff] [blame] | 35 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 36 | /** Compute Kernel Writer tensor shape |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 37 | * The value -1 for the tensor dimension is reserved to dynamic dimensions. |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 38 | */ |
| 39 | using TensorShape = std::array<int32_t, 5>; |
| 40 | |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 41 | /** Tensor dimension value reserved to dynamic dimensions */ |
| 42 | constexpr int32_t kDynamicTensorDimensionValue = -1; |
| 43 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 44 | /** Compute Kernel Writer tensor info */ |
| 45 | class TensorInfo |
| 46 | { |
| 47 | public: |
Gian Marco Iodice | ebfdb5a | 2023-07-07 11:25:57 +0100 | [diff] [blame] | 48 | /** Default constructor */ |
| 49 | TensorInfo() = default; |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 50 | /** Constructor |
| 51 | * |
| 52 | * @param[in] dt Tensor data type |
| 53 | * @param[in] shape Tensor shape |
| 54 | * @param[in] dl Tensor data layout |
| 55 | * @param[in] id Tensor id. The id is used to keep track of the user tensor binded. Through the id, |
| 56 | * the user can know what tensor has been used by the Compute Kernel Writer. |
| 57 | * Possible id values: |
| 58 | * - greater than or equal to 0: bind a user specific tensors |
| 59 | * - less than 0: bind a virtual tensor (tile) |
| 60 | */ |
| 61 | TensorInfo(DataType dt, const TensorShape &shape, TensorDataLayout dl, int32_t id); |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 62 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 63 | /** Set shape */ |
| 64 | TensorInfo &shape(const TensorShape &shape); |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 65 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 66 | /** Get shape */ |
| 67 | TensorShape shape() const; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 68 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 69 | /** Set data type */ |
| 70 | TensorInfo &data_type(DataType dt); |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 71 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 72 | /** Get data type */ |
| 73 | DataType data_type() const; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 74 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 75 | /** Set data layout */ |
| 76 | TensorInfo &data_layout(TensorDataLayout dl); |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 77 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 78 | /** Get data layout */ |
| 79 | TensorDataLayout data_layout() const; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 80 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 81 | /** Set id */ |
| 82 | TensorInfo &id(int32_t id); |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 83 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 84 | /** Get layout */ |
| 85 | int32_t id() const; |
| 86 | |
| 87 | private: |
| 88 | TensorShape _shape{ { 0 } }; |
| 89 | DataType _dt{ DataType::Unknown }; |
| 90 | TensorDataLayout _dl{ TensorDataLayout::Unknown }; |
| 91 | int32_t _id{ -1 }; |
| 92 | }; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 93 | } // namespace ckw |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 94 | |
| 95 | #endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TENSORINFO_H */ |