Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
883a8eea
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,发现更多精彩内容 >>
未验证
提交
883a8eea
编写于
3月 17, 2022
作者:
Y
YuanRisheng
提交者:
GitHub
3月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename math (#40641)
上级
7d0db629
变更
19
显示空白变更内容
内联
并排
Showing
19 changed file
with
320 addition
and
397 deletion
+320
-397
paddle/fluid/operators/determinant_op.h
paddle/fluid/operators/determinant_op.h
+1
-1
paddle/fluid/operators/eig_op.h
paddle/fluid/operators/eig_op.h
+1
-1
paddle/fluid/operators/elementwise/elementwise_add_op.h
paddle/fluid/operators/elementwise/elementwise_add_op.h
+1
-1
paddle/fluid/operators/elementwise/elementwise_mul_op.h
paddle/fluid/operators/elementwise/elementwise_mul_op.h
+1
-1
paddle/fluid/operators/lu_op.h
paddle/fluid/operators/lu_op.h
+1
-1
paddle/phi/kernels/CMakeLists.txt
paddle/phi/kernels/CMakeLists.txt
+1
-2
paddle/phi/kernels/cpu/elementwise_kernel.cc
paddle/phi/kernels/cpu/elementwise_kernel.cc
+117
-0
paddle/phi/kernels/cpu/math_kernel.cc
paddle/phi/kernels/cpu/math_kernel.cc
+0
-140
paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc
paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc
+1
-1
paddle/phi/kernels/elementwise_kernel.cc
paddle/phi/kernels/elementwise_kernel.cc
+1
-1
paddle/phi/kernels/elementwise_kernel.h
paddle/phi/kernels/elementwise_kernel.h
+97
-1
paddle/phi/kernels/gpu/elementwise_kernel.cu
paddle/phi/kernels/gpu/elementwise_kernel.cu
+93
-0
paddle/phi/kernels/gpu/math_kernel.cu
paddle/phi/kernels/gpu/math_kernel.cu
+0
-125
paddle/phi/kernels/gpu/matrix_rank_tol_kernel.cu
paddle/phi/kernels/gpu/matrix_rank_tol_kernel.cu
+1
-1
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/determinant_grad_kernel_impl.h
paddle/phi/kernels/impl/determinant_grad_kernel_impl.h
+1
-1
paddle/phi/kernels/impl/eigh_grad_kernel_impl.h
paddle/phi/kernels/impl/eigh_grad_kernel_impl.h
+1
-1
paddle/phi/kernels/math_kernel.h
paddle/phi/kernels/math_kernel.h
+0
-117
paddle/phi/tests/kernels/test_elementwise_dev_api.cc
paddle/phi/tests/kernels/test_elementwise_dev_api.cc
+1
-1
未找到文件。
paddle/fluid/operators/determinant_op.h
浏览文件 @
883a8eea
...
...
@@ -22,6 +22,7 @@
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/phi/kernels/complex_kernel.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/full_kernel.h"
#include "paddle/phi/kernels/funcs/common_shape.h"
#include "paddle/phi/kernels/funcs/diag_functor.h"
...
...
@@ -30,7 +31,6 @@
#include "paddle/phi/kernels/funcs/unsqueeze.h"
#include "paddle/phi/kernels/impl/determinant_grad_kernel_impl.h"
#include "paddle/phi/kernels/impl/determinant_kernel_impl.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/matmul_kernel.h"
#include "paddle/phi/kernels/transpose_kernel.h"
...
...
paddle/fluid/operators/eig_op.h
浏览文件 @
883a8eea
...
...
@@ -21,13 +21,13 @@
#include "paddle/fluid/operators/transpose_op.h"
#include "paddle/fluid/platform/for_range.h"
#include "paddle/phi/kernels/complex_kernel.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/funcs/complex_functors.h"
#include "paddle/phi/kernels/funcs/diag_functor.h"
#include "paddle/phi/kernels/funcs/lapack/lapack_function.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/slice.h"
#include "paddle/phi/kernels/funcs/unsqueeze.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/matmul_kernel.h"
#include "paddle/phi/kernels/transpose_kernel.h"
...
...
paddle/fluid/operators/elementwise/elementwise_add_op.h
浏览文件 @
883a8eea
...
...
@@ -27,7 +27,7 @@ limitations under the License. */
// only can include the headers in paddle/phi/include dirs
#include "paddle/phi/kernels/elementwise_grad_kernel.h"
#include "paddle/phi/kernels/
math
_kernel.h"
#include "paddle/phi/kernels/
elementwise
_kernel.h"
#endif
namespace
paddle
{
...
...
paddle/fluid/operators/elementwise/elementwise_mul_op.h
浏览文件 @
883a8eea
...
...
@@ -18,7 +18,7 @@ limitations under the License. */
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
#include "paddle/fluid/platform/cpu_info.h"
#include "paddle/phi/kernels/
math
_kernel.h"
#include "paddle/phi/kernels/
elementwise
_kernel.h"
namespace
paddle
{
namespace
operators
{
...
...
paddle/fluid/operators/lu_op.h
浏览文件 @
883a8eea
...
...
@@ -18,9 +18,9 @@ limitations under the License. */
#include "paddle/fluid/framework/phi_utils.h"
#include "paddle/fluid/operators/set_value_op.h"
#include "paddle/fluid/operators/svd_helper.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/funcs/lapack/lapack_function.h"
#include "paddle/phi/kernels/funcs/tril_triu_compute.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/triangular_solve_kernel.h"
namespace
paddle
{
...
...
paddle/phi/kernels/CMakeLists.txt
浏览文件 @
883a8eea
...
...
@@ -27,7 +27,7 @@ kernel_library(full_kernel DEPS ${COMMON_KERNEL_DEPS} empty_kernel)
# Some kernels depend on some targets that are not commonly used.
# These targets are not suitable for common dependencies.
# In this case, you need to manually generate them here.
set
(
MANUAL_BUILD_KERNELS eigh_kernel gumbel_softmax_kernel gumbel_softmax_grad_kernel
math_kernel
set
(
MANUAL_BUILD_KERNELS eigh_kernel gumbel_softmax_kernel gumbel_softmax_grad_kernel
matrix_power_kernel matrix_power_grad_kernel maxout_kernel maxout_grad_kernel pool_kernel
put_along_axis_kernel put_along_axis_grad_kernel segment_pool_kernel segment_pool_grad_kernel
softmax_kernel softmax_grad_kernel take_along_axis_kernel take_along_axis_grad_kernel
...
...
@@ -35,7 +35,6 @@ set(MANUAL_BUILD_KERNELS eigh_kernel gumbel_softmax_kernel gumbel_softmax_grad_k
kernel_library
(
eigh_kernel DEPS
${
COMMON_KERNEL_DEPS
}
lapack_function
)
kernel_library
(
gumbel_softmax_kernel DEPS
${
COMMON_KERNEL_DEPS
}
softmax
)
kernel_library
(
gumbel_softmax_grad_kernel DEPS
${
COMMON_KERNEL_DEPS
}
softmax
)
kernel_library
(
math_kernel DEPS
${
COMMON_KERNEL_DEPS
}
cast_kernel copy_kernel
)
kernel_library
(
matrix_power_kernel DEPS
${
COMMON_KERNEL_DEPS
}
matrix_inverse
)
kernel_library
(
matrix_power_grad_kernel DEPS
${
COMMON_KERNEL_DEPS
}
matrix_inverse
)
kernel_library
(
maxout_kernel DEPS
${
COMMON_KERNEL_DEPS
}
maxouting
)
...
...
paddle/phi/kernels/cpu/elementwise_kernel.cc
浏览文件 @
883a8eea
...
...
@@ -12,10 +12,81 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/cpu/elementwise.h"
#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/impl/elementwise_kernel_impl.h"
namespace
phi
{
#define DEFINE_CPU_ELEMENTWISE_OP(name) \
template <typename T, typename Context> \
void name##RawKernel(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<SameDims##name##Functor<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::name##Functor<T>, T>( \
dev_ctx, x, y, axis, funcs::name##Functor<T>(), out); \
} else { \
funcs::ElementwiseCompute<funcs::Inverse##name##Functor<T>, T>( \
dev_ctx, x, y, axis, funcs::Inverse##name##Functor<T>(), out); \
} \
} \
}
template
<
typename
T
,
typename
Context
>
void
DivideRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
// allocate memory for out
dev_ctx
.
template
Alloc
<
T
>(
out
);
if
(
x
.
dims
()
==
y
.
dims
()
&&
std
::
is_floating_point
<
T
>::
value
)
{
SameDimsElementwiseCompute
<
SameDimsDivideFunctor
<
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
::
DivideFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
axis
,
funcs
::
DivideFunctor
<
T
>
(),
out
);
}
else
{
funcs
::
ElementwiseCompute
<
funcs
::
InverseDivideFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
axis
,
funcs
::
InverseDivideFunctor
<
T
>
(),
out
);
}
}
}
// Create the definition of Add
DEFINE_CPU_ELEMENTWISE_OP
(
Add
)
// Create the definition of Subtract
DEFINE_CPU_ELEMENTWISE_OP
(
Subtract
)
// Create the definition of Multiply
DEFINE_CPU_ELEMENTWISE_OP
(
Multiply
)
}
// 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
(
elementwise_fmax
,
CPU
,
ALL_LAYOUT
,
...
...
@@ -33,3 +104,49 @@ PD_REGISTER_KERNEL(elementwise_fmin,
double
,
int
,
int64_t
)
{}
PD_REGISTER_KERNEL
(
add_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
AddRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
subtract_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
,
phi
::
dtype
::
bfloat16
)
{}
PD_REGISTER_KERNEL
(
divide_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
DivideRawKernel
,
float
,
double
,
int
,
int64_t
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
multiply_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
MultiplyRawKernel
,
float
,
double
,
int
,
int64_t
,
bool
,
complex64
,
complex128
,
phi
::
dtype
::
bfloat16
)
{}
paddle/phi/kernels/cpu/math_kernel.cc
已删除
100644 → 0
浏览文件 @
7d0db629
// Copyright (c) 2021 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/math_kernel.h"
#include "paddle/phi/api/ext/dispatch.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/scalar.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/cpu/elementwise.h"
#include "paddle/phi/kernels/funcs/elementwise_base.h"
#include "paddle/phi/kernels/funcs/elementwise_functor.h"
// See Note [ Why still include the fluid headers? ]
#include "paddle/fluid/framework/eigen.h"
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/common/complex.h"
namespace
phi
{
#define DEFINE_CPU_ELEMENTWISE_OP(name) \
template <typename T, typename Context> \
void name##RawKernel(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<SameDims##name##Functor<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::name##Functor<T>, T>( \
dev_ctx, x, y, axis, funcs::name##Functor<T>(), out); \
} else { \
funcs::ElementwiseCompute<funcs::Inverse##name##Functor<T>, T>( \
dev_ctx, x, y, axis, funcs::Inverse##name##Functor<T>(), out); \
} \
} \
}
template
<
typename
T
,
typename
Context
>
void
DivideRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
)
{
// allocate memory for out
dev_ctx
.
template
Alloc
<
T
>(
out
);
if
(
x
.
dims
()
==
y
.
dims
()
&&
std
::
is_floating_point
<
T
>::
value
)
{
SameDimsElementwiseCompute
<
SameDimsDivideFunctor
<
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
::
DivideFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
axis
,
funcs
::
DivideFunctor
<
T
>
(),
out
);
}
else
{
funcs
::
ElementwiseCompute
<
funcs
::
InverseDivideFunctor
<
T
>
,
T
>
(
dev_ctx
,
x
,
y
,
axis
,
funcs
::
InverseDivideFunctor
<
T
>
(),
out
);
}
}
}
// Create the definition of Add
DEFINE_CPU_ELEMENTWISE_OP
(
Add
)
// Create the definition of Subtract
DEFINE_CPU_ELEMENTWISE_OP
(
Subtract
)
// Create the definition of Multiply
DEFINE_CPU_ELEMENTWISE_OP
(
Multiply
)
}
// 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
)
{}
PD_REGISTER_KERNEL
(
subtract_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
complex64
,
complex128
,
phi
::
dtype
::
bfloat16
)
{}
PD_REGISTER_KERNEL
(
divide_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
DivideRawKernel
,
float
,
double
,
int
,
int64_t
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
multiply_raw
,
CPU
,
ALL_LAYOUT
,
phi
::
MultiplyRawKernel
,
float
,
double
,
int
,
int64_t
,
bool
,
complex64
,
complex128
,
phi
::
dtype
::
bfloat16
)
{}
paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc
浏览文件 @
883a8eea
...
...
@@ -17,12 +17,12 @@
#include <Eigen/Dense>
#include <Eigen/SVD>
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/full_kernel.h"
#include "paddle/phi/kernels/funcs/compare_functors.h"
#include "paddle/phi/kernels/funcs/eigen/common.h"
#include "paddle/phi/kernels/funcs/elementwise_base.h"
#include "paddle/phi/kernels/impl/matrix_rank_kernel_impl.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/reduce_kernel.h"
namespace
phi
{
...
...
paddle/phi/kernels/
math
_kernel.cc
→
paddle/phi/kernels/
elementwise
_kernel.cc
浏览文件 @
883a8eea
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/
math
_kernel.h"
#include "paddle/phi/kernels/
elementwise
_kernel.h"
#include "paddle/phi/backends/all_context.h"
#include "paddle/phi/core/kernel_registry.h"
...
...
paddle/phi/kernels/elementwise_kernel.h
浏览文件 @
883a8eea
...
...
@@ -15,7 +15,7 @@
#pragma once
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/
core/device_context
.h"
#include "paddle/phi/
infermeta/binary
.h"
namespace
phi
{
...
...
@@ -33,4 +33,100 @@ void ElementwiseFMinKernel(const Context& dev_ctx,
int
axis
,
DenseTensor
*
out
);
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
>
void
AddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
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
>
void
SubtractKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
DivideRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
DivideKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
MultiplyRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
MultiplyKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
DenseTensor
Add
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
AddKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
template
<
typename
T
,
typename
Context
>
DenseTensor
Subtract
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
SubtractKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
template
<
typename
T
,
typename
Context
>
DenseTensor
Divide
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
DivideKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
template
<
typename
T
,
typename
Context
>
DenseTensor
Multiply
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
MultiplyKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
}
// namespace phi
paddle/phi/kernels/gpu/elementwise_kernel.cu
浏览文件 @
883a8eea
...
...
@@ -13,9 +13,50 @@
// limitations under the License.
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/complex.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/elementwise_kernel_impl.h"
namespace
phi
{
#define DEFINE_CUDA_ELEMENTWISE_OP(name) \
template <typename T, typename Context> \
void name##RawKernel(const Context& dev_ctx, \
const DenseTensor& x, \
const DenseTensor& y, \
int axis, \
DenseTensor* out) { \
std::vector<const DenseTensor*> inputs; \
std::vector<DenseTensor*> outputs; \
inputs.emplace_back(&x); \
inputs.emplace_back(&y); \
outputs.emplace_back(out); \
dev_ctx.template Alloc<T>(out); \
funcs::BroadcastKernel<ElementwiseType::kBinary, T, T>( \
dev_ctx, inputs, &outputs, axis, funcs::name##Functor<T>()); \
}
/**
* Kernels
*/
// Create the definition of Add
DEFINE_CUDA_ELEMENTWISE_OP
(
Add
)
// Create the definition of Subtract
DEFINE_CUDA_ELEMENTWISE_OP
(
Subtract
)
// Create the definition of Multiply
DEFINE_CUDA_ELEMENTWISE_OP
(
Multiply
)
// Create the definition of Divide
DEFINE_CUDA_ELEMENTWISE_OP
(
Divide
)
}
// namespace phi
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
(
elementwise_fmax
,
GPU
,
ALL_LAYOUT
,
...
...
@@ -33,3 +74,55 @@ PD_REGISTER_KERNEL(elementwise_fmin,
double
,
int
,
int64_t
)
{}
PD_REGISTER_KERNEL
(
add_raw
,
GPU
,
ALL_LAYOUT
,
phi
::
AddRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
subtract_raw
,
GPU
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
divide_raw
,
GPU
,
ALL_LAYOUT
,
phi
::
DivideRawKernel
,
float
,
double
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
multiply_raw
,
GPU
,
ALL_LAYOUT
,
phi
::
MultiplyRawKernel
,
float
,
double
,
int
,
int64_t
,
bool
,
float16
,
complex64
,
complex128
,
bfloat16
)
{}
paddle/phi/kernels/gpu/math_kernel.cu
已删除
100644 → 0
浏览文件 @
7d0db629
/* Copyright (c) 2021 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/math_kernel.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/kernels/funcs/broadcast_function.h"
#include "paddle/phi/kernels/funcs/elementwise_functor.h"
#include "paddle/phi/kernels/gpu/reduce.h"
#ifdef __NVCC__
#include "cub/cub.cuh"
#endif
#ifdef __HIPCC__
#include <hipcub/hipcub.hpp>
namespace
cub
=
hipcub
;
#endif
#include "paddle/phi/common/complex.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/core/compat/convert_utils.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/kernel_registry.h"
namespace
phi
{
#define DEFINE_CUDA_ELEMENTWISE_OP(name) \
template <typename T, typename Context> \
void name##RawKernel(const Context& dev_ctx, \
const DenseTensor& x, \
const DenseTensor& y, \
int axis, \
DenseTensor* out) { \
std::vector<const DenseTensor*> inputs; \
std::vector<DenseTensor*> outputs; \
inputs.emplace_back(&x); \
inputs.emplace_back(&y); \
outputs.emplace_back(out); \
dev_ctx.template Alloc<T>(out); \
funcs::BroadcastKernel<ElementwiseType::kBinary, T, T>( \
dev_ctx, inputs, &outputs, axis, funcs::name##Functor<T>()); \
}
/**
* Kernels
*/
// Create the definition of Add
DEFINE_CUDA_ELEMENTWISE_OP
(
Add
)
// Create the definition of Subtract
DEFINE_CUDA_ELEMENTWISE_OP
(
Subtract
)
// Create the definition of Multiply
DEFINE_CUDA_ELEMENTWISE_OP
(
Multiply
)
// Create the definition of Divide
DEFINE_CUDA_ELEMENTWISE_OP
(
Divide
)
}
// namespace phi
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
,
GPU
,
ALL_LAYOUT
,
phi
::
AddRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
subtract_raw
,
GPU
,
ALL_LAYOUT
,
phi
::
SubtractRawKernel
,
float
,
double
,
int16_t
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
divide_raw
,
GPU
,
ALL_LAYOUT
,
phi
::
DivideRawKernel
,
float
,
double
,
int
,
int64_t
,
float16
,
bfloat16
,
complex64
,
complex128
)
{}
PD_REGISTER_KERNEL
(
multiply_raw
,
GPU
,
ALL_LAYOUT
,
phi
::
MultiplyRawKernel
,
float
,
double
,
int
,
int64_t
,
bool
,
float16
,
complex64
,
complex128
,
bfloat16
)
{}
paddle/phi/kernels/gpu/matrix_rank_tol_kernel.cu
浏览文件 @
883a8eea
...
...
@@ -23,11 +23,11 @@
#include "paddle/phi/backends/dynload/cusolver.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/abs_kernel.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/full_kernel.h"
#include "paddle/phi/kernels/funcs/broadcast_function.h"
#include "paddle/phi/kernels/funcs/compare_functors.h"
#include "paddle/phi/kernels/impl/matrix_rank_kernel_impl.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/reduce_kernel.h"
namespace
phi
{
...
...
paddle/phi/kernels/impl/cholesky_solve_grad_kernel_impl.h
浏览文件 @
883a8eea
...
...
@@ -19,6 +19,7 @@
#include "paddle/phi/kernels/cholesky_solve_kernel.h"
#include "paddle/phi/kernels/complex_kernel.h"
#include "paddle/phi/kernels/copy_kernel.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/expand_kernel.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
...
...
@@ -27,7 +28,6 @@
#include "paddle/phi/kernels/funcs/for_range.h"
#include "paddle/phi/kernels/funcs/matrix_reduce.h"
#include "paddle/phi/kernels/funcs/tril_triu_compute.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/transpose_kernel.h"
namespace
phi
{
...
...
paddle/phi/kernels/impl/determinant_grad_kernel_impl.h
浏览文件 @
883a8eea
...
...
@@ -17,13 +17,13 @@
#include "paddle/phi/kernels/determinant_grad_kernel.h"
#include "paddle/phi/kernels/copy_kernel.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/full_kernel.h"
#include "paddle/phi/kernels/funcs/for_range.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/matrix_inverse.h"
#include "paddle/phi/kernels/funcs/unsqueeze.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/transpose_kernel.h"
namespace
phi
{
...
...
paddle/phi/kernels/impl/eigh_grad_kernel_impl.h
浏览文件 @
883a8eea
...
...
@@ -16,11 +16,11 @@
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/kernels/complex_kernel.h"
#include "paddle/phi/kernels/elementwise_kernel.h"
#include "paddle/phi/kernels/funcs/diag_functor.h"
#include "paddle/phi/kernels/funcs/eigen/common.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/unsqueeze.h"
#include "paddle/phi/kernels/math_kernel.h"
#include "paddle/phi/kernels/matmul_kernel.h"
#include "paddle/phi/kernels/transpose_kernel.h"
...
...
paddle/phi/kernels/math_kernel.h
已删除
100644 → 0
浏览文件 @
7d0db629
/* Copyright (c) 2021 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
);
template
<
typename
T
,
typename
Context
>
void
AddKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
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
>
void
SubtractKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
DivideRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
DivideKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
MultiplyRawKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
int
axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
MultiplyKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
DenseTensor
Add
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
AddKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
template
<
typename
T
,
typename
Context
>
DenseTensor
Subtract
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
SubtractKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
template
<
typename
T
,
typename
Context
>
DenseTensor
Divide
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
DivideKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
template
<
typename
T
,
typename
Context
>
DenseTensor
Multiply
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
y
)
{
DenseTensor
dense_out
;
MetaTensor
meta_out
(
&
dense_out
);
ElementwiseInferMeta
(
x
,
y
,
&
meta_out
);
MultiplyKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
,
&
dense_out
);
return
dense_out
;
}
}
// namespace phi
paddle/phi/tests/kernels/test_elementwise_dev_api.cc
浏览文件 @
883a8eea
...
...
@@ -16,7 +16,7 @@ limitations under the License. */
#include <memory>
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/kernels/
math
_kernel.h"
#include "paddle/phi/kernels/
elementwise
_kernel.h"
#include "paddle/fluid/memory/allocation/allocator_facade.h"
#include "paddle/phi/api/lib/utils/allocator.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录