)]}'
{
  "commit": "5f72e26ac2e941ccf40ead9e30c438993282de9d",
  "tree": "1da102ee0f3b7a267542c7a7c3dda0674dd05bbe",
  "parents": [
    "7fffae0105d04fe58dc922bb66a885e1424dadda"
  ],
  "author": {
    "name": "Maksymilian B. Knust",
    "email": "knust@roofline.ai",
    "time": "Wed Oct 28 15:44:19 2026 +0100"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Wed Oct 28 15:44:19 2026 +0100"
  },
  "message": "[LinalgExt] Add group_matmul and group_mmt4d ops (#24909)\n\n# What \u0026 why\n\nThis PR introduces a new `group_matmul` operation, to be the IREE\nequivalent of Torch\u0027s\n[grouped_mm](https://docs.pytorch.org/docs/main/generated/torch.nn.functional.grouped_mm.html).\nIt\u0027s purpose is to enable efficient inference of Mixture-of-Experts\nmodels. The op is superficially similar to `linalg.matmul` and\n`linalg.batch_matmul`, but cannot be expressed as a pure\n`linalg.generic` without masking inactive elements, so I believe it\nbelongs here in LinalgExt. The description in LinalgExtOps.td gives more\ninfo.\n\n# How\n\n1) We add the standard matmul encodings to LHS, RHS and result of our op\nin SetEncoding.cpp\n2) We define an auxillary `group_mmt4d` op - the grouped equivalent of\n`mmt4d`\n3) In MaterializeEncodingPatterns.cpp, we convert `group_matmul` to\n`group_mmt4d`\n4) We implement the tiling interface for `group_mmt4d`\n5) After workgroup tiling, we add a `DecomposeGroupMmt4DPass`, which\nturns `group_mmt4d` into `mmt4d` + some extra ops\na) if all input rows of a tile belong to the same expert, we just slice\n+ `mmt4d`\nb) otherwise, we loop over experts; for each of them we mask out rows\nthat don\u0027t belong to it\n\n# Performance\n\nPreliminary benchmarks have shown speed close to a matmul of comparable\nshape. This is expected since:\n- decomposition of `group_mmt4d` happens after workgroup tiling, so the\nop turns into a single dispatch\n - there is no control flow on the host side\n- the number of tiles containing a boundary between experts is limited:\n(5a) is much more common than (5b)\n- only the weights of the active experts need are accessed - no wasted\nmemory bandwidth\n\n# Known shortcomings / future work\n - only LLVMCPU backend is supported currently\n   - dynamic tile sizes (RVV \u0026 SVE) not implemented\n - for compilation to succeed, you must have enabled:\n   - data tiling\n   - distribution tiling (on by default)\n - LHS and RHS must be floats\n- integer operands could result in an identity layout (not implemented)\n- the attribute placed on `group_mmt4d` to support the narrow-N\ntranspose is an ugly hack\n- this will no longer be needed once we can lower to `inner_tiled`\ninstead\n- both ops implemented here could possibly be unified into some kind of\n`group_contract`\n- by analogy to\n[linalg.contract](https://mlir.llvm.org/docs/Dialects/Linalg/#linalgcontract-linalgcontractop)\n- instead of passing in expert offsets, perhaps LHS should just be a\nproper [ragged\ntensor](https://iree.dev/reference/mlir-dialects/TensorExt/#iree_tensor_extcast_to_ragged_shape-tensorextcasttoraggedshapeop)?\n   - this feature is still work-in-progress IIUC\n - gather/scatter should be fused with this op\n\nAssisted-by: Codex\n\nSigned-off-by: Maksymilian B. Knust \u003cknust@roofline.ai\u003e",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "02d329b48d8f9a1cf89b5ee1bc772e446e6c68cf",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/Common/MaterializeEncodingPatterns.cpp",
      "new_id": "ee3e3153c29fedc384f3be48acaa37f328a8db39",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/Common/MaterializeEncodingPatterns.cpp"
    },
    {
      "type": "modify",
      "old_id": "fe0df344a73121f21000e3e45d60f70fd4569893",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/ExternalInterfaces/test/materialize_encoding_invalid.mlir",
      "new_id": "022587856f0c8352d3c7713d6d055965ff12bedb",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/ExternalInterfaces/test/materialize_encoding_invalid.mlir"
    },
    {
      "type": "modify",
      "old_id": "8edc9d1bfdd4d3cc728f8064e098d8d1e4a18098",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/Interfaces/PartitionableLoopsInterface.cpp",
      "new_id": "a41d2406f5afdfd331725f900d0d0d9224d284a8",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/Interfaces/PartitionableLoopsInterface.cpp"
    },
    {
      "type": "modify",
      "old_id": "4e8151110a948b34e1c8a126fe85766c1c07233b",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/BUILD.bazel",
      "new_id": "90f2e5bafee2bda6b2a37ea1a58295e61ce0c314",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/BUILD.bazel"
    },
    {
      "type": "modify",
      "old_id": "d20f7445eb426b5b729b8414cb8267941f3e8deb",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/CMakeLists.txt",
      "new_id": "910c739fd457e5af5dd9ec80bc2c04766072e999",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/CMakeLists.txt"
    },
    {
      "type": "modify",
      "old_id": "2248a21d6be6b74863a06d6cb2e38cd8999d7946",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/KernelDispatch.cpp",
      "new_id": "1a27fdc7e983e6ae40990b1bb0a4aab0806294c7",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/KernelDispatch.cpp"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "8110c02a000bd5c040d9e76dac2af0db58d85170",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUDecomposeGroupMmt4D.cpp"
    },
    {
      "type": "modify",
      "old_id": "9984e0c7de64b39a532a439dd0b73aac21166520",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.cpp",
      "new_id": "9bcfaabd0f8a6f52e5d460c2e558ef76a69d3865",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.cpp"
    },
    {
      "type": "modify",
      "old_id": "39e24dc019693d0dd2bfd3043348c8a81016523c",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.td",
      "new_id": "5d291e12d1fe8988c107ebaf693887cb08105b2d",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.td"
    },
    {
      "type": "modify",
      "old_id": "5fb818616255df5aa084b28ffe9a9483dd60b639",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtInterfaces.h",
      "new_id": "f8055cbdde7164f546e094ffa8d8e48bb9b1868b",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtInterfaces.h"
    },
    {
      "type": "modify",
      "old_id": "eb7a33c86924d6640d2f88aee9ea188e30c45f01",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp",
      "new_id": "2c6f0b2e4cfd3d1f4aafff1d088c8d0f27986cc7",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp"
    },
    {
      "type": "modify",
      "old_id": "5f6fd1f536f291a93bcabd4b21432497d261290f",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.h",
      "new_id": "036d8441d7120953485526f1e6e7d0a7b3586265",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.h"
    },
    {
      "type": "modify",
      "old_id": "b03e89c0f0269e825bc02e4676616f3a89c43d18",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.td",
      "new_id": "272dacbaa042cb11648cbb904df9e86ab4498466",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.td"
    },
    {
      "type": "modify",
      "old_id": "b83e022f88d7f79a79314a9faf7dd15c56bcfc07",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/TilingInterfaceImpl.cpp",
      "new_id": "096e1b3a11821af294b841271798e618992fe470",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/TilingInterfaceImpl.cpp"
    },
    {
      "type": "modify",
      "old_id": "90450078a2171e77aa6c7296621b8250d4fd0c49",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/invalid.mlir",
      "new_id": "4fd015b5d4c9022bb1cd5242b1e8899755b844bd",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/invalid.mlir"
    },
    {
      "type": "modify",
      "old_id": "f52f21b9fb5581d244682dbe1b34a9bf5b3b92a5",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/roundtrip.mlir",
      "new_id": "b018017bb74eef3a89c97ca3cf3773aa644621fb",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/roundtrip.mlir"
    },
    {
      "type": "modify",
      "old_id": "633cd864902a426df1d19854b77b1e42122fc214",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Dialect/LinalgExt/Transforms/test/tiling.mlir",
      "new_id": "a2958b7dc2116fc79eb2656fb887620725787d1b",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Dialect/LinalgExt/Transforms/test/tiling.mlir"
    },
    {
      "type": "modify",
      "old_id": "43d85af771ab8be7251e512bd3f1a1e2d2bd3fcd",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/DispatchCreation/AnnotateDataTilingHints.cpp",
      "new_id": "397f77e325f0af4a52df7e25befa37c39fefb3c0",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/DispatchCreation/AnnotateDataTilingHints.cpp"
    },
    {
      "type": "modify",
      "old_id": "7c086385585420ec138dab304f0bf97e25f8fd49",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/DispatchCreation/SetEncoding.cpp",
      "new_id": "41807bf86f98de3d9a8aa9d3332cdc28649e6cbc",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/DispatchCreation/SetEncoding.cpp"
    },
    {
      "type": "modify",
      "old_id": "ef50384a92578446dfd6353be77bf17d393124f0",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/DispatchCreation/test/set_encoding.mlir",
      "new_id": "de2433b37dd7f3e163f6d4a91bb5c13b0b3d061a",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/DispatchCreation/test/set_encoding.mlir"
    },
    {
      "type": "modify",
      "old_id": "2dd29713099dbf7cc11af4da81ae6eb780c93663",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/ExternalInterfaces/LinalgExtExternalModels.cpp",
      "new_id": "a4e3e9df7ddc98c3b051dd0b8688fb81ce1c8903",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/ExternalInterfaces/LinalgExtExternalModels.cpp"
    },
    {
      "type": "modify",
      "old_id": "57238d51891fe97f24676c8a04af98d43956e368",
      "old_mode": 33188,
      "old_path": "tests/e2e/linalg_ext_ops/BUILD.bazel",
      "new_id": "ab07d93cc9d2b6a8ba8cbf49b5030806f9814e23",
      "new_mode": 33188,
      "new_path": "tests/e2e/linalg_ext_ops/BUILD.bazel"
    },
    {
      "type": "modify",
      "old_id": "aba7ceb2f4bb5867f8e11e01e934c7bb4c9d15a0",
      "old_mode": 33188,
      "old_path": "tests/e2e/linalg_ext_ops/CMakeLists.txt",
      "new_id": "37c10c7e2ed5d14ba385767964a131612188a496",
      "new_mode": 33188,
      "new_path": "tests/e2e/linalg_ext_ops/CMakeLists.txt"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "5bd0387161a84162f4f4513e3a8ebb631a8a8908",
      "new_mode": 33188,
      "new_path": "tests/e2e/linalg_ext_ops/grouped_matmul.mlir"
    }
  ]
}
