Skip to content

feat(codegen): validate remainder op family - #2186

Open
hashiqiqixian wants to merge 2 commits into
hw-native-sys:mainfrom
hashiqiqixian:feat/ptoas-b05-remainder
Open

feat(codegen): validate remainder op family#2186
hashiqiqixian wants to merge 2 commits into
hw-native-sys:mainfrom
hashiqiqixian:feat/ptoas-b05-remainder

Conversation

@hashiqiqixian

Copy link
Copy Markdown
Contributor

Summary

  • align tile.rem, tile.rems, tile.fmod, and tile.fmods with the current PTO-ISA dtype, shape, valid-region, scratch, layout, and aliasing contracts
  • emit the four canonical PTOAS ops with their exact tile-tile and tile-scalar signatures
  • add focused type/codegen/memory-reuse coverage and same-name runtime ST, and mark the A2/A3 hardware evidence in both status matrices

Validation

  • complete local diff review: passed
  • git diff --check: passed
  • Ruff check and format check for changed Python files: passed
  • serial CMake build and editable install on /data/chenshenai/test2: passed
  • focused UT: 56 passed
  • A2/A3 codegen-only with pass dumps and latest PTOAS assembly: 12 passed; generated .pto files contain exact pto.trem, pto.trems, pto.tfmod, and pto.tfmods ops
  • A2/A3 task-submit hardware, one precompile worker and one 12-case batch: 12/12 passed on device 1

A5 hardware validation remains pending and is documented in the status matrix.

@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: bec2b944-8c92-44c4-9ee1-2775e0d2a6db

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 remainder family now uses stricter dtype, shape, valid-region, scalar, and scratch-tile contracts. Backend layout and memory-reuse handling are updated, with added unit, codegen, runtime, and hardware-status coverage.

Changes

Remainder family

Layer / File(s) Summary
Remainder contracts and registrations
src/ir/op/..., python/pypto/ir/op/tile_ops.py
Tensor and tile remainder operators now enforce supported dtypes, matching shapes, valid regions, scalar types, and scratch-tile requirements.
Backend layout and non-alias enforcement
src/backend/common/pto_ops_elementwise.cpp, docs/.../31-memory_reuse.md, tests/ut/ir/transforms/test_memory_reuse.py
tile.rems requires row-major layout, and tile.rem/tile.rems are protected from unsafe buffer aliasing.
Operator and codegen validation
tests/ut/ir/operators/*, tests/ut/codegen/test_pto_codegen_ops.py
Tests cover invalid contracts and verify exact PTO operation names, operand arity, and output clauses.
Runtime coverage and status records
tests/st/runtime/ops/test_remainder.py, docs/*/dev/ptoas-op-status.md
Runtime tests cover the four remainder operations on A2/A3, and status matrices record the updated ST results.

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

Sequence Diagram(s)

sequenceDiagram
  participant TestRunner
  participant RemainderCase
  participant TileOps
  participant PTOCodegen
  participant A2A3Hardware
  TestRunner->>RemainderCase: create operation-specific case
  RemainderCase->>TileOps: build rem, rems, fmod, or fmods
  TileOps->>PTOCodegen: validate and lower remainder operation
  PTOCodegen->>A2A3Hardware: execute exact PTO instruction
  A2A3Hardware-->>TestRunner: return valid-region results
Loading

Possibly related PRs

Suggested labels: enhancement

Poem

I’m a rabbit with tiles in a row,
Matching shapes make remainder flows go.
No aliases hide in the hay,
Exact ops now hop on their way.
A2 and A3 pass with cheer—
While A5 waits another year!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.58% 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 summarizes the main change: validating the remainder op family.
Description check ✅ Passed The description is directly related to the remainder family validation, codegen, and test updates.
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: cb73445fff

ℹ️ 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.

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (2)
src/ir/op/tensor_ops/elementwise.cpp (1)

296-314: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale "floating-point remainder" description now that integer dtypes are supported.

DeduceTensorRemainderType/DeduceTensorScalarRemainderType route through IsRemainderDataType, which now accepts INT16, UINT16, INT32, UINT32 in addition to FP16/FP32. The tensor.fmod/tensor.fmods set_description(...) text still reads "floating-point remainder", which is misleading for the newly-supported integer paths. This mirrors the same drift in tile.fmods (src/ir/op/tile_ops/elementwise.cpp); tile.fmod's description was correctly updated to "truncating remainder" but the scalar variants and tensor level were missed.

🤖 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/tensor_ops/elementwise.cpp` around lines 296 - 314, Update the
set_description text for tensor.fmod and tensor.fmods to describe a truncating
remainder rather than a floating-point remainder, matching the integer-capable
behavior and the existing tile.fmod terminology.
src/ir/op/tile_ops/elementwise.cpp (1)

647-660: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale "floating-point remainder" description; see companion comment in src/ir/op/tensor_ops/elementwise.cpp.

tile.fmods now routes through DeduceTileScalarRemainderType, which accepts integer dtypes via IsRemainderDataType, but its set_description (line 649) is unchanged and still says "floating-point remainder" — inconsistent with the correctly-updated tile.fmod description right above it ("truncating remainder ... with matching dtype and shape").

🤖 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 647 - 660, Update the
set_description for the tile.fmods registration to describe a truncating
remainder with matching dtype and shape, consistent with tile.fmod and the
integer-capable DeduceTileScalarRemainderType behavior; leave the registration
and type-deduction logic unchanged.
🧹 Nitpick comments (1)
python/pypto/ir/op/tile_ops.py (1)

837-838: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Sync the pl.tile.* wrapper docstrings with the corrected IR contracts.

python/pypto/language/op/tile_ops.py still documents rem/rems tmp as a same-shape/temporary hardware tile, and fmod/fmods as “IEEE-style ... matching torch.fmod”. Update these wrappers to match the corrected docs/tests: describe the actual valid-row/valid-column tmp requirements for rem/rems, and describe fmod/fmods as truncating remainders matching torch.fmod with the dividend signing.

🤖 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/op/tile_ops.py` around lines 837 - 838, Update the pl.tile.*
wrapper docstrings in the rem/rems and fmod/fmods definitions: document tmp
using the actual valid-row and valid-column requirements from the corrected IR
contract, rather than same-shape or temporary-hardware wording, and describe
fmod/fmods as truncating remainders matching torch.fmod with dividend signing
instead of “IEEE-style.”
🤖 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.

Inline comments:
In `@src/ir/op/tile_ops/elementwise.cpp`:
- Around line 301-332: Update CheckRemainderTileContract’s physical-shape-rank
and valid-shape-rank CHECK messages to include the actual lhs and rhs rank
values, using the existing “but got X and Y” diagnostic pattern from sibling
contract checks. Leave the dimension-level validation and other checks
unchanged.

---

Outside diff comments:
In `@src/ir/op/tensor_ops/elementwise.cpp`:
- Around line 296-314: Update the set_description text for tensor.fmod and
tensor.fmods to describe a truncating remainder rather than a floating-point
remainder, matching the integer-capable behavior and the existing tile.fmod
terminology.

In `@src/ir/op/tile_ops/elementwise.cpp`:
- Around line 647-660: Update the set_description for the tile.fmods
registration to describe a truncating remainder with matching dtype and shape,
consistent with tile.fmod and the integer-capable DeduceTileScalarRemainderType
behavior; leave the registration and type-deduction logic unchanged.

---

Nitpick comments:
In `@python/pypto/ir/op/tile_ops.py`:
- Around line 837-838: Update the pl.tile.* wrapper docstrings in the rem/rems
and fmod/fmods definitions: document tmp using the actual valid-row and
valid-column requirements from the corrected IR contract, rather than same-shape
or temporary-hardware wording, and describe fmod/fmods as truncating remainders
matching torch.fmod with dividend signing instead of “IEEE-style.”
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 50b28204-992c-4a29-8780-89970407f51c

📥 Commits

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

📒 Files selected for processing (14)
  • docs/en/dev/passes/31-memory_reuse.md
  • docs/en/dev/ptoas-op-status.md
  • docs/zh-cn/dev/passes/31-memory_reuse.md
  • docs/zh-cn/dev/ptoas-op-status.md
  • python/pypto/ir/op/tile_ops.py
  • src/backend/common/pto_ops_elementwise.cpp
  • src/ir/op/tensor_ops/elementwise.cpp
  • src/ir/op/tile_ops/elementwise.cpp
  • tests/st/runtime/ops/test_bitwise.py
  • tests/st/runtime/ops/test_remainder.py
  • tests/ut/codegen/test_pto_codegen_ops.py
  • tests/ut/ir/operators/test_tensor_ops.py
  • tests/ut/ir/operators/test_tile_ops.py
  • tests/ut/ir/transforms/test_memory_reuse.py

Comment thread src/ir/op/tile_ops/elementwise.cpp
@hashiqiqixian
hashiqiqixian force-pushed the feat/ptoas-b05-remainder branch from 7b1300d to ff882cf Compare July 29, 2026 03:05
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