Skip to content

Fuse element-wise op with multi-use in single consumer op #14407

Open

Description

@pzread

In MobileNetV3Small_fp32, we found the case that two elementwise fusable ops can be fused in FusionOfTensorOpsPass, but the producer appears twice in the consumer operands:

  %65 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%cst_51, %64 : tensor<96xf32>, tensor<784x96xf32>) outs(%62 : tensor<784x96xf32>) {
  ^bb0(%in: f32, %in_180: f32, %out: f32):
    %322 = arith.addf %in, %in_180 : f32
    linalg.yield %322 : f32
  } -> tensor<784x96xf32>
  %66 = tensor.empty() : tensor<784x96xf32>
  %67 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%65, %65 : tensor<784x96xf32>, tensor<784x96xf32>) outs(%66 : tensor<784x96xf32>) {
  ^bb0(%in: f32, %in_180: f32, %out: f32):
    %322 = arith.addf %in_180, %cst_2 : f32
    %323 = arith.minf %322, %cst_106 : f32
    %324 = arith.maxf %323, %cst_61 : f32
    %325 = arith.mulf %in, %324 : f32
    %326 = arith.mulf %325, %cst_1 : f32
    linalg.yield %326 : f32
  } -> tensor<784x96xf32>

This should be possible when --iree-flow-fuse-multi-use is enabled, but the check below still prevent it:

https://github.com/openxla/iree/blob/093afb78ed3258cfc6d072da37a5ec184bb89f22/compiler/src/iree/compiler/Dialect/Flow/Transforms/FusionOfTensorOps.cpp#L56-L64

Sample IR: https://gist.github.com/pzread/00a10d37f8ffebe21a83c10f5a4c4c42

Activity

  1. changed the title [-]Relax the elementwise fusion on multi-use ops[/-] [+]Fuse element-wise op with multi-use in a single consumer op[/+] on Jul 14, 2023
  2. changed the title [-]Fuse element-wise op with multi-use in a single consumer op[/-] [+]Fuse element-wise op with multi-use in single consumer op[/+] on Jul 14, 2023
  3. moved this from Inbox to Backlog in (Deprecated) IREEon Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions