Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
5f1ded73
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
大约 1 年 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5f1ded73
编写于
5月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8647 新增2个NNRTDeviceInfo相关用例,删除不支持的uint8特性用例
Merge pull request !8647 from zhuguodong/master
上级
1dbf9a3d
cbb8daa4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
99 addition
and
46 deletion
+99
-46
ai/mindspore/src/ohos_c_api_test_mslite.cpp
ai/mindspore/src/ohos_c_api_test_mslite.cpp
+99
-46
未找到文件。
ai/mindspore/src/ohos_c_api_test_mslite.cpp
浏览文件 @
5f1ded73
...
...
@@ -62,30 +62,84 @@ void AddContextDeviceCPU(OH_AI_ContextHandle context) {
// add nnrt device info
void
AddContextDeviceNNRT
(
OH_AI_ContextHandle
context
)
{
size_t
num
=
0
;
auto
desc
=
OH_AI_NNRTGetAllDeviceDescs
(
&
num
);
if
(
desc
==
nullptr
)
{
return
;
}
std
::
cout
<<
"found "
<<
num
<<
" nnrt devices"
<<
std
::
endl
;
auto
id
=
OH_AI_NNRTDeviceDescGetId
(
desc
);
auto
name
=
OH_AI_NNRTDeviceDescGetName
(
desc
);
auto
type
=
OH_AI_NNRTDeviceDescGetType
(
desc
);
std
::
cout
<<
"NNRT device: id = "
<<
id
<<
", name: "
<<
name
<<
", type:"
<<
type
<<
std
::
endl
;
OH_AI_DeviceInfoHandle
nnrt_device_info
=
OH_AI_DeviceInfoCreate
(
OH_AI_DEVICETYPE_NNRT
);
ASSERT_NE
(
nnrt_device_info
,
nullptr
);
OH_AI_DeviceInfoSetDeviceId
(
nnrt_device_info
,
id
);
OH_AI_NNRTDestroyAllDeviceDescs
(
&
desc
);
OH_AI_DeviceType
device_type
=
OH_AI_DeviceInfoGetDeviceType
(
nnrt_device_info
);
printf
(
"==========device_type:%d
\n
"
,
device_type
);
ASSERT_EQ
(
device_type
,
OH_AI_DEVICETYPE_NNRT
);
OH_AI_DeviceInfoSetPerformanceMode
(
nnrt_device_info
,
OH_AI_PERFORMANCE_MEDIUM
);
ASSERT_EQ
(
OH_AI_DeviceInfoGetPerformanceMode
(
nnrt_device_info
),
OH_AI_PERFORMANCE_MEDIUM
);
OH_AI_DeviceInfoSetPriority
(
nnrt_device_info
,
OH_AI_PRIORITY_MEDIUM
);
ASSERT_EQ
(
OH_AI_DeviceInfoGetPriority
(
nnrt_device_info
),
OH_AI_PRIORITY_MEDIUM
);
OH_AI_ContextAddDeviceInfo
(
context
,
nnrt_device_info
);
}
// add nnrt device info by type
void
AddContextDeviceNNRTByType
(
OH_AI_ContextHandle
context
)
{
size_t
num
=
0
;
auto
desc
=
OH_AI_NNRTGetAllDeviceDescs
(
&
num
);
if
(
desc
==
nullptr
)
{
return
;
}
std
::
cout
<<
"found "
<<
num
<<
" nnrt devices"
<<
std
::
endl
;
for
(
size_t
i
=
0
;
i
<
num
;
i
++
)
{
std
::
cout
<<
"nnrt device "
<<
i
<<
": {device_id: "
<<
desc
[
i
].
device_id
<<
", type:"
<<
desc
[
i
].
device_type
<<
", name:"
<<
desc
[
i
].
device_name
<<
std
::
endl
;
}
auto
id
=
OH_AI_NNRTDeviceDescGetId
(
desc
);
auto
name
=
OH_AI_NNRTDeviceDescGetName
(
desc
);
auto
type
=
OH_AI_NNRTDeviceDescGetType
(
desc
);
std
::
cout
<<
"NNRT device: id = "
<<
id
<<
", name: "
<<
name
<<
", type:"
<<
type
<<
std
::
endl
;
OH_AI_DeviceInfoSetDeviceId
(
nnrt_device_info
,
desc
[
0
].
device_id
);
auto
nnrt_device_info
=
OH_AI_CreateNNRTDeviceInfoByType
(
type
);
OH_AI_NNRTDestroyAllDeviceDescs
(
&
desc
);
ASSERT_NE
(
nnrt_device_info
,
nullptr
);
OH_AI_DeviceType
device_type
=
OH_AI_DeviceInfoGetDeviceType
(
nnrt_device_info
);
printf
(
"==========device_type:%d
\n
"
,
device_type
);
ASSERT_EQ
(
device_type
,
OH_AI_DEVICETYPE_NNRT
);
ASSERT_EQ
(
OH_AI_DeviceInfoGetDeviceId
(
nnrt_device_info
),
id
);
OH_AI_ContextAddDeviceInfo
(
context
,
nnrt_device_info
);
}
// add nnrt device info by name
void
AddContextDeviceNNRTByName
(
OH_AI_ContextHandle
context
)
{
size_t
num
=
0
;
auto
desc
=
OH_AI_NNRTGetAllDeviceDescs
(
&
num
);
if
(
desc
==
nullptr
)
{
return
;
}
std
::
cout
<<
"found "
<<
num
<<
" nnrt devices"
<<
std
::
endl
;
auto
id
=
OH_AI_NNRTDeviceDescGetId
(
desc
);
auto
name
=
OH_AI_NNRTDeviceDescGetName
(
desc
);
auto
type
=
OH_AI_NNRTDeviceDescGetType
(
desc
);
std
::
cout
<<
"NNRT device: id = "
<<
id
<<
", name: "
<<
name
<<
", type:"
<<
type
<<
std
::
endl
;
auto
nnrt_device_info
=
OH_AI_CreateNNRTDeviceInfoByName
(
name
);
OH_AI_NNRTDestroyAllDeviceDescs
(
&
desc
);
ASSERT_NE
(
nnrt_device_info
,
nullptr
);
OH_AI_DeviceType
device_type
=
OH_AI_DeviceInfoGetDeviceType
(
nnrt_device_info
);
printf
(
"==========device_type:%d
\n
"
,
device_type
);
ASSERT_EQ
(
device_type
,
OH_AI_DEVICETYPE_NNRT
);
ASSERT_EQ
(
OH_AI_DeviceInfoGetDeviceId
(
nnrt_device_info
),
id
);
OH_AI_ContextAddDeviceInfo
(
context
,
nnrt_device_info
);
}
// fill data to inputs tensor
void
FillInputsData
(
OH_AI_TensorHandleArray
inputs
,
string
model_name
,
bool
is_transpose
)
{
...
...
@@ -1559,7 +1613,7 @@ HWTEST(MSLiteTest, OHOS_Compatible_0001, Function | MediumTest | Level1) {
OH_AI_ModelDestroy
(
&
model
);
}
// delegate异构
// delegate异构
:选取第一个NNRT设备
HWTEST
(
MSLiteTest
,
OHOS_NNRT_0001
,
Function
|
MediumTest
|
Level1
)
{
printf
(
"==========Init Context==========
\n
"
);
OH_AI_ContextHandle
context
=
OH_AI_ContextCreate
();
...
...
@@ -1586,41 +1640,62 @@ HWTEST(MSLiteTest, OHOS_NNRT_0001, Function | MediumTest | Level1) {
OH_AI_ModelDestroy
(
&
model
);
}
// delegate异构:
多输入单输出
// delegate异构:
根据类型确定NNRT设备
HWTEST
(
MSLiteTest
,
OHOS_NNRT_0002
,
Function
|
MediumTest
|
Level1
)
{
printf
(
"==========Init Context==========
\n
"
);
OH_AI_ContextHandle
context
=
OH_AI_ContextCreate
();
ASSERT_NE
(
context
,
nullptr
);
AddContextDeviceNNRT
(
context
);
AddContextDeviceNNRT
ByType
(
context
);
AddContextDeviceCPU
(
context
);
printf
(
"==========Create model==========
\n
"
);
OH_AI_ModelHandle
model
=
OH_AI_ModelCreate
();
ASSERT_NE
(
model
,
nullptr
);
printf
(
"==========Build model==========
\n
"
);
OH_AI_Status
ret
=
OH_AI_ModelBuildFromFile
(
model
,
"/data/test/ml_
headpose_pb2tflit
e.ms"
,
OH_AI_Status
ret
=
OH_AI_ModelBuildFromFile
(
model
,
"/data/test/ml_
face_isfac
e.ms"
,
OH_AI_MODELTYPE_MINDIR
,
context
);
printf
(
"==========build model return code:%d
\n
"
,
ret
);
ASSERT_EQ
(
ret
,
OH_AI_STATUS_SUCCESS
);
printf
(
"==========GetInputs==========
\n
"
);
OH_AI_TensorHandleArray
inputs
=
OH_AI_ModelGetInputs
(
model
);
ASSERT_NE
(
inputs
.
handle_list
,
nullptr
);
FillInputsData
(
inputs
,
"ml_
headpose_pb2tflite"
,
fals
e
);
FillInputsData
(
inputs
,
"ml_
face_isface"
,
tru
e
);
printf
(
"==========Model Predict==========
\n
"
);
OH_AI_TensorHandleArray
outputs
;
ret
=
OH_AI_ModelPredict
(
model
,
inputs
,
&
outputs
,
nullptr
,
nullptr
);
ASSERT_EQ
(
ret
,
OH_AI_STATUS_SUCCESS
);
CompareResult
(
outputs
,
"ml_
headpose_pb2tflite"
,
0.02
,
0.02
);
CompareResult
(
outputs
,
"ml_
face_isface"
);
OH_AI_ModelDestroy
(
&
model
);
}
//
delegate异构:输入为uint8模型
//
delegate异构:根据名称确定NNRT设备
HWTEST
(
MSLiteTest
,
OHOS_NNRT_0003
,
Function
|
MediumTest
|
Level1
)
{
printf
(
"==========ReadFile==========
\n
"
);
size_t
size1
;
size_t
*
ptr_size1
=
&
size1
;
const
char
*
imagePath
=
"/data/test/aiy_vision_classifier_plants_V1_3.input"
;
char
*
imageBuf
=
ReadFile
(
imagePath
,
ptr_size1
);
ASSERT_NE
(
imageBuf
,
nullptr
);
printf
(
"==========Init Context==========
\n
"
);
OH_AI_ContextHandle
context
=
OH_AI_ContextCreate
();
ASSERT_NE
(
context
,
nullptr
);
AddContextDeviceNNRTByName
(
context
);
AddContextDeviceCPU
(
context
);
printf
(
"==========Create model==========
\n
"
);
OH_AI_ModelHandle
model
=
OH_AI_ModelCreate
();
ASSERT_NE
(
model
,
nullptr
);
printf
(
"==========Build model==========
\n
"
);
OH_AI_Status
ret
=
OH_AI_ModelBuildFromFile
(
model
,
"/data/test/ml_face_isface.ms"
,
OH_AI_MODELTYPE_MINDIR
,
context
);
printf
(
"==========build model return code:%d
\n
"
,
ret
);
ASSERT_EQ
(
ret
,
OH_AI_STATUS_SUCCESS
);
printf
(
"==========GetInputs==========
\n
"
);
OH_AI_TensorHandleArray
inputs
=
OH_AI_ModelGetInputs
(
model
);
ASSERT_NE
(
inputs
.
handle_list
,
nullptr
);
FillInputsData
(
inputs
,
"ml_face_isface"
,
true
);
printf
(
"==========Model Predict==========
\n
"
);
OH_AI_TensorHandleArray
outputs
;
ret
=
OH_AI_ModelPredict
(
model
,
inputs
,
&
outputs
,
nullptr
,
nullptr
);
ASSERT_EQ
(
ret
,
OH_AI_STATUS_SUCCESS
);
CompareResult
(
outputs
,
"ml_face_isface"
);
OH_AI_ModelDestroy
(
&
model
);
}
// delegate异构:多输入单输出
HWTEST
(
MSLiteTest
,
OHOS_NNRT_0004
,
Function
|
MediumTest
|
Level1
)
{
printf
(
"==========Init Context==========
\n
"
);
OH_AI_ContextHandle
context
=
OH_AI_ContextCreate
();
ASSERT_NE
(
context
,
nullptr
);
...
...
@@ -1630,41 +1705,19 @@ HWTEST(MSLiteTest, OHOS_NNRT_0003, Function | MediumTest | Level1) {
OH_AI_ModelHandle
model
=
OH_AI_ModelCreate
();
ASSERT_NE
(
model
,
nullptr
);
printf
(
"==========Build model==========
\n
"
);
OH_AI_Status
ret
=
OH_AI_ModelBuildFromFile
(
model
,
"/data/test/
aiy_vision_classifier_plants_V1_3.ms"
,
OH_AI_MODELTYPE_MINDIR
,
context
);
OH_AI_Status
ret
=
OH_AI_ModelBuildFromFile
(
model
,
"/data/test/
ml_headpose_pb2tflite.ms"
,
OH_AI_MODELTYPE_MINDIR
,
context
);
printf
(
"==========build model return code:%d
\n
"
,
ret
);
ASSERT_EQ
(
ret
,
OH_AI_STATUS_SUCCESS
);
printf
(
"==========GetInputs==========
\n
"
);
OH_AI_TensorHandleArray
inputs
=
OH_AI_ModelGetInputs
(
model
);
ASSERT_NE
(
inputs
.
handle_list
,
nullptr
);
for
(
size_t
i
=
0
;
i
<
inputs
.
handle_num
;
++
i
)
{
OH_AI_TensorHandle
tensor
=
inputs
.
handle_list
[
i
];
int64_t
element_num
=
OH_AI_TensorGetElementNum
(
tensor
);
printf
(
"Tensor name: %s, elements num: %"
PRId64
".
\n
"
,
OH_AI_TensorGetName
(
tensor
),
element_num
);
void
*
input_data
=
OH_AI_TensorGetMutableData
(
inputs
.
handle_list
[
i
]);
ASSERT_NE
(
input_data
,
nullptr
);
memcpy_s
(
input_data
,
size1
,
imageBuf
,
size1
);
}
FillInputsData
(
inputs
,
"ml_headpose_pb2tflite"
,
false
);
printf
(
"==========Model Predict==========
\n
"
);
OH_AI_TensorHandleArray
outputs
;
ret
=
OH_AI_ModelPredict
(
model
,
inputs
,
&
outputs
,
nullptr
,
nullptr
);
ASSERT_EQ
(
ret
,
OH_AI_STATUS_SUCCESS
);
printf
(
"==========GetOutput==========
\n
"
);
for
(
size_t
i
=
0
;
i
<
outputs
.
handle_num
;
++
i
)
{
OH_AI_TensorHandle
tensor
=
outputs
.
handle_list
[
i
];
int64_t
element_num
=
OH_AI_TensorGetElementNum
(
tensor
);
printf
(
"Tensor name: %s, elements num: %"
PRId64
".
\n
"
,
OH_AI_TensorGetName
(
tensor
),
element_num
);
uint8_t
*
output_data
=
reinterpret_cast
<
uint8_t
*>
(
OH_AI_TensorGetMutableData
(
tensor
));
printf
(
"output data is:"
);
for
(
int
j
=
0
;
j
<
element_num
&&
j
<=
20
;
++
j
)
{
printf
(
"%d "
,
output_data
[
j
]);
}
printf
(
"
\n
"
);
printf
(
"==========compFp32WithTData==========
\n
"
);
string
expectedDataFile
=
"/data/test/aiy_vision_classifier_plants_V1_3"
+
std
::
to_string
(
i
)
+
".output"
;
bool
result
=
compUint8WithTData
(
output_data
,
expectedDataFile
,
0.01
,
0.01
,
false
);
EXPECT_EQ
(
result
,
true
);
}
delete
[]
imageBuf
;
CompareResult
(
outputs
,
"ml_headpose_pb2tflite"
,
0.02
,
0.02
);
OH_AI_ModelDestroy
(
&
model
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录