Repository: pytorch
Issue: `nn.functional.embedding_bag` Trigger out-of-bound Read under Compute Sanitizer
Labels: module: cuda,triaged

### 🐛 Describe the bug

A test case for `torch.nn.functional.embedding_bag` behaves differently under CPU and GPU.
The test is shown as follows:
```python
import torch

def test():
    arg_1 = torch.randint(-2048,256,[8], dtype=torch.int64).clone().cuda()
    arg_2 = torch.rand([10, 3], dtype=torch.float64).clone().cuda()
    arg_3 = torch.randint(-8192,128,[2], dtype=torch.int64).clone().cuda()
    arg_4 = False
    res = torch.nn.functional.embedding_bag(arg_1,arg_2,arg_3,arg_4,)

test()
```
The test with `.cuda()` is supposed to be run under GPU and it exits with `returncode=0`. If we remove the `.cuda()`, i.e, run the test under CPU, it reports an invalid argument error with `returncode=1`:
```
IndexError: select(): index -1923 out of range for tensor of size [10, 3] at dimension 0
```
Additionally, we use compute sanitizer to run the GPU version test and it reports an out-of-bound read error:
```
# command: compute-sanitizer python3 test.py
========= COMPUTE-SANITIZER
========= Invalid __global__ read of size 8 bytes
=========     at 0x310 in void at::native::<unnamed>::renorm_kernel<double, double, long>(T1 *, T3 *, T2, T2, long, long, long, long *)
=========     by thread (0,0,0) in block (0,0,0)
=========     Address 0x7fb982ffa800 is out of bounds
=========     and is 22,528 bytes before the nearest allocation at 0x7fb983000000 of size 2,097,152 bytes
========= 
========= Invalid __global__ read of size 8 bytes
=========     at 0x310 in void at::native::<unnamed>::renorm_kernel<double, double, long>(T1 *, T3 *, T2, T2, long, long, long, long *)
=========     by thread (1,0,0) in block (0,0,0)
=========     Address 0x7fb982ffa808 is out of bounds
=========     and is 22,520 bytes before the nearest allocation at 0x7fb983000000 of size 2,097,152 bytes
=========     ... (omitte)
========= ERROR SUMMARY: 21 errors
```

### Versions

```
PyTorch version: 1.14.0a0+git81042d3
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.1 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: 11.1.0-6
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-52-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.6.124
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090

Nvidia driver version: 515.65.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.4.1
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.21.5
[pip3] torch==1.14.0a0+git81042d3
[pip3] torchvision==0.13.1
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.3.1               h2bc3f7f_2  
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0            py39h7f8727e_0  
[conda] mkl_fft                   1.3.1            py39hd3c417c_0  
[conda] mkl_random                1.2.2            py39h51133e4_0  
[conda] numpy                     1.21.5           py39he7a7128_1  
[conda] numpy-base                1.21.5           py39hf524024_1  
[conda] numpydoc                  1.2                pyhd3eb1b0_0
```

cc @ngimel