/******************************************************************************* * nnctrl.h * * History: * 2018/08/22 - [Tao Wu] created for CV22 * * Copyright (c) 2018 Ambarella, Inc. * * This file and its contents ( "Software" ) are protected by intellectual * property rights including, without limitation, U.S. and/or foreign * copyrights. This Software is also the confidential and proprietary * information of Ambarella, Inc. and its licensors. You may not use, reproduce, * disclose, distribute, modify, or otherwise iproare derivative works of this * Software or any portion thereof except pursuant to a signed license agreement * or nondisclosure agreement with Ambarella, Inc. or its authorized affiliates. * In the absence of such an agreement, you agree to promptly notify and return * this Software to Ambarella, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, * MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL AMBARELLA, INC. OR ITS AFFILIATES BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; COMPUTER FAILURE OR MALFUNCTION; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************/ #ifndef _NNCTL_H_ #define _NNCTL_H_ #ifdef __cplusplus extern "C" { #endif #include #include #ifndef IN #define IN #endif #ifndef OUT #define OUT #endif #ifndef INOUT #define INOUT #endif struct nnctrl_version { uint32_t major; uint32_t minor; uint32_t patch; uint32_t cavalry_parser; unsigned int mod_time; char description[64]; }; struct net_cfg { IN const char *net_file; /* filename of NET.bin generated by cavalry_gen */ IN const uint8_t *net_feed_virt; /* virtual memory of NET.bin */ IN uint32_t verbose : 1; IN uint32_t reuse_mem : 1; IN uint32_t print_time : 1; uint32_t reserved_0 : 29; IN uint32_t net_loop_cnt; /* Load dvi once and run dvi multi-times (N). * It will save (N-1) dvi loading time. * blob_mem_total (IN, ..., OUT) will multiple (N) times */ OUT uint32_t net_mem_total; /* every dvi and blob 32 aligned */ OUT uint32_t dvi_mem_total; /* non 32 aligned */ OUT uint32_t blob_mem_total; /* non 32 aligned */ OUT uint32_t bandwidth_total; /* non 32 aligned */ }; struct net_mem { uint8_t *virt_addr; /* The virtual address mmap by app for network */ uint32_t phy_addr; /* The absolute physical address */ uint32_t mem_size; /* The memory size assigned by app */ }; struct io_dim { uint32_t plane; uint32_t depth; uint32_t height; uint32_t width; uint32_t pitch; /* Alignment of width */ uint32_t pitch_byte_offset; /* define as *_dpitchm1_byte_offset in .h */ uint32_t pitch_bsize : 6; /* define as *_dpitchm1_bsize in .h */ uint32_t bitvector : 1; /* 0: false; 1: true */ uint32_t reserved_0 : 1; uint32_t dram_fmt : 8; /* Internal use */ uint32_t reserved_1 : 16; }; struct io_data_fmt { uint8_t sign; uint8_t size; int8_t expoffset; uint8_t expbits; }; enum ROTATE_FILP_BITMAP { DROTATE_BIT = 0, HFLIP_BIT = 1, VFLIP_BIT = 2, DFLIP_BIT = 3, PFLIP_BIT = 4, ROTATE_FLIP_BIT_NUM, }; struct input_desc { IN const char *name; /* Set by APP */ INOUT uint8_t *virt; /* return absolute virtual address if no_mem is 0 */ INOUT uint32_t addr; /* Set by APP if set no_mem, otherwise get from Library; * absolute physical address */ INOUT uint32_t size; /* Set by APP if set no_mem, otherwise get from Library */ IN uint32_t no_mem : 1; /* Not allocate memory for input port by this lib, * since it may from yuv addr in live mode */ IN uint32_t rotate_flip_bitmap : 5; /* Bitmap for 5 field, order (High -> Low): * 4: pflip; 3: dflip; 2: vflip; 1: hflip; 0: rotate. */ uint32_t reserved_0 : 2; uint32_t reserved_1 : 8; IN uint32_t update_pitch : 16; /* Run time change the pitch of input. * Do not minus one on real pitch, library will minus one internal */ OUT struct io_dim dim; OUT struct io_data_fmt data_fmt; }; struct output_desc { IN const char *name; /* Set by APP */ INOUT uint8_t *virt; /* return absolute virtual address if no_mem is 0 */ INOUT uint32_t addr; /* Set by APP if set no_mem, otherwise get from Library; * absolute physical address */ OUT uint32_t size; /* Get from Library */ IN uint32_t no_mem : 1; /* Not allocate memory for output port by this lib */ IN uint32_t rotate_flip_bitmap : 5; /* Bitmap for 5 field, order (High -> Low): * 4: pflip; 3: dflip; 2: vflip; 1: hflip; 0: rotate. */ uint32_t reserved_0 : 26; OUT struct io_dim dim; OUT struct io_data_fmt data_fmt; }; /* Neural Network's external input and output*/ #define MAX_IO_NUM (16) struct net_input_cfg { IN uint32_t in_num; struct input_desc in_desc[MAX_IO_NUM]; }; struct net_output_cfg { IN uint32_t out_num; struct output_desc out_desc[MAX_IO_NUM]; }; struct net_dvi_cfg { uint8_t *virt; /* absolute virtual address */ uint32_t addr; /* absolute physical address */ dvi_desc_t dvi_desc; }; struct net_run_cfg { uint32_t net_loop_cnt; //1 uint32_t single_dag_run : 1; //1 /* For debug every dag execute time, * should disable in real case */ uint32_t reserved_0 : 31;//26//29//31 }; struct net_result { float vp_time_us; }; #ifndef AMBA_API #define AMBA_API __attribute__((visibility("default"))) #endif /* Neural Network Control Library API */ AMBA_API int nnctrl_init(IN int fd_cav, IN uint8_t verbose); AMBA_API int nnctrl_get_version(struct nnctrl_version *ver); AMBA_API int nnctrl_suspend_net(uint8_t quit_all); AMBA_API void nnctrl_exit(void); /* Nerual Network API */ AMBA_API int nnctrl_init_net(INOUT struct net_cfg *net_cf, INOUT struct net_input_cfg *net_in, INOUT struct net_output_cfg *net_out); AMBA_API int nnctrl_load_net(IN int net_id, IN struct net_mem *net_m, INOUT struct net_input_cfg *net_in, INOUT struct net_output_cfg *net_out); AMBA_API int nnctrl_get_net_io_cfg(IN int net_id, OUT struct net_input_cfg *net_in, OUT struct net_output_cfg *net_out); AMBA_API int nnctrl_set_net_io_cfg(IN int net_id, IN struct net_input_cfg *net_in, IN struct net_output_cfg *net_out); AMBA_API int nnctrl_query_dvi(IN int net_id, IN uint32_t dvi_id, OUT struct net_dvi_cfg *net_dvi); /* nnctrl_run_net * * The function returns 0 if ok, * -EINTR if it was interrupted by a signal, * -EAGAIN if after call nnctrl_suspend_net. */ AMBA_API int nnctrl_run_net(IN int net_id, OUT struct net_result *net_ret, IN struct net_run_cfg *net_rev, IN struct net_input_cfg *net_in, IN struct net_output_cfg *net_out); /* nnctrl_resume_net * * The function returns 0 if ok, * -EINTR if it was interrupted by a signal, * -EAGAIN if after call nnctrl_suspend_net. */ AMBA_API int nnctrl_resume_net(IN int net_id, OUT struct net_result *net_ret); AMBA_API int nnctrl_exit_net(IN int net_id); /* Dump Neural Network dvi, dump blob if reuse_mem equal zero */ AMBA_API int nnctrl_dump_net(IN int net_id, IN const char *path); #ifdef __cplusplus } #endif #endif