Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
afe761d8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
afe761d8
编写于
10月 19, 2018
作者:
X
xiaolil1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix quantize bug and add debug log
上级
e214530d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
56 addition
and
10 deletion
+56
-10
paddle/fluid/operators/conv_mkldnn_op.cc
paddle/fluid/operators/conv_mkldnn_op.cc
+20
-2
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
+29
-3
paddle/fluid/platform/mkldnn_helper.h
paddle/fluid/platform/mkldnn_helper.h
+6
-4
未找到文件。
paddle/fluid/operators/conv_mkldnn_op.cc
浏览文件 @
afe761d8
...
...
@@ -350,10 +350,29 @@ 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 "
,
*
(
input_data
+
i
)
/
scale_in_data
);
}
printf
(
"
\n
"
);
fflush
(
stdout
);
std
::
vector
<
float
>
scale_weights_data
(
count
);
for
(
int
i
=
0
;
i
<
count
;
i
++
){
scale_weights_data
[
i
]
=*
(
scale_weights
->
data
<
float
>
()
+
i
);
...
...
@@ -479,7 +498,6 @@ std::cout<<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
){
...
...
@@ -510,7 +528,7 @@ std::cout<<key_conv_pd<<std::endl;
handler
.
AcquireDstMemoryFromPrimitive
(
to_void_cast
<
int8_t
>
(
output_data
));
}
}
std
::
cout
<<
"input fmt = "
<<
input
->
format
()
<<
"
output fmt = "
<<
output
->
format
()
<<
" dst fmt = "
<<
dst_memory_p
->
get_primitive_desc
().
desc
().
data
.
format
<<
std
::
endl
;
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
;
}
else
{
T
*
output_data
=
nullptr
;
if
(
fuse_residual_conn
)
{
...
...
paddle/fluid/operators/dequantize_op.cc
浏览文件 @
afe761d8
...
...
@@ -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
(
dst_pd
,
src
_pd
,
attri
));
new
reorder
::
primitive_desc
(
src_pd
,
dst
_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
浏览文件 @
afe761d8
...
...
@@ -47,9 +47,35 @@ 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
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
uint8_t
*
output_data
=
output
->
mutable_data
<
uint8_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
);
...
...
@@ -63,10 +89,10 @@ std::cout<<"this is quantize op!!!!!!!!!!!!!!"<<std::endl;
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
<
T
>
(
output_data
));
auto
dst_memory
=
mkldnn
::
memory
(
dst_pd
,
to_void_cast
<
uint8_t
>
(
output_data
));
auto
reorder_pd
=
std
::
shared_ptr
<
reorder
::
primitive_desc
>
(
new
reorder
::
primitive_desc
(
dst_pd
,
src
_pd
,
attri
));
new
reorder
::
primitive_desc
(
src_pd
,
dst
_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/platform/mkldnn_helper.h
浏览文件 @
afe761d8
...
...
@@ -212,16 +212,18 @@ class MKLDNNHandler {
std
::
shared_ptr
<
mkldnn
::
primitive
>
reorder_p
;
if
(
mpd
!=
user_mpd
)
{
target_memory_p
=
std
::
make_shared
<
mkldnn
::
memory
>
(
mpd
);
auto
reorder_p
=
std
::
make_shared
<
mkldnn
::
reorder
>
(
*
user_memory_p
,
*
target_memory_p
);
std
::
shared_ptr
<
mkldnn
::
reorder
>
reorder_p
;
//
=
//
std::make_shared<mkldnn::reorder>(*user_memory_p, *target_memory_p);
if
(
is_INT8
){
mkldnn
::
primitive_attr
attri
;
attri
.
set_output_scales
(
mask
,
scale_data
);
auto
reorder_pd
=
std
::
shared_ptr
<
mkldnn
::
reorder
::
primitive_desc
>
(
new
mkldnn
::
reorder
::
primitive_desc
(
mpd
,
user_
mpd
,
attri
));
auto
reorder_p
=
new
mkldnn
::
reorder
::
primitive_desc
(
user_mpd
,
mpd
,
attri
));
reorder_p
=
std
::
shared_ptr
<
mkldnn
::
reorder
>
(
new
mkldnn
::
reorder
(
*
reorder_pd
,
*
user_memory_p
,
*
target_memory_p
));
}
else
{
reorder_p
=
std
::
make_shared
<
mkldnn
::
reorder
>
(
*
user_memory_p
,
*
target_memory_p
);
}
dev_ctx_
.
SetBlob
(
key_reorder_p
,
reorder_p
);
pipeline
.
push_back
(
*
reorder_p
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录