Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
f0eef679
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f0eef679
编写于
8月 13, 2020
作者:
Y
yangruoqi713
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MS][LITE] fix bug of arm cpu fp32 op: conv depthwise; rewrite member variables of some ops
上级
8c377fd1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
98 addition
and
34 deletion
+98
-34
mindspore/lite/src/ops/deconvolution_depthwise.cc
mindspore/lite/src/ops/deconvolution_depthwise.cc
+2
-2
mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.h
mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.h
+4
-4
mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.h
.../lite/src/runtime/kernel/arm/fp32/convolution_depthwise.h
+4
-4
mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.h
...e/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.h
+5
-5
mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.h
mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.h
+6
-6
mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc
mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc
+10
-8
mindspore/lite/src/runtime/kernel/arm/fp32/scale.h
mindspore/lite/src/runtime/kernel/arm/fp32/scale.h
+4
-5
mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/batchnorm_fp32_tests.cc
...st/ut/src/runtime/kernel/arm/fp32/batchnorm_fp32_tests.cc
+63
-0
未找到文件。
mindspore/lite/src/ops/deconvolution_depthwise.cc
浏览文件 @
f0eef679
...
...
@@ -48,8 +48,8 @@ int DeconvDepthwiseConv2D::InferShape(std::vector<tensor::Tensor *> inputs_, std
pad_u_
=
conv_prim
->
padUp
();
pad_d_
=
conv_prim
->
padDown
();
pad_r_
=
conv_prim
->
padRight
();
output_h
=
conv_prim
->
strideH
()
*
(
input_h
-
1
)
*
conv_prim
->
kernelH
()
-
pad_u_
-
pad_d_
;
output_w
=
conv_prim
->
strideW
()
*
(
input_w
-
1
)
*
conv_prim
->
kernelW
()
-
pad_l_
-
pad_r_
;
output_h
=
conv_prim
->
strideH
()
*
(
input_h
-
1
)
+
conv_prim
->
kernelH
()
-
pad_u_
-
pad_d_
;
output_w
=
conv_prim
->
strideW
()
*
(
input_w
-
1
)
+
conv_prim
->
kernelW
()
-
pad_l_
-
pad_r_
;
if
((
output_h
+
conv_prim
->
padUp
()
+
conv_prim
->
padDown
()
-
conv_prim
->
kernelH
())
%
conv_prim
->
strideH
()
!=
0
)
{
output_h
+=
(
output_h
+
conv_prim
->
padLeft
()
+
conv_prim
->
padRight
()
-
conv_prim
->
kernelH
())
%
conv_prim
->
strideH
();
}
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.h
浏览文件 @
f0eef679
...
...
@@ -42,10 +42,10 @@ class BatchnormCPUKernel : public LiteKernel {
int
DoExecute
(
int
tid
);
private:
float
*
in_addr_
;
float
*
mean_addr_
;
float
*
var_addr_
;
float
*
out_addr_
;
float
*
in_addr_
=
nullptr
;
float
*
mean_addr_
=
nullptr
;
float
*
var_addr_
=
nullptr
;
float
*
out_addr_
=
nullptr
;
BatchNormParameter
*
batchnorm_param_
;
};
}
// namespace mindspore::kernel
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.h
浏览文件 @
f0eef679
...
...
@@ -40,10 +40,10 @@ class ConvolutionDepthwiseCPUKernel : public ConvolutionBaseCPUKernel {
int
Execute
(
int
task_id
);
private:
SlidingWindowParam
*
sliding_
;
float
*
packed_weight_
;
float
*
packed_input_
;
float
*
packed_output_
;
SlidingWindowParam
*
sliding_
=
nullptr
;
float
*
packed_weight_
=
nullptr
;
float
*
packed_input_
=
nullptr
;
float
*
packed_output_
=
nullptr
;
bool
need_align_
=
false
;
};
}
// namespace mindspore::kernel
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.h
浏览文件 @
f0eef679
...
...
@@ -49,11 +49,11 @@ class ConvolutionDepthwise3x3CPUKernel : public ConvolutionBaseCPUKernel {
int
Execute
(
int
task_id
);
private:
float
*
packed_weight_
;
float
*
packed_input_
;
float
*
packed_output_
;
float
*
block_buffer_
;
float
*
trans_buffer_
;
float
*
packed_weight_
=
nullptr
;
float
*
packed_input_
=
nullptr
;
float
*
packed_output_
=
nullptr
;
float
*
block_buffer_
=
nullptr
;
float
*
trans_buffer_
=
nullptr
;
int
trans_size_
;
bool
need_align_
=
false
;
};
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.h
浏览文件 @
f0eef679
...
...
@@ -40,12 +40,12 @@ class FusedBatchnormCPUKernel : public LiteKernel {
int
Execute
(
int
task_id
);
private:
float
*
in_addr_
;
float
*
mean_addr_
;
float
*
var_addr_
;
float
*
scale_addr_
;
float
*
offset_addr_
;
float
*
out_addr_
;
float
*
in_addr_
=
nullptr
;
float
*
mean_addr_
=
nullptr
;
float
*
var_addr_
=
nullptr
;
float
*
scale_addr_
=
nullptr
;
float
*
offset_addr_
=
nullptr
;
float
*
out_addr_
=
nullptr
;
BatchNormParameter
*
batchnorm_param_
;
};
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc
浏览文件 @
f0eef679
...
...
@@ -28,9 +28,7 @@ using mindspore::lite::RET_OK;
using
mindspore
::
schema
::
PrimitiveType_Scale
;
namespace
mindspore
::
kernel
{
ScaleCPUKernel
::~
ScaleCPUKernel
()
{
FreeTmpBuffer
();
}
void
ScaleCPUKernel
::
FreeTmpBuffer
()
{
ScaleCPUKernel
::~
ScaleCPUKernel
()
{
if
(
scale_param_
->
const_scale_
)
{
if
(
scale_
!=
nullptr
)
{
free
(
scale_
);
...
...
@@ -46,7 +44,6 @@ void ScaleCPUKernel::FreeTmpBuffer() {
}
int
ScaleCPUKernel
::
InitScaleOffset
()
{
FreeTmpBuffer
();
auto
scale_tensor
=
in_tensors_
.
at
(
1
);
float
*
scale_ptr
=
reinterpret_cast
<
float
*>
(
in_tensors_
.
at
(
1
)
->
Data
());
if
(
scale_ptr
!=
nullptr
)
{
...
...
@@ -116,10 +113,7 @@ int ScaleCPUKernel::Init() {
if
(
!
InferShapeDone
())
{
return
RET_OK
;
}
return
ReSize
();
}
int
ScaleCPUKernel
::
ReSize
()
{
auto
ret
=
InitParameter
();
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Scale fp32 InitParameter failed."
;
...
...
@@ -134,6 +128,15 @@ int ScaleCPUKernel::ReSize() {
return
RET_OK
;
}
int
ScaleCPUKernel
::
ReSize
()
{
auto
ret
=
InitParameter
();
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Scale fp32 InitParameter failed."
;
return
RET_ERROR
;
}
return
RET_OK
;
}
int
ScaleCPUKernel
::
Scale
(
int
task_id
)
{
auto
ret
=
DoScale
(
input_ptr_
,
output_ptr_
,
scale_
,
offset_
,
task_id
,
scale_param_
);
if
(
ret
!=
RET_OK
)
{
...
...
@@ -173,7 +176,6 @@ int ScaleCPUKernel::Run() {
MS_LOG
(
ERROR
)
<<
"Scale error error_code["
<<
ret
<<
"]"
;
return
RET_ERROR
;
}
FreeTmpBuffer
();
return
RET_OK
;
}
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/scale.h
浏览文件 @
f0eef679
...
...
@@ -41,11 +41,10 @@ class ScaleCPUKernel : public LiteKernel {
int
Scale
(
int
task_id
);
private:
void
FreeTmpBuffer
();
float
*
input_ptr_
;
float
*
scale_
;
float
*
offset_
;
float
*
output_ptr_
;
float
*
input_ptr_
=
nullptr
;
float
*
scale_
=
nullptr
;
float
*
offset_
=
nullptr
;
float
*
output_ptr_
=
nullptr
;
ScaleParameter
*
scale_param_
;
};
}
// namespace mindspore::kernel
...
...
mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/batchnorm_fp32_tests.cc
浏览文件 @
f0eef679
...
...
@@ -84,4 +84,67 @@ TEST_F(TestBatchnormFp32, BNTest) {
output0_tensor
.
SetData
(
nullptr
);
MS_LOG
(
INFO
)
<<
"TestBathNormFp32 accuracy passed"
;
}
TEST_F
(
TestBatchnormFp32
,
FusedBNTest
)
{
std
::
vector
<
float
>
in_data
=
{
-
7.400094
,
11.37495
,
2.0271842
,
5.5954003
,
13.255154
,
4.6289115
,
9.591311
,
8.699771
,
-
12.226144
,
-
6.1819935
,
6.957936
,
-
8.70818
};
std
::
vector
<
float
>
scale
=
{
13.323708
,
14.0656395
,
12.634319
};
std
::
vector
<
float
>
offset
=
{
27.888096
,
24.533648
,
15.335093
};
std
::
vector
<
float
>
mean
=
{
11.5127125
,
0.47681615
,
5.851508
};
std
::
vector
<
float
>
var
=
{
1.270583
,
13.005714
,
6.089223
};
std
::
vector
<
lite
::
tensor
::
Tensor
*>
inputs_tensor
;
std
::
vector
<
lite
::
tensor
::
Tensor
*>
outputs_tensor
;
BatchNormParameter
op_param
;
op_param
.
op_parameter_
.
type_
=
schema
::
PrimitiveType_BatchNorm
;
op_param
.
epsilon_
=
0.001
f
;
std
::
vector
<
int
>
shape
=
{
1
,
2
,
2
,
3
};
lite
::
tensor
::
Tensor
input
[
5
];
input
[
0
].
SetData
(
in_data
.
data
());
input
[
1
].
SetData
(
scale
.
data
());
input
[
2
].
SetData
(
offset
.
data
());
input
[
3
].
SetData
(
mean
.
data
());
input
[
4
].
SetData
(
var
.
data
());
input
[
0
].
set_shape
(
shape
);
for
(
int
i
=
1
;
i
<
5
;
i
++
)
{
input
[
i
].
set_shape
({
3
});
}
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
inputs_tensor
.
push_back
(
&
input
[
i
]);
}
std
::
vector
<
float
>
output
(
12
);
std
::
vector
<
float
>
corr_out
=
{
-
195.5765
,
67.03745
,
-
4.243883
,
-
42.028015
,
74.37044
,
9.075897
,
5.1857452
,
56.60399
,
-
77.215096
,
-
181.18402
,
49.81066
,
-
59.204563
};
lite
::
tensor
::
Tensor
output0_tensor
;
outputs_tensor
.
push_back
(
&
output0_tensor
);
output0_tensor
.
SetData
(
output
.
data
());
output0_tensor
.
set_shape
(
shape
);
kernel
::
KernelKey
desc
=
{
kernel
::
KERNEL_ARCH
::
kCPU
,
kNumberTypeFloat32
,
schema
::
PrimitiveType_FusedBatchNorm
};
auto
creator
=
lite
::
KernelRegistry
::
GetInstance
()
->
GetCreator
(
desc
);
ASSERT_NE
(
creator
,
nullptr
);
lite
::
Context
ctx
;
ctx
.
thread_num_
=
1
;
kernel
::
LiteKernel
*
kernel
=
creator
(
inputs_tensor
,
outputs_tensor
,
reinterpret_cast
<
OpParameter
*>
(
&
op_param
),
&
ctx
,
desc
,
nullptr
);
ASSERT_NE
(
kernel
,
nullptr
);
auto
output_tensor_shape
=
output0_tensor
.
shape
();
kernel
->
Run
();
printf
(
"==================output data=================
\n
"
);
for
(
int
i
=
0
;
i
<
output0_tensor
.
ElementsNum
();
i
++
)
{
std
::
cout
<<
output
[
i
]
<<
" ,"
;
}
std
::
cout
<<
std
::
endl
;
CompareOutputData
(
output
.
data
(),
corr_out
.
data
(),
output0_tensor
.
ElementsNum
(),
0.001
);
for
(
int
i
=
1
;
i
<
5
;
i
++
)
{
input
[
i
].
SetData
(
nullptr
);
}
output0_tensor
.
SetData
(
nullptr
);
MS_LOG
(
INFO
)
<<
"TestFusedBathNormFp32 accuracy passed"
;
}
}
// namespace mindspore
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录