[iOS GPU] Implement view and reshape in metal shaders (#54107)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54107
The current implementation doesn't change the underlying texture's shape. This diff converts MPSImage from one shape to the other. The way we'll do it is we implement this as an elementwise kernel. We have a thread grid of size (N2, C2, H2, W2) with a thread for each output element, and we compute the "linear index" of the output element, and convert it to the equivalent "linear index" of the input element. This is the known as sub2ind/ind2sub conversion in MATLAB, ravel_multi_index in numpy, etc. https://github.com/cupy/cupy/blob/a08841a8e18d285652df0f7a2a25f5ae5bc1a897/cupy/indexing/generate.py#L301-L304 is a clean generic version of ind2sub.
ghstack-source-id: 124113407
Test Plan:
```
2021-03-16 00:27:31.280761-0700 PyTorchPlayground[16024:6249832] [bool test_view()],[1 10 2 2 ],[SUCCEED]
2021-03-16 00:27:31.282833-0700 PyTorchPlayground[16024:6249832] [bool test_view2()],[1 10 2 2 ],[SUCCEED]
2021-03-16 00:27:31.285320-0700 PyTorchPlayground[16024:6249832] [bool test_view3()],[5 8 ],[SUCCEED]
2021-03-16 00:27:31.286929-0700 PyTorchPlayground[16024:6249832] [bool test_view4()],[5 8 ],[SUCCEED]
```
- Sandcastle CI
- CircleCI
Reviewed By: SS-JIA
Differential Revision: D27074719
fbshipit-source-id: 445f55fefeb9cc7b3eeab106b6d567facef58343