Skip to content

feat(ir): Add pad field to TensorView and tensor.slice pad_value kwarg#1136

Merged
lyfne123 merged 2 commits intohw-native-sys:mainfrom
Hzfengsy:tensor-view-pad
Apr 23, 2026
Merged

feat(ir): Add pad field to TensorView and tensor.slice pad_value kwarg#1136
lyfne123 merged 2 commits intohw-native-sys:mainfrom
Hzfengsy:tensor-view-pad

Conversation

@Hzfengsy
Copy link
Copy Markdown
Member

Summary

Third and final PR of the slice+fillpad unification series (follows #1129). Mirrors the tile-layer change at the tensor layer so TensorView::pad and tensor.slice(..., pad_value=...) become peers of the existing TileView::pad / tile.slice(..., pad_value=...).

  • TensorView::pad: new PadValue field, default PadValue::null. Peer of the existing TileView::pad, same enum and same encoding everywhere.
  • tensor.slice accepts pad_value: writes the kwarg into the output TensorView::pad. Validation block matches tile.slice exactly (same error wording).
  • Python layers: IR-op wrapper forwards the kwarg, DSL pl.tensor.slice adds a pad_value param and emits UserWarning when pad_value is set without valid_shape (same message template as pl.tile.slice).
  • Conversion: convert_tensor_to_tile_ops_pass forwards pad_value through tensor.slice → tile.slice. The tensor.slice → tile.load path leaves the kwarg dropped (tile.load doesn't carry pad_value); noted inline.
  • Type-system plumbing: serializer / deserializer (backward-compatible — pre-existing files missing pad default to null), Python printer, structural_equal, and the simplify / convert_to_ssa / RemapTensorViewExprs type-remap paths all preserve the new field.
  • Cross-layer sync: C++ header → nanobind binding → ir.pyi stub → _TensorViewMeta.__call__ metaclass wrapper. PadValue enum moved above both TensorView and TileView since both now carry it.

No changes to tile.fillpad, tensor.fillpad, fillpad_inplace, set_validshape, or any codegen path — backend already handles the merged form. FuseFillpadIntoSlice (PR 2 of the series) is not in this PR.

Testing

  • New unit tests added:
    • test_tensor_ops.py: test_tensor_slice_with_pad_value, test_tensor_slice_default_pad_is_null, test_tensor_slice_rejects_bad_pad_value, test_tensor_slice_accepts_numeric_sugar_pad_value, test_tensor_slice_pad_without_valid_shape_warns
    • test_op_registry.py: test_tensor_slice_pad_value_kwarg_schema
    • test_convert_tensor_to_tile_ops.py: test_local_tensor_slice_with_pad_value_forwards_to_tile_slice
    • test_serialization.py: test_tensortype_tensorview_pad_survives_round_trip
  • Full regression clean: python -m pytest tests/ut/ -n auto --maxprocesses 8 → 4023 passed, 17 skipped
  • Backward compat: existing tensor.slice() without pad_value still produces the original TensorType (no tensor_view when neither valid_shape nor pad_value is set)
  • Serialized files predating this PR deserialize to pad = PadValue::null
  • EN + zh-cn IR type docs updated

Related

Follows #1129 (tile-layer pad_value kwarg on tile.slice).

Mirrors the tile-layer change from hw-native-sys#1129: TensorView gains a PadValue
pad field (default PadValue::null), and tensor.slice accepts a
pad_value kwarg that is written into the output TensorView::pad. DSL
wrapper warns when pad_value is set without valid_shape.

convert_tensor_to_tile_ops_pass forwards the kwarg so tensor.slice
with pad lowers cleanly to tile.slice with pad (supported since hw-native-sys#1129).
Serializer, deserializer, printer, structural_equal, and simplify/SSA
type-remap all handle the new field; old serialized files without
the field deserialize to null (backward compatible).
Copilot AI review requested due to automatic review settings April 23, 2026 03:11
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6e16168a-3935-42c5-957d-8c94ddd1355e

📥 Commits

Reviewing files that changed from the base of the PR and between f8e731e and 652ddcb.

📒 Files selected for processing (2)
  • include/pypto/ir/type.h
  • python/bindings/modules/ir.cpp

📝 Walkthrough

Walkthrough

Adds a PadValue enum-backed pad field to TensorView and propagates it through type definitions, constructors, Python bindings, ops (tensor.slice), serialization, transforms, printers, utilities, and tests to control out-of-bounds padding behavior.

Changes

Cohort / File(s) Summary
Core Types
include/pypto/ir/type.h, src/ir/type.cpp
Introduce shared enum class PadValue { null, zero, max, min }; add PadValue pad to TensorView and update constructors to accept pad.
Serialization
src/ir/serialization/serializer.cpp, src/ir/serialization/deserializer.cpp
Serialize/deserialize TensorView.pad as string enum (`"null"
Type Deduction & Ops (C++)
src/ir/op/tensor_ops/memory.cpp, src/ir/transforms/op_conversion_registry.cpp
DeduceTensorSliceType and op conversion parse/validate optional pad_value kwarg and include/forward it when constructing TensorView or emitting tile.slice.
Transforms & Utilities
src/ir/transforms/convert_to_ssa_pass.cpp, src/ir/transforms/simplify_pass.cpp, src/ir/transforms/structural_equal.cpp, include/pypto/ir/transforms/utils/memref_utils.h
Preserve TensorView.pad during SSA/type substitutions, simplification, structural equality checks, and remapping utilities.
Python Bindings & Runtime
python/bindings/modules/ir.cpp, python/pypto/ir/type.py, python/pypto/ir/op/tensor_ops.py, python/pypto/language/op/tensor_ops.py
Export PadValue earlier; extend TensorView bindings/constructors and add pad prop; accept/forward pad_value in Python tensor.slice wrappers with normalization and DSL-level warning when ineffective.
Stubs & Type Hints
python/pypto/pypto_core/ir.pyi
Add TensorView.pad: PadValue and update constructor overload signatures to include optional pad.
Python Printer
src/ir/transforms/python_printer.cpp
Treat non-null pad as non-trivial and emit pad=pl.PadValue.<...> in printed TensorView constructors for round-trip fidelity.
Docs
docs/en/dev/ir/02-types.md, docs/zh-cn/dev/ir/02-types.md
Document TensorView.pad behavior, list supported PadValue options, and add examples (including pad=PadValue.zero).
Tests
tests/ut/ir/operators/test_tensor_ops.py, tests/ut/ir/operators/test_op_registry.py, tests/ut/ir/transforms/test_serialization.py, tests/ut/ir/transforms/test_convert_tensor_to_tile_ops.py
Add tests for tensor.slice pad_value kwarg schema, normalization of numeric sugar, DSL warning when valid_shape absent, serialization round-trip for pad, and lowering to tile.slice with forwarded pad_value.
Minor API Adjustment
include/pypto/ir/transforms/utils/memref_utils.h
RemapTensorViewExprs updated to preserve original TensorView.pad when remapping expressions.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(200,200,255,0.5)
    participant Client as Tensor DSL
    end
    rect rgba(200,255,200,0.5)
    participant SliceOp as tensor.slice
    participant PythonWrapper as python wrapper
    end
    rect rgba(255,200,200,0.5)
    participant TypeDeduce as DeduceTensorSliceType
    participant TensorView as TensorView/TensorType
    end
    rect rgba(240,240,160,0.5)
    participant Serializer as Serialization
    end

    Client->>PythonWrapper: call slice(..., valid_shape?, pad_value?)
    PythonWrapper->>SliceOp: normalize pad_value (numeric sugar) and forward kwarg
    SliceOp->>TypeDeduce: forward pad_value in kwargs
    TypeDeduce->>TypeDeduce: validate pad_value ∈ {null,zero,max,min}
    TypeDeduce->>TensorView: construct TensorView(..., valid_shape?, pad=pad_value)
    TensorView-->>TypeDeduce: return TensorType with pad
    TypeDeduce-->>SliceOp: typed result
    Client->>Serializer: serialize IR (includes TensorView.pad)
    Serializer->>Serializer: encode pad as string enum
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • lyfne123

"I nibble bytes and bounce with glee,
A pad for tensors — null, zero, max, or min, you see!
I hop through slices, bindings, tests in a run,
Preserving pads so out-of-bounds plays are done. 🐇✨"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.79% 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 accurately and concisely summarizes the main changes: adding a pad field to TensorView and a pad_value kwarg to tensor.slice, which are the primary objectives of the PR.
Description check ✅ Passed The description comprehensively explains the PR's purpose, changes across multiple layers (C++, Python, DSL), testing, and backward compatibility, all directly related to the changeset.
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.

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


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 and usage tips.

Copy link
Copy Markdown
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 PadValue support to TensorView, enabling the tensor.slice operation to handle padding for out-of-valid-region accesses. The implementation updates the C++ IR core, Python bindings, serialization logic, and various IR transformation passes to ensure padding modes are correctly preserved and utilized. Feedback focuses on resolving a NameError in the Python DSL due to a missing import, correcting a misleading documentation comment in the C++ header, and adding runtime assertions to enum switch statements to ensure robustness and consistency with project safety standards.

Comment thread python/pypto/language/op/tensor_ops.py
Comment thread include/pypto/ir/type.h Outdated
Comment thread src/ir/serialization/serializer.cpp
Comment thread src/ir/transforms/python_printer.cpp
Copy link
Copy Markdown

@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.

Caution

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

⚠️ Outside diff range comments (3)
src/ir/serialization/serializer.cpp (1)

343-378: ⚠️ Potential issue | 🟠 Major

Round-trip TensorView::valid_shape with the new pad payload.

SerializeTensorView now emits pad, but the same TensorView payload still omits valid_shape. A tensor.slice(..., valid_shape=..., pad_value=...) can round-trip with pad preserved but an empty valid_shape, changing fill/padding bounds semantics.

Proposed fix
   msgpack::object SerializeTensorView(const std::optional<TensorView>& tensor_view, msgpack::zone& zone) {
     if (!tensor_view.has_value()) {
       return msgpack::object();  // null
     }
 
     std::map<std::string, msgpack::object> tv_map;
 
     // Serialize stride
     std::vector<msgpack::object> stride_vec;
     for (const auto& dim : tensor_view->stride) {
       stride_vec.push_back(SerializeNode(dim, zone));
     }
     tv_map["stride"] = msgpack::object(stride_vec, zone);
+
+    // Serialize valid_shape
+    std::vector<msgpack::object> valid_shape_vec;
+    for (const auto& dim : tensor_view->valid_shape) {
+      valid_shape_vec.push_back(SerializeNode(dim, zone));
+    }
+    tv_map["valid_shape"] = msgpack::object(valid_shape_vec, zone);
 
     // Serialize layout enum
     tv_map["layout"] = msgpack::object(TensorLayoutToString(tensor_view->layout), zone);

Companion deserializer update:

       if (key == "stride") {
         if (p->val.type == msgpack::type::ARRAY) {
           for (uint32_t i = 0; i < p->val.via.array.size; ++i) {
             tensor_view.stride.push_back(
                 std::static_pointer_cast<const Expr>(DeserializeNode(p->val.via.array.ptr[i], zone)));
           }
         }
+      } else if (key == "valid_shape") {
+        if (p->val.type == msgpack::type::ARRAY) {
+          for (uint32_t i = 0; i < p->val.via.array.size; ++i) {
+            tensor_view.valid_shape.push_back(
+                std::static_pointer_cast<const Expr>(DeserializeNode(p->val.via.array.ptr[i], zone)));
+          }
+        }
       } else if (key == "layout") {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ir/serialization/serializer.cpp` around lines 343 - 378,
SerializeTensorView currently writes "pad" but omits TensorView::valid_shape, so
valid_shape is lost on round-trip; update SerializeTensorView to also emit a
"valid_shape" entry by serializing each dimension similar to how "stride" is
handled (use SerializeNode on each element of tensor_view->valid_shape and place
the resulting vector into tv_map["valid_shape"]), and ensure the deserializer
(e.g., DeserializeTensorView or the corresponding parsing routine) is updated to
read "valid_shape" when present to fully restore TensorView state.
src/ir/op/tensor_ops/memory.cpp (1)

202-229: ⚠️ Potential issue | 🟡 Minor

Consider documenting or reconciling the asymmetry between tensor.slice and tile.slice regarding view creation.

When pad_value != null but no 4th valid_shape argument is supplied (lines 224–228), tensor.slice produces a TensorType with a TensorView carrying only pad (empty valid_shape, ND layout). However, tile.slice always creates a view (regardless of pad_value or valid_shape presence), making the two ops diverge in their view-creation logic. The DSL-level UserWarning notes "pad_value has no effect" without valid_shape, but the IR still materializes a view that downstream if tensor_view.has_value() checks will pick up—differing from the no-pad/no-valid_shape path (line 229), which returns a view-less type.

If this intentional deviation from tile.slice is by design, add a comment clarifying why. Otherwise, dropping the tensor_view_ when valid_shape is empty would keep the view-presence invariant consistent with the DSL warning.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ir/op/tensor_ops/memory.cpp` around lines 202 - 229, The code creates a
TensorView when pad_value != PadValue::null even if no valid_shape (4th arg) was
supplied, which makes tensor.slice return a type-with-view in that case
(contradicting the DSL warning and diverging from tile.slice); change the logic
so that if no valid_shape is provided you do not construct a TensorView just
because pad_value is set — return std::make_shared<TensorType>(new_shape,
tensor_type->dtype_) (i.e., no tensor_view) when args.size() != 4 and pad_value
!= PadValue::null; update or add a short comment near the TensorView
creation/return explaining that pad_value alone does not create a view to
preserve the invariant checked by tensor_view.has_value().
include/pypto/ir/type.h (1)

156-224: ⚠️ Potential issue | 🟡 Minor

Backward compatibility for missing pad field is correctly implemented, but test coverage needs expansion.

PadValue hoisting and TensorView::pad addition are clean. Enum is now shared by both TensorView and TileView; new constructor params default to PadValue::null (ABI-compatible); reflection descriptor is updated.

The deserializer at src/ir/serialization/deserializer.cpp:310 explicitly handles omitted pad fields ("Older serialized IR may omit "pad"; default stays PadValue::null."). The manual field-by-field deserialization in DeserializeTensorView() gracefully skips missing fields, retaining the default.

However, the test at tests/ut/ir/transforms/test_serialization.py:769 only round-trips freshly-constructed objects, not actual pre-existing serialized payloads. To fully verify backward compatibility, add a fixture containing a pre-PR TensorView serialization (without the pad field) and deserialize it to confirm it loads correctly with pad defaulting to null.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/pypto/ir/type.h` around lines 156 - 224, The existing tests only
round-trip new TensorView objects, so they don't verify backward compatibility
for omitted pad; add a unit test fixture containing a pre-change serialized
TensorView blob that lacks the "pad" field, then in the test call the
deserializer (DeserializeTensorView) to load that blob and assert the resulting
TensorView.pad equals PadValue::null; update
tests/ut/ir/transforms/test_serialization.py to load the fixture, deserialize,
and assert pad defaulting, keeping existing round-trip checks unchanged.
🧹 Nitpick comments (1)
python/bindings/modules/ir.cpp (1)

294-300: Make the PadValue docstring view-neutral.

PadValue now applies to both TensorView and TileView, so the Python binding help text should not call it tile-only.

Proposed wording tweak
-  nb::enum_<PadValue>(ir, "PadValue", "Tile pad mode enumeration")
+  nb::enum_<PadValue>(ir, "PadValue", "Pad mode enumeration for tensor and tile views")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@python/bindings/modules/ir.cpp` around lines 294 - 300, Update the PadValue
enum docstring to be view-neutral: change the nb::enum_<PadValue>(ir,
"PadValue", "Tile pad mode enumeration") description to a neutral phrase (e.g.,
"Padding mode enumeration used by TensorView and TileView" or simply "Padding
mode enumeration") so the Python help text no longer implies it's tile-only;
this affects the PadValue declaration associated with TensorView and TileView in
ir.cpp.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@include/pypto/ir/type.h`:
- Around line 156-224: The existing tests only round-trip new TensorView
objects, so they don't verify backward compatibility for omitted pad; add a unit
test fixture containing a pre-change serialized TensorView blob that lacks the
"pad" field, then in the test call the deserializer (DeserializeTensorView) to
load that blob and assert the resulting TensorView.pad equals PadValue::null;
update tests/ut/ir/transforms/test_serialization.py to load the fixture,
deserialize, and assert pad defaulting, keeping existing round-trip checks
unchanged.

In `@src/ir/op/tensor_ops/memory.cpp`:
- Around line 202-229: The code creates a TensorView when pad_value !=
PadValue::null even if no valid_shape (4th arg) was supplied, which makes
tensor.slice return a type-with-view in that case (contradicting the DSL warning
and diverging from tile.slice); change the logic so that if no valid_shape is
provided you do not construct a TensorView just because pad_value is set —
return std::make_shared<TensorType>(new_shape, tensor_type->dtype_) (i.e., no
tensor_view) when args.size() != 4 and pad_value != PadValue::null; update or
add a short comment near the TensorView creation/return explaining that
pad_value alone does not create a view to preserve the invariant checked by
tensor_view.has_value().

In `@src/ir/serialization/serializer.cpp`:
- Around line 343-378: SerializeTensorView currently writes "pad" but omits
TensorView::valid_shape, so valid_shape is lost on round-trip; update
SerializeTensorView to also emit a "valid_shape" entry by serializing each
dimension similar to how "stride" is handled (use SerializeNode on each element
of tensor_view->valid_shape and place the resulting vector into
tv_map["valid_shape"]), and ensure the deserializer (e.g., DeserializeTensorView
or the corresponding parsing routine) is updated to read "valid_shape" when
present to fully restore TensorView state.

---

Nitpick comments:
In `@python/bindings/modules/ir.cpp`:
- Around line 294-300: Update the PadValue enum docstring to be view-neutral:
change the nb::enum_<PadValue>(ir, "PadValue", "Tile pad mode enumeration")
description to a neutral phrase (e.g., "Padding mode enumeration used by
TensorView and TileView" or simply "Padding mode enumeration") so the Python
help text no longer implies it's tile-only; this affects the PadValue
declaration associated with TensorView and TileView in ir.cpp.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 87089395-448a-47a5-906c-b7ccca4ba9a9

📥 Commits

Reviewing files that changed from the base of the PR and between a0d21d1 and f8e731e.

📒 Files selected for processing (22)
  • docs/en/dev/ir/02-types.md
  • docs/zh-cn/dev/ir/02-types.md
  • include/pypto/ir/transforms/utils/memref_utils.h
  • include/pypto/ir/type.h
  • python/bindings/modules/ir.cpp
  • python/pypto/ir/op/tensor_ops.py
  • python/pypto/ir/type.py
  • python/pypto/language/op/tensor_ops.py
  • python/pypto/pypto_core/ir.pyi
  • src/ir/op/tensor_ops/memory.cpp
  • src/ir/serialization/deserializer.cpp
  • src/ir/serialization/serializer.cpp
  • src/ir/transforms/convert_to_ssa_pass.cpp
  • src/ir/transforms/op_conversion_registry.cpp
  • src/ir/transforms/python_printer.cpp
  • src/ir/transforms/simplify_pass.cpp
  • src/ir/transforms/structural_equal.cpp
  • src/ir/type.cpp
  • tests/ut/ir/operators/test_op_registry.py
  • tests/ut/ir/operators/test_tensor_ops.py
  • tests/ut/ir/transforms/test_convert_tensor_to_tile_ops.py
  • tests/ut/ir/transforms/test_serialization.py

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds tensor-layer parity with the existing tile-layer padding semantics by introducing TensorView::pad and a pad_value kwarg on tensor.slice, then wires the new field through serialization, printing, equality, remap/transforms, Python bindings/stubs, and conversion to tile ops.

Changes:

  • Add PadValue pad to TensorView (default null) and plumb it through C++/Python type APIs, printer, serializer/deserializer, and structural equality.
  • Extend tensor.slice(..., pad_value=...) across C++ op registration/deduction, Python IR op wrapper, and DSL wrapper (including warning behavior).
  • Add unit tests and update EN/zh-cn IR type docs for the new field and kwarg.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/ut/ir/transforms/test_serialization.py Adds round-trip coverage for TensorView.pad in serialization.
tests/ut/ir/transforms/test_convert_tensor_to_tile_ops.py Tests pad_value forwarding on the local-lowering path (tensor.slicetile.slice).
tests/ut/ir/operators/test_tensor_ops.py Adds tensor.slice pad_value behavior, defaults, validation, numeric sugar, and DSL warning tests.
tests/ut/ir/operators/test_op_registry.py Verifies tensor.slice kwarg schema includes pad_value.
src/ir/type.cpp Updates TensorView int-ctor to accept/initialize pad.
src/ir/transforms/structural_equal.cpp Compares TensorView.pad during type structural equality.
src/ir/transforms/simplify_pass.cpp Preserves TensorView.pad when rebuilding simplified views.
src/ir/transforms/python_printer.cpp Prints TensorView(pad=...) when non-null; skips view when all defaults.
src/ir/transforms/op_conversion_registry.cpp Forwards pad_value on tensor.slicetile.slice conversions; notes drop on tile.load path.
src/ir/transforms/convert_to_ssa_pass.cpp Preserves TensorView.pad when rebuilding SSA-substituted views.
src/ir/serialization/serializer.cpp Serializes TensorView.pad using the same string encoding as TileView.pad.
src/ir/serialization/deserializer.cpp Deserializes TensorView.pad with backward-compatible defaulting to null.
src/ir/op/tensor_ops/memory.cpp Adds pad_value kwarg handling to tensor.slice type deduction and registers the attr.
python/pypto/pypto_core/ir.pyi Updates TensorView stub to include pad field/constructor arg.
python/pypto/language/op/tensor_ops.py Adds DSL pl.tensor.slice(..., pad_value=...) param and warning when valid_shape is absent.
python/pypto/ir/type.py Updates _TensorViewMeta.__call__ to accept/forward pad and treat all-default as empty view.
python/pypto/ir/op/tensor_ops.py Adds IR wrapper pad_value kwarg support with shared normalization.
python/bindings/modules/ir.cpp Moves/binds PadValue before TensorView and adds TensorView.pad bindings/ctors.
include/pypto/ir/type.h Introduces PadValue earlier and adds TensorView::pad + reflection descriptor.
include/pypto/ir/transforms/utils/memref_utils.h Preserves TensorView.pad in RemapTensorViewExprs.
docs/zh-cn/dev/ir/02-types.md Documents TensorView.pad and tensor.slice(..., pad_value=...) in zh-cn types doc.
docs/en/dev/ir/02-types.md Documents TensorView.pad and tensor.slice(..., pad_value=...) in EN types doc.
Comments suppressed due to low confidence (1)

src/ir/transforms/op_conversion_registry.cpp:239

  • In the TensorType path of the tensor.slice conversion, the implementation returns a tile.load call without propagating pad_value anywhere. This means tensor.slice(..., pad_value=...) semantics are silently dropped for global tensors (while being preserved for local TileType inputs), which can lead to incorrect behavior downstream. Consider preserving the metadata by attaching pad_value to the result (e.g., via an additional view op) or explicitly rejecting/diagnosing pad_value on this lowering path until tile.load can carry it.
          std::vector<std::pair<std::string, std::any>> load_kwargs = {{"target_memory", MemorySpace::Vec},
                                                                       {"transpose", false}};
          auto load_call =
              op_reg.Create("tile.load", {input, offset, shape, valid_shapes}, load_kwargs, span);
          return ConversionResult{load_call};

Comment thread python/bindings/modules/ir.cpp Outdated
Comment thread include/pypto/ir/type.h Outdated
…#1136

- Clarify TensorView::pad comment: "accesses outside valid_shape but
  within shape" instead of the misleading "inside valid_shape".
- Rename PadValue Doxygen brief from "Tile pad enumeration" to
  "Pad mode enumeration (shared by TileView and TensorView)".
- Update the PadValue nanobind docstring to reflect the same shared
  usage across tile and tensor views.

No functional changes.
@lyfne123 lyfne123 merged commit dc119fb into hw-native-sys:main Apr 23, 2026
8 checks passed
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.

3 participants