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

GH-112354: Initial implementation of warm up on exits and trace-stitching #114142

Merged
merged 50 commits into from Feb 20, 2024

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Jan 16, 2024

Only works for boolean guards, not type guards, for now. And _EXIT_TRACE now.

Needs to be carefully documented, there's some subtlety here.

Exits are implemented as an array of records attached to the executors, and a fixed set of cold exit executors.
We can shrink the _PyExitData further, by moving the counters into a global table, but that's for another PR.

See faster-cpython/ideas#644 for a rough sketch of the design.

@bedevere-app bedevere-app bot mentioned this pull request Jan 16, 2024
@brandtbucher brandtbucher self-requested a review January 16, 2024 21:26
@markshannon
Copy link
Member Author

@markshannon markshannon marked this pull request as ready for review January 17, 2024 15:55
@brandtbucher
Copy link
Member

Sorry, didn't get to a proper review of this today. I've been trying (and failing) to merge the JIT branch into this one without crashing.

Maybe we can chat "in person" later?

@brandtbucher
Copy link
Member

Okay, I was able to get it working-ish... but it's not pretty. We can go over it when we meet.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Here's a first, partial pass. I've tried to focus on things that confused me. I haven't fully reviewed optimizer.c yet, nor the _COLD_EXIT uop definition, so I'll focus on those when I find some time.

Maybe it would be useful to add TODO comments indicating things you're planning to tackle in the near future (subsequent PRs)? Like the counters.

Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/tier2_engine.md Show resolved Hide resolved
Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/bytecodes.c Show resolved Hide resolved
Python/ceval.c Show resolved Hide resolved
Python/bytecodes.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Include/cpython/optimizer.h Show resolved Hide resolved
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I still have a bunch of minor nits from the last review, and I can't say I follow all of the JIT-related code, but this looks about ready to merge after adding some comments here and there. (The bit fiddling of the thresholds still mystifies me and I'd love an explanation somewhere.)

Lib/test/test_generated_cases.py Show resolved Hide resolved
Python/ceval.c Outdated Show resolved Hide resolved
Tools/cases_generator/analyzer.py Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Include/internal/pycore_interp.h Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
@@ -226,8 +229,9 @@ static PyMethodDef executor_methods[] = {

static void
uop_dealloc(_PyExecutorObject *self) {
Copy link
Member

Choose a reason for hiding this comment

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

Or better, executor_blah, matching e.g. executor_clear.

@brandtbucher
Copy link
Member

Sorry, forgot about this. I'll review first thing tomorrow.

@markshannon
Copy link
Member Author

Or better, executor_blah, matching e.g. executor_clear.

I'd prefer to save that for another PR. Maybe the one that removes the CounterExecutor.

@markshannon
Copy link
Member Author

FTR, the thresholds are likely to get completely changed soon.

We probably want to change the fixed thresholds to some sort of adaptive thresholds, and consider the T1 and T2 thresholds together so that specialization works correctly.

Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/tier2_redundancy_eliminator_cases.c.h Show resolved Hide resolved
@gvanrossum
Copy link
Member

If you look at GitHub there’s still a missing cast somewhere.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Didn't look too closely at the cases generator or optimizer (I'm assuming there are other eyes on that).

  • I appreciate the writeup!
  • I like that the interpreter/JIT interfaces are a lot more unified on this iteration. I know you're not crazy about conditional macro stuff but I think it makes things a lot easier to follow in this case. Thanks.
  • Suggestions to remove bit of tricky code duplication in template.c.
  • A couple of questions about setting tstate->previous_executor.
  • A few other random questions/suggestions I had while reading through.
  • One thing I find sort of tricky to keep track of is the nuances of the first couple of instructions in the trace (when/where _START_EXECUTOR is added, when/where pointers to optimizers/executors are smuggled in as operands, etc). This might be worth cleaning up now or in the future, or at least writing up. Not sure.

Tools/jit/template.c Outdated Show resolved Hide resolved
Tools/jit/template.c Show resolved Hide resolved
Tools/jit/template.c Outdated Show resolved Hide resolved
Tools/jit/template.c Outdated Show resolved Hide resolved
Tools/jit/template.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Include/cpython/optimizer.h Outdated Show resolved Hide resolved
Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/bytecodes.c Show resolved Hide resolved
Tools/jit/template.c Show resolved Hide resolved
@bedevere-app
Copy link

bedevere-app bot commented Feb 16, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Python/optimizer.c Outdated Show resolved Hide resolved
Modules/_testinternalcapi.c Outdated Show resolved Hide resolved
Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/tier2_engine.md Outdated Show resolved Hide resolved
Python/tier2_engine.md Show resolved Hide resolved
@markshannon markshannon merged commit 7b21403 into python:main Feb 20, 2024
57 checks passed
@encukou
Copy link
Member

encukou commented Feb 20, 2024

The refleaks buildbot failed on test.test_capi.test_opt.TestUops.test_confidence_score. Likely causes: GH-114142, GH-115558, or GH-115688
I'll investigate later if it's not fixed; you probably have more context.

@markshannon
Copy link
Member Author

I don't think there is a new bug here, but this PR exposes it. #115727

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

Successfully merging this pull request may close these issues.

None yet

6 participants