Skip to content

feat(tilelib): materialize PTODSL in process - #1103

Draft
mouliangyu wants to merge 8 commits into
mainfrom
codex/embedded-ptodsl-context
Draft

feat(tilelib): materialize PTODSL in process#1103
mouliangyu wants to merge 8 commits into
mainfrom
codex/embedded-ptodsl-context

Conversation

@mouliangyu

@mouliangyu mouliangyu commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

背景

TileOp 展开此前通过独立 Python daemon 完成 PTODSL 模板选择和 MLIR 生成,需要维护子进程、Unix socket、JSON 协议、临时文件以及 MLIR 文本打印/解析。主线移除 legacy TileLang backend 后,这些设施只服务于 PTODSL,已经没有保留双后端抽象的必要。

主要变更

  • 新增与 Python 无关的 TileLibService C++ 接口,供 InsertTemplateAttributes 查询候选元数据、供 ExpandTileOp 请求模板实例化。
  • Python CLI 为每次编译创建并持有一个 MLIR Context;native PTOASContext_core.main 调用期间借用同一个底层 MLIRContext
  • PTODSL 在共享 context 中直接 materialize source module;native 边界校验 context identity,并在 Python owner 存活期间 clone 为 C++ ownership。
  • ExpandTileOp 按显式 entry symbol 导入实例化 module 中的入口和 helper functions,处理符号冲突与 symbol ref 重写,然后复用现有 call/erase 流程。
  • 保留 JSON 作为纯 specialization metadata 边界,不再通过文本、bytecode、临时文件或进程间协议传递 MLIR。
  • InsertTemplateAttributesExpandTileOp 收口为 compiler-session passes:只允许通过 TileLibService factory 构造,不再提供无参 factory 或全局 textual pass 注册。
  • 将 context-sensitive materialization 收口到内部 compiler runtime,不再通过公开 SpecializedTileTemplate.materialize(context) 暴露 ownership 敏感接口。
  • 删除 C++ daemon manager、Python socket/client/helper/wire 实现、daemon 专用测试,以及 backend/socket/Python executable/package-path 相关选项和脚本配置。
  • 将候选发现与选择逻辑迁移到中性的 _selection.py,同步更新 CLI、wheel smoke、ST 脚本和设计文档;ST runner 不再执行遗留 daemon socket cleanup。

生命周期与安全边界

  • Python Context 是底层 MLIRContext 的唯一 owner;C++ 只在 compilation session 动态范围内借用。
  • native compiler 运行时释放 GIL;metadata/materialize callback 同步 reacquire GIL,不引入 worker thread 或 subinterpreter。
  • Python 返回的 MlirModule 只作为 non-owning handle 使用;source module owner 保持存活直到 clone 完成。
  • materialize 结果必须来自当前 PTOAS context,否则编译失败,不允许跨 MLIR runtime/context 混用。
  • 两个依赖 TileLibService 的 pass 不进入全局 pass registry,避免脱离 compiler session 后构造出不可运行的 pass。

验证

  • ninja -C .work/tileop-embedded-python-study/build PTOASPythonCore PTOASPythonPackage -j4
  • ctest --test-dir .work/tileop-embedded-python-study/build --output-on-failure -R '^ptodsl_(ptoas_cli|tilelib_(catalog|constraints|elementwise|render|select))$':6/6 通过
  • llvm-lit -v expand_tile_op_ptodsl_tsub.pto expand_tile_op_ptodsl_view_stride_cache.pto:2/2 通过
  • llvm-lit -v expand_tile_op_trelu_tilelang.pto:1/1 通过
  • cmake --build .work/tileop-embedded-python-study/build --target PTOPassesIncGen PTOTransforms PTOASPythonCore -j4
  • test_tilelib_render.py focused tests:5/5 通过
  • ptoas --help 确认两个 session-only pass 不再出现在 standalone textual pass 列表
  • python3 -m py_compilebash -n docker/test_wheel_imports.shgit diff --check 通过

构建和测试使用 LLVM/MLIR 21.1.8。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant