iree: Fix SDXL dispatch count regression from llvm integrate
The most recent llvm integrate, https://github.com/iree-org/iree/pull/18987, introduced a minor regression in SDXL clip dispatch count (1139 ⇾ 1141). I tracked it to https://github.com/llvm/llvm-project/commit/df0d249b6511289f1e8c1389f4fd33d7b4c083fa. I was able to restore the dispatch count by locally reverting this single commit.
Here are the 2 additional dispatches after LLVM integrate:
Command used:
iree-compile artifacts/sdxl_clip/model.mlirbc -o extra-dispatches.mlir --iree-hal-target-backends=rocm --iree-hip-target=gfx942 --iree-opt-const-eval=false --iree-global-opt-propagate-transposes=true --iree-dispatch-creation-enable-fuse-horizontal-contractions=true --iree-dispatch-creation-enable-aggressive-fusion=true --iree-opt-aggressively-propagate-transposes=true --iree-opt-outer-dim-concat=true --iree-llvmgpu-enable-prefetch=true --iree-opt-data-tiling=false --iree-codegen-gpu-native-math-precision=true --iree-codegen-llvmgpu-use-vector-distribution --iree-hip-waves-per-eu=2 --iree-execution-model=async-external --iree-scheduling-dump-statistics-format=json --iree-scheduling-dump-statistics-file=compilation_info.json '--iree-preprocessing-pass-pipeline=builtin.module(iree-preprocessing-transpose-convolution-pipeline,iree-preprocessing-pad-to-intrinsics)' --compile-to=dispatch-creation
MLIR:
util.global private @__hoisted_tensor_64x768xf16_255 {stream.affinity.default = #hal.device.affinity<@__device_0>} : tensor<64x768xf16>
util.initializer attributes {stream.affinity.default = #hal.device.affinity<@__device_0>} {
%cst = arith.constant dense_resource<torch_tensor_1_77_torch.int64> : tensor<1x77xi64>
%_params.text_encoder_model_1.text_model.embeddings.position_embedding.weight = util.global.load immutable @_params.text_encoder_model_1.text_model.embeddings.position_embedding.weight : tensor<77x768xf16>
%0 = flow.dispatch.workgroups(%cst, %_params.text_encoder_model_1.text_model.embeddings.position_embedding.weight) : (tensor<1x77xi64>, tensor<77x768xf16>) -> tensor<64x768xf16> =
(%arg0: !flow.dispatch.tensor<readonly:tensor<1x77xi64>>, %arg1: !flow.dispatch.tensor<readonly:tensor<77x768xf16>>, %arg2: !flow.dispatch.tensor<writeonly:tensor<64x768xf16>>) {
%c77 = arith.constant 77 : index
%c0_i64 = arith.constant 0 : i64
%1 = flow.dispatch.tensor.load %arg1, offsets = [0, 0], sizes = [77, 768], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<77x768xf16>> -> tensor<77x768xf16>
%2 = tensor.empty() : tensor<64x768xf16>
%3 = flow.dispatch.tensor.load %arg0, offsets = [0, 0], sizes = [1, 64], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<1x77xi64>> -> tensor<64xi64>
%4 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%3 : tensor<64xi64>) outs(%2 : tensor<64x768xf16>) {
^bb0(%in: i64, %out: f16):
%5 = arith.index_cast %in : i64 to index
%6 = linalg.index 1 : index
%7 = arith.cmpi slt, %5, %c77 : index
cf.assert %7, "index must be smaller than dim size"
%8 = arith.cmpi sge, %in, %c0_i64 : i64
cf.assert %8, "index must be larger or equal to 0"
%extracted = tensor.extract %1[%5, %6] : tensor<77x768xf16>
linalg.yield %extracted : f16
} -> tensor<64x768xf16>
flow.dispatch.tensor.store %4, %arg2, offsets = [0, 0], sizes = [64, 768], strides = [1, 1] : tensor<64x768xf16> -> !flow.dispatch.tensor<writeonly:tensor<64x768xf16>>
flow.return
} count() -> (index, index, index) {
%x, %y, %z = flow.dispatch.workgroup_count_from_slice
flow.return %x, %y, %z : index, index, index
}
util.global.store %0, @__hoisted_tensor_64x768xf16_255 : tensor<64x768xf16>
util.return
}
util.global private @__hoisted_tensor_64x1280xf16_256 {stream.affinity.default = #hal.device.affinity<@__device_0>} : tensor<64x1280xf16>
util.initializer attributes {stream.affinity.default = #hal.device.affinity<@__device_0>} {
%cst = arith.constant dense_resource<torch_tensor_1_77_torch.int64_1> : tensor<1x77xi64>
%_params.text_encoder_model_2.text_model.embeddings.position_embedding.weight = util.global.load immutable @_params.text_encoder_model_2.text_model.embeddings.position_embedding.weight : tensor<77x1280xf16>
%0 = flow.dispatch.workgroups(%cst, %_params.text_encoder_model_2.text_model.embeddings.position_embedding.weight) : (tensor<1x77xi64>, tensor<77x1280xf16>) -> tensor<64x1280xf16> =
(%arg0: !flow.dispatch.tensor<readonly:tensor<1x77xi64>>, %arg1: !flow.dispatch.tensor<readonly:tensor<77x1280xf16>>, %arg2: !flow.dispatch.tensor<writeonly:tensor<64x1280xf16>>) {
%c77 = arith.constant 77 : index
%c0_i64 = arith.constant 0 : i64
%1 = flow.dispatch.tensor.load %arg1, offsets = [0, 0], sizes = [77, 1280], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<77x1280xf16>> -> tensor<77x1280xf16>
%2 = tensor.empty() : tensor<64x1280xf16>
%3 = flow.dispatch.tensor.load %arg0, offsets = [0, 0], sizes = [1, 64], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<1x77xi64>> -> tensor<64xi64>
%4 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%3 : tensor<64xi64>) outs(%2 : tensor<64x1280xf16>) {
^bb0(%in: i64, %out: f16):
%5 = arith.index_cast %in : i64 to index
%6 = linalg.index 1 : index
%7 = arith.cmpi slt, %5, %c77 : index
cf.assert %7, "index must be smaller than dim size"
%8 = arith.cmpi sge, %in, %c0_i64 : i64
cf.assert %8, "index must be larger or equal to 0"
%extracted = tensor.extract %1[%5, %6] : tensor<77x1280xf16>
linalg.yield %extracted : f16
} -> tensor<64x1280xf16>
flow.dispatch.tensor.store %4, %arg2, offsets = [0, 0], sizes = [64, 1280], strides = [1, 1] : tensor<64x1280xf16> -> !flow.dispatch.tensor<writeonly:tensor<64x1280xf16>>
flow.return
} count() -> (index, index, index) {
%x, %y, %z = flow.dispatch.workgroup_count_from_slice
flow.return %x, %y, %z : index, index, index
}
util.global.store %0, @__hoisted_tensor_64x1280xf16_256 : tensor<64x1280xf16>
util.return
}
It appears these linalg.generics were getting CSE’d before the change but can’t anymore because of the cf.assert which have side effects.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (10 by maintainers)
Commits related to this issue
- Add strip assertions flag (#19014) This change _temporarily_ adds `iree-opt-strip-assertions` to SDXL CI which should fix the regression discussed in https://github.com/iree-org/iree/issues/19002. ... — committed to iree-org/iree by IanWood1 2 years ago
- Add strip assertions flag (#19014) This change _temporarily_ adds `iree-opt-strip-assertions` to SDXL CI which should fix the regression discussed in https://github.com/iree-org/iree/issues/19002. ... — committed to Groverkss/iree by IanWood1 2 years ago
- Add strip assertions flag (#19014) This change _temporarily_ adds `iree-opt-strip-assertions` to SDXL CI which should fix the regression discussed in https://github.com/iree-org/iree/issues/19002. As... — committed to giacs-epic/iree by IanWood1 2 years ago
Maybe no change is needed, just add it to all non “-O0” after https://github.com/iree-org/iree/issues/19072.
(oh and I’m pretty sure we don’t derive information from the assertions today - so it’d be safe to move now!)
@IanWood1 maybe start with adding this flag to all the CI tests, and a separate PR that turns it on by default.