-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Phi] Move QR to Phi #44742
Conversation
paddle/fluid/operators/lstsq_op.cu
Outdated
@@ -29,6 +28,29 @@ namespace operators { | |||
|
|||
using paddle::framework::Tensor; | |||
|
|||
template <typename DeviceContext, typename T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lstsq_op.cu这个文件应该可以删了
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释可以去掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/phi/kernels/gpu/qr_kernel.cu
Outdated
} | ||
|
||
template <typename T, typename Context> | ||
static DenseTensor TrilTriu(const Context& ctx, |
There was a problem hiding this comment.
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复用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/phi/kernels/gpu/qr_kernel.cu
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workspace和info用指针容易内存泄露,建议使用栈上对象或者unique_ptr替换
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/phi/kernels/gpu/qr_kernel.cu
Outdated
DenseTensor* workspace = new DenseTensor(); | ||
workspace->Resize(make_ddim({lwork})); | ||
double* workspace_ptr = dev_ctx.template Alloc<double>(workspace); | ||
|
||
DenseTensor* info = new DenseTensor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/phi/kernels/gpu/qr_kernel.cu
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/phi/kernels/gpu/qr_kernel.cu
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
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, | ||
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以放在对应Kernel的头文件中方便复用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/phi/kernels/gpu/qr_kernel.cu
Outdated
#include <vector> | ||
|
||
#include "paddle/fluid/memory/memcpy.h" | ||
#include "paddle/fluid/platform/enforce.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是不是可以删掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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
PR types
Others
PR changes
Ops
Describe
This pr moves the QR kernels to Phi library.