Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
56f15c43
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
56f15c43
编写于
11月 21, 2022
作者:
W
wanghuancoder
提交者:
GitHub
11月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine reduce_all (#48133)
* refine reduce_all
上级
208f625b
变更
65
隐藏空白更改
内联
并排
Showing
65 changed file
with
82 addition
and
56 deletion
+82
-56
paddle/phi/core/kernel_utils.h
paddle/phi/core/kernel_utils.h
+11
-0
paddle/phi/kernels/cpu/prod_kernel.cc
paddle/phi/kernels/cpu/prod_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce.h
paddle/phi/kernels/cpu/reduce.h
+2
-0
paddle/phi/kernels/cpu/reduce_all_kernel.cc
paddle/phi/kernels/cpu/reduce_all_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_amax_grad_kernel.cc
paddle/phi/kernels/cpu/reduce_amax_grad_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_amax_kernel.cc
paddle/phi/kernels/cpu/reduce_amax_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_amin_grad_kernel.cc
paddle/phi/kernels/cpu/reduce_amin_grad_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_amin_kernel.cc
paddle/phi/kernels/cpu/reduce_amin_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_any_kernel.cc
paddle/phi/kernels/cpu/reduce_any_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_max_kernel.cc
paddle/phi/kernels/cpu/reduce_max_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_mean_grad_kernel.cc
paddle/phi/kernels/cpu/reduce_mean_grad_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_mean_kernel.cc
paddle/phi/kernels/cpu/reduce_mean_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_min_kernel.cc
paddle/phi/kernels/cpu/reduce_min_kernel.cc
+1
-0
paddle/phi/kernels/cpu/reduce_sum_grad_kernel.cc
paddle/phi/kernels/cpu/reduce_sum_grad_kernel.cc
+1
-0
paddle/phi/kernels/funcs/reduce_function.h
paddle/phi/kernels/funcs/reduce_function.h
+1
-0
paddle/phi/kernels/gpu/frobenius_norm_kernel.cu
paddle/phi/kernels/gpu/frobenius_norm_kernel.cu
+1
-0
paddle/phi/kernels/gpu/reduce.h
paddle/phi/kernels/gpu/reduce.h
+1
-0
paddle/phi/kernels/gpu/reduce_amax_grad_kernel.cu
paddle/phi/kernels/gpu/reduce_amax_grad_kernel.cu
+1
-0
paddle/phi/kernels/gpu/reduce_amin_amax_common.h
paddle/phi/kernels/gpu/reduce_amin_amax_common.h
+1
-3
paddle/phi/kernels/gpu/reduce_amin_grad_kernel.cu
paddle/phi/kernels/gpu/reduce_amin_grad_kernel.cu
+1
-0
paddle/phi/kernels/gpu/reduce_grad.h
paddle/phi/kernels/gpu/reduce_grad.h
+1
-0
paddle/phi/kernels/gpu/reduce_mean_grad_kernel.cu
paddle/phi/kernels/gpu/reduce_mean_grad_kernel.cu
+1
-3
paddle/phi/kernels/gpu/reduce_sum_grad_kernel.cu
paddle/phi/kernels/gpu/reduce_sum_grad_kernel.cu
+1
-3
paddle/phi/kernels/impl/frobenius_norm_grad_kernel_impl.h
paddle/phi/kernels/impl/frobenius_norm_grad_kernel_impl.h
+1
-0
paddle/phi/kernels/impl/frobenius_norm_kernel_impl.h
paddle/phi/kernels/impl/frobenius_norm_kernel_impl.h
+1
-0
paddle/phi/kernels/impl/logsumexp_grad_kernel_impl.h
paddle/phi/kernels/impl/logsumexp_grad_kernel_impl.h
+1
-3
paddle/phi/kernels/impl/logsumexp_kernel_impl.h
paddle/phi/kernels/impl/logsumexp_kernel_impl.h
+1
-3
paddle/phi/kernels/impl/prod_grad_kernel_impl.h
paddle/phi/kernels/impl/prod_grad_kernel_impl.h
+1
-0
paddle/phi/kernels/impl/reduce_grad.h
paddle/phi/kernels/impl/reduce_grad.h
+3
-3
paddle/phi/kernels/impl/reduce_max_grad_kernel_impl.h
paddle/phi/kernels/impl/reduce_max_grad_kernel_impl.h
+1
-0
paddle/phi/kernels/impl/reduce_min_grad_kernel_impl.h
paddle/phi/kernels/impl/reduce_min_grad_kernel_impl.h
+1
-0
paddle/phi/kernels/kps/prod_kernel.cu
paddle/phi/kernels/kps/prod_kernel.cu
+1
-0
paddle/phi/kernels/kps/reduce_all_kernel.cu
paddle/phi/kernels/kps/reduce_all_kernel.cu
+2
-1
paddle/phi/kernels/kps/reduce_amax_kernel.cu
paddle/phi/kernels/kps/reduce_amax_kernel.cu
+1
-0
paddle/phi/kernels/kps/reduce_amin_kernel.cu
paddle/phi/kernels/kps/reduce_amin_kernel.cu
+1
-0
paddle/phi/kernels/kps/reduce_any_kernel.cu
paddle/phi/kernels/kps/reduce_any_kernel.cu
+2
-1
paddle/phi/kernels/kps/reduce_max_kernel.cu
paddle/phi/kernels/kps/reduce_max_kernel.cu
+1
-0
paddle/phi/kernels/kps/reduce_mean_kernel.cu
paddle/phi/kernels/kps/reduce_mean_kernel.cu
+1
-0
paddle/phi/kernels/kps/reduce_min_kernel.cu
paddle/phi/kernels/kps/reduce_min_kernel.cu
+1
-0
paddle/phi/kernels/kps/reduce_sum_kernel.cu
paddle/phi/kernels/kps/reduce_sum_kernel.cu
+2
-0
paddle/phi/kernels/onednn/reduce_kernel_impl.h
paddle/phi/kernels/onednn/reduce_kernel_impl.h
+2
-0
paddle/phi/kernels/onednn/reduce_max_kernel.cc
paddle/phi/kernels/onednn/reduce_max_kernel.cc
+1
-0
paddle/phi/kernels/onednn/reduce_mean_grad_kernel.cc
paddle/phi/kernels/onednn/reduce_mean_grad_kernel.cc
+1
-0
paddle/phi/kernels/onednn/reduce_mean_kernel.cc
paddle/phi/kernels/onednn/reduce_mean_kernel.cc
+1
-0
paddle/phi/kernels/onednn/reduce_min_kernel.cc
paddle/phi/kernels/onednn/reduce_min_kernel.cc
+1
-0
paddle/phi/kernels/onednn/reduce_sum_grad_kernel.cc
paddle/phi/kernels/onednn/reduce_sum_grad_kernel.cc
+1
-0
paddle/phi/kernels/onednn/reduce_sum_kernel.cc
paddle/phi/kernels/onednn/reduce_sum_kernel.cc
+1
-0
paddle/phi/kernels/prod_kernel.cc
paddle/phi/kernels/prod_kernel.cc
+1
-1
paddle/phi/kernels/reduce_all_kernel.cc
paddle/phi/kernels/reduce_all_kernel.cc
+1
-4
paddle/phi/kernels/reduce_amax_kernel.cc
paddle/phi/kernels/reduce_amax_kernel.cc
+1
-4
paddle/phi/kernels/reduce_amin_kernel.cc
paddle/phi/kernels/reduce_amin_kernel.cc
+1
-4
paddle/phi/kernels/reduce_any_kernel.cc
paddle/phi/kernels/reduce_any_kernel.cc
+1
-4
paddle/phi/kernels/reduce_max_kernel.cc
paddle/phi/kernels/reduce_max_kernel.cc
+1
-4
paddle/phi/kernels/reduce_mean_kernel.cc
paddle/phi/kernels/reduce_mean_kernel.cc
+1
-4
paddle/phi/kernels/reduce_min_kernel.cc
paddle/phi/kernels/reduce_min_kernel.cc
+1
-4
paddle/phi/kernels/reduce_sum_kernel.cc
paddle/phi/kernels/reduce_sum_kernel.cc
+1
-4
paddle/phi/kernels/xpu/prod_kernel.cc
paddle/phi/kernels/xpu/prod_kernel.cc
+1
-0
paddle/phi/kernels/xpu/reduce.h
paddle/phi/kernels/xpu/reduce.h
+1
-0
paddle/phi/kernels/xpu/reduce_max_grad_kernel.cc
paddle/phi/kernels/xpu/reduce_max_grad_kernel.cc
+1
-0
paddle/phi/kernels/xpu/reduce_max_kernel.cc
paddle/phi/kernels/xpu/reduce_max_kernel.cc
+1
-0
paddle/phi/kernels/xpu/reduce_mean_grad_kernel.cc
paddle/phi/kernels/xpu/reduce_mean_grad_kernel.cc
+1
-0
paddle/phi/kernels/xpu/reduce_mean_kernel.cc
paddle/phi/kernels/xpu/reduce_mean_kernel.cc
+1
-0
paddle/phi/kernels/xpu/reduce_min_kernel.cc
paddle/phi/kernels/xpu/reduce_min_kernel.cc
+1
-0
paddle/phi/kernels/xpu/reduce_sum_grad_kernel.cc
paddle/phi/kernels/xpu/reduce_sum_grad_kernel.cc
+1
-3
paddle/phi/kernels/xpu/reduce_sum_kernel.cc
paddle/phi/kernels/xpu/reduce_sum_kernel.cc
+1
-0
未找到文件。
paddle/phi/core/kernel_utils.h
浏览文件 @
56f15c43
...
...
@@ -336,4 +336,15 @@ struct KernelImpl<Return (*)(DevCtx, Args...), kernel_fn> {
};
};
inline
bool
recompute_reduce_all
(
const
DenseTensor
&
x
,
const
IntArray
&
dims
,
bool
reduce_all
=
false
)
{
if
(
dims
.
size
()
==
0
||
static_cast
<
int
>
(
dims
.
size
())
==
x
.
dims
().
size
()
||
reduce_all
)
{
return
true
;
}
else
{
return
false
;
}
}
}
// namespace phi
paddle/phi/kernels/cpu/prod_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void ProdRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
CPUContext
,
T
,
phi
::
funcs
::
ProdFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/cpu/reduce.h
浏览文件 @
56f15c43
...
...
@@ -30,6 +30,7 @@ void Reduce(const DeviceContext& dev_ctx,
bool
keep_dim
,
DataType
out_dtype
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
// If the dims has full dim, set the reduce_all is True
const
int
&
input_dim_size
=
x
.
dims
().
size
();
std
::
set
<
int
>
dims_set
(
dims
.
begin
(),
dims
.
end
());
...
...
@@ -71,6 +72,7 @@ void BoolReduceKernel(const DeviceContext& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
phi
::
DenseTensor
*
output
)
{
reduce_all
=
recompute_reduce_all
(
input
,
dims
,
reduce_all
);
dev_ctx
.
template
Alloc
<
OutT
>(
output
);
// The dims has full dim, set the reduce_all is True
...
...
paddle/phi/kernels/cpu/reduce_all_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void AllRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
phi
::
BoolReduceKernel
<
CPUContext
,
T
,
phi
::
funcs
::
AllFunctor
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/cpu/reduce_amax_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void ReduceAMaxGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceGradKernel
<
Context
,
T
,
funcs
::
AMaxOrAMinGradFunctor
>
(
dev_ctx
,
x
,
out
,
out_grad
,
dims
,
keep_dim
,
reduce_all
,
x_grad
);
}
...
...
paddle/phi/kernels/cpu/reduce_amax_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void AMaxRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
CPUContext
,
T
,
phi
::
funcs
::
MaxFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
,
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/cpu/reduce_amin_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void ReduceAMinGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceGradKernel
<
Context
,
T
,
funcs
::
AMaxOrAMinGradFunctor
>
(
dev_ctx
,
x
,
out
,
out_grad
,
dims
,
keep_dim
,
reduce_all
,
x_grad
);
}
...
...
paddle/phi/kernels/cpu/reduce_amin_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void AMinRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
CPUContext
,
T
,
phi
::
funcs
::
MinFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
,
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/cpu/reduce_any_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void AnyRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
phi
::
BoolReduceKernel
<
CPUContext
,
T
,
phi
::
funcs
::
AnyFunctor
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/cpu/reduce_max_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void MaxRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
CPUContext
,
T
,
phi
::
funcs
::
MaxFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/cpu/reduce_mean_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void ReduceMeanGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceGradKernel
<
Context
,
T
,
funcs
::
MeanGradFunctor
,
true
>
(
dev_ctx
,
x
,
paddle
::
none
,
...
...
paddle/phi/kernels/cpu/reduce_mean_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void MeanRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
CPUContext
,
T
,
phi
::
funcs
::
MeanFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/cpu/reduce_min_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void MinRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
CPUContext
,
T
,
phi
::
funcs
::
MinFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/cpu/reduce_sum_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -77,6 +77,7 @@ void ReduceSumGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
if
(
dims
.
size
()
==
1
)
{
if
(
out_grad
.
dtype
()
!=
x
.
dtype
())
{
DenseTensorMeta
x_grad_meta
(
...
...
paddle/phi/kernels/funcs/reduce_function.h
浏览文件 @
56f15c43
...
...
@@ -58,6 +58,7 @@ using dim3 = phi::kps::dim3;
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/kernel_utils.h"
#include "paddle/phi/core/utils/array.h"
#include "paddle/phi/kernels/funcs/eigen/common.h"
#include "paddle/phi/kernels/funcs/eigen/eigen_function.h"
...
...
paddle/phi/kernels/gpu/frobenius_norm_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -26,6 +26,7 @@ void FrobeniusNormKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
AddFunctor
,
kps
::
SquareFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
,
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/gpu/reduce.h
浏览文件 @
56f15c43
...
...
@@ -36,6 +36,7 @@ void Reduce(const KPDevice& dev_ctx,
DataType
out_dtype
,
DenseTensor
*
out
,
bool
is_mean
=
false
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
std
::
vector
<
int
>
reduce_dims
=
phi
::
funcs
::
details
::
GetReduceDim
(
dims
,
x
.
dims
().
size
(),
reduce_all
);
...
...
paddle/phi/kernels/gpu/reduce_amax_grad_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void ReduceAMaxGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceCudaAMaxAMinGrad
<
T
,
Context
>
(
dev_ctx
,
x
,
out
,
out_grad
,
dims
,
keep_dim
,
reduce_all
,
x_grad
);
}
...
...
paddle/phi/kernels/gpu/reduce_amin_amax_common.h
浏览文件 @
56f15c43
...
...
@@ -32,15 +32,13 @@ void ReduceCudaAMaxAMinGrad(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
*
in_x
=
&
x
;
auto
*
out_y
=
&
out
;
auto
*
d_out
=
&
out_grad
;
auto
*
d_x
=
x_grad
;
// get reduce_dim and reduce_num for reduce_mean_grad
int
dim_size
=
in_x
->
dims
().
size
();
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
auto
reduce_dims
=
funcs
::
details
::
GetReduceDim
(
dims
,
dim_size
,
reduce_all
);
auto
update_dims
=
vectorize
(
d_x
->
dims
());
int
reduce_num
=
1
;
...
...
paddle/phi/kernels/gpu/reduce_amin_grad_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -29,6 +29,7 @@ void ReduceAMinGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceCudaAMaxAMinGrad
<
T
,
Context
>
(
dev_ctx
,
x
,
out
,
out_grad
,
dims
,
keep_dim
,
reduce_all
,
x_grad
);
}
...
...
paddle/phi/kernels/gpu/reduce_grad.h
浏览文件 @
56f15c43
...
...
@@ -52,6 +52,7 @@ void ReduceGradKernel(const Context& dev_ctx,
bool
reduce_all
,
DenseTensor
*
x_grad
,
Functor
functor
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
*
in_x
=
&
x
;
auto
*
d_out
=
&
out_grad
;
auto
*
d_x
=
x_grad
;
...
...
paddle/phi/kernels/gpu/reduce_mean_grad_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -29,11 +29,9 @@ void ReduceMeanGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
// get reduce_dim and reduce_num for reduce_mean_grad
int
dim_size
=
x
.
dims
().
size
();
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
std
::
vector
<
int
>
reduce_dims
=
funcs
::
details
::
GetReduceDim
(
dims
.
GetData
(),
dim_size
,
reduce_all
);
...
...
paddle/phi/kernels/gpu/reduce_sum_grad_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -29,11 +29,9 @@ void ReduceSumGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
// get reduce_dim for reduce_mean_grad
int
dim_size
=
x
.
dims
().
size
();
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
std
::
vector
<
int
>
reduce_dims
=
funcs
::
details
::
GetReduceDim
(
dims
.
GetData
(),
dim_size
,
reduce_all
);
...
...
paddle/phi/kernels/impl/frobenius_norm_grad_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -29,6 +29,7 @@ void FrobeniusNormGradKernel(const Context& ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
dx
)
{
reduce_all
=
recompute_reduce_all
(
x
,
axis
,
reduce_all
);
ReduceGradKernel
<
Context
,
T
,
funcs
::
FrobeniusNormGradFunctor
>
(
ctx
,
x
,
out
,
dout
,
axis
,
keep_dim
,
reduce_all
,
dx
);
}
...
...
paddle/phi/kernels/impl/frobenius_norm_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -27,6 +27,7 @@ void FrobeniusNormKernel(const Context& ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
axis
,
reduce_all
);
Reduce
<
Context
,
T
,
funcs
::
FrobeniusNormFunctor
>
(
ctx
,
x
,
reduce_all
,
axis
,
keep_dim
,
x
.
dtype
(),
out
);
}
...
...
paddle/phi/kernels/impl/logsumexp_grad_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -60,9 +60,7 @@ void LogsumexpGradKernel(const Context& dev_ctx,
DenseTensor
*
in_grad
)
{
dev_ctx
.
template
Alloc
<
T
>(
in_grad
);
if
(
axis
.
size
()
==
0
||
static_cast
<
int
>
(
axis
.
size
())
==
in
.
dims
().
size
())
{
reduce_all
=
true
;
}
reduce_all
=
recompute_reduce_all
(
in
,
axis
,
reduce_all
);
if
(
reduce_all
)
{
auto
x
=
phi
::
EigenVector
<
T
>::
Flatten
(
in
);
...
...
paddle/phi/kernels/impl/logsumexp_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -69,9 +69,7 @@ void LogsumexpKernel(const Context& dev_ctx,
DenseTensor
*
out
)
{
dev_ctx
.
template
Alloc
<
T
>(
out
);
if
(
axis
.
size
()
==
0
||
static_cast
<
int
>
(
axis
.
size
())
==
x
.
dims
().
size
())
{
reduce_all
=
true
;
}
reduce_all
=
recompute_reduce_all
(
x
,
axis
,
reduce_all
);
if
(
reduce_all
)
{
// Flatten and reduce 1-D tensor
...
...
paddle/phi/kernels/impl/prod_grad_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -30,6 +30,7 @@ void ProdGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceGradKernel
<
Context
,
T
,
funcs
::
ProdGradFunctor
>
(
dev_ctx
,
x
,
out
,
out_grad
,
dims
.
GetData
(),
keep_dim
,
reduce_all
,
x_grad
);
}
...
...
paddle/phi/kernels/impl/reduce_grad.h
浏览文件 @
56f15c43
...
...
@@ -34,6 +34,7 @@ void ComputeFromInput(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
*
input0
=
&
x
;
auto
*
input1
=
out
.
get_ptr
();
auto
*
output
=
x_grad
;
...
...
@@ -91,9 +92,8 @@ void ReduceGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
if
(
x
.
dtype
()
!=
out_grad
.
dtype
())
{
DenseTensorMeta
x_grad_meta
(
out_grad
.
dtype
(),
x_grad
->
dims
(),
x_grad
->
layout
());
...
...
paddle/phi/kernels/impl/reduce_max_grad_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -29,6 +29,7 @@ void ReduceMaxGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceGradKernel
<
Context
,
T
,
funcs
::
MaxOrMinGradFunctor
>
(
dev_ctx
,
x
,
out
,
out_grad
,
dims
.
GetData
(),
keep_dim
,
reduce_all
,
x_grad
);
}
...
...
paddle/phi/kernels/impl/reduce_min_grad_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -29,6 +29,7 @@ void ReduceMinGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceGradKernel
<
Context
,
T
,
funcs
::
MaxOrMinGradFunctor
>
(
dev_ctx
,
x
,
out
,
out_grad
,
dims
.
GetData
(),
keep_dim
,
reduce_all
,
x_grad
);
}
...
...
paddle/phi/kernels/kps/prod_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void ProdRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
MulFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/kps/reduce_all_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/reduce_all_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/gpu/reduce.h"
#include "paddle/phi/kernels/reduce_all_kernel.h"
namespace
phi
{
...
...
@@ -25,6 +25,7 @@ void AllRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
LogicalAndFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
,
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/kps/reduce_amax_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void AMaxRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
MaxFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
,
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/kps/reduce_amin_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void AMinRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
MinFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
,
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/kps/reduce_any_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/reduce_any_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/gpu/reduce.h"
#include "paddle/phi/kernels/reduce_any_kernel.h"
namespace
phi
{
...
...
@@ -25,6 +25,7 @@ void AnyRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
LogicalOrFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
,
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/kps/reduce_max_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void MaxRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
MaxFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/kps/reduce_mean_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void MeanRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
AddFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
,
true
);
...
...
paddle/phi/kernels/kps/reduce_min_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void MinRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
out_dtype
=
x
.
dtype
();
phi
::
Reduce
<
T
,
kps
::
MinFunctor
,
kps
::
IdentityFunctor
>
(
dev_ctx
,
x
,
reduce_all
,
dims
.
GetData
(),
keep_dim
,
out_dtype
,
out
);
...
...
paddle/phi/kernels/kps/reduce_sum_kernel.cu
浏览文件 @
56f15c43
...
...
@@ -35,6 +35,7 @@ void ReduceSumEigen(const KPDevice& dev_ctx,
DataType
out_dtype
,
DenseTensor
*
out
,
std
::
vector
<
int
>*
reduce_dims
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
// Resize Input Tensor
auto
new_x
=
x
;
int
added_dims
=
EigenDimSize
-
x
.
dims
().
size
();
...
...
@@ -79,6 +80,7 @@ void SumRawKernel(const Context& dev_ctx,
bool
reduce_all
,
DataType
out_dtype
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
if
(
out_dtype
==
DataType
::
UNDEFINED
&&
out
->
dtype
()
!=
x
.
dtype
())
{
out_dtype
=
out
->
dtype
();
}
...
...
paddle/phi/kernels/onednn/reduce_kernel_impl.h
浏览文件 @
56f15c43
...
...
@@ -46,6 +46,7 @@ void ReduceKernel(const Context& dev_ctx,
bool
reduce_all
,
DenseTensor
*
out
,
dnnl
::
algorithm
reduction_type
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
const
auto
&
onednn_engine
=
dev_ctx
.
GetEngine
();
auto
x_tz
=
vectorize
(
x
.
dims
());
auto
out_tz
=
...
...
@@ -116,6 +117,7 @@ void ReduceGradKernel(const Context& dev_ctx,
dnnl
::
algorithm
reduction_type
,
float
scale_x
,
float
scale_y
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
const
auto
&
onednn_engine
=
dev_ctx
.
GetEngine
();
auto
out_grad_tz
=
CalculateReducedDims
(
x_grad
,
&
out_grad
,
dims
.
GetData
(),
reduce_all
,
keep_dim
);
...
...
paddle/phi/kernels/onednn/reduce_max_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -24,6 +24,7 @@ void MaxRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
dims
,
...
...
paddle/phi/kernels/onednn/reduce_mean_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void MeanGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
auto
input_dims
=
phi
::
vectorize
(
x
.
dims
());
std
::
vector
<
int64_t
>
reduce_dims
=
dims
.
GetData
();
int
number_of_elements
=
1
;
...
...
paddle/phi/kernels/onednn/reduce_mean_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -24,6 +24,7 @@ void MeanRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
dims
,
...
...
paddle/phi/kernels/onednn/reduce_min_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -24,6 +24,7 @@ void MinRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
dims
,
...
...
paddle/phi/kernels/onednn/reduce_sum_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void SumGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceGradKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
out_grad
,
...
...
paddle/phi/kernels/onednn/reduce_sum_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,6 +25,7 @@ void SumRawKernel(const Context& dev_ctx,
bool
reduce_all
,
DataType
out_dtype
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
ReduceKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
dims
,
...
...
paddle/phi/kernels/prod_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,7 +25,7 @@ void ProdKernel(const Context& dev_ctx,
const
IntArray
&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
bool
reduce_all
=
false
;
// recompute_reduce_all(x, dims);
ProdRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_all_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,10 +25,7 @@ void AllKernel(const Context& dev_ctx,
const
std
::
vector
<
int64_t
>&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
||
static_cast
<
int
>
(
dims
.
size
())
==
x
.
dims
().
size
())
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
AllRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_amax_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,10 +25,7 @@ void AMaxKernel(const Context& dev_ctx,
const
std
::
vector
<
int64_t
>&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
AMaxRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_amin_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,10 +25,7 @@ void AMinKernel(const Context& dev_ctx,
const
std
::
vector
<
int64_t
>&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
AMinRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_any_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,10 +25,7 @@ void AnyKernel(const Context& dev_ctx,
const
std
::
vector
<
int64_t
>&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
||
static_cast
<
int
>
(
dims
.
size
())
==
x
.
dims
().
size
())
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
AnyRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_max_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,10 +25,7 @@ void MaxKernel(const Context& dev_ctx,
const
IntArray
&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
||
static_cast
<
int
>
(
dims
.
size
())
==
x
.
dims
().
size
())
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
MaxRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_mean_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,10 +25,7 @@ void MeanKernel(const Context& dev_ctx,
const
IntArray
&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
MeanRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_min_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -25,10 +25,7 @@ void MinKernel(const Context& dev_ctx,
const
IntArray
&
dims
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
||
static_cast
<
int
>
(
dims
.
size
())
==
x
.
dims
().
size
())
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
MinRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
paddle/phi/kernels/reduce_sum_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -26,10 +26,7 @@ void SumKernel(const Context& dev_ctx,
DataType
out_dtype
,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
false
;
if
(
dims
.
size
()
==
0
)
{
reduce_all
=
true
;
}
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
SumRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out_dtype
,
out
);
}
...
...
paddle/phi/kernels/xpu/prod_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void ProdRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
int
r
=
XPUReduce
<
Context
,
T
>
(
dev_ctx
,
x
,
dims
.
GetData
(),
...
...
paddle/phi/kernels/xpu/reduce.h
浏览文件 @
56f15c43
...
...
@@ -33,6 +33,7 @@ int XPUReduce(const Context& dev_ctx,
T
*
,
const
std
::
vector
<
int
>&
,
const
std
::
vector
<
int
>&
)
>
func
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
dev_ctx
.
template
Alloc
<
T
>(
out
);
const
auto
*
x_data
=
x
.
data
<
T
>
();
...
...
paddle/phi/kernels/xpu/reduce_max_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -31,6 +31,7 @@ void ReduceMaxGradKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims_arr
,
reduce_all
);
auto
dims
=
dims_arr
.
GetData
();
dev_ctx
.
template
Alloc
<
T
>(
x_grad
);
...
...
paddle/phi/kernels/xpu/reduce_max_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void MaxRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
int
r
=
XPUReduce
<
Context
,
T
>
(
dev_ctx
,
x
,
dims
.
GetData
(),
...
...
paddle/phi/kernels/xpu/reduce_mean_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -31,6 +31,7 @@ void ReduceMeanGradKernel(const Context& dev_ctx,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
reduce_all
=
recompute_reduce_all
(
x
,
dims_arr
,
reduce_all
);
dev_ctx
.
template
Alloc
<
T
>(
x_grad
);
const
XPUType
*
dy_data
=
reinterpret_cast
<
const
XPUType
*>
(
out_grad
.
data
<
T
>
());
...
...
paddle/phi/kernels/xpu/reduce_mean_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void MeanRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
int
r
=
XPUReduce
<
Context
,
T
>
(
dev_ctx
,
x
,
dims
.
GetData
(),
...
...
paddle/phi/kernels/xpu/reduce_min_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,6 +28,7 @@ void MinRawKernel(const Context& dev_ctx,
bool
keep_dim
,
bool
reduce_all
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
int
r
=
XPUReduce
<
Context
,
T
>
(
dev_ctx
,
x
,
dims
.
GetData
(),
...
...
paddle/phi/kernels/xpu/reduce_sum_grad_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -28,13 +28,11 @@ void ReduceSumGradKernel(const Context& dev_ctx,
bool
reduce_all
,
DenseTensor
*
x_grad
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
reduce_all
=
recompute_reduce_all
(
x
,
dims_arr
,
reduce_all
);
auto
dims
=
dims_arr
.
GetData
();
dev_ctx
.
template
Alloc
<
XPUType
>(
x_grad
);
const
auto
*
out_data
=
out_grad
.
data
<
XPUType
>
();
auto
*
x_grad_data
=
x_grad
->
data
<
XPUType
>
();
if
(
dims_arr
.
size
()
==
0
)
{
reduce_all
=
true
;
}
const
auto
&
input_dim_size
=
x
.
dims
().
size
();
std
::
vector
<
int
>
true_dims
;
for
(
size_t
i
=
0
;
i
<
dims
.
size
();
++
i
)
{
...
...
paddle/phi/kernels/xpu/reduce_sum_kernel.cc
浏览文件 @
56f15c43
...
...
@@ -29,6 +29,7 @@ void SumRawKernel(const Context& dev_ctx,
bool
reduce_all
,
DataType
out_dtype
,
DenseTensor
*
out
)
{
reduce_all
=
recompute_reduce_all
(
x
,
dims
,
reduce_all
);
int
r
=
XPUReduce
<
Context
,
T
>
(
dev_ctx
,
x
,
dims
.
GetData
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录