Skip to content

feat(ops): add B02 TSELS and TPRELU support - #2182

Open
hashiqiqixian wants to merge 7 commits into
hw-native-sys:mainfrom
hashiqiqixian:feat/ptoas-b02-selection-prelu
Open

feat(ops): add B02 TSELS and TPRELU support#2182
hashiqiqixian wants to merge 7 commits into
hw-native-sys:mainfrom
hashiqiqixian:feat/ptoas-b02-selection-prelu

Conversation

@hashiqiqixian

Copy link
Copy Markdown
Contributor

Summary

  • replace the obsolete three-operand tile.sels path with the canonical mask, src, tmp, scalar TSELS contract
  • add canonical three-input tile.prelu(src, slope, tmp) inference, backend emission, alias rules, debug codegen, and bilingual documentation
  • add focused IR/codegen/memory-reuse coverage plus same-name TSELS/TPRELU hardware tests
  • document the pinned PTO-ISA target split: A2/A3 TSELS supports FP16/FP32, while integer TSELS coverage is A5-only

Validation

  • remote serial C++ build: cmake --build build --parallel 1
  • remote Ruff lint/format: PASS
  • remote diff-scoped clang-tidy 21.1 with --jobs=1: PASS
  • focused unit tests:
    • TPRELU IR: 10 passed
    • TSELS IR: 11 passed
    • PTO codegen: 2 passed
    • Torch debug codegen: 1 passed
    • memory reuse alias rules: 2 passed
  • A2/A3 hardware, PTOAS 0.48, one device / one precompile worker:
    • task task_20260728_033948_204201930367
    • 19 passed, 22 deselected
  • repository checks:
    • 1,080 English-source checks passed
    • 964 header checks passed
    • 81 EN/ZH documentation pairs passed

Platform status

  • A2/A3 hardware: verified
  • A5 hardware: pending

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

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.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 557415ac-3e47-45d1-b983-9a4ccd4122b3

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 PR replaces tile.sels with a mask/source/scratch/scalar interface, adds dedicated tile.prelu validation and alias constraints, updates backend emission, and adds hardware, unit, codegen, memory-reuse, and documentation coverage.

Changes

Selection and PReLU operation updates

Layer / File(s) Summary
Operation contracts and Python APIs
python/pypto/ir/..., python/pypto/language/..., src/ir/op/tile_ops/elementwise.cpp
tile.sels now selects between src and scalar using mask and tmp; tile.prelu validates source, slope, scratch, valid-shape, and aliasing contracts.
Backend registration and debug emission
src/backend/common/..., python/pypto/debug/...
Backend arities and row-major registration are updated, and Torch emission uses the scalar false branch for tile.sels.
Hardware operation coverage
tests/st/runtime/ops/*
Runtime tests cover TSELS comparison modes, dtypes, tails, and TPRELU dtypes, tails, and scratch configurations.
IR, codegen, and aliasing validation
tests/ut/codegen/..., tests/ut/debug/..., tests/ut/ir/...
Tests validate operand contracts, output types and valid shapes, emitted operand counts, debug expressions, and forbidden output aliases.
Documentation and status references
docs/en/..., docs/zh-cn/...
Operation references, MemoryReuse no-alias tables, test lists, and PTOAS status rows describe the updated behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant TileSelsWrapper
  participant IR
  participant PTOCodegen
  Caller->>TileSelsWrapper: call sels(mask, src, tmp, scalar)
  TileSelsWrapper->>IR: create tile.sels operation
  IR->>PTOCodegen: emit four-operand tsels
  PTOCodegen-->>Caller: generated operation
Loading

Possibly related PRs

Suggested labels: enhancement

Poem

I’m a rabbit with tiles in my paws,
Masked choices now follow new laws.
Scratch buffers stay neatly apart,
PReLU tests hop through each chart.
Four inputs march, three inputs play—
Docs and code bloom bright today!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly names the main feature addition: B02 TSELS and TPRELU support.
Description check ✅ Passed The description accurately summarizes the TSELS/TPRELU changes and validation, matching the pull request contents.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4d7e26ec8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/ir/op/tile_ops/elementwise.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
python/pypto/ir/utils.py (1)

331-345: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Silent float→int truncation when retype_constants=True on an integer operand.

With retyping enabled, a float literal paired with an integer tile no longer takes the float fallback, so _const_at_dtype runs int(value): sels(mask, int32_tile, tmp, -1.5) silently becomes -1. Previously this combination surfaced as a dtype mismatch. Consider rejecting non-integral floats on integer targets instead of truncating.

🛡️ Proposed guard
     if target.is_float() or target.is_int():
+        if target.is_int() and isinstance(value, float) and not float(value).is_integer():
+            raise ValueError(
+                f"Scalar {value} cannot be represented exactly in {target}; "
+                "use an integer literal or cast the operand."
+            )
         return _const_at_dtype(value, target, span)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/pypto/ir/utils.py` around lines 331 - 345, Update the constant-typing
logic before _const_at_dtype so retype_constants=True does not convert a
non-integral float to an integer target. Reject or preserve the existing
dtype-mismatch behavior for float values with fractional parts when
target.is_int(), while allowing integral floats and leaving other promotion
paths unchanged.
🧹 Nitpick comments (1)
src/ir/op/tile_ops/elementwise.cpp (1)

918-932: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Rows check uses physical extent while cols check uses valid extent.

required_rows is compared against tmp_type->shape_[0] but required_cols against tmp_valid_shape[1]. If that mixed contract is deliberate, a one-line comment would help; otherwise both should read from the same extent source. The literal 8 also duplicates the packed-predicate bits-per-byte constant used in MakePackedPredicateTileType; hoisting it to a file-scope constexpr would keep the two paths in sync.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ir/op/tile_ops/elementwise.cpp` around lines 918 - 932, The UINT8
validation in the surrounding elementwise operator uses inconsistent physical
versus valid extents and duplicates the packed-predicate bit-width literal.
Align the row and column checks to the intended extent contract, document the
choice if the difference is deliberate, and replace the literal 8 in
required_cols and MakePackedPredicateTileType with one shared file-scope
constexpr.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@python/pypto/ir/utils.py`:
- Around line 331-345: Update the constant-typing logic before _const_at_dtype
so retype_constants=True does not convert a non-integral float to an integer
target. Reject or preserve the existing dtype-mismatch behavior for float values
with fractional parts when target.is_int(), while allowing integral floats and
leaving other promotion paths unchanged.

---

Nitpick comments:
In `@src/ir/op/tile_ops/elementwise.cpp`:
- Around line 918-932: The UINT8 validation in the surrounding elementwise
operator uses inconsistent physical versus valid extents and duplicates the
packed-predicate bit-width literal. Align the row and column checks to the
intended extent contract, document the choice if the difference is deliberate,
and replace the literal 8 in required_cols and MakePackedPredicateTileType with
one shared file-scope constexpr.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 303255eb-bb59-47b7-830d-e72a1c4180c9

📥 Commits

Reviewing files that changed from the base of the PR and between 478ddad and a4d7e26.

📒 Files selected for processing (19)
  • docs/en/dev/passes/31-memory_reuse.md
  • docs/en/dev/ptoas-op-status.md
  • docs/en/user/02-operation_reference.md
  • docs/zh-cn/dev/passes/31-memory_reuse.md
  • docs/zh-cn/dev/ptoas-op-status.md
  • docs/zh-cn/user/02-operation_reference.md
  • python/pypto/debug/torch_codegen.py
  • python/pypto/ir/op/tile_ops.py
  • python/pypto/ir/utils.py
  • python/pypto/language/op/tile_ops.py
  • src/backend/common/pto_ops_elementwise.cpp
  • src/ir/op/tile_ops/elementwise.cpp
  • tests/st/runtime/ops/test_activation_ops.py
  • tests/st/runtime/ops/test_prelu.py
  • tests/st/runtime/ops/test_sels.py
  • tests/ut/codegen/test_pto_codegen_ops.py
  • tests/ut/debug/test_torch_codegen.py
  • tests/ut/ir/operators/test_tile_ops.py
  • tests/ut/ir/transforms/test_memory_reuse.py

@hashiqiqixian

Copy link
Copy Markdown
Contributor Author

Review follow-up: 9dceb8d also rejects non-integral floating constants before integer retyping. The PReLU scratch check intentionally uses physical rows (the extra hardware scratch row) and valid columns (usable packed-predicate bytes); the shared 8-bit packing constant and an explanatory comment now make that distinction explicit.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant