Skip to content

Commit 34d9d5f

Browse files
authored
[Encoding] Implement OpAsmDialectInterface for IREE Encoding dialect. (#19146)
The revision implements the dialect interface which hoists the encodings out of the tensor type. It makes IR dumps much easier in terms of readability because the same encodings are collapsed into a single one and the alias is shorter. The revision refines the lit checks for Encoding/IR/test/roundtrip.mlir which makes the style consistent; it adapts some tests to hoist the encodings, which matches the IR dumps. The `IREEEncodingInlinerInterface` is renamed to `EncodingInlinerInterface` in this patch for consistency. The `IREE` prefix is redundant because it is already in an anonymous namespace under the IREE namespace. Fixes #19024 Signed-off-by: hanhanW <[email protected]>
1 parent 9eaa4ef commit 34d9d5f

File tree

9 files changed

+506
-304
lines changed

9 files changed

+506
-304
lines changed

compiler/src/iree/compiler/Codegen/Common/CPU/test/vmvx_materialize_encoding.mlir

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,29 @@ func.func @matmul_lowering_i8i8i32_vmvx_ukernel() attributes {
4343
-> !flow.dispatch.tensor<readwrite:tensor<?x?xi32, #encoding_result>>{%M, %N}
4444
return
4545
}
46-
4746
// CHECK-DAG: #[[MAP_CEILDIV:.+]] = affine_map<()[s0, s1] -> (s0 ceildiv s1)>
47+
// CHECK-DAG: #[[MAP0:.+]] = affine_map<(d0, d1, d2) -> (d0, d2)>
48+
// CHECK-DAG: #[[MAP1:.+]] = affine_map<(d0, d1, d2) -> (d2, d1)>
49+
// CHECK-DAG: #[[MAP2:.+]] = affine_map<(d0, d1, d2) -> (d0, d1)>
50+
// CHECK: #[[LHS_ENCODING:.+]] = #iree_encoding.encoding<operand_index = 0 : i64, op_type = matmul, element_types = [i8, i8, i32], user_indexing_maps = [#[[MAP0]], #[[MAP1]], #[[MAP2]]], round_dims_to = array<i64: 32, 32, 32>>
51+
// CHECK: #[[RHS_ENCODING:.+]] = #iree_encoding.encoding<operand_index = 1 : i64, op_type = matmul, element_types = [i8, i8, i32], user_indexing_maps = [#[[MAP0]], #[[MAP1]], #[[MAP2]]], round_dims_to = array<i64: 32, 32, 32>>
52+
// CHECK: #[[OUT_ENCODING:.+]] = #iree_encoding.encoding<operand_index = 2 : i64, op_type = matmul, element_types = [i8, i8, i32], user_indexing_maps = [#[[MAP0]], #[[MAP1]], #[[MAP2]]], round_dims_to = array<i64: 32, 32, 32>>
4853
// CHECK: func @matmul_lowering_i8i8i32_vmvx_ukernel()
4954
// CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index
5055
// CHECK-DAG: %[[M:.+]] = hal.interface.constant.load layout({{.+}}) ordinal(0)
5156
// CHECK-DAG: %[[N:.+]] = hal.interface.constant.load layout({{.+}}) ordinal(1)
5257
// CHECK-DAG: %[[K:.+]] = hal.interface.constant.load layout({{.+}}) ordinal(2)
53-
// CHECK: %[[LHS_TILE_SIZES:.+]]:2 = iree_codegen.query_tile_sizes tensor<?x?xi8, #iree_encoding.encoding<operand_index = 0 : i64, op_type = matmul, element_types = [i8, i8, i32], user_indexing_maps = [#map, #map1, #map2], round_dims_to = array<i64: 32, 32, 32>>> -> index, index
58+
// CHECK: %[[LHS_TILE_SIZES:.+]]:2 = iree_codegen.query_tile_sizes tensor<?x?xi8, #[[LHS_ENCODING]]> -> index, index
5459
// CHECK-DAG: %[[LHS_OUTER_SIZE0:.+]] = affine.apply #[[MAP_CEILDIV]]()[%[[M]], %[[LHS_TILE_SIZES]]#0]
5560
// CHECK-DAG: %[[LHS_OUTER_SIZE1:.+]] = affine.apply #[[MAP_CEILDIV]]()[%[[K]], %[[LHS_TILE_SIZES]]#1]
5661
// CHECK: %[[LHS_BINDING:.+]] = hal.interface.binding.subspan layout({{.+}}) binding(0)
5762
// CHECK-SAME: !flow.dispatch.tensor<readonly:tensor<?x?x?x?xi8>>{%[[LHS_OUTER_SIZE0]], %[[LHS_OUTER_SIZE1]], %[[LHS_TILE_SIZES]]#0, %[[LHS_TILE_SIZES]]#1}
58-
// CHECK: %[[RHS_TILE_SIZES:.+]]:2 = iree_codegen.query_tile_sizes tensor<?x?xi8, #iree_encoding.encoding<operand_index = 1 : i64, op_type = matmul, element_types = [i8, i8, i32], user_indexing_maps = [#map, #map1, #map2], round_dims_to = array<i64: 32, 32, 32>>> -> index, index
63+
// CHECK: %[[RHS_TILE_SIZES:.+]]:2 = iree_codegen.query_tile_sizes tensor<?x?xi8, #[[RHS_ENCODING]]> -> index, index
5964
// CHECK-DAG: %[[RHS_OUTER_SIZE0:.+]] = affine.apply #[[MAP_CEILDIV]]()[%[[N]], %[[RHS_TILE_SIZES]]#0]
6065
// CHECK-DAG: %[[RHS_OUTER_SIZE1:.+]] = affine.apply #[[MAP_CEILDIV]]()[%[[K]], %[[RHS_TILE_SIZES]]#1]
6166
// CHECK: %[[RHS_BINDING:.+]] = hal.interface.binding.subspan layout({{.+}}) binding(1)
6267
// CHECK-SAME: !flow.dispatch.tensor<readonly:tensor<?x?x?x?xi8>>{%[[RHS_OUTER_SIZE0]], %[[RHS_OUTER_SIZE1]], %[[RHS_TILE_SIZES]]#0, %[[RHS_TILE_SIZES]]#1}
63-
// CHECK: %[[RESULT_TILE_SIZES:.+]]:2 = iree_codegen.query_tile_sizes tensor<?x?xi32, #iree_encoding.encoding<operand_index = 2 : i64, op_type = matmul, element_types = [i8, i8, i32], user_indexing_maps = [#map, #map1, #map2], round_dims_to = array<i64: 32, 32, 32>>> -> index, index
68+
// CHECK: %[[RESULT_TILE_SIZES:.+]]:2 = iree_codegen.query_tile_sizes tensor<?x?xi32, #[[OUT_ENCODING]]> -> index, index
6469
// CHECK-DAG: %[[RESULT_OUTER_SIZE0:.+]] = affine.apply #[[MAP_CEILDIV]]()[%[[M]], %[[RESULT_TILE_SIZES]]#0]
6570
// CHECK-DAG: %[[RESULT_OUTER_SIZE1:.+]] = affine.apply #[[MAP_CEILDIV]]()[%[[N]], %[[RESULT_TILE_SIZES]]#1]
6671
// CHECK: %[[OUTS_BINDING:.+]] = hal.interface.binding.subspan layout({{.+}}) binding(2)

compiler/src/iree/compiler/Dialect/Encoding/IR/EncodingDialect.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,27 @@
2323
#undef GET_ATTRDEF_CLASSES
2424

2525
namespace mlir::iree_compiler::IREE::Encoding {
26+
namespace {
27+
28+
// Used for custom printing support.
29+
struct EncodingOpAsmInterface : public OpAsmDialectInterface {
30+
using OpAsmDialectInterface::OpAsmDialectInterface;
31+
/// Hooks for getting an alias identifier alias for a given symbol, that is
32+
/// not necessarily a part of this dialect. The identifier is used in place
33+
/// of the symbol when printing textual IR. These aliases must not contain
34+
/// `.` or end with a numeric digit([0-9]+). Returns success if an alias was
35+
/// provided, failure otherwise.
36+
AliasResult getAlias(Attribute attr, raw_ostream &os) const override {
37+
if (llvm::isa<EncodingAttr>(attr)) {
38+
os << "encoding";
39+
return AliasResult::OverridableAlias;
40+
}
41+
return AliasResult::NoAlias;
42+
}
43+
};
2644

2745
// Used to control inlining behavior.
28-
struct IREEEncodingInlinerInterface : public DialectInlinerInterface {
46+
struct EncodingInlinerInterface : public DialectInlinerInterface {
2947
using DialectInlinerInterface::DialectInlinerInterface;
3048

3149
bool isLegalToInline(Operation *call, Operation *callable,
@@ -45,9 +63,10 @@ struct IREEEncodingInlinerInterface : public DialectInlinerInterface {
4563
return true;
4664
}
4765
};
66+
} // namespace
4867

4968
void IREEEncodingDialect::initialize() {
50-
addInterfaces<IREEEncodingInlinerInterface>();
69+
addInterfaces<EncodingOpAsmInterface, EncodingInlinerInterface>();
5170

5271
addAttributes<
5372
#define GET_ATTRDEF_LIST

0 commit comments

Comments
 (0)