[SOT][3.12] Support CALL_INTRINSIC_1 opcode in Python 3.12#61995
[SOT][3.12] Support CALL_INTRINSIC_1 opcode in Python 3.12#61995SigureMo merged 8 commits intoPaddlePaddle:developfrom
CALL_INTRINSIC_1 opcode in Python 3.12#61995Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
| class Intrinsics_UnaryFunctions(Enum): | ||
| INTRINSIC_1_INVALID = 0 | ||
| INTRINSIC_PRINT = 1 # no support, print | ||
| INTRINSIC_IMPORT_STAR = 2 # no support, `from module import *` | ||
| INTRINSIC_STOPITERATION_ERROR = ( | ||
| 3 # no support, generator or coroutine | ||
| ) | ||
| INTRINSIC_ASYNC_GEN_WRAP = 4 # no support, async | ||
| INTRINSIC_UNARY_POSITIVE = 5 | ||
| INTRINSIC_LIST_TO_TUPLE = 6 | ||
| INTRINSIC_TYPEVAR = 7 # no support, PEP 695 | ||
| INTRINSIC_PARAMSPEC = 8 # no support, PEP 695 | ||
| INTRINSIC_TYPEVARTUPLE = 9 # no support, PEP 695 | ||
| INTRINSIC_SUBSCRIPT_GENERIC = 10 # no support, PEP 695 | ||
| INTRINSIC_TYPEALIAS = 11 # no support, PEP 695 | ||
|
|
||
| def to_func(self): | ||
| if self == self.INTRINSIC_1_INVALID: | ||
| raise RuntimeError("invalid intrinsic function") | ||
| elif self == self.INTRINSIC_UNARY_POSITIVE: | ||
| return OpcodeExecutor_.UNARY_POSITIVE | ||
| elif self == self.INTRINSIC_LIST_TO_TUPLE: | ||
| return OpcodeExecutor_.LIST_TO_TUPLE | ||
| else: | ||
| raise BreakGraphError(f"No support Intrinsics, {self.name}") |
There was a problem hiding this comment.
将数据和操作分离吧,数据放在 instr_flag.py,然后在这边进行派发
另外我看了一下背景,大概就是将原本一些低频的字节码集中在了其中两条字节码上(分别是 unary 和 binary),以降低解释器循环大小
那么这里应该只是相当于额外一层派发,不支持的字节码不应该直接 Fallback 么?而不是 BreakGraph
另外也看一下 INTRINSIC_PRINT,根据描述是只用在 REPL 的,可以测试下非 REPL print 是否会有这个字节码,以及是何种行为,如果有,那么我们需要对齐原来 print 的打断行为
There was a problem hiding this comment.
INTRINSIC_PRINT仅在交互模式(non-interactive)下触发,且会在inspect.getsourcelines的时候拿不到源码,所以暂时不处理这种行为
| CFE_HAS_KWARGS = 0x01 | ||
|
|
||
|
|
||
| class Intrinsics_UnaryFunctions(Enum): |
There was a problem hiding this comment.
| class Intrinsics_UnaryFunctions(Enum): | |
| class IntrinsicsUnaryFunctions(Enum): |
这里按照 Python 代码风格
另外加一下注释,这里的是从 cpython 哪里 copy 来的,以便未来版本适配时更新
There was a problem hiding this comment.
下一个 PR 加一下 binary 的,但是全部 Fallback 吧
| def CALL_INTRINSIC_1(self, instr: Instruction): | ||
| assert isinstance(instr.arg, int) | ||
| assert instr.arg <= MAX_INTRINSIC_1 | ||
| opce: OpcodeExecutorBase = self |
| def to_func(args): | ||
| if args == Intrinsics_UnaryFunctions.INTRINSIC_1_INVALID: | ||
| raise RuntimeError("invalid intrinsic function") | ||
| elif args == Intrinsics_UnaryFunctions.INTRINSIC_UNARY_POSITIVE: | ||
| return opce.UNARY_POSITIVE | ||
| elif args == Intrinsics_UnaryFunctions.INTRINSIC_LIST_TO_TUPLE: | ||
| return opce.LIST_TO_TUPLE | ||
| else: | ||
| raise FallbackError(f"No support Intrinsics, {args.name}") |
…or.py Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
|
@diadestiny 可以也来 review 下这个~ |
可以通过这个 approve~ @diadestiny |
|
冲突了需要解决下~ |
Done |

PR types
Others
PR changes
Others
Description
python 3.12 支持
CALL_INTRINSIC_1参考链接:
CALL_INTRINSIC_1instruction python/cpython#100771相关链接:
(TODO: 好像跑不到
BreakGraphError让我测测)