Skip to content

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

Closed

Description

@pzread

With patch #11980

iree-compile --output-format=vm-bytecode \
  --iree-hal-target-backends=llvm-cpu \
  --iree-input-type=tosa \
  --iree-llvm-target-triple=aarch64-none-linux-android29 \
  --iree-flow-enable-data-tiling \
  --iree-flow-enable-fuse-padding-into-linalg-consumer-ops \
  --iree-llvmcpu-enable-pad-consumer-fusion \
  iree_58855e40-eba9-4a71-b878-6b35e3460244_MobileNetV3Small_fp32.mlir 

Input MLIR: https://storage.googleapis.com/iree-jerry-test/debug-11980/iree_58855e40-eba9-4a71-b878-6b35e3460244_MobileNetV3Small_fp32.mlir

Error message:

iree-compile: /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/include/llvm/ADT/SmallBitVector.h:460: bool llvm::SmallBitVector::operator[](unsigned int) co
nst: Assertion `Idx < size() && "Out-of-bounds Bit access."' failed.                                                                                                             
Please report issues to https://github.com/iree-org/iree/issues and include the crash backtrace.                                                                                 
Stack dump:                                                                                                                                                                      
0.      Program arguments: ./tools/iree-compile --output-format=vm-bytecode --iree-hal-target-backends=llvm-cpu --iree-input-type=tosa --iree-llvm-target-triple=aarch64-none-lin
ux-android29 --iree-flow-enable-data-tiling --iree-flow-enable-fuse-padding-into-linalg-consumer-ops --iree-llvmcpu-enable-pad-consumer-fusion e2e_test_artifacts/iree_58855e40-e
ba9-4a71-b878-6b35e3460244_MobileNetV3Small_fp32.mlir                                                                                                                            
 #0 0x00007f40df614457 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:567
:13                                                                                                                                                                              
 #1 0x00007f40df6126c0 llvm::sys::RunSignalHandlers() /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:105:18                       
 #2 0x00007f40df614ada SignalHandler(int) /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:412:1                               
 #3 0x00007f40d6a5af90 (/lib/x86_64-linux-gnu/libc.so.6+0x3bf90)                                                                                                                 
 #4 0x00007f40d6aa9ccc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76                                                                                          
 #5 0x00007f40d6a5aef2 raise ./signal/../sysdeps/posix/raise.c:27:6                                                                                                              
 #6 0x00007f40d6a45472 abort ./stdlib/./stdlib/abort.c:81:7                                                                                                                      
 #7 0x00007f40d6a45395 _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9                                                                                                         
 #8 0x00007f40d6a53df2 (/lib/x86_64-linux-gnu/libc.so.6+0x34df2)                                                                                                                 
 #9 0x00007f40df447a82 llvm::SmallVectorTemplateCommon<unsigned long, void>::operator[](unsigned long) /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/incl
ude/llvm/ADT/SmallVector.h:294:5                                                                                                                                                 
#10 0x00007f40df447a82 llvm::BitVector::reference::reference(llvm::BitVector&, unsigned int) /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/include/llvm/A
DT/BitVector.h:99:18                                                                                                                                                             
#11 0x00007f40df447a82 llvm::BitVector::operator[](unsigned int) /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/include/llvm/ADT/BitVector.h:439:12       
#12 0x00007f40df447a82 llvm::SmallBitVector::operator[](unsigned int) const /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/include/llvm/ADT/SmallBitVector
.h:463:26                                                                                                                                                                        
#13 0x00007f40df447a82 llvm::SmallBitVector::test(unsigned int) const /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/llvm/include/llvm/ADT/SmallBitVector.h:473
:12                                                                                                                                                                              
#14 0x00007f40df447a82 mlir::compressDims(mlir::AffineMap, llvm::SmallBitVector const&) /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/mlir/lib/IR/AffineMap.cp
p:579:20                                                                                                                                                                         
#15 0x00007f40df4492b6 mlir::getProjectedMap(mlir::AffineMap, llvm::SmallBitVector const&) /usr/local/google/home/cheyuw/iree/iree/third_party/llvm-project/mlir/lib/IR/AffineMap
.cpp:746:10                                                                                                                                                                      
#16 0x00007f40dc061dc3 mlir::iree_compiler::IREE::Flow::hasCompatibleOuterParallelLoops(mlir::OpOperand&, llvm::SmallBitVector const&) /usr/local/google/home/cheyuw/iree/iree/co
mpiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp:368:7                                                                                                   
#17 0x00007f40dc061dc3 mlir::iree_compiler::IREE::Flow::areOpsAggresiveFusable(mlir::Operation*, mlir::Operation*, llvm::SmallBitVector const&, bool)::$_11::operator()(mlir::OpO
perand*) const /usr/local/google/home/cheyuw/iree/iree/compiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp:411:16

Activity

  1. pzread commented on Feb 20, 2023

    @pzread
    ContributorAuthor
      %82 = iree_linalg_ext.set_encoding %padded_144 : tensor<784x32xf32> -> tensor<784x32xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_LHS>>
      %83 = iree_linalg_ext.set_encoding %padded_145 : tensor<32x96xf32> -> tensor<32x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RHS_TRANSPOSE>>
      %84 = tensor.empty() : tensor<784x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RESULT>>
      %85 = linalg.fill ins(%cst : f32) outs(%84 : tensor<784x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RESULT>>) -> tensor<784x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RESULT>>
      %86 = linalg.matmul ins(%82, %83 : tensor<784x32xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_LHS>>, tensor<32x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RHS_TRANSPOSE>>) outs(%85 : tensor<784x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RESULT>>) -> tensor<784x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RESULT>>
      %87 = iree_linalg_ext.unset_encoding %86 : tensor<784x96xf32, #iree_linalg_ext.encoding<MATMUL_F32F32F32_RESULT>> -> tensor<784x96xf32>
      %88 = 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_64, %87 : tensor<96xf32>, tensor<784x96xf32>) outs(%81 : tensor<784x96xf32>) {
      ^bb0(%in: f32, %in_282: f32, %out: f32):
        %445 = arith.addf %in, %in_282 : f32
        linalg.yield %445 : f32 
      } -> tensor<784x96xf32>
      %89 = 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(%88, %88 : tensor<784x96xf32>, tensor<784x96xf32>) outs(%81 : tensor<784x96xf32>) {
      ^bb0(%in: f32, %in_282: f32, %out: f32):
        %445 = arith.addf %in_282, %cst_4 : f32
        %446 = arith.minf %445, %cst_3 : f32
        %447 = arith.maxf %446, %cst : f32
        %448 = arith.mulf %in, %447 : f32
        %449 = arith.mulf %448, %cst_2 : f32
        linalg.yield %449 : f32
      } -> tensor<784x96xf32>
    

    The iree_linalg_ext.unset_encoding is marked as root op, and the assertion failed when checking if the consumer %89 = linalg.generic is fusable, because we don't handle the root parallel loop for unset_encoding in getOuterParallelLoops

  2. self-assigned this
    on Feb 20, 2023
  3. MaheshRavishankar commented on Feb 21, 2023

    @MaheshRavishankar
    Collaborator

    @pzread . Thanks for looking into it. Btw, do you know why the %88 and %89 arent fused?

  4. pzread commented on Feb 21, 2023

    @pzread
    ContributorAuthor

    %89 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>

    Good point. I think it's because the consumer %89 uses the producer %88 twice in its inputs (generated during the process of elementwise fusion) and we have this check:

    // For now check that the `sourceOp` is only used once in the consumer.

    Didn't recall the exact reason for that check but I can dig a little more.

  5. moved this from Not Started to Inbox in (Deprecated) IREEon Apr 5, 2023
  6. moved this from Inbox to In Progress in (Deprecated) IREEon Apr 13, 2023
  7. allieculp commented on Apr 19, 2023

    @allieculp

    @pzread Any update on this one?

  8. moved this from In Progress to Not Started in (Deprecated) IREEon Apr 19, 2023
  9. moved this from Not Started to In Progress in (Deprecated) IREEon Jul 13, 2023
  10. added a commit that references this issue on Jul 13, 2023
    093afb7
  11. moved this from In Progress to Done in (Deprecated) IREEon Jul 13, 2023
  12. pzread commented on Jul 13, 2023

    @pzread
    ContributorAuthor

    %89 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>

    Good point. I think it's because the consumer %89 uses the producer %88 twice in its inputs (generated during the process of elementwise fusion) and we have this check:

    // For now check that the `sourceOp` is only used once in the consumer.

    Didn't recall the exact reason for that check but I can dig a little more.

    I'll file another issue to see if we can relax this restriction.

  13. pzread commented on Jul 14, 2023

    @pzread
    ContributorAuthor

    %89 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>

    Good point. I think it's because the consumer %89 uses the producer %88 twice in its inputs (generated during the process of elementwise fusion) and we have this check:

    // For now check that the `sourceOp` is only used once in the consumer.

    Didn't recall the exact reason for that check but I can dig a little more.

    I'll file another issue to see if we can relax this restriction.

    Tracked in #14407

  14. added a commit that references this issue on Aug 24, 2023
    eab23a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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