Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ab583173
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
ab583173
编写于
8月 16, 2022
作者:
Z
zhangkaihuo
提交者:
GitHub
8月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use base visit in cpu kernel (#45062)
上级
0b4268a6
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
62 addition
and
63 deletion
+62
-63
paddle/phi/kernels/sparse/cpu/coalesce_kernel.cc
paddle/phi/kernels/sparse/cpu/coalesce_kernel.cc
+1
-1
paddle/phi/kernels/sparse/cpu/conv_grad_kernel.cc
paddle/phi/kernels/sparse/cpu/conv_grad_kernel.cc
+1
-1
paddle/phi/kernels/sparse/cpu/conv_kernel.cc
paddle/phi/kernels/sparse/cpu/conv_kernel.cc
+1
-1
paddle/phi/kernels/sparse/cpu/elementwise_grad_kernel.cc
paddle/phi/kernels/sparse/cpu/elementwise_grad_kernel.cc
+32
-30
paddle/phi/kernels/sparse/cpu/elementwise_kernel.cc
paddle/phi/kernels/sparse/cpu/elementwise_kernel.cc
+18
-21
paddle/phi/kernels/sparse/cpu/mask_kernel.cc
paddle/phi/kernels/sparse/cpu/mask_kernel.cc
+2
-2
paddle/phi/kernels/sparse/cpu/pool_grad_kernel.cc
paddle/phi/kernels/sparse/cpu/pool_grad_kernel.cc
+1
-1
paddle/phi/kernels/sparse/cpu/pool_kernel.cc
paddle/phi/kernels/sparse/cpu/pool_kernel.cc
+1
-1
paddle/phi/kernels/sparse/cpu/softmax_grad_kernel.cc
paddle/phi/kernels/sparse/cpu/softmax_grad_kernel.cc
+1
-1
paddle/phi/kernels/sparse/cpu/softmax_kernel.cc
paddle/phi/kernels/sparse/cpu/softmax_kernel.cc
+1
-1
paddle/phi/kernels/sparse/cpu/sparse_utils_kernel.cc
paddle/phi/kernels/sparse/cpu/sparse_utils_kernel.cc
+3
-3
未找到文件。
paddle/phi/kernels/sparse/cpu/coalesce_kernel.cc
浏览文件 @
ab583173
...
...
@@ -98,7 +98,7 @@ template <typename T, typename Context>
void
CoalesceKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
SparseCooTensor
*
out
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"CoalesceCPUKernel"
,
([
&
]
{
CoalesceCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
out
);
}));
...
...
paddle/phi/kernels/sparse/cpu/conv_grad_kernel.cc
浏览文件 @
ab583173
...
...
@@ -196,7 +196,7 @@ void Conv3dCooGradKernel(const Context& dev_ctx,
const
std
::
string
&
key
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"Conv3dCooGradCPUKernel"
,
([
&
]
{
Conv3dCooGradCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
...
...
paddle/phi/kernels/sparse/cpu/conv_kernel.cc
浏览文件 @
ab583173
...
...
@@ -186,7 +186,7 @@ void Conv3dCooKernel(const Context& dev_ctx,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
,
DenseTensor
*
counter
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"Conv3dCooCPUKernel"
,
([
&
]
{
Conv3dCooCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
...
...
paddle/phi/kernels/sparse/cpu/elementwise_grad_kernel.cc
浏览文件 @
ab583173
...
...
@@ -236,7 +236,7 @@ void ElementWiseDivideCsrGradKernel(const Context& dev_ctx,
const
SparseCsrTensor
&
dout
,
SparseCsrTensor
*
dx
,
SparseCsrTensor
*
dy
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_crows
().
dtype
(),
"ElementWiseDivideCsrGradCPUKernel"
,
([
&
]
{
ElementWiseDivideCsrGradCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
y
,
out
,
dout
,
dx
,
dy
);
...
...
@@ -250,7 +250,7 @@ void ElementWiseDivideCooGradKernel(const Context& dev_ctx,
const
SparseCooTensor
&
dout
,
SparseCooTensor
*
dx
,
SparseCooTensor
*
dy
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"ElementWiseDivideCooGradCPUKernel"
,
([
&
]
{
ElementWiseDivideCooGradCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
y
,
out
,
dout
,
dx
,
dy
);
...
...
@@ -262,36 +262,38 @@ void ElementWiseDivideCooGradKernel(const Context& dev_ctx,
\
DEFINE_ELEMENTWISE_GRAD_KERNEL_COO(name)
#define DEFINE_ELEMENTWISE_GRAD_KERNEL_CSR(name) \
template <typename T, typename Context> \
void ElementWise##name##CsrGradKernel(const Context& dev_ctx, \
const SparseCsrTensor& x, \
const SparseCsrTensor& y, \
const SparseCsrTensor& dout, \
SparseCsrTensor* dx, \
SparseCsrTensor* dy) { \
PD_VISIT_INTEGRAL_TYPES(x.non_zero_crows().dtype(), \
"ElementWise##name##CsrGradCPUKernel", \
([&] { \
ElementWise##name##CsrGradCPUKernel<T, data_t>( \
dev_ctx, x, y, dout, dx, dy); \
})); \
#define DEFINE_ELEMENTWISE_GRAD_KERNEL_CSR(name) \
template <typename T, typename Context> \
void ElementWise##name##CsrGradKernel(const Context& dev_ctx, \
const SparseCsrTensor& x, \
const SparseCsrTensor& y, \
const SparseCsrTensor& dout, \
SparseCsrTensor* dx, \
SparseCsrTensor* dy) { \
PD_VISIT_BASE_INTEGRAL_TYPES( \
x.non_zero_crows().dtype(), \
"ElementWise##name##CsrGradCPUKernel", \
([&] { \
ElementWise##name##CsrGradCPUKernel<T, data_t>( \
dev_ctx, x, y, dout, dx, dy); \
})); \
}
#define DEFINE_ELEMENTWISE_GRAD_KERNEL_COO(name) \
template <typename T, typename Context> \
void ElementWise##name##CooGradKernel(const Context& dev_ctx, \
const SparseCooTensor& x, \
const SparseCooTensor& y, \
const SparseCooTensor& dout, \
SparseCooTensor* dx, \
SparseCooTensor* dy) { \
PD_VISIT_INTEGRAL_TYPES(x.non_zero_indices().dtype(), \
"ElementWise##name##CooGradCPUKernel", \
([&] { \
ElementWise##name##CooGradCPUKernel<T, data_t>( \
dev_ctx, x, y, dout, dx, dy); \
})); \
#define DEFINE_ELEMENTWISE_GRAD_KERNEL_COO(name) \
template <typename T, typename Context> \
void ElementWise##name##CooGradKernel(const Context& dev_ctx, \
const SparseCooTensor& x, \
const SparseCooTensor& y, \
const SparseCooTensor& dout, \
SparseCooTensor* dx, \
SparseCooTensor* dy) { \
PD_VISIT_BASE_INTEGRAL_TYPES( \
x.non_zero_indices().dtype(), \
"ElementWise##name##CooGradCPUKernel", \
([&] { \
ElementWise##name##CooGradCPUKernel<T, data_t>( \
dev_ctx, x, y, dout, dx, dy); \
})); \
}
DEFINE_ELEMENTWISE_GRAD_KERNEL
(
Add
)
...
...
paddle/phi/kernels/sparse/cpu/elementwise_kernel.cc
浏览文件 @
ab583173
...
...
@@ -57,11 +57,12 @@ void Merge(const IntT el_len,
const
IntT
len_b_max
,
IntT
*
c_index
,
T
*
c_values
,
IntT
&
nnz
,
IntT
*
out_
nnz
,
const
Functor
&
functor_org
,
const
bool
is_divide
)
{
IntT
a
=
0
;
IntT
b
=
0
;
IntT
&
nnz
=
(
*
out_nnz
);
nnz
=
0
;
const
IntT
*
b_index
=
nullptr
;
std
::
vector
<
IntT
>
b_full_index
;
...
...
@@ -94,9 +95,7 @@ void Merge(const IntT el_len,
}
++
a
;
++
b
;
}
// coordinate x[a] < coordinate y[b]
else
if
(
a_index
[
a
]
<
b_index
[
b
])
{
}
else
if
(
a_index
[
a
]
<
b_index
[
b
])
{
// coordinate x[a] < coordinate y[b]
if
(
!
functor
(
a_values
+
a
*
el_len
,
zero
.
data
(),
c_values
+
nnz
*
el_len
,
...
...
@@ -105,9 +104,7 @@ void Merge(const IntT el_len,
++
nnz
;
}
++
a
;
}
// coordinate x[a] > coordinate y[b]
else
if
(
a_index
[
a
]
>
b_index
[
b
])
{
}
else
if
(
a_index
[
a
]
>
b_index
[
b
])
{
// coordinate x[a] > coordinate y[b]
if
(
!
functor
(
zero
.
data
(),
b_values
[
b_index
[
b
]],
c_values
+
nnz
*
el_len
,
...
...
@@ -215,7 +212,7 @@ void ElementWiseCooKernelImpl(const Context& dev_ctx,
max_len
,
out_indexs
.
data
(),
out_values_vec
.
data
(),
nnz
,
&
nnz
,
functor
,
is_divide
);
...
...
@@ -292,7 +289,7 @@ void ElementWiseCooKernelImpl(const Context& dev_ctx,
const SparseCsrTensor& x, \
const SparseCsrTensor& y, \
SparseCsrTensor* out) { \
PD_VISIT_
INTEGRAL_TYPES(
\
PD_VISIT_
BASE_INTEGRAL_TYPES(
\
x.non_zero_crows().dtype(), "ElementWise##name##CsrCPUKernel", ([&] { \
ElementWise##name##CsrCPUKernel<T, data_t>(dev_ctx, x, y, out); \
})); \
...
...
@@ -309,18 +306,18 @@ void ElementWiseCooKernelImpl(const Context& dev_ctx,
dev_ctx, x, y, out, functor); \
}
#define DEFINE_COO_ELEMENTWISE_KERNEL(name) \
template <typename T, typename Context> \
void ElementWise##name##CooKernel(const Context& dev_ctx, \
const SparseCooTensor& x, \
const SparseCooTensor& y, \
SparseCooTensor* out) { \
PD_VISIT_INTEGRAL_TYPES(x.non_zero_indices().dtype(), \
"ElementWise##name##CooCPUKernel", \
([&] { \
ElementWise##name##CooCPUKernel<T, data_t>( \
dev_ctx, x, y, out); \
})); \
#define DEFINE_COO_ELEMENTWISE_KERNEL(name)
\
template <typename T, typename Context>
\
void ElementWise##name##CooKernel(const Context& dev_ctx,
\
const SparseCooTensor& x,
\
const SparseCooTensor& y,
\
SparseCooTensor* out) {
\
PD_VISIT_
BASE_
INTEGRAL_TYPES(x.non_zero_indices().dtype(), \
"ElementWise##name##CooCPUKernel", \
([&] { \
ElementWise##name##CooCPUKernel<T, data_t>( \
dev_ctx, x, y, out); \
})); \
}
DEFINE_CSR_ELEMENTWISE_CPU_KERNEL
(
Add
)
...
...
paddle/phi/kernels/sparse/cpu/mask_kernel.cc
浏览文件 @
ab583173
...
...
@@ -79,7 +79,7 @@ void SparseMaskKernel(const Context& dev_ctx,
const
DenseTensor
&
x
,
const
SparseCooTensor
&
mask
,
SparseCooTensor
*
out
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
mask
.
non_zero_indices
().
dtype
(),
"SparseMaskCPUKernel"
,
([
&
]
{
SparseMaskCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
mask
,
out
);
}));
...
...
@@ -146,7 +146,7 @@ void SparseMaskHelperKernel(const Context& dev_ctx,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
mask_indices
,
DenseTensor
*
out
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"SparseMaskHelperCPUKernel"
,
([
&
]
{
SparseMaskHelperCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
mask_indices
,
out
);
}));
...
...
paddle/phi/kernels/sparse/cpu/pool_grad_kernel.cc
浏览文件 @
ab583173
...
...
@@ -83,7 +83,7 @@ void MaxPoolCooGradKernel(const Context& dev_ctx,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
kernel_sizes
,
SparseCooTensor
*
x_grad
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"MaxPoolCooGradCPUKernel"
,
([
&
]
{
MaxPoolCooGradCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
rulebook
,
counter
,
out
,
out_grad
,
kernel_sizes
,
x_grad
);
...
...
paddle/phi/kernels/sparse/cpu/pool_kernel.cc
浏览文件 @
ab583173
...
...
@@ -109,7 +109,7 @@ void MaxPoolCooKernel(const Context& dev_ctx,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
,
DenseTensor
*
counter
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"MaxPoolCooCPUKernel"
,
([
&
]
{
MaxPoolCooCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
...
...
paddle/phi/kernels/sparse/cpu/softmax_grad_kernel.cc
浏览文件 @
ab583173
...
...
@@ -62,7 +62,7 @@ void SoftmaxCsrGradKernel(const Context& dev_ctx,
T
*
dx_data
=
dx_values
->
data
<
T
>
();
// dx = (dout - sum(dout * out)) * out
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
out
.
non_zero_crows
().
dtype
(),
"SoftmaxCsrGradKernel"
,
([
&
]
{
const
data_t
*
out_crows_data
=
out_crows
.
data
<
data_t
>
();
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
...
...
paddle/phi/kernels/sparse/cpu/softmax_kernel.cc
浏览文件 @
ab583173
...
...
@@ -60,7 +60,7 @@ void SoftmaxCsrKernel(const Context& dev_ctx,
T
*
out_data
=
out_values
->
data
<
T
>
();
// out = exp(x-x_max) / sum( exp(x-x_max ))
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_crows
().
dtype
(),
"CsrSoftmaxKernel"
,
([
&
]
{
const
data_t
*
x_crows_data
=
x_crows
.
data
<
data_t
>
();
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
...
...
paddle/phi/kernels/sparse/cpu/sparse_utils_kernel.cc
浏览文件 @
ab583173
...
...
@@ -160,7 +160,7 @@ template <typename T, typename Context>
void
SparseCsrToCooKernel
(
const
Context
&
dev_ctx
,
const
SparseCsrTensor
&
x
,
SparseCooTensor
*
out
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_crows
().
dtype
(),
"SparseCsrToCooCPUKernel"
,
([
&
]
{
SparseCsrToCooCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
out
);
}));
...
...
@@ -250,7 +250,7 @@ template <typename T, typename Context>
void
SparseCooToCsrKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
SparseCsrTensor
*
out
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"SparseCooToCsrCPUKernel"
,
([
&
]
{
SparseCooToCsrCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
out
);
}));
...
...
@@ -304,7 +304,7 @@ template <typename T, typename Context>
void
SparseCooToDenseKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
DenseTensor
*
out
)
{
PD_VISIT_INTEGRAL_TYPES
(
PD_VISIT_
BASE_
INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"SparseCooToDenseCPUKernel"
,
([
&
]
{
SparseCooToDenseCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
out
);
}));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录