GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-118335: Configure Tier 2 interpreter at build time by gvanrossum · Pull Request #118339 · python/cpython

Conversation

@gvanrossum

@gvanrossum gvanrossum commented Apr 27, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The code for Tier 2 is now only compiled when configured with --enable-experimental-jit[=yes|interpreter]. We drop support for PYTHON_UOPS and -Xuops, but you can disable the interpreter or JIT at runtime by setting PYTHON_JIT=0. You can also build it without enabling it by default using --enable-experimental-jit=yes-off; enable with PYTHON_JIT=1.

@mdboom See note in issue about benchmarking setup.

@markshannon An alternative approach would be to keep the APIs but make them always fail. In particular, there are some PyUnstable APIs that will only exist when _Py_TIER2 is defined. Thoughts?

EDIT: In particular, we could arguably keep offering PyUnstable_{Get,Set}Optimizer, so 3rd parties could create and activate their own optimizers, like in your original design (which I cannot find back -- you had something where 3rd parties could register optimizations and parameters indicating the cost and benefit, or something). However, the rest of the optimizer machinery is now dependent on executors (starting with _PyOptimizer_Optimize, ). If we wanted to keep supporting both optimizers and executors, we'd have to do something different in ENTER_EXECUTOR too. (Possibly in both cases the key issue is that GOTO_TIER_TWO(executor) assumes JIT or Tier 2 IR.)

EDIT 2: Another consideration is whether we'd still want the runtime -Xuops flag and the PYTHON_UOPS env var, when enabled at build time. Or perhaps at least PYTHON_UOPS=0 to disable at runtime (which is a simple change in pylifecycle.c). I'd use that when debugging tests with PYTHON_LLTRACE=N, since the debug output from the test infrastructure might overwhelm that for the test proper.

Yet another option would be to leave everything as it was, except change the default with the build-time flag.

  • Issue: Configure Tier 2 interpreter at build time #118335

📚 Documentation preview 📚: https://cpython-previews--118339.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gvanrossum added 10 commits April 26, 2024 14:11
@gvanrossum
Step 1: replace 'python -Xuops' with 'configure --enable-experimental…
1eb8fea
…-tier2'
@gvanrossum
Make JIT imply TIER2, for convenience
0863c17
@gvanrossum
Step 2: Remove all code from optimizer*.c unless TIER2; fix deps exce…
9e43331
…pt _testinternalcapi
@gvanrossum
Remove TIER2 stuff from _testinternalcapi
064de58
@gvanrossum
Fix test_dis.py: _opcode.get_executor() may raise RuntimeError
13b8ef0
@gvanrossum
Fix test_regrtest (by tweaking without_getoptimizer)
edbaeef
@gvanrossum
Fix test_optimizer.py
9311198
@gvanrossum
Fix test_opcache
300ae6d
@gvanrossum
Fix test_monitoring
db911e4
@gvanrossum
Fix test_capi.test_opt (by disabling unless get_optimizer exists)
8cb71dd
@gvanrossum
gvanrossum requested a review from markshannon April 27, 2024 00:30
@bedevere-app bedevere-app Bot mentioned this pull request Apr 27, 2024
Configure Tier 2 interpreter at build time #118335
Closed
@gvanrossum

gvanrossum commented Apr 27, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

WASI build is failing, just like it did before when I had an option to disable Tier 2.

I'm away from my Windows laptop so I can't debug the Windows JIT failures yet -- this seems to be in test_opcache.TestRacesDoNotCrash.test_store_attr_with_hint.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum added 2 commits April 26, 2024 20:49
@gvanrossum
Fix _opcode.c
7e79509
@gvanrossum
Fix warning in sysmodule.c
638b7ec
@gvanrossum

gvanrossum commented Apr 27, 2024

Copy link
Copy Markdown
Member Author

There's also this failure (a hang in test_multiprocessing, apparently): https://github.com/python/cpython/actions/runs/8857124270/job/24324215355?pr=118339

PS. I've updated the discussion in the initial comment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Apr 27, 2024

Copy link
Copy Markdown
Member Author

Benchmark says 1% faster (in Tier 1 mode).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum gvanrossum mentioned this pull request Apr 29, 2024
Move Tier 2 interpreter out of _PyEval_EvalFrameDefault #116970
Open
gvanrossum added 3 commits April 29, 2024 15:55
@gvanrossum
When compiling _testinternalcapi.c, define _Py_JIT
8fc905f
@gvanrossum
Try making WASI Debug recursion limit 400
877a005
@gvanrossum
Merge main into tier2-flag
e4464d4
@gvanrossum

gvanrossum commented Apr 29, 2024

Copy link
Copy Markdown
Member Author

Looks like Windows JIT builds now pass. WASI build still fails. I wonder if there's something in the WASI build similar to the Windows problem (which had to do with _Py_TIER2 never getting set in a place where it was tested).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdboom mdboom mentioned this pull request Apr 30, 2024
Use new configure flags for Tier2 and JIT python/bench_runner#183
Merged
gvanrossum added 4 commits April 30, 2024 07:39
@gvanrossum
Revert "Try making WASI Debug recursion limit 400"
ffd7722
It doesn't work. I'm giving up.

This reverts commit 877a005.
@gvanrossum
Update jit/README.md to require LLVM 18 everywhere
6e2777b
@gvanrossum
Rip out --enable-experimental-tier2, in favor of --enable-experimenta…
f228a06
…l-jit=XXX

There's more to do.
@gvanrossum
Rip out _Py_TIER2, replace with _Py_JIT
70e18a5
The value is a bitflag:
- 0: off
- 1: JIT, on by default
- 3: JIT, off by default (not yet implemented, requires fiddling pystate.c)
- 4: tier 2 interpreter, on by default
@gvanrossum
gvanrossum force-pushed the tier2-flag branch from e8cf5bd to 70e18a5 Compare April 30, 2024 14:41
mdboom
mdboom requested changes Apr 30, 2024
View reviewed changes

@mdboom mdboom left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This may already be on your radar, but a reminder to also update the Windows build.bat script to support this 4-way option.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 30, 2024
@gvanrossum
gvanrossum requested review from mdboom and removed request for ericsnowcurrently, erlend-aasland and markshannon April 30, 2024 20:53
@gvanrossum

gvanrossum commented Apr 30, 2024

Copy link
Copy Markdown
Member Author

WASI bliss at last.

@brandtbucher Do you have time to review this?

@mdboom I peeked at your new-flags branch in the benchmarking repo. We lose the ability to benchmark Tier 2 on Windows (for now) -- is that reflected in the diff there? (As an only occasional user of the UI there I rely on the script to let me know if I've selected an impossible combination.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher

brandtbucher commented Apr 30, 2024

Copy link
Copy Markdown
Member

@brandtbucher Do you have time to review this?

Yep, looking at it now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brandtbucher
brandtbucher reviewed Apr 30, 2024
View reviewed changes

@brandtbucher brandtbucher left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for taking the time to tackle this. Performing the surgery after-the-fact definitely seems like a tricky task.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/whatsnew/3.13.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.13.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.13.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/support/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Core and Builtins/2024-04-26-14-06-18.gh-issue-118335.SRFsxO.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Tools/jit/README.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pylifecycle.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/instrumentation.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_opcode.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum added 6 commits April 30, 2024 15:01
@gvanrossum
Shorten to --enable-exerimental-jit=yes-off
8276a9a
@gvanrossum
Tweak code in test/support/__init__.py without_optimizer()
f950e25
@gvanrossum
Fix news blurb
6be70c0
@gvanrossum
Fix typo in _opcode.c
fdbe440
@gvanrossum
Shut up annoying warning
3c919bb
@gvanrossum
Use Py_FatalError for ENTER_EXECUTOR in non-TIER2 build
d5a3ff0
@gvanrossum
gvanrossum requested a review from markshannon as a code owner April 30, 2024 22:56
@gvanrossum

gvanrossum commented Apr 30, 2024

Copy link
Copy Markdown
Member Author

@brandtbucher I believe I've done everything from your review that I gave a thumbs up, and for everything else I stated a reason.

@mdboom -- At Brandt's suggestion I've shortened the "default off" flag to --enable-experimental-jit=yes-off. I think this has no repercussions for your new-flags branch of the benchmarking repo, but you may want to double-check.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brandtbucher
brandtbucher approved these changes Apr 30, 2024
View reviewed changes

@brandtbucher brandtbucher left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@brandtbucher I believe I've done everything from your review that I gave a thumbs up, and for everything else I stated a reason.

Yep!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Apr 30, 2024
gvanrossum added 2 commits April 30, 2024 17:02
@gvanrossum
Add --experimental-jit-{off|interpreter} to PCbuild/build.bat
07c485e
@gvanrossum
Revert "Shut up annoying warning"
a2d4f30
Apparently makes the CI fuzzer unhappy.

This reverts commit 3c919bb.
@gvanrossum

gvanrossum commented May 1, 2024

Copy link
Copy Markdown
Member Author

Okay, I've got the Windows flag stuff sorted out. It's a little different from Unix, because you apparently can't say "--experimental-jit=yes-off" while also supporting "--experimental-jit"; it treats the "=" as a space. Rather than becoming a .BAT file CLI parsing expert I chose the following option names:

  • --experimental-jit
  • --experimental-jit-off (build JIT, but default off)
  • --experimental-interpreter
  • --experimental-interpreter-off (undocumented, for Mark :-)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum
gvanrossum merged commit 7d83f7b into python:main May 1, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label May 1, 2024
@gvanrossum
gvanrossum deleted the tier2-flag branch May 1, 2024 01:26
gvanrossum added a commit to gvanrossum/cpython that referenced this pull request May 1, 2024
@gvanrossum
Also patch up news blurb for pythongh-118339
bd54618
gvanrossum added a commit that referenced this pull request May 1, 2024
@gvanrossum
gh-118335: Make REGEN_JIT_COMMAND empty if tier2 interpreter enabled (#…
a524152
…118493)

Also patch up news blurb for gh-118339
(add warning that PYTHON_UOPS is now PYTHON_JIT).
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
@gvanrossum @SonicField
pythongh-118335: Configure Tier 2 interpreter at build time (python#1…
3345321
…18339)

The code for Tier 2 is now only compiled when configured
with `--enable-experimental-jit[=yes|interpreter]`.

We drop support for `PYTHON_UOPS` and -`Xuops`,
but you can disable the interpreter or JIT
at runtime by setting `PYTHON_JIT=0`.
You can also build it without enabling it by default
using `--enable-experimental-jit=yes-off`;
enable with `PYTHON_JIT=1`.

On Windows, the `build.bat` script supports
`--experimental-jit`, `--experimental-jit-off`,
`--experimental-interpreter`.

In the C code, `_Py_JIT` is defined as before
when the JIT is enabled; the new variable
`_Py_TIER2` is defined when the JIT *or* the
interpreter is enabled. It is actually a bitmask:
1: JIT; 2: default-off; 4: interpreter.
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
@gvanrossum @SonicField
pythongh-118335: Make REGEN_JIT_COMMAND empty if tier2 interpreter en…
122867b
…abled (python#118493)

Also patch up news blurb for pythongh-118339
(add warning that PYTHON_UOPS is now PYTHON_JIT).
@brandtbucher brandtbucher added the topic-JIT label May 31, 2024
@mdboom mdboom mentioned this pull request Jul 2, 2024
gh-121263: Macro-ify most stackref functions for MSVC #121270
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brandtbucher brandtbucher brandtbucher approved these changes
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner is a code owner
@corona10 corona10 Awaiting requested review from corona10 corona10 is a code owner
@mdboom mdboom Awaiting requested review from mdboom
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-JIT

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@gvanrossum @mdboom @brandtbucher
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.