• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 __HI_RUNTIME_COMM_H__
17 #define __HI_RUNTIME_COMM_H__
18 #include "hi_type.h"
19 
20 #ifdef __cplusplus
21 #if __cplusplus
22 extern "C" {
23 #endif
24 #endif /* __cplusplus */
25 
26 #define MAX_NAME_LEN 64                 /* Model max name */
27 #define FULL_NAME_LEN 130
28 
29 typedef HI_VOID *HI_MW_PTR;                /* Handle define for model and tasks */
30 
31 #ifndef IN
32 #define IN
33 #endif
34 
35 #ifndef OUT
36 #define OUT
37 #endif
38 
39 #ifndef INOUT
40 #define INOUT
41 #endif
42 
43 /* Blob type */
44 typedef enum hiRUNTIME_BLOB_TYPE_E {
45     HI_RUNTIME_BLOB_TYPE_S32       =  0x0,
46     HI_RUNTIME_BLOB_TYPE_U8        =  0x1,
47     HI_RUNTIME_BLOB_TYPE_YVU420SP  =  0x2,
48     HI_RUNTIME_BLOB_TYPE_YVU422SP  =  0x3,
49     HI_RUNTIME_BLOB_TYPE_VEC_S32   =  0x4,
50     HI_RUNTIME_BLOB_TYPE_SEQ_S32   =  0x5,
51     HI_RUNTIME_BLOB_TYPE_BUTT
52 } HI_RUNTIME_BLOB_TYPE_E;
53 
54 typedef enum hiRUNTIME_GROUP_PRIORITY_E {
55     HI_RUNTIME_GROUP_PRIORITY_HIGHEST = 0x0,
56     HI_RUNTIME_GROUP_PRIORITY_HIGH,
57     HI_RUNTIME_GROUP_PRIORITY_MEDIUM,
58     HI_RUNTIME_GROUP_PRIORITY_LOW,
59     HI_RUNTIME_GROUP_PRIORITY_LOWEST,
60     HI_RUNTIME_GROUP_PRIORITY_BUTT
61 } HI_RUNTIME_GROUP_PRIORITY_E;
62 
63 /****************************** Blob struct ******************************
64 In Caffe, the blob contain shape info as the following order:
65 Image\FeatureMap:               N       C       H       W
66 RNN\LSTM(Recurrent) vector:     T       N       D
67 
68 The relationship of the following blob struct with Caffe blob is as follows:
69 Image\FeatureMap:               Num    Chn    Height   With
70 RNN\LSTM(SEQ_S32) vector:       Step   Num     Dim
71 The stride, which measuring unit is byte, is always algined by the width or
72 dim direction.
73 **************************************************************************/
74 typedef struct hiRUNTIME_BLOB_S {
75     HI_RUNTIME_BLOB_TYPE_E enBlobType;  /* Blob type */
76     HI_U32 u32Stride;                /* Stride, a line bytes num */
77     HI_U64 u64VirAddr;               /* virtual addr */
78     HI_U64 u64PhyAddr;               /* physical addr */
79 
80     HI_U32 u32Num;                   /* N: frame num or sequence num, correspond to caffe blob's n */
81     union {
82         struct {
83             HI_U32 u32Width;         /* W: frame width, correspond to caffe blob's w */
84             HI_U32 u32Height;        /* H: frame height, correspond to caffe blob's h */
85             HI_U32 u32Chn;           /* C: frame channel, correspond to caffe blob's c */
86         } stWhc;
87         struct {
88             HI_U32 u32Dim;           /* D: vecotr dimension */
89             HI_U64 u64VirAddrStep;   /* T: virtual adress of time steps array in each sequence */
90         } stSeq;
91     } unShape;
92 } HI_RUNTIME_BLOB_S, *HI_RUNTIME_BLOB_PTR;
93 
94 typedef struct hiRUNTIME_SRC_BLOB_ARRAY_S {
95     HI_U32 u32BlobNum;
96     HI_RUNTIME_BLOB_S *pstBlobs;
97 } HI_RUNTIME_BLOB_ARRAY_S, *HI_RUNTIME_BLOB_ARRAY_PTR;
98 
99 typedef HI_RUNTIME_BLOB_ARRAY_S HI_RUNTIME_SRC_BLOB_ARRAY_S;
100 typedef HI_RUNTIME_BLOB_ARRAY_S HI_RUNTIME_DST_BLOB_ARRAY_S;
101 typedef HI_RUNTIME_BLOB_ARRAY_PTR HI_RUNTIME_SRC_BLOB_ARRAY_PTR;
102 typedef HI_RUNTIME_BLOB_ARRAY_PTR HI_RUNTIME_DST_BLOB_ARRAY_PTR;
103 
104 typedef struct hiRUNTIME_GROUP_BLOB_S {
105     HI_RUNTIME_BLOB_PTR pstBlob;
106     HI_CHAR acOwnerName[MAX_NAME_LEN + 1];
107     HI_CHAR acBlobName[MAX_NAME_LEN + 1];
108 } HI_RUNTIME_GROUP_BLOB_S, *HI_RUNTIME_GROUP_BLOB_PTR;
109 
110 typedef HI_RUNTIME_GROUP_BLOB_S HI_RUNTIME_GROUP_SRC_BLOB_S;
111 typedef HI_RUNTIME_GROUP_BLOB_S HI_RUNTIME_GROUP_DST_BLOB_S;
112 
113 /* Mem information */
114 typedef struct hiRUNTIME_MEM_S {
115     HI_U64  u64PhyAddr; /* RW;The physical address of the memory */
116     HI_U64  u64VirAddr; /* RW;The virtual address of the memory */
117     HI_U32  u32Size;    /* RW;The size of memory */
118 } HI_RUNTIME_MEM_S, *HI_RUNTIME_MEM_PTR;
119 
120 typedef HI_S32 (*HI_RUNTIME_AllocMem)(INOUT HI_RUNTIME_MEM_S *pstMemInfo);
121 typedef HI_S32 (*HI_RUNTIME_FlushCache)(HI_RUNTIME_MEM_S *pstMemInfo);
122 typedef HI_S32 (*HI_RUNTIME_FreeMem)(HI_RUNTIME_MEM_S *pstMemInfo);
123 
124 typedef struct hiRUNTIME_MEM_CTRL_S {
125     HI_RUNTIME_AllocMem allocMem;
126     HI_RUNTIME_FlushCache flushMem;
127     HI_RUNTIME_FreeMem freeMem;
128 } HI_RUNTIME_MEM_CTRL_S;
129 
130 typedef struct hiRUNTIME_WK_MEM_S {
131     HI_CHAR acModelName[MAX_NAME_LEN + 1];
132     HI_RUNTIME_MEM_S stWKMemory;
133 } HI_RUNTIME_WK_INFO_S;
134 
135 typedef struct hiRUNTIME_WK_MEM_ARRAY_S {
136     HI_U32 u32WKNum;
137     HI_RUNTIME_WK_INFO_S *pstAttrs;
138 } HI_RUNTIME_WK_INFO_ARRAY_S, *HI_RUNTIME_WK_INFO_ARRAY_PTR;
139 
140 typedef struct hiRUNTIME_COP_ATTR_S {
141     HI_CHAR acModelName[MAX_NAME_LEN + 1];
142     HI_CHAR acCopName[MAX_NAME_LEN + 1];
143     HI_U32 u32ConstParamSize;
144     HI_VOID *pConstParam;
145 } HI_RUNTIME_COP_ATTR_S, *HI_RUNTIME_COP_ATTR_PTR;
146 
147 typedef struct hiRUNTIME_COP_ATTR_ARRAY_S {
148     HI_U32 u32CopNum;
149     HI_RUNTIME_COP_ATTR_S *pstAttrs;
150 } HI_RUNTIME_COP_ATTR_ARRAY_S, *HI_RUNTIME_COP_ATTR_ARRAY_PTR;
151 
152 /* Forward callback event */
153 typedef enum hiRUNTIME_FORWARD_STATUS_CALLBACK_E {
154     HI_RUNTIME_FORWARD_STATUS_SUCC = 0x0,
155     HI_RUNTIME_FORWARD_STATUS_FAIL,
156     HI_RUNTIME_FORWARD_STATUS_ABORT,
157     HI_RUNTIME_FORWARD_STATUS_BUTT
158 } HI_RUNTIME_FORWARD_STATUS_CALLBACK_E;
159 
160 typedef HI_S32 (*HI_RUNTIME_Connector_Compute) (HI_RUNTIME_SRC_BLOB_ARRAY_S* pstConnectorSrc,
161     HI_RUNTIME_DST_BLOB_ARRAY_S* pstConnectorDst, HI_U64 u64SrcId, HI_VOID* pParam);
162 
163 typedef struct hiRUNTIME_CONNECTOR_ATTR_S {
164     HI_CHAR acName[MAX_NAME_LEN + 1];
165     HI_RUNTIME_Connector_Compute pConnectorFun;
166     HI_VOID *pParam;
167 } HI_RUNTIME_CONNECTOR_ATTR_S;
168 
169 typedef struct hiRUNTIME_CONNECTOR_ATTR_ARRAY_S {
170     HI_U32 u32ConnectorNum;
171     HI_RUNTIME_CONNECTOR_ATTR_S *pstAttrs;
172 } HI_RUNTIME_CONNECTOR_ATTR_ARRAY_S, *HI_RUNTIME_CONNECTOR_ATTR_ARRAY_PTR;
173 
174 typedef struct hiRUNTIME_GROUP_INFO_S {
175     HI_RUNTIME_WK_INFO_ARRAY_S stWKsInfo;
176     HI_RUNTIME_COP_ATTR_ARRAY_S stCopsAttr;
177     HI_RUNTIME_CONNECTOR_ATTR_ARRAY_S stConnectorsAttr;
178 } HI_RUNTIME_GROUP_INFO_S, *HI_RUNTIME_GROUP_INFO_PTR;
179 
180 /* handle info after LoadModelGroup */
181 typedef HI_VOID *HI_RUNTIME_GROUP_HANDLE;
182 
183 /* the src blobs of group, all model inputs are inside */
184 typedef struct hiRUNTIME_GROUP_BLOB_ARRAY_S {
185     HI_U32 u32BlobNum;
186     HI_RUNTIME_GROUP_BLOB_S *pstBlobs;
187 } HI_RUNTIME_GROUP_BLOB_ARRAY_S, *HI_RUNTIME_GROUP_BLOB_ARRAY_PTR;
188 
189 typedef HI_RUNTIME_GROUP_BLOB_ARRAY_S HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S;
190 typedef HI_RUNTIME_GROUP_BLOB_ARRAY_S HI_RUNTIME_GROUP_DST_BLOB_ARRAY_S;
191 typedef HI_RUNTIME_GROUP_BLOB_ARRAY_S *HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_PTR;
192 typedef HI_RUNTIME_GROUP_BLOB_ARRAY_S *HI_RUNTIME_GROUP_DST_BLOB_ARRAY_PTR;
193 
194 /**
195 \brief forward result calback function.
196 \attention \n
197 none.
198 \param[out] enEvent:  Result message of forward.
199 \param[out] pstGroup: Group Handle
200 \param[out] u64SrcId: Frame ID
201 \param[out] pstDst:   Result blob
202 \see \n
203 none.
204 */
205 typedef HI_S32 (*HI_RUNTIME_Forward_Callback)(HI_RUNTIME_FORWARD_STATUS_CALLBACK_E enEvent,
206     HI_RUNTIME_GROUP_HANDLE hGroupHandle, HI_U64 u64SrcId, HI_RUNTIME_GROUP_DST_BLOB_ARRAY_PTR pstDst);
207 
208 // errno message
209 enum {
210     HI_ERR_SVP_RUNTIME_BASE = (HI_S32)(0xFF000F00),
211     HI_ERR_SVP_RUNTIME_ILLEGAL_STATE,
212     HI_ERR_SVP_RUNTIME_MODEL_NOLOAD,
213     HI_ERR_SVP_RUNTIME_NULL_PTR,
214     HI_ERR_SVP_RUNTIME_INVALID_PARAM,
215     HI_ERR_SVP_RUNTIME_SDK_ERROR,
216     HI_ERR_SVP_RUNTIME_SDK_NOMEM,
217 };
218 
219 #ifndef hi_unsed
220 #define hi_unused(x)    ((hi_void)x)
221 #endif
222 
223 #ifdef __cplusplus
224 #if __cplusplus
225 }
226 #endif
227 #endif /* __cplusplus */
228 
229 #endif /* __HI_RUNTIME_COMM_H__ */
230