Fail to build c++ extension in pytorch 2.0.0
Labels: module: windows, module: cpp-extensions, triaged

### 🐛 Describe the bug

I am using pytorch2.0.0, vs19 and cuda11.8, and trying to build my custom c++ extension function. The code was built successfully when I was using pytorch1.11.0, vs19 and cuda11.3. The same code is built unsuccessfully when I am now using pytorch 2.0.0, vs19 and cuda11.8. I am not sure what the problem is. The following shows the error messages. Please kindly help me. Thank you very much.

```
D:\NP\self_code\det\extension\sigmoid_focal_loss\src>python setup.py build
running build
running build_ext
D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\utils\cpp_extension.py:359: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。
  warnings.warn(f'Error checking compiler version for {compiler}: {error}')
building 'sigmoid_focal_loss_cuda' extension
Emitting ninja build file D:\NP\self_code\det\extension\sigmoid_focal_loss\src\build\temp.win-amd64-cpython-38\Release\build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/2] cl /showIncludes /nologo /O2 /W3 /GL /DNDEBUG /MD /MD /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /EHsc -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages
\torch\include\torch\csrc\api\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\TH -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\in
clude" -ID:\Programs\Anaconda3\envs\NP\include -ID:\Programs\Anaconda3\envs\NP\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visua
l Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include" -c D:\NP\self_code\det\extension\sigmoid_focal_loss\src\sigmoid_focal_loss.cpp /FoD:\NP\self_code\det\extension\sigmoid_focal_loss\src\build\temp.win-amd64-cpython-38\Release\s
igmoid_focal_loss.obj -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=sigmoid_focal_loss_cuda -D_GLIBCXX_USE_CXX11_ABI=0 /std:c++17
FAILED: D:/NP/self_code/det/extension/sigmoid_focal_loss/src/build/temp.win-amd64-cpython-38/Release/sigmoid_focal_loss.obj
cl /showIncludes /nologo /O2 /W3 /GL /DNDEBUG /MD /MD /wd4819 /wd4251 /wd4244 /wd4267 /wd4275 /wd4018 /wd4190 /EHsc -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch
\include\torch\csrc\api\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\TH -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\include"
 -ID:\Programs\Anaconda3\envs\NP\include -ID:\Programs\Anaconda3\envs\NP\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Stud
io\2019\Community\VC\Tools\MSVC\14.29.30133\include" -c D:\NP\self_code\det\extension\sigmoid_focal_loss\src\sigmoid_focal_loss.cpp /FoD:\NP\self_code\det\extension\sigmoid_focal_loss\src\build\temp.win-amd64-cpython-38\Release\sigmoid
_focal_loss.obj -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=sigmoid_focal_loss_cuda -D_GLIBCXX_USE_CXX11_ABI=0 /std:c++17
注意: 包含文件:  D:\NP\self_code\det\extension\sigmoid_focal_loss\src\pytorch_cpp_helper.hpp
注意: 包含文件:   D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\torch\csrc\api\include\torch/types.h
注意: 包含文件:    D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\ATen/ATen.h
注意: 包含文件:     D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\ATen/Context.h
注意: 包含文件:      D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\ATen/CPUGeneratorImpl.h
注意: 包含文件:       D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\ATen/core/Generator.h
注意: 包含文件:        C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\stdint.h
注意: 包含文件:         C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\vcruntime.h
注意: 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\sal.h
注意: 包含文件:           C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\concurrencysal.h
注意: 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\vadefs.h
注意: 包含文件:        C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\mutex
注意: 包含文件:         C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\yvals_core.h
注意: 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xkeycheck.h
注意: 包含文件:         C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\__msvc_chrono.hpp
注意: 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\yvals.h
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\yvals.h(12): fatal error C1083: 无法打开包括文件: “crtdbg.h”: No such file or directory
[2/2] C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\nvcc --generate-dependencies-with-compile --dependency-output D:\NP\self_code\det\extension\sigmoid_focal_loss\src\build\temp.win-amd64-cpython-38\Release\sigmoid_focal
_loss_cuda.obj.d --use-local-env -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcompiler /wd4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_h
as_different_dll_interface -Xcudafe --diag_suppress=field_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -ID:\Programs\Anaconda3\envs
\NP\lib\site-packages\torch\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\torch\csrc\api\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\TH -ID:\Programs\Anaconda3\envs\NP\lib\site-pack
ages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\include" -ID:\Programs\Anaconda3\envs\NP\include -ID:\Programs\Anaconda3\envs\NP\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Communit
y\VC\Tools\MSVC\14.29.30133\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include" -c D:\NP\self_code\det\extension\sigmoid_focal_loss\src\sigmoid_focal_loss_cuda.cu -o D:\NP
\self_code\det\extension\sigmoid_focal_loss\src\build\temp.win-amd64-cpython-38\Release\sigmoid_focal_loss_cuda.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERAT
ORS__ --expt-relaxed-constexpr -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=sigmoid_focal_loss_cuda -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_89,code=compute_89 -gencode=arch=compute_89,code=sm_89
FAILED: D:/NP/self_code/det/extension/sigmoid_focal_loss/src/build/temp.win-amd64-cpython-38/Release/sigmoid_focal_loss_cuda.obj
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\nvcc --generate-dependencies-with-compile --dependency-output D:\NP\self_code\det\extension\sigmoid_focal_loss\src\build\temp.win-amd64-cpython-38\Release\sigmoid_focal_loss_
cuda.obj.d --use-local-env -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcompiler /wd4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_has_dif
ferent_dll_interface -Xcudafe --diag_suppress=field_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -ID:\Programs\Anaconda3\envs\NP\li
b\site-packages\torch\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\torch\csrc\api\include -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\include\TH -ID:\Programs\Anaconda3\envs\NP\lib\site-packages\t
orch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\include" -ID:\Programs\Anaconda3\envs\NP\include -ID:\Programs\Anaconda3\envs\NP\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\T
ools\MSVC\14.29.30133\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include" -c D:\NP\self_code\det\extension\sigmoid_focal_loss\src\sigmoid_focal_loss_cuda.cu -o D:\NP\self_
code\det\extension\sigmoid_focal_loss\src\build\temp.win-amd64-cpython-38\Release\sigmoid_focal_loss_cuda.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__
--expt-relaxed-constexpr -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=sigmoid_focal_loss_cuda -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_89,code=compute_89 -gencode=arch=compute_89,code=sm_89
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/include\crtdefs.h(10): fatal error C1083: 无法打开包括文件: “corecrt.h”: No such file or directory
sigmoid_focal_loss_cuda.cu
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\utils\cpp_extension.py", line 1893, in _run_ninja_build
    subprocess.run(
  File "D:\Programs\Anaconda3\envs\NP\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "setup.py", line 8, in <module>
    setup(name='sigmoid_focal_loss',
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\__init__.py", line 107, in setup
    return distutils.core.setup(**attrs)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
    return run_commands(dist)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
    dist.run_commands()
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
    self.run_command(cmd)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\dist.py", line 1244, in run_command
    super().run_command(command)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
    cmd_obj.run()
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run
    self.run_command(cmd_name)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
    self.distribution.run_command(command)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\dist.py", line 1244, in run_command
    super().run_command(command)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
    cmd_obj.run()
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\command\build_ext.py", line 84, in run
    _build_ext.run(self)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 345, in run
    self.build_extensions()
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\utils\cpp_extension.py", line 843, in build_extensions
    build_ext.build_extensions(self)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 467, in build_extensions
    self._build_extensions_serial()
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 493, in _build_extensions_serial
    self.build_extension(ext)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\command\build_ext.py", line 246, in build_extension
    _build_ext.build_extension(self, ext)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\Cython\Distutils\build_ext.py", line 127, in build_extension
    super(build_ext, self).build_extension(ext)
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 548, in build_extension
    objects = self.compiler.compile(
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\utils\cpp_extension.py", line 815, in win_wrap_ninja_compile
    _write_ninja_file_and_compile_objects(
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\utils\cpp_extension.py", line 1574, in _write_ninja_file_and_compile_objects
    _run_ninja_build(
  File "D:\Programs\Anaconda3\envs\NP\lib\site-packages\torch\utils\cpp_extension.py", line 1909, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error compiling objects for extension
```

### Versions

PyTorch version: 2.0.0
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 专业版
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A

Python version: 3.8.17 (default, Jul  5 2023, 20:44:21) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19045-SP0
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\cudnn_ops_train64_8.dll
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
'wmic' 不是内部或外部命令，也不是可运行的程序
或批处理文件。

Versions of relevant libraries:
[pip3] numpy==1.23.2
[pip3] torch==2.0.0
[pip3] torchaudio==2.0.0
[pip3] torchvision==0.15.0
[conda] blas                      2.117                       mkl    conda-forge
[conda] blas-devel                3.9.0              17_win64_mkl    conda-forge
[conda] libblas                   3.9.0              17_win64_mkl    conda-forge
[conda] libcblas                  3.9.0              17_win64_mkl    conda-forge
[conda] liblapack                 3.9.0              17_win64_mkl    conda-forge
[conda] liblapacke                3.9.0              17_win64_mkl    conda-forge
[conda] mkl                       2022.1.0           h6a75c08_874    conda-forge
[conda] mkl-devel                 2022.1.0           h57928b3_875    conda-forge
[conda] mkl-include               2022.1.0           h6a75c08_874    conda-forge
[conda] numpy                     1.23.2           py38h223ccf5_0    conda-forge
[conda] pytorch                   2.0.0           py3.8_cuda11.8_cudnn8_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
[conda] pytorch-cuda              11.8                 h24eeafa_5    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
[conda] pytorch-mutex             1.0                        cuda    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
[conda] torchaudio                2.0.0                    pypi_0    pypi
[conda] torchvision               0.15.0                   pypi_0    pypi

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm @vladimir-aubrecht @iremyux @Blackhex @cristianPanaite @malfet @zou3519