Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9e307229
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9e307229
编写于
7月 19, 2022
作者:
Z
zhangkaihuo
提交者:
GitHub
7月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Standard name of sparse pool (#44344)
上级
f382eb06
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
152 addition
and
152 deletion
+152
-152
paddle/phi/api/yaml/sparse_api.yaml
paddle/phi/api/yaml/sparse_api.yaml
+2
-2
paddle/phi/api/yaml/sparse_bw_api.yaml
paddle/phi/api/yaml/sparse_bw_api.yaml
+8
-8
paddle/phi/kernels/sparse/cpu/pool_grad_kernel.cc
paddle/phi/kernels/sparse/cpu/pool_grad_kernel.cc
+19
-19
paddle/phi/kernels/sparse/cpu/pool_kernel.cc
paddle/phi/kernels/sparse/cpu/pool_kernel.cc
+28
-28
paddle/phi/kernels/sparse/gpu/pool_grad_kernel.cu
paddle/phi/kernels/sparse/gpu/pool_grad_kernel.cu
+19
-19
paddle/phi/kernels/sparse/gpu/pool_kernel.cu
paddle/phi/kernels/sparse/gpu/pool_kernel.cu
+28
-28
paddle/phi/kernels/sparse/pool_grad_kernel.h
paddle/phi/kernels/sparse/pool_grad_kernel.h
+14
-14
paddle/phi/kernels/sparse/pool_kernel.h
paddle/phi/kernels/sparse/pool_kernel.h
+16
-16
paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc
paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc
+18
-18
未找到文件。
paddle/phi/api/yaml/sparse_api.yaml
浏览文件 @
9e307229
...
...
@@ -316,10 +316,10 @@
args
:
(Tensor x, int[] kernel_sizes, int[] paddings, int[] dilations, int[] strides)
output
:
Tensor(out), Tensor(rulebook)
kernel
:
func
:
sparse_maxpool
{sparse_coo -> sparse_coo, dense}
func
:
maxpool_coo
{sparse_coo -> sparse_coo, dense}
layout
:
x
intermediate
:
rulebook
backward
:
sparse_
maxpool_grad
backward
:
maxpool_grad
-
api
:
mv
args
:
(Tensor x, Tensor vec)
...
...
paddle/phi/api/yaml/sparse_bw_api.yaml
浏览文件 @
9e307229
...
...
@@ -137,6 +137,13 @@
matmul_coo_dense_grad {sparse_coo, dense, dense -> sparse_coo, dense},
matmul_coo_coo_grad {sparse_coo, sparse_coo, sparse_coo -> sparse_coo, sparse_coo}
-
backward_api
:
maxpool_grad
forward
:
maxpool(Tensor x, int[] kernel_sizes, int[] paddings, int[] dilations, int[] strides) -> Tensor(out), Tensor(rulebook)
args
:
(Tensor x, Tensor rulebook, Tensor out, Tensor out_grad, int[] kernel_sizes)
output
:
Tensor(x_grad)
kernel
:
func
:
maxpool_coo_grad {sparse_coo, dense, sparse_coo, sparse_coo -> sparse_coo}
-
backward_api
:
multiply_grad
forward
:
multiply(Tensor x, Tensor y) -> Tensor(out)
args
:
(Tensor x, Tensor y, Tensor out_grad)
...
...
@@ -198,13 +205,6 @@
kernel
:
func
:
softmax_csr_grad{sparse_csr, sparse_csr -> sparse_csr}
-
backward_api
:
sparse_maxpool_grad
forward
:
sparse_maxpool(Tensor x, int[] kernel_sizes, int[] paddings, int[] dilations, int[] strides) -> Tensor(out), Tensor(rulebook)
args
:
(Tensor x, Tensor rulebook, Tensor out, Tensor out_grad, int[] kernel_sizes)
output
:
Tensor(x_grad)
kernel
:
func
:
sparse_maxpool_grad {sparse_coo, dense, sparse_coo, sparse_coo -> sparse_coo}
-
backward_api
:
sqrt_grad
forward
:
sqrt(Tensor x) -> Tensor(out)
args
:
(Tensor out, Tensor out_grad)
...
...
paddle/phi/kernels/sparse/cpu/
sparse_
pool_grad_kernel.cc
→
paddle/phi/kernels/sparse/cpu/pool_grad_kernel.cc
浏览文件 @
9e307229
...
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/phi/kernels/sparse/
sparse_
pool_grad_kernel.h"
#include "paddle/phi/kernels/sparse/pool_grad_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
...
...
@@ -25,7 +25,7 @@ namespace phi {
namespace
sparse
{
template
<
typename
T
,
typename
IntT
=
int
>
void
MaxPoolGradCPUKernel
(
const
CPUContext
&
dev_ctx
,
void
MaxPool
Coo
GradCPUKernel
(
const
CPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out
,
...
...
@@ -75,7 +75,7 @@ void MaxPoolGradCPUKernel(const CPUContext& dev_ctx,
}
template
<
typename
T
,
typename
Context
>
void
MaxPoolGradKernel
(
const
Context
&
dev_ctx
,
void
MaxPool
Coo
GradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out
,
...
...
@@ -83,8 +83,8 @@ void MaxPoolGradKernel(const Context& dev_ctx,
const
std
::
vector
<
int
>&
kernel_sizes
,
SparseCooTensor
*
x_grad
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"MaxPoolGradCPUKernel"
,
([
&
]
{
MaxPoolGradCPUKernel
<
T
,
data_t
>
(
x
.
non_zero_indices
().
dtype
(),
"MaxPool
Coo
GradCPUKernel"
,
([
&
]
{
MaxPool
Coo
GradCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
rulebook
,
out
,
out_grad
,
kernel_sizes
,
x_grad
);
}));
}
...
...
@@ -92,10 +92,10 @@ void MaxPoolGradKernel(const Context& dev_ctx,
}
// namespace sparse
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_maxpool
_grad
,
PD_REGISTER_KERNEL
(
maxpool_coo
_grad
,
CPU
,
ALL_LAYOUT
,
phi
::
sparse
::
MaxPoolGradKernel
,
phi
::
sparse
::
MaxPool
Coo
GradKernel
,
float
,
double
)
{
kernel
->
InputAt
(
0
).
SetDataLayout
(
phi
::
DataLayout
::
SPARSE_COO
);
...
...
paddle/phi/kernels/sparse/cpu/
sparse_
pool_kernel.cc
→
paddle/phi/kernels/sparse/cpu/pool_kernel.cc
浏览文件 @
9e307229
...
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/phi/kernels/sparse/
sparse_
pool_kernel.h"
#include "paddle/phi/kernels/sparse/pool_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_meta.h"
...
...
@@ -30,7 +30,7 @@ namespace sparse {
* out: (N, D, H, W, OC)
**/
template
<
typename
T
,
typename
IntT
=
int
>
void
MaxPoolCPUKernel
(
const
CPUContext
&
dev_ctx
,
void
MaxPoolC
ooC
PUKernel
(
const
CPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
std
::
vector
<
int
>&
kernel_sizes
,
const
std
::
vector
<
int
>&
paddings
,
...
...
@@ -98,7 +98,7 @@ void MaxPoolCPUKernel(const CPUContext& dev_ctx,
}
template
<
typename
T
,
typename
Context
>
void
MaxPoolKernel
(
const
Context
&
dev_ctx
,
void
MaxPool
Coo
Kernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
std
::
vector
<
int
>&
kernel_sizes
,
const
std
::
vector
<
int
>&
paddings
,
...
...
@@ -107,8 +107,8 @@ void MaxPoolKernel(const Context& dev_ctx,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"MaxPoolCPUKernel"
,
([
&
]
{
MaxPoolCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
.
non_zero_indices
().
dtype
(),
"MaxPoolC
ooC
PUKernel"
,
([
&
]
{
MaxPoolC
ooC
PUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel_sizes
,
paddings
,
...
...
@@ -122,10 +122,10 @@ void MaxPoolKernel(const Context& dev_ctx,
}
// namespace sparse
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_maxpool
,
PD_REGISTER_KERNEL
(
maxpool_coo
,
CPU
,
ALL_LAYOUT
,
phi
::
sparse
::
MaxPoolKernel
,
phi
::
sparse
::
MaxPool
Coo
Kernel
,
float
,
double
)
{
kernel
->
InputAt
(
0
).
SetDataLayout
(
phi
::
DataLayout
::
SPARSE_COO
);
...
...
paddle/phi/kernels/sparse/gpu/
sparse_
pool_grad_kernel.cu
→
paddle/phi/kernels/sparse/gpu/pool_grad_kernel.cu
浏览文件 @
9e307229
...
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/phi/kernels/sparse/
sparse_
pool_grad_kernel.h"
#include "paddle/phi/kernels/sparse/pool_grad_kernel.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/gpu/gpu_info.h"
...
...
@@ -52,7 +52,7 @@ __global__ void MaxPoolGradCudaKernel(const T* in_features_ptr,
}
template
<
typename
T
,
typename
IntT
=
int
>
void
MaxPoolGradGPUKernel
(
const
GPUContext
&
dev_ctx
,
void
MaxPool
Coo
GradGPUKernel
(
const
GPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out
,
...
...
@@ -121,7 +121,7 @@ void MaxPoolGradGPUKernel(const GPUContext& dev_ctx,
}
template
<
typename
T
,
typename
Context
>
void
MaxPoolGradKernel
(
const
Context
&
dev_ctx
,
void
MaxPool
Coo
GradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out
,
...
...
@@ -129,8 +129,8 @@ void MaxPoolGradKernel(const Context& dev_ctx,
const
std
::
vector
<
int
>&
kernel_sizes
,
SparseCooTensor
*
x_grad
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"MaxPoolGradGPUKernel"
,
([
&
]
{
MaxPoolGradGPUKernel
<
T
,
data_t
>
(
x
.
non_zero_indices
().
dtype
(),
"MaxPool
Coo
GradGPUKernel"
,
([
&
]
{
MaxPool
Coo
GradGPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
rulebook
,
out
,
out_grad
,
kernel_sizes
,
x_grad
);
}));
}
...
...
@@ -138,10 +138,10 @@ void MaxPoolGradKernel(const Context& dev_ctx,
}
// namespace sparse
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_maxpool
_grad
,
PD_REGISTER_KERNEL
(
maxpool_coo
_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
MaxPoolGradKernel
,
phi
::
sparse
::
MaxPool
Coo
GradKernel
,
float
,
double
)
{
kernel
->
InputAt
(
0
).
SetDataLayout
(
phi
::
DataLayout
::
SPARSE_COO
);
...
...
paddle/phi/kernels/sparse/gpu/
sparse_
pool_kernel.cu
→
paddle/phi/kernels/sparse/gpu/pool_kernel.cu
浏览文件 @
9e307229
...
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/phi/kernels/sparse/
sparse_
pool_kernel.h"
#include "paddle/phi/kernels/sparse/pool_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_meta.h"
...
...
@@ -48,7 +48,7 @@ __global__ void MaxPoolCudaKernel(const T* in_features_ptr,
* out: (N, D, H, W, OC)
**/
template
<
typename
T
,
typename
IntT
=
int
>
void
MaxPoolGPUKernel
(
const
GPUContext
&
dev_ctx
,
void
MaxPool
Coo
GPUKernel
(
const
GPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
std
::
vector
<
int
>&
kernel_sizes
,
const
std
::
vector
<
int
>&
paddings
,
...
...
@@ -127,7 +127,7 @@ void MaxPoolGPUKernel(const GPUContext& dev_ctx,
}
template
<
typename
T
,
typename
Context
>
void
MaxPoolKernel
(
const
Context
&
dev_ctx
,
void
MaxPool
Coo
Kernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
std
::
vector
<
int
>&
kernel_sizes
,
const
std
::
vector
<
int
>&
paddings
,
...
...
@@ -136,8 +136,8 @@ void MaxPoolKernel(const Context& dev_ctx,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"MaxPoolGPUKernel"
,
([
&
]
{
MaxPoolGPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
.
non_zero_indices
().
dtype
(),
"MaxPool
Coo
GPUKernel"
,
([
&
]
{
MaxPool
Coo
GPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel_sizes
,
paddings
,
...
...
@@ -151,10 +151,10 @@ void MaxPoolKernel(const Context& dev_ctx,
}
// namespace sparse
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_maxpool
,
PD_REGISTER_KERNEL
(
maxpool_coo
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
MaxPoolKernel
,
phi
::
sparse
::
MaxPool
Coo
Kernel
,
float
,
double
,
phi
::
dtype
::
float16
)
{
...
...
paddle/phi/kernels/sparse/
sparse_
pool_grad_kernel.h
→
paddle/phi/kernels/sparse/pool_grad_kernel.h
浏览文件 @
9e307229
...
...
@@ -22,7 +22,7 @@ namespace phi {
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
MaxPoolGradKernel
(
const
Context
&
dev_ctx
,
void
MaxPool
Coo
GradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out
,
...
...
@@ -31,14 +31,14 @@ void MaxPoolGradKernel(const Context& dev_ctx,
SparseCooTensor
*
x_grad
);
template
<
typename
T
,
typename
Context
>
SparseCooTensor
MaxPoolGrad
(
const
Context
&
dev_ctx
,
SparseCooTensor
MaxPool
Coo
Grad
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
kernel_sizes
)
{
SparseCooTensor
x_grad
;
MaxPoolGradKernel
<
T
,
Context
>
(
MaxPool
Coo
GradKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
rulebook
,
out
,
out_grad
,
kernel_sizes
,
&
x_grad
);
return
x_grad
;
}
...
...
paddle/phi/kernels/sparse/
sparse_
pool_kernel.h
→
paddle/phi/kernels/sparse/pool_kernel.h
浏览文件 @
9e307229
...
...
@@ -22,7 +22,7 @@ namespace phi {
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
MaxPoolKernel
(
const
Context
&
dev_ctx
,
void
MaxPool
Coo
Kernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
std
::
vector
<
int
>&
kernel_sizes
,
const
std
::
vector
<
int
>&
paddings
,
...
...
@@ -32,7 +32,7 @@ void MaxPoolKernel(const Context& dev_ctx,
DenseTensor
*
rulebook
);
template
<
typename
T
,
typename
Context
>
SparseCooTensor
MaxPool
(
const
Context
&
dev_ctx
,
SparseCooTensor
MaxPool
Coo
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
std
::
vector
<
int
>&
kernel_sizes
,
const
std
::
vector
<
int
>&
paddings
,
...
...
@@ -40,7 +40,7 @@ SparseCooTensor MaxPool(const Context& dev_ctx,
const
std
::
vector
<
int
>&
strides
,
DenseTensor
*
rulebook
)
{
SparseCooTensor
coo
;
MaxPoolKernel
<
T
,
Context
>
(
MaxPool
Coo
Kernel
<
T
,
Context
>
(
dev_ctx
,
x
,
kernel_sizes
,
paddings
,
dilations
,
strides
,
&
coo
,
rulebook
);
return
coo
;
}
...
...
paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc
浏览文件 @
9e307229
...
...
@@ -23,8 +23,8 @@ limitations under the License. */
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/sparse/coalesce_kernel.h"
#include "paddle/phi/kernels/sparse/
sparse_
pool_grad_kernel.h"
#include "paddle/phi/kernels/sparse/
sparse_
pool_kernel.h"
#include "paddle/phi/kernels/sparse/pool_grad_kernel.h"
#include "paddle/phi/kernels/sparse/pool_kernel.h"
namespace
phi
{
namespace
tests
{
...
...
@@ -91,7 +91,7 @@ void TestMaxPoolBase(const std::vector<IntT>& indices,
if
(
!
std
::
is_same
<
T
,
phi
::
dtype
::
float16
>::
value
)
{
DenseTensor
rulebook
;
SparseCooTensor
out
=
sparse
::
MaxPool
<
T
>
(
dev_ctx_cpu
,
SparseCooTensor
out
=
sparse
::
MaxPool
Coo
<
T
>
(
dev_ctx_cpu
,
x_tensor
,
kernel_sizes
,
paddings
,
...
...
@@ -113,7 +113,7 @@ void TestMaxPoolBase(const std::vector<IntT>& indices,
f_verify
(
out
.
non_zero_elements
().
data
<
T
>
(),
correct_out_features
);
if
(
backward
)
{
SparseCooTensor
x_grad
=
sparse
::
MaxPoolGrad
<
T
>
(
SparseCooTensor
x_grad
=
sparse
::
MaxPool
Coo
Grad
<
T
>
(
dev_ctx_cpu
,
x_tensor
,
rulebook
,
out
,
out
,
kernel_sizes
);
f_verify
(
x_grad
.
non_zero_elements
().
data
<
T
>
(),
features_grad
);
}
...
...
@@ -151,7 +151,7 @@ void TestMaxPoolBase(const std::vector<IntT>& indices,
SparseCooTensor
d_x_tensor
(
d_indices_tensor
,
d_features_tensor
,
x_dims
);
DenseTensor
d_rulebook
;
SparseCooTensor
d_out
=
sparse
::
MaxPool
<
T
>
(
dev_ctx_gpu
,
SparseCooTensor
d_out
=
sparse
::
MaxPool
Coo
<
T
>
(
dev_ctx_gpu
,
d_x_tensor
,
kernel_sizes
,
paddings
,
...
...
@@ -191,7 +191,7 @@ void TestMaxPoolBase(const std::vector<IntT>& indices,
f_verify
(
h_features_tensor
.
data
<
T
>
(),
correct_out_features
);
if
(
backward
)
{
SparseCooTensor
x_grad
=
sparse
::
MaxPoolGrad
<
T
>
(
SparseCooTensor
x_grad
=
sparse
::
MaxPool
Coo
Grad
<
T
>
(
dev_ctx_gpu
,
d_x_tensor
,
d_rulebook
,
d_out
,
d_out
,
kernel_sizes
);
DenseTensor
h_features_grad
=
phi
::
EmptyLike
<
T
>
(
dev_ctx_cpu
,
x_grad
.
non_zero_elements
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录