Thanks to visit codestin.com
Credit goes to github.com

Skip to content

codecache: Remove cpp_prefix.h duplication per build, then precompile it #144293

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 67 commits into
base: gh/benjaminglass1/51/base
Choose a base branch
from

Conversation

benjaminglass1
Copy link
Collaborator

@benjaminglass1 benjaminglass1 commented Jan 7, 2025

Stack from ghstack (oldest at bottom):

Prior to this PR, _inductor/codegen/cpp_prefix.h was copied into a new temporary directory on every inductor run utilizing the CPP backend (i.e. CPU-only), then included in the output source code. Instead, this PR puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Due to difficulties getting this to work in FBCode, the precompilation itself is only enabled in OSS PyTorch.

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

Differential Revision: D69420620

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Jan 7, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 2 Unrelated Failures

As of commit 16eb3db with merge base 48bfe9a (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

benjaminglass1 added a commit that referenced this pull request Jan 7, 2025
Prior to this PR, `_inductor/codegen/cpp_prefix.h` was copied into a new temporary directory on every inductor run utilizing the CPP backend, then included in the output source code. Instead, this puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Note for reviewers: I believe I've traced down all the implications of this change for FBCode here on the OSS side, but someone will need to run this through tests on the FB side to be sure.

ghstack-source-id: 78acea9
Pull Request resolved: #144293
@benjaminglass1 benjaminglass1 added the topic: not user facing topic category label Jan 7, 2025
[ghstack-poisoned]
benjaminglass1 added a commit that referenced this pull request Jan 7, 2025
Prior to this PR, `_inductor/codegen/cpp_prefix.h` was copied into a new temporary directory on every inductor run utilizing the CPP backend, then included in the output source code. Instead, this puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Note for reviewers: I believe I've traced down all the implications of this change for FBCode here on the OSS side, but someone will need to run this through tests on the FB side to be sure.

ghstack-source-id: 91fa52d
Pull Request resolved: #144293
[ghstack-poisoned]
benjaminglass1 added a commit that referenced this pull request Jan 7, 2025
Prior to this PR, `_inductor/codegen/cpp_prefix.h` was copied into a new temporary directory on every inductor run utilizing the CPP backend, then included in the output source code. Instead, this puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Note for reviewers: I believe I've traced down all the implications of this change for FBCode here on the OSS side, but someone will need to run this through tests on the FB side to be sure.

ghstack-source-id: 754a728
Pull Request resolved: #144293
@benjaminglass1
Copy link
Collaborator Author

Additional note to reviewers: lintrunner insisted on reformatting cpp_prefix.h once I'd moved it. I apologize about the diff there; the only actual change is switching from #pragma once to include guards to avoid a warning when precompiling headers in GCC.

@benjaminglass1 benjaminglass1 self-assigned this Jan 7, 2025
@benjaminglass1 benjaminglass1 marked this pull request as ready for review January 7, 2025 16:26
@benjaminglass1 benjaminglass1 requested a review from a team as a code owner January 7, 2025 16:26
[ghstack-poisoned]
@benjaminglass1
Copy link
Collaborator Author

Additional note to reviewers: lintrunner insisted on reformatting cpp_prefix.h once I'd moved it. I apologize about the diff there; the only actual change is switching from #pragma once to include guards to avoid a warning when precompiling headers in GCC.

Per conversation in #143909, I'll be reverting this to #pragma once.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
jurgen-paul pushed a commit to jurgen-paul/pytorch.git.file that referenced this pull request Mar 19, 2025
Prior to this PR, `_inductor/codegen/cpp_prefix.h` was copied into a new temporary directory on every inductor run utilizing the CPP backend, then included in the output source code. Instead, this puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Note for reviewers: I believe I've traced down all the implications of this change for FBCode here on the OSS side, but someone will need to run this through tests on the FB side to be sure.

ghstack-source-id: 3795def
Pull Request resolved: pytorch/pytorch#144293
jurgen-paul pushed a commit to jurgen-paul/pytorch.git.file that referenced this pull request Mar 19, 2025
Prior to this PR, `_inductor/codegen/cpp_prefix.h` was copied into a new temporary directory on every inductor run utilizing the CPP backend, then included in the output source code. Instead, this puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Note for reviewers: I believe I've traced down all the implications of this change for FBCode here on the OSS side, but someone will need to run this through tests on the FB side to be sure.

ghstack-source-id: 2e64a7b
Pull Request resolved: pytorch/pytorch#144293
NaderAlAwar pushed a commit to NaderAlAwar/PyTorch that referenced this pull request Mar 21, 2025
Prior to this PR, `_inductor/codegen/cpp_prefix.h` was copied into a new temporary directory on every inductor run utilizing the CPP backend, then included in the output source code. Instead, this puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Note for reviewers: I believe I've traced down all the implications of this change for FBCode here on the OSS side, but someone will need to run this through tests on the FB side to be sure.

ghstack-source-id: 9403381
Pull Request resolved: pytorch/pytorch#144293
[ghstack-poisoned]
@desertfire
Copy link
Contributor

@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

[ghstack-poisoned]
@desertfire
Copy link
Contributor

@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@desertfire
Copy link
Contributor

@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Divigroup-RAP pushed a commit to Divigroup-RAP/PYTORCH that referenced this pull request Apr 22, 2025
Prior to this PR, `_inductor/codegen/cpp_prefix.h` was copied into a new temporary directory on every inductor run utilizing the CPP backend, then included in the output source code. Instead, this puts it in an appropriate place in the torch includes, and includes it from there. This allows us to precompile it in cpp_wrapper and AOT inductor mode, saving significant compilation time.

Note for reviewers: I believe I've traced down all the implications of this change for FBCode here on the OSS side, but someone will need to run this through tests on the FB side to be sure.

ghstack-source-id: 4e417ce
Pull Request resolved: pytorch/pytorch#144293
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@desertfire
Copy link
Contributor

@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants