Skip to content

[TensorExt][NFC] Remove dependency on Encoding through ExternalModel - #20612

Merged
jtuyls merged 1 commit into
iree-org:mainfrom
jtuyls:encoding-type-external-model
Apr 23, 2025
Merged

jtuyls merged 1 commit into
iree-org:mainfrom
jtuyls:encoding-type-external-model

Conversation

@jtuyls

@jtuyls jtuyls commented Apr 23, 2025

Copy link
Copy Markdown
Contributor

There is no strong dependency of DispatchTensorType on the Encoding dialect as the encoding can be just any attribute and is optional, so I don't think there's a need to have the TensorExt dialect explicitly depend on the Encoding just for the interface. Decoupling them would avoid potential circular dependency issues (I ran into that while working on #20160 (comment)), remove the need for other (potential) users of the TensorExt dialect to use the encoding and allow users to bring their own encoding interfaces while avoiding having to bring in the Encoding dialect.

@jtuyls
jtuyls requested a review from hanhanW April 23, 2025 10:43
@jtuyls
jtuyls requested a review from benvanik as a code owner April 23, 2025 10:43
@jtuyls
jtuyls force-pushed the encoding-type-external-model branch from ea31bb9 to 7c78a13 Compare April 23, 2025 10:44
Comment on lines +44 to +63
//===----------------------------------------------------------------------===//
// Type Interfaces
//===----------------------------------------------------------------------===//

struct EncodingTypeExternalModel
: public IREE::Encoding::EncodingTypeInterface::ExternalModel<
EncodingTypeExternalModel, IREE::TensorExt::DispatchTensorType> {

Type getEncodingType(Type type) const {
auto dispatchTensorType = cast<IREE::TensorExt::DispatchTensorType>(type);
return dispatchTensorType.getBoundType();
}

Type updateEncoding(Type type, Attribute encoding) const {
auto dispatchTensorType = cast<IREE::TensorExt::DispatchTensorType>(type);
return IREE::TensorExt::DispatchTensorType::get(
dispatchTensorType.getAccess(), dispatchTensorType.getShape(),
dispatchTensorType.getBoundElementType(), encoding);
}
};

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 feel that this should be implemented in EncodingExternalModels.cpp after I looked at other files, because the interface is defined in Encoding dialect. E.g., StreamExternalModels.cpp has all the implementation from other dialects for Stream interfaces.

@pashu123 is adding the file in #20567, and I think you can go ahead to create the file. The conflicts should be easy to fix, so you don't need to wait for each other.

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 don't think it's that consistent as other ExternalModels files seem to do it the other way around:

That way, you can keep track of all the interfaces attached to for example HAL ops/attributes and types in a single file instead of having them spread across different files, which is preferable imo as it makes it easier to look up and maintain the interfaces of ops. This is also more closely resembles the 'normal' way ops implement interfaces directly as the ops would reference the interface they implement and it's not the interfaces that reference the ops that should implement the interface.

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.

Yes, I see your point and I like the idea that it is easier to look up and maintain the interfaces for the ops.

@jtuyls
jtuyls merged commit 89da9fc into iree-org:main Apr 23, 2025
@jtuyls
jtuyls deleted the encoding-type-external-model branch April 23, 2025 21:52
KyleHerndon pushed a commit to KyleHerndon/iree that referenced this pull request May 7, 2025
…ree-org#20612)

There is no strong dependency of `DispatchTensorType` on the Encoding
dialect as the encoding can be just any attribute and is optional, so I
don't think there's a need to have the TensorExt dialect explicitly
depend on the Encoding just for the interface. Decoupling them would
avoid potential circular dependency issues (I ran into that while
working on
iree-org#20160 (comment)),
remove the need for other (potential) users of the TensorExt dialect to
use the encoding and allow users to bring their own encoding interfaces
while avoiding having to bring in the Encoding dialect.

Signed-off-by: Jorn Tuyls <[email protected]>
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
…20612)

There is no strong dependency of `DispatchTensorType` on the Encoding
dialect as the encoding can be just any attribute and is optional, so I
don't think there's a need to have the TensorExt dialect explicitly
depend on the Encoding just for the interface. Decoupling them would
avoid potential circular dependency issues (I ran into that while
working on
#20160 (comment)),
remove the need for other (potential) users of the TensorExt dialect to
use the encoding and allow users to bring their own encoding interfaces
while avoiding having to bring in the Encoding dialect.

Signed-off-by: Jorn Tuyls <[email protected]>
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.

2 participants