Repository: pytorch
Issue: [dynamo] Detect mkldnn_max_pool2d/mkldnn view errors at tracing time
Labels: low priority,triaged,oncall: pt2,module: fakeTensor,module: dynamo

Discovered with https://github.com/pytorch/pytorch/pull/126341

Original repro: `PYTORCH_TEST_WITH_DYNAMO=1 pytest test/test_mkldnn.py::TestMkldnnCPU::test_max_pool_unsupported_cpu` and `PYTORCH_TEST_WITH_DYNAMO=1 pytest test/test_mkldnn.py::TestMkldnnCPU::test_view_cpu`.

Minified repro:
```python
import torch

def f(x):
    try:
        x = x.view(x.size(0), -1)
    except:
        return x + 1
    return x + 2

opt_f = torch.compile(f, backend="eager")
x = torch.randn(3, 4, 5, dtype=torch.float32).to_mkldnn()
opt_f(x)
```

Output:
```
$ TORCH_LOGS="graph_code" python playground3.py 
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code] TRACED GRAPH
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]  ===== __compiled_fn_1 =====
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]  /data/users/williamwen/pytorch2/torch/fx/_lazy_graph_module.py class GraphModule(torch.nn.Module):
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]     def forward(self, L_x_: "f32[3, 4, 5]"):
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         l_x_ = L_x_
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         # File: /data/users/williamwen/pytorch2/playground3.py:5 in f, code: x = x.view(x.size(0), -1)
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         x: "f32[3, 20]" = l_x_.view(3, -1);  l_x_ = None
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         # File: /data/users/williamwen/pytorch2/playground3.py:8 in f, code: return x + 2
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         add: "f32[3, 20]" = x + 2;  x = None
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         return (add,)
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code] 
Traceback (most recent call last):
  File "/data/users/williamwen/pytorch2/playground3.py", line 12, in <module>
    opt_f(x)
  File "/data/users/williamwen/pytorch2/torch/_dynamo/eval_frame.py", line 414, in _fn
    return fn(*args, **kwargs)
  File "/data/users/williamwen/pytorch2/playground3.py", line 3, in f
    def f(x):
  File "/data/users/williamwen/pytorch2/torch/_dynamo/eval_frame.py", line 548, in _fn
    return fn(*args, **kwargs)
  File "<eval_with_key>.1", line 6, in forward
RuntimeError: Currently Mkldnn tensor does not support view. Change to use reshape instead
```

cc @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang @eellison @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng