blob: 9a002ad22c8cd1bfd871fe43fc93a4ffb5cddc80 [file] [log] [blame]
Georgios Pinitas8a5146f2021-01-12 15:51:07 +00001/*
2 * Copyright (c) 2021 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 */
Georgios Pinitas06ac6e42021-07-05 08:08:52 +010024#ifndef ARM_COMPUTE_ACL_TYPES_H_
25#define ARM_COMPUTE_ACL_TYPES_H_
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000026
27#include <stddef.h>
28#include <stdint.h>
29
30#ifdef __cplusplus
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010031extern "C"
32{
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000033#endif /* __cplusplus */
34
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010035 /**< Opaque Context object */
36 typedef struct AclContext_ *AclContext;
37 /**< Opaque Queue object */
38 typedef struct AclQueue_ *AclQueue;
39 /**< Opaque Tensor object */
40 typedef struct AclTensor_ *AclTensor;
41 /**< Opaque Tensor pack object */
42 typedef struct AclTensorPack_ *AclTensorPack;
43 /**< Opaque Operator object */
44 typedef struct AclOperator_ *AclOperator;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000045
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010046 // Capabilities bitfield (Note: if multiple are enabled ComputeLibrary will pick the best possible)
47 typedef uint64_t AclTargetCapabilities;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000048
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010049 /**< Error codes returned by the public entry-points */
50 typedef enum AclStatus : int32_t
51 {
52 AclSuccess = 0, /**< Call succeeded, leading to valid state for all involved objects/data */
53 AclRuntimeError = 1, /**< Call failed during execution */
54 AclOutOfMemory = 2, /**< Call failed due to failure to allocate resources */
55 AclUnimplemented = 3, /**< Call failed as requested capability is not implemented */
56 AclUnsupportedTarget = 4, /**< Call failed as an invalid backend was requested */
57 AclInvalidTarget = 5, /**< Call failed as invalid argument was passed */
58 AclInvalidArgument = 6, /**< Call failed as invalid argument was passed */
59 AclUnsupportedConfig = 7, /**< Call failed as configuration is unsupported */
60 AclInvalidObjectState = 8, /**< Call failed as an object has invalid state */
61 } AclStatus;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000062
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 /**< Supported CPU targets */
64 typedef enum AclTarget
65 {
66 AclCpu = 0, /**< Cpu target that uses SIMD extensions */
67 AclGpuOcl = 1, /**< OpenCL target for GPU */
68 } AclTarget;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000069
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010070 /** Execution mode types */
71 typedef enum AclExecutionMode
72 {
73 AclPreferFastRerun = 0, /**< Prioritize performance when multiple iterations are performed */
74 AclPreferFastStart = 1, /**< Prioritize performance when a single iterations is expected to be performed */
75 } AclExecutionMode;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000076
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010077 /** Available CPU capabilities */
78 typedef enum AclCpuCapabilities
79 {
80 AclCpuCapabilitiesAuto = 0, /**< Automatic discovery of capabilities */
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000081
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082 AclCpuCapabilitiesNeon = (1 << 0), /**< Enable NEON optimized paths */
83 AclCpuCapabilitiesSve = (1 << 1), /**< Enable SVE optimized paths */
84 AclCpuCapabilitiesSve2 = (1 << 2), /**< Enable SVE2 optimized paths */
85 // Reserve 3, 4, 5, 6
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000086
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 AclCpuCapabilitiesFp16 = (1 << 7), /**< Enable float16 data-type support */
88 AclCpuCapabilitiesBf16 = (1 << 8), /**< Enable bfloat16 data-type support */
89 // Reserve 9, 10, 11, 12
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000090
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010091 AclCpuCapabilitiesDot = (1 << 13), /**< Enable paths that use the udot/sdot instructions */
92 AclCpuCapabilitiesMmlaInt8 = (1 << 14), /**< Enable paths that use the mmla integer instructions */
93 AclCpuCapabilitiesMmlaFp = (1 << 15), /**< Enable paths that use the mmla float instructions */
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000094
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010095 AclCpuCapabilitiesAll = ~0 /**< Enable all paths */
96 } AclCpuCapabilities;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000097
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010098 /**< Allocator interface that can be passed to a context */
99 typedef struct AclAllocator
100 {
101 /** Allocate a block of size bytes of memory.
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000102 *
103 * @param[in] user_data User provided data that can be used by the allocator
104 * @param[in] size Size of the allocation
105 *
106 * @return A pointer to the allocated block if successfull else NULL
107 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100108 void *(*alloc)(void *user_data, size_t size);
109 /** Release a block of size bytes of memory.
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000110 *
111 * @param[in] user_data User provided data that can be used by the allocator
112 * @param[in] size Size of the allocation
113 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100114 void (*free)(void *user_data, void *ptr);
115 /** Allocate a block of size bytes of memory.
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000116 *
117 * @param[in] user_data User provided data that can be used by the allocator
118 * @param[in] size Size of the allocation
119 *
120 * @return A pointer to the allocated block if successfull else NULL
121 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100122 void *(*aligned_alloc)(void *user_data, size_t size, size_t alignment);
123 /** Allocate a block of size bytes of memory.
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000124 *
125 * @param[in] user_data User provided data that can be used by the allocator
126 * @param[in] size Size of the allocation
127 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100128 void (*aligned_free)(void *user_data, void *ptr);
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000129
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100130 /**< User provided information */
131 void *user_data;
132 } AclAllocator;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000133
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100134 /**< Context options */
135 typedef struct AclContextOptions
136 {
137 AclExecutionMode mode; /**< Execution mode to use */
138 AclTargetCapabilities capabilities; /**< Target capabilities */
139 bool enable_fast_math; /**< Allow precision loss */
140 const char *kernel_config_file; /**< Kernel cofiguration file */
141 int32_t max_compute_units; /**< Max compute units that can be used by a queue created from the context.
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000142 If <=0 the system will use the hw concurency insted */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100143 AclAllocator *allocator; /**< Allocator to be used by all the memory internally */
144 } AclContextOptions;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000145
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100146 /**< Supported tuning modes */
147 typedef enum
148 {
149 AclTuningModeNone = 0, /**< No tuning */
150 AclRapid = 1, /**< Fast tuning mode, testing a small portion of the tuning space */
151 AclNormal = 2, /**< Normal tuning mode, gives a good balance between tuning mode and performance */
152 AclExhaustive = 3, /**< Exhaustive tuning mode, increased tuning time but with best results */
153 } AclTuningMode;
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000154
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100155 /**< Queue options */
156 typedef struct
157 {
158 AclTuningMode mode; /**< Tuning mode */
159 int32_t compute_units; /**< Compute Units that the queue will deploy */
160 } AclQueueOptions;
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000161
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100162 /**< Supported data types */
163 typedef enum AclDataType
164 {
165 AclDataTypeUnknown = 0, /**< Unknown data type */
166 AclUInt8 = 1, /**< 8-bit unsigned integer */
167 AclInt8 = 2, /**< 8-bit signed integer */
168 AclUInt16 = 3, /**< 16-bit unsigned integer */
169 AclInt16 = 4, /**< 16-bit signed integer */
170 AclUint32 = 5, /**< 32-bit unsigned integer */
171 AclInt32 = 6, /**< 32-bit signed integer */
172 AclFloat16 = 7, /**< 16-bit floating point */
173 AclBFloat16 = 8, /**< 16-bit brain floating point */
174 AclFloat32 = 9, /**< 32-bit floating point */
175 } AclDataType;
Georgios Pinitas3f26ef42021-02-23 10:01:33 +0000176
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100177 /**< Supported data layouts for operations */
178 typedef enum AclDataLayout
179 {
180 AclDataLayoutUnknown = 0, /**< Unknown data layout */
181 AclNhwc = 1, /**< Native, performant, Compute Library data layout */
182 AclNchw = 2, /**< Data layout where width is the fastest changing dimension */
183 } AclDataLayout;
Georgios Pinitas3f26ef42021-02-23 10:01:33 +0000184
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100185 /** Type of memory to be imported */
186 typedef enum AclImportMemoryType
187 {
188 AclHostPtr = 0 /**< Host allocated memory */
189 } AclImportMemoryType;
Georgios Pinitas3f26ef42021-02-23 10:01:33 +0000190
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100191 /**< Tensor Descriptor */
192 typedef struct AclTensorDescriptor
193 {
194 int32_t ndims; /**< Number or dimensions */
195 int32_t *shape; /**< Tensor Shape */
196 AclDataType data_type; /**< Tensor Data type */
197 int64_t *strides; /**< Strides on each dimension. Linear memory is assumed if nullptr */
198 int64_t boffset; /**< Offset in terms of bytes for the first element */
199 } AclTensorDescriptor;
Georgios Pinitas3f26ef42021-02-23 10:01:33 +0000200
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100201 /**< Slot type of a tensor */
202 typedef enum
203 {
204 AclSlotUnknown = -1,
205 AclSrc = 0,
206 AclSrc0 = 0,
207 AclSrc1 = 1,
208 AclDst = 30,
209 AclSrcVec = 256,
210 } AclTensorSlot;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000211
212#ifdef __cplusplus
213}
214#endif /* __cplusplus */
Georgios Pinitas06ac6e42021-07-05 08:08:52 +0100215#endif /* ARM_COMPUTE_ACL_TYPES_H_ */