tenstorrent / tt-mlir

Tenstorrent MLIR compiler
https://tenstorrent.github.io/tt-mlir/
Apache License 2.0
51 stars 7 forks source link

1d tensors erroring out in affine maps code #471

Closed svuckovicTT closed 2 weeks ago

svuckovicTT commented 3 weeks ago

I was writing the embedding op and hit an issue with affine maps. I realized that if I add extra dims to my tensors (1d->2d) in test/ttmlir/Dialect/TTNN/embedding/simple_embedding.mlir test, the test passes. So I'm suspecting there's an edge case where 1d tensors cause an error.

@nsmithtt since you're closest to this code, would you mind taking a look?

Repro:

In the test file, I've added both the working and non-working examples, with the working one commented out.

ttmlir-opt: /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TT/IR/TTOpsTypes.cpp:294: mlir::AffineMap collapsedLinearAffineMap(::mlir::MLIRContext *, ::llvm::ArrayRef<int64_t>, ::llvm::ArrayRef<int64_t>, ::llvm::ArrayRef<std::pair<std::int64_t, std::int64_t>>): Assertion `end > 0' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: ./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn test/ttmlir/Dialect/TTNN/embedding/simple_embedding.mlir --mlir-print-stacktrace-on-diagnostic
 #0 0x00007f72ccd82f47 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/ttmlir-toolchain/lib/libLLVM.so.19.0git+0x1063f47)
 #1 0x00007f72ccd810a2 llvm::sys::RunSignalHandlers() (/opt/ttmlir-toolchain/lib/libLLVM.so.19.0git+0x10620a2)
 #2 0x00007f72ccd82275 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f72cb7f5520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f72cb8499fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f72cb8499fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f72cb8499fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f72cb7f5476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f72cb7db7f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f72cb7db71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f72cb7ece96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000055d286b11379 collapsedLinearAffineMap(mlir::MLIRContext*, llvm::ArrayRef<long>, llvm::ArrayRef<long>, llvm::ArrayRef<std::pair<long, long>>) /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TT/IR/TTOpsTypes.cpp:287:14
#12 0x000055d286b110a4 mlir::tt::LayoutAttr::get(mlir::MLIRContext*, llvm::ArrayRef<long>, mlir::Type, mlir::tt::MemorySpace, mlir::tt::GridAttr, llvm::ArrayRef<std::pair<long, long>>, mlir::tt::OOBVal) /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TT/IR/TTOpsTypes.cpp:353:17
#13 0x000055d286b11ba5 mlir::tt::LayoutAttr::get(mlir::MLIRContext*, mlir::RankedTensorType, mlir::tt::MemorySpace, mlir::tt::GridAttr, llvm::ArrayRef<std::pair<long, long>>, mlir::tt::OOBVal) /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TT/IR/TTOpsTypes.cpp:367:10
#14 0x000055d286bcc3e0 mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)::operator()(mlir::RankedTensorType) const /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TTIR/Transforms/Passes.cpp:444:24
#15 0x000055d286bcc249 std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&)::operator()(mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&) const /opt/ttmlir-toolchain/include/mlir/Transforms/DialectConversion.h:359:43
#16 0x000055d286bcc206 std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)::operator()(mlir::Type, llvm::SmallVectorImpl<mlir::Type>&) const /opt/ttmlir-toolchain/include/mlir/Transforms/DialectConversion.h:380:14
#17 0x000055d286bcc190 mlir::RankedTensorType std::__invoke_impl<std::optional<llvm::LogicalResult>, std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)&, mlir::Type, llvm::SmallVectorImpl<mlir::Type>&>(std::__invoke_other, mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&, mlir::Type&&, llvm::SmallVectorImpl<mlir::Type>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:14
#18 0x000055d286bcc115 std::enable_if<is_invocable_r_v<mlir::RankedTensorType, mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::Type, llvm::SmallVectorImpl<mlir::Type>&>, mlir::RankedTensorType>::type std::__invoke_r<std::optional<llvm::LogicalResult>, std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)&, mlir::Type, llvm::SmallVectorImpl<mlir::Type>&>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&, mlir::Type&&, llvm::SmallVectorImpl<mlir::Type>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:114:9
#19 0x000055d286bcc02d std::_Function_handler<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&), std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, std::enable_if<std::is_invocable_v<mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType), mlir::RankedTensorType>, std::function<std::optional<llvm::LogicalResult> (mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>>::type mlir::TypeConverter::wrapCallback<mlir::RankedTensorType, mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::RankedTensorType, llvm::SmallVectorImpl<mlir::Type>&)>(mlir::tt::ttir::TTIRLayoutTensorTypeConverter::TTIRLayoutTensorTypeConverter(mlir::MLIRContext*, mlir::tt::MemorySpace)::'lambda'(mlir::RankedTensorType)&&) const::'lambda'(mlir::Type, llvm::SmallVectorImpl<mlir::Type>&)>::_M_invoke(std::_Any_data const&, mlir::Type&&, llvm::SmallVectorImpl<mlir::Type>&) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/std_function.h:290:9
#20 0x000055d286c73310 mlir::TypeConverter::convertType(mlir::Type, llvm::SmallVectorImpl<mlir::Type>&) const (./build/bin/ttmlir-opt+0x2958310)
#21 0x000055d286c73863 mlir::TypeConverter::convertTypes(mlir::TypeRange, llvm::SmallVectorImpl<mlir::Type>&) const (./build/bin/ttmlir-opt+0x2958863)
#22 0x000055d286bcce72 bool mlir::tt::ttir::TTIRLayoutTensorTypeRewriter::convertTypes<mlir::OperandRange>(mlir::OperandRange, llvm::SmallVector<mlir::Type, 6u>&) const /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TTIR/Transforms/Passes.cpp:460:30
#23 0x000055d286bccce5 mlir::tt::ttir::TTIRLayoutTensorTypeRewriter::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TTIR/Transforms/Passes.cpp:504:16
#24 0x000055d286ca4412 void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::'lambda'()>(long) PatternApplicator.cpp:0:0
#25 0x000055d286ca38f3 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (./build/bin/ttmlir-opt+0x29888f3)
#26 0x000055d286c83add (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#27 0x000055d286c83bfb void llvm::function_ref<void ()>::callback_fn<(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::'lambda2'()>(long) GreedyPatternRewriteDriver.cpp:0:0
#28 0x000055d286c82963 mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (./build/bin/ttmlir-opt+0x2967963)
#29 0x000055d2853c7505 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (./build/bin/ttmlir-opt+0x10ac505)
#30 0x000055d286bc8e45 mlir::tt::ttir::TTIRLayout::runOnOperation() /localdev/svuckovic/_workspace/repos/tt-mlir/lib/Dialect/TTIR/Transforms/Passes.cpp:635:18
#31 0x000055d286d2d4da void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda0'()>(long) Pass.cpp:0:0
#32 0x000055d286d2bbc8 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./build/bin/ttmlir-opt+0x2a10bc8)
#33 0x000055d286d2bd4e mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./build/bin/ttmlir-opt+0x2a10d4e)
#34 0x000055d286d2bea9 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (./build/bin/ttmlir-opt+0x2a10ea9)
#35 0x000055d286d2c190 mlir::PassManager::run(mlir::Operation*) (./build/bin/ttmlir-opt+0x2a11190)
#36 0x000055d2860f1223 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#37 0x000055d2860f16fe processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#38 0x000055d2860f17e3 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#39 0x000055d286e66cdf mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (./build/bin/ttmlir-opt+0x2b4bcdf)
#40 0x000055d2860ee325 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./build/bin/ttmlir-opt+0x1dd3325)
#41 0x000055d2860f19e6 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./build/bin/ttmlir-opt+0x1dd69e6)
#42 0x000055d2860f1b79 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./build/bin/ttmlir-opt+0x1dd6b79)
#43 0x000055d28511735b main /localdev/svuckovic/_workspace/repos/tt-mlir/tools/ttmlir-opt/ttmlir-opt.cpp:21:7
#44 0x00007f72cb7dcd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#45 0x00007f72cb7dce40 call_init ./csu/../csu/libc-start.c:128:20
#46 0x00007f72cb7dce40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#47 0x000055d285117225 _start (./build/bin/ttmlir-opt+0xdfc225)