Skip to content

Conversation

@zhangqi-chen
Copy link
Contributor

Integrate the PTOAS (PTO Assembler & Optimizer) tool to automatically compile .pto MLIR files to C++ code when using the PTO backend. Update 3 pto mlir.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zhangqi-chen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the PyPTO compilation workflow by incorporating the PTOAS tool. This integration streamlines the process of generating C++ code from PTO MLIR, improving the overall backend compilation pipeline. The changes also include necessary updates to existing MLIR reference files to align with new type definitions and location specifications.

Highlights

  • PTOAS Integration: The PTOAS (PTO Assembler & Optimizer) tool has been integrated into the PyPTO compilation pipeline, enabling automatic compilation of .pto MLIR files to C++ code.
  • Automated C++ Generation: When using the PTO backend, the compilation process now automatically invokes PTOAS to generate C++ output from the intermediate .pto MLIR representation.
  • MLIR Reference Updates: Three reference .pto MLIR files (addc-pto-ir.mlir, adds-pto-ir.mlir, mul-pto-ir.mlir) have been updated to reflect changes in tensor view types and tile buffer locations, specifically transitioning from subview to partition_view and loc=ub to loc=vec.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/pypto/ir/compile.py
    • Added shutil, subprocess, and warnings to imports for external process execution and warning handling.
    • Introduced a new private function _run_ptoas to encapsulate the logic for invoking the PTOAS binary, including binary resolution and error handling.
    • Updated the docstring of the compile function to reflect the new step of optionally invoking ptoas for C++ generation.
    • Integrated the _run_ptoas call within the compile function for the PTO backend, compiling .pto output to .cpp with the --enable-insert-sync flag.
  • reference/pto-isa/addc-pto-ir.mlir
    • Updated !pto.tensor_view types to specify concrete dimensions (e.g., 32x32xf32) or generic dimensions (?x?xf32).
    • Replaced pto.subview operations with pto.partition_view.
    • Updated !pto.tile_view types to !pto.partition_tensor_view.
    • Changed tile buffer location from loc=ub to loc=vec in pto.alloc_tile, pto.tload, and pto.tstore operations.
  • reference/pto-isa/adds-pto-ir.mlir
    • Updated !pto.tensor_view types to specify generic dimensions (?x?xf32).
    • Replaced pto.subview operations with pto.partition_view.
    • Updated !pto.tile_view types to !pto.partition_tensor_view.
    • Changed tile buffer location from loc=ub to loc=vec in pto.alloc_tile, pto.tload, and pto.tstore operations.
  • reference/pto-isa/mul-pto-ir.mlir
    • Updated !pto.tensor_view types to specify generic dimensions (?x?xf32).
    • Replaced pto.subview operations with pto.partition_view.
    • Updated !pto.tile_view types to !pto.partition_tensor_view.
    • Changed tile buffer location from loc=ub to loc=vec in pto.alloc_tile, pto.tload, and pto.tstore operations.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@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 integrates the ptoas tool into the compilation pipeline, which automatically compiles .pto MLIR files into C++ code. The changes look good, adding a _run_ptoas helper to handle the external process call and updating the compile function. The reference MLIR files have also been updated. I have one suggestion to improve the error handling when calling the external ptoas tool to make it more robust and provide more informative warnings on failure.

Comment on lines 51 to 56
try:
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
if result.returncode != 0:
warnings.warn(f"ptoas compilation failed: {result.stderr.strip()}", stacklevel=2)
except (OSError, FileNotFoundError):
warnings.warn("Failed to execute ptoas.", stacklevel=2)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The error handling for the subprocess.run call can be improved to be more idiomatic and provide more specific feedback upon failure. Using check=True will raise a subprocess.CalledProcessError for non-zero exit codes, which can be caught separately from FileNotFoundError or other OSError exceptions. This allows for more granular and informative error reporting, which is helpful for debugging issues with the external ptoas tool.

Suggested change
try:
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
if result.returncode != 0:
warnings.warn(f"ptoas compilation failed: {result.stderr.strip()}", stacklevel=2)
except (OSError, FileNotFoundError):
warnings.warn("Failed to execute ptoas.", stacklevel=2)
try:
subprocess.run(cmd, capture_output=True, text=True, check=True)
except FileNotFoundError:
warnings.warn(f"ptoas binary not found at '{resolved_bin}'.", stacklevel=2)
except subprocess.CalledProcessError as e:
warnings.warn(f"ptoas compilation failed: {e.stderr.strip()}", stacklevel=2)
except OSError as e:
warnings.warn(f"Failed to execute ptoas: {e}", stacklevel=2)

@lyfne123
Copy link
Contributor

如果找不到ptoas会报怎样的错

…ipeline

Add ptoas as a project dependency and invoke it automatically to compile
.pto MLIR files to C++ when using the PTO backend. Update 3 pto mlir.
@zhangqi-chen zhangqi-chen changed the title feat(codegen): Integrate PTOAS into PTO backend compilation pipeline [WIP] feat(codegen): Integrate PTOAS into PTO backend compilation pipeline Feb 12, 2026
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.

2 participants