Repository navigation
Closed
Labels
codegen/llvmLLVM code generation compiler backend
Description
With #10177 reduction with the compatible parallel iteration domains get fused into a single dispatch. For example
hal.executable private @multi_root_repro {
hal.executable.variant public @embedded_elf_x86_64, target = <"llvm-cpu", "embedded-elf-x86_64", {cpu_features = "", data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", native_vector_size = 16 : index, target_triple = "x86_64-unknown-unknown-eabi-elf"}> {
hal.executable.export public @_softmax_dispatch_0_generic_12x128x128 ordinal(0) layout(#hal.pipeline.layout<push_constants = 0, sets = [<0, bindings = [<0, storage_buffer, ReadOnly>, <1, storage_buffer, ReadOnly>, <2, storage_buffer>, <3, storage_buffer>]>]>) {
^bb0(%arg0: !hal.device, %arg1: index, %arg2: index, %arg3: index):
%x, %y, %z = flow.dispatch.default_workgroup_count %arg1, %arg2, %arg3
hal.return %x, %y, %z : index, index, index
}
builtin.module {
func.func @_softmax_dispatch_0_generic_12x128x128() {
%c0 = arith.constant 0 : index
%c6144 = arith.constant 6144 : index
%c792576 = arith.constant 792576 : index
%cst = arith.constant 0.000000e+00 : f32
%0 = hal.interface.binding.subspan set(0) binding(0) type(storage_buffer) offset(%c0) alignment(64) : !flow.dispatch.tensor<readonly:12x128x128xf32>
%1 = hal.interface.binding.subspan set(0) binding(1) type(storage_buffer) offset(%c0) alignment(64) : !flow.dispatch.tensor<readonly:12x128xf32>
%2 = hal.interface.binding.subspan set(0) binding(2) type(storage_buffer) offset(%c6144) alignment(64) : !flow.dispatch.tensor<writeonly:12x128x128xf32>
%3 = hal.interface.binding.subspan set(0) binding(3) type(storage_buffer) offset(%c792576) alignment(64) : !flow.dispatch.tensor<writeonly:12x128xf32>
%4 = flow.dispatch.tensor.load %0, offsets = [0, 0, 0], sizes = [12, 128, 128], strides = [1, 1, 1] : !flow.dispatch.tensor<readonly:12x128x128xf32> -> tensor<12x128x128xf32>
%5 = flow.dispatch.tensor.load %1, offsets = [0, 0], sizes = [12, 128], strides = [1, 1] : !flow.dispatch.tensor<readonly:12x128xf32> -> tensor<12x128xf32>
%6 = linalg.init_tensor [12, 128, 128] : tensor<12x128x128xf32>
%7 = linalg.init_tensor [12, 128] : tensor<12x128xf32>
%8 = linalg.fill ins(%cst : f32) outs(%7 : tensor<12x128xf32>) -> tensor<12x128xf32>
%9 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"]} ins(%4 : tensor<12x128x128xf32>) outs(%5 : tensor<12x128xf32>) {
^bb0(%arg0: f32, %arg1: f32):
%11 = arith.cmpf ogt, %arg0, %arg1 : f32
%12 = arith.select %11, %arg0, %arg1 : f32
linalg.yield %12 : f32
} -> tensor<12x128xf32>
%10:2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"]} ins(%4, %9 : tensor<12x128x128xf32>, tensor<12x128xf32>) outs(%6, %8 : tensor<12x128x128xf32>, tensor<12x128xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32, %arg3: f32):
%11 = arith.subf %arg0, %arg1 : f32
%12 = math.exp %11 : f32
%13 = arith.addf %12, %arg3 : f32
linalg.yield %12, %13 : f32, f32
} -> (tensor<12x128x128xf32>, tensor<12x128xf32>)
flow.dispatch.tensor.store %10#0, %2, offsets = [0, 0, 0], sizes = [12, 128, 128], strides = [1, 1, 1] : tensor<12x128x128xf32> -> !flow.dispatch.tensor<writeonly:12x128x128xf32>
flow.dispatch.tensor.store %10#1, %3, offsets = [0, 0], sizes = [12, 128], strides = [1, 1] : tensor<12x128xf32> -> !flow.dispatch.tensor<writeonly:12x128xf32>
return
}
}
}
}
This has two linalg.generic operation with "reduction" iterator types. Running this with
iree-opt -pass-pipeline="hal.executable(hal.executable.variant(iree-llvmcpu-lower-executable-target))" multi_root_repro.mlir
fails with the following error
multi_root_repro.mlir:29:15: error: 'linalg.generic' op unhandled multiple root operations in dispatch region
%10:2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"]} ins(%4, %9 : tensor<12x128x128xf32>, tensor<12x128xf32>) outs(%6, %8 : tensor<12x128x128xf32>, tensor<12x128xf32>) {
^
multi_root_repro.mlir:29:15: note: see current operation: %14:2 = "linalg.generic"(%8, %13, %10, %12) ({
^bb0(%arg0: f32, %arg1: f32, %arg2: f32, %arg3: f32):
%15 = "arith.subf"(%arg0, %arg1) : (f32, f32) -> f32
%16 = "math.exp"(%15) : (f32) -> f32
%17 = "arith.addf"(%16, %arg3) : (f32, f32) -> f32
"linalg.yield"(%16, %17) : (f32, f32) -> ()
}) {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"], operand_segment_sizes = array<i32: 2, 2>} : (tensor<12x128x128xf32>, tensor<12x128xf32>, tensor<12x128x128xf32>, tensor<12x128xf32>) -> (tensor<12x128x128xf32>, tensor<12x128xf32>)
This should be supportable. This happens on other backends too, but starting with CPU backend for now.
Metadata
Metadata
Assignees
Labels
codegen/llvmLLVM code generation compiler backend
Type
Projects
- StatusShow more project fieldsDone
Activity
MaheshRavishankar commentedon Aug 25, 2022
PR #10210 gets past the above error. This is the dump of IR before/after all with the
iree-optcommand in the first comment (https://gist.github.com/MaheshRavishankar/62954bf5ea0eadfa7673002bff4f5125)Issue now seems to be the op isnt vectorized
@hanhanW in case he has some quick insights into this while I dig deeper.
MaheshRavishankar commentedon Aug 25, 2022
FYI @pzread
hanhanW commentedon Aug 25, 2022
Looks like it failed to meet precondition.
Might fail in this check:
MaheshRavishankar commentedon Aug 25, 2022
Thanks @hanhanW , couple of fixes seems to make things work great.
to
Then I get the desired output
Looks kind of like what I am looking for..
Find root by traversing the compute ops in reverse. (#10210)
MaheshRavishankar commentedon Aug 26, 2022
Closed by #10210
Squashed commit of the following: