Skip to content

Populate outer parallel loops for UnsetEncodingOp - #12289

Merged
pzread merged 3 commits into
iree-org:mainfrom
pzread:fix-12285
Jul 13, 2023
Merged

pzread merged 3 commits into
iree-org:mainfrom
pzread:fix-12285

Conversation

@pzread

@pzread pzread commented Feb 20, 2023 •

Copy link
Copy Markdown
Contributor

Similar to SetEncodingOp, this change populates the outer parallel loops = result rank for UnsetEncodingOp.

Previously getOuterParallelLoops returns an empty bitvector for UnsetEncodingOp. That fails the pass when UnsetEncodingOp is selected as the root op, because rootOuterParallelLoops = getOuterParallelLoops(rootOp) returns an empty bitvector and the fusable check of consumer ops causes out-of-bound accesses on the vector.

Note that this is only an issue when we try to fuse a chain of consumers with the root op UnsetEncodingOp. For example:

#map = affine_map<(d0, d1) -> (d1)>
#map1 = affine_map<(d0, d1) -> (d0, d1)>
module {
  func.func @root_on_unset_encoding(
      %arg0: tensor<784x96xf32, #iree_linalg_ext.encoding<user = MATMUL_F32F32F32, role = LHS>>,
      %arg1: tensor<96xf32>) -> tensor<784x96xf32> {
    %0 = iree_linalg_ext.unset_encoding %arg0 : tensor<784x96xf32, #iree_linalg_ext.encoding<user = MATMUL_F32F32F32, role = LHS>> -> tensor<784x96xf32>
    %1 = tensor.empty() : tensor<784x96xf32>
    %cst = arith.constant 0.000000e+00 : f32
    %2 = linalg.fill ins(%cst : f32) outs(%1 : tensor<784x96xf32>) -> tensor<784x96xf32>
    %3 = linalg.generic {indexing_maps = [#map, #map1, #map1], iterator_types = ["parallel", "parallel"]} ins(%arg1, %0 : tensor<96xf32>, tensor<784x96xf32>) outs(%1 : tensor<784x96xf32>) {
    ^bb0(%in: f32, %in_0: f32, %out: f32):
      %5 = arith.addf %in, %in_0 : f32
      linalg.yield %5 : f32
    } -> tensor<784x96xf32>
    %4 = linalg.generic {indexing_maps = [#map1, #map1, #map1], iterator_types = ["parallel", "parallel"]} ins(%3, %3 : tensor<784x96xf32>, tensor<784x96xf32>) outs(%1 : tensor<784x96xf32>) {
    ^bb0(%in: f32, %in_0: f32, %out: f32):
      %5 = arith.addf %in, %in_0 : f32
      linalg.yield %5 : f32
    } -> tensor<784x96xf32>
    return %4 : tensor<784x96xf32>
  }
}

Assume the iree_linalg_ext.unset_encoding is the root op. When we fuse the first linalg.generic op, the fusion is specially handled by
https://github.com/openxla/iree/blob/2184784590cb8abe9e5523cb6f64ff583920c339/compiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp#L471-L492

But then we try to also fuse the second linalg.generic into the dispatch, since the producer is now a generic op, the pass runs general check below to see if the ops are fusable:

https://github.com/openxla/iree/blob/2184784590cb8abe9e5523cb6f64ff583920c339/compiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp#L519-L521

This check crashed when rootOuterParallelLoops from UnsetEncodingOp was incorrectly populated with an empty vector.

Fix #12285

@pzread pzread changed the title Populate UnsetEncodingOp Populate outer parallel loops for UnsetEncodingOp Feb 20, 2023
@github-actions

github-actions Bot commented Feb 21, 2023 •

Copy link
Copy Markdown

Abbreviated Benchmark Summary

@ commit 1a399f680a97c4fb41bad6e496fd0962017776eb (vs. base 80fd032ef5c1f415c3456095ac62cfc2fd142d77)

Regressed Latencies 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
BertLargefp16PTBatch1(linalg) [cuda-sm\_80-linux\_gnu-cuda][default-flags] cuda(none)[full-inference,default-flags] with zeros @ a2-highgpu-1g[gpu] 9.715 (vs. 5.870, 65.50%↑) 9.711 0.015
DeepLabV3\_fp32(tflite) [x86\_64-cascadelake-linux\_gnu-llvm\_cpu][default-flags] local\_task(embedded\_elf)[1-thread,full-inference,default-flags] with zeros @ c2-standard-16[cpu] 35.032 (vs. 27.847, 25.80%↑) 35.051 0.141
DeepLabV3\_fp32(tflite) [x86\_64-cascadelake-linux\_gnu-llvm\_cpu][default-flags] local\_task(embedded\_elf)[8-thread,full-inference,default-flags] with zeros @ c2-standard-16[cpu] 8.811 (vs. 7.507, 17.37%↑) 8.754 0.558

[Top 3 out of 6 results showed]

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV3Small\_fp32(tflite) [vmvx-generic-vmvx-vmvx][experimental-flags] local\_task(vmvx\_module)[4-thread,full-inference,system-scheduling] with zeros @ pixel-6-pro[big-core] 993.061 (vs. 1235.855, 19.65%↓) 995.014 17.526
MobileNetV2\_fp32(tflite) [vmvx-generic-vmvx-vmvx][experimental-flags] local\_task(vmvx\_module)[4-thread,full-inference,system-scheduling] with zeros @ pixel-6-pro[big-core] 4988.482 (vs. 5858.154, 14.85%↓) 5040.983 159.787
BertLargeTF(stablehlo) [x86\_64-cascadelake-linux\_gnu-llvm\_cpu][experimental-flags,fuse-padding] local\_task(embedded\_elf)[8-thread,full-inference,default-flags] with zeros @ c2-standard-16[cpu] 1498.194 (vs. 1670.854, 10.33%↓) 1503.531 45.233

[Top 3 out of 10 results showed]

Regressed Total Dispatch Sizes 🚩

Benchmark Name Total Dispatch Size (bytes)
BertLargefp16PTBatch1(linalg) [cuda-sm\_80-linux\_gnu-cuda][default-flags,compile-stats] 115018 (vs. 107354, 7.14%↑)

Regressed Stream IR Dispatch Count (# of cmd.dispatch ops) 🚩

Benchmark Name Stream IR Dispatch Count (# of cmd.dispatch ops)
BertLargefp16PTBatch1(linalg) [cuda-sm\_80-linux\_gnu-cuda][default-flags,compile-stats] 582 (vs. 437, 33.18%↑)

For more information:

Source Workflow Run

@pzread pzread added benchmarks:cuda Run default CUDA benchmarks benchmarks:x86_64 Run default x86_64 benchmarks benchmarks:comp-stats Run default compilation statistics benchmarks benchmarks:android-cpu Run default Android CPU benchmarks benchmarks:android-gpu Run default Android GPU benchmarks benchmarks:vulkan-nvidia Run default Vulkan benchmarks on NVIDIA GPU and removed (deprecated) buildkite:benchmark-android labels Jul 13, 2023
@pzread

pzread commented Jul 13, 2023

Copy link
Copy Markdown
Contributor Author

Regression on BertLargefp16PTBatch1 is due to a know issue #14399 after we update the MLIR files for benchmarking, and the dashboard hasn't updated with the new latency

@pzread pzread removed benchmarks:cuda Run default CUDA benchmarks benchmarks:x86_64 Run default x86_64 benchmarks benchmarks:comp-stats Run default compilation statistics benchmarks benchmarks:android-cpu Run default Android CPU benchmarks benchmarks:android-gpu Run default Android GPU benchmarks benchmarks:vulkan-nvidia Run default Vulkan benchmarks on NVIDIA GPU labels Jul 13, 2023
@pzread
pzread marked this pull request as ready for review July 13, 2023 22:10

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@pzread
pzread merged commit 093afb7 into iree-org:main Jul 13, 2023
nhasabni pushed a commit to plaidml/iree that referenced this pull request Aug 24, 2023
Similar to `SetEncodingOp`, this change populates `the outer parallel
loops = result rank` for `UnsetEncodingOp`.

Fix iree-org#12285
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Aggressive Fusion] Out-of-bounds Bit access in hasCompatibleOuterParallelLoops

3 participants