Repository navigation
Description
Similar to upstream LinAlg dialect, we should decouple the op definition between pure ops (e.g., linalg_ext.yield) and LinalgExtOp (e.g., scatter/gather/sort/etc). This way, we don't need to attach interface implementation when we create a new LinalgExt op. It can be done by including the generated .inc.h or .inc.cpp files. E.g.,
void mlir::linalg::registerTilingInterfaceExternalModels(
DialectRegistry ®istry) {
registry.addExtension(+[](MLIRContext *ctx, linalg::LinalgDialect *dialect) {
registerOne<linalg::GenericOp>(ctx);
linalg::PackOp::attachInterface<PackOpTiling>(*ctx);
linalg::UnPackOp::attachInterface<UnPackOpTiling>(*ctx);
registerAll<
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
>(ctx);
});
}Currently, it can benefit at least four places in the codebase:
iree/compiler/src/iree/compiler/ExternalInterfaces/UtilExternalModels.cpp
Lines 479 to 506 in 7c55b52
| // TODO(matthias-springer): Use a helper instead of listing all ops. This is | |
| // tricky because LinalgExtOps.td includes YieldOp. | |
| registry.addExtension(+[](MLIRContext *context, | |
| IREE::LinalgExt::IREELinalgExtDialect *dialect) { | |
| IREE::LinalgExt::ScatterOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::ScatterOp>>(*context); | |
| IREE::LinalgExt::SortOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::SortOp>>(*context); | |
| IREE::LinalgExt::FftOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::FftOp>>(*context); | |
| IREE::LinalgExt::ScanOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::ScanOp>>(*context); | |
| IREE::LinalgExt::TopkOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::TopkOp>>(*context); | |
| IREE::LinalgExt::WinogradInputTransformOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::WinogradInputTransformOp>>( | |
| *context); | |
| IREE::LinalgExt::WinogradFilterTransformOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::WinogradFilterTransformOp>>( | |
| *context); | |
| IREE::LinalgExt::WinogradOutputTransformOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::WinogradOutputTransformOp>>( | |
| *context); | |
| IREE::LinalgExt::Im2colOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::Im2colOp>>(*context); | |
| IREE::LinalgExt::AttentionOp::attachInterface< | |
| LinalgOpTiedOpInterface<IREE::LinalgExt::AttentionOp>>(*context); | |
| }); |
iree/compiler/src/iree/compiler/Codegen/Interfaces/PartitionableLoopsInterface.cpp
Lines 241 to 270 in 7c55b52
| registry.addExtension(+[](MLIRContext *ctx, | |
| IREE::LinalgExt::IREELinalgExtDialect *dialect) { | |
| IREE::LinalgExt::FftOp::attachInterface<FftOpPartitionableLoops>(*ctx); | |
| IREE::LinalgExt::ScanOp::attachInterface< | |
| AllParallelAsPartitionableLoops<IREE::LinalgExt::ScanOp>>(*ctx); | |
| IREE::LinalgExt::ScatterOp::attachInterface< | |
| OuterParallelAsPartitionableLoops<IREE::LinalgExt::ScatterOp>>(*ctx); | |
| IREE::LinalgExt::GatherOp::attachInterface< | |
| AllParallelAsPartitionableLoops<IREE::LinalgExt::GatherOp>>(*ctx); | |
| IREE::LinalgExt::SortOp::attachInterface< | |
| AllParallelAsPartitionableLoops<IREE::LinalgExt::SortOp>>(*ctx); | |
| IREE::LinalgExt::TopkOp::attachInterface< | |
| AllParallelAsPartitionableLoops<IREE::LinalgExt::TopkOp>>(*ctx); | |
| IREE::LinalgExt::WinogradInputTransformOp::attachInterface< | |
| AllParallelAsPartitionableLoops< | |
| IREE::LinalgExt::WinogradInputTransformOp>>(*ctx); | |
| IREE::LinalgExt::WinogradFilterTransformOp::attachInterface< | |
| AllParallelAsPartitionableLoops< | |
| IREE::LinalgExt::WinogradFilterTransformOp>>(*ctx); | |
| IREE::LinalgExt::WinogradOutputTransformOp::attachInterface< | |
| AllParallelAsPartitionableLoops< | |
| IREE::LinalgExt::WinogradOutputTransformOp>>(*ctx); | |
| IREE::LinalgExt::Im2colOp::attachInterface< | |
| AllParallelAsPartitionableLoops<IREE::LinalgExt::Im2colOp>>(*ctx); | |
| IREE::LinalgExt::AttentionOp::attachInterface< | |
| AllParallelAsPartitionableLoops<IREE::LinalgExt::AttentionOp>>(*ctx); | |
| IREE::LinalgExt::OnlineAttentionOp::attachInterface< | |
| AllParallelAsPartitionableLoops<IREE::LinalgExt::OnlineAttentionOp>>( | |
| *ctx); | |
| }); |
iree/compiler/src/iree/compiler/Codegen/Interfaces/BufferizationInterfaces.cpp
Lines 689 to 715 in 7c55b52
| registry.addExtension(+[](MLIRContext *ctx, | |
| IREE::LinalgExt::IREELinalgExtDialect *dialect) { | |
| IREE::LinalgExt::FftOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::FftOp>>(*ctx); | |
| IREE::LinalgExt::PackOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::PackOp>>(*ctx); | |
| IREE::LinalgExt::UnPackOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::UnPackOp>>(*ctx); | |
| IREE::LinalgExt::ScanOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::ScanOp>>(*ctx); | |
| IREE::LinalgExt::ScatterOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::ScatterOp>>(*ctx); | |
| IREE::LinalgExt::GatherOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::GatherOp>>(*ctx); | |
| IREE::LinalgExt::SortOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::SortOp>>(*ctx); | |
| IREE::LinalgExt::TopkOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::TopkOp>>(*ctx); | |
| IREE::LinalgExt::WinogradInputTransformOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::WinogradInputTransformOp>>(*ctx); | |
| IREE::LinalgExt::WinogradFilterTransformOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::WinogradFilterTransformOp>>(*ctx); | |
| IREE::LinalgExt::WinogradOutputTransformOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::WinogradOutputTransformOp>>(*ctx); | |
| IREE::LinalgExt::AttentionOp::attachInterface< | |
| LinalgExtOpInterface<IREE::LinalgExt::AttentionOp>>(*ctx); | |
| }); |
iree/compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp
Lines 2216 to 2238 in 7c55b52
| #define DEFINE_OP_GET_EFFECTS(OP_NAME) \ | |
| void OP_NAME::getEffects( \ | |
| SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>> \ | |
| &effects) { \ | |
| getEffectsImpl(effects, getDpsInputOperands(), getDpsInitsMutable()); \ | |
| } | |
| DEFINE_OP_GET_EFFECTS(ScatterOp) | |
| DEFINE_OP_GET_EFFECTS(GatherOp) | |
| DEFINE_OP_GET_EFFECTS(MapScatterOp) | |
| DEFINE_OP_GET_EFFECTS(SortOp) | |
| DEFINE_OP_GET_EFFECTS(FftOp) | |
| DEFINE_OP_GET_EFFECTS(ScanOp) | |
| DEFINE_OP_GET_EFFECTS(TopkOp) | |
| DEFINE_OP_GET_EFFECTS(PackOp) | |
| DEFINE_OP_GET_EFFECTS(UnPackOp) | |
| DEFINE_OP_GET_EFFECTS(WinogradInputTransformOp) | |
| DEFINE_OP_GET_EFFECTS(WinogradFilterTransformOp) | |
| DEFINE_OP_GET_EFFECTS(WinogradOutputTransformOp) | |
| DEFINE_OP_GET_EFFECTS(AttentionOp) | |
| DEFINE_OP_GET_EFFECTS(OnlineAttentionOp) | |
| DEFINE_OP_GET_EFFECTS(Im2colOp) | |
| DEFINE_OP_GET_EFFECTS(CustomOp) |
Activity
sakupan102 commentedon Oct 13, 2025
@hanhanW
Please assign me to this issue if it hasn't been worked on yet.
I would like to contribute.
hanhanW commentedon Oct 13, 2025
Please go ahead and create a PR, thanks for offering the help!
[LinalgExt] Split the op definition between pure ops and LinalgExt ops
[LinalgExt] Attach interface implementation by including the generate…
[LinalgExt] Split the op definition between pure ops and LinalgExt ops
[LinalgExt] Attach interface implementation by including the generate…
[LinalgExt] Split the op definition between pure ops and LinalgExt ops
[LinalgExt] Attach interface implementation by including the generate…
[LinalgExt] Split the op definition between pure ops and LinalgExt ops
[LinalgExt] Attach interface implementation by including the generate…
[LinalgExt] Split the op definition between pure ops and LinalgExt ops
[LinalgExt] Attach interface implementation by including the generate…
[LinalgExt][NFC] Split the op definition between pure ops and LinalgE…
[LinalgExt][NFC] Split the op definition between pure ops and LinalgE…
[LinalgExt][NFC] Split the op definition between pure ops and LinalgE…
[LinalgExt][NFC] Split the op definition between pure ops and LinalgE…