Skip to content

[LinalgExt] Add padding attributes to im2col op#23950

Open
Max191 wants to merge 1 commit intomainfrom
users/Max191/im2col-padding
Open

[LinalgExt] Add padding attributes to im2col op#23950
Max191 wants to merge 1 commit intomainfrom
users/Max191/im2col-padding

Conversation

@Max191
Copy link
Copy Markdown
Contributor

@Max191 Max191 commented Mar 27, 2026

Add optional padding fields to the im2col op:

  • input_pad_low/high: per-input-dimension padding amounts
  • output_pad_low/high: per-output-dimension padding amounts
  • pad_value: the value for out-of-bounds positions

This includes:

This change is effectively non-functional, since we do not yet make use of the padding attributes. The follow-up PR will introduce canonicalizers that fold padding into im2col, which will enable the padding path.

Add optional padding fields to the im2col op:
- input_pad_low/high: per-input-dimension padding amounts
- output_pad_low/high: per-output-dimension padding amounts
- pad_value: the value for out-of-bounds positions

This includes:
- Op definition with custom printer/parser for optional padding
- Padding accessors, setters, and verifier checks
- Output padding propagation in the tiling interface
- Decomposition bail-out for padded im2col ops (full padding
  support via direct vectorization comes in a follow-up)
- Roundtrip, verifier, and tiling tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
@Max191 Max191 force-pushed the users/Max191/im2col-padding branch from d2a2c6a to 8566950 Compare March 27, 2026 20:24
Copy link
Copy Markdown
Contributor

@hanhanW hanhanW left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment on lines +2459 to +2468
void Im2colOp::build(
OpBuilder &builder, OperationState &state, Value input, Value output,
ArrayRef<int64_t> strides, ArrayRef<int64_t> dilations,
ArrayRef<OpFoldResult> kernelSize, ArrayRef<OpFoldResult> offsets,
ArrayRef<SmallVector<OpFoldResult>> outputSizes, ArrayRef<int64_t> batchPos,
ArrayRef<int64_t> mPos, ArrayRef<int64_t> kPos,
ArrayRef<int64_t> inputKPerm, ArrayRef<int64_t> outputPerm,
ArrayRef<OpFoldResult> inputPadLow, ArrayRef<OpFoldResult> inputPadHigh,
ArrayRef<OpFoldResult> outputPadLow, ArrayRef<OpFoldResult> outputPadHigh,
Value padValue) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks scary. 😱

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And this is after I've already consolidated some of the fields in a recent PR :p

Copy link
Copy Markdown
Contributor

@yzhang93 yzhang93 left a comment

Choose a reason for hiding this comment

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

LGTM! Just minor comments.

// -----

// Verify output_pad_low/output_pad_high roundtrip with input padding.
func.func @im2col_output_padding(%arg0: tensor<2x34x34x640xf32>) -> tensor<2x1040x5760xf32> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: These test names are not accurate. The first one should be im2col_input_padding, and the second should be im2col_input_output_padding

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.

3 participants