Estimate effort needed to bring PyTorch to Windows Arm64
Labels: module: windows, triaged

Past efforts enabled Windows Arm64 support for libtorch. This effort is now [under testing](https://github.com/pytorch/pytorch/issues/92304).

Next step for this effort is to bring rest of Pytorch to Arm64 and first step is investigate what is missing. That should allow us to evaluate amount of work needed.

### Goals of this ticket
- Review attached list of dependencies (something might be missing).
- Identify why we need each of those dependencies.
- Identify which dependencies are missing Arm64 support.

### Pytorch dependencies
- [ ] CUDA
- [ ] Custom Protobuf
- [ ] Threads
- [ ] protobuf
- [ ] BLAS
- [ ] FFTW
- [ ] pthreadpool
- [ ] Caffe2
- [ ] QNNPACK
- [ ] PYTORCH_QNNPACK
- [ ] NNPACK
- [ ] XNNPACK
- [ ] Vulkan
- [ ] gflags
- [ ] Google-glog
- [ ] Googletest and benchmark
- [ ] FBGEMM
- [ ] LMDB
- [ ] LevelDB
- [ ] Snappy
- [ ] NUMA
- [ ] ZMQ
- [ ] Redis
- [ ] OpenCV
- [ ] FFMPEG
- [ ] EIGEN
- [ ] Python
- [ ] pybind11
- [ ] MPI
- [ ] OpenMP
- [ ] Android
- [ ] Kernel asserts
- [ ] LLVM
- [ ] cuDNN
- [ ] HIP
- [ ] ROCm
- [ ] NCCL
- [ ] UCC
- [ ] CUB
- [ ] Onnx
- [ ] Kineto

### Minimum viable product
For the purpose of the estimation of an initial effort to bring PyTorch to Windows Arm64 we define the MVP as a locally and natively compiled PyTorch binaries with a minimum set of dependencies enabling CPU-only features passing the PyTorch core tests suites (`test_autograd.py`, `test_modules.py`, `test_nn.py`, `test_ops.py`, `test_ops_fwd_gradients.py`, `test_ops_gradients.py`, `test_ops_jit.py`, and `test_torch.py`).

### Gap analysis
Although the PyTorch codebase itself currently compiles on Windows Arm64 using Visual Studion 2022 (Build Tools) fine, the resulting binaries are not 100% functional, in a sense of MVP definition, and most of the issues originate from the dependencies (especially OpenBLAS).

From the external PyTorch dependencies, only the following are needed to fullfill the NVP, i.e., to pass all the core tests:
- [OpenBLAS](https://github.com/xianyi/OpenBLAS) - The most of the test failures listed in the issues bellow originate from this dependency.
- [SciPy ](https://github.com/scipy/scipy) - This Python package is needed for running the tests and it is not a direct dependency of PyTorch itself. Official PIP Windows Arm64 pre-built package is not available and compiling it with `pip install` fails due to missing Fortran compiler (adding it to the Windows Arm64 system is not a straightforward task). There is a 3rd party package available at https://github.com/cgohlke/win_arm64-wheels that works.
- [NumPy](https://github.com/numpy/numpy) - The above 3rd party SciPy Windows Arm64 package does not work with the official NumPy PIP package. The 3rd party NumPy package from the same source needs to be used.

Other dependencies might be selected from the PyTorch codebase (submodules) and do not require any changes except of:
- [cpuinfo](https://github.com/pytorch/cpuinfo) - The upstream main branch contains changes needed for Windows Arm64 already, updating the PyTorch repository to that version will require update of [XNNPACK](https://github.com/google/XNNPACK) and fix of Buck build in the [PyTorch](https://github.com/pytorch/pytorch) repository. Some additional changes for particular CPUs might be reqired.

Currently, to pass all PyTorch core tests, the following issues has to be relolved, they fall into two categories, the issues that either crash or block the entire test run:
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=29013308 - have preliminary fix
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=29020667 - RC unknown, either deadlock or "infinite" loop of some sort due to using uninitialized value in loop condition.
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=29023111 - RC unknown, access violation connected to C++ template expansion.

and "regular" test failures:
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27702131 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27702449 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27702773 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27703046 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27703676 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27703801 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27705583 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27705812 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=28831055 - RC unknown
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=28838928 - RC unknown

Additionally, the following tasks should be considered as well:
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=29035519 - invalid VCRuntime detection
- https://github.com/orgs/pytorch/projects/27/views/19?pane=issue&itemId=27700678 - investigation task

### Technical Notes
- Currently, some of the tests need to be explicitly excluded from the run as they are either crashing the test run entirely or stucking forever. For the list of those excluded tests refer to this VSCode launch.json file https://github.com/Blackhex/pytorch/commit/d0706220ae3437be1c751149c63807d45abda268.

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm