Repository: pytorch
Issue: max_pool1d(): `RuntimeError: [enforce fail at CPUAllocator.cpp:68] . DefaultCPUAllocator: can't allocate memory`
Labels: triaged,module: pooling

### 🐛 Describe the bug

`RuntimeError: [enforce fail at CPUAllocator.cpp:68] . DefaultCPUAllocator: can't allocate memory` for `max_pool1d()`.

### Example to reproduce

Using the following code, I set all three arguments `kernel_size`, `stride` and `dilation` to `2147483697`:

```python
import torch

# Set value of variables
i = 2147483697

self = torch.full((2, 10, 4,), 0.5, dtype=torch.float64, requires_grad=False)
kernel_size = [i]  # Set above
stride = [i]  # Set above
padding = [0]
dilation = [i]  # Set above
ceil_mode = True
torch.max_pool1d(self, kernel_size, stride, padding, dilation, ceil_mode)
```

### Result

```stacktrace
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: [enforce fail at CPUAllocator.cpp:68] . DefaultCPUAllocator: can't allocate memory: you tried to allocate 343597382720 bytes. 
Error code 12 (Cannot allocate memory)
```

### Expected behavior

An error like `RuntimeError: max_pool1d() Invalid computed output size:`, as [`pooling_output_shape()` should return an invalid output size](https://github.com/pytorch/pytorch/blob/74fe57079f00d7a74f1fccffd35a1970da3982a6/aten/src/ATen/native/MaxPooling.cpp#L74). 

For example, we could have something similar to the following, which PyTorch currently does for many incorrect input values (to clarify, PyTorch already outputs the following stacktrace in the following case, but not for the "Example to reproduce" above):
```python
import torch

self = torch.full((2, 10, 4,), 0.5, dtype=torch.float64, requires_grad=False)
kernel_size = [10]
stride = [1]
padding = [0]
dilation = [1]
ceil_mode = True
torch.max_pool1d(self, kernel_size, stride, padding, dilation, ceil_mode)
```

```stacktrace
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: max_pool1d() Invalid computed output size: -5
```

### Versions

PyTorch version: 1.10.1+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.4 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.9.7 (default, Sep 16 2021, 13:09:58)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.11.0-27-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration:
GPU 0: NVIDIA GeForce GTX 1080 Ti
GPU 1: NVIDIA GeForce GTX 1080 Ti
GPU 2: NVIDIA GeForce GTX 1080 Ti
GPU 3: NVIDIA GeForce GTX 1080 Ti

Nvidia driver version: 470.103.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.4
[pip3] torch==1.10.1
[conda] mypy-extensions           0.4.3                    pypi_0    pypi
[conda] numpy                     1.21.4                   pypi_0    pypi
[conda] torch                     1.10.1                   pypi_0    pypi