Skip to content

feat(harness): Add PTO backend support and PTOAS on-board tests#278

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

feat(harness): Add PTO backend support and PTOAS on-board tests#278
lyfne123 merged 1 commit intohw-native-sys:mainfrom
lwDavid:dim

Conversation

@lwDavid
Copy link
Contributor

@lwDavid lwDavid commented Feb 26, 2026

feat(harness): Add PTO backend support and PTOAS on-board tests

Enable test harness to use PTO backend (via ptoas compiler) in addition
to the default CCE backend.

Harness changes:

  • Add get_backend_type() to PTOTestCase (default CCE, backward compatible)
  • Accept backend_type in ProgramCodeGenerator, replacing hardcoded CCE
  • Propagate backend_type from test case through TestRunner

Runtime tests:

  • Add PTO+PTOAS variants for DAG, elementwise (add/mul), and matmul
  • Fix TestTileAddWithPTOAS: was missing backend_type override, causing
    PTOAS strategy to run with CCE backend (sync not inserted → wrong results)
  • Remove skip marker on elementwise PTOAS test now that root cause is fixed

CI:

  • chmod +x ptoas-bin/bin/ptoas (actual binary, not just wrapper script)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lwDavid, 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 test harness by introducing explicit support for the PTO backend, alongside the existing CCE backend. It refactors the code generation process to be configurable by individual test cases, allowing them to specify their target backend. This change is crucial for expanding test coverage to the PTO backend and validating its functionality, as demonstrated by the inclusion of a new test for a vector DAG program using PTOAS optimization.

Highlights

  • PTO Backend Support: The test harness now supports specifying the PTO backend for code generation, allowing system tests to target the ptoas compiler.
  • Configurable Backend Type: The ProgramCodeGenerator has been updated to accept a backend_type parameter, and PTOTestCase now includes a get_backend_type method, enabling test cases to define their desired backend.
  • Test Runner Integration: The TestRunner dynamically retrieves the backend_type from the PTOTestCase and passes it to the code generator, ensuring the correct backend is used for each test.
  • New PTOAS DAG Test: A new system test, test_vector_dag_pto.py, has been added to validate the PTO backend and PTOAS optimization for a multi-kernel vector DAG orchestration.
Changelog
  • tests/st/harness/adapters/program_generator.py
    • Modified ProgramCodeGenerator constructor to accept an optional backend_type parameter, defaulting to BackendType.CCE.
    • Updated the generate method to use the instance's backend_type instead of a hardcoded value.
  • tests/st/harness/core/harness.py
    • Imported BackendType for use within the harness.
    • Introduced get_backend_type method in PTOTestCase to enable test cases to define their target backend, with a default implementation returning BackendType.CCE.
  • tests/st/harness/core/test_runner.py
    • Updated run method to fetch the backend_type from the PTOTestCase instance.
    • Configured set_backend_type and ProgramCodeGenerator to use the backend_type provided by the test case.
  • tests/st/runtime/test_vector_dag_pto.py
    • Added TestVectorDAGPTO to define a specific test case for a vector DAG program, targeting the PTO backend with PTOAS optimization.
    • Implemented TestPTOBackendOperations to execute TestVectorDAGPTO using the test runner, verifying correct behavior of the PTO backend.
Activity
  • The pull request was created by lwDavid to add support for the PTO backend in the test harness and include a new test case.
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 26, 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

The changes introduce dynamic backend type selection in the test harness infrastructure. A new optional backend_type parameter is added to ProgramCodeGenerator, PTOTestCase gains a get_backend_type() method, and the test runner now retrieves and passes the backend type dynamically. A new test module validates PTO-backed vector DAG execution with this infrastructure.

Changes

Cohort / File(s) Summary
Backend Type Parameter
tests/st/harness/adapters/program_generator.py
Added optional backend_type parameter to constructor; defaults to BackendType.CCE if not provided, and passes the value to ir.compile() invocation.
Test Harness Backend Selection
tests/st/harness/core/harness.py, tests/st/harness/core/test_runner.py
Added get_backend_type() method to PTOTestCase returning BackendType.CCE. Updated test runner to dynamically retrieve backend type from test case and pass it to ProgramCodeGenerator constructor and set_backend_type() call.
PTO Backend Test Suite
tests/st/runtime/test_vector_dag_pto.py
New test module containing TestVectorDAGPTO test case and TestPTOBackendOperations suite. Implements end-to-end validation of PTO-backed vector DAG execution with arithmetic operations (add, multiply) on 128×128 FP32 tensors.

Sequence Diagram

sequenceDiagram
    participant TestCase as Test Case
    participant Runner as Test Runner
    participant Generator as ProgramCodeGenerator
    participant Compiler as ir.compile()
    
    TestCase->>Runner: get_backend_type()
    Runner->>Runner: backend_type = BackendType.PTO (or CCE)
    Runner->>Runner: set_backend_type(backend_type)
    Runner->>Generator: __init__(strategy, backend_type)
    Generator->>Generator: self.backend_type = backend_type
    Generator->>Compiler: generate() calls ir.compile(backend_type=self.backend_type)
    Compiler->>Compiler: Compile with selected backend
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • Hzfengsy

Poem

🐰 A rabbit hops through backends bright,
Threading types left and right,
From test case down to compile's call,
Dynamic dispatch serves them all!
PTO's path now shines so clear. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 captures the main objective of the PR: adding PTO backend support to the test harness and introducing a PTOAS-based test.
Description check ✅ Passed The pull request description accurately describes the changeset, covering harness changes, runtime tests, and CI modifications related to PTO backend support.

✏️ 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 effectively adds support for the PTO backend in the test harness, making it more flexible. The changes are well-implemented, propagating the backend_type from the test case down to the code generator while maintaining backward compatibility by defaulting to the CCE backend. The new test test_vector_dag_pto.py is a great addition for end-to-end validation of this new path. I have one suggestion in the new test file to improve type safety, aligning with best practices for passing primitive-like types to internal bindings.

Comment on lines 101 to 102
d: pl.Tensor[[128, 128], pl.FP32] = self.kernel_add_scalar(c, 1.0) # type: ignore[reportArgumentType]
e: pl.Tensor[[128, 128], pl.FP32] = self.kernel_add_scalar(c, 2.0) # type: ignore[reportArgumentType]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using type: ignore[reportArgumentType] hides a potential type mismatch. Instead of passing a raw float and suppressing the type checker, you should use pl.const() to explicitly create a DSL scalar constant. This resolves the type error, removes the need for # type: ignore, and makes the code more robust and readable. This aligns with the guideline that when passing primitive-like types to internal bindings, they should be explicitly converted to the expected internal representation (e.g., Scalar or Expr) to match the expected C++ types.

Suggested change
d: pl.Tensor[[128, 128], pl.FP32] = self.kernel_add_scalar(c, 1.0) # type: ignore[reportArgumentType]
e: pl.Tensor[[128, 128], pl.FP32] = self.kernel_add_scalar(c, 2.0) # type: ignore[reportArgumentType]
d: pl.Tensor[[128, 128], pl.FP32] = self.kernel_add_scalar(c, pl.const(1.0))
e: pl.Tensor[[128, 128], pl.FP32] = self.kernel_add_scalar(c, pl.const(2.0))
References
  1. When passing a sequence of IntLike (int | Scalar | Expr) to C++ bindings, ensure any Scalar objects are unwrapped to Expr objects to match the expected C++ types.

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 (1)
tests/st/harness/adapters/program_generator.py (1)

29-29: Consider updating docstrings to reflect multi-backend support.

The class docstring says "Generates CCE C++ kernel..." but now supports both CCE and PTO backends. Similarly, the generate() method docstring at line 130 mentions "CCE C++ kernel files."

📝 Suggested docstring updates
 class ProgramCodeGenerator:
-    """Generates CCE C++ kernel and orchestration code from PyPTO Programs.
+    """Generates C++ kernel and orchestration code from PyPTO Programs.
 
     Pipeline: ir.Program -> ir.compile() -> C++ source files

And at line 130:

     def generate(
         ...
     ) -> dict[str, Any]:
-        """Generate CCE C++ kernel files from a PyPTO Program.
+        """Generate C++ kernel files from a PyPTO Program.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/st/harness/adapters/program_generator.py` at line 29, Update the class
docstring and the generate() method docstring in program_generator.py to reflect
multi-backend support (both CCE and PTO) instead of only "CCE C++ kernel";
specifically edit the top-level class docstring that currently begins "Generates
CCE C++ kernel and orchestration code from PyPTO Programs." and the docstring
inside the generate() method (around line 130) that mentions "CCE C++ kernel
files" so both describe that the generator produces backend-specific code for
CCE and PTO (or a generic "CCE/PTO" phrasing) and note any backend selection
behavior handled by the generate() method.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/st/harness/adapters/program_generator.py`:
- Line 29: Update the class docstring and the generate() method docstring in
program_generator.py to reflect multi-backend support (both CCE and PTO) instead
of only "CCE C++ kernel"; specifically edit the top-level class docstring that
currently begins "Generates CCE C++ kernel and orchestration code from PyPTO
Programs." and the docstring inside the generate() method (around line 130) that
mentions "CCE C++ kernel files" so both describe that the generator produces
backend-specific code for CCE and PTO (or a generic "CCE/PTO" phrasing) and note
any backend selection behavior handled by the generate() method.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cfa5373 and 7ba4ade.

📒 Files selected for processing (4)
  • tests/st/harness/adapters/program_generator.py
  • tests/st/harness/core/harness.py
  • tests/st/harness/core/test_runner.py
  • tests/st/runtime/test_vector_dag_pto.py

@lwDavid lwDavid force-pushed the dim branch 3 times, most recently from 4508a21 to e743431 Compare February 26, 2026 12:36
@lwDavid lwDavid changed the title feat(harness): Support PTO backend in test harness and add PTOAS DAG test feat(harness): Add PTO backend support and PTOAS on-board tests Feb 26, 2026
@lwDavid
Copy link
Contributor Author

lwDavid commented Feb 27, 2026

@Hzfengsy Request review.

@lyfne123 lyfne123 merged commit d651b61 into hw-native-sys:main Feb 27, 2026
6 checks passed
@lwDavid lwDavid deleted the dim branch February 27, 2026 10:34
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