Repository: pytorch
Issue: [1.8.x] Build from source with USE_VULKAN fails (requires C++20 instead of C++14)
Labels: module: build,triaged

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

With Visual Studio 2019, build from source (directly invoke CMakeLists) with `USE_VULKAN ON` (and `USE_VULKAN_SHADERC_RUNTIME ON`) fails due to usage of C++20 features in libtorch source code.

## To Reproduce

Steps to reproduce the behavior:

1. Launch a build from source of pytorch with `USE_VULKAN ON` and `USE_VULKAN_SHADERC_RUNTIME ON`

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

It should compile without having to force C++20 manually, CMakeLists should handle that, or C++20 features should be removed.

## Environment

 - PyTorch Version (e.g., 1.0): 1.8.0
 - OS (e.g., Linux): Windows 10
 - How you installed PyTorch (`conda`, `pip`, source): I build from source
 - Build command you used (if compiling from source): Probably something like `cmake -G "Ninja" -DUSE_VULKAN=ON -DUSE_VULKAN_SHADERC_RUNTIME=ON -DUSE_SYSTEM_LIBS=ON -DUSE_CUDA=OFF -DBUILD_PYTHON=OFF ..` then `cmake --build .`. But I'm packaging libtorch for conan with all third party libraries unvendored, so there is a level of abstraction between conan call and actual build command call (for example a long line of paths added to CMAKE_MODULE_PATH and CMAKE_PREFIX_PATH) + a big patch to fix CMakeLists of libtorch (I didn't change CXX_STANDARD behavior).
 - Python version: 3.9.1
 - CUDA/cuDNN version: N/A (disabled)
 - GPU models and configuration: Doesn't really matter here
 - Any other relevant information: Visual Studio 2019 (cl 19.28.29913 / VC++ 14.28)

## Additional context

Before trying to build with Vulkan support, I had to fix https://github.com/pytorch/pytorch/blob/master/cmake/VulkanCodegen.cmake for Windows because `set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}:${CMAKE_CURRENT_LIST_DIR}/..")` is obviously broken on Windows (separator is `;`).

log of build error:

```
[177/1263] Building CXX object source_subfolder\caffe2\CMakeFiles\torch_cpu.dir\__\aten\src\ATen\native\Copy.cpp.obj
FAILED: source_subfolder/caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/native/Copy.cpp.obj
C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\cl.exe  /nologo /TP -DENABLE_HLSL -DENABLE_OPT -DGFLAGS_DLL_DECLARE_FLAG="" -DGFLAGS_DLL_DEFINE_FLAG="" -DGLOG_NO_ABBREVIATED_SEVERITIES -DGOOGLE_GLOG_DLL_DECL="" -DLIBJPEG_STATIC -DLZMA_API_STATIC -DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx -DSODIUM_STATIC=1 -DUSE_DISTRIBUTED -DUSE_EXTERNAL_MZCRC -DWIN32_LEAN_AND_MEAN -DZMQ_STATIC -D_CRT_SECURE_NO_DEPRECATE=1 -Dtorch_cpu_EXPORTS -Iaten\src -I..\source_subfolder\aten\src -Isource_subfolder -I..\source_subfolder -Isource_subfolder\caffe2\contrib\aten -I..\source_subfolder\torch\csrc\api -I..\source_subfolder\torch\csrc\api\include -I..\source_subfolder\caffe2\aten\src\TH -Isource_subfolder\caffe2\aten\src\TH -Isource_subfolder\caffe2\aten\src -Isource_subfolder\caffe2\..\aten\src -Isource_subfolder\caffe2\..\aten\src\ATen -I..\source_subfolder\torch\csrc -I..\source_subfolder\third_party\miniz-2.0.8 -I..\source_subfolder\aten\src\TH -Ivulkan -I..\source_subfolder\aten\..\third_party\catch\single_include -I..\source_subfolder\aten\src\ATen\.. -Isource_subfolder\caffe2\aten\src\ATen -I..\source_subfolder\caffe2\core\nomnigraph\include -I..\source_subfolder\c10\.. -I. -IC:\Users\spaceim\.conan_short\1e9abd\1\include -IC:\Users\spaceim\.conan\data\eigen\3.3.9\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include -IC:\Users\spaceim\.conan\data\eigen\3.3.9\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include\eigen3 -I..\source_subfolder\caffe2 -IC:\Users\spaceim\.conan\data\zlib\1.2.11\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include -IC:\Users\spaceim\.conan\data\gflags\2.2.2\_\_\package\276ecda833039958fbea98273ce18f54031274b8\include -IC:\Users\spaceim\.conan\data\glog\0.4.0\_\_\package\7388bbc133673b4a6d4abbc3dc58a3c2c9fc3fa4\include -IC:\Users\spaceim\.conan\data\openblas\0.3.13\_\_\package\fc5ffe128dfe443039d26bf5230fc292084d3ce2\include -IC:\Users\spaceim\.conan\data\openblas\0.3.13\_\_\package\fc5ffe128dfe443039d26bf5230fc292084d3ce2\include\openblas -IC:\Users\spaceim\.conan\data\cpuinfo\cci.20201217\_\_\package\a8513eb4ca474258f0f9558c938b9c1f16df8fc0\include -IC:\Users\spaceim\.conan\data\xnnpack\cci.20210310\_\_\package\3f67201969d3f509bbab9ecdcb5c10980682bc6e\include -IC:\Users\spaceim\.conan\data\fp16\cci.20200514\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include -IC:\Users\spaceim\.conan\data\psimd\cci.20200517\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include -IC:\Users\spaceim\.conan\data\fxdiv\cci.20200417\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include -IC:\Users\spaceim\.conan\data\pthreadpool\cci.20210218\_\_\package\1f8777fe8cbd10cd15e97f26a0a770910d0a2e7b\include -IC:\Users\spaceim\.conan\data\vulkan-headers\1.2.170.0\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include -IC:\Users\spaceim\.conan\data\vulkan-headers\1.2.170.0\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\res\vulkan\registry -IC:\Users\spaceim\.conan\data\shaderc\2019.0\_\_\package\16ecbb1ef331d7aa17e96f6c5e60f8946c93bc82\include -IC:\Users\spaceim\.conan_short\d09c18\1\include -IC:\Users\spaceim\.conan_short\48eba3\1\include -IC:\Users\spaceim\.conan\data\spirv-headers\1.5.3\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include -IC:\Users\spaceim\.conan\data\leveldb\1.22\_\_\package\768c5aae763cd1373b3ddde9f5511f96ea361b62\include -IC:\Users\spaceim\.conan\data\snappy\1.1.8\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include -IC:\Users\spaceim\.conan\data\zeromq\4.3.4\_\_\package\d01371535f7dae3ecb776ca4941c99ad2c31d60e\include -IC:\Users\spaceim\.conan_short\5df6d8\1\include -IC:\Users\spaceim\.conan_short\f00a1e\1\include -IC:\Users\spaceim\.conan\data\libjpeg\9d\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include -IC:\Users\spaceim\.conan\data\jasper\2.0.25\_\_\package\264d5d4a0e3e283cd524e2a58344075802f4577c\include -IC:\Users\spaceim\.conan\data\libpng\1.6.37\_\_\package\d140711d95cc16a85766a8fc3a551dfafe84cf63\include -IC:\Users\spaceim\.conan\data\openexr\2.5.5\_\_\package\d140711d95cc16a85766a8fc3a551dfafe84cf63\include\OpenEXR -IC:\Users\spaceim\.conan\data\openexr\2.5.5\_\_\package\d140711d95cc16a85766a8fc3a551dfafe84cf63\include -IC:\Users\spaceim\.conan\data\libtiff\4.2.0\_\_\package\a08a8e56550da57f6f3d93bb076a90cc6c19cfa2\include -IC:\Users\spaceim\.conan\data\libdeflate\1.7\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include -IC:\Users\spaceim\.conan\data\xz_utils\5.2.5\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include -IC:\Users\spaceim\.conan\data\jbig\20160605\_\_\package\1c06f8aa5b65435590877732bd94377a1ed95260\include -IC:\Users\spaceim\.conan\data\zstd\1.4.9\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include -IC:\Users\spaceim\.conan\data\libwebp\1.1.0\_\_\package\638042d3fd356128c913f5e725646a0c2af264c7\include -IC:\Users\spaceim\.conan\data\quirc\1.1\_\_\package\8e7d69ac1d5596196386f046159aacd9644a7227\include -IC:\Users\spaceim\.conan\data\onnx\1.8.1\_\_\package\0457621776ea7f1c9786e0c5742e013cb2b08370\include -IC:\Users\spaceim\.conan\data\foxi\cci.20210217\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include -IC:\Users\spaceim\.conan\data\fmt\7.1.3\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab\include /DWIN32 /D_WINDOWS  /GR /EHsc /MP8 /w /bigobj -DUSE_PTHREADPOOL -DNDEBUG -DUSE_XNNPACK -DUSE_VULKAN -DUSE_VULKAN_API -DUSE_VULKAN_SHADERC_RUNTIME -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION /MD /O2 /Ob2 /DNDEBUG /w /bigobj -DNDEBUG -DUSE_GCC_GET_CPUID -DUSE_AVX -DUSE_AVX2 -DTH_HAVE_THREAD /EHsc /DNOMINMAX /wd4267 /wd4251 /wd4522 /wd4838 /wd4305 /wd4244 /wd4190 /wd4101 /wd4996 /wd4275 /bigobj -O2 -DCAFFE2_BUILD_MAIN_LIB -DONNX_BUILD_MAIN_LIB -std:c++14 /showIncludes /Fosource_subfolder\caffe2\CMakeFiles\torch_cpu.dir\__\aten\src\ATen\native\Copy.cpp.obj /Fdsource_subfolder\caffe2\CMakeFiles\torch_cpu.dir\ /FS -c ..\source_subfolder\aten\src\ATen\native\Copy.cpp
..\source_subfolder\aten\src\ATen/native/vulkan/api/Shader.h(234): error C7555: use of designated initializers requires at least '/std:c++latest'
..\source_subfolder\aten\src\ATen/native/vulkan/api/Shader.h(249): error C7555: use of designated initializers requires at least '/std:c++latest'
..\source_subfolder\aten\src\ATen/native/vulkan/ops/Tensor.h(395): error C2248: 'at::native::vulkan::ops::vTensor::View::State': cannot access private class declared in class 'at::native::vulkan::ops::vTensor::View'
..\source_subfolder\aten\src\ATen/native/vulkan/ops/Tensor.h(275): note: see declaration of 'at::native::vulkan::ops::vTensor::View::State'
..\source_subfolder\aten\src\ATen/native/vulkan/ops/Tensor.h(229): note: see declaration of 'at::native::vulkan::ops::vTensor::View'
[184/1263] Building CXX object source_subfolder\caffe2\CMakeFiles\torch_cpu.dir\__\aten\src\ATen\native\MaxUnpooling.cpp.obj
```

Tried to force C++20 in Torch top CMakeLists, but it quickly fails in several compilation units of `Caffe2_perfkernels_avx*` targets.

cc @malfet @seemethere @walterddr