Skip to content

support PGO on custom project #110605

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

Merged
merged 1 commit into from
May 18, 2023
Merged

support PGO on custom project #110605

merged 1 commit into from
May 18, 2023

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Apr 20, 2023

make PGO easier for custom toolchain distribution.

r? @Kobzol

@rustbot
Copy link
Collaborator

rustbot commented Apr 20, 2023

Failed to set assignee to Kobzol: invalid assignee

Note: Only org members, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Apr 20, 2023
@csmoe csmoe force-pushed the open-cgo branch 2 times, most recently from b40b1ba to 6eade7b Compare April 20, 2023 14:16
@Kobzol
Copy link
Contributor

Kobzol commented Apr 20, 2023

Hi, the use-case seems reasonable. Although care should be taken that the custom command will generate the profiles into the correct files - you will thus probably want to distinguish between gathering profiles for LLVM/Rustc/BOLT even for custom runners, and pass the correct env. variables to them.

Therefore, I would prefer a more "OOP-like" implementation, to reduce complexity and conditions in the logic of the individual stages, and also to move the various benchmark logic to a single place.

Something like

class BenchmarkRunner:
    def run_rustc(self, pipeline: Pipeline):
    def run_llvm(self, pipeline: Pipeline):
    def run_bolt(self, pipeline: Pipeline):

    # (or maybe just a single method that would receive an enum - Rustc/LLVM/BOLT)

class DefaultBenchmarkRunner(BenchmarkRunner):
    def run_rustc(self, pipeline: Pipeline):
         self.run_compiler_benchmarks(
            pipeline,
            profiles=["Check", "Debug", "Opt"],
            scenarios=["All"],
            crates=RUSTC_PGO_CRATES,
            env=dict(
                LLVM_PROFILE_FILE=str(pipeline.rustc_profile_template_path())
            )
        )
   ...


class CustomBenchmarkRunner(BenchmarkRunner):
    ...

and then some function that creates the corresponding BenchmarkRunner from the environment at the beginning of the script. The selected runner would be then passed to the individual stages (it could also be stored within Pipeline directly to make it easier to access, it's not super nice because of the cyclic dependency, but it should be fine here).

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Good, this is how I imagined it :) Is this enough for you? Or do you also want to implement support for custom runners in this PR?

@csmoe
Copy link
Member Author

csmoe commented May 9, 2023

Really thanks for your kind review.
I haven't written much python, I'm imaging a common workflow as:

# content of a custom build.py

from stage-build import BenchmarkRunner, run
class CustomRunner(BenchmarkRunner):
    ...
runner = CustomRunner()
run(runner)

So I move the logic in __main__ into a run function for external invocation, is that ok?

@csmoe csmoe marked this pull request as ready for review May 9, 2023 11:39
@Kobzol
Copy link
Contributor

Kobzol commented May 12, 2023

Alright, that sounds reasonable :) Let's see if everything still works.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 12, 2023
@bors
Copy link
Collaborator

bors commented May 12, 2023

⌛ Trying commit 27beb46 with merge 47ee1f814e2773f0403b768ccb711b607af2b80d...

@bors
Copy link
Collaborator

bors commented May 12, 2023

☀️ Try build successful - checks-actions
Build commit: 47ee1f814e2773f0403b768ccb711b607af2b80d (47ee1f814e2773f0403b768ccb711b607af2b80d)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (47ee1f814e2773f0403b768ccb711b607af2b80d): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.8% [3.8%, 3.8%] 1
Regressions ❌
(secondary)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.8% [3.8%, 3.8%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 660.274s -> 659.215s (-0.16%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 12, 2023
@Kobzol
Copy link
Contributor

Kobzol commented May 12, 2023

Perf looks good, LGTM.

I don't have merge right, so reassigning.

r? @Mark-Simulacrum

@Mark-Simulacrum
Copy link
Member

@bors r=Kobzol

This seems fine to me, though of course no stability guarantees are offered on these scripts.

@bors
Copy link
Collaborator

bors commented May 18, 2023

📌 Commit 27beb46 has been approved by Kobzol

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2023
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 18, 2023
@bors
Copy link
Collaborator

bors commented May 18, 2023

⌛ Testing commit 27beb46 with merge ba6f5e3...

@bors
Copy link
Collaborator

bors commented May 18, 2023

☀️ Test successful - checks-actions
Approved by: Kobzol
Pushing ba6f5e3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 18, 2023
@bors bors merged commit ba6f5e3 into rust-lang:master May 18, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 18, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ba6f5e3): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.3% [2.0%, 2.6%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.3% [-1.7%, -1.0%] 4
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.9% [1.3%, 3.4%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 641.167s -> 643.087s (0.30%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants