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

Move compare OPs to phi #39970

Merged
merged 5 commits into from
Mar 3, 2022
Merged

Conversation

From00
Copy link
Contributor

@From00 From00 commented Feb 27, 2022

PR types

Function optimization

PR changes

OPs

Describe

Move a series of compare OPs to phi, including less_than, less_equal, greater_than, greater_equal, equal, not_equal, and equal_all.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

ctx.template Alloc<bool>(out);
std::vector<const DenseTensor*> ins{&x, &y};
std::vector<DenseTensor*> outs{out};
paddle::operators::LaunchElementwiseCudaKernel<ElementwiseType::kBinary,
Copy link
Contributor

Choose a reason for hiding this comment

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

代码已经迁到phi下,使用funcs下的BroadcastKernel替代


std::vector<const DenseTensor*> ins{&x, &y};
std::vector<DenseTensor*> outs{&tmp};
paddle::operators::LaunchSameDimsElementwiseCudaKernel<bool>(
Copy link
Contributor

Choose a reason for hiding this comment

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

代码已经迁到phi下,使用ElementwiseKernel替代

Comment on lines 20 to 21
#include "paddle/fluid/operators/elementwise/elementwise_op_broadcast.cu.h"
#include "paddle/fluid/operators/elementwise/elementwise_op_impl.cu.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

可以替换成phi头文件

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 "paddle/phi/kernels/compare_kernel.h"

#include "paddle/phi/core/dense_tensor.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

dense_tensor.h应该不需要include了

Comment on lines +19 to +46
KernelSignature LessThanArgumentMapping(const ArgumentMappingContext& ctx) {
return KernelSignature("less_than", {"X", "Y"}, {"axis"}, {"Out"});
}

KernelSignature LessEqualArgumentMapping(const ArgumentMappingContext& ctx) {
return KernelSignature("less_equal", {"X", "Y"}, {"axis"}, {"Out"});
}

KernelSignature GreaterThanArgumentMapping(const ArgumentMappingContext& ctx) {
return KernelSignature("greater_than", {"X", "Y"}, {"axis"}, {"Out"});
}

KernelSignature GreaterEqualArgumentMapping(const ArgumentMappingContext& ctx) {
return KernelSignature("greater_equal", {"X", "Y"}, {"axis"}, {"Out"});
}

KernelSignature EqualArgumentMapping(const ArgumentMappingContext& ctx) {
return KernelSignature("equal", {"X", "Y"}, {"axis"}, {"Out"});
}

KernelSignature NotEqualArgumentMapping(const ArgumentMappingContext& ctx) {
return KernelSignature("not_equal", {"X", "Y"}, {"axis"}, {"Out"});
}

KernelSignature EqualAllArgumentMapping(const ArgumentMappingContext& ctx) {
return KernelSignature("equal_all", {"X", "Y"}, {}, {"Out"});
}

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.

此OP实现较特殊,去掉映射函数的话InferShape会报错(原因不明):
image

zyfncg
zyfncg previously approved these changes Mar 1, 2022
YuanRisheng
YuanRisheng previously approved these changes Mar 1, 2022
@From00 From00 dismissed stale reviews from YuanRisheng and zyfncg via 01e3b8e March 2, 2022 03:38
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Mar 2, 2022
@PaddlePaddle PaddlePaddle unlocked this conversation Mar 2, 2022
@From00 From00 closed this Mar 2, 2022
@From00 From00 reopened this Mar 2, 2022
zyfncg
zyfncg previously approved these changes Mar 2, 2022
YuanRisheng
YuanRisheng previously approved these changes Mar 2, 2022
@From00 From00 dismissed stale reviews from YuanRisheng and zyfncg via a345a80 March 2, 2022 12:25
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@From00 From00 merged commit 0969a4e into PaddlePaddle:develop Mar 3, 2022
@From00 From00 deleted the move-compare-op-to-phi branch March 11, 2022 07:16
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