/* Copyright (c), 2001-2022, Shenshu Tech. Co., Ltd. */ #ifndef OT_RUNTIME_COMM_H #define OT_RUNTIME_COMM_H #include "ot_type.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif /* __cplusplus */ #define MAX_NAME_LEN 64 /* Model max name */ #define FULL_NAME_LEN 130 typedef td_void* OtMwPtr; /* Handle define for model and tasks */ #ifndef IN #define IN #endif #ifndef OUT #define OUT #endif #ifndef INOUT #define INOUT #endif /* Blob type */ typedef enum { OT_RUNTIME_BLOB_TYPE_S20Q12 = 0x0, OT_RUNTIME_BLOB_TYPE_U8 = 0x1, OT_RUNTIME_BLOB_TYPE_YVU420SP = 0x2, OT_RUNTIME_BLOB_TYPE_YVU422SP = 0x3, OT_RUNTIME_BLOB_TYPE_VEC_S20Q12 = 0x4, OT_RUNTIME_BLOB_TYPE_SEQ_S20Q12 = 0x5, OT_RUNTIME_BLOB_TYPE_BBOX_S20Q12 = 0x6, OT_RUNTIME_BLOB_TYPE_BSI_SQ32 = 0x7, OT_RUNTIME_BLOB_TYPE_S12Q20 = 0x8, OT_RUNTIME_BLOB_TYPE_VEC_S12Q20 = 0x9, OT_RUNTIME_BLOB_TYPE_S32 = 0xa, OT_RUNTIME_BLOB_TYPE_U32 = 0xb, // not support OT_RUNTIME_BLOB_TYPE_FP32 = 0xc, // not support OT_RUNTIME_BLOB_TYPE_FP16 = 0xd, // not support OT_RUNTIME_BLOB_TYPE_U16 = 0xe, OT_RUNTIME_BLOB_TYPE_BUTT } OT_RTBlobType; typedef enum { OT_RUNTIME_GROUP_PRIORITY_HIGHEST = 0x0, OT_RUNTIME_GROUP_PRIORITY_HIGH, OT_RUNTIME_GROUP_PRIORITY_MEDIUM, OT_RUNTIME_GROUP_PRIORITY_LOW, OT_RUNTIME_GROUP_PRIORITY_LOWEST, OT_RUNTIME_GROUP_PRIORITY_BUTT } OT_RTGroupPriority; /****************************** Blob struct ****************************** In Caffe, the blob contain shape info as the following order: Image\FeatureMap: N C H W RNN\LSTM(Recurrent) vector: T N D The relationship of the following blob struct with Caffe blob is as follows: Image\FeatureMap: Num Chn Height With RNN\LSTM(SEQ_S32) vector: Step Num Dim The stride, which measuring unit is byte, is always algined by the width or dim direction. **************************************************************************/ typedef struct { OT_RTBlobType blobType; /* Blob type */ td_u32 stride; /* Stride, a line bytes num */ td_u64 virtAddr; /* virtual addr */ td_u64 physAddr; /* physical addr */ td_u32 num; /* N: frame num or sequence num, correspond to caffe blob's n */ union { struct { td_u32 width; /* W: frame width, correspond to caffe blob's w */ td_u32 height; /* H: frame height, correspond to caffe blob's h */ td_u32 chn; /* C: frame channel, correspond to caffe blob's c */ } whc; /* AUTO: OT_RTBlobType: other; */ struct { td_u32 dim; /* D: vecotr dimension */ td_u64 virtAddrStep; /* T: virtual adress of time steps array in each sequence */ } seq; /* AUTO: OT_RTBlobType: OT_RUNTIME_BLOB_TYPE_SEQ_S20Q12; */ } shape; } OT_RTBlob, *OT_RTBlobPtr; typedef struct { td_u32 blobNum; OT_RTBlob *blobs; } OT_RTBlobArray, *OT_RTBlobArrayPtr; typedef OT_RTBlobArray OT_RTSrcBlobArray; typedef OT_RTBlobArray OT_RTDstBlobArray; typedef OT_RTBlobArrayPtr OT_RTSrcBlobArrayPtr; typedef OT_RTBlobArrayPtr OT_RTDstBlobArrayPtr; typedef struct { OT_RTBlobPtr blob; td_char ownerName[MAX_NAME_LEN + 1]; td_char blobName[MAX_NAME_LEN + 1]; } OT_RTGroupBlob, *OT_RTGroupBlobPtr; typedef OT_RTGroupBlob OT_RTGroupSrcBlob; typedef OT_RTGroupBlob OT_RTGroupDstBlob; /* Mem information */ typedef struct { td_u64 physAddr; /* RW;The physical address of the memory */ td_u64 virtAddr; /* RW;The virtual address of the memory */ td_u32 size; /* RW;The size of memory */ } OT_RTMem, *OT_RTMemPtr; typedef td_s32 (*OT_RTAllocMem)(INOUT OT_RTMem *memInfo); typedef td_s32 (*OT_RTFlushCache)(OT_RTMem *memInfo); typedef td_s32 (*OT_RTFreeMem)(OT_RTMem *memInfo); typedef struct { OT_RTAllocMem allocMem; OT_RTFlushCache flushMem; OT_RTFreeMem freeMem; } OT_RTMemCtrl; typedef struct { td_s32 xLeft; td_s32 yLeft; td_s32 xRight; td_s32 yRight; } OT_RTPriorboxCoord; typedef struct { OT_RTPriorboxCoord priorBox; OT_RTPriorboxCoord var; } OT_RTPriorBoxInfo, *OT_RTPriorBoxInfoPtr; typedef struct { td_u32 priorBoxNum; td_u32 varNum; } OT_RTPriorBoxNum, *OT_RTPriorBoxNumPtr; typedef td_s32(*OT_RTGenerateBaseAnchorCallback)(OT_RTPriorBoxNum priorBoxNumAddr[], td_u32 priorBoxNum, OT_RTPriorBoxInfo priorBoxInfo[], td_u32 *priorBoxBlobNum); typedef struct { td_u32 minWidth; /* min width */ td_u32 minHeight; /* min height */ td_u32 nmsThreshold; /* nms thresh */ td_u32 scoreThreshold; /* score thresh */ } OT_RTThreshold; typedef struct { td_char modelName[MAX_NAME_LEN + 1]; OT_RTMem wkMemory; OT_RTThreshold proposalThreshold; OT_RTGenerateBaseAnchorCallback generateBaseAnchorCallback; } OT_RTWkInfo; typedef struct { td_u32 wkNum; OT_RTWkInfo *attrs; } OT_RTWkInfoArray, *OT_RTWkInfoArrayPtr; typedef struct { td_char modelName[MAX_NAME_LEN + 1]; td_char copName[MAX_NAME_LEN + 1]; td_u32 constParamSize; td_void *constParam; } OT_RTCopAttr, *OT_RTCopAttrPtr; typedef struct { td_u32 copNum; OT_RTCopAttr *attrs; } OT_RTCopAttrArray, *OT_RTCopAttrArrayPtr; /* Forward callback event */ typedef enum { OT_RUNTIME_FORWARD_STATUS_SUCC = 0x0, OT_RUNTIME_FORWARD_STATUS_FAIL, OT_RUNTIME_FORWARD_STATUS_ABORT, OT_RUNTIME_FORWARD_STATUS_BUTT } OT_RTForwardStatusCallback; typedef td_s32 (*OT_RTConnectorCompute)(OT_RTSrcBlobArray* connectorSrc, OT_RTDstBlobArray* connectorDst, td_u64 srcId, td_void* param); typedef struct { td_char name[MAX_NAME_LEN + 1]; OT_RTConnectorCompute connectorFunc; td_void *param; } OT_RTConnectorAttr; typedef struct { td_u32 connectorNum; OT_RTConnectorAttr *attrs; } OT_RTConnectorAttrArray, *OT_RTConnectorAttrArrayPtr; typedef struct { OT_RTWkInfoArray wksInfo; OT_RTCopAttrArray copsAttr; OT_RTConnectorAttrArray connectorsAttr; } OT_RTGroupInfo, *OT_RTGroupInfoPtr; /* handle info after LoadModelGroup */ typedef td_void* OT_RTGroupHandle; /* the src blobs of group, all model inputs are inside */ typedef struct { td_u32 blobNum; OT_RTGroupBlob* blobs; } OT_RTGroupBlobArray, *OT_RTGroupBlobArrayPtr; typedef OT_RTGroupBlobArray OT_RTGroupSrcBlobArray; typedef OT_RTGroupBlobArray OT_RTGroupDstBlobArray; typedef OT_RTGroupBlobArray* OT_RTGroupSrcBlobArrayPtr; typedef OT_RTGroupBlobArray* OT_RTGroupDstBlobArrayPtr; /** \brief forward result calback function. \attention none. \param[out] enEvent: Result message of forward. \param[out] pstGroup: Group Handle \param[out] u64SrcId: Frame ID \param[out] pstDst: Result blob \see \n none. */ typedef td_s32 (*OT_RTForwardCallback)(OT_RTForwardStatusCallback event, OT_RTGroupHandle groupHandle, td_u64 srcId, OT_RTGroupDstBlobArrayPtr dst); // errno message enum { OT_ERR_SVP_RUNTIME_BASE = (td_s32)(0xFF000F00), OT_ERR_SVP_RUNTIME_ILLEGAL_STATE, OT_ERR_SVP_RUNTIME_MODEL_NOLOAD, OT_ERR_SVP_RUNTIME_NULL_PTR, OT_ERR_SVP_RUNTIME_INVALID_PARAM, OT_ERR_SVP_RUNTIME_SDK_ERROR, OT_ERR_SVP_RUNTIME_SDK_NOMEM, }; #ifndef ot_unused #define ot_unused(x) ((td_void)(x)) #endif #ifdef __cplusplus #if __cplusplus } #endif #endif /* __cplusplus */ #endif /* OT_RUNTIME_COMM_H */