Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions paddle/phi/kernels/cpu/pool_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/pool_grad_kernel_impl.h"

PD_REGISTER_KERNEL(
pool2d_grad, CPU, ALL_LAYOUT, phi::Pool2dGradKernel, float, double) {}
PD_REGISTER_KERNEL(pool2d_grad,
CPU,
ALL_LAYOUT,
phi::Pool2dGradKernel,
float,
double,
phi::dtype::float16) {}
PD_REGISTER_KERNEL(
lp_pool2d_grad, CPU, ALL_LAYOUT, phi::LPPool2dGradKernel, float, double) {}
PD_REGISTER_KERNEL(pool2d_double_grad,
Expand All @@ -36,8 +41,13 @@ PD_REGISTER_KERNEL(max_pool2d_with_index_grad,
kernel->InputAt(1).SetDataType(phi::CppTypeToDataType<int>::Type());
}

PD_REGISTER_KERNEL(
pool3d_grad, CPU, ALL_LAYOUT, phi::Pool3dGradKernel, float, double) {}
PD_REGISTER_KERNEL(pool3d_grad,
CPU,
ALL_LAYOUT,
phi::Pool3dGradKernel,
float,
double,
phi::dtype::float16) {}
PD_REGISTER_KERNEL(max_pool3d_with_index_grad,
CPU,
ALL_LAYOUT,
Expand Down
16 changes: 14 additions & 2 deletions paddle/phi/kernels/cpu/pool_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/pool_kernel_impl.h"

PD_REGISTER_KERNEL(pool2d, CPU, ALL_LAYOUT, phi::Pool2dKernel, float, double) {}
PD_REGISTER_KERNEL(pool2d,
CPU,
ALL_LAYOUT,
phi::Pool2dKernel,
float,
double,
phi::dtype::float16) {}
PD_REGISTER_KERNEL(
lp_pool2d, CPU, ALL_LAYOUT, phi::LPPool2dKernel, float, double) {}
PD_REGISTER_KERNEL(max_pool2d_with_index,
Expand All @@ -29,7 +35,13 @@ PD_REGISTER_KERNEL(max_pool2d_with_index,
kernel->OutputAt(1).SetDataType(phi::CppTypeToDataType<int>::Type());
}

PD_REGISTER_KERNEL(pool3d, CPU, ALL_LAYOUT, phi::Pool3dKernel, float, double) {}
PD_REGISTER_KERNEL(pool3d,
CPU,
ALL_LAYOUT,
phi::Pool3dKernel,
float,
double,
phi::dtype::float16) {}
PD_REGISTER_KERNEL(max_pool3d_with_index,
CPU,
ALL_LAYOUT,
Expand Down
36 changes: 36 additions & 0 deletions paddle/phi/kernels/funcs/pooling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ class MaxPool2dGradFunctor<CPUContext, T> {
template class MaxPool2dGradFunctor<CPUContext, float>;
template class MaxPool2dGradFunctor<CPUContext, double>;

template class MaxPool2dGradFunctor<CPUContext, dtype::float16>;

template class Pool2dFunctor<CPUContext, MaxPool<float>, float>;
template class Pool2dFunctor<CPUContext, AvgPool<float>, float>;
template class Pool2dFunctor<CPUContext, LPPool<float>, float>;
Expand All @@ -477,6 +479,24 @@ template class Pool2dGradFunctor<CPUContext, MaxPoolGrad<double>, double>;
template class Pool2dGradFunctor<CPUContext, AvgPoolGrad<double>, double>;
template class Pool2dGradFunctor<CPUContext, LPPoolGrad<double>, double>;

template class Pool2dFunctor<phi::CPUContext,
MaxPool<dtype::float16>,
dtype::float16>;
template class Pool2dFunctor<phi::CPUContext,
AvgPool<dtype::float16>,
dtype::float16>;
template class Pool2dFunctor<phi::CPUContext,
LPPool<dtype::float16>,
dtype::float16>;
template class Pool2dGradFunctor<phi::CPUContext,
MaxPoolGrad<dtype::float16>,
dtype::float16>;
template class Pool2dGradFunctor<phi::CPUContext,
AvgPoolGrad<dtype::float16>,
dtype::float16>;
template class Pool2dGradFunctor<phi::CPUContext,
LPPoolGrad<dtype::float16>,
dtype::float16>;
/*
* Tensors are in NCDHW or NDHWC format.
* Ksize, strides, paddings are three elements. These three elements represent
Expand Down Expand Up @@ -1057,6 +1077,7 @@ class MaxPool3dGradFunctor<CPUContext, T> {
};
template class MaxPool3dGradFunctor<CPUContext, float>;
template class MaxPool3dGradFunctor<CPUContext, double>;
template class MaxPool3dGradFunctor<CPUContext, dtype::float16>;

template class Pool3dFunctor<CPUContext, MaxPool<float>, float>;
template class Pool3dFunctor<CPUContext, AvgPool<float>, float>;
Expand All @@ -1067,6 +1088,21 @@ template class Pool3dFunctor<CPUContext, AvgPool<double>, double>;
template class Pool3dGradFunctor<CPUContext, MaxPoolGrad<double>, double>;
template class Pool3dGradFunctor<CPUContext, AvgPoolGrad<double>, double>;

template class Pool3dFunctor<phi::CPUContext,
MaxPool<dtype::float16>,
dtype::float16>;
template class Pool3dFunctor<phi::CPUContext,
AvgPool<dtype::float16>,
dtype::float16>;
template class Pool3dFunctor<phi::CPUContext,
LPPool<dtype::float16>,
dtype::float16>;
template class Pool3dGradFunctor<phi::CPUContext,
MaxPoolGrad<dtype::float16>,
dtype::float16>;
template class Pool3dGradFunctor<phi::CPUContext,
AvgPoolGrad<dtype::float16>,
dtype::float16>;
/*
* All tensors are in NCHW format.
* Ksize, strides, paddings are two elements. These two elements represent
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/gpudnn/pool_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void Pool3dGPUDNNKernel(const Context& dev_ctx,
const std::string& padding_algorithm,
DenseTensor* out) {
if (x.numel() == 0) {
if (pooling_type == "max" || pooling_type == "avg") {
if (pooling_type == "max") {
phi::Full<T, Context>(
dev_ctx, phi::IntArray(common::vectorize(out->dims())), 0, out);
} else {
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/impl/pool_kernel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void Pool3dKernel(const Context& dev_ctx,
const std::string& padding_algorithm,
DenseTensor* out) {
if (x.numel() == 0) {
if (pooling_type == "max" || pooling_type == "avg") {
if (pooling_type == "max") {
phi::Full<T, Context>(
dev_ctx, phi::IntArray(common::vectorize(out->dims())), 0, out);
} else {
Expand Down