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

[NFC] Use reference instead of copies in few places #5118

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

anmyachev
Copy link
Contributor

No description provided.

Signed-off-by: Anatoly Myachev <[email protected]>
anmyachev added a commit to intel/intel-xpu-backend-for-triton that referenced this pull request Nov 12, 2024
For Triton as well: triton-lang/triton#5118

Signed-off-by: Anatoly Myachev <[email protected]>
Comment on lines 1085 to 1086
curr = AxisInfo(std::move(newContiguity), std::move(newDivisibility),
std::move(newConstancy), curr.getConstantValue());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure those move semantic do much as the constructor currently takes arg by copy. Is there anything special you are trying to fix? I'm not sure this helps readability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

constructor currently takes arg by copy

The AxisInfo constructor takes arguments by their value, yes, in this case SmallVector' copy constructor or the move constructor can be called (SmallVector has a move constructor). Since std::move casts the object to something like: SmallVector&&, the move constructor will be called, that is, we can get rid of one copy (for each SmallVector value).

I'm not sure this helps readability

It's a bit harder to read, I agree, but it saves three copies.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the better fix here simply making the AxisInfo constructor take everything by const-ref? I think it's just an oversight, as the constructor doesn't use the "copy-move" idiom.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the better fix here simply making the AxisInfo constructor take everything by const-ref? I think it's just an oversight, as the constructor doesn't use the "copy-move" idiom.

I agree

Copy link
Contributor

Choose a reason for hiding this comment

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

Or ArrayRef<int64_t>

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 +87 to +88
const auto &inOrd = gpu::getOrder(srcLayout);
const auto &outOrd = gpu::getOrder(dstLayout);
Copy link
Contributor

@lezcano lezcano Nov 14, 2024

Choose a reason for hiding this comment

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

Can you take this result by reference? Is it one of those cases where the lifetime is extended?

At any rate, a better fix would be to make getOrder have NRVO semantics, but it's pretty much a microoptimisation at this point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it one of those cases where the lifetime is extended?

Yes, I would also like to point out that this was suggested by https://scan.coverity.com/ tool, which we use in XPU backend mostly for our files, but since some of it is duplicated, I thought it would be nice to push even such minor changes upstream to improve the code a bit.

At any rate, a better fix would be to make getOrder have NRVO semantics, but it's pretty much a microoptimisation at this point

Unfortunately I'm not sure what needs to be done for this. Can we leave it as is until this code is considered part of the hottest path?

@Jokeren
Copy link
Contributor

Jokeren commented Nov 14, 2024

Clean up PRs could have two distinct goals here: clarity and compilation speed. For clarity, if the current implementation is already understandable and memory-safe without significant issues, we can keep it as is. For compilation speed optimization, however, it’s unclear if altering these small areas will provide much benefit. If speeding up compilation is the priority, it would be more effective to identify which passes are time-consuming and focus optimization efforts there. Something like pass timing would be helpful https://mlir.llvm.org/docs/PassManagement/#pass-timing

@anmyachev
Copy link
Contributor Author

Thank you very much to everyone for the comments! I will address them a bit later.

@ThomasRaoux ThomasRaoux changed the title Fix coverity issues [NFC] Use reference instead of copies in few places Nov 15, 2024
@anmyachev
Copy link
Contributor Author

@ThomasRaoux conflicts fixed. Is there anything else I should do in this pull request?

Clean up PRs could have two distinct goals here: clarity and compilation speed. For clarity, if the current implementation is already understandable and memory-safe without significant issues, we can keep it as is. For compilation speed optimization, however, it’s unclear if altering these small areas will provide much benefit. If speeding up compilation is the priority, it would be more effective to identify which passes are time-consuming and focus optimization efforts there. Something like pass timing would be helpful https://mlir.llvm.org/docs/PassManagement/#pass-timing

@Jokeren my goal is much simpler - to port small changes that the static analyzer finds. However, thanks for the advice, now I know where to look when I need to specifically optimize passes!

@peterbell10 peterbell10 enabled auto-merge (squash) November 18, 2024 19:18
@peterbell10 peterbell10 merged commit 1fc3269 into triton-lang:main Nov 18, 2024
7 checks passed
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.

5 participants