Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
48f5af99
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看板
未验证
提交
48f5af99
编写于
5月 24, 2023
作者:
Z
zhangyuqin1998
提交者:
GitHub
5月 24, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move raw kernels to legacy (#53913)
* move raw kernels to legacy * Update elementwise_add_kernel.cu * fix
上级
8032d57e
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
503 addition
and
193 deletion
+503
-193
paddle/phi/kernels/cpu/elementwise_add_kernel.cc
paddle/phi/kernels/cpu/elementwise_add_kernel.cc
+34
-5
paddle/phi/kernels/cpu/elementwise_subtract_kernel.cc
paddle/phi/kernels/cpu/elementwise_subtract_kernel.cc
+23
-5
paddle/phi/kernels/elementwise_add_kernel.h
paddle/phi/kernels/elementwise_add_kernel.h
+0
-7
paddle/phi/kernels/elementwise_kernel.cc
paddle/phi/kernels/elementwise_kernel.cc
+0
-123
paddle/phi/kernels/elementwise_subtract_kernel.h
paddle/phi/kernels/elementwise_subtract_kernel.h
+0
-7
paddle/phi/kernels/impl/cholesky_solve_grad_kernel_impl.h
paddle/phi/kernels/impl/cholesky_solve_grad_kernel_impl.h
+1
-1
paddle/phi/kernels/impl/lu_kernel_impl.h
paddle/phi/kernels/impl/lu_kernel_impl.h
+2
-2
paddle/phi/kernels/kps/elementwise_add_kernel.cu
paddle/phi/kernels/kps/elementwise_add_kernel.cu
+32
-7
paddle/phi/kernels/kps/elementwise_subtract_kernel.cu
paddle/phi/kernels/kps/elementwise_subtract_kernel.cu
+19
-6
paddle/phi/kernels/legacy/cpu/elementwise_add_kernel.cc
paddle/phi/kernels/legacy/cpu/elementwise_add_kernel.cc
+46
-0
paddle/phi/kernels/legacy/cpu/elementwise_subtract_kernel.cc
paddle/phi/kernels/legacy/cpu/elementwise_subtract_kernel.cc
+47
-0
paddle/phi/kernels/legacy/elementwise_add_kernel.h
paddle/phi/kernels/legacy/elementwise_add_kernel.h
+28
-0
paddle/phi/kernels/legacy/elementwise_subtract_kernel.h
paddle/phi/kernels/legacy/elementwise_subtract_kernel.h
+29
-0
paddle/phi/kernels/legacy/kps/elementwise_add_kernel.cu
paddle/phi/kernels/legacy/kps/elementwise_add_kernel.cu
+51
-0
paddle/phi/kernels/legacy/kps/elementwise_subtract_kernel.cu
paddle/phi/kernels/legacy/kps/elementwise_subtract_kernel.cu
+54
-0
paddle/phi/kernels/legacy/xpu/elementwise_add_kernel.cc
paddle/phi/kernels/legacy/xpu/elementwise_add_kernel.cc
+60
-0
paddle/phi/kernels/legacy/xpu/elementwise_subtract_kernel.cc
paddle/phi/kernels/legacy/xpu/elementwise_subtract_kernel.cc
+48
-0
paddle/phi/kernels/xpu/elementwise_add_kernel.cc
paddle/phi/kernels/xpu/elementwise_add_kernel.cc
+22
-22
paddle/phi/kernels/xpu/elementwise_subtract_kernel.cc
paddle/phi/kernels/xpu/elementwise_subtract_kernel.cc
+7
-8
未找到文件。
paddle/phi/kernels/cpu/elementwise_add_kernel.cc
浏览文件 @
48f5af99
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
// 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/phi/kernels/elementwise_add_kernel.h"
#include "paddle/phi/api/ext/dispatch.h"
#include "paddle/phi/api/ext/dispatch.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/common/bfloat16.h"
...
@@ -22,15 +23,43 @@
...
@@ -22,15 +23,43 @@
namespace
phi
{
namespace
phi
{
// Create the definition of Add
template
<
typename
T
,
typename
Context
>
DEFINE_CPU_ELEMENTWISE_OP
(
Add
)
void
AddFunctor
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
dev_ctx
.
template
Alloc
<
T
>(
out
);
if
(
x
.
dims
()
==
y
.
dims
())
{
SameDimsElementwiseCompute
<
SameDimsAddFunctor
<
CPUContext
,
T
>>
()(
dev_ctx
,
x
,
y
,
out
);
}
else
{
auto
x_dims
=
x
.
dims
();
auto
y_dims
=
y
.
dims
();
if
(
x_dims
.
size
()
>=
y_dims
.
size
())
{
funcs
::
ElementwiseCompute
<
funcs
::
AddFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
funcs
::
AddFunctor
<
T
>
(),
out
,
axis
);
}
else
{
funcs
::
ElementwiseCompute
<
funcs
::
InverseAddFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
funcs
::
InverseAddFunctor
<
T
>
(),
out
,
axis
);
}
}
}
template
<
typename
T
,
typename
Context
>
void
AddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
AddFunctor
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
);
}
template
<
typename
T
,
typename
Context
>
template
<
typename
T
,
typename
Context
>
void
GradAddKernel
(
const
Context
&
dev_ctx
,
void
GradAddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
DenseTensor
*
out
)
{
Add
RawKernel
<
T
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
);
Add
Functor
<
T
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
);
}
}
}
// namespace phi
}
// namespace phi
...
@@ -41,10 +70,10 @@ using complex128 = ::phi::dtype::complex<double>;
...
@@ -41,10 +70,10 @@ using complex128 = ::phi::dtype::complex<double>;
// NOTE(chenweihang): using bfloat16 will cause redefine with xpu bfloat16
// NOTE(chenweihang): using bfloat16 will cause redefine with xpu bfloat16
// using bfloat16 = ::phi::dtype::bfloat16;
// using bfloat16 = ::phi::dtype::bfloat16;
PD_REGISTER_KERNEL
(
add
_raw
,
PD_REGISTER_KERNEL
(
add
,
CPU
,
CPU
,
ALL_LAYOUT
,
ALL_LAYOUT
,
phi
::
Add
Raw
Kernel
,
phi
::
AddKernel
,
float
,
float
,
double
,
double
,
int16_t
,
int16_t
,
...
...
paddle/phi/kernels/cpu/elementwise_subtract_kernel.cc
浏览文件 @
48f5af99
...
@@ -22,9 +22,27 @@
...
@@ -22,9 +22,27 @@
namespace
phi
{
namespace
phi
{
// Create the definition of Subtract
template
<
typename
T
,
typename
Context
>
DEFINE_CPU_ELEMENTWISE_OP
(
Subtract
)
void
SubtractKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
dev_ctx
.
template
Alloc
<
T
>(
out
);
if
(
x
.
dims
()
==
y
.
dims
())
{
SameDimsElementwiseCompute
<
SameDimsSubtractFunctor
<
CPUContext
,
T
>>
()(
dev_ctx
,
x
,
y
,
out
);
}
else
{
auto
x_dims
=
x
.
dims
();
auto
y_dims
=
y
.
dims
();
if
(
x_dims
.
size
()
>=
y_dims
.
size
())
{
funcs
::
ElementwiseCompute
<
funcs
::
SubtractFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
funcs
::
SubtractFunctor
<
T
>
(),
out
,
-
1
);
}
else
{
funcs
::
ElementwiseCompute
<
funcs
::
InverseSubtractFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
funcs
::
InverseSubtractFunctor
<
T
>
(),
out
,
-
1
);
}
}
}
}
// namespace phi
}
// namespace phi
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
...
@@ -33,10 +51,10 @@ using complex128 = ::phi::dtype::complex<double>;
...
@@ -33,10 +51,10 @@ using complex128 = ::phi::dtype::complex<double>;
// NOTE(chenweihang): using bfloat16 will cause redefine with xpu bfloat16
// NOTE(chenweihang): using bfloat16 will cause redefine with xpu bfloat16
// using bfloat16 = ::phi::dtype::bfloat16;
// using bfloat16 = ::phi::dtype::bfloat16;
PD_REGISTER_KERNEL
(
subtract
_raw
,
PD_REGISTER_KERNEL
(
subtract
,
CPU
,
CPU
,
ALL_LAYOUT
,
ALL_LAYOUT
,
phi
::
Subtract
Raw
Kernel
,
phi
::
SubtractKernel
,
float
,
float
,
double
,
double
,
int16_t
,
int16_t
,
...
...
paddle/phi/kernels/elementwise_add_kernel.h
浏览文件 @
48f5af99
...
@@ -18,13 +18,6 @@
...
@@ -18,13 +18,6 @@
#include "paddle/phi/infermeta/binary.h"
#include "paddle/phi/infermeta/binary.h"
namespace
phi
{
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
AddRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
template
<
typename
T
,
typename
Context
>
void
AddKernel
(
const
Context
&
dev_ctx
,
void
AddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
x
,
...
...
paddle/phi/kernels/elementwise_kernel.cc
已删除
100644 → 0
浏览文件 @
8032d57e
// 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/elementwise_kernel.h"
#include "paddle/phi/kernels/elementwise_add_kernel.h"
#include "paddle/phi/kernels/elementwise_divide_kernel.h"
#include "paddle/phi/kernels/elementwise_multiply_kernel.h"
#include "paddle/phi/kernels/elementwise_subtract_kernel.h"
#include "paddle/phi/backends/all_context.h"
#include "paddle/phi/core/kernel_registry.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
AddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
AddRawKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
);
}
template
<
typename
T
,
typename
Context
>
void
SubtractKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
int
axis
=
-
1
;
SubtractRawKernel
<
T
>
(
dev_ctx
,
x
,
y
,
axis
,
out
);
}
}
// namespace phi
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
PD_REGISTER_KERNEL
(
subtract
,
CPU
,
ALL_LAYOUT
,
phi
::
SubtractKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
,
phi
::
dtype
::
bfloat16
)
{}
PD_REGISTER_KERNEL
(
add
,
CPU
,
ALL_LAYOUT
,
phi
::
AddKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
)
{}
#if defined(PADDLE_WITH_XPU_KP) && defined(PADDLE_WITH_XPU)
PD_REGISTER_KERNEL
(
subtract
,
KPS
,
ALL_LAYOUT
,
phi
::
SubtractKernel
,
float
)
{}
PD_REGISTER_KERNEL
(
add
,
KPS
,
ALL_LAYOUT
,
phi
::
AddKernel
,
float
)
{}
#elif defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PD_REGISTER_KERNEL
(
subtract
,
KPS
,
ALL_LAYOUT
,
phi
::
SubtractKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
phi
::
dtype
::
float16
,
complex64
,
complex128
,
phi
::
dtype
::
bfloat16
)
{}
PD_REGISTER_KERNEL
(
add
,
KPS
,
ALL_LAYOUT
,
phi
::
AddKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
complex64
,
complex128
)
{}
#endif
#if defined(PADDLE_WITH_XPU) && !defined(PADDLE_WITH_XPU_KP)
PD_REGISTER_KERNEL
(
add
,
XPU
,
ALL_LAYOUT
,
phi
::
AddKernel
,
phi
::
dtype
::
float16
,
float
,
int
,
int64_t
)
{}
PD_REGISTER_KERNEL
(
subtract
,
XPU
,
ALL_LAYOUT
,
phi
::
SubtractKernel
,
float
,
phi
::
dtype
::
float16
,
int64_t
)
{}
#endif
paddle/phi/kernels/elementwise_subtract_kernel.h
浏览文件 @
48f5af99
...
@@ -19,13 +19,6 @@
...
@@ -19,13 +19,6 @@
namespace
phi
{
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
SubtractRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
template
<
typename
T
,
typename
Context
>
void
SubtractKernel
(
const
Context
&
dev_ctx
,
void
SubtractKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
x
,
...
...
paddle/phi/kernels/impl/cholesky_solve_grad_kernel_impl.h
浏览文件 @
48f5af99
...
@@ -84,7 +84,7 @@ void CholeskySolveGradKernel(const Context& dev_ctx,
...
@@ -84,7 +84,7 @@ void CholeskySolveGradKernel(const Context& dev_ctx,
DenseTensor
commonterm_conj
=
Conj
<
T
,
Context
>
(
dev_ctx
,
commonterm
);
DenseTensor
commonterm_conj
=
Conj
<
T
,
Context
>
(
dev_ctx
,
commonterm
);
commonterm_conj
=
phi
::
TransposeLast2Dim
<
T
>
(
dev_ctx
,
commonterm_conj
);
commonterm_conj
=
phi
::
TransposeLast2Dim
<
T
>
(
dev_ctx
,
commonterm_conj
);
phi
::
Add
RawKernel
<
T
>
(
dev_ctx
,
commonterm
,
commonterm_conj
,
-
1
,
&
commonterm
);
phi
::
Add
Kernel
<
T
>
(
dev_ctx
,
commonterm
,
commonterm_conj
,
&
commonterm
);
DenseTensor
dy_bst
=
phi
::
Empty
<
T
,
Context
>
(
dev_ctx
,
y_bst_dims
);
DenseTensor
dy_bst
=
phi
::
Empty
<
T
,
Context
>
(
dev_ctx
,
y_bst_dims
);
if
(
upper
)
{
if
(
upper
)
{
...
...
paddle/phi/kernels/impl/lu_kernel_impl.h
浏览文件 @
48f5af99
...
@@ -237,7 +237,7 @@ void Tensor_Add(const Context& dev_ctx,
...
@@ -237,7 +237,7 @@ void Tensor_Add(const Context& dev_ctx,
out
->
Resize
(
src1
.
dims
());
out
->
Resize
(
src1
.
dims
());
dev_ctx
.
template
Alloc
<
T
>(
out
);
dev_ctx
.
template
Alloc
<
T
>(
out
);
phi
::
Add
RawKernel
<
T
,
Context
>
(
dev_ctx
,
src1
,
src2
,
-
1
,
out
);
phi
::
Add
Kernel
<
T
,
Context
>
(
dev_ctx
,
src1
,
src2
,
out
);
}
}
template
<
typename
Context
,
typename
T
>
template
<
typename
Context
,
typename
T
>
...
@@ -248,7 +248,7 @@ void Tensor_Sub(const Context& dev_ctx,
...
@@ -248,7 +248,7 @@ void Tensor_Sub(const Context& dev_ctx,
out
->
Resize
(
src1
.
dims
());
out
->
Resize
(
src1
.
dims
());
dev_ctx
.
template
Alloc
<
T
>(
out
);
dev_ctx
.
template
Alloc
<
T
>(
out
);
phi
::
Subtract
RawKernel
<
T
,
Context
>
(
dev_ctx
,
src1
,
src2
,
-
1
,
out
);
phi
::
Subtract
Kernel
<
T
,
Context
>
(
dev_ctx
,
src1
,
src2
,
out
);
}
}
template
<
typename
Context
,
typename
T
,
size_t
D
>
template
<
typename
Context
,
typename
T
,
size_t
D
>
...
...
paddle/phi/kernels/kps/elementwise_add_kernel.cu
浏览文件 @
48f5af99
...
@@ -18,24 +18,49 @@
...
@@ -18,24 +18,49 @@
#include "paddle/phi/common/float16.h"
#include "paddle/phi/common/float16.h"
#endif
#endif
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/elementwise_add_kernel.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
namespace
phi
{
namespace
phi
{
DEFINE_CUDA_ELEMENTWISE_OP
(
Add
)
template
<
typename
T
,
typename
Context
>
void
AddCudaFunctor
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
std
::
vector
<
const
DenseTensor
*>
inputs
;
inputs
.
reserve
(
2
);
std
::
vector
<
DenseTensor
*>
outputs
;
outputs
.
reserve
(
1
);
inputs
.
emplace_back
(
&
x
);
inputs
.
emplace_back
(
&
y
);
outputs
.
emplace_back
(
out
);
dev_ctx
.
template
Alloc
<
T
>(
out
);
funcs
::
BroadcastKernel
<
T
>
(
dev_ctx
,
inputs
,
&
outputs
,
funcs
::
AddFunctor
<
T
>
(),
axis
);
}
template
<
typename
T
,
typename
Context
>
void
AddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
AddCudaFunctor
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
);
}
template
<
typename
T
,
typename
Context
>
template
<
typename
T
,
typename
Context
>
void
GradAddKernel
(
const
Context
&
dev_ctx
,
void
GradAddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
DenseTensor
*
out
)
{
Add
RawKernel
<
T
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
);
Add
CudaFunctor
<
T
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
);
}
}
}
// namespace phi
}
// namespace phi
#ifdef PADDLE_WITH_XPU_KP
#ifdef PADDLE_WITH_XPU_KP
PD_REGISTER_KERNEL
(
add
_raw
,
KPS
,
ALL_LAYOUT
,
phi
::
AddRaw
Kernel
,
float
)
{}
PD_REGISTER_KERNEL
(
add
,
KPS
,
ALL_LAYOUT
,
phi
::
Add
Kernel
,
float
)
{}
#else
#else
using
float16
=
phi
::
dtype
::
float16
;
using
float16
=
phi
::
dtype
::
float16
;
...
@@ -43,17 +68,17 @@ using bfloat16 = phi::dtype::bfloat16;
...
@@ -43,17 +68,17 @@ using bfloat16 = phi::dtype::bfloat16;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
PD_REGISTER_KERNEL
(
add
_raw
,
PD_REGISTER_KERNEL
(
add
,
KPS
,
KPS
,
ALL_LAYOUT
,
ALL_LAYOUT
,
phi
::
Add
Raw
Kernel
,
phi
::
AddKernel
,
float
,
float
,
double
,
double
,
int16_t
,
int16_t
,
int
,
int
,
int64_t
,
int64_t
,
float16
,
phi
::
dtype
::
float16
,
bfloat16
,
phi
::
dtype
::
bfloat16
,
complex64
,
complex64
,
complex128
)
{}
complex128
)
{}
...
...
paddle/phi/kernels/kps/elementwise_subtract_kernel.cu
浏览文件 @
48f5af99
...
@@ -22,14 +22,27 @@
...
@@ -22,14 +22,27 @@
namespace
phi
{
namespace
phi
{
// Create the definition of Subtract
template
<
typename
T
,
typename
Context
>
DEFINE_CUDA_ELEMENTWISE_OP
(
Subtract
)
void
SubtractKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
std
::
vector
<
const
DenseTensor
*>
inputs
;
inputs
.
reserve
(
2
);
std
::
vector
<
DenseTensor
*>
outputs
;
outputs
.
reserve
(
1
);
inputs
.
emplace_back
(
&
x
);
inputs
.
emplace_back
(
&
y
);
outputs
.
emplace_back
(
out
);
dev_ctx
.
template
Alloc
<
T
>(
out
);
funcs
::
BroadcastKernel
<
T
>
(
dev_ctx
,
inputs
,
&
outputs
,
funcs
::
SubtractFunctor
<
T
>
(),
-
1
);
}
}
// namespace phi
}
// namespace phi
#ifdef PADDLE_WITH_XPU_KP
#ifdef PADDLE_WITH_XPU_KP
PD_REGISTER_KERNEL
(
PD_REGISTER_KERNEL
(
subtract
,
KPS
,
ALL_LAYOUT
,
phi
::
SubtractKernel
,
float
)
{}
subtract_raw
,
KPS
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
)
{}
#else
#else
using
float16
=
phi
::
dtype
::
float16
;
using
float16
=
phi
::
dtype
::
float16
;
...
@@ -37,10 +50,10 @@ using bfloat16 = phi::dtype::bfloat16;
...
@@ -37,10 +50,10 @@ using bfloat16 = phi::dtype::bfloat16;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
PD_REGISTER_KERNEL
(
subtract
_raw
,
PD_REGISTER_KERNEL
(
subtract
,
KPS
,
KPS
,
ALL_LAYOUT
,
ALL_LAYOUT
,
phi
::
Subtract
Raw
Kernel
,
phi
::
SubtractKernel
,
float
,
float
,
double
,
double
,
int16_t
,
int16_t
,
...
...
paddle/phi/kernels/legacy/cpu/elementwise_add_kernel.cc
0 → 100644
浏览文件 @
48f5af99
// Copyright (c) 2023 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/api/ext/dispatch.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/common/complex.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/cpu/elementwise.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
namespace
phi
{
// Create the definition of Add
DEFINE_CPU_ELEMENTWISE_OP
(
Add
)
}
// namespace phi
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
// NOTE(chenweihang): using bfloat16 will cause redefine with xpu bfloat16
// using bfloat16 = ::phi::dtype::bfloat16;
PD_REGISTER_KERNEL
(
add_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
AddRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
)
{}
paddle/phi/kernels/legacy/cpu/elementwise_subtract_kernel.cc
0 → 100644
浏览文件 @
48f5af99
// Copyright (c) 2023 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/api/ext/dispatch.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/common/complex.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/cpu/elementwise.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
namespace
phi
{
// Create the definition of Subtract
DEFINE_CPU_ELEMENTWISE_OP
(
Subtract
)
}
// namespace phi
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
// NOTE(chenweihang): using bfloat16 will cause redefine with xpu bfloat16
// using bfloat16 = ::phi::dtype::bfloat16;
PD_REGISTER_KERNEL
(
subtract_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
,
phi
::
dtype
::
bfloat16
)
{}
paddle/phi/kernels/legacy/elementwise_add_kernel.h
0 → 100644
浏览文件 @
48f5af99
// Copyright (c) 2023 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/core/dense_tensor.h"
#include "paddle/phi/infermeta/binary.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
AddRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
}
// namespace phi
paddle/phi/kernels/legacy/elementwise_subtract_kernel.h
0 → 100644
浏览文件 @
48f5af99
// Copyright (c) 2023 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/core/dense_tensor.h"
#include "paddle/phi/infermeta/binary.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
SubtractRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
}
// namespace phi
paddle/phi/kernels/legacy/kps/elementwise_add_kernel.cu
0 → 100644
浏览文件 @
48f5af99
// Copyright (c) 2023 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/backends/gpu/gpu_context.h"
#ifndef PADDLE_WITH_XPU_KP
#include "paddle/phi/common/complex.h"
#include "paddle/phi/common/float16.h"
#endif
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
namespace
phi
{
DEFINE_CUDA_ELEMENTWISE_OP
(
Add
)
}
// namespace phi
#ifdef PADDLE_WITH_XPU_KP
PD_REGISTER_KERNEL
(
add_raw
,
KPS
,
ALL_LAYOUT
,
phi
::
AddRawKernel
,
float
)
{}
#else
using
float16
=
phi
::
dtype
::
float16
;
using
bfloat16
=
phi
::
dtype
::
bfloat16
;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
PD_REGISTER_KERNEL
(
add_raw
,
KPS
,
ALL_LAYOUT
,
phi
::
AddRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
#endif
paddle/phi/kernels/legacy/kps/elementwise_subtract_kernel.cu
0 → 100644
浏览文件 @
48f5af99
// Copyright (c) 2023 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/backends/gpu/gpu_context.h"
#ifndef PADDLE_WITH_XPU_KP
#include "paddle/phi/common/complex.h"
#include "paddle/phi/common/float16.h"
#endif
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
namespace
phi
{
// Create the definition of Subtract
DEFINE_CUDA_ELEMENTWISE_OP
(
Subtract
)
}
// namespace phi
#ifdef PADDLE_WITH_XPU_KP
PD_REGISTER_KERNEL
(
subtract_raw
,
KPS
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
)
{}
#else
using
float16
=
phi
::
dtype
::
float16
;
using
bfloat16
=
phi
::
dtype
::
bfloat16
;
using
complex64
=
::
phi
::
dtype
::
complex
<
float
>
;
using
complex128
=
::
phi
::
dtype
::
complex
<
double
>
;
PD_REGISTER_KERNEL
(
subtract_raw
,
KPS
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
#endif
paddle/phi/kernels/legacy/xpu/elementwise_add_kernel.cc
0 → 100644
浏览文件 @
48f5af99
// Copyright (c) 2023 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/elementwise_add_kernel.h"
#include <memory>
#include <string>
#include "paddle/phi/api/ext/dispatch.h"
#include "paddle/phi/backends/xpu/enforce_xpu.h"
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/backends/xpu/xpu_header.h"
#include "paddle/phi/backends/xpu/xpu_info.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
#include "paddle/phi/kernels/xpu/elementwise.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
AddRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
auto
f
=
[](
xpu
::
Context
*
ctx
,
const
XPUType
*
x
,
const
XPUType
*
y
,
XPUType
*
z
,
const
std
::
vector
<
int
>&
xshape
,
const
std
::
vector
<
int
>&
yshape
)
{
return
xpu
::
broadcast_add
<
XPUType
>
(
ctx
,
x
,
y
,
z
,
xshape
,
yshape
);
};
XPUElementwise
<
T
,
XPUType
>
(
dev_ctx
,
x
,
y
,
axis
,
out
,
f
);
}
}
// namespace phi
PD_REGISTER_KERNEL
(
add_raw
,
XPU
,
ALL_LAYOUT
,
phi
::
AddRawKernel
,
phi
::
dtype
::
float16
,
float
,
int
,
int64_t
)
{}
paddle/phi/kernels/legacy/xpu/elementwise_subtract_kernel.cc
0 → 100644
浏览文件 @
48f5af99
/* Copyright (c) 2023 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/elementwise_subtract_kernel.h"
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/backends/xpu/xpu_header.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/xpu/elementwise.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
SubtractRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
auto
f
=
[](
xpu
::
Context
*
ctx
,
const
XPUType
*
x
,
const
XPUType
*
y
,
XPUType
*
z
,
const
std
::
vector
<
int
>&
xshape
,
const
std
::
vector
<
int
>&
yshape
)
{
return
xpu
::
broadcast_sub
<
XPUType
>
(
ctx
,
x
,
y
,
z
,
xshape
,
yshape
);
};
phi
::
XPUElementwise
<
T
,
XPUType
>
(
dev_ctx
,
x
,
y
,
axis
,
out
,
f
);
}
}
// namespace phi
PD_REGISTER_KERNEL
(
subtract_raw
,
XPU
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
,
phi
::
dtype
::
float16
,
int64_t
)
{}
paddle/phi/kernels/xpu/elementwise_add_kernel.cc
浏览文件 @
48f5af99
...
@@ -28,6 +28,25 @@
...
@@ -28,6 +28,25 @@
namespace
phi
{
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
AddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
auto
f
=
[](
xpu
::
Context
*
ctx
,
const
XPUType
*
x
,
const
XPUType
*
y
,
XPUType
*
z
,
const
std
::
vector
<
int
>&
xshape
,
const
std
::
vector
<
int
>&
yshape
)
{
return
xpu
::
broadcast_add
<
XPUType
>
(
ctx
,
x
,
y
,
z
,
xshape
,
yshape
);
};
XPUElementwise
<
T
,
XPUType
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
,
f
);
}
template
<
typename
T
,
typename
Context
>
template
<
typename
T
,
typename
Context
>
void
GradAddXPUKernel
(
const
Context
&
dev_ctx
,
void
GradAddXPUKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
x
,
...
@@ -47,26 +66,6 @@ void GradAddXPUKernel(const Context& dev_ctx,
...
@@ -47,26 +66,6 @@ void GradAddXPUKernel(const Context& dev_ctx,
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"broadcast_add"
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"broadcast_add"
);
}
}
template
<
typename
T
,
typename
Context
>
void
AddRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
auto
f
=
[](
xpu
::
Context
*
ctx
,
const
XPUType
*
x
,
const
XPUType
*
y
,
XPUType
*
z
,
const
std
::
vector
<
int
>&
xshape
,
const
std
::
vector
<
int
>&
yshape
)
{
return
xpu
::
broadcast_add
<
XPUType
>
(
ctx
,
x
,
y
,
z
,
xshape
,
yshape
);
};
XPUElementwise
<
T
,
XPUType
>
(
dev_ctx
,
x
,
y
,
axis
,
out
,
f
);
}
}
// namespace phi
}
// namespace phi
PD_REGISTER_KERNEL
(
grad_add
,
PD_REGISTER_KERNEL
(
grad_add
,
...
@@ -75,10 +74,11 @@ PD_REGISTER_KERNEL(grad_add,
...
@@ -75,10 +74,11 @@ PD_REGISTER_KERNEL(grad_add,
phi
::
GradAddXPUKernel
,
phi
::
GradAddXPUKernel
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
float16
,
float
)
{}
float
)
{}
PD_REGISTER_KERNEL
(
add_raw
,
PD_REGISTER_KERNEL
(
add
,
XPU
,
XPU
,
ALL_LAYOUT
,
ALL_LAYOUT
,
phi
::
Add
Raw
Kernel
,
phi
::
AddKernel
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
float16
,
float
,
float
,
int
,
int
,
...
...
paddle/phi/kernels/xpu/elementwise_subtract_kernel.cc
浏览文件 @
48f5af99
...
@@ -20,11 +20,10 @@ limitations under the License. */
...
@@ -20,11 +20,10 @@ limitations under the License. */
namespace
phi
{
namespace
phi
{
template
<
typename
T
,
typename
Context
>
template
<
typename
T
,
typename
Context
>
void
SubtractRawKernel
(
const
Context
&
dev_ctx
,
void
SubtractKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
DenseTensor
*
out
)
{
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
auto
f
=
[](
xpu
::
Context
*
ctx
,
auto
f
=
[](
xpu
::
Context
*
ctx
,
const
XPUType
*
x
,
const
XPUType
*
x
,
...
@@ -35,14 +34,14 @@ void SubtractRawKernel(const Context& dev_ctx,
...
@@ -35,14 +34,14 @@ void SubtractRawKernel(const Context& dev_ctx,
return
xpu
::
broadcast_sub
<
XPUType
>
(
ctx
,
x
,
y
,
z
,
xshape
,
yshape
);
return
xpu
::
broadcast_sub
<
XPUType
>
(
ctx
,
x
,
y
,
z
,
xshape
,
yshape
);
};
};
phi
::
XPUElementwise
<
T
,
XPUType
>
(
dev_ctx
,
x
,
y
,
axis
,
out
,
f
);
phi
::
XPUElementwise
<
T
,
XPUType
>
(
dev_ctx
,
x
,
y
,
-
1
,
out
,
f
);
}
}
}
// namespace phi
}
// namespace phi
PD_REGISTER_KERNEL
(
subtract
_raw
,
PD_REGISTER_KERNEL
(
subtract
,
XPU
,
XPU
,
ALL_LAYOUT
,
ALL_LAYOUT
,
phi
::
Subtract
Raw
Kernel
,
phi
::
SubtractKernel
,
float
,
float
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
float16
,
int64_t
)
{}
int64_t
)
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录