blob: 69717ec8a89d381b33038d7b978028aa1d97c3c7 [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 */
24#ifndef ARM_COMPUTE_ACLTYPES_H_
25#define ARM_COMPUTE_ACLTYPES_H_
26
27#include <stddef.h>
28#include <stdint.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif /* __cplusplus */
33
34/**< Opaque Context object */
35typedef struct AclContext_ *AclContext;
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000036/**< Opaque Tensor object */
37typedef struct AclTensor_ *AclTensor;
38/**< Opaque Tensor pack object */
39typedef struct AclTensorPack_ *AclTensorPack;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000040
41// Capabilities bitfield (Note: if multiple are enabled ComputeLibrary will pick the best possible)
42typedef uint64_t AclTargetCapabilities;
43
44/**< Error codes returned by the public entry-points */
45typedef enum AclStatus : int32_t
46{
47 AclSuccess = 0, /**< Call succeeded, leading to valid state for all involved objects/data */
48 AclRuntimeError = 1, /**< Call failed during execution */
49 AclOutOfMemory = 2, /**< Call failed due to failure to allocate resources */
50 AclUnimplemented = 3, /**< Call failed as requested capability is not implemented */
51 AclUnsupportedTarget = 4, /**< Call failed as an invalid backend was requested */
52 AclInvalidTarget = 5, /**< Call failed as invalid argument was passed */
53 AclInvalidArgument = 6, /**< Call failed as invalid argument was passed */
54 AclUnsupportedConfig = 7, /**< Call failed as configuration is unsupported */
55 AclInvalidObjectState = 8, /**< Call failed as an object has invalid state */
56} AclStatus;
57
58/**< Supported CPU targets */
59typedef enum AclTarget
60{
61 AclCpu = 0, /**< Cpu target that uses SIMD extensions */
62 AclGpuOcl = 1, /**< OpenCL target for GPU */
63} AclTarget;
64
65/** Execution mode types */
66typedef enum AclExecutionMode
67{
68 AclPreferFastRerun = 0, /**< Prioritize performance when multiple iterations are performed */
69 AclPreferFastStart = 1, /**< Prioritize performance when a single iterations is expected to be performed */
70} AclExecutionMode;
71
72/** Available CPU capabilities */
Georgios Pinitasd122c102021-03-10 00:30:18 +000073typedef enum AclCpuCapabilities
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000074{
75 AclCpuCapabilitiesAuto = 0, /**< Automatic discovery of capabilities */
76
77 AclCpuCapabilitiesNeon = (1 << 0), /**< Enable NEON optimized paths */
78 AclCpuCapabilitiesSve = (1 << 1), /**< Enable SVE optimized paths */
79 AclCpuCapabilitiesSve2 = (1 << 2), /**< Enable SVE2 optimized paths */
80 // Reserve 3, 4, 5, 6
81
82 AclCpuCapabilitiesFp16 = (1 << 7), /**< Enable float16 data-type support */
83 AclCpuCapabilitiesBf16 = (1 << 8), /**< Enable bfloat16 data-type support */
84 // Reserve 9, 10, 11, 12
85
86 AclCpuCapabilitiesDot = (1 << 13), /**< Enable paths that use the udot/sdot instructions */
87 AclCpuCapabilitiesMmlaInt8 = (1 << 14), /**< Enable paths that use the mmla integer instructions */
88 AclCpuCapabilitiesMmlaFp = (1 << 15), /**< Enable paths that use the mmla float instructions */
89
90 AclCpuCapabilitiesAll = ~0 /**< Enable all paths */
Georgios Pinitasd122c102021-03-10 00:30:18 +000091} AclCpuCapabilities;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000092
93/**< Allocator interface that can be passed to a context */
94typedef struct AclAllocator
95{
96 /** Allocate a block of size bytes of memory.
97 *
98 * @param[in] user_data User provided data that can be used by the allocator
99 * @param[in] size Size of the allocation
100 *
101 * @return A pointer to the allocated block if successfull else NULL
102 */
103 void *(*alloc)(void *user_data, size_t size);
104 /** Release a block of size bytes of memory.
105 *
106 * @param[in] user_data User provided data that can be used by the allocator
107 * @param[in] size Size of the allocation
108 */
109 void (*free)(void *user_data, void *ptr);
110 /** Allocate a block of size bytes of memory.
111 *
112 * @param[in] user_data User provided data that can be used by the allocator
113 * @param[in] size Size of the allocation
114 *
115 * @return A pointer to the allocated block if successfull else NULL
116 */
117 void *(*aligned_alloc)(void *user_data, size_t size, size_t alignment);
118 /** Allocate a block of size bytes of memory.
119 *
120 * @param[in] user_data User provided data that can be used by the allocator
121 * @param[in] size Size of the allocation
122 */
123 void (*aligned_free)(void *user_data, void *ptr);
124
125 /**< User provided information */
126 void *user_data;
127} AclAllocator;
128
129/**< Context options */
130typedef struct AclContextOptions
131{
132 AclExecutionMode mode; /**< Execution mode to use */
133 AclTargetCapabilities capabilities; /**< Target capabilities */
134 bool enable_fast_math; /**< Allow precision loss */
135 const char *kernel_config_file; /**< Kernel cofiguration file */
136 int32_t max_compute_units; /**< Max compute units that can be used by a queue created from the context.
137 If <=0 the system will use the hw concurency insted */
138 AclAllocator *allocator; /**< Allocator to be used by all the memory internally */
139} AclContextOptions;
140
Georgios Pinitas3f26ef42021-02-23 10:01:33 +0000141/**< Supported data types */
142typedef enum AclDataType
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000143{
Georgios Pinitas3f26ef42021-02-23 10:01:33 +0000144 AclDataTypeUnknown = 0, /**< Unknown data type */
145 AclUInt8 = 1, /**< 8-bit unsigned integer */
146 AclInt8 = 2, /**< 8-bit signed integer */
147 AclUInt16 = 3, /**< 16-bit unsigned integer */
148 AclInt16 = 4, /**< 16-bit signed integer */
149 AclUint32 = 5, /**< 32-bit unsigned integer */
150 AclInt32 = 6, /**< 32-bit signed integer */
151 AclFloat16 = 7, /**< 16-bit floating point */
152 AclBFloat16 = 8, /**< 16-bit brain floating point */
153 AclFloat32 = 9, /**< 32-bit floating point */
154} AclDataType;
155
156/**< Supported data layouts for operations */
157typedef enum AclDataLayout
158{
159 AclDataLayoutUnknown = 0, /**< Unknown data layout */
160 AclNhwc = 1, /**< Native, performant, Compute Library data layout */
161 AclNchw = 2, /**< Data layout where width is the fastest changing dimension */
162} AclDataLayout;
163
164/** Type of memory to be imported */
165typedef enum AclImportMemoryType
166{
167 AclHostPtr = 0 /**< Host allocated memory */
168} AclImportMemoryType;
169
170/**< Tensor Descriptor */
171typedef struct AclTensorDescriptor
172{
173 int32_t ndims; /**< Number or dimensions */
174 int32_t *shape; /**< Tensor Shape */
175 AclDataType data_type; /**< Tensor Data type */
176 int64_t *strides; /**< Strides on each dimension. Linear memory is assumed if nullptr */
177 int64_t boffset; /**< Offset in terms of bytes for the first element */
178} AclTensorDescriptor;
179
180/**< Slot type of a tensor */
181typedef enum
182{
183 AclSlotUnknown = -1,
184 AclSrc = 0,
185 AclSrc0 = 0,
186 AclSrc1 = 1,
187 AclDst = 30,
188 AclSrcVec = 256,
189} AclTensorSlot;
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000190
191#ifdef __cplusplus
192}
193#endif /* __cplusplus */
194#endif /* ARM_COMPUTE_ACLTYPES_H_ */