blob: 87cf7c142653e991f4a928078d60ea4fce08fe09 [file] [log] [blame]
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +00001/*
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 Jensen5ff48022023-06-27 14:13:24 +010028#include "ckw/types/DataType.h"
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010029#include "ckw/types/TensorDataLayout.h"
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000030#include <array>
31#include <cstdint>
32
33namespace ckw
34{
Jakub Sujak8c49f162023-06-16 09:52:50 +010035
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000036/** Compute Kernel Writer tensor shape
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010037 * The value -1 for the tensor dimension is reserved to dynamic dimensions.
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000038 */
39using TensorShape = std::array<int32_t, 5>;
40
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010041/** Tensor dimension value reserved to dynamic dimensions */
42constexpr int32_t kDynamicTensorDimensionValue = -1;
43
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000044/** Compute Kernel Writer tensor info */
45class TensorInfo
46{
47public:
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010048 /** Default constructor */
49 TensorInfo() = default;
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000050 /** 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 Jensenacea4072023-07-03 09:44:42 +010062
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000063 /** Set shape */
64 TensorInfo &shape(const TensorShape &shape);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010065
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000066 /** Get shape */
67 TensorShape shape() const;
Nikolaj Jensenacea4072023-07-03 09:44:42 +010068
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000069 /** Set data type */
70 TensorInfo &data_type(DataType dt);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010071
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000072 /** Get data type */
73 DataType data_type() const;
Nikolaj Jensenacea4072023-07-03 09:44:42 +010074
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000075 /** Set data layout */
76 TensorInfo &data_layout(TensorDataLayout dl);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010077
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000078 /** Get data layout */
79 TensorDataLayout data_layout() const;
Nikolaj Jensenacea4072023-07-03 09:44:42 +010080
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000081 /** Set id */
82 TensorInfo &id(int32_t id);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010083
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000084 /** Get layout */
85 int32_t id() const;
86
87private:
88 TensorShape _shape{ { 0 } };
89 DataType _dt{ DataType::Unknown };
90 TensorDataLayout _dl{ TensorDataLayout::Unknown };
91 int32_t _id{ -1 };
92};
Nikolaj Jensenacea4072023-07-03 09:44:42 +010093} // namespace ckw
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000094
95#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TENSORINFO_H */