Skip to content

[DT] Implement LayoutMaterializerAttr for identity resolver. - #22337

Merged
hanhanW merged 4 commits into
iree-org:mainfrom
hanhanW:identity-resolver
Oct 21, 2025
Merged

hanhanW merged 4 commits into
iree-org:mainfrom
hanhanW:identity-resolver

Conversation

@hanhanW

@hanhanW hanhanW commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

The identity resolver is one of the basic encoding resolvers that drops encodings. The revision implements the interface and retires the IREE::Codegen::EncodingNopLayoutAttr.

Fixes #20846

Comment on lines -49 to -51
if (!type.doesSliceSpanWholeTensor(dynamicDims, offsets, sizes, strides)) {
return failure();
}

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.

I don't see how we can drop this check? If this is not checked, the below implementation is incorrect?

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.

By the definition of the attribute, it does not transform any dimension, so we can safely use the same offsets/sizes/strides. However, I failed to add a test because we still have such checks in load/store ops lowering. The patterns already deny partial load/store, so we don't really need the check.

// Only handle operations where the load covers the entire
// `!iree_tensor_ext.dispatch.tensor` type.
// TODO(ravishankarm): Relax this for partial loads.
if (!loadOp.isLoadOfWholeSource()) {
return rewriter.notifyMatchFailure(loadOp, "unhandled partial loads");
}

// Only handle operations where the store covers the entire
// `!iree_tensor_ext.dispatch.tensor` type.
// TODO(ravishankarm): Relax this for partial stores.
if (!storeOp.isStoreToWholeTarget()) {
return rewriter.notifyMatchFailure(storeOp, "unhandled partial stores");
}

I think the check is required for data-tiling, but not identity resolver and maybe padding resolver.

The partial slice check should belong to interface implementation, IMO. I want to move the checks to data-tiling resolvers in a follow-up; then we can add the tests.

I can add the check back for now, if it makes you more comfortable. My point is that the definition allows the change. Both look okay to me, as the patterns already have the check.

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.

The patterns already deny partial load/store, so we don't really need the check.

The materialization patterns do, but those are users of these interface functions, and I think it's generally more robust to put the check in the implementations themselves. From the definition of this interface method, it is possible to provide a slice through offsets, sizes and strides and by removing this check, we actually disregard those parameters and pretend it's always a whole tensor slice :

Returns success if materialized newOffsets, newSizes and
newStrides can be calculated and set for the slice specified by
offsets, sizes and strides on the dispatch tensor type with
potential dynamicDims sizes.

The partial slice check should belong to interface implementation, IMO.

This is the implementation for the IdentityResolverAttr of the getOffsetSizesStrides interface method right? So, I think the check belongs here. If we remove them anywhere (which wouldn't even advocate), it should be in the users (materialization patterns in this case).

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.

I think we all agree that the check belongs to interface implementations, and my point is that it can be dropped naturally based on the resolver definition. So let me add the check back, as I can't add a test now. I'll do it in a follow-up that moves the check from patterns to implementation, drop the check and add the test.

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.

The implementation is done in #22360

@hanhanW
hanhanW requested a review from jtuyls October 20, 2025 23:53

@Max191 Max191 left a comment

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 about the title: Maybe [DT] Implement LayoutMaterializerAttr for identity resolver instead?

Also, do we have e2e tests for the identity layout encodings (or lit tests)?

@hanhanW hanhanW changed the title [DT] Implement encoding interfaces for identity resolver. [DT] Implement LayoutMaterializerAttr for identity resolver. Oct 21, 2025

@jtuyls jtuyls left a comment

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.

LGTM

@hanhanW

hanhanW commented Oct 21, 2025

Copy link
Copy Markdown
Contributor Author

nit about the title: Maybe [DT] Implement LayoutMaterializerAttr for identity resolver instead?

Also, do we have e2e tests for the identity layout encodings (or lit tests)?

I forgot to answer the question. Yes, we have lit tests in specialize_encodings.mlir, materialize_encoding_into_nop.mlir and a new test case in materialize_encoding_for_iree_ops.mlir.

We also have e2e tests in vulkan, cuda and any backend that don't support data-tiling, because the default is using the resolver to drop the encodings.

It will need further setup to expose the identity resolver option to data-tiling, but it violates the purpose of using data-tiling: if you don't want it, please don't enable it.

@hanhanW
hanhanW merged commit 3815582 into iree-org:main Oct 21, 2025
@hanhanW
hanhanW deleted the identity-resolver branch October 21, 2025 17:12
pstarkcdpr pushed a commit to pstarkcdpr/iree that referenced this pull request Nov 28, 2025
…g#22337)

The identity resolver is one of the basic encoding resolvers that drops
encodings. The revision implements the interface and retires the
IREE::Codegen::EncodingNopLayoutAttr.

Fixes iree-org#20846

---------

Signed-off-by: hanhanW <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Encoding] Revisit the need of EncodingNopLayout resolver

3 participants