c_cpp 海思运行时API学习记录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 海思运行时API学习记录相关的知识,希望对你有一定的参考价值。
//参考sample_runtime_group_rfcnalex.c
/*PhyAddr和VirAddr关系*/
VirAddr = (HI_U8*) HI_MPI_SYS_Mmap(PhyAddr, u32Size);//将物理地址映射到虚拟地址
//设置开辟空间,为Forward提供输入输出空间HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S
//参考sample_runtime_group_rfcnalex.c
//设置开辟空间,为Forward提供输入输出空间HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S
//HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_PTR为HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S的引用&
HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S stGroupSrc;
HI_RUNTIME_GROUP_BLOB_S astGroupInputBlobs[1];
HI_RUNTIME_BLOB_S astInputBlobs[2];
//1.三个结构体之间的关系:
/*从上往下为包含关系,HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S包含HI_RUNTIME_GROUP_BLOB_S
,HI_RUNTIME_GROUP_BLOB_S又包含HI_RUNTIME_BLOB_S。*/
//2.使用方法如下:
memset(&astGroupInputBlobs[0], 0, sizeof(astGroupInputBlobs));
//将HI_RUNTIME_GROUP_BLOB_S指针赋给HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S
stGroupSrc.u32BlobNum=1;
stGroupSrc.pstBlobs = &astGroupInputBlobs[0];
//将HI_RUNTIME_BLOB_S指针赋给
//HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S的第一个元素下的“HI_RUNTIME_GROUP_BLOB_S”
strncpy(stGroupSrc.pstBlobs[0].acOwnerName, "", MAX_NAME_LEN);
strncpy(stGroupSrc.pstBlobs[0].acBlobName, "data", MAX_NAME_LEN);
stGroupSrc.pstBlobs[0].pstBlob = &astInputBlobs[0];
//HI_RUNTIME_BLOB_S设为0
memset(astInputBlobs, 0x0, sizeof(astInputBlobs));
//给HI_RUNTIME_BLOB_S开辟空间
s32Ret = SAMPLE_RUNTIME_SetBlob(&pstInputBlobs[0], HI_RUNTIME_BLOB_TYPE_U8, 1, 800, 600, 3, ALIGN_16);
SAMPLE_CHK_RETURN(HI_SUCCESS != s32Ret, s32Ret, "SAMPLE_RUNTIME_SetBlob faster rcnn failed!\n");
//给最里层的HI_RUNTIME_BLOB_S赋值
s32Ret = SAMPLE_RUNTIME_ReadSrcFile(pcSrcFile, &(pstInputBlobs[0]));
SAMPLE_CHK_RETURN(HI_SUCCESS != s32Ret, s32Ret, "ReadSrcFile failed!\n");
//最后推理
s32Ret = HI_SVPRT_RUNTIME_ForwardGroupASync(hGroupHandle, &stGroupSrc, &stGroupDst, 0, rfcn_alexnet_forward_finish);
HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S stGroupSrc;
HI_RUNTIME_GROUP_BLOB_S astGroupInputBlobs[1];
HI_RUNTIME_BLOB_S astInputBlobs[2];
//1.三个结构体之间的关系:
/*从上往下为包含关系,HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S包含HI_RUNTIME_GROUP_BLOB_S
,HI_RUNTIME_GROUP_BLOB_S又包含HI_RUNTIME_BLOB_S。*/
//2.使用方法如下:
memset(&astGroupInputBlobs[0], 0, sizeof(astGroupInputBlobs));
//将HI_RUNTIME_GROUP_BLOB_S指针赋给HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S
stGroupSrc.u32BlobNum=1;
stGroupSrc.pstBlobs = &astGroupInputBlobs[0];
//将HI_RUNTIME_BLOB_S指针赋给
//HI_RUNTIME_GROUP_SRC_BLOB_ARRAY_S的第一个元素下的“HI_RUNTIME_GROUP_BLOB_S”
strncpy(stGroupSrc.pstBlobs[0].acOwnerName, "", MAX_NAME_LEN);
strncpy(stGroupSrc.pstBlobs[0].acBlobName, "data", MAX_NAME_LEN);
stGroupSrc.pstBlobs[0].pstBlob = &astInputBlobs[0];
//HI_RUNTIME_BLOB_S设为0
memset(astInputBlobs, 0x0, sizeof(astInputBlobs));
//给HI_RUNTIME_BLOB_S开辟空间
s32Ret = SAMPLE_RUNTIME_SetBlob(&pstInputBlobs[0], HI_RUNTIME_BLOB_TYPE_U8, 1, 800, 600, 3, ALIGN_16);
SAMPLE_CHK_RETURN(HI_SUCCESS != s32Ret, s32Ret, "SAMPLE_RUNTIME_SetBlob faster rcnn failed!\n");
//给最里层的HI_RUNTIME_BLOB_S赋值
s32Ret = SAMPLE_RUNTIME_ReadSrcFile(pcSrcFile, &(pstInputBlobs[0]));
SAMPLE_CHK_RETURN(HI_SUCCESS != s32Ret, s32Ret, "ReadSrcFile failed!\n");
//最后推理
s32Ret = HI_SVPRT_RUNTIME_ForwardGroupASync(hGroupHandle, &stGroupSrc, &stGroupDst, 0, rfcn_alexnet_forward_finish);
//加载模型流程 //涉及的变量
HI_**_Param_S copParam[1];//自定义层参数结构体
static HI_RUNTIME_GROUP_INFO_S s_stGroupInfo;//模型组信息结构体,Load时用到
HI_RUNTIME_GROUP_HANDLE hGroupHandle;//句柄
HI_RUNTIME_WK_INFO_S astWkInfo[2];//wk模型信息,有几个模型就有多少元素
HI_RUNTIME_COP_ATTR_S stProposalAttr = {}; //custom operator自定义操作的属性
HI_RUNTIME_CONNECTOR_ATTR_S stConnectorAttr = {0};//连接器的属性
HI_CHAR acConfig[1024] = {0};//modelgroup文件读入的数组
memset(&stProposalAttr, 0, sizeof(HI_RUNTIME_COP_ATTR_S));
memset(&stConnectorAttr, 0, sizeof(HI_RUNTIME_CONNECTOR_ATTR_S));
memset(acConfig, 0, sizeof(acConfig));
//初始化RUNTIME系统
HI_SVPRT_RUNTIME_Init("log_level:VERBOSE cpu_task_affinity:2 cpu_task_affinity:3", NULL);
//加载模型wk,有多少加载多少,对应修改数组下标
strncpy(pstWkInfo[0].acModelName, "rfcn", MAX_NAME_LEN);
s32Ret = SAMPLE_RUNTIME_LoadModelFile(pcModelFileRFCN, &pstWkInfo[0].stWKMemory);
//自定义层参数
strncpy(stProposalAttr.acModelName, "rfcn", MAX_NAME_LEN);//所述模型名称
strncpy(stProposalAttr.acCopName, "proposal", MAX_NAME_LEN);//自定义层名称
stProposalAttr.u32ConstParamSize = sizeof(HI_PROPOSAL_Param_S);//自定义层参数size
s32Ret = createRFCNCopParam(1, &stProposalAttr, pProposalParam);//为stProposalAttr赋值
//连接器属性配置
strncpy(stConnectorAttr.acName, "rfcn_conn_alexnet", MAX_NAME_LEN);
stConnectorAttr.pParam = &s_u32RoiNum;
stConnectorAttr.pConnectorFun = Connector_RFCNToAlexNet;
/********************/
//模型组信息结构体配置
//数量和各自的属性,或者回调函数
s_stGroupInfo.stWKsInfo.u32WKNum = 2;//模型数量
s_stGroupInfo.stWKsInfo.pstAttrs = &pstWkInfo[0];
s_stGroupInfo.stCopsAttr.u32CopNum = 1;//自定义层数量
s_stGroupInfo.stCopsAttr.pstAttrs = &stProposalAttr;
s_stGroupInfo.stConnectorsAttr.u32ConnectorNum = 1;//连接器数量
s_stGroupInfo.stConnectorsAttr.pstAttrs = &stConnectorAttr;
//加载模型组
//入参:modelgroup文件,模型组信息结构体
//出参:句柄hGroupHandle
HI_SVPRT_RUNTIME_LoadModelGroup)(acConfig,&s_stGroupInfo,&hGroupHandle);
以上是关于c_cpp 海思运行时API学习记录的主要内容,如果未能解决你的问题,请参考以下文章