Repository: pytorch
Issue: Core dumped with large matmul on aarch64
Labels: module: crash,triaged,module: arm,Stale

## Issue description

I have a simple testcase that reliably crashes python on my ubuntu 64 raspberry pi, producing "Illegal instruction (core dumped)".

The crash does not happen if the tensors are much smaller.

## Code example

```
import torch
torch.mm(torch.zeros((1,1024)), torch.zeros((1024,1024)))
```
```
Illegal instruction (core dumped)
```

## System Info
```
Collecting environment information...
PyTorch version: 1.10.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 21.10 (aarch64)
GCC version: (Ubuntu 11.2.0-7ubuntu2) 11.2.0
Clang version: 13.0.0-2
CMake version: version 3.18.4
Libc version: glibc-2.34

Python version: 3.9.7 (default, Sep 10 2021, 14:59:43)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.13.0-1011-raspi-aarch64-with-glibc2.34
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.2
[pip3] torch==1.10.1
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.9.1
[conda] Could not collect

```

## GDB Backtrace
```
$ gdb --args python3 test.py
GNU gdb (Ubuntu 11.1-0ubuntu2) 11.1
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...
(No debugging symbols found in python3)
(gdb) run
Starting program: /usr/bin/python3 test.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
[New Thread 0xffffe676e150 (LWP 143528)]
[New Thread 0xffffe5f5e150 (LWP 143529)]
[New Thread 0xffffe374e150 (LWP 143530)]
[New Thread 0xffffdb82f150 (LWP 143547)]
[New Thread 0xffffdb01f150 (LWP 143548)]
[New Thread 0xffffda80f150 (LWP 143549)]

Thread 1 "python3" received signal SIGILL, Illegal instruction.
0x0000fffff3d7ba78 in exec_blas () from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
(gdb) bt
#0  0x0000fffff3d7ba78 in exec_blas ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#1  0x0000fffff3d31210 in gemm_driver.isra ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#2  0x0000fffff3d3131c in sgemm_thread_nn ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#3  0x0000fffff3d24010 in sgemm_ ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#4  0x0000fffff1217bc8 in at::native::cpublas::gemm(at::native::TransposeType, at::native::TransposeType, long, long, long, float, float const*, long, float const*, long, float, float*, long) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#5  0x0000fffff12be3e0 in at::native::addmm_impl_cpu_(at::Tensor&, at::Tensor const&, at::Tensor, at::Tensor, c10::Scalar const&, c10::Scalar const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#6  0x0000fffff12bef40 in at::native::structured_mm_out_cpu::impl(at::Tensor const&, at::Tensor const&, at::Tensor const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#7  0x0000fffff1a6785c in at::(anonymous namespace)::wrapper_mm(at::Tensor const&, at::Tensor const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#8  0x0000fffff1a678ac in c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (at::Tensor const&, at::Tensor const&), &at::(anonymous namespace)::wrapper_mm>, at::Tensor, c10::guts::typelist::typelist<at::Tensor const&, at::Tensor const&> >, at::Tensor (at::Tensor const&, at::Tensor const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&, at::Tensor const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#9  0x0000fffff18d5eb0 in at::_ops::mm::redispatch(c10::DispatchKeySet, at::Tensor const&, at::Tensor const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#10 0x0000fffff2e4a690 in torch::autograd::VariableType::(anonymous namespace)::mm(c10::DispatchKeySet, at::Tensor const&, at::Tensor const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#11 0x0000fffff2e4af84 in c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&), &torch::autograd::VariableType::(anonymous namespace)::mm>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor const&, at::Tensor const&> >, at::Tensor (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&, at::Tensor const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#12 0x0000fffff191d780 in at::_ops::mm::call(at::Tensor const&, at::Tensor const&) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so
#13 0x0000fffff64408f4 in torch::autograd::THPVariable_mm(_object*, _object*, _object*) ()
   from /home/ubuntu/.local/lib/python3.9/site-packages/torch/lib/libtorch_python.so
#14 0x00000000004c35d0 in ?? ()
#15 0x00000000004a0ff8 in _PyObject_MakeTpCall ()
#16 0x0000000000498e54 in _PyEval_EvalFrameDefault ()
#17 0x0000000000492d14 in ?? ()
#18 0x0000000000492aa0 in _PyEval_EvalCodeWithName ()
#19 0x000000000058358c in PyEval_EvalCode ()
#20 0x00000000005b3aa8 in ?? ()
#21 0x00000000005acf10 in ?? ()
#22 0x00000000005b29a4 in ?? ()
#23 0x00000000005b2298 in PyRun_SimpleFileExFlags ()
#24 0x00000000005a39b8 in Py_RunMain ()
#25 0x00000000005737b8 in Py_BytesMain ()
#26 0x0000fffff7d33ffc in __libc_start_call_main (
    main=main@entry=0x5736b4 <_start+52>, argc=argc@entry=2, 
    argv=argv@entry=0xfffffffff318)
    at ../sysdeps/nptl/libc_start_call_main.h:58
#27 0x0000fffff7d340c8 in __libc_start_main_impl (main=0x5736b4 <_start+52>, 
    argc=2, argv=0xfffffffff318, init=<optimized out>, fini=<optimized out>, 
    rtld_fini=<optimized out>, stack_end=<optimized out>)
    at ../csu/libc-start.c:409
#28 0x00000000005736b0 in _start ()
```


cc @malfet