Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
4e4ad85c
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4e4ad85c
编写于
4年前
作者:
Y
yangruoqi713
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MS][LITE] fix bug of arm cpu fp16 infer: set subgraph output tensor data_type float32
上级
fc9161a4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
47 deletion
+27
-47
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc
+20
-35
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.h
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.h
+1
-9
mindspore/lite/src/scheduler.cc
mindspore/lite/src/scheduler.cc
+6
-3
未找到文件。
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc
浏览文件 @
4e4ad85c
...
...
@@ -21,6 +21,7 @@
#include "include/errorcode.h"
#include "nnacl/op_base.h"
#include "nnacl/fp16/cast_fp16.h"
#include "src/runtime/kernel/arm/fp16/common_fp16.h"
using
mindspore
::
kernel
::
KERNEL_ARCH
::
kCPU
;
using
mindspore
::
lite
::
KernelRegistrar
;
...
...
@@ -29,29 +30,6 @@ using mindspore::lite::RET_OK;
using
mindspore
::
schema
::
PrimitiveType_Pooling
;
namespace
mindspore
::
kernel
{
int
PoolingFp16CPUKernel
::
InitBuffer
()
{
int
in_batch
=
pooling_param_
->
input_batch_
;
int
in_h
=
pooling_param_
->
input_h_
;
int
in_w
=
pooling_param_
->
input_w_
;
int
in_channel
=
pooling_param_
->
input_channel_
;
fp16_input_
=
reinterpret_cast
<
float16_t
*>
(
malloc
(
in_batch
*
in_h
*
in_w
*
in_channel
*
sizeof
(
float16_t
)));
if
(
fp16_input_
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"malloc fp16_input_ failed."
;
return
RET_ERROR
;
}
int
out_batch
=
pooling_param_
->
output_batch_
;
int
out_h
=
pooling_param_
->
output_h_
;
int
out_w
=
pooling_param_
->
output_w_
;
int
out_channel
=
pooling_param_
->
output_channel_
;
fp16_output_
=
reinterpret_cast
<
float16_t
*>
(
malloc
(
out_batch
*
out_h
*
out_w
*
out_channel
*
sizeof
(
float16_t
)));
if
(
fp16_output_
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"fp16_out malloc failed."
;
return
RET_ERROR
;
}
return
RET_OK
;
}
int
PoolingFp16CPUKernel
::
Init
()
{
auto
ret
=
PoolingBaseCPUKernel
::
Init
();
if
(
ret
!=
RET_OK
)
{
...
...
@@ -71,12 +49,6 @@ int PoolingFp16CPUKernel::ReSize() {
MS_LOG
(
ERROR
)
<<
"PoolingBase ReSize fai1!ret: "
<<
ret
;
return
ret
;
}
ret
=
InitBuffer
();
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Init Buffer fail!ret: "
<<
ret
;
return
ret
;
}
return
RET_OK
;
}
...
...
@@ -105,9 +77,16 @@ int PoolingFp16CPUKernel::Run() {
MS_LOG
(
ERROR
)
<<
"Prepare fail!ret: "
<<
prepare_ret
;
return
prepare_ret
;
}
auto
ele_num
=
in_tensors_
.
front
()
->
ElementsNum
();
auto
input_ptr
=
reinterpret_cast
<
float
*>
(
in_tensors_
.
at
(
kInputIndex
)
->
Data
());
Float32ToFloat16
(
input_ptr
,
fp16_input_
,
ele_num
);
auto
input_tensor
=
in_tensors_
.
at
(
kInputIndex
);
auto
in_data_type_
=
input_tensor
->
data_type
();
MS_ASSERT
(
in_data_type_
==
kNumberTypeFloat32
||
in_data_type_
==
kNumberTypeFloat16
);
fp16_input_
=
ConvertInputFp32toFp16
(
input_tensor
,
context_
);
auto
out_tensor
=
out_tensors_
.
at
(
kOutputIndex
);
auto
out_data_type_
=
out_tensor
->
data_type
();
MS_ASSERT
(
out_data_type_
==
kNumberTypeFloat32
||
out_data_type_
==
kNumberTypeFloat16
);
fp16_output_
=
MallocOutputFp16
(
out_tensor
,
context_
);
int
error_code
=
ParallelLaunch
(
THREAD_POOL_DEFAULT
,
PoolingFp16Impl
,
this
,
thread_count_
);
if
(
error_code
!=
RET_OK
)
{
...
...
@@ -115,9 +94,15 @@ int PoolingFp16CPUKernel::Run() {
return
RET_ERROR
;
}
auto
out_ele_num
=
out_tensors_
.
front
()
->
ElementsNum
();
auto
output_ptr
=
reinterpret_cast
<
float
*>
(
out_tensors_
.
at
(
kOutputIndex
)
->
Data
());
Float16ToFloat32
(
fp16_output_
,
output_ptr
,
out_ele_num
);
if
(
in_data_type_
==
kNumberTypeFloat32
)
{
context_
->
allocator
->
Free
(
fp16_input_
);
}
if
(
out_data_type_
==
kNumberTypeFloat32
)
{
auto
out_ele_num
=
out_tensor
->
ElementsNum
();
auto
output_addr
=
reinterpret_cast
<
float
*>
(
out_tensor
->
Data
());
Float16ToFloat32
(
fp16_output_
,
output_addr
,
out_ele_num
);
context_
->
allocator
->
Free
(
fp16_output_
);
}
return
RET_OK
;
}
...
...
This diff is collapsed.
Click to expand it.
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.h
浏览文件 @
4e4ad85c
...
...
@@ -28,17 +28,9 @@ class PoolingFp16CPUKernel : public PoolingBaseCPUKernel {
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
const
Context
*
ctx
,
const
mindspore
::
lite
::
PrimitiveC
*
primitive
)
:
PoolingBaseCPUKernel
(
parameter
,
inputs
,
outputs
,
ctx
,
primitive
)
{}
~
PoolingFp16CPUKernel
()
override
{
if
(
fp16_input_
!=
nullptr
)
{
free
(
fp16_input_
);
}
if
(
fp16_output_
!=
nullptr
)
{
free
(
fp16_output_
);
}
};
~
PoolingFp16CPUKernel
()
override
=
default
;
int
Init
()
override
;
int
InitBuffer
();
int
ReSize
()
override
;
int
Run
()
override
;
int
RunImpl
(
int
task_id
);
...
...
This diff is collapsed.
Click to expand it.
mindspore/lite/src/scheduler.cc
浏览文件 @
4e4ad85c
...
...
@@ -182,9 +182,12 @@ void Scheduler::ConstructSubgraphs(std::vector<kernel::LiteKernel *> *kernels) {
for
(
auto
kernel
:
temp_kernels
)
{
for
(
auto
tensor
:
kernel
->
out_tensors
())
{
tensor
->
set_allocator
(
context_
->
allocator
.
get
());
if
(
context_
->
float16_priority
&&
tensor
->
data_type
()
==
kNumberTypeFloat16
)
{
tensor
->
set_data_type
(
kNumberTypeFloat32
);
}
}
}
std
::
vector
<
tensor
::
Tensor
*>
output_tensor
=
kernel
::
LiteKernelUtil
::
SubgraphOutputTensors
(
temp_kernels
);
for
(
auto
tensor
:
output_tensor
)
{
if
(
context_
->
float16_priority
&&
tensor
->
data_type
()
==
kNumberTypeFloat16
)
{
tensor
->
set_data_type
(
kNumberTypeFloat32
);
}
}
std
::
copy
(
temp_kernels
.
begin
(),
temp_kernels
.
end
(),
std
::
back_inserter
(
subgraph_kernels
));
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部