blob: 5c87cb5b120c30fac9bd944ac00deb54af5391aa [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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000031#include <array>
32#include <cstdint>
33
34namespace ckw
35{
Jakub Sujak8c49f162023-06-16 09:52:50 +010036
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000037/** Compute Kernel Writer tensor shape
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010038 * The value -1 for the tensor dimension is reserved to dynamic dimensions.
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000039 */
40using TensorShape = std::array<int32_t, 5>;
41
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010042/** Tensor dimension value reserved to dynamic dimensions */
43constexpr int32_t kDynamicTensorDimensionValue = -1;
44
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000045/** Compute Kernel Writer tensor info */
46class TensorInfo
47{
48public:
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010049 /** Default constructor */
50 TensorInfo() = default;
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000051 /** Constructor
52 *
53 * @param[in] dt Tensor data type
54 * @param[in] shape Tensor shape
55 * @param[in] dl Tensor data layout
56 * @param[in] id Tensor id. The id is used to keep track of the user tensor binded. Through the id,
57 * the user can know what tensor has been used by the Compute Kernel Writer.
58 * Possible id values:
59 * - greater than or equal to 0: bind a user specific tensors
60 * - less than 0: bind a virtual tensor (tile)
61 */
62 TensorInfo(DataType dt, const TensorShape &shape, TensorDataLayout dl, int32_t id);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010063
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000064 /** Set shape */
65 TensorInfo &shape(const TensorShape &shape);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010066
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000067 /** Get shape */
68 TensorShape shape() const;
Nikolaj Jensenacea4072023-07-03 09:44:42 +010069
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000070 /** Set data type */
71 TensorInfo &data_type(DataType dt);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010072
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000073 /** Get data type */
74 DataType data_type() const;
Nikolaj Jensenacea4072023-07-03 09:44:42 +010075
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000076 /** Set data layout */
77 TensorInfo &data_layout(TensorDataLayout dl);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010078
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000079 /** Get data layout */
80 TensorDataLayout data_layout() const;
Nikolaj Jensenacea4072023-07-03 09:44:42 +010081
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000082 /** Set id */
83 TensorInfo &id(int32_t id);
Nikolaj Jensenacea4072023-07-03 09:44:42 +010084
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000085 /** Get layout */
86 int32_t id() const;
87
88private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010089 TensorShape _shape{{0}};
90 DataType _dt{DataType::Unknown};
91 TensorDataLayout _dl{TensorDataLayout::Unknown};
92 int32_t _id{-1};
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000093};
Nikolaj Jensenacea4072023-07-03 09:44:42 +010094} // namespace ckw
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000095
96#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_TENSORINFO_H */