Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【complex op No.33】abs_coo/abs_csr(sparse) #62237

Merged
merged 26 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions paddle/phi/kernels/sparse/cpu/sparse_utils_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ PD_REGISTER_KERNEL(dense_to_coo,
int8_t,
int16_t,
int,
int64_t) {}
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(csr_to_coo,
CPU,
Expand All @@ -342,7 +344,9 @@ PD_REGISTER_KERNEL(csr_to_coo,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(coo_to_csr,
CPU,
Expand All @@ -356,7 +360,9 @@ PD_REGISTER_KERNEL(coo_to_csr,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(dense_to_csr,
CPU,
Expand All @@ -369,7 +375,9 @@ PD_REGISTER_KERNEL(dense_to_csr,
int8_t,
int16_t,
int,
int64_t) {}
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(coo_to_dense,
CPU,
Expand All @@ -383,7 +391,9 @@ PD_REGISTER_KERNEL(coo_to_dense,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(csr_to_dense,
CPU,
Expand All @@ -397,7 +407,9 @@ PD_REGISTER_KERNEL(csr_to_dense,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(values_coo,
CPU,
Expand All @@ -411,7 +423,9 @@ PD_REGISTER_KERNEL(values_coo,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

Expand Down Expand Up @@ -442,7 +456,9 @@ PD_REGISTER_KERNEL(values_csr,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}

Expand All @@ -456,4 +472,6 @@ PD_REGISTER_KERNEL(sparse_coo_tensor,
uint8_t,
int16_t,
int,
int64_t) {}
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
22 changes: 21 additions & 1 deletion paddle/phi/kernels/sparse/cpu/unary_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,32 @@ PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(sqrt, Sqrt)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(square, Square)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(log1p, Log1p)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(relu, Relu)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(abs, Abs)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(pow, Pow)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(expm1, Expm1)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(relu6, Relu6)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_KERNEL(abs_coo_grad,
CPU,
ALL_LAYOUT,
phi::sparse::AbsCooGradKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

PD_REGISTER_KERNEL(abs_csr_grad,
CPU,
ALL_LAYOUT,
phi::sparse::AbsCsrGradKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}
PD_REGISTER_KERNEL(cast_coo_grad,
CPU,
ALL_LAYOUT,
Expand Down
23 changes: 22 additions & 1 deletion paddle/phi/kernels/sparse/cpu/unary_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,34 @@ PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(sqrt, Sqrt)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(square, Square)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(log1p, Log1p)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(relu, Relu)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(abs, Abs)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(pow, Pow)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(scale, Scale)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(expm1, Expm1)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(relu6, Relu6)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_KERNEL(abs_coo,
CPU,
ALL_LAYOUT,
phi::sparse::AbsCooKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

PD_REGISTER_KERNEL(abs_csr,
CPU,
ALL_LAYOUT,
phi::sparse::AbsCsrKernel,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}

PD_REGISTER_KERNEL(divide_scalar_coo,
CPU,
ALL_LAYOUT,
Expand Down
16 changes: 12 additions & 4 deletions paddle/phi/kernels/sparse/empty_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ PD_REGISTER_KERNEL(empty_like_coo,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

Expand All @@ -78,7 +80,9 @@ PD_REGISTER_KERNEL(empty_like_csr,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}

Expand All @@ -95,7 +99,9 @@ PD_REGISTER_KERNEL(empty_like_coo,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

Expand All @@ -111,7 +117,9 @@ PD_REGISTER_KERNEL(empty_like_csr,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}
#endif
36 changes: 27 additions & 9 deletions paddle/phi/kernels/sparse/gpu/sparse_utils_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ PD_REGISTER_KERNEL(dense_to_coo,
int8_t,
int16_t,
int,
int64_t) {}
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(csr_to_coo,
GPU,
Expand All @@ -603,7 +605,9 @@ PD_REGISTER_KERNEL(csr_to_coo,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(coo_to_csr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些kernel 对应的grad kernel 也注册上复数吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些kernel 对应的grad kernel 也注册上复数吧

这一次提交里面,在对应的sparse_backward.yaml下面能找到的后向我改掉了,但是对应的to_dense和value的梯度,涉及到
mask_kernel下面的两个kernel
另外还有之前提到的,稀疏格式在backward的时候涉及到的meta丢失的问题,在修改to_dense的梯度的时候也出现了,这一次也改掉了

GPU,
Expand All @@ -617,7 +621,9 @@ PD_REGISTER_KERNEL(coo_to_csr,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(dense_to_csr,
GPU,
Expand All @@ -630,7 +636,9 @@ PD_REGISTER_KERNEL(dense_to_csr,
int8_t,
int16_t,
int,
int64_t) {}
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(coo_to_dense,
GPU,
Expand All @@ -644,7 +652,9 @@ PD_REGISTER_KERNEL(coo_to_dense,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(csr_to_dense,
GPU,
Expand All @@ -658,7 +668,9 @@ PD_REGISTER_KERNEL(csr_to_dense,
int16_t,
int,
int64_t,
bool) {}
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}

PD_REGISTER_KERNEL(values_coo,
GPU,
Expand All @@ -672,7 +684,9 @@ PD_REGISTER_KERNEL(values_coo,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

Expand All @@ -688,7 +702,9 @@ PD_REGISTER_KERNEL(values_csr,
int16_t,
int,
int64_t,
bool) {
bool,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}

Expand Down Expand Up @@ -717,4 +733,6 @@ PD_REGISTER_KERNEL(sparse_coo_tensor,
uint8_t,
int16_t,
int,
int64_t) {}
int64_t,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {}
25 changes: 24 additions & 1 deletion paddle/phi/kernels/sparse/gpu/unary_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,35 @@ PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(sqrt, Sqrt)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(square, Square)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(log1p, Log1p)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(relu, Relu)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(abs, Abs)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(pow, Pow)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(expm1, Expm1)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(relu6, Relu6)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_KERNEL(abs_coo_grad,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注册的形式是一样的,这里是不是也写一个带复数注册的宏会更好一点,也更方便后面稀疏方法的注册,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注册的形式是一样的,这里是不是也写一个带复数注册的宏会更好一点,也更方便后面稀疏方法的注册,

事实上我在后面的复数修改就重新写了新的宏,我晚上有时间就去把那边pr的代码移动过来

GPU,
ALL_LAYOUT,
phi::sparse::AbsCooGradKernel,
phi::dtype::float16,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

PD_REGISTER_KERNEL(abs_csr_grad,
GPU,
ALL_LAYOUT,
phi::sparse::AbsCsrGradKernel,
phi::dtype::float16,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}

PD_REGISTER_KERNEL(cast_coo_grad,
GPU,
ALL_LAYOUT,
Expand Down
25 changes: 24 additions & 1 deletion paddle/phi/kernels/sparse/gpu/unary_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,36 @@ PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(sqrt, Sqrt)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(square, Square)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(log1p, Log1p)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(relu, Relu)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(abs, Abs)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(pow, Pow)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(scale, Scale)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(expm1, Expm1)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(relu6, Relu6)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_KERNEL(abs_coo,
GPU,
ALL_LAYOUT,
phi::sparse::AbsCooKernel,
phi::dtype::float16,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

PD_REGISTER_KERNEL(abs_csr,
GPU,
ALL_LAYOUT,
phi::sparse::AbsCsrKernel,
phi::dtype::float16,
float,
double,
phi::dtype::complex<float>,
phi::dtype::complex<double>) {
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR);
}

PD_REGISTER_KERNEL(divide_scalar_coo,
GPU,
ALL_LAYOUT,
Expand Down
Loading