Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1f3300ba
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看板
提交
1f3300ba
编写于
9月 29, 2018
作者:
X
xiaolil1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify quantization op name and fmt source
上级
350a58b0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
15 addition
and
40 deletion
+15
-40
paddle/fluid/operators/conv_mkldnn_op.cc
paddle/fluid/operators/conv_mkldnn_op.cc
+2
-2
paddle/fluid/operators/dequantize_op.cc
paddle/fluid/operators/dequantize_op.cc
+5
-29
paddle/fluid/operators/dequantize_op.h
paddle/fluid/operators/dequantize_op.h
+0
-0
paddle/fluid/operators/quantize_op.cc
paddle/fluid/operators/quantize_op.cc
+3
-4
paddle/fluid/operators/quantize_op.h
paddle/fluid/operators/quantize_op.h
+0
-0
paddle/fluid/operators/requantize_op.cc
paddle/fluid/operators/requantize_op.cc
+5
-5
paddle/fluid/operators/requantize_op.h
paddle/fluid/operators/requantize_op.h
+0
-0
未找到文件。
paddle/fluid/operators/conv_mkldnn_op.cc
浏览文件 @
1f3300ba
...
@@ -278,7 +278,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -278,7 +278,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
auto
*
bias
=
ctx
.
HasInput
(
"Bias"
)
?
ctx
.
Input
<
Tensor
>
(
"Bias"
)
:
nullptr
;
auto
*
bias
=
ctx
.
HasInput
(
"Bias"
)
?
ctx
.
Input
<
Tensor
>
(
"Bias"
)
:
nullptr
;
auto
*
output
=
ctx
.
Output
<
Tensor
>
(
"Output"
);
auto
*
output
=
ctx
.
Output
<
Tensor
>
(
"Output"
);
bool
is_INT8
=
ctx
.
HasInput
(
"
Bias
"
)
?
true
:
false
;
bool
is_INT8
=
ctx
.
HasInput
(
"
Scale_in
"
)
?
true
:
false
;
auto
*
scale_in
=
ctx
.
HasInput
(
"Scale_in"
)
?
ctx
.
Input
<
Tensor
>
(
"Scale_in"
)
:
nullptr
;
auto
*
scale_in
=
ctx
.
HasInput
(
"Scale_in"
)
?
ctx
.
Input
<
Tensor
>
(
"Scale_in"
)
:
nullptr
;
auto
*
scale_in_eltwise
=
ctx
.
HasInput
(
"Scale_in_eltwise"
)
?
ctx
.
Input
<
Tensor
>
(
"Scale_in_eltwise"
)
:
nullptr
;
auto
*
scale_in_eltwise
=
ctx
.
HasInput
(
"Scale_in_eltwise"
)
?
ctx
.
Input
<
Tensor
>
(
"Scale_in_eltwise"
)
:
nullptr
;
auto
*
scale_weights
=
ctx
.
HasInput
(
"Scale_weights"
)
?
ctx
.
Input
<
Tensor
>
(
"Scale_weights"
)
:
nullptr
;
auto
*
scale_weights
=
ctx
.
HasInput
(
"Scale_weights"
)
?
ctx
.
Input
<
Tensor
>
(
"Scale_weights"
)
:
nullptr
;
...
@@ -478,7 +478,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -478,7 +478,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
if
(
fuse_relu
)
{
if
(
fuse_relu
)
{
constexpr
float
scale
=
1.0
f
;
constexpr
float
scale
=
1.0
f
;
constexpr
float
negative_slope
=
0.0
f
;
constexpr
float
negative_slope
=
0.0
f
;
constexpr
float
placeholder
=
0.0
f
;
constexpr
float
placeholder
=
0.0
f
;
//beta
post_operations
.
append_eltwise
(
scale
,
mkldnn
::
algorithm
::
eltwise_relu
,
post_operations
.
append_eltwise
(
scale
,
mkldnn
::
algorithm
::
eltwise_relu
,
negative_slope
,
placeholder
);
negative_slope
,
placeholder
);
}
}
...
...
paddle/fluid/operators/dequantiz
ation
_op.cc
→
paddle/fluid/operators/dequantiz
e
_op.cc
浏览文件 @
1f3300ba
...
@@ -16,7 +16,7 @@ limitations under the License. */
...
@@ -16,7 +16,7 @@ limitations under the License. */
#include "mkldnn.hpp"
#include "mkldnn.hpp"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/operators/dequantiz
ation
_op.h"
#include "paddle/fluid/operators/dequantiz
e
_op.h"
#include "paddle/fluid/framework/data_layout_transform.h"
#include "paddle/fluid/framework/data_layout_transform.h"
namespace
paddle
{
namespace
paddle
{
...
@@ -36,29 +36,6 @@ template <typename DeviceContext, typename T>
...
@@ -36,29 +36,6 @@ template <typename DeviceContext, typename T>
class
DeQuantOpKernel
:
public
framework
::
OpKernel
<
T
>
{
class
DeQuantOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
// MKLDNNDataType ToMKLDNNDataType(const std::type_index type) {
// static const std::map<std::type_index, MKLDNNDataType> dict{
// {std::type_index(typeid(float)), MKLDNNDataType::f32}, // NOLINT
// {std::type_index(typeid(char)), MKLDNNDataType::s8}, // NOLINT
// {std::type_index(typeid(unsigned char)), MKLDNNDataType::u8},
// {std::type_index(typeid(int16_t)), MKLDNNDataType::s16},
// {std::type_index(typeid(int32_t)), MKLDNNDataType::s32}};
// auto iter = dict.find(type);
// if (iter != dict.end()) return iter->second;
// return MKLDNNDataType::data_undef;
// }
//mkldnn::memory::data_type ToMKLDNNDataType(const std::type_index type) const override{
// static const std::map<std::type_index, mkldnn::memory::data_type> dict{
// {std::type_index(typeid(float)), mkldnn::memory::data_type::f32}, // NOLINT
// {std::type_index(typeid(char)), mkldnn::memory::data_type::s8}, // NOLINT
// {std::type_index(typeid(unsigned char)), mkldnn::memory::data_type::u8},
// {std::type_index(typeid(int16_t)), mkldnn::memory::data_type::s16},
// {std::type_index(typeid(int32_t)), mkldnn::memory::data_type::s32}};
// auto iter = dict.find(type);
// if (iter != dict.end()) return iter->second;
// return mkldnn::memory::data_type::data_undef;
//}
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
*
input
=
ctx
.
Input
<
Tensor
>
(
"Input"
);
auto
*
input
=
ctx
.
Input
<
Tensor
>
(
"Input"
);
auto
*
scale
=
ctx
.
Input
<
Tensor
>
(
"Scale"
);
auto
*
scale
=
ctx
.
Input
<
Tensor
>
(
"Scale"
);
...
@@ -77,15 +54,14 @@ class DeQuantOpKernel : public framework::OpKernel<T> {
...
@@ -77,15 +54,14 @@ class DeQuantOpKernel : public framework::OpKernel<T> {
std
::
vector
<
int
>
src_tz
=
paddle
::
framework
::
vectorize2int
(
input
->
dims
());
std
::
vector
<
int
>
src_tz
=
paddle
::
framework
::
vectorize2int
(
input
->
dims
());
std
::
vector
<
int
>
dst_tz
=
paddle
::
framework
::
vectorize2int
(
output
->
dims
());
std
::
vector
<
int
>
dst_tz
=
paddle
::
framework
::
vectorize2int
(
output
->
dims
());
mkldnn
::
memory
::
data_type
src_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
());
mkldnn
::
memory
::
data_type
src_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
());
mkldnn
::
memory
::
format
src_fmt
=
input
->
format
();
mkldnn
::
memory
::
format
src_fmt
=
memory
::
format
::
nhwc
;
//
input->format();
mkldnn
::
primitive_attr
attri
;
mkldnn
::
primitive_attr
attri
;
int
mask
=
0
;
int
mask
=
0
;
attri
.
set_output_scales
(
mask
,
scale_data
);
attri
.
set_output_scales
(
mask
,
scale_data
);
//attri.set_int_output_round_mode(round_nearest); //FIX ME
auto
src_md
=
platform
::
MKLDNNMemDesc
(
auto
src_md
=
platform
::
MKLDNNMemDesc
(
{
src_tz
},
src_dt
,
src_fmt
);
//FIX ME WITH S8
{
src_tz
},
src_dt
,
src_fmt
);
auto
src_pd
=
mkldnn
::
memory
::
primitive_desc
{
src_md
,
engine
};
auto
src_pd
=
mkldnn
::
memory
::
primitive_desc
{
src_md
,
engine
};
auto
src_memory
=
std
::
make_shared
<
mkldnn
::
memory
>
(
src_pd
,
to_void_cast
<
T
>
(
input_data
));
auto
src_memory
=
std
::
make_shared
<
mkldnn
::
memory
>
(
src_pd
,
to_void_cast
<
T
>
(
input_data
));
std
::
shared_ptr
<
primitive
::
at
>
src_memory_p
=
std
::
shared_ptr
<
primitive
::
at
>
(
new
primitive
::
at
(
*
src_memory
));
std
::
shared_ptr
<
primitive
::
at
>
src_memory_p
=
std
::
shared_ptr
<
primitive
::
at
>
(
new
primitive
::
at
(
*
src_memory
));
...
@@ -130,8 +106,8 @@ This op will quantize data from INT8 to FP32
...
@@ -130,8 +106,8 @@ This op will quantize data from INT8 to FP32
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
dequantiz
ation
,
ops
::
DeQuantOp
,
ops
::
DeQuantOpMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
);
REGISTER_OPERATOR
(
dequantiz
e
,
ops
::
DeQuantOp
,
ops
::
DeQuantOpMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
);
REGISTER_OP_CPU_KERNEL
(
dequantiz
ation
,
ops
::
DeQuantOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
dequantiz
e
,
ops
::
DeQuantOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
paddle/fluid/operators/dequantiz
ation
_op.h
→
paddle/fluid/operators/dequantiz
e
_op.h
浏览文件 @
1f3300ba
文件已移动
paddle/fluid/operators/quantiz
ation
_op.cc
→
paddle/fluid/operators/quantiz
e
_op.cc
浏览文件 @
1f3300ba
...
@@ -16,7 +16,7 @@ limitations under the License. */
...
@@ -16,7 +16,7 @@ limitations under the License. */
#include "mkldnn.hpp"
#include "mkldnn.hpp"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/operators/quantiz
ation
_op.h"
#include "paddle/fluid/operators/quantiz
e
_op.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -53,7 +53,6 @@ class QuantOpKernel : public framework::OpKernel<T> {
...
@@ -53,7 +53,6 @@ class QuantOpKernel : public framework::OpKernel<T> {
mkldnn
::
primitive_attr
attri
;
mkldnn
::
primitive_attr
attri
;
int
mask
=
0
;
int
mask
=
0
;
attri
.
set_output_scales
(
mask
,
scale_data
);
attri
.
set_output_scales
(
mask
,
scale_data
);
//attri.set_int_output_round_mode(round_nearest); //FIX ME
auto
src_md
=
platform
::
MKLDNNMemDesc
(
auto
src_md
=
platform
::
MKLDNNMemDesc
(
{
src_tz
},
memory
::
data_type
::
f32
,
input
->
format
());
{
src_tz
},
memory
::
data_type
::
f32
,
input
->
format
());
...
@@ -102,9 +101,9 @@ This op will quantize data from FP32 to INT8
...
@@ -102,9 +101,9 @@ This op will quantize data from FP32 to INT8
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
quantiz
ation
,
ops
::
QuantOp
,
ops
::
QuantOpMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
);
REGISTER_OPERATOR
(
quantiz
e
,
ops
::
QuantOp
,
ops
::
QuantOpMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
);
REGISTER_OP_CPU_KERNEL
(
quantiz
ation
,
ops
::
QuantOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
quantiz
e
,
ops
::
QuantOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
//REGISTER_OP_KERNEL(quantization, MKLDNN, paddle::platform::CPUPlace, ops::QuantOpKernel<paddle::platform::CPUDeviceContext, float>);
//REGISTER_OP_KERNEL(quantization, MKLDNN, paddle::platform::CPUPlace, ops::QuantOpKernel<paddle::platform::CPUDeviceContext, float>);
...
...
paddle/fluid/operators/quantiz
ation
_op.h
→
paddle/fluid/operators/quantiz
e
_op.h
浏览文件 @
1f3300ba
文件已移动
paddle/fluid/operators/requantiz
ation
_op.cc
→
paddle/fluid/operators/requantiz
e
_op.cc
浏览文件 @
1f3300ba
...
@@ -16,7 +16,7 @@ limitations under the License. */
...
@@ -16,7 +16,7 @@ limitations under the License. */
#include "mkldnn.hpp"
#include "mkldnn.hpp"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/operators/requantiz
ation
_op.h"
#include "paddle/fluid/operators/requantiz
e
_op.h"
#include "paddle/fluid/framework/data_layout_transform.h"
#include "paddle/fluid/framework/data_layout_transform.h"
namespace
paddle
{
namespace
paddle
{
...
@@ -48,8 +48,8 @@ class ReQuantOpKernel : public framework::OpKernel<T> {
...
@@ -48,8 +48,8 @@ class ReQuantOpKernel : public framework::OpKernel<T> {
std
::
vector
<
int
>
dst_tz
=
paddle
::
framework
::
vectorize2int
(
output
->
dims
());
std
::
vector
<
int
>
dst_tz
=
paddle
::
framework
::
vectorize2int
(
output
->
dims
());
mkldnn
::
memory
::
data_type
src_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
());
mkldnn
::
memory
::
data_type
src_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
());
mkldnn
::
memory
::
data_type
dst_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
output
->
type
());
mkldnn
::
memory
::
data_type
dst_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
output
->
type
());
mkldnn
::
memory
::
format
src_fmt
=
input
->
format
();
mkldnn
::
memory
::
format
src_fmt
=
memory
::
format
::
nhwc
;
//
input->format();
mkldnn
::
memory
::
format
dst_fmt
=
output
->
format
();
mkldnn
::
memory
::
format
dst_fmt
=
memory
::
format
::
nhwc
;
//
output->format();
const
T
*
input_data
=
input
->
data
<
T
>
();
const
T
*
input_data
=
input
->
data
<
T
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
T
*
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
@@ -107,7 +107,7 @@ This op will requantize data from INT8 to INT8
...
@@ -107,7 +107,7 @@ This op will requantize data from INT8 to INT8
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
requantiz
ation
,
ops
::
ReQuantOp
,
ops
::
ReQuantOpMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
);
REGISTER_OPERATOR
(
requantiz
e
,
ops
::
ReQuantOp
,
ops
::
ReQuantOpMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
);
REGISTER_OP_CPU_KERNEL
(
requantiz
ation
,
ops
::
ReQuantOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
requantiz
e
,
ops
::
ReQuantOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
paddle/fluid/operators/requantiz
ation
_op.h
→
paddle/fluid/operators/requantiz
e
_op.h
浏览文件 @
1f3300ba
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录