1 /****************************************************************************
2 *
3 * Copyright (c) 2017 - 2022 by Rockchip Corp. All rights reserved.
4 *
5 * The material in this file is confidential and contains trade secrets
6 * of Rockchip Corporation. This is proprietary information owned by
7 * Rockchip Corporation. No part of this work may be disclosed,
8 * reproduced, copied, transmitted, or used in any way for any purpose,
9 * without the express written permission of Rockchip Corporation.
10 *
11 *****************************************************************************/
12
13
14 #ifndef _RKNN_API_H
15 #define _RKNN_API_H
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #include <stdint.h>
22
23 /*
24 Definition of extended flag for rknn_init.
25 */
26 /* set high priority context. */
27 #define RKNN_FLAG_PRIOR_HIGH 0x00000000
28
29 /* set medium priority context */
30 #define RKNN_FLAG_PRIOR_MEDIUM 0x00000001
31
32 /* set low priority context. */
33 #define RKNN_FLAG_PRIOR_LOW 0x00000002
34
35 /* asynchronous mode.
36 when enable, rknn_outputs_get will not block for too long because it directly retrieves the result of
37 the previous frame which can increase the frame rate on single-threaded mode, but at the cost of
38 rknn_outputs_get not retrieves the result of the current frame.
39 in multi-threaded mode you do not need to turn this mode on. */
40 #define RKNN_FLAG_ASYNC_MASK 0x00000004
41
42 /* collect performance mode.
43 when enable, you can get detailed performance reports via rknn_query(ctx, RKNN_QUERY_PERF_DETAIL, ...),
44 but it will reduce the frame rate. */
45 #define RKNN_FLAG_COLLECT_PERF_MASK 0x00000008
46
47 /* allocate all memory in outside, includes weight/internal/inputs/outputs */
48 #define RKNN_FLAG_MEM_ALLOC_OUTSIDE 0x00000010
49
50 /* weight sharing with the same network structure */
51 #define RKNN_FLAG_SHARE_WEIGHT_MEM 0x00000020
52
53 /* send fence fd from outside */
54 #define RKNN_FLAG_FENCE_IN_OUTSIDE 0x00000040
55
56 /* get fence fd from inside */
57 #define RKNN_FLAG_FENCE_OUT_OUTSIDE 0x00000080
58
59 /* dummy init flag: could only get total_weight_size and total_internal_size by rknn_query*/
60 #define RKNN_FLAG_COLLECT_MODEL_INFO_ONLY 0x00000100
61
62 /*
63 Error code returned by the RKNN API.
64 */
65 #define RKNN_SUCC 0 /* execute succeed. */
66 #define RKNN_ERR_FAIL -1 /* execute failed. */
67 #define RKNN_ERR_TIMEOUT -2 /* execute timeout. */
68 #define RKNN_ERR_DEVICE_UNAVAILABLE -3 /* device is unavailable. */
69 #define RKNN_ERR_MALLOC_FAIL -4 /* memory malloc fail. */
70 #define RKNN_ERR_PARAM_INVALID -5 /* parameter is invalid. */
71 #define RKNN_ERR_MODEL_INVALID -6 /* model is invalid. */
72 #define RKNN_ERR_CTX_INVALID -7 /* context is invalid. */
73 #define RKNN_ERR_INPUT_INVALID -8 /* input is invalid. */
74 #define RKNN_ERR_OUTPUT_INVALID -9 /* output is invalid. */
75 #define RKNN_ERR_DEVICE_UNMATCH -10 /* the device is unmatch, please update rknn sdk
76 and npu driver/firmware. */
77 #define RKNN_ERR_INCOMPATILE_PRE_COMPILE_MODEL -11 /* This RKNN model use pre_compile mode, but not compatible with current driver. */
78 #define RKNN_ERR_INCOMPATILE_OPTIMIZATION_LEVEL_VERSION -12 /* This RKNN model set optimization level, but not compatible with current driver. */
79 #define RKNN_ERR_TARGET_PLATFORM_UNMATCH -13 /* This RKNN model set target platform, but not compatible with current platform. */
80
81 /*
82 Definition for tensor
83 */
84 #define RKNN_MAX_DIMS 16 /* maximum dimension of tensor. */
85 #define RKNN_MAX_NUM_CHANNEL 15 /* maximum channel number of input tensor. */
86 #define RKNN_MAX_NAME_LEN 256 /* maximum name lenth of tensor. */
87 #define RKNN_MAX_DYNAMIC_SHAPE_NUM 512 /* maximum number of dynamic shape for each input. */
88
89 #ifdef __arm__
90 typedef uint32_t rknn_context;
91 #else
92 typedef uint64_t rknn_context;
93 #endif
94
95
96 /*
97 The query command for rknn_query
98 */
99 typedef enum _rknn_query_cmd {
100 RKNN_QUERY_IN_OUT_NUM = 0, /* query the number of input & output tensor. */
101 RKNN_QUERY_INPUT_ATTR = 1, /* query the attribute of input tensor. */
102 RKNN_QUERY_OUTPUT_ATTR = 2, /* query the attribute of output tensor. */
103 RKNN_QUERY_PERF_DETAIL = 3, /* query the detail performance, need set
104 RKNN_FLAG_COLLECT_PERF_MASK when call rknn_init,
105 this query needs to be valid after rknn_outputs_get. */
106 RKNN_QUERY_PERF_RUN = 4, /* query the time of run,
107 this query needs to be valid after rknn_outputs_get. */
108 RKNN_QUERY_SDK_VERSION = 5, /* query the sdk & driver version */
109
110 RKNN_QUERY_MEM_SIZE = 6, /* query the weight & internal memory size */
111 RKNN_QUERY_CUSTOM_STRING = 7, /* query the custom string */
112
113 RKNN_QUERY_NATIVE_INPUT_ATTR = 8, /* query the attribute of native input tensor. */
114 RKNN_QUERY_NATIVE_OUTPUT_ATTR = 9, /* query the attribute of native output tensor. */
115
116 RKNN_QUERY_NATIVE_NC1HWC2_INPUT_ATTR = 8, /* query the attribute of native input tensor. */
117 RKNN_QUERY_NATIVE_NC1HWC2_OUTPUT_ATTR = 9, /* query the attribute of native output tensor. */
118
119 RKNN_QUERY_NATIVE_NHWC_INPUT_ATTR = 10, /* query the attribute of native input tensor. */
120 RKNN_QUERY_NATIVE_NHWC_OUTPUT_ATTR = 11, /* query the attribute of native output tensor. */
121
122 RKNN_QUERY_DEVICE_MEM_INFO = 12, /* query the attribute of rknn memory information. */
123
124 RKNN_QUERY_INPUT_DYNAMIC_RANGE = 13, /* query the dynamic shape range of rknn input tensor. */
125 RKNN_QUERY_CURRENT_INPUT_ATTR = 14, /* query the current shape of rknn input tensor, only valid for dynamic rknn model*/
126 RKNN_QUERY_CURRENT_OUTPUT_ATTR = 15, /* query the current shape of rknn output tensor, only valid for dynamic rknn model*/
127
128 RKNN_QUERY_CMD_MAX
129 } rknn_query_cmd;
130
131 /*
132 the tensor data type.
133 */
134 typedef enum _rknn_tensor_type {
135 RKNN_TENSOR_FLOAT32 = 0, /* data type is float32. */
136 RKNN_TENSOR_FLOAT16, /* data type is float16. */
137 RKNN_TENSOR_INT8, /* data type is int8. */
138 RKNN_TENSOR_UINT8, /* data type is uint8. */
139 RKNN_TENSOR_INT16, /* data type is int16. */
140 RKNN_TENSOR_UINT16, /* data type is uint16. */
141 RKNN_TENSOR_INT32, /* data type is int32. */
142 RKNN_TENSOR_UINT32, /* data type is uint32. */
143 RKNN_TENSOR_INT64, /* data type is int64. */
144 RKNN_TENSOR_BOOL,
145
146 RKNN_TENSOR_TYPE_MAX
147 } rknn_tensor_type;
148
get_type_string(rknn_tensor_type type)149 inline static const char* get_type_string(rknn_tensor_type type)
150 {
151 switch(type) {
152 case RKNN_TENSOR_FLOAT32: return "FP32";
153 case RKNN_TENSOR_FLOAT16: return "FP16";
154 case RKNN_TENSOR_INT8: return "INT8";
155 case RKNN_TENSOR_UINT8: return "UINT8";
156 case RKNN_TENSOR_INT16: return "INT16";
157 case RKNN_TENSOR_UINT16: return "UINT16";
158 case RKNN_TENSOR_INT32: return "INT32";
159 case RKNN_TENSOR_UINT32: return "UINT32";
160 case RKNN_TENSOR_INT64: return "INT64";
161 case RKNN_TENSOR_BOOL: return "BOOL";
162 default: return "UNKNOW";
163 }
164 }
165
166 /*
167 the quantitative type.
168 */
169 typedef enum _rknn_tensor_qnt_type {
170 RKNN_TENSOR_QNT_NONE = 0, /* none. */
171 RKNN_TENSOR_QNT_DFP, /* dynamic fixed point. */
172 RKNN_TENSOR_QNT_AFFINE_ASYMMETRIC, /* asymmetric affine. */
173
174 RKNN_TENSOR_QNT_MAX
175 } rknn_tensor_qnt_type;
176
get_qnt_type_string(rknn_tensor_qnt_type type)177 inline static const char* get_qnt_type_string(rknn_tensor_qnt_type type)
178 {
179 switch(type) {
180 case RKNN_TENSOR_QNT_NONE: return "NONE";
181 case RKNN_TENSOR_QNT_DFP: return "DFP";
182 case RKNN_TENSOR_QNT_AFFINE_ASYMMETRIC: return "AFFINE";
183 default: return "UNKNOW";
184 }
185 }
186
187 /*
188 the tensor data format.
189 */
190 typedef enum _rknn_tensor_format {
191 RKNN_TENSOR_NCHW = 0, /* data format is NCHW. */
192 RKNN_TENSOR_NHWC, /* data format is NHWC. */
193 RKNN_TENSOR_NC1HWC2, /* data format is NC1HWC2. */
194 RKNN_TENSOR_UNDEFINED,
195
196 RKNN_TENSOR_FORMAT_MAX
197 } rknn_tensor_format;
198
199 /*
200 the mode of running on target NPU core.
201 */
202 typedef enum _rknn_core_mask {
203 RKNN_NPU_CORE_AUTO = 0, /* default, run on NPU core randomly. */
204 RKNN_NPU_CORE_0 = 1, /* run on NPU core 0. */
205 RKNN_NPU_CORE_1 = 2, /* run on NPU core 1. */
206 RKNN_NPU_CORE_2 = 4, /* run on NPU core 2. */
207 RKNN_NPU_CORE_0_1 = RKNN_NPU_CORE_0 | RKNN_NPU_CORE_1, /* run on NPU core 1 and core 2. */
208 RKNN_NPU_CORE_0_1_2 = RKNN_NPU_CORE_0_1 | RKNN_NPU_CORE_2, /* run on NPU core 1 and core 2 and core 3. */
209
210 RKNN_NPU_CORE_UNDEFINED,
211 } rknn_core_mask;
212
get_format_string(rknn_tensor_format fmt)213 inline static const char* get_format_string(rknn_tensor_format fmt)
214 {
215 switch(fmt) {
216 case RKNN_TENSOR_NCHW: return "NCHW";
217 case RKNN_TENSOR_NHWC: return "NHWC";
218 case RKNN_TENSOR_NC1HWC2: return "NC1HWC2";
219 case RKNN_TENSOR_UNDEFINED: return "UNDEFINED";
220 default: return "UNKNOW";
221 }
222 }
223
224 /*
225 the information for RKNN_QUERY_IN_OUT_NUM.
226 */
227 typedef struct _rknn_input_output_num {
228 uint32_t n_input; /* the number of input. */
229 uint32_t n_output; /* the number of output. */
230 } rknn_input_output_num;
231
232 /*
233 the information for RKNN_QUERY_INPUT_ATTR / RKNN_QUERY_OUTPUT_ATTR.
234 */
235 typedef struct _rknn_tensor_attr {
236 uint32_t index; /* input parameter, the index of input/output tensor,
237 need set before call rknn_query. */
238
239 uint32_t n_dims; /* the number of dimensions. */
240 uint32_t dims[RKNN_MAX_DIMS]; /* the dimensions array. */
241 char name[RKNN_MAX_NAME_LEN]; /* the name of tensor. */
242
243 uint32_t n_elems; /* the number of elements. */
244 uint32_t size; /* the bytes size of tensor. */
245
246 rknn_tensor_format fmt; /* the data format of tensor. */
247 rknn_tensor_type type; /* the data type of tensor. */
248 rknn_tensor_qnt_type qnt_type; /* the quantitative type of tensor. */
249 int8_t fl; /* fractional length for RKNN_TENSOR_QNT_DFP. */
250 int32_t zp; /* zero point for RKNN_TENSOR_QNT_AFFINE_ASYMMETRIC. */
251 float scale; /* scale for RKNN_TENSOR_QNT_AFFINE_ASYMMETRIC. */
252
253 uint32_t w_stride; /* the stride of tensor along the width dimention of input,
254 Note: it is read-only, 0 means equal to width. */
255 uint32_t size_with_stride; /* the bytes size of tensor with stride. */
256
257 uint8_t pass_through; /* pass through mode, for rknn_set_io_mem interface.
258 if TRUE, the buf data is passed directly to the input node of the rknn model
259 without any conversion. the following variables do not need to be set.
260 if FALSE, the buf data is converted into an input consistent with the model
261 according to the following type and fmt. so the following variables
262 need to be set.*/
263 uint32_t h_stride; /* the stride along the height dimention of input,
264 Note: it is write-only, if it was set to 0, h_stride = height. */
265 } rknn_tensor_attr;
266
267 typedef struct _rknn_input_range {
268 uint32_t index; /* input parameter, the index of input/output tensor,
269 need set before call rknn_query. */
270 uint32_t shape_number; /* the number of shape. */
271 rknn_tensor_format fmt; /* the data format of tensor. */
272 char name[RKNN_MAX_NAME_LEN]; /* the name of tensor. */
273 uint32_t dyn_range[RKNN_MAX_DYNAMIC_SHAPE_NUM][RKNN_MAX_DIMS]; /* the dynamic input dimensions range. */
274 uint32_t n_dims; /* the number of dimensions. */
275
276 } rknn_input_range;
277
278 /*
279 the information for RKNN_QUERY_PERF_DETAIL.
280 */
281 typedef struct _rknn_perf_detail {
282 char* perf_data; /* the string pointer of perf detail. don't need free it by user. */
283 uint64_t data_len; /* the string length. */
284 } rknn_perf_detail;
285
286 /*
287 the information for RKNN_QUERY_PERF_RUN.
288 */
289 typedef struct _rknn_perf_run {
290 int64_t run_duration; /* real inference time (us) */
291 } rknn_perf_run;
292
293 /*
294 the information for RKNN_QUERY_SDK_VERSION.
295 */
296 typedef struct _rknn_sdk_version {
297 char api_version[256]; /* the version of rknn api. */
298 char drv_version[256]; /* the version of rknn driver. */
299 } rknn_sdk_version;
300
301 /*
302 the information for RKNN_QUERY_MEM_SIZE.
303 */
304 typedef struct _rknn_mem_size {
305 uint32_t total_weight_size; /* the weight memory size */
306 uint32_t total_internal_size; /* the internal memory size, exclude inputs/outputs */
307 uint64_t total_dma_allocated_size; /* total dma memory allocated size */
308 uint32_t total_sram_size; /* total system sram size reserved for rknn */
309 uint32_t free_sram_size; /* free system sram size reserved for rknn */
310 uint32_t reserved[10]; /* reserved */
311 } rknn_mem_size;
312
313 /*
314 the information for RKNN_QUERY_CUSTOM_STRING.
315 */
316 typedef struct _rknn_custom_string {
317 char string[1024]; /* the string of custom, lengths max to 1024 bytes */
318 } rknn_custom_string;
319
320 /*
321 The flags of rknn_tensor_mem.
322 */
323 typedef enum _rknn_tensor_mem_flags {
324 RKNN_TENSOR_MEMORY_FLAGS_ALLOC_INSIDE = 1, /*Used to mark in rknn_destroy_mem() whether it is necessary to release the "mem" pointer itself.
325 If the flag RKNN_TENSOR_MEMORY_FLAGS_ALLOC_INSIDE is set, rknn_destroy_mem() will call free(mem).*/
326 RKNN_TENSOR_MEMORY_FLAGS_FROM_FD = 2, /*Used to mark in rknn_create_mem_from_fd() whether it is necessary to release the "mem" pointer itself.
327 If the flag RKNN_TENSOR_MEMORY_FLAGS_FROM_FD is set, rknn_destroy_mem() will call free(mem).*/
328 RKNN_TENSOR_MEMORY_FLAGS_FROM_PHYS = 3, /*Used to mark in rknn_create_mem_from_phys() whether it is necessary to release the "mem" pointer itself.
329 If the flag RKNN_TENSOR_MEMORY_FLAGS_FROM_PHYS is set, rknn_destroy_mem() will call free(mem).*/
330 RKNN_TENSOR_MEMORY_FLAGS_UNKNOWN
331 } rknn_tensor_mem_flags;
332
333 /*
334 the memory information of tensor.
335 */
336 typedef struct _rknn_tensor_memory {
337 void* virt_addr; /* the virtual address of tensor buffer. */
338 uint64_t phys_addr; /* the physical address of tensor buffer. */
339 int32_t fd; /* the fd of tensor buffer. */
340 int32_t offset; /* indicates the offset of the memory. */
341 uint32_t size; /* the size of tensor buffer. */
342 uint32_t flags; /* the flags of tensor buffer, reserved */
343 void * priv_data; /* the private data of tensor buffer. */
344 } rknn_tensor_mem;
345
346 /*
347 the input information for rknn_input_set.
348 */
349 typedef struct _rknn_input {
350 uint32_t index; /* the input index. */
351 void* buf; /* the input buf for index. */
352 uint32_t size; /* the size of input buf. */
353 uint8_t pass_through; /* pass through mode.
354 if TRUE, the buf data is passed directly to the input node of the rknn model
355 without any conversion. the following variables do not need to be set.
356 if FALSE, the buf data is converted into an input consistent with the model
357 according to the following type and fmt. so the following variables
358 need to be set.*/
359 rknn_tensor_type type; /* the data type of input buf. */
360 rknn_tensor_format fmt; /* the data format of input buf.
361 currently the internal input format of NPU is NCHW by default.
362 so entering NCHW data can avoid the format conversion in the driver. */
363 } rknn_input;
364
365 /*
366 the output information for rknn_outputs_get.
367 */
368 typedef struct _rknn_output {
369 uint8_t want_float; /* want transfer output data to float */
370 uint8_t is_prealloc; /* whether buf is pre-allocated.
371 if TRUE, the following variables need to be set.
372 if FALSE, the following variables do not need to be set. */
373 uint32_t index; /* the output index. */
374 void* buf; /* the output buf for index.
375 when is_prealloc = FALSE and rknn_outputs_release called,
376 this buf pointer will be free and don't use it anymore. */
377 uint32_t size; /* the size of output buf. */
378 } rknn_output;
379
380 /*
381 the extend information for rknn_init.
382 */
383 typedef struct _rknn_init_extend {
384 rknn_context ctx; /* rknn context */
385 int32_t real_model_offset; /* real rknn model file offset, only valid when init context with rknn file path */
386 uint32_t real_model_size; /* real rknn model file size, only valid when init context with rknn file path */
387 uint8_t reserved[120]; /* reserved */
388 } rknn_init_extend;
389
390 /*
391 the extend information for rknn_run.
392 */
393 typedef struct _rknn_run_extend {
394 uint64_t frame_id; /* output parameter, indicate current frame id of run. */
395 int32_t non_block; /* block flag of run, 0 is block else 1 is non block */
396 int32_t timeout_ms; /* timeout for block mode, in milliseconds */
397 int32_t fence_fd; /* fence fd from other unit */
398 } rknn_run_extend;
399
400 /*
401 the extend information for rknn_outputs_get.
402 */
403 typedef struct _rknn_output_extend {
404 uint64_t frame_id; /* output parameter, indicate the frame id of outputs, corresponds to
405 struct rknn_run_extend.frame_id.*/
406 } rknn_output_extend;
407
408
409 /* rknn_init
410
411 initial the context and load the rknn model.
412
413 input:
414 rknn_context* context the pointer of context handle.
415 void* model if size > 0, pointer to the rknn model, if size = 0, filepath to the rknn model.
416 uint32_t size the size of rknn model.
417 uint32_t flag extend flag, see the define of RKNN_FLAG_XXX_XXX.
418 rknn_init_extend* extend the extend information of init.
419 return:
420 int error code.
421 */
422 int rknn_init(rknn_context* context, void* model, uint32_t size, uint32_t flag, rknn_init_extend* extend);
423
424 /* rknn_dup_context
425
426 initial the context and load the rknn model.
427
428 input:
429 rknn_context* context_in the pointer of context in handle.
430 rknn_context* context_out the pointer of context out handle.
431 return:
432 int error code.
433 */
434 int rknn_dup_context(rknn_context* context_in, rknn_context* context_out);
435
436 /* rknn_destroy
437
438 unload the rknn model and destroy the context.
439
440 input:
441 rknn_context context the handle of context.
442 return:
443 int error code.
444 */
445 int rknn_destroy(rknn_context context);
446
447
448 /* rknn_query
449
450 query the information about model or others. see rknn_query_cmd.
451
452 input:
453 rknn_context context the handle of context.
454 rknn_query_cmd cmd the command of query.
455 void* info the buffer point of information.
456 uint32_t size the size of information.
457 return:
458 int error code.
459 */
460 int rknn_query(rknn_context context, rknn_query_cmd cmd, void* info, uint32_t size);
461
462
463 /* rknn_inputs_set
464
465 set inputs information by input index of rknn model.
466 inputs information see rknn_input.
467
468 input:
469 rknn_context context the handle of context.
470 uint32_t n_inputs the number of inputs.
471 rknn_input inputs[] the arrays of inputs information, see rknn_input.
472 return:
473 int error code
474 */
475 int rknn_inputs_set(rknn_context context, uint32_t n_inputs, rknn_input inputs[]);
476
477 /*
478 rknn_set_batch_core_num
479
480 set rknn batch core_num.
481
482 input:
483 rknn_context context the handle of context.
484 int core_num the core number.
485 return:
486 int error code.
487
488 */
489 int rknn_set_batch_core_num(rknn_context context, int core_num);
490
491 /* rknn_set_core_mask
492
493 set rknn core mask.(only supported on RK3588 now)
494
495 RKNN_NPU_CORE_AUTO: auto mode, default value
496 RKNN_NPU_CORE_0: core 0 mode
497 RKNN_NPU_CORE_1: core 1 mode
498 RKNN_NPU_CORE_2: core 2 mode
499 RKNN_NPU_CORE_0_1: combine core 0/1 mode
500 RKNN_NPU_CORE_0_1_2: combine core 0/1/2 mode
501
502 input:
503 rknn_context context the handle of context.
504 rknn_core_mask core_mask the core mask.
505 return:
506 int error code.
507 */
508 int rknn_set_core_mask(rknn_context context, rknn_core_mask core_mask);
509
510 /* rknn_run
511
512 run the model to execute inference.
513
514 input:
515 rknn_context context the handle of context.
516 rknn_run_extend* extend the extend information of run.
517 return:
518 int error code.
519 */
520 int rknn_run(rknn_context context, rknn_run_extend* extend);
521
522
523 /* rknn_wait
524
525 wait the model after execute inference.
526
527 input:
528 rknn_context context the handle of context.
529 rknn_run_extend* extend the extend information of run.
530 return:
531 int error code.
532 */
533 int rknn_wait(rknn_context context, rknn_run_extend* extend);
534
535
536 /* rknn_outputs_get
537
538 wait the inference to finish and get the outputs.
539 this function will block until inference finish.
540 the results will set to outputs[].
541
542 input:
543 rknn_context context the handle of context.
544 uint32_t n_outputs the number of outputs.
545 rknn_output outputs[] the arrays of output, see rknn_output.
546 rknn_output_extend* the extend information of output.
547 return:
548 int error code.
549 */
550 int rknn_outputs_get(rknn_context context, uint32_t n_outputs, rknn_output outputs[], rknn_output_extend* extend);
551
552
553 /* rknn_outputs_release
554
555 release the outputs that get by rknn_outputs_get.
556 after called, the rknn_output[x].buf get from rknn_outputs_get will
557 also be free when rknn_output[x].is_prealloc = FALSE.
558
559 input:
560 rknn_context context the handle of context.
561 uint32_t n_ouputs the number of outputs.
562 rknn_output outputs[] the arrays of output.
563 return:
564 int error code
565 */
566 int rknn_outputs_release(rknn_context context, uint32_t n_ouputs, rknn_output outputs[]);
567
568
569 /* new api for zero copy */
570
571 /* rknn_create_mem_from_phys (memory allocated outside)
572
573 initialize tensor memory from physical address.
574
575 input:
576 rknn_context ctx the handle of context.
577 uint64_t phys_addr physical address.
578 void *virt_addr virtual address.
579 uint32_t size the size of tensor buffer.
580 return:
581 rknn_tensor_mem the pointer of tensor memory information.
582 */
583 rknn_tensor_mem* rknn_create_mem_from_phys(rknn_context ctx, uint64_t phys_addr, void *virt_addr, uint32_t size);
584
585
586 /* rknn_create_mem_from_fd (memory allocated outside)
587
588 initialize tensor memory from file description.
589
590 input:
591 rknn_context ctx the handle of context.
592 int32_t fd file description.
593 void *virt_addr virtual address.
594 uint32_t size the size of tensor buffer.
595 int32_t offset indicates the offset of the memory (virt_addr without offset).
596 return:
597 rknn_tensor_mem the pointer of tensor memory information.
598 */
599 rknn_tensor_mem* rknn_create_mem_from_fd(rknn_context ctx, int32_t fd, void *virt_addr, uint32_t size, int32_t offset);
600
601
602 /* rknn_create_mem_from_mb_blk (memory allocated outside)
603
604 create tensor memory from mb_blk.
605
606 input:
607 rknn_context ctx the handle of context.
608 void *mb_blk mb_blk allocate from system api.
609 int32_t offset indicates the offset of the memory.
610 return:
611 rknn_tensor_mem the pointer of tensor memory information.
612 */
613 rknn_tensor_mem* rknn_create_mem_from_mb_blk(rknn_context ctx, void *mb_blk, int32_t offset);
614
615
616 /* rknn_create_mem (memory allocated inside)
617
618 create tensor memory.
619
620 input:
621 rknn_context ctx the handle of context.
622 uint32_t size the size of tensor buffer.
623 return:
624 rknn_tensor_mem the pointer of tensor memory information.
625 */
626 rknn_tensor_mem* rknn_create_mem(rknn_context ctx, uint32_t size);
627
628
629 /* rknn_destroy_mem (support allocate inside and outside)
630
631 destroy tensor memory.
632
633 input:
634 rknn_context ctx the handle of context.
635 rknn_tensor_mem *mem the pointer of tensor memory information.
636 return:
637 int error code
638 */
639 int rknn_destroy_mem(rknn_context ctx, rknn_tensor_mem *mem);
640
641
642 /* rknn_set_weight_mem
643
644 set the weight memory.
645
646 input:
647 rknn_context ctx the handle of context.
648 rknn_tensor_mem *mem the array of tensor memory information
649 return:
650 int error code.
651 */
652 int rknn_set_weight_mem(rknn_context ctx, rknn_tensor_mem *mem);
653
654
655 /* rknn_set_internal_mem
656
657 set the internal memory.
658
659 input:
660 rknn_context ctx the handle of context.
661 rknn_tensor_mem *mem the array of tensor memory information
662 return:
663 int error code.
664 */
665 int rknn_set_internal_mem(rknn_context ctx, rknn_tensor_mem *mem);
666
667
668 /* rknn_set_io_mem
669
670 set the input and output tensors buffer.
671
672 input:
673 rknn_context ctx the handle of context.
674 rknn_tensor_mem *mem the array of tensor memory information.
675 rknn_tensor_attr *attr the attribute of input or output tensor buffer.
676 return:
677 int error code.
678 */
679 int rknn_set_io_mem(rknn_context ctx, rknn_tensor_mem *mem, rknn_tensor_attr *attr);
680
681 /* rknn_set_input_shape
682
683 set the input tensor shape (only valid for dynamic shape rknn model).
684
685 input:
686 rknn_context ctx the handle of context.
687 rknn_tensor_attr *attr the attribute of input or output tensor buffer.
688 return:
689 int error code.
690 */
691 int rknn_set_input_shape(rknn_context ctx, rknn_tensor_attr* attr);
692
693 #ifdef __cplusplus
694 } //extern "C"
695 #endif
696
697 #endif //_RKNN_API_H
698