llvm-project
llvm-project copied to clipboard
MLIR Affine supervectorizer issue while optimizing a conv2d program
Hi,
I got into this issue when I try to apply MLIR affine supervectorizer optimization.
Bug Trace:
<unknown>:0: error: vector elements must be int/index/float type but got 'vector<4xindex>'
mlir-opt: /home/me/llvm-project/mlir/include/mlir/IR/StorageUniquerSupport.h:140: static ConcreteT mlir::detail::StorageUserBase<mlir::VectorType, mlir::Type, mlir::detail::VectorTypeStorage, mlir::detail::TypeUniquer, Trait, Trait>::get(mlir::MLIRContext *, Args...) [ConcreteT = mlir::VectorType, BaseT = mlir::Type, StorageT = mlir::detail::VectorTypeStorage, UniquerT = mlir::detail::TypeUniquer, Traits = <Trait, Trait>, Args = <llvm::ArrayRef<long>, mlir::Type, unsigned int>]: Assertion `succeeded(ConcreteT::verify(getDefaultDiagnosticEmitFn(ctx), args...))' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: mlir-opt linalg_conv2d.mlir --pass-pipeline=func.func(linalg-bufferize),func-bufferize,func.func(convert-linalg-to-affine-loops),func.func(affine-super-vectorize{virtual-vector-size=4}) --mlir-print-ir-after-all
#0 0x00000000008b7fe3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/me/llvm-project/build/bin/mlir-opt+0x8b7fe3)
#1 0x00000000008b5d8e llvm::sys::RunSignalHandlers() (/home/me/llvm-project/build/bin/mlir-opt+0x8b5d8e)
#2 0x00000000008b85cf SignalHandler(int) Signals.cpp:0:0
#3 0x00007f988b6773c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
#4 0x00007f988b10a03b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
#5 0x00007f988b0e9859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x00007f988b0e9729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#7 0x00007f988b0fb006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
#8 0x000000000180f324 (/home/me/llvm-project/build/bin/mlir-opt+0x180f324)
#9 0x000000000180f236 mlir::VectorType::get(llvm::ArrayRef<long>, mlir::Type, unsigned int) (/home/me/llvm-project/build/bin/mlir-opt+0x180f236)
#10 0x0000000000941d97 widenOp(mlir::Operation*, (anonymous namespace)::VectorizationState&) SuperVectorize.cpp:0:0
#11 0x000000000093e62b mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::callback_fn<vectorizeLoopNest(std::vector<llvm::SmallVector<mlir::AffineForOp, 2u>, std::allocator<llvm::SmallVector<mlir::AffineForOp, 2u>>>&, mlir::VectorizationStrategy const&)::$_3>(long, mlir::Operation*) SuperVectorize.cpp:0:0
#12 0x000000000186b7c2 mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/home/me/llvm-project/build/bin/mlir-opt+0x186b7c2)
#13 0x000000000186b767 mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/home/me/llvm-project/build/bin/mlir-opt+0x186b767)
#14 0x000000000093c8c4 vectorizeLoopNest(std::vector<llvm::SmallVector<mlir::AffineForOp, 2u>, std::allocator<llvm::SmallVector<mlir::AffineForOp, 2u>>>&, mlir::VectorizationStrategy const&) SuperVectorize.cpp:0:0
#15 0x000000000093c033 vectorizeLoops(mlir::Operation*, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>&, llvm::ArrayRef<long>, llvm::ArrayRef<long>, llvm::DenseMap<mlir::Operation*, llvm::SmallVector<mlir::LoopReduction, 2u>, llvm::DenseMapInfo<mlir::Operation*, void>, llvm::detail::DenseMapPair<mlir::Operation*, llvm::SmallVector<mlir::LoopReduction, 2u>>> const&) SuperVectorize.cpp:0:0
#16 0x0000000000945706 (anonymous namespace)::Vectorize::runOnOperation() SuperVectorize.cpp:0:0
#17 0x0000000001748c49 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/me/llvm-project/build/bin/mlir-opt+0x1748c49)
#18 0x00000000017494b4 mlir::detail::OpToOpPassAdaptor::runPipeline(llvm::iterator_range<llvm::pointee_iterator<std::unique_ptr<mlir::Pass, std::default_delete<mlir::Pass>>*, mlir::Pass>>, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/me/llvm-project/build/bin/mlir-opt+0x17494b4)
#19 0x000000000174daf5 auto mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_8::operator()<std::pair<mlir::Operation*, mlir::AnalysisManager>>(std::pair<mlir::Operation*, mlir::AnalysisManager>&) const Pass.cpp:0:0
#20 0x000000000174d96b mlir::LogicalResult mlir::failableParallelForEach<__gnu_cxx::__normal_iterator<std::pair<mlir::Operation*, mlir::AnalysisManager>*, std::vector<std::pair<mlir::Operation*, mlir::AnalysisManager>, std::allocator<std::pair<mlir::Operation*, mlir::AnalysisManager>>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_8&>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator<std::pair<mlir::Operation*, mlir::AnalysisManager>*, std::vector<std::pair<mlir::Operation*, mlir::AnalysisManager>, std::allocator<std::pair<mlir::Operation*, mlir::AnalysisManager>>>>, __gnu_cxx::__normal_iterator<std::pair<mlir::Operation*, mlir::AnalysisManager>*, std::vector<std::pair<mlir::Operation*, mlir::AnalysisManager>, std::allocator<std::pair<mlir::Operation*, mlir::AnalysisManager>>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_8&) Pass.cpp:0:0
#21 0x000000000174a234 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/home/me/llvm-project/build/bin/mlir-opt+0x174a234)
#22 0x0000000001748d56 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/me/llvm-project/build/bin/mlir-opt+0x1748d56)
#23 0x00000000017494b4 mlir::detail::OpToOpPassAdaptor::runPipeline(llvm::iterator_range<llvm::pointee_iterator<std::unique_ptr<mlir::Pass, std::default_delete<mlir::Pass>>*, mlir::Pass>>, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/me/llvm-project/build/bin/mlir-opt+0x17494b4)
#24 0x000000000174af99 mlir::PassManager::run(mlir::Operation*) (/home/me/llvm-project/build/bin/mlir-opt+0x174af99)
#25 0x00000000017213b6 performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>) MlirOptMain.cpp:0:0
#26 0x000000000171f6ca processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, bool, bool, bool, bool, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#27 0x000000000171f367 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool) (/home/me/llvm-project/build/bin/mlir-opt+0x171f367)
#28 0x000000000171ff5f mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/home/me/llvm-project/build/bin/mlir-opt+0x171ff5f)
#29 0x0000000000855e28 main (/home/me/llvm-project/build/bin/mlir-opt+0x855e28)
#30 0x00007f988b0eb0b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#31 0x0000000000855b2e _start (/home/me/llvm-project/build/bin/mlir-opt+0x855b2e)
Aborted
Steps to reproduce the error:
- MLIR program to run
//Filename: linalg_conv2d.mlir
#map0 = affine_map<(d0, d1, d2, d3) -> (d1)>
#map1 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
module attributes {torch.debug_module_name = "Conv2d"} {
func.func @forward(%arg0: tensor<3x3x32x32xf32>) -> tensor<3x3x30x30xf32> {
%cst = arith.constant dense<[[[[0.10544271, -0.0632548705, 0.155782789], [0.149627611, -0.174780861, -0.0418872535], [-0.0906655266, 0.040773496, -0.11680039]], [[-0.170247212, 0.147964194, 0.0955948085], [0.16221562, 0.123264179, -0.171233669], [-0.149017662, 0.117653273, -0.0985492393]], [[0.0153566934, -0.178193122, 0.0848361403], [0.12641643, 0.148512617, 0.129268169], [-0.088901095, -0.17654486, -0.142492354]]], [[[-0.0374182314, 0.0986094102, -0.0577251315], [-0.0560243614, 0.131479472, 0.116924271], [-0.117099918, -0.0475517772, -0.00175973075]], [[0.17515704, -0.022550635, -0.0670964569], [-0.0284233782, -0.127548784, -0.0599880889], [0.166481301, -0.0813012421, -0.0646878853]], [[-0.157592237, 6.752100e-02, 0.0271486603], [-0.020048758, 0.0247509405, -0.0860386863], [0.152274042, 0.0267280918, -0.00991346687]]], [[[0.0988490208, -0.010171975, 0.0832737833], [-0.0220279731, -0.03541518, 0.0541252345], [-0.174909547, -0.113369323, -0.00568466634]], [[-0.0633686408, 0.165419623, 0.119426101], [0.16138503, 0.105015323, -0.0401478037], [0.0357512757, 0.0698492751, 0.00555766048]], [[0.181034967, -0.176028982, -0.0634875447], [0.140753478, 0.114295989, 0.18496187], [0.0485140048, 0.00907306094, 0.0741938576]]]]> : tensor<3x3x3x3xf32>
%cst_0 = arith.constant dense<[0.189480066, -0.124956347, 0.0124727432]> : tensor<3xf32>
%0 = linalg.init_tensor [3, 3, 30, 30] : tensor<3x3x30x30xf32>
%1 = linalg.generic {indexing_maps = [#map0, #map1], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%cst_0 : tensor<3xf32>) outs(%0 : tensor<3x3x30x30xf32>) {
^bb0(%arg1: f32, %arg2: f32):
linalg.yield %arg1 : f32
} -> tensor<3x3x30x30xf32>
%2 = linalg.conv_2d_nchw_fchw {dilations = dense<1> : vector<2xi64>, strides = dense<1> : vector<2xi64>} ins(%arg0, %cst : tensor<3x3x32x32xf32>, tensor<3x3x3x3xf32>) outs(%1 : tensor<3x3x30x30xf32>) -> tensor<3x3x30x30xf32>
return %2 : tensor<3x3x30x30xf32>
}
}
- run the following command
mlir-opt linalg_conv2d.mlir --pass-pipeline='func.func(linalg-bufferize),func-bufferize,func.func(convert-linalg-to-affine-loops),func.func(affine-super-vectorize{virtual-vector-size=4})' --mlir-print-ir-after-all
@llvm/issue-subscribers-mlir-affine
I confirmed that this crash was fixed by commit 3974ecb7ec05 (https://reviews.llvm.org/D147679).