Skip to content

feat: support ptodsl#725

Open
mouliangyu wants to merge 306 commits into
hw-native-sys:mainfrom
mouliangyu:feature-vpto-backend-merge2
Open

feat: support ptodsl#725
mouliangyu wants to merge 306 commits into
hw-native-sys:mainfrom
mouliangyu:feature-vpto-backend-merge2

Conversation

@mouliangyu
Copy link
Copy Markdown
Contributor

No description provided.

Zhendong404 and others added 30 commits May 25, 2026 11:13
mouliangyu and others added 28 commits May 28, 2026 19:57
* feat: update workflow

* feat: rename pto.aicore to pto.kernel

---------

Co-authored-by: mouliangyu <mouliangyu@huawei.com>
* pip install ptoas

* use pip install in CI

* wheels pipelines use pip install

* add missing license header

* fix pip setup
@reedhecre
Copy link
Copy Markdown

reedhecre commented May 28, 2026

Codex Review

该评论由 review 机器人自动更新。

  • PR: feat: support ptodsl #725 feat: support ptodsl
  • Author: mouliangyu
  • Base/Head: main / feature-vpto-backend-merge2
  • Head SHA: a6007c028bb1
  • Trigger: 检测到新的 open PR
  • Generated At: 2026-05-28T17:36:36Z
  • Status: completed

Summary

发现 2 个问题:版本号被回退会影响发布和产物版本,TileLang DSL 的旧方言导入在常规安装包中会失败。

Findings

  1. P2 不要回退 PTOAS 项目版本号 CMakeLists.txt:10

该 PR 相对 origin/main 把 project(ptoas VERSION ...) 从 0.43 回退到 0.41。仓库的 compute_ptoas_version.py 直接读取这个字段,workflow 会用它校验 release tag,普通构建也会把它编入 ptoas --version(没有 override 时)。合入后会让产物报告旧版本,并使基于当前 main 版本线的 release 校验失败。

  1. P2 TileLang DSL 仍引用未安装的旧 PTO 方言命名空间 tilelang-dsl/python/tilelang_dsl/lowering_backend.py:77

这里仍从 pto.dialects 导入 PTO 方言,但本 PR 的 CMake/wheel 安装路径是 mlir/dialects/pto.py,文档和 smoke test 也都使用 from mlir.dialects import pto;常规 pip install . 产物不会包含 pto/dialects 这个旧命名空间。结果是安装包中 TextBackendLoweringResult.as_module()compare_backends() 的 text 侧验证等会在环境正确时仍因 ImportError 失败。应改为 mlir.dialects.pto,并同步同文件族里的环境检查路径。

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several new developer skills under .codex/skills, adds the 3rdparty/PTO-Gym submodule, updates .gitignore, and implements a PEP 517 build backend in _ptoas_build_backend.py along with updated Docker and distribution scripts to package TileLang resources. It also updates CMakeLists.txt to register new tests and adds extensive documentation. The reviewer feedback highlights critical configuration issues, such as missing directories (tilelang-dsl and ptodsl/tests) that will break CMake, and configure-time evaluation of $ENV{PYTHONPATH}. Additionally, several improvements are suggested for the Python build backend, including failing fast on missing package directories, handling non-directory paths safely when removing directories, explicitly passing PY_PACKAGE_DIR to the wheel creation script, and adhering to PEP 427 by omitting the non-integer Build tag from the wheel metadata.

Comment thread CMakeLists.txt
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python/pto)

add_subdirectory(python)
add_subdirectory(tilelang-dsl)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The directory tilelang-dsl is added via add_subdirectory, but it is missing from the repository and not defined as a submodule in .gitmodules. This will cause CMake configuration to fail immediately. Please ensure the tilelang-dsl directory is included in the repository or added as a submodule.

Comment thread CMakeLists.txt
if(BUILD_TESTING)
enable_testing()
if(PTO_ENABLE_PYTHON_BINDING)
add_subdirectory(ptodsl/tests)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The directory ptodsl/tests is added via add_subdirectory, but the ptodsl directory is missing from the repository. This will cause CMake configuration to fail. Please ensure the ptodsl directory is included in the repository.

Comment thread CMakeLists.txt
Comment on lines +142 to +144
set_tests_properties(tilelang_dsl_import PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Evaluating $ENV{PYTHONPATH} at configure time is an anti-pattern because it captures the environment of the configure-time shell rather than the test-run shell. Furthermore, if PYTHONPATH is empty at configure time, this results in a trailing colon (e.g., PYTHONPATH=/path/to/bin:), which tells Python to prepend the current working directory (.) to sys.path, posing a security and predictability risk.

If CMake 3.22+ is supported, consider using ENVIRONMENT_MODIFICATION to prepend to PYTHONPATH dynamically:

set_tests_properties(tilelang_dsl_import PROPERTIES
  ENVIRONMENT_MODIFICATION "PYTHONPATH=path_list_prepend:${CMAKE_BINARY_DIR}/python"
)

Otherwise, avoid appending $ENV{PYTHONPATH} directly if it might be empty.

    set_tests_properties(tilelang_dsl_import PROPERTIES
      ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python"
    )

Comment thread CMakeLists.txt
Comment on lines +151 to +153
set_tests_properties(tilelang_dsl_unittest PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Evaluating $ENV{PYTHONPATH} at configure time is an anti-pattern because it captures the environment of the configure-time shell rather than the test-run shell. Furthermore, if PYTHONPATH is empty at configure time, this results in a trailing colon (e.g., PYTHONPATH=/path/to/bin:), which tells Python to prepend the current working directory (.) to sys.path, posing a security and predictability risk.

If CMake 3.22+ is supported, consider using ENVIRONMENT_MODIFICATION to prepend to PYTHONPATH dynamically:

set_tests_properties(tilelang_dsl_unittest PROPERTIES
  ENVIRONMENT_MODIFICATION "PYTHONPATH=path_list_prepend:${CMAKE_BINARY_DIR}/python"
)

Otherwise, avoid appending $ENV{PYTHONPATH} directly if it might be empty.

    set_tests_properties(tilelang_dsl_unittest PROPERTIES
      ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python"
    )

Comment thread _ptoas_build_backend.py

def _cmake_configure_and_build():
"""CMake configure + Ninja build + install."""
_BUILD_DIR.mkdir(parents=True, exist_ok=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If _MLIR_PY_PKG (which is derived from LLVM_BUILD_DIR) does not exist, the build will fail much later during the wheel creation or dialect installation phase. Checking its existence early in _cmake_configure_and_build provides a much clearer error message and avoids wasting time on a compilation that is guaranteed to fail.

Suggested change
_BUILD_DIR.mkdir(parents=True, exist_ok=True)
_BUILD_DIR.mkdir(parents=True, exist_ok=True)
if not _MLIR_PY_PKG.exists():
raise RuntimeError(
f"MLIR python package directory not found at {_MLIR_PY_PKG}. "
"Please ensure LLVM_BUILD_DIR is set correctly and LLVM was built with python bindings enabled."
)

Comment thread _ptoas_build_backend.py
Comment on lines +141 to +143
if dst.exists():
shutil.rmtree(dst)
shutil.copytree(tilelang_src, dst)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using shutil.rmtree(dst) directly when dst.exists() is true can fail with NotADirectoryError if dst is a file or a symlink rather than a directory. A safer approach is to check if dst is a directory and not a symlink before calling shutil.rmtree, and use dst.unlink() otherwise.

        if dst.exists() or dst.is_symlink():
            if dst.is_dir() and not dst.is_symlink():
                shutil.rmtree(dst)
            else:
                dst.unlink()
        shutil.copytree(tilelang_src, dst)

Comment thread _ptoas_build_backend.py
Comment on lines +154 to +159
env = os.environ.copy()
env.update({
"PTO_SOURCE_DIR": str(_REPO),
"PTO_INSTALL_DIR": str(_PTO_INSTALL_DIR),
"LLVM_BUILD_DIR": str(_LLVM_BUILD_DIR),
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The create_wheel.sh script relies on PY_PACKAGE_DIR to copy the dialect files and TileLang resources. When running locally outside of Docker, PY_PACKAGE_DIR might not be set in the user's environment, causing the script to fail or copy files to incorrect locations. Explicitly passing PY_PACKAGE_DIR in the environment dictionary ensures reliable local builds.

    env = os.environ.copy()
    env.update({
        "PTO_SOURCE_DIR": str(_REPO),
        "PTO_INSTALL_DIR": str(_PTO_INSTALL_DIR),
        "LLVM_BUILD_DIR": str(_LLVM_BUILD_DIR),
        "PY_PACKAGE_DIR": str(_MLIR_PY_PKG),
    })

Comment thread _ptoas_build_backend.py
Comment on lines +224 to +230
"Generator: _ptoas_build_backend\n"
"Root-Is-Purelib: True\n"
f"Tag: {tag}\n"
"Build: editable\n"
).encode()
metadata_content = (
"Metadata-Version: 2.1\n"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

According to PEP 427, the Build tag in the WHEEL metadata is optional, but if present, it must be an integer (e.g., Build: 1). Using a non-integer value like Build: editable violates the specification and can cause packaging or installation tools to fail. It is safer to omit the Build tag entirely.

    wheel_meta = (
        "Wheel-Version: 1.0\n"
        "Generator: _ptoas_build_backend\n"
        "Root-Is-Purelib: True\n"
        f"Tag: {tag}\n"
    ).encode()

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.