Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
4acf1ef7
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4acf1ef7
编写于
9月 06, 2022
作者:
Y
ykkk2333
提交者:
GitHub
9月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
migrate unsqueeze kernels to phi, test=kunlun (#45673)
上级
5c95e5c8
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
238 addition
and
259 deletion
+238
-259
paddle/fluid/operators/unsqueeze_op_xpu.cc
paddle/fluid/operators/unsqueeze_op_xpu.cc
+0
-62
paddle/fluid/operators/where_op_xpu.cc
paddle/fluid/operators/where_op_xpu.cc
+0
-66
paddle/phi/kernels/cpu/unsqueeze_grad_kernel.cc
paddle/phi/kernels/cpu/unsqueeze_grad_kernel.cc
+0
-35
paddle/phi/kernels/cpu/unsqueeze_kernel.cc
paddle/phi/kernels/cpu/unsqueeze_kernel.cc
+0
-51
paddle/phi/kernels/gpu/unsqueeze_grad_kernel.cu
paddle/phi/kernels/gpu/unsqueeze_grad_kernel.cu
+0
-36
paddle/phi/kernels/unsqueeze_grad_kernel.cc
paddle/phi/kernels/unsqueeze_grad_kernel.cc
+42
-9
paddle/phi/kernels/unsqueeze_kernel.cc
paddle/phi/kernels/unsqueeze_kernel.cc
+147
-0
paddle/phi/kernels/xpu/where_kernel.cc
paddle/phi/kernels/xpu/where_kernel.cc
+49
-0
未找到文件。
paddle/fluid/operators/unsqueeze_op_xpu.cc
已删除
100644 → 0
浏览文件 @
5c95e5c8
/* 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/unsqueeze_op.h"
#ifdef PADDLE_WITH_XPU
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_XPU_KERNEL
(
unsqueeze
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
REGISTER_OP_XPU_KERNEL
(
unsqueeze_grad
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
UnsqueezeGradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
REGISTER_OP_XPU_KERNEL
(
unsqueeze2
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
UnsqueezeKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
REGISTER_OP_XPU_KERNEL
(
unsqueeze2_grad
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
double
>
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
plat
::
float16
>
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
bool
>
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
uint8_t
>
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int8_t
>
,
ops
::
Unsqueeze2GradKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
#endif
paddle/fluid/operators/where_op_xpu.cc
已删除
100644 → 0
浏览文件 @
5c95e5c8
// Copyright (c) 2020 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.
#ifdef PADDLE_WITH_XPU
#include "paddle/fluid/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
template
<
typename
DeviceContext
,
typename
T
>
class
WhereXPUKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
condition
=
context
.
Input
<
framework
::
Tensor
>
(
"Condition"
);
auto
*
X
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
Y
=
context
.
Input
<
framework
::
Tensor
>
(
"Y"
);
auto
*
out
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
const
bool
*
cond_data
=
condition
->
data
<
bool
>
();
const
T
*
x_data
=
X
->
data
<
T
>
();
const
T
*
y_data
=
Y
->
data
<
T
>
();
T
*
out_data
=
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
cond_dims
=
phi
::
vectorize
<
int
>
(
condition
->
dims
());
auto
input_dims
=
phi
::
vectorize
<
int
>
(
X
->
dims
());
auto
&
dev_ctx
=
context
.
template
device_context
<
DeviceContext
>();
int
ret
=
xpu
::
select
(
dev_ctx
.
x_context
(),
cond_data
,
x_data
,
y_data
,
out_data
,
cond_dims
,
input_dims
);
PADDLE_ENFORCE_EQ
(
ret
,
XPU_SUCCESS
,
platform
::
errors
::
External
(
"XPU select kernel return wrong value[%d %s]"
,
ret
,
XPUAPIErrorMsg
[
ret
]));
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_XPU_KERNEL
(
where
,
ops
::
WhereXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
,
ops
::
WhereXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
WhereXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int64_t
>
);
#endif
paddle/phi/kernels/cpu/unsqueeze_grad_kernel.cc
已删除
100644 → 0
浏览文件 @
5c95e5c8
// 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/unsqueeze_grad_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/unsqueeze_grad_kernel_impl.h"
PD_REGISTER_KERNEL
(
unsqueeze_grad
,
CPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeGradKernel
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
int16_t
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
,
float
,
double
)
{}
paddle/phi/kernels/cpu/unsqueeze_kernel.cc
已删除
100644 → 0
浏览文件 @
5c95e5c8
// 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/unsqueeze_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/unsqueeze_kernel_impl.h"
PD_REGISTER_KERNEL
(
unsqueeze
,
CPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
int16_t
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
unsqueeze_with_xshape
,
CPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
int16_t
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
paddle/phi/kernels/gpu/unsqueeze_grad_kernel.cu
已删除
100644 → 0
浏览文件 @
5c95e5c8
// 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/unsqueeze_grad_kernel.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/unsqueeze_grad_kernel_impl.h"
PD_REGISTER_KERNEL
(
unsqueeze_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeGradKernel
,
phi
::
dtype
::
bfloat16
,
phi
::
dtype
::
float16
,
bool
,
int
,
int16_t
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
,
float
,
double
)
{}
paddle/phi/kernels/
gpu/unsqueeze_kernel.cu
→
paddle/phi/kernels/
unsqueeze_grad_kernel.cc
浏览文件 @
4acf1ef7
...
...
@@ -12,19 +12,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/unsqueeze_kernel.h"
#include "paddle/phi/kernels/unsqueeze_
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/unsqueeze_kernel_impl.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/funcs/unsqueeze.h"
PD_REGISTER_KERNEL
(
unsqueeze
,
GPU
,
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
UnsqueezeGradKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x_shape
,
const
DenseTensor
&
dout
,
DenseTensor
*
dx
)
{
auto
xshape_dims
=
x_shape
.
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
(),
true
,
dx
);
dx
->
Resize
(
x_dims
);
}
}
// namespace phi
PD_REGISTER_KERNEL
(
unsqueeze_grad
,
CPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeKernel
,
phi
::
Unsqueeze
Grad
Kernel
,
float
,
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
...
...
@@ -35,10 +49,11 @@ PD_REGISTER_KERNEL(unsqueeze,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
unsqueeze_with_xshape
,
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PD_REGISTER_KERNEL
(
unsqueeze_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
Unsqueeze
WithXShape
Kernel
,
phi
::
Unsqueeze
Grad
Kernel
,
float
,
double
,
phi
::
dtype
::
float16
,
...
...
@@ -51,3 +66,21 @@ PD_REGISTER_KERNEL(unsqueeze_with_xshape,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
#endif
#ifdef PADDLE_WITH_XPU
PD_REGISTER_KERNEL
(
unsqueeze_grad
,
XPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeGradKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
)
{}
#endif
paddle/phi/kernels/
impl/unsqueeze_kernel_impl.h
→
paddle/phi/kernels/
unsqueeze_kernel.cc
浏览文件 @
4acf1ef7
...
...
@@ -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/unsqueeze_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"
...
...
@@ -48,3 +50,98 @@ void UnsqueezeWithXShapeKernel(const Context& dev_ctx,
UnsqueezeKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
axes
,
out
);
}
}
// namespace phi
PD_REGISTER_KERNEL
(
unsqueeze
,
CPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
int16_t
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
unsqueeze_with_xshape
,
CPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
int16_t
,
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
(
unsqueeze
,
GPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
int16_t
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
PD_REGISTER_KERNEL
(
unsqueeze_with_xshape
,
GPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
bool
,
int
,
int16_t
,
uint8_t
,
int8_t
,
int64_t
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{}
#endif
#ifdef PADDLE_WITH_XPU
PD_REGISTER_KERNEL
(
unsqueeze
,
XPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
)
{}
PD_REGISTER_KERNEL
(
unsqueeze_with_xshape
,
XPU
,
ALL_LAYOUT
,
phi
::
UnsqueezeWithXShapeKernel
,
float
,
double
,
phi
::
dtype
::
float16
,
bool
,
int
,
uint8_t
,
int8_t
,
int64_t
)
{}
#endif
paddle/phi/kernels/
impl/unsqueeze_grad_kernel_impl.h
→
paddle/phi/kernels/
xpu/where_kernel.cc
浏览文件 @
4acf1ef7
...
...
@@ -12,20 +12,38 @@
// 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/core/tensor_utils.h"
#include "paddle/phi/kernels/where_kernel.h"
#include "paddle/phi/backends/xpu/enforce_xpu.h"
#include "paddle/phi/core/kernel_registry.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
UnsqueezeGradKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x_shape
,
const
DenseTensor
&
dout
,
DenseTensor
*
dx
)
{
auto
xshape_dims
=
x_shape
.
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
(),
true
,
dx
);
dx
->
Resize
(
x_dims
);
void
WhereKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
condition
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
const
bool
*
cond_data
=
condition
.
data
<
bool
>
();
const
T
*
x_data
=
x
.
data
<
T
>
();
const
T
*
y_data
=
y
.
data
<
T
>
();
T
*
out_data
=
ctx
.
template
Alloc
<
T
>(
out
);
auto
cond_dims
=
phi
::
vectorize
<
int
>
(
condition
.
dims
());
auto
input_dims
=
phi
::
vectorize
<
int
>
(
x
.
dims
());
int
ret
=
xpu
::
select
(
ctx
.
x_context
(),
cond_data
,
x_data
,
y_data
,
out_data
,
cond_dims
,
input_dims
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
ret
,
"select"
);
}
}
// namespace phi
PD_REGISTER_KERNEL
(
where
,
XPU
,
ALL_LAYOUT
,
phi
::
WhereKernel
,
float
,
int
,
int64_t
)
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录