Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4d7a9eef
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
4d7a9eef
编写于
5月 24, 2022
作者:
Y
YuanRisheng
提交者:
GitHub
5月 24, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Phi]Move grad_add op kernel into phi and delete elementwise_add_op file (#42903)
* move grad_add * fix unittest bugs * fix compile bugs
上级
9e5acc1f
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
74 addition
and
167 deletion
+74
-167
paddle/fluid/operators/dgc_op.h
paddle/fluid/operators/dgc_op.h
+9
-7
paddle/fluid/operators/elementwise/elementwise_add_op.cc
paddle/fluid/operators/elementwise/elementwise_add_op.cc
+0
-13
paddle/fluid/operators/elementwise/elementwise_add_op.h
paddle/fluid/operators/elementwise/elementwise_add_op.h
+0
-66
paddle/fluid/operators/elementwise/elementwise_add_op.kps
paddle/fluid/operators/elementwise/elementwise_add_op.kps
+0
-61
paddle/fluid/operators/elementwise/elementwise_add_op_npu.cc
paddle/fluid/operators/elementwise/elementwise_add_op_npu.cc
+0
-1
paddle/fluid/operators/elementwise/elementwise_add_op_xpu.cc
paddle/fluid/operators/elementwise/elementwise_add_op_xpu.cc
+0
-1
paddle/fluid/operators/fused/attn_gemm.h
paddle/fluid/operators/fused/attn_gemm.h
+4
-4
paddle/fluid/operators/fused/fmha_ref.h
paddle/fluid/operators/fused/fmha_ref.h
+5
-5
paddle/fluid/operators/fused/fused_attention_op.cu
paddle/fluid/operators/fused/fused_attention_op.cu
+4
-4
paddle/fluid/operators/fused/fused_feedforward_op.cu
paddle/fluid/operators/fused/fused_feedforward_op.cu
+4
-4
paddle/fluid/operators/fused/fused_multi_transformer_op.cu
paddle/fluid/operators/fused/fused_multi_transformer_op.cu
+0
-1
paddle/phi/kernels/cpu/elementwise_add_kernel.cc
paddle/phi/kernels/cpu/elementwise_add_kernel.cc
+20
-0
paddle/phi/kernels/kps/elementwise_add_kernel.cu
paddle/phi/kernels/kps/elementwise_add_kernel.cu
+22
-0
paddle/phi/ops/compat/elementwise_sig.cc
paddle/phi/ops/compat/elementwise_sig.cc
+6
-0
未找到文件。
paddle/fluid/operators/dgc_op.h
浏览文件 @
4d7a9eef
...
@@ -15,9 +15,11 @@ limitations under the License. */
...
@@ -15,9 +15,11 @@ limitations under the License. */
#pragma once
#pragma once
#include <vector>
#include <vector>
#include "dgc/dgc.h"
#include "dgc/dgc.h"
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/memory/malloc.h"
#include "paddle/fluid/memory/malloc.h"
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op_function.h"
#include "paddle/phi/kernels/funcs/elementwise_functor.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -153,18 +155,18 @@ class DGCOpKernel : public framework::OpKernel<T> {
...
@@ -153,18 +155,18 @@ class DGCOpKernel : public framework::OpKernel<T> {
u_out_e
.
device
(
eigen_ctx
)
=
m
*
(
u_e
+
grad_out_e
);
u_out_e
.
device
(
eigen_ctx
)
=
m
*
(
u_e
+
grad_out_e
);
// v = u + v + g
// v = u + v + g
ElementwiseComputeEx
<
AddFunctor
<
T
>
,
DeviceContext
,
T
>
(
ElementwiseComputeEx
<
phi
::
funcs
::
AddFunctor
<
T
>
,
DeviceContext
,
T
>
(
ctx
,
u
,
v
,
0
,
AddFunctor
<
T
>
(),
v_out
);
ctx
,
u
,
v
,
0
,
phi
::
funcs
::
AddFunctor
<
T
>
(),
v_out
);
ElementwiseComputeEx
<
AddFunctor
<
T
>
,
DeviceContext
,
T
>
(
ElementwiseComputeEx
<
phi
::
funcs
::
AddFunctor
<
T
>
,
DeviceContext
,
T
>
(
ctx
,
g
,
v
,
0
,
AddFunctor
<
T
>
(),
v_out
);
ctx
,
g
,
v
,
0
,
phi
::
funcs
::
AddFunctor
<
T
>
(),
v_out
);
}
else
{
}
else
{
// u = m * u + g
// u = m * u + g
u_out_e
.
device
(
eigen_ctx
)
=
m
*
u_e
+
grad_out_e
;
u_out_e
.
device
(
eigen_ctx
)
=
m
*
u_e
+
grad_out_e
;
// v = u + v
// v = u + v
ElementwiseComputeEx
<
AddFunctor
<
T
>
,
DeviceContext
,
T
>
(
ElementwiseComputeEx
<
phi
::
funcs
::
AddFunctor
<
T
>
,
DeviceContext
,
T
>
(
ctx
,
u
,
v
,
0
,
AddFunctor
<
T
>
(),
v_out
);
ctx
,
u
,
v
,
0
,
phi
::
funcs
::
AddFunctor
<
T
>
(),
v_out
);
}
}
T
*
v_out_data
=
v_out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
T
*
v_out_data
=
v_out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
...
paddle/fluid/operators/elementwise/elementwise_add_op.cc
浏览文件 @
4d7a9eef
...
@@ -12,8 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,8 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include <string>
#include <string>
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
...
@@ -125,17 +123,6 @@ REGISTER_OPERATOR(
...
@@ -125,17 +123,6 @@ REGISTER_OPERATOR(
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OP_CPU_KERNEL
(
grad_add
,
ops
::
ElementwiseAddKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
ElementwiseAddKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
,
ops
::
ElementwiseAddKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
ElementwiseAddKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
,
ops
::
ElementwiseAddKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
ElementwiseAddKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
double
>>
);
REGISTER_OP_VERSION
(
elementwise_add
)
REGISTER_OP_VERSION
(
elementwise_add
)
.
AddCheckpoint
(
.
AddCheckpoint
(
R"ROC(Register elementwise_add for adding the attribute of
R"ROC(Register elementwise_add for adding the attribute of
...
...
paddle/fluid/operators/elementwise/elementwise_add_op.h
已删除
100644 → 0
浏览文件 @
9e5acc1f
/* Copyright (c) 2016 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
#ifdef __xpu__
#include <memory>
#include <string>
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op_broadcast.cu.h"
#include "paddle/fluid/operators/elementwise/elementwise_xpu.h"
#include "paddle/fluid/platform/device/device_wrapper.h"
#else
#include <algorithm>
#include <utility>
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
// only can include the headers in paddle/phi/include dirs
#include "paddle/phi/kernels/elementwise_add_grad_kernel.h"
#include "paddle/phi/kernels/elementwise_add_kernel.h"
#endif
namespace
paddle
{
namespace
operators
{
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseAddKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
#ifdef __xpu__
std
::
vector
<
const
framework
::
Tensor
*>
ins
;
std
::
vector
<
framework
::
Tensor
*>
outs
;
int
axis
=
PackTensorsIntoVector
<
T
>
(
ctx
,
&
ins
,
&
outs
);
const
auto
&
xpu_ctx
=
ctx
.
template
device_context
<
paddle
::
platform
::
XPUDeviceContext
>();
paddle
::
operators
::
LaunchElementwiseCudaKernel
<
ElementwiseType
::
kBinary
,
T
,
T
,
kps
::
AddFunctor
<
T
>
,
1
>
(
xpu_ctx
,
ins
,
&
outs
,
axis
,
kps
::
AddFunctor
<
T
>
());
#else
auto
*
x
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"X"
);
auto
*
y
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"Y"
);
auto
*
z
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
z
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
&
dev_ctx
=
ctx
.
device_context
<
DeviceContext
>
();
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
phi
::
AddRawKernel
<
T
>
(
static_cast
<
const
typename
framework
::
ConvertToPhiContext
<
DeviceContext
>::
TYPE
&>
(
dev_ctx
),
*
x
,
*
y
,
axis
,
z
);
#endif
}
};
}
// namespace operators
}
// namespace paddle
paddle/fluid/operators/elementwise/elementwise_add_op.kps
已删除
100644 → 0
浏览文件 @
9e5acc1f
/* 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. */
#ifdef PADDLE_WITH_XPU_KP
// Please do not modify the following code
#if defined(__CUDA_ARCH__)
#undef __CUDA_ARCH__
#endif
#if defined(__CUDACC__)
#undef __CUDACC__
#endif
#if defined(__CUDA__)
#undef __CUDA__
#endif
#if defined(__NVCC__)
#undef __NVCC__
#endif
#include <xpu/runtime.h> // NOLINT
#include "xpu/kernel/cluster_header.h" // NOLINT
#include "xpu/kernel/debug.h" // NOLINT
#include "xpu/kernel/math.h" // NOLINT
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#else
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include "paddle/phi/kernels/gpu/elementwise_grad.h"
#endif
namespace ops = paddle::operators;
namespace plat = paddle::platform;
#ifdef PADDLE_WITH_XPU_KP
REGISTER_OP_KERNEL(elementwise_add, KP, plat::XPUPlace,
ops::ElementwiseAddKernel<plat::XPUDeviceContext, float>);
#else
REGISTER_OP_CUDA_KERNEL(
grad_add, ops::ElementwiseAddKernel<plat::CUDADeviceContext, float>,
ops::ElementwiseAddKernel<plat::CUDADeviceContext, double>,
ops::ElementwiseAddKernel<plat::CUDADeviceContext, int>,
ops::ElementwiseAddKernel<plat::CUDADeviceContext, int64_t>,
ops::ElementwiseAddKernel<plat::CUDADeviceContext, plat::float16>,
ops::ElementwiseAddKernel<plat::CUDADeviceContext, plat::bfloat16>,
ops::ElementwiseAddKernel<plat::CUDADeviceContext, plat::complex<float>>,
ops::ElementwiseAddKernel<plat::CUDADeviceContext, plat::complex<double>>);
#endif
paddle/fluid/operators/elementwise/elementwise_add_op_npu.cc
浏览文件 @
4d7a9eef
...
@@ -16,7 +16,6 @@ limitations under the License. */
...
@@ -16,7 +16,6 @@ limitations under the License. */
#include <string>
#include <string>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_npu.h"
#include "paddle/fluid/operators/elementwise/elementwise_npu.h"
#include "paddle/fluid/platform/device/npu/npu_op_runner.h"
#include "paddle/fluid/platform/device/npu/npu_op_runner.h"
...
...
paddle/fluid/operators/elementwise/elementwise_add_op_xpu.cc
浏览文件 @
4d7a9eef
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#ifdef PADDLE_WITH_XPU
#ifdef PADDLE_WITH_XPU
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include <memory>
#include <memory>
#include <string>
#include <string>
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
...
...
paddle/fluid/operators/fused/attn_gemm.h
浏览文件 @
4d7a9eef
...
@@ -14,9 +14,10 @@ limitations under the License. */
...
@@ -14,9 +14,10 @@ limitations under the License. */
#include "paddle/fluid/platform/float16.h"
#include "paddle/fluid/platform/float16.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/fluid/operators/elementwise/elementwise_op_broadcast.cu.h"
#include "paddle/fluid/operators/kernel_primitives/kernel_primitives.h"
#include "paddle/fluid/operators/kernel_primitives/kernel_primitives.h"
#include "paddle/fluid/operators/reduce_ops/reduce_op.cu.h"
#include "paddle/fluid/operators/reduce_ops/reduce_op.cu.h"
#include "paddle/phi/kernels/funcs/broadcast_function.h"
#include "paddle/phi/kernels/funcs/elementwise_functor.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -67,9 +68,8 @@ class AttnMatMul {
...
@@ -67,9 +68,8 @@ class AttnMatMul {
ins
.
emplace_back
(
bias
);
ins
.
emplace_back
(
bias
);
outs
.
emplace_back
(
bias_out
);
outs
.
emplace_back
(
bias_out
);
int
elewise_add_axis
=
-
1
;
int
elewise_add_axis
=
-
1
;
paddle
::
operators
::
LaunchElementwiseCudaKernel
<
ElementwiseType
::
kBinary
,
phi
::
funcs
::
BroadcastKernel
<
phi
::
ElementwiseType
::
kBinary
,
T
,
T
>
(
T
,
T
>
(
dev_ctx_
,
ins
,
&
outs
,
elewise_add_axis
,
phi
::
funcs
::
AddFunctor
<
T
>
());
dev_ctx_
,
ins
,
&
outs
,
elewise_add_axis
,
AddFunctor
<
T
>
());
}
}
}
}
...
...
paddle/fluid/operators/fused/fmha_ref.h
浏览文件 @
4d7a9eef
...
@@ -12,12 +12,12 @@ limitations under the License. */
...
@@ -12,12 +12,12 @@ limitations under the License. */
#pragma once
#pragma once
#include "paddle/fluid/operators/dropout_impl.cu.h"
#include "paddle/fluid/operators/dropout_impl.cu.h"
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op_broadcast.cu.h"
#include "paddle/fluid/operators/fused/fused_softmax_mask.cu.h"
#include "paddle/fluid/operators/fused/fused_softmax_mask.cu.h"
#include "paddle/fluid/operators/transpose_op.cu.h"
#include "paddle/fluid/operators/transpose_op.cu.h"
#include "paddle/phi/kernels/funcs/broadcast_function.h"
#include "paddle/phi/kernels/funcs/concat_and_split_functor.h"
#include "paddle/phi/kernels/funcs/concat_and_split_functor.h"
#include "paddle/phi/kernels/funcs/elementwise_base.h"
#include "paddle/phi/kernels/funcs/elementwise_base.h"
#include "paddle/phi/kernels/funcs/elementwise_functor.h"
#include "paddle/phi/kernels/funcs/functors.h"
#include "paddle/phi/kernels/funcs/functors.h"
#include "paddle/phi/kernels/gpudnn/softmax_gpudnn.h"
#include "paddle/phi/kernels/gpudnn/softmax_gpudnn.h"
...
@@ -160,9 +160,9 @@ class FMHARef {
...
@@ -160,9 +160,9 @@ class FMHARef {
ins
.
emplace_back
(
src_mask_tensor
);
ins
.
emplace_back
(
src_mask_tensor
);
outs
.
emplace_back
(
src_mask_out_tensor
);
outs
.
emplace_back
(
src_mask_out_tensor
);
int
elewise_add_axis
=
-
1
;
int
elewise_add_axis
=
-
1
;
p
addle
::
operators
::
LaunchElementwiseCudaKernel
<
ElementwiseType
::
kBinary
,
p
hi
::
funcs
::
BroadcastKernel
<
phi
::
ElementwiseType
::
kBinary
,
T
,
T
>
(
T
,
T
>
(
dev_ctx_
,
ins
,
&
outs
,
elewise_add_axis
,
dev_ctx_
,
ins
,
&
outs
,
elewise_add_axis
,
AddFunctor
<
T
>
());
phi
::
funcs
::
AddFunctor
<
T
>
());
phi
::
SoftmaxForwardCUDAKernelDriver
<
T
>
(
phi
::
SoftmaxForwardCUDAKernelDriver
<
T
>
(
dev_ctx_
,
*
src_mask_out_tensor
,
softmax_axis
,
softmax_out_tensor
);
dev_ctx_
,
*
src_mask_out_tensor
,
softmax_axis
,
softmax_out_tensor
);
...
...
paddle/fluid/operators/fused/fused_attention_op.cu
浏览文件 @
4d7a9eef
...
@@ -19,7 +19,8 @@ limitations under the License. */
...
@@ -19,7 +19,8 @@ limitations under the License. */
#include "paddle/fluid/platform/device/gpu/gpu_device_function.h"
#include "paddle/fluid/platform/device/gpu/gpu_device_function.h"
#include "paddle/fluid/platform/device/gpu/gpu_dnn.h"
#include "paddle/fluid/platform/device/gpu/gpu_dnn.h"
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include "paddle/phi/kernels/funcs/broadcast_function.h"
#include "paddle/phi/kernels/funcs/elementwise_functor.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/fluid/operators/fused/attention_layer_norm.h"
#include "paddle/fluid/operators/fused/attention_layer_norm.h"
...
@@ -543,10 +544,9 @@ class FusedAttentionGradKernel : public framework::OpKernel<T> {
...
@@ -543,10 +544,9 @@ class FusedAttentionGradKernel : public framework::OpKernel<T> {
ins
.
emplace_back
(
d_x
);
ins
.
emplace_back
(
d_x
);
outs
.
emplace_back
(
d_x
);
outs
.
emplace_back
(
d_x
);
int
elewise_add_axis
=
-
1
;
int
elewise_add_axis
=
-
1
;
paddle
::
operators
::
LaunchElementwiseCudaKernel
<
ElementwiseType
::
kBinary
,
T
,
phi
::
funcs
::
BroadcastKernel
<
phi
::
ElementwiseType
::
kBinary
,
T
,
T
>
(
T
>
(
ctx
.
cuda_device_context
(),
ins
,
&
outs
,
elewise_add_axis
,
ctx
.
cuda_device_context
(),
ins
,
&
outs
,
elewise_add_axis
,
AddFunctor
<
T
>
());
phi
::
funcs
::
AddFunctor
<
T
>
());
}
}
};
};
...
...
paddle/fluid/operators/fused/fused_feedforward_op.cu
浏览文件 @
4d7a9eef
...
@@ -17,9 +17,10 @@ limitations under the License. */
...
@@ -17,9 +17,10 @@ limitations under the License. */
#include "paddle/fluid/operators/matmul_v2_op.h"
#include "paddle/fluid/operators/matmul_v2_op.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include "paddle/fluid/operators/fused/fused_dropout_helper.h"
#include "paddle/fluid/operators/fused/fused_dropout_helper.h"
#include "paddle/fluid/operators/layer_norm_kernel.cu.h"
#include "paddle/fluid/operators/layer_norm_kernel.cu.h"
#include "paddle/phi/kernels/funcs/broadcast_function.h"
#include "paddle/phi/kernels/funcs/elementwise_functor.h"
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#include "paddle/fluid/platform/collective_helper.h"
#include "paddle/fluid/platform/collective_helper.h"
...
@@ -345,9 +346,8 @@ class FusedFeedForwardGradKernel : public framework::OpKernel<T> {
...
@@ -345,9 +346,8 @@ class FusedFeedForwardGradKernel : public framework::OpKernel<T> {
ins
[
1
]
=
d_x
;
ins
[
1
]
=
d_x
;
outs
[
0
]
=
d_x
;
outs
[
0
]
=
d_x
;
int
elewise_add_axis
=
-
1
;
int
elewise_add_axis
=
-
1
;
paddle
::
operators
::
LaunchElementwiseCudaKernel
<
ElementwiseType
::
kBinary
,
T
,
phi
::
funcs
::
BroadcastKernel
<
phi
::
ElementwiseType
::
kBinary
,
T
,
T
>
(
T
>
(
ctx
,
ins
,
&
outs
,
elewise_add_axis
,
phi
::
funcs
::
AddFunctor
<
T
>
());
ctx
,
ins
,
&
outs
,
elewise_add_axis
,
AddFunctor
<
T
>
());
}
}
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
...
...
paddle/fluid/operators/fused/fused_multi_transformer_op.cu
浏览文件 @
4d7a9eef
...
@@ -24,7 +24,6 @@ limitations under the License. */
...
@@ -24,7 +24,6 @@ limitations under the License. */
#include "paddle/fluid/platform/device/gpu/gpu_device_function.h"
#include "paddle/fluid/platform/device/gpu/gpu_device_function.h"
#include "paddle/fluid/platform/device/gpu/gpu_dnn.h"
#include "paddle/fluid/platform/device/gpu/gpu_dnn.h"
#include "paddle/fluid/operators/elementwise/elementwise_add_op.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/fluid/operators/fused/attention_layer_norm.h"
#include "paddle/fluid/operators/fused/attention_layer_norm.h"
...
...
paddle/phi/kernels/cpu/elementwise_add_kernel.cc
浏览文件 @
4d7a9eef
...
@@ -34,6 +34,14 @@ void AddKernel(const Context& dev_ctx,
...
@@ -34,6 +34,14 @@ void AddKernel(const Context& dev_ctx,
AddRawKernel
<
T
>
(
dev_ctx
,
x
,
y
,
axis
,
out
);
AddRawKernel
<
T
>
(
dev_ctx
,
x
,
y
,
axis
,
out
);
}
}
template
<
typename
T
,
typename
Context
>
void
GradAddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
AddKernel
<
T
>
(
dev_ctx
,
x
,
y
,
out
);
}
}
// namespace phi
}
// namespace phi
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
...
@@ -65,3 +73,15 @@ PD_REGISTER_KERNEL(add,
...
@@ -65,3 +73,15 @@ PD_REGISTER_KERNEL(add,
int64_t
,
int64_t
,
complex64
,
complex64
,
complex128
)
{}
complex128
)
{}
PD_REGISTER_KERNEL
(
grad_add
,
CPU
,
ALL_LAYOUT
,
phi
::
GradAddKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
)
{}
paddle/phi/kernels/kps/elementwise_add_kernel.cu
浏览文件 @
4d7a9eef
...
@@ -33,6 +33,14 @@ void AddKernel(const Context& dev_ctx,
...
@@ -33,6 +33,14 @@ void AddKernel(const Context& dev_ctx,
AddRawKernel
<
T
>
(
dev_ctx
,
x
,
y
,
axis
,
out
);
AddRawKernel
<
T
>
(
dev_ctx
,
x
,
y
,
axis
,
out
);
}
}
template
<
typename
T
,
typename
Context
>
void
GradAddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
AddKernel
<
T
>
(
dev_ctx
,
x
,
y
,
out
);
}
}
// namespace phi
}
// namespace phi
#ifdef PADDLE_WITH_XPU_KP
#ifdef PADDLE_WITH_XPU_KP
...
@@ -71,4 +79,18 @@ PD_REGISTER_KERNEL(add,
...
@@ -71,4 +79,18 @@ PD_REGISTER_KERNEL(add,
phi
::
dtype
::
bfloat16
,
phi
::
dtype
::
bfloat16
,
complex64
,
complex64
,
complex128
)
{}
complex128
)
{}
PD_REGISTER_KERNEL
(
grad_add
,
KPS
,
ALL_LAYOUT
,
phi
::
GradAddKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
complex64
,
complex128
)
{}
#endif
#endif
paddle/phi/ops/compat/elementwise_sig.cc
浏览文件 @
4d7a9eef
...
@@ -25,6 +25,11 @@ KernelSignature ElementwiseAddOpArgumentMapping(
...
@@ -25,6 +25,11 @@ KernelSignature ElementwiseAddOpArgumentMapping(
return
KernelSignature
(
"add_raw"
,
{
"X"
,
"Y"
},
{
"axis"
},
{
"Out"
});
return
KernelSignature
(
"add_raw"
,
{
"X"
,
"Y"
},
{
"axis"
},
{
"Out"
});
}
}
KernelSignature
ElementwiseGradAddOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"grad_add"
,
{
"X"
,
"Y"
},
{},
{
"Out"
});
}
KernelSignature
ElementwiseSubOpArgumentMapping
(
KernelSignature
ElementwiseSubOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
const
ArgumentMappingContext
&
ctx
)
{
int
axis
=
paddle
::
any_cast
<
int
>
(
ctx
.
Attr
(
"axis"
));
int
axis
=
paddle
::
any_cast
<
int
>
(
ctx
.
Attr
(
"axis"
));
...
@@ -317,3 +322,4 @@ PD_REGISTER_ARG_MAPPING_FN(elementwise_heaviside_grad,
...
@@ -317,3 +322,4 @@ PD_REGISTER_ARG_MAPPING_FN(elementwise_heaviside_grad,
phi
::
ElementwiseHeavisideGradOpArgumentMapping
);
phi
::
ElementwiseHeavisideGradOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
elementwise_pow_grad
,
PD_REGISTER_ARG_MAPPING_FN
(
elementwise_pow_grad
,
phi
::
ElementwisePowGradOpArgumentMapping
);
phi
::
ElementwisePowGradOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
grad_add
,
phi
::
ElementwiseGradAddOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录