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

[Phi] Move QR to Phi #44742

Merged
merged 9 commits into from
Aug 2, 2022
Merged

[Phi] Move QR to Phi #44742

merged 9 commits into from
Aug 2, 2022

Conversation

aoyulong
Copy link
Contributor

@aoyulong aoyulong commented Jul 29, 2022

PR types

Others

PR changes

Ops

Describe

This pr moves the QR kernels to Phi library.

@@ -29,6 +28,29 @@ namespace operators {

using paddle::framework::Tensor;

template <typename DeviceContext, typename T>
Copy link
Contributor

Choose a reason for hiding this comment

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

lstsq_op.cu这个文件应该可以删了

Copy link
Contributor Author

@aoyulong aoyulong Jul 31, 2022

Choose a reason for hiding this comment

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

Done.

param : [x]
kernel :
func : qr_grad
# optional: q_grad, r_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.

Done.

}

template <typename T, typename Context>
static DenseTensor TrilTriu(const Context& ctx,
Copy link
Contributor

Choose a reason for hiding this comment

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

这个TrilTriu可以放到 paddle/phi/kernels/tril_triu_kernel.h头文件中,方便其他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.

Done.

Comment on lines 212 to 218
DenseTensor* workspace = new DenseTensor();
workspace->Resize(make_ddim({lwork}));
float* workspace_ptr = dev_ctx.template Alloc<float>(workspace);

DenseTensor* info = new DenseTensor();
info->Resize(make_ddim({1}));
int* info_d = dev_ctx.template Alloc<int>(info);
Copy link
Contributor

Choose a reason for hiding this comment

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

workspace和info用指针容易内存泄露,建议使用栈上对象或者unique_ptr替换

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 266 to 270
DenseTensor* workspace = new DenseTensor();
workspace->Resize(make_ddim({lwork}));
double* workspace_ptr = dev_ctx.template Alloc<double>(workspace);

DenseTensor* info = new DenseTensor();
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.

Done.

Comment on lines 321 to 327
DenseTensor* workspace = new DenseTensor();
workspace->Resize(make_ddim({lwork}));
float* workspace_ptr = dev_ctx.template Alloc<float>(workspace);

DenseTensor* info = new DenseTensor();
info->Resize(make_ddim({1}));
int* info_d = dev_ctx.template Alloc<int>(info);
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.

Done.

Comment on lines 377 to 383
DenseTensor* workspace = new DenseTensor();
workspace->Resize(make_ddim({lwork}));
double* workspace_ptr = dev_ctx.template Alloc<double>(workspace);

DenseTensor* info = new DenseTensor();
info->Resize(make_ddim({1}));
int* info_d = dev_ctx.template Alloc<int>(info);
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.

Done.

Comment on lines 51 to 76
template <typename T, typename Context>
static DenseTensor TrilTriu(const Context& ctx,
const DenseTensor& x,
int diagonal,
bool lower) {
DenseTensor dense_out;
MetaTensor meta_out(&dense_out);
TrilTriuInferMeta(x, diagonal, lower, &meta_out);
TrilTriuKernel<T, Context>(ctx, x, diagonal, lower, &dense_out);
return dense_out;
}

template <typename T, typename Context>
static DenseTensor TriangularSolve(const Context& ctx,
const DenseTensor& x,
const DenseTensor& y,
bool upper,
bool transpose,
bool unitriangular) {
DenseTensor dense_out;
MetaTensor meta_out(&dense_out);
TriangularSolveInferMeta(x, y, upper, transpose, unitriangular, &meta_out);
TriangularSolveKernel<T, Context>(
ctx, x, y, upper, transpose, unitriangular, &dense_out);
return dense_out;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

可以放在对应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.

Done.

#include <vector>

#include "paddle/fluid/memory/memcpy.h"
#include "paddle/fluid/platform/enforce.h"
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.

Done.

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM for error message

@aoyulong aoyulong merged commit 2cf2e78 into PaddlePaddle:develop Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants