Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f5565494
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看板
未验证
提交
f5565494
编写于
10月 11, 2022
作者:
C
ceci3
提交者:
GitHub
10月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
speedup ChannelClipAndQuantDequantKernelQuantAxis1 kernel (#46471) (#46551)
上级
9cc3f69f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
45 deletion
+47
-45
paddle/fluid/operators/fake_quantize_op.cu.h
paddle/fluid/operators/fake_quantize_op.cu.h
+47
-45
未找到文件。
paddle/fluid/operators/fake_quantize_op.cu.h
浏览文件 @
f5565494
...
@@ -590,20 +590,16 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis0(const T *in,
...
@@ -590,20 +590,16 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis0(const T *in,
const
T
*
scale
,
const
T
*
scale
,
const
int
bin_cnt
,
const
int
bin_cnt
,
const
int
round_type
,
const
int
round_type
,
const
int
n
,
const
int
wh_size
,
const
int
c
,
const
int
num
,
const
int
cout
,
T
*
out
)
{
T
*
out
)
{
int
tid
=
threadIdx
.
x
;
int64_t
idx
=
blockDim
.
x
*
blockIdx
.
x
+
threadIdx
.
x
;
int
channel_size
=
n
/
c
;
const
T
*
in_c
=
in
+
blockIdx
.
x
*
channel_size
;
T
*
out_c
=
out
+
blockIdx
.
x
*
channel_size
;
T
s
=
scale
[
blockIdx
.
x
];
T
inv_s
=
inverse
(
s
);
for
(
int
i
=
tid
;
i
<
channel_size
;
i
+=
blockDim
.
x
)
{
for
(
int64_t
i
=
idx
;
i
<
num
;
i
+=
blockDim
.
x
*
gridDim
.
x
)
{
T
x
=
in_c
[
i
];
T
s
=
scale
[(
i
/
wh_size
)
%
cout
];
T
inv_s
=
inverse
(
s
);
T
x
=
in
[
i
];
if
(
round_type
==
0
)
{
if
(
round_type
==
0
)
{
x
=
bin_cnt
*
inv_s
*
x
;
x
=
bin_cnt
*
inv_s
*
x
;
x
=
roundWithTiesToEven
(
x
);
x
=
roundWithTiesToEven
(
x
);
...
@@ -611,12 +607,12 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis0(const T *in,
...
@@ -611,12 +607,12 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis0(const T *in,
T
min_bound
=
-
bin_cnt
-
static_cast
<
T
>
(
1
);
T
min_bound
=
-
bin_cnt
-
static_cast
<
T
>
(
1
);
x
=
x
>
max_bound
?
max_bound
:
x
;
x
=
x
>
max_bound
?
max_bound
:
x
;
x
=
x
<
min_bound
?
min_bound
:
x
;
x
=
x
<
min_bound
?
min_bound
:
x
;
out
_c
[
i
]
=
(
x
*
s
)
/
bin_cnt
;
out
[
i
]
=
(
x
*
s
)
/
bin_cnt
;
}
else
{
}
else
{
T
v
=
x
>
s
?
s
:
x
;
T
v
=
x
>
s
?
s
:
x
;
v
=
v
<
-
s
?
-
s
:
v
;
v
=
v
<
-
s
?
-
s
:
v
;
v
=
bin_cnt
*
inv_s
*
v
;
v
=
bin_cnt
*
inv_s
*
v
;
out
_c
[
i
]
=
round
(
v
)
*
s
/
bin_cnt
;
out
[
i
]
=
round
(
v
)
*
s
/
bin_cnt
;
}
}
}
}
}
}
...
@@ -627,19 +623,16 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis1(const T *in,
...
@@ -627,19 +623,16 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis1(const T *in,
const
T
*
scale
,
const
T
*
scale
,
const
int
bin_cnt
,
const
int
bin_cnt
,
const
int
round_type
,
const
int
round_type
,
const
int
n
,
const
int
wh_size
,
const
int
cin
,
const
int
num
,
const
int
cout
,
const
int
cout
,
T
*
out
)
{
T
*
out
)
{
T
s
=
scale
[
blockIdx
.
x
%
cout
];
int64_t
idx
=
blockDim
.
x
*
blockIdx
.
x
+
threadIdx
.
x
;
T
inv_s
=
inverse
(
s
);
int
wh_size
=
n
/
(
cin
*
cout
);
const
T
*
in_c
=
in
+
blockIdx
.
x
*
wh_size
;
T
*
out_c
=
out
+
blockIdx
.
x
*
wh_size
;
for
(
int
i
=
threadIdx
.
x
;
i
<
wh_size
;
i
+=
blockDim
.
x
)
{
for
(
int64_t
i
=
idx
;
i
<
num
;
i
+=
blockDim
.
x
*
gridDim
.
x
)
{
T
x
=
in_c
[
i
];
T
s
=
scale
[(
i
/
wh_size
)
%
cout
];
T
inv_s
=
inverse
(
s
);
T
x
=
in
[
i
];
if
(
round_type
==
0
)
{
if
(
round_type
==
0
)
{
x
=
bin_cnt
*
inv_s
*
x
;
x
=
bin_cnt
*
inv_s
*
x
;
x
=
roundWithTiesToEven
(
x
);
x
=
roundWithTiesToEven
(
x
);
...
@@ -647,12 +640,12 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis1(const T *in,
...
@@ -647,12 +640,12 @@ __global__ void ChannelClipAndQuantDequantKernelQuantAxis1(const T *in,
T
min_bound
=
-
bin_cnt
-
static_cast
<
T
>
(
1
);
T
min_bound
=
-
bin_cnt
-
static_cast
<
T
>
(
1
);
x
=
x
>
max_bound
?
max_bound
:
x
;
x
=
x
>
max_bound
?
max_bound
:
x
;
x
=
x
<
min_bound
?
min_bound
:
x
;
x
=
x
<
min_bound
?
min_bound
:
x
;
out
_c
[
i
]
=
(
x
*
s
)
/
bin_cnt
;
out
[
i
]
=
(
x
*
s
)
/
bin_cnt
;
}
else
{
}
else
{
T
v
=
x
>
s
?
s
:
x
;
T
v
=
x
>
s
?
s
:
x
;
v
=
v
<
-
s
?
-
s
:
v
;
v
=
v
<
-
s
?
-
s
:
v
;
v
=
bin_cnt
*
inv_s
*
v
;
v
=
bin_cnt
*
inv_s
*
v
;
out
_c
[
i
]
=
round
(
v
)
*
s
/
bin_cnt
;
out
[
i
]
=
round
(
v
)
*
s
/
bin_cnt
;
}
}
}
}
}
}
...
@@ -682,30 +675,39 @@ struct ChannelClipFakeQuantDequantFunctor<phi::GPUContext, T> {
...
@@ -682,30 +675,39 @@ struct ChannelClipFakeQuantDequantFunctor<phi::GPUContext, T> {
const
T
*
scale_data
=
scale
.
data
<
T
>
();
const
T
*
scale_data
=
scale
.
data
<
T
>
();
T
*
out_data
=
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
T
*
out_data
=
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
int64_t
block_size
=
std
::
min
(
static_cast
<
int64_t
>
(
num
),
static_cast
<
int64_t
>
(
ctx
.
GetMaxThreadsPerBlock
()
/
4
));
int64_t
max_threads
=
ctx
.
GetMaxPhysicalThreadCount
();
// SM * block_per_SM
const
int64_t
max_blocks
=
std
::
max
(((
max_threads
-
1
)
/
block_size
+
1
),
static_cast
<
int64_t
>
(
1
));
const
int64_t
grid_size
=
std
::
min
(
max_blocks
,
(
num
+
block_size
-
1
)
/
block_size
);
if
(
quant_axis
==
0
)
{
if
(
quant_axis
==
0
)
{
int
grid
=
in_dims
[
0
];
const
int
window_size
=
num
/
in_dims
[
0
];
int
block
=
1024
;
ChannelClipAndQuantDequantKernelQuantAxis0
<
T
>
ChannelClipAndQuantDequantKernelQuantAxis0
<
T
>
<<<
grid
,
block
,
0
,
ctx
.
stream
()
>>>
(
in_data
,
<<<
grid_size
,
block_size
,
0
,
ctx
.
stream
()
>>>
(
in_data
,
scale_data
,
scale_data
,
bin_cnt
,
bin_cnt
,
round_type
,
round_type
,
num
,
window_size
,
in_dims
[
0
],
num
,
out_data
);
in_dims
[
0
],
out_data
);
}
else
if
(
quant_axis
==
1
)
{
}
else
if
(
quant_axis
==
1
)
{
int
grid
=
in_dims
[
0
]
*
in_dims
[
1
];
const
int
window_size
=
num
/
(
in_dims
[
0
]
*
in_dims
[
1
]);
int
block
=
1024
;
ChannelClipAndQuantDequantKernelQuantAxis1
<
T
>
ChannelClipAndQuantDequantKernelQuantAxis1
<
T
>
<<<
grid
,
block
,
0
,
ctx
.
stream
()
>>>
(
in_data
,
<<<
grid
_size
,
block_size
,
0
,
ctx
.
stream
()
>>>
(
in_data
,
scale_data
,
scale_data
,
bin_cnt
,
bin_cnt
,
round_type
,
round_type
,
num
,
window_size
,
in_dims
[
0
]
,
num
,
in_dims
[
1
],
in_dims
[
1
],
out_data
);
out_data
);
}
}
}
}
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录