Skip to content

feat(codegen): Add skip_ptoas option to PTO backend code generation#280

Merged
lyfne123 merged 1 commit intohw-native-sys:mainfrom
lyfne123:main
Feb 27, 2026
Merged

feat(codegen): Add skip_ptoas option to PTO backend code generation#280
lyfne123 merged 1 commit intohw-native-sys:mainfrom
lyfne123:main

Conversation

@lyfne123
Copy link
Contributor

Add skip_ptoas parameter to generate() and compile() to bypass the ptoas compilation step and emit raw MLIR (.pto) files directly. Orchestration code is still generated; kernel_config.py is skipped when ptoas is not invoked.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 PTO backend code generation by introducing a new skip_ptoas option. This allows users to bypass the ptoas compilation step, enabling direct output of raw MLIR files for kernels. This change provides greater flexibility for workflows that may not require immediate C++ kernel compilation, while still generating orchestration code.

Highlights

  • New skip_ptoas option: Introduced a skip_ptoas boolean parameter to the compile() and generate() functions in the PTO backend. When set to True, this option bypasses the ptoas compilation step.
  • Direct MLIR output: If skip_ptoas is enabled, the code generation process will directly emit raw MLIR (.pto) files for kernels instead of compiling them into C++ kernel wrappers.
  • Conditional kernel_config.py generation: The kernel_config.py file, which is typically generated for compiled kernels, will now be skipped when skip_ptoas is True.
  • New unit tests: Added a new test suite to verify the functionality of the skip_ptoas option, ensuring that .pto files are returned as expected when the option is active.
Changelog
  • python/pypto/ir/compile.py
    • Added skip_ptoas parameter to the compile function signature and its docstring.
    • Modified the call to generate to pass the new skip_ptoas parameter.
  • python/pypto/ir/pto_codegen.py
    • Added skip_ptoas parameter to the generate function signature and updated its docstring.
    • Implemented conditional logic to skip ptoas compilation and directly return raw MLIR content for InCore functions when skip_ptoas is True.
    • Removed the unconditional creation of the ptoas directory.
    • Added a conditional check to prevent kernel_config.py generation when skip_ptoas is True.
  • tests/ut/codegen/test_pto_codegen.py
    • Imported the generate function for testing.
    • Added a new test class TestGenerateSkipPtoas to validate the behavior of generate when skip_ptoas is True, specifically checking for .pto file extensions.
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.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A new skip_ptoas boolean parameter is introduced to the compile() and generate() functions. When enabled, the codegen pipeline skips PTOAS compilation and emits raw MLIR (.pto) files directly for kernels, bypassing the .cpp wrapper generation and configuration steps.

Changes

Cohort / File(s) Summary
Codegen API Extensions
python/pypto/ir/compile.py, python/pypto/ir/pto_codegen.py
Added skip_ptoas: bool = False parameter to both compile() and generate() functions. When enabled, generate() skips the PTOAS→.cpp→wrapper pipeline and outputs raw .pto files; kernel_config.py generation is also skipped. Parameter is propagated from compile() to generate().
Test Coverage
tests/ut/codegen/test_pto_codegen.py
New test class TestGenerateSkipPtoas with test_returns_pto_files() verifying that when skip_ptoas=True, kernel output keys end with .pto (not .cpp) and at least one kernel file exists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • Hzfengsy

Poem

🐰 With skip_ptoas flag set true,
We bound past the compilation queue,
Raw MLIR hops right through,
No .cpp wrappers slow our view—
Straight to .pto files, fresh and new! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a skip_ptoas option to PTO backend code generation.
Description check ✅ Passed The description clearly relates to the changeset by explaining what the skip_ptoas parameter does and its effects on the compilation pipeline.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

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 introduces a skip_ptoas option to the compile and generate functions, allowing users to bypass the ptoas compilation step and directly emit raw MLIR files. The implementation is clean and correctly handles the new flag, including skipping the generation of kernel_config.py when ptoas is not invoked. I've added one suggestion to improve the completeness of the new test case, aligning with best practices for specific negative assertions in tests.

assert len(kernel_keys) > 0, "Expected at least one kernel file"
for key in kernel_keys:
assert key.endswith(".pto"), f"Expected .pto extension, got: {key}"
assert not key.endswith(".cpp"), f"Unexpected .cpp extension: {key}"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test correctly verifies that .pto files are generated when skip_ptoas=True. However, it's missing a check to ensure that kernel_config.py is not generated in this case, as described in the PR description and implemented in pto_codegen.py. Please add the following assertion after this block:

assert "kernel_config.py" not in result, "kernel_config.py should not be generated when skip_ptoas=True"
References
  1. When writing negative assertions in tests, be specific about the pattern being excluded to avoid ambiguity and potential false positives. The suggested assertion assert "kernel_config.py" not in result adheres to this by being specific about the file name being excluded.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
tests/ut/codegen/test_pto_codegen.py (1)

531-556: Consider adding an assertion that kernel_config.py is absent.

The test verifies .pto files are generated but doesn't verify the expected side effect that kernel_config.py is skipped when skip_ptoas=True.

🧪 Suggested additional assertion
         for key in kernel_keys:
             assert key.endswith(".pto"), f"Expected .pto extension, got: {key}"
             assert not key.endswith(".cpp"), f"Unexpected .cpp extension: {key}"
+
+        # Verify kernel_config.py is not generated when skip_ptoas=True
+        assert "kernel_config.py" not in result, "kernel_config.py should not be generated with skip_ptoas=True"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/ut/codegen/test_pto_codegen.py` around lines 531 - 556, Add an
assertion after calling generate(transformed_program, ..., skip_ptoas=True) in
TestGenerateSkipPtoas that verifies the generated result does not include the
kernel_config.py artifact; specifically check that "kernel_config.py" is not
present in the keys of the result returned by generate (this complements the
existing checks on kernel file extensions and ensures skip_ptoas=True also
suppresses kernel_config.py generation).
python/pypto/ir/compile.py (1)

86-96: Consider validating skip_ptoas usage with non-PTO backends.

If a user passes skip_ptoas=True with BackendType.CCE, it's silently ignored. While the docstring documents this is "PTO backend only", a warning could help users catch misconfigurations.

⚠️ Optional: Add a warning for skip_ptoas with non-PTO backends
+import warnings
+
 def compile(
     ...
 ) -> str:
     ...
+    if skip_ptoas and backend_type != BackendType.PTO:
+        warnings.warn(
+            "skip_ptoas is only supported for PTO backend; ignoring for {backend_type.name}",
+            stacklevel=2,
+        )
+
     if backend_type == BackendType.PTO:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@python/pypto/ir/compile.py` around lines 86 - 96, The code silently ignores
skip_ptoas when backend_type != BackendType.PTO; update the compile path (the
block using backend_type, BackendType, skip_ptoas, generate, and CCECodegen in
python/pypto/ir/compile.py) to emit a warning when skip_ptoas is True but
backend_type is not BackendType.PTO (use the project's logger or warnings.warn)
before proceeding to CCECodegen(). Keep behavior unchanged otherwise and include
a clear message stating that skip_ptoas is PTO-only.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@python/pypto/ir/compile.py`:
- Around line 86-96: The code silently ignores skip_ptoas when backend_type !=
BackendType.PTO; update the compile path (the block using backend_type,
BackendType, skip_ptoas, generate, and CCECodegen in python/pypto/ir/compile.py)
to emit a warning when skip_ptoas is True but backend_type is not
BackendType.PTO (use the project's logger or warnings.warn) before proceeding to
CCECodegen(). Keep behavior unchanged otherwise and include a clear message
stating that skip_ptoas is PTO-only.

In `@tests/ut/codegen/test_pto_codegen.py`:
- Around line 531-556: Add an assertion after calling
generate(transformed_program, ..., skip_ptoas=True) in TestGenerateSkipPtoas
that verifies the generated result does not include the kernel_config.py
artifact; specifically check that "kernel_config.py" is not present in the keys
of the result returned by generate (this complements the existing checks on
kernel file extensions and ensures skip_ptoas=True also suppresses
kernel_config.py generation).

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a848223 and f4aeb90.

📒 Files selected for processing (3)
  • python/pypto/ir/compile.py
  • python/pypto/ir/pto_codegen.py
  • tests/ut/codegen/test_pto_codegen.py

Add skip_ptoas parameter to generate() and compile() to bypass the
ptoas compilation step and emit raw MLIR (.pto) files directly.
Orchestration code is still generated; kernel_config.py is skipped
when ptoas is not invoked.
@lyfne123 lyfne123 merged commit f124899 into hw-native-sys:main Feb 27, 2026
6 checks passed
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