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

Expose jit_code field for UOp Executor #117958

Closed
tonybaloney opened this issue Apr 17, 2024 · 2 comments
Closed

Expose jit_code field for UOp Executor #117958

tonybaloney opened this issue Apr 17, 2024 · 2 comments
Labels
performance Performance or resource usage type-feature A feature request or enhancement

Comments

@tonybaloney
Copy link
Contributor

tonybaloney commented Apr 17, 2024

Feature or enhancement

Proposal:

I would like to add a method to the UOpExecutor type to expose the JIT code via a byte string using the jit_code and jit_size fields of the executor object. This would be useful for testing and debugging, as well as verification code.

from _opcode import get_executor


def get_executors(func):
    code = func.__code__
    co_code = code.co_code
    executors = {}
    for i in range(0, len(co_code), 2):
        try:
            executors[i] = co_code[i], get_executor(code, i)
        except ValueError:
            pass
    return executors

def testfunc(x):
    i = 0
    while i < x:
        i += 1

testfunc(20)

ex = get_executors(testfunc)

with open('jit_dump.raw', 'wb') as dumpfile:
    for i, executor in ex.items():
        print(i, executor[0], executor[1])

        try:
            code = executor[1].get_jit_code()
            dumpfile.write(code)
        except ValueError:
            print('Failed to get JIT code for', executor[0])




def f():
    a = [0, 1, 2, 3]
    return a[1]

Has this already been discussed elsewhere?

https://discuss.python.org/t/jit-mapping-bytecode-instructions-and-assembly/50809

Links to previous discussion of this feature:

No response

Linked PRs

@gvanrossum
Copy link
Member

Keeping this open, since in the discussion for gh-117959 there's some discussion about possibly more useful (and more complex) APIs that we could add later if the current form is deemed insufficient. But at least now we provide access at the raw bytes.

@brandtbucher
Copy link
Member

Let's move the discussion to GH-118467, which is the more specific feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants