1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ADAPTER_WRAPPER_H
17 #define ADAPTER_WRAPPER_H
18 
19 #include "protocol/retcode_inner/aie_retcode_inner.h"
20 #include "ipc_skeleton.h"
21 #include "protocol/struct_definition/aie_info_define.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /**
28  * Allocate client ID and generate adapter for client.
29  *
30  * @return Returns client ID if the operation is successful, returns INVALID_CLIENT_ID otherwise.
31  */
32 extern int GenerateClient();
33 
34 /**
35  * Generate transaction ID and load certain algorithm based on the information transferred from client.
36  *
37  * @param [in] clientInfo Client information.
38  * @param [in] algorithmInfo Algorithm information.
39  * @param [in] inputInfo Data information needed to load algorithm plugin.
40  * @param [out] outputInfo The returned data information after loading the algorithm plugin.
41  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
42  */
43 extern int LoadAlgoWrapper(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo,
44     const DataInfo *inputInfo, DataInfo *outputInfo);
45 
46 /**
47  * Execute algorithm inference synchronously.
48  *
49  * @param [in] clientInfo Client information.
50  * @param [in] AlgorithmInfo Algorithm information.
51  * @param [in] inputInfo Data information needed to synchronous execution algorithm.
52  * @param [out] outputInfo Algorithm inference results.
53  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
54  */
55 extern int SyncExecAlgoWrapper(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo,
56     const DataInfo *inputInfo, DataInfo *outputInfo);
57 
58 /**
59  * Execute algorithm inference asynchronously.
60  *
61  * @param [in] clientInfo Client information.
62  * @param [in] AlgorithmInfo Algorithm information.
63  * @param [in] inputInfo Data information needed to synchronous execution algorithm.
64  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
65  */
66 extern int AsyncExecAlgoWrapper(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo, const DataInfo *inputInfo);
67 
68 /**
69  * Unload algorithm plugin and model based on algorithm information and client information.
70  *
71  * @param [in] clientInfo Client information.
72  * @param [in] algorithmInfo Algorithm information.
73  * @param [in] inputInfo Data information needed to load algorithm plugin.
74  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
75  */
76 extern int UnloadAlgoWrapper(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo, const DataInfo *inputInfo);
77 
78 /**
79  * Delete client adapter.
80  *
81  * @param [in] clientInfo Client information.
82  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
83  */
84 extern int RemoveAdapterWrapper(const ClientInfo *clientInfo);
85 
86 /**
87  * Set the configuration parameters of the engine or plugin.
88  *
89  * @param [in] clientInfo Client information.
90  * @param [in] optionType The type of setting option.
91  * @param [in] inputInfo Configuration parameter needed to set up the engine or plugin.
92  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
93  */
94 extern int SetOptionWrapper(const ClientInfo *clientInfo, int optionType, const DataInfo *inputInfo);
95 
96 /**
97  * Get the configuration parameters of the engine or plugin.
98  *
99  * @param [in] clientInfo Client information.
100  * @param [in] optionType The type of getting option.
101  * @param [in] inputInfo Parameter information for getting options.
102  * @param [out] outputInfo The configuration parameter information.
103  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
104  */
105 extern int GetOptionWrapper(const ClientInfo *clientInfo, int optionType, const DataInfo *inputInfo,
106     DataInfo *outputInfo);
107 
108 /**
109  * Save listener to call client async process, and register server async handler.
110  *
111  * @param [in] clientInfo Client information.
112  * @param [in] sid Client async callback SVC handle identity
113  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
114  */
115 extern int RegisterCallbackWrapper(const ClientInfo *clientInfo, SvcIdentity *sid);
116 
117 /**
118  * Delete listener to call client async process, and stop server async handler.
119  *
120  * @param [in] clientInfo Client information.
121  * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
122  */
123 extern int UnregisterCallbackWrapper(const ClientInfo *clientInfo);
124 
125 #ifdef __cplusplus
126 };
127 #endif
128 
129 #endif // ADAPTER_WRAPPER_H
130