JIT: map uops with code generated by the JIT
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
Proposal:
This is a follow up feature of https://github.com/python/cpython/issues/117958. That feature exposes just the bare JIT Code of the executor object.
To improve the debug experience of the JIT implementation, a map between the UOp and the generated code should be implemented.
@brandtbucher suggested the following in his comment
Hello, thanks for the PR! It certainly does the job of capturing the machine code generated by the JIT but I was hoping to have a map between the uop byte code and the related machine code similarly to what I was envisaging here
So, I've thought about this, and it should be possible with a couple of tweaks.
Basically, this current PR returns a byte string, which consists of the code for each instruction in sequence, followed by the auxiliary data for each instruction in sequence.
Meaning, for a trace of:
[A, B, C, D]It returns:
b"".join([<A code>, <B code>, <C code>, <D code>, <A data>, <B data>, <C data>, <D data>, <padding>])However, the executor knows the uops that make up its trace. If we
#include "jit_stencils.h", we should be able to usestencil_groups[instruction->opcode].code.body_sizeandstencil_groups[instruction->opcode].data.body_sizeto compute these chunks.Maybe @tonybaloney and @diegorusso can confirm, but it seems like the most useful info to return would be a 3-tuple of base address, a list of code byte strings (corresponding to uops) and a list of data byte strings (again, corresponding to uops).
So, for the above example, the return value would be:
( <base address>, [<A code>, <B code>, <C code>, <D code>], [<A data>, <B data>, <C data>, <D data>], )(I think base address is needed for some absolute addressing that we use in places.)
So each of the code or data lists can be
zip'd with the executor to map them to individual uops. And if I want the raw string of data that this PR returns now, I can just take this tuple and dob"".join(result[1] + result[2]).Would this meet everyone's needs, or am I overthinking it? Even though it's internal, I don't want to tweak this too much after the beta freeze on Monday, so I'm leaning towards providing more information rather than less.
Originally posted by @brandtbucher in https://github.com/python/cpython/issues/117959#issuecomment-2088028660
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/jit-mapping-bytecode-instructions-and-assembly/50809
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先閱讀相關 issue 117958 和 117959、Discourse 討論以及 jit_stencils.h。追蹤 executor 如何公開其 JIT 程式碼,以及 stencil_groups 如何提供程式碼和資料大小。完成的標誌是公開一個基底位址,以及按 uop 划分的程式碼和資料位元組字串清單,並且這些清單可以映射回 executor 的 uop。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- compilers
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100