Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d3366853
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看板
未验证
提交
d3366853
编写于
9月 13, 2022
作者:
Y
ykkk2333
提交者:
GitHub
9月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
migrate squeeze kernel to phi, test=kunlun (#45968)
上级
e6d397e6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
182 addition
and
224 deletion
+182
-224
paddle/fluid/operators/squeeze_op_xpu.cc
paddle/fluid/operators/squeeze_op_xpu.cc
+0
-62
paddle/phi/kernels/cpu/squeeze_grad_kernel.cc
paddle/phi/kernels/cpu/squeeze_grad_kernel.cc
+0
-34
paddle/phi/kernels/cpu/squeeze_kernel.cc
paddle/phi/kernels/cpu/squeeze_kernel.cc
+0
-49
paddle/phi/kernels/gpu/squeeze_grad_kernel.cu
paddle/phi/kernels/gpu/squeeze_grad_kernel.cu
+0
-35
paddle/phi/kernels/impl/squeeze_grad_kernel_impl.h
paddle/phi/kernels/impl/squeeze_grad_kernel_impl.h
+0
-34
paddle/phi/kernels/squeeze_grad_kernel.cc
paddle/phi/kernels/squeeze_grad_kernel.cc
+44
-10
paddle/phi/kernels/squeeze_kernel.cc
paddle/phi/kernels/squeeze_kernel.cc
+138
-0
未找到文件。
paddle/fluid/operators/squeeze_op_xpu.cc
已删除
100644 → 0
浏览文件 @
e6d397e6
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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/fluid/operators/squeeze_op.h"
#ifdef PADDLE_WITH_XPU
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_XPU_KERNEL
(
squeeze
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
SqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
REGISTER_OP_XPU_KERNEL
(
squeeze_grad
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
SqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
REGISTER_OP_XPU_KERNEL
(
squeeze2
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
Squeeze2Kernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
REGISTER_OP_XPU_KERNEL
(
squeeze2_grad
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
Squeeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
#endif
paddle/phi/kernels/cpu/squeeze_grad_kernel.cc
已删除
100644 → 0
浏览文件 @
e6d397e6
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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/squeeze_grad_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/squeeze_grad_kernel_impl.h"
PD_REGISTER_KERNEL
(
squeeze_grad
,
CPU
,
ALL_LAYOUT
,
phi
::
SqueezeGradKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
paddle/phi/kernels/cpu/squeeze_kernel.cc
已删除
100644 → 0
浏览文件 @
e6d397e6
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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/squeeze_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/squeeze_kernel_impl.h"
PD_REGISTER_KERNEL
(
squeeze
,
CPU
,
ALL_LAYOUT
,
phi
::
SqueezeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
squeeze_with_xshape
,
CPU
,
ALL_LAYOUT
,
phi
::
SqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
paddle/phi/kernels/gpu/squeeze_grad_kernel.cu
已删除
100644 → 0
浏览文件 @
e6d397e6
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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/squeeze_grad_kernel.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/squeeze_grad_kernel_impl.h"
PD_REGISTER_KERNEL
(
squeeze_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
SqueezeGradKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
paddle/phi/kernels/impl/squeeze_grad_kernel_impl.h
已删除
100644 → 0
浏览文件 @
e6d397e6
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
#pragma once
#include "paddle/phi/common/int_array.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/tensor_utils.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
SqueezeGradKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
xshape
,
const
DenseTensor
&
dout
,
const
IntArray
&
axes
,
DenseTensor
*
dx
)
{
auto
xshape_dims
=
xshape
.
dims
();
auto
x_dims
=
phi
::
slice_ddim
(
xshape_dims
,
1
,
xshape_dims
.
size
());
dev_ctx
.
template
Alloc
<
T
>(
dx
);
phi
::
Copy
(
dev_ctx
,
dout
,
dev_ctx
.
GetPlace
(),
false
,
dx
);
dx
->
Resize
(
x_dims
);
}
}
// namespace phi
paddle/phi/kernels/
gpu/squeeze_kernel.cu
→
paddle/phi/kernels/
squeeze_grad_kernel.cc
浏览文件 @
d3366853
...
...
@@ -12,20 +12,35 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/squeeze_kernel.h"
#include "paddle/phi/kernels/squeeze_
grad_
kernel.h"
#include "paddle/phi/backends/
gpu/gpu
_context.h"
#include "paddle/phi/backends/
all
_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/
kernels/impl/squeeze_kernel_impl
.h"
#include "paddle/phi/
core/tensor_utils
.h"
PD_REGISTER_KERNEL
(
squeeze
,
GPU
,
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
SqueezeGradKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
xshape
,
const
DenseTensor
&
dout
,
const
IntArray
&
axes
,
DenseTensor
*
dx
)
{
auto
xshape_dims
=
xshape
.
dims
();
auto
x_dims
=
phi
::
slice_ddim
(
xshape_dims
,
1
,
xshape_dims
.
size
());
dev_ctx
.
template
Alloc
<
T
>(
dx
);
phi
::
Copy
(
dev_ctx
,
dout
,
dev_ctx
.
GetPlace
(),
false
,
dx
);
dx
->
Resize
(
x_dims
);
}
}
// namespace phi
PD_REGISTER_KERNEL
(
squeeze_grad
,
CPU
,
ALL_LAYOUT
,
phi
::
SqueezeKernel
,
phi
::
Squeeze
Grad
Kernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
...
...
@@ -34,14 +49,15 @@ PD_REGISTER_KERNEL(squeeze,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
squeeze_with_xshape
,
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PD_REGISTER_KERNEL
(
squeeze_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
Squeeze
WithXShape
Kernel
,
phi
::
Squeeze
Grad
Kernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
...
...
@@ -49,3 +65,21 @@ PD_REGISTER_KERNEL(squeeze_with_xshape,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
#endif
#ifdef PADDLE_WITH_XPU
PD_REGISTER_KERNEL
(
squeeze_grad
,
XPU
,
ALL_LAYOUT
,
phi
::
SqueezeGradKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
)
{}
#endif
paddle/phi/kernels/
impl/squeeze_kernel_impl.h
→
paddle/phi/kernels/
squeeze_kernel.cc
浏览文件 @
d3366853
...
...
@@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/kernels/squeeze_kernel.h"
#include "paddle/phi/backends/all_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/funcs/unsqueeze.h"
...
...
@@ -43,3 +45,94 @@ void SqueezeWithXShapeKernel(const Context& dev_ctx,
}
}
// namespace phi
PD_REGISTER_KERNEL
(
squeeze
,
CPU
,
ALL_LAYOUT
,
phi
::
SqueezeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
squeeze_with_xshape
,
CPU
,
ALL_LAYOUT
,
phi
::
SqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PD_REGISTER_KERNEL
(
squeeze
,
GPU
,
ALL_LAYOUT
,
phi
::
SqueezeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
squeeze_with_xshape
,
GPU
,
ALL_LAYOUT
,
phi
::
SqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
#endif
#ifdef PADDLE_WITH_XPU
PD_REGISTER_KERNEL
(
squeeze
,
XPU
,
ALL_LAYOUT
,
phi
::
SqueezeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
)
{}
PD_REGISTER_KERNEL
(
squeeze_with_xshape
,
XPU
,
ALL_LAYOUT
,
phi
::
SqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
)
{}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录