blob: 117e8de2cf983c8b02ef49509010ce21f4bee765 [file] [log] [blame]
Gunes Bayire4211672023-07-25 10:37:13 +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_INCLUDE_CKW_TENSORSAMPLER_H
26#define CKW_INCLUDE_CKW_TENSORSAMPLER_H
27
Gunes Bayire4211672023-07-25 10:37:13 +010028#include "ckw/types/TensorSamplerTypes.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029#include "ckw/types/TensorStorageType.h"
Gunes Bayire4211672023-07-25 10:37:13 +010030
31namespace ckw
32{
33
34/** Tensor sampler
35 *
36 * It contains information about how the tensor is sampled. It can be used to
37 * tell how a tile should be stored to tensor memory, and how a tensor should be
38 * sampled to get the values stored in a tile. Where to sample the tensor is
39 * defined with the coordinates respecting the addressing modes, storage type and
40 * the tensor format defined in this class.
41 */
42class TensorSampler
43{
44public:
45 /** Initialize a new instance of @ref TensorSampler class. */
46 TensorSampler();
47
48 /** Initialize a new instance of @ref TensorSampler class.
49 *
50 * @param[in] storage Tensor storage to load/store the tensor from/to
51 * @param[in] format The tensor data format.
52 * @param[in] address_mode_x The address mode of the x dimension.
53 * @param[in] address_mode_y The address mode of the y dimension.
54 * @param[in] address_mode_z The address mode of the z dimension.
55 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010056 TensorSampler(TensorStorageType storage,
57 TensorSamplerFormat format,
58 TensorSamplerAddressModeX address_mode_x,
59 TensorSamplerAddressModeY address_mode_y,
60 TensorSamplerAddressModeZ address_mode_z);
Gunes Bayire4211672023-07-25 10:37:13 +010061
62 /** Get the storage for the tensor */
63 TensorStorageType storage() const;
64
65 /** Set the storage for the tensor */
66 TensorSampler &storage(TensorStorageType storage);
67
68 /** Get the format of the tensor. */
69 TensorSamplerFormat format() const;
70
71 /** Set the format of the tensor. */
72 TensorSampler &format(TensorSamplerFormat format);
73
74 /** Get the address mode of the x dimension. */
75 TensorSamplerAddressModeX address_mode_x() const;
76
77 /** Set the address mode of the x dimension. */
78 TensorSampler &address_mode_x(TensorSamplerAddressModeX address_mode_x);
79
80 /** Get the address mode of the y dimension. */
81 TensorSamplerAddressModeY address_mode_y() const;
82
83 /** Set the address mode of the y dimension. */
84 TensorSampler &address_mode_y(TensorSamplerAddressModeY address_mode_y);
85
86 /** Get the address mode of the z dimension. */
87 TensorSamplerAddressModeZ address_mode_z() const;
88
89 /** Set the address mode of the z dimension. */
90 TensorSampler &address_mode_z(TensorSamplerAddressModeZ address_mode_z);
91
92private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010093 TensorStorageType _storage{TensorStorageType::BufferUint8Ptr};
94 TensorSamplerFormat _format{TensorSamplerFormat::Unknown};
95 TensorSamplerAddressModeX _address_mode_x{TensorSamplerAddressModeX::Unknown};
96 TensorSamplerAddressModeY _address_mode_y{TensorSamplerAddressModeY::Unknown};
97 TensorSamplerAddressModeZ _address_mode_z{TensorSamplerAddressModeZ::Unknown};
Gunes Bayire4211672023-07-25 10:37:13 +010098};
99
100} // namespace ckw
101
102#endif // CKW_PROTOTYPE_INCLUDE_CKW_TENSORSAMPLER_H