Skip to content

[SYCL][NATIVECPU][PERF] Avoid generating uncalled kernel subhandlers #17353

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

Open
wants to merge 19 commits into
base: sycl
Choose a base branch
from

Conversation

uwedolinsky
Copy link
Contributor

This PR prevents the generation of NativeCPU kernel subhandlers that cannot be called.
Also reduces number of kernel lookups during compilation.

@uwedolinsky uwedolinsky requested a review from a team as a code owner March 7, 2025 14:27
@@ -404,7 +404,8 @@ PreservedAnalyses PrepareSYCLNativeCPUPass::run(Module &M,
NewF->takeName(OldF);
OldF->replaceAllUsesWith(NewF);
OldF->eraseFromParent();
NewKernels.push_back(NewF);
if (NewF->getName() != "")
NewKernels.push_back(NewF);
Copy link
Contributor

@hvdijk hvdijk Mar 7, 2025

Choose a reason for hiding this comment

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

Since NewF takes its name from OldF, this would only apply to functions where originally OldF.getName() == "", right? If so, could we skip the whole cloneFunctionAndAddParam as well and just do if (OldF.getName() == "") continue; at the start? Or maybe even keep it out of OldKernels entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cloning may not be needed in this case right now, but we will need it again when we don't need the thread_local, which is another optimization PR I'm working on. So could remove it now for this case but would need to put it back in later again.

Copy link
Contributor

Choose a reason for hiding this comment

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

When we don't need the thread_local, can we not just continue using OldF and thereby still avoid the clone? But maybe I am misunderstanding what you mean.

Copy link
Contributor

@coldav coldav Mar 7, 2025

Choose a reason for hiding this comment

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

Are we sure that NewF can not have a name anyway? In what situation does that happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we don't need the thread_local, can we not just continue using OldF and thereby still avoid the clone? But maybe I am misunderstanding what you mean.

This PR just intends to avoid generating uncalled subhandlers in the smallest self-contained way. I guess we could add more optimizations related to kernel cloning, but we would probably have to change scope and description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we sure that NewF can not have a name anyway? In what situation does that happen?

It does have a name when it wasn't replaced - see the old comment in the code.

@uwedolinsky uwedolinsky changed the title [SYCL][NATIVECPU] Avoid generating uncalled kernel subhandlers [SYCL][NATIVECPU][PERF] Avoid generating uncalled kernel subhandlers Apr 2, 2025
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.

3 participants