Skip to content

Commit cbfb33a

Browse files
hanhanWpstarkcdpr
authored andcommitted
[DT] Support partial load/store for GPU padding encoding resolver. (iree-org#22372)
I don't see an actual use case, and the revision is mostly for completeness. By definition, the padding resolver behaves like an identity resolver. The main difference is that the DispatchTensorType types get padded. The offsets, sizes and strides do not get transformed in this case. Signed-off-by: hanhanW <[email protected]>
1 parent ce18e6f commit cbfb33a

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

compiler/src/iree/compiler/Codegen/Common/test/materialize_encoding_into_padding.mlir

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,42 @@ func.func @set_pad_encoding_and_store() {
3434

3535
// -----
3636

37+
// This tests that the padding resolver can handle partial loads/stores. The
38+
// offsets, sizes and strides are arbitrarily chosen in the test.
39+
// TODO(#20160): Move the test case to materialize_encoding_for_iree_ops.mlir.
40+
41+
#binding_ro = #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">
42+
#binding = #hal.pipeline.binding<storage_buffer, Indirect>
43+
#encoding_mmt = #iree_encoding.encoding<operand_index = 0 : index, op_type = matmul, element_types = [f16, f16, f16]>
44+
#pad_encoding = #iree_encoding.layout<[#iree_encoding.padding<[0, 64]>]>
45+
func.func @set_pad_encoding_and_partial_load_store() {
46+
%c0 = arith.constant 0 : index
47+
%0 = hal.interface.constant.load layout(<constants = 1, bindings = [#binding_ro, #binding], flags = Indirect>) ordinal(0) : i32
48+
%1 = arith.index_castui %0 : i32 to index
49+
%3 = hal.interface.binding.subspan layout(<constants = 1, bindings = [#binding_ro, #binding], flags = Indirect>) binding(0) alignment(64) offset(%1) flags("ReadOnly|Indirect")
50+
: !iree_tensor_ext.dispatch.tensor<readonly:tensor<2048x2048xf16>>
51+
%4 = hal.interface.binding.subspan layout(<constants = 1, bindings = [#binding_ro, #binding], flags = Indirect>) binding(1) alignment(64) offset(%c0) flags(Indirect)
52+
: !iree_tensor_ext.dispatch.tensor<writeonly:tensor<2048x2048xf16, #pad_encoding>>
53+
%5 = iree_tensor_ext.dispatch.tensor.load %3, offsets = [0, 0], sizes = [1024, 1024], strides = [2, 2]
54+
: !iree_tensor_ext.dispatch.tensor<readonly:tensor<2048x2048xf16>> -> tensor<1024x1024xf16>
55+
%6 = iree_encoding.set_encoding %5 : tensor<1024x1024xf16> -> tensor<1024x1024xf16, #encoding_mmt>
56+
iree_tensor_ext.dispatch.tensor.store %6, %4, offsets = [0, 0], sizes = [1024, 1024], strides = [2, 2]
57+
: tensor<1024x1024xf16, #encoding_mmt> -> !iree_tensor_ext.dispatch.tensor<writeonly:tensor<2048x2048xf16, #pad_encoding>>
58+
return
59+
}
60+
61+
// CHECK-LABEL: @set_pad_encoding_and_partial_load_store
62+
// CHECK: %[[A:.+]] = hal.interface.binding.subspan layout({{.+}}) binding(0)
63+
// CHECK-SAME: !iree_tensor_ext.dispatch.tensor<readonly:tensor<2048x2048xf16>>
64+
// CHECK: %[[B:.+]] = hal.interface.binding.subspan layout({{.+}}) binding(1)
65+
// CHECK-SAME: !iree_tensor_ext.dispatch.tensor<writeonly:tensor<2048x2112xf16>>
66+
// CHECK: %[[LD:.+]] = iree_tensor_ext.dispatch.tensor.load %[[A]], offsets = [0, 0], sizes = [1024, 1024], strides = [2, 2]
67+
// CHECK-SAME: !iree_tensor_ext.dispatch.tensor<readonly:tensor<2048x2048xf16>> -> tensor<1024x1024xf16>
68+
// CHECK: iree_tensor_ext.dispatch.tensor.store %[[LD]], %[[B]], offsets = [0, 0], sizes = [1024, 1024], strides = [2, 2]
69+
// CHECK-SAME: tensor<1024x1024xf16> -> !iree_tensor_ext.dispatch.tensor<writeonly:tensor<2048x2112xf16>>
70+
71+
// -----
72+
3773
#binding_ro = #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">
3874
#binding = #hal.pipeline.binding<storage_buffer, Indirect>
3975
#encoding_mmt = #iree_encoding.encoding<operand_index = 0 : index, op_type = matmul, element_types = [f16, f16, f16]>

compiler/src/iree/compiler/Codegen/ExternalInterfaces/GPUEncodingExternalModels.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,9 @@ struct GPUPadEncodingLayoutMaterializerAttr final
593593
if (!boundType || !boundType.getEncoding()) {
594594
return failure();
595595
}
596-
// Only handle cases where the slice spans the whole
597-
// `!iree_tensor_ext.dispatch.tensor` type.
598-
// TODO(hanchung): Enable partial slices. It was copied from pattern's
599-
// implementaion, i.e., the users, and it can be dropped after we move the
600-
// checks to the interface implementations.
601-
if (!type.doesSliceSpanWholeTensor(dynamicDims, offsets, sizes, strides)) {
602-
return failure();
603-
}
604-
newSizes = getMixedValues(boundType.getShape(), dynamicDims, builder);
605-
newOffsets.resize(newSizes.size(), builder.getIndexAttr(0));
606-
newStrides.resize(newSizes.size(), builder.getIndexAttr(1));
596+
newSizes.assign(sizes.begin(), sizes.end());
597+
newOffsets.assign(offsets.begin(), offsets.end());
598+
newStrides.assign(strides.begin(), strides.end());
607599
return success();
608600
}
609601

0 commit comments

Comments
 (0)