Skip to content

Refactor cpp codegen to support overridable class attributes.#155553

Closed
vpandya-quic wants to merge 1 commit intopytorch:mainfrom
vpandya-quic:vpandya/cpp_proxy_kernel_refactoring
Closed

Refactor cpp codegen to support overridable class attributes.#155553
vpandya-quic wants to merge 1 commit intopytorch:mainfrom
vpandya-quic:vpandya/cpp_proxy_kernel_refactoring

Conversation

@vpandya-quic
Copy link
Copy Markdown
Contributor

@vpandya-quic vpandya-quic commented Jun 10, 2025

  • Refactored CppKernelProxy and CppScheduling to use class-level attributes (kernel_cls, kernel_proxy_cls) for backend-specific kernel customization.
  • Avoids method duplication (e.g., codegen_functions, codegen_node) for backend-specific overrides thus reduces downstream maintenance when upgrading Torch.
  • Ensures type safety with annotations while keeping core logic centralized and extensible.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Jun 10, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/155553

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit e522b1c with merge base f810e98 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Jun 10, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@vpandya-quic
Copy link
Copy Markdown
Contributor Author

@leslie-fang-intel could you please review?

@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 10, 2025
@leslie-fang-intel leslie-fang-intel requested a review from CaoE June 11, 2025 01:15
Copy link
Copy Markdown
Collaborator

@leslie-fang-intel leslie-fang-intel left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Could you add a summary in the description explaining the motivation behind this change?

@vpandya-quic vpandya-quic force-pushed the vpandya/cpp_proxy_kernel_refactoring branch from 2158107 to 0d9bf40 Compare June 11, 2025 08:57
@vpandya-quic vpandya-quic changed the title Refactored CppKernelProxy to support overridable kernel class attributes for cleaner backend customization. Refactor cpp codegen to support overridable class attributes. Jun 11, 2025
@vpandya-quic
Copy link
Copy Markdown
Contributor Author

vpandya-quic commented Jun 11, 2025

Thanks for the PR! Could you add a summary in the description explaining the motivation behind this change?

Updated the PR with couple of more changes and description to explain motivation behind this change.
To elaborate more say I am extending cpp backend for arch where std lib is not supported in such case I may want to override CppOverrides , CppVecOverrides etc classes and wire all this I have to copy paste codegen_functions() , codegen_node() methods and just to replace CppKernel with MyCustomCppKernel and same for CppVecKernel.

This change will allow me to achieve my goal without copy pasting whole function just to change certain class.

@leslie-fang-intel leslie-fang-intel added topic: not user facing topic category ciflow/trunk Trigger trunk jobs on your pull request labels Jun 11, 2025
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Jun 11, 2025

To add the ciflow label ciflow/trunk please first approve the workflows that are awaiting approval (scroll to the bottom of this page).

This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows.

@pytorch-bot pytorch-bot Bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Jun 11, 2025
@vpandya-quic vpandya-quic force-pushed the vpandya/cpp_proxy_kernel_refactoring branch from 0d9bf40 to a1bb370 Compare June 12, 2025 09:35
@vpandya-quic
Copy link
Copy Markdown
Contributor Author

I have tried to fix linter issues. The other two CI failure seems unrelated to this change.

Comment thread torch/_inductor/codegen/cpp.py Outdated
Comment on lines 3801 to 3809
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add comments on these fields explaining why we need them and how they can be used for customization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added comments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jgong5 could you please review?

 - Refactored CppKernelProxy and CppScheduling to use class-level attributes (kernel_cls, kernel_proxy_cls) for backend-specific kernel customization.
 - Avoids method duplication (e.g., codegen_functions, codegen_node) for backend-specific overrides thus reduces downstream maintenance when upgrading Torch.
 - Ensures type safety with annotations while keeping core logic centralized and extensible.
@vpandya-quic vpandya-quic force-pushed the vpandya/cpp_proxy_kernel_refactoring branch from a1bb370 to e522b1c Compare June 16, 2025 10:05
@vpandya-quic vpandya-quic requested a review from jgong5 June 16, 2025 10:05
@vpandya-quic
Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 23, 2025
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants