Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
94e0a673
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
94e0a673
编写于
10月 25, 2018
作者:
X
xiaolil1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "fix conv int8 reorder mask"
This reverts commit
00970fb8
.
上级
00970fb8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
11 addition
and
68 deletion
+11
-68
paddle/fluid/operators/conv_mkldnn_op.cc
paddle/fluid/operators/conv_mkldnn_op.cc
+7
-38
paddle/fluid/operators/dequantize_op.cc
paddle/fluid/operators/dequantize_op.cc
+1
-1
paddle/fluid/operators/quantize_op.cc
paddle/fluid/operators/quantize_op.cc
+3
-29
未找到文件。
paddle/fluid/operators/conv_mkldnn_op.cc
浏览文件 @
94e0a673
...
...
@@ -350,59 +350,27 @@ std::cout<<"fuse_relu = "<<fuse_relu<<" fuse_residual_conn = "<<fuse_residual_c
std
::
vector
<
float
>
output_shift_scale
;
float
sum_scale
=
1.0
f
;
for
(
int
i
=
0
;
i
<
50
;
i
++
){
printf
(
"%f "
,
(
float
)
*
(
input_data
+
i
));
}
printf
(
"
\n
"
);
fflush
(
stdout
);
if
(
is_INT8
){
std
::
cout
<<
"this is conv int8 op .............."
<<
std
::
endl
;
unsigned
char
*
a
=
(
unsigned
char
*
)(
input_data
);
for
(
int
i
=
0
;
i
<
50
;
i
++
){
printf
(
"%d "
,
a
[
i
]);
}
printf
(
"
\n
"
);
int
count
=
is_multi_channel
?
(
g
>
1
?
weights_tz
[
1
]
*
weights_tz
[
0
]
:
weights_tz
[
0
])
:
1
;
float
scale_in_data
=
*
(
scale_in
->
data
<
float
>
());
for
(
int
i
=
0
;
i
<
50
;
i
++
){
printf
(
"%f "
,
(
float
)(
input_data
[
i
])
/
scale_in_data
);
}
printf
(
"
\n
"
);
fflush
(
stdout
);
std
::
cout
<<
"scale_in_data = "
<<
scale_in_data
<<
std
::
endl
;
std
::
vector
<
float
>
scale_weights_data
(
count
);
std
::
cout
<<
"scale_weights_data = "
;
for
(
int
i
=
0
;
i
<
count
;
i
++
){
scale_weights_data
[
i
]
=*
(
scale_weights
->
data
<
float
>
()
+
i
);
std
::
cout
<<
scale_weights_data
[
i
]
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
float
scale_out_data
=
*
(
scale_out
->
data
<
float
>
());
std
::
cout
<<
"scale_out_data = "
<<
scale_out_data
<<
std
::
endl
;
output_shift_scale
.
resize
(
count
);
std
::
cout
<<
"output_shift_scale = "
;
for
(
int
i
=
0
;
i
<
count
;
i
++
){
if
(
scale_weights_data
[
i
]
==
0.0
)
output_shift_scale
[
i
]
=
scale_out_data
;
else
output_shift_scale
[
i
]
=
scale_out_data
/
(
scale_in_data
*
scale_weights_data
[
i
]);
std
::
cout
<<
output_shift_scale
[
i
]
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
if
(
fuse_residual_conn
){
float
scale_in_eltwise_data
=
*
(
scale_in_eltwise
->
data
<
float
>
());
std
::
cout
<<
"scale_in_eltwise_data = "
<<
scale_in_eltwise_data
<<
std
::
endl
;
sum_scale
=
scale_out_data
/
scale_in_eltwise_data
;
}
std
::
cout
<<
" sum_scale = "
<<
sum_scale
<<
std
::
endl
;
}
// Get unique name for storing MKLDNN primitives
...
...
@@ -411,7 +379,7 @@ std::cout<<" sum_scale = "<<sum_scale<<std::endl;
ctx
.
op
().
Output
(
"Output"
));
const
std
::
string
key_conv_pd
=
key
+
"@conv_pd"
;
std
::
cout
<<
"current op is = "
<<
key_conv_pd
<<
std
::
endl
;
std
::
cout
<<
key_conv_pd
<<
std
::
endl
;
std
::
vector
<
primitive
>
pipeline
;
auto
user_src_md
=
platform
::
MKLDNNMemDesc
(
...
...
@@ -444,7 +412,7 @@ std::cout<<"current op is = "<<key_conv_pd<<std::endl;
weights_tz
,
memory
::
data_type
::
s8
,
(
g
==
1
)
?
chosen_memory_format
:
mkldnn
::
memory
::
format
::
goihw
);
dst_md
=
platform
::
MKLDNNMemDesc
(
dst_tz
,
// memory::data_type::f32, chosen_memory_format);
dst_tz
,
fuse_relu
?
paddle
::
framework
::
ToMKLDNNDataType
(
std
::
type_index
(
typeid
(
unsigned
char
)))
:
paddle
::
framework
::
ToMKLDNNDataType
(
std
::
type_index
(
typeid
(
char
))),
chosen_memory_format
);
...
...
@@ -499,7 +467,7 @@ std::cout<<"current op is = "<<key_conv_pd<<std::endl;
std
::
shared_ptr
<
mkldnn
::
memory
>
weights_memory_p
;
// = handler.AcquireWeightsMemoryFromPrimitive(
//user_weights_memory_p, pipeline, is_test);
if
(
is_INT8
){
int
mask_reorder
=
is_multi_channel
?
((
g
!=
1
)
?
(
1
<<
1
)
+
(
1
<<
0
)
:
1
<<
0
)
:
0
;
int
mask_reorder
=
is_multi_channel
?
0
:
((
g
!=
1
)
?
(
1
<<
1
)
+
(
1
<<
0
)
:
1
<<
0
)
;
int
count
=
is_multi_channel
?
(
g
>
1
?
weights_tz
[
1
]
*
weights_tz
[
0
]
:
weights_tz
[
0
])
:
1
;
std
::
vector
<
float
>
scale_weights_data
(
count
);
for
(
int
i
=
0
;
i
<
count
;
i
++
){
...
...
@@ -511,6 +479,7 @@ std::cout<<"current op is = "<<key_conv_pd<<std::endl;
weights_memory_p
=
handler
.
AcquireWeightsMemoryFromPrimitive
(
user_weights_memory_p
,
pipeline
,
is_test
);
}
std
::
shared_ptr
<
mkldnn
::
memory
>
dst_memory_p
;
if
(
is_INT8
){
...
...
@@ -541,7 +510,7 @@ std::cout<<"current op is = "<<key_conv_pd<<std::endl;
handler
.
AcquireDstMemoryFromPrimitive
(
to_void_cast
<
int8_t
>
(
output_data
));
}
}
std
::
cout
<<
"input fmt = "
<<
input
->
format
()
<<
"
input dt = "
<<
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
())
<<
" output fmt = "
<<
output
->
format
()
<<
" output dt = "
<<
paddle
::
framework
::
ToMKLDNNDataType
(
output
->
type
())
<<
" dst fmt = "
<<
dst_memory_p
->
get_primitive_desc
().
desc
().
data
.
format
<<
" dst dt = "
<<
dst_memory_p
->
get_primitive_desc
().
desc
().
data
.
data_type
<<
std
::
endl
;
std
::
cout
<<
"input fmt = "
<<
input
->
format
()
<<
"
output fmt = "
<<
output
->
format
()
<<
" dst fmt = "
<<
dst_memory_p
->
get_primitive_desc
().
desc
().
data
.
format
<<
std
::
endl
;
}
else
{
T
*
output_data
=
nullptr
;
if
(
fuse_residual_conn
)
{
...
...
@@ -576,7 +545,7 @@ std::cout<<"input fmt = "<<input->format()<<" input dt = "<<paddle::framework:
std
::
shared_ptr
<
mkldnn
::
memory
>
bias_memory_p
;
// =
//handler.AcquireBiasMemoryFromPrimitive(user_bias_memory_p, pipeline);
if
(
is_INT8
){
int
mask_reorder
=
is_multi_channel
?
1
<<
0
:
1
;
int
mask_reorder
=
is_multi_channel
?
0
:
1
<<
0
;
int
count
=
is_multi_channel
?
(
g
>
1
?
weights_tz
[
1
]
*
weights_tz
[
0
]
:
weights_tz
[
0
])
:
1
;
std
::
vector
<
float
>
scale_bias_data
(
count
);
for
(
int
i
=
0
;
i
<
count
;
i
++
){
...
...
@@ -625,7 +594,7 @@ std::cout<<"input fmt = "<<input->format()<<" output fmt = "<<output->format()<
if
(
fuse_relu
)
{
constexpr
float
scale
=
1.0
f
;
constexpr
float
negative_slope
=
0.0
f
;
constexpr
float
placeholder
=
1
.0
f
;
//beta
constexpr
float
placeholder
=
0
.0
f
;
//beta
post_operations
.
append_eltwise
(
scale
,
mkldnn
::
algorithm
::
eltwise_relu
,
negative_slope
,
placeholder
);
}
...
...
paddle/fluid/operators/dequantize_op.cc
浏览文件 @
94e0a673
...
...
@@ -72,7 +72,7 @@ std::cout<<"this is dequant op ***********"<<std::endl;
auto
dst_memory
=
mkldnn
::
memory
(
dst_pd
,
to_void_cast
<
float
>
(
output_data
));
auto
reorder_pd
=
std
::
shared_ptr
<
reorder
::
primitive_desc
>
(
new
reorder
::
primitive_desc
(
src_pd
,
dst
_pd
,
attri
));
new
reorder
::
primitive_desc
(
dst_pd
,
src
_pd
,
attri
));
auto
reorder_p
=
std
::
shared_ptr
<
reorder
>
(
new
reorder
(
*
reorder_pd
,
*
src_memory_p
,
dst_memory
));
pipeline
.
push_back
(
*
reorder_p
);
...
...
paddle/fluid/operators/quantize_op.cc
浏览文件 @
94e0a673
...
...
@@ -47,35 +47,9 @@ std::cout<<"this is quantize op!!!!!!!!!!!!!!"<<std::endl;
std
::
vector
<
int
>
dst_tz
=
paddle
::
framework
::
vectorize2int
(
output
->
dims
());
const
T
*
input_data
=
input
->
data
<
T
>
();
uint8_t
*
output_data
=
output
->
mutable_data
<
uint8_t
>
(
ctx
.
GetPlace
());
T
*
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
std
::
vector
<
T
>
scale_data
=
{
*
(
scale
->
data
<
T
>
())};
FILE
*
fp
=
fopen
(
"quant_input.txt"
,
"w"
);
printf
(
"quantize check!!!!
\n
"
);
std
::
vector
<
int
>
tz
=
paddle
::
framework
::
vectorize2int
(
input
->
dims
());
int
count
=
1
;
for
(
int
i
=
0
;
i
<
tz
.
size
();
i
++
){
count
*=
tz
[
i
];
printf
(
"%d "
,
tz
[
i
]);
}
printf
(
"
\n
"
);
int
num
=
0
;
for
(
int
i
=
0
;
i
<
count
;
i
++
){
if
(
num
==
32
){
fprintf
(
fp
,
"
\n
"
);
num
=
0
;}
fprintf
(
fp
,
"%f "
,
*
(
input_data
+
i
));
num
++
;
}
fprintf
(
fp
,
"
\n
"
);
fclose
(
fp
);
for
(
int
i
=
0
;
i
<
scale_data
.
size
();
i
++
){
printf
(
"%f"
,
scale_data
[
i
]);
}
printf
(
"
\n
"
);
for
(
int
i
=
0
;
i
<
50
;
i
++
){
printf
(
"%f "
,
(
*
(
input_data
+
i
))
*
scale_data
[
0
]);
}
printf
(
"
\n
"
);
fflush
(
stdout
);
mkldnn
::
primitive_attr
attri
;
int
mask
=
0
;
attri
.
set_output_scales
(
mask
,
scale_data
);
...
...
@@ -89,10 +63,10 @@ fflush(stdout);
auto
dst_md
=
platform
::
MKLDNNMemDesc
(
{
dst_tz
},
memory
::
data_type
::
u8
,
memory
::
format
::
nhwc
);
auto
dst_pd
=
mkldnn
::
memory
::
primitive_desc
(
dst_md
,
engine
);
auto
dst_memory
=
mkldnn
::
memory
(
dst_pd
,
to_void_cast
<
uint8_t
>
(
output_data
));
auto
dst_memory
=
mkldnn
::
memory
(
dst_pd
,
to_void_cast
<
T
>
(
output_data
));
auto
reorder_pd
=
std
::
shared_ptr
<
reorder
::
primitive_desc
>
(
new
reorder
::
primitive_desc
(
src_pd
,
dst
_pd
,
attri
));
new
reorder
::
primitive_desc
(
dst_pd
,
src
_pd
,
attri
));
auto
reorder_p
=
std
::
shared_ptr
<
reorder
>
(
new
reorder
(
*
reorder_pd
,
*
src_memory_p
,
dst_memory
));
pipeline
.
push_back
(
*
reorder_p
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录