Repository: pytorch
Issue: `torch.mm` produces wrong result on cpu when using in-place computation
Labels: module: docs,triaged

### 🐛 Describe the bug

If I use `out` to specify the output tensor to be the same as the input tensor, `torch.mm` gives wrong result on cpu. Using`torch.mm`  on cpu w/o `out` or on cuda gives the same correct result.

Here is the minimized code to reproduce the bug:
```
import torch
torch.manual_seed(420)
torch.cuda.manual_seed_all(420)
A = torch.rand(50, 50)
B = torch.clone(A).cuda()
C = torch.clone(A)
torch.mm(C, C, out=C)
print("cpu in place:", C)  # CPU (in place) gives wrong results
D = torch.mm(A, A)
print("cpu:", D)
print(torch.allclose(C, D)) # False

torch.mm(B, B, out=B)
print("GPU in place:", B)  # GPU gives right answer
print(torch.allclose(B.cpu(), D)) # True


```
outputs:
```
cpu in place: tensor([[1.2465e+01, 1.1267e+01, 1.2204e+01,  ..., 8.7870e+02, 1.0072e+04,
         1.0345e+04],
        [1.2971e+01, 1.1560e+01, 1.1516e+01,  ..., 8.3331e+02, 9.5578e+03,
         9.8192e+03],
        [1.3755e+01, 1.3913e+01, 1.3279e+01,  ..., 9.6774e+02, 1.1126e+04,
         1.1423e+04],
        ...,
        [1.2447e+01, 1.1978e+01, 1.1767e+01,  ..., 8.3779e+02, 9.6226e+03,
         9.8825e+03],
        [1.2835e+01, 1.0712e+01, 1.0594e+01,  ..., 7.8456e+02, 8.9946e+03,
         9.2391e+03],
        [1.1591e+01, 9.3684e+00, 1.0208e+01,  ..., 7.8547e+02, 9.0087e+03,
         9.2529e+03]])
cpu: tensor([[12.4649, 11.2666, 12.2036,  ..., 10.9338, 12.4515, 11.9901],
        [12.9706, 11.5600, 11.5161,  ..., 10.0883, 11.9705, 11.6685],
        [13.7549, 13.9132, 13.2790,  ..., 11.9514, 16.0034, 13.1333],
        ...,
        [12.4474, 11.9785, 11.7670,  ...,  9.8250, 13.5130, 10.8965],
        [12.8352, 10.7118, 10.5938,  ...,  9.0758, 12.7024, 10.3281],
        [11.5908,  9.3684, 10.2079,  ...,  9.5821, 11.1185,  9.8437]])
False
GPU in place: tensor([[12.4649, 11.2666, 12.2036,  ..., 10.9338, 12.4515, 11.9901],
        [12.9706, 11.5600, 11.5161,  ..., 10.0883, 11.9705, 11.6685],
        [13.7549, 13.9132, 13.2790,  ..., 11.9514, 16.0034, 13.1333],
        ...,
        [12.4474, 11.9785, 11.7670,  ...,  9.8250, 13.5130, 10.8965],
        [12.8352, 10.7118, 10.5938,  ...,  9.0758, 12.7024, 10.3281],
        [11.5908,  9.3684, 10.2079,  ...,  9.5821, 11.1185,  9.8437]],
       device='cuda:0')
True
```

### Versions

PyTorch version: 1.12.1+cu113
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
CMake version: version 3.22.6
Libc version: glibc-2.26

Python version: 3.7.14 (default, Sep  8 2022, 00:06:44)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.10.133+-x86_64-with-Ubuntu-18.04-bionic
Is CUDA available: True
CUDA runtime version: 11.1.105
GPU models and configuration: GPU 0: Tesla T4
Nvidia driver version: 460.32.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.21.6
[pip3] torch==1.12.1+cu113
[pip3] torchaudio==0.12.1+cu113
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.13.1
[pip3] torchvision==0.13.1+cu113
[conda] Could not collect

cc @svekars @holly1238