xref: /aosp_15_r20/external/ComputeLibrary/arm_compute/AclEntrypoints.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1*c217d954SCole Faust /*
2*c217d954SCole Faust  * Copyright (c) 2021 Arm Limited.
3*c217d954SCole Faust  *
4*c217d954SCole Faust  * SPDX-License-Identifier: MIT
5*c217d954SCole Faust  *
6*c217d954SCole Faust  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*c217d954SCole Faust  * of this software and associated documentation files (the "Software"), to
8*c217d954SCole Faust  * deal in the Software without restriction, including without limitation the
9*c217d954SCole Faust  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*c217d954SCole Faust  * sell copies of the Software, and to permit persons to whom the Software is
11*c217d954SCole Faust  * furnished to do so, subject to the following conditions:
12*c217d954SCole Faust  *
13*c217d954SCole Faust  * The above copyright notice and this permission notice shall be included in all
14*c217d954SCole Faust  * copies or substantial portions of the Software.
15*c217d954SCole Faust  *
16*c217d954SCole Faust  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*c217d954SCole Faust  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*c217d954SCole Faust  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*c217d954SCole Faust  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*c217d954SCole Faust  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*c217d954SCole Faust  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*c217d954SCole Faust  * SOFTWARE.
23*c217d954SCole Faust  */
24*c217d954SCole Faust #ifndef ARM_COMPUTE_ACL_ENTRYPOINTS_H_
25*c217d954SCole Faust #define ARM_COMPUTE_ACL_ENTRYPOINTS_H_
26*c217d954SCole Faust 
27*c217d954SCole Faust #include "arm_compute/AclTypes.h"
28*c217d954SCole Faust 
29*c217d954SCole Faust #ifdef __cplusplus
30*c217d954SCole Faust extern "C" {
31*c217d954SCole Faust #endif /** __cplusplus */
32*c217d954SCole Faust 
33*c217d954SCole Faust /** Create a context object
34*c217d954SCole Faust  *
35*c217d954SCole Faust  * Context is responsible for retaining internal information and work as an aggregate service mechanism
36*c217d954SCole Faust  *
37*c217d954SCole Faust  * @param[in, out] ctx     A valid non-zero context object if no failure occurs
38*c217d954SCole Faust  * @param[in]      target  Target to create the context for
39*c217d954SCole Faust  * @param[in]      options Context options to be used for all the kernels that are created under the context
40*c217d954SCole Faust  *
41*c217d954SCole Faust  * @return Status code
42*c217d954SCole Faust  *
43*c217d954SCole Faust  * Returns:
44*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
45*c217d954SCole Faust  *  - @ref AclOutOfMemory if there was a failure allocating memory resources
46*c217d954SCole Faust  *  - @ref AclUnsupportedTarget if the requested target is unsupported
47*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
48*c217d954SCole Faust  */
49*c217d954SCole Faust AclStatus AclCreateContext(AclContext              *ctx,
50*c217d954SCole Faust                            AclTarget                target,
51*c217d954SCole Faust                            const AclContextOptions *options);
52*c217d954SCole Faust 
53*c217d954SCole Faust /** Destroy a given context object
54*c217d954SCole Faust  *
55*c217d954SCole Faust  * @param[in] ctx A valid context object to destroy
56*c217d954SCole Faust  *
57*c217d954SCole Faust  * @return Status code
58*c217d954SCole Faust  *
59*c217d954SCole Faust  * Returns:
60*c217d954SCole Faust  *  - @ref AclSuccess if functions was completed successfully
61*c217d954SCole Faust  *  - @ref AclInvalidArgument if the provided context is invalid
62*c217d954SCole Faust  */
63*c217d954SCole Faust AclStatus AclDestroyContext(AclContext ctx);
64*c217d954SCole Faust 
65*c217d954SCole Faust /** Create an operator queue
66*c217d954SCole Faust  *
67*c217d954SCole Faust  * Queue is responsible for any scheduling related activities
68*c217d954SCole Faust  *
69*c217d954SCole Faust  * @param[in, out] queue   A valid non-zero queue object is not failures occur
70*c217d954SCole Faust  * @param[in]      ctx     Context to be used
71*c217d954SCole Faust  * @param[in]      options Queue options to be used for the operators using the queue
72*c217d954SCole Faust  *
73*c217d954SCole Faust  * @return Status code
74*c217d954SCole Faust  *
75*c217d954SCole Faust  * Returns:
76*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
77*c217d954SCole Faust  *  - @ref AclOutOfMemory if there was a failure allocating memory resources
78*c217d954SCole Faust  *  - @ref AclUnsupportedTarget if the requested target is unsupported
79*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
80*c217d954SCole Faust  */
81*c217d954SCole Faust AclStatus AclCreateQueue(AclQueue *queue, AclContext ctx, const AclQueueOptions *options);
82*c217d954SCole Faust 
83*c217d954SCole Faust /** Wait until all elements on the queue have been completed
84*c217d954SCole Faust  *
85*c217d954SCole Faust  * @param[in] queue Queue to wait on completion
86*c217d954SCole Faust  *
87*c217d954SCole Faust  * @return Status code
88*c217d954SCole Faust  *
89*c217d954SCole Faust  * Returns:
90*c217d954SCole Faust  *  - @ref AclSuccess if functions was completed successfully
91*c217d954SCole Faust  *  - @ref AclInvalidArgument if the provided queue is invalid
92*c217d954SCole Faust  *  - @ref AclRuntimeError on any other runtime related error
93*c217d954SCole Faust  */
94*c217d954SCole Faust AclStatus AclQueueFinish(AclQueue queue);
95*c217d954SCole Faust 
96*c217d954SCole Faust /** Destroy a given queue object
97*c217d954SCole Faust  *
98*c217d954SCole Faust  * @param[in] queue A valid context object to destroy
99*c217d954SCole Faust  *
100*c217d954SCole Faust  * @return Status code
101*c217d954SCole Faust  *
102*c217d954SCole Faust  * Returns:
103*c217d954SCole Faust  *  - @ref AclSuccess if functions was completed successfully
104*c217d954SCole Faust  *  - @ref AclInvalidArgument if the provided context is invalid
105*c217d954SCole Faust  */
106*c217d954SCole Faust AclStatus AclDestroyQueue(AclQueue queue);
107*c217d954SCole Faust 
108*c217d954SCole Faust /** Create a Tensor object
109*c217d954SCole Faust  *
110*c217d954SCole Faust  * Tensor is a generalized matrix construct that can represent up to ND dimensionality (where N = 6 for Compute Library)
111*c217d954SCole Faust  * The object holds a backing memory along-side to operate on
112*c217d954SCole Faust  *
113*c217d954SCole Faust  * @param[in, out] tensor   A valid non-zero tensor object if no failures occur
114*c217d954SCole Faust  * @param[in]      ctx      Context to be used
115*c217d954SCole Faust  * @param[in]      desc     Tensor representation meta-data
116*c217d954SCole Faust  * @param[in]      allocate Instructs allocation of the tensor objects
117*c217d954SCole Faust  *
118*c217d954SCole Faust  * Returns:
119*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
120*c217d954SCole Faust  *  - @ref AclOutOfMemory if there was a failure allocating memory resources
121*c217d954SCole Faust  *  - @ref AclUnsupportedTarget if the requested target is unsupported
122*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
123*c217d954SCole Faust  */
124*c217d954SCole Faust AclStatus AclCreateTensor(AclTensor *tensor, AclContext ctx, const AclTensorDescriptor *desc, bool allocate);
125*c217d954SCole Faust 
126*c217d954SCole Faust /** Map a tensor's backing memory to the host
127*c217d954SCole Faust  *
128*c217d954SCole Faust  * @param[in]      tensor Tensor to be mapped
129*c217d954SCole Faust  * @param[in, out] handle A handle to the underlying backing memory
130*c217d954SCole Faust  *
131*c217d954SCole Faust  * @return Status code
132*c217d954SCole Faust  *
133*c217d954SCole Faust  * Returns:
134*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
135*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
136*c217d954SCole Faust  */
137*c217d954SCole Faust AclStatus AclMapTensor(AclTensor tensor, void **handle);
138*c217d954SCole Faust 
139*c217d954SCole Faust /** Unmap the tensor's backing memory
140*c217d954SCole Faust  *
141*c217d954SCole Faust  * @param[in] tensor tensor to unmap memory from
142*c217d954SCole Faust  * @param[in] handle Backing memory to be unmapped
143*c217d954SCole Faust  *
144*c217d954SCole Faust  * @return Status code
145*c217d954SCole Faust  *
146*c217d954SCole Faust  * Returns:
147*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
148*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
149*c217d954SCole Faust  */
150*c217d954SCole Faust AclStatus AclUnmapTensor(AclTensor tensor, void *handle);
151*c217d954SCole Faust 
152*c217d954SCole Faust /** Import external memory to a given tensor object
153*c217d954SCole Faust  *
154*c217d954SCole Faust  * @param[in, out] tensor Tensor to import memory to
155*c217d954SCole Faust  * @param[in]      handle Backing memory to be imported
156*c217d954SCole Faust  * @param[in]      type   Type of the imported memory
157*c217d954SCole Faust  *
158*c217d954SCole Faust  * Returns:
159*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
160*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
161*c217d954SCole Faust  */
162*c217d954SCole Faust AclStatus AclTensorImport(AclTensor tensor, void *handle, AclImportMemoryType type);
163*c217d954SCole Faust 
164*c217d954SCole Faust /** Destroy a given tensor object
165*c217d954SCole Faust  *
166*c217d954SCole Faust  * @param[in,out] tensor A valid tensor object to be destroyed
167*c217d954SCole Faust  *
168*c217d954SCole Faust  * @return Status code
169*c217d954SCole Faust  *
170*c217d954SCole Faust  * Returns:
171*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
172*c217d954SCole Faust  *  - @ref AclInvalidArgument if the provided tensor is invalid
173*c217d954SCole Faust  */
174*c217d954SCole Faust AclStatus AclDestroyTensor(AclTensor tensor);
175*c217d954SCole Faust 
176*c217d954SCole Faust /** Creates a tensor pack
177*c217d954SCole Faust  *
178*c217d954SCole Faust  * Tensor packs are used to create a collection of tensors that can be passed around for operator execution
179*c217d954SCole Faust  *
180*c217d954SCole Faust  * @param[in,out] pack A valid non-zero tensor pack object if no failures occur
181*c217d954SCole Faust  * @param[in]     ctx  Context to be used
182*c217d954SCole Faust  *
183*c217d954SCole Faust  * @return Status code
184*c217d954SCole Faust  *
185*c217d954SCole Faust  * Returns:
186*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
187*c217d954SCole Faust  *  - @ref AclOutOfMemory if there was a failure allocating memory resources
188*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
189*c217d954SCole Faust  */
190*c217d954SCole Faust AclStatus AclCreateTensorPack(AclTensorPack *pack, AclContext ctx);
191*c217d954SCole Faust 
192*c217d954SCole Faust /** Add a tensor to a tensor pack
193*c217d954SCole Faust  *
194*c217d954SCole Faust  * @param[in,out] pack    Pack to append a tensor to
195*c217d954SCole Faust  * @param[in]     tensor  Tensor to pack
196*c217d954SCole Faust  * @param[in]     slot_id Slot of the operator that the tensors corresponds to
197*c217d954SCole Faust  *
198*c217d954SCole Faust  * @return Status code
199*c217d954SCole Faust  *
200*c217d954SCole Faust  * Returns:
201*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
202*c217d954SCole Faust  *  - @ref AclOutOfMemory if there was a failure allocating memory resources
203*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
204*c217d954SCole Faust  */
205*c217d954SCole Faust AclStatus AclPackTensor(AclTensorPack pack, AclTensor tensor, int32_t slot_id);
206*c217d954SCole Faust 
207*c217d954SCole Faust /** A list of tensors to a tensor pack
208*c217d954SCole Faust  *
209*c217d954SCole Faust  * @param[in,out] pack        Pack to append the tensors to
210*c217d954SCole Faust  * @param[in]     tensors     Tensors to append to the pack
211*c217d954SCole Faust  * @param[in]     slot_ids    Slot IDs of each tensors to the operators
212*c217d954SCole Faust  * @param[in]     num_tensors Number of tensors that are passed
213*c217d954SCole Faust  *
214*c217d954SCole Faust  * @return Status code
215*c217d954SCole Faust  *
216*c217d954SCole Faust  * Returns:
217*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
218*c217d954SCole Faust  *  - @ref AclOutOfMemory if there was a failure allocating memory resources
219*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
220*c217d954SCole Faust  */
221*c217d954SCole Faust AclStatus AclPackTensors(AclTensorPack pack, AclTensor *tensors, int32_t *slot_ids, size_t num_tensors);
222*c217d954SCole Faust 
223*c217d954SCole Faust /** Destroy a given tensor pack object
224*c217d954SCole Faust  *
225*c217d954SCole Faust  * @param[in,out] pack A valid tensor pack object to destroy
226*c217d954SCole Faust  *
227*c217d954SCole Faust  * @return Status code
228*c217d954SCole Faust  *
229*c217d954SCole Faust  * Returns:
230*c217d954SCole Faust  *  - @ref AclSuccess if functions was completed successfully
231*c217d954SCole Faust  *  - @ref AclInvalidArgument if the provided context is invalid
232*c217d954SCole Faust  */
233*c217d954SCole Faust AclStatus AclDestroyTensorPack(AclTensorPack pack);
234*c217d954SCole Faust 
235*c217d954SCole Faust /** Eager execution of a given operator on a list of inputs and outputs
236*c217d954SCole Faust  *
237*c217d954SCole Faust  * @param[in]     op      Operator to execute
238*c217d954SCole Faust  * @param[in]     queue   Queue to schedule the operator on
239*c217d954SCole Faust  * @param[in,out] tensors A list of input and outputs tensors to execute the operator on
240*c217d954SCole Faust  *
241*c217d954SCole Faust  * @return Status Code
242*c217d954SCole Faust  *
243*c217d954SCole Faust  * Returns:
244*c217d954SCole Faust  *  - @ref AclSuccess if function was completed successfully
245*c217d954SCole Faust  *  - @ref AclOutOfMemory if there was a failure allocating memory resources
246*c217d954SCole Faust  *  - @ref AclUnsupportedTarget if the requested target is unsupported
247*c217d954SCole Faust  *  - @ref AclInvalidArgument if a given argument is invalid
248*c217d954SCole Faust  *  - @ref AclRuntimeError on any other runtime related error
249*c217d954SCole Faust  */
250*c217d954SCole Faust AclStatus AclRunOperator(AclOperator op, AclQueue queue, AclTensorPack tensors);
251*c217d954SCole Faust 
252*c217d954SCole Faust /** Destroy a given operator object
253*c217d954SCole Faust  *
254*c217d954SCole Faust  * @param[in,out] op A valid operator object to destroy
255*c217d954SCole Faust  *
256*c217d954SCole Faust  * @return Status code
257*c217d954SCole Faust  *
258*c217d954SCole Faust  * Returns:
259*c217d954SCole Faust  *  - @ref AclSuccess if functions was completed successfully
260*c217d954SCole Faust  *  - @ref AclInvalidArgument if the provided context is invalid
261*c217d954SCole Faust  */
262*c217d954SCole Faust AclStatus AclDestroyOperator(AclOperator op);
263*c217d954SCole Faust #ifdef __cplusplus
264*c217d954SCole Faust }
265*c217d954SCole Faust #endif /* __cplusplus */
266*c217d954SCole Faust #endif /* ARM_COMPUTE_ACL_ENTRYPOINTS_H_ */
267