Repository: pytorch
Issue: torch.cppExtension won't work with wsl2
Labels: triaged,module: wsl

### 🐛 Describe the bug

oper.cu:
`
#include <torch/torch.h>
#include <c10/cuda/CUDAStream.h>
#include <c10/cuda/CUDAGuard.h>
#include <torch/extension.h>


torch::Tensor TS_DELAY_FIXED_PERIOD(torch::Tensor &ten_x,int64_t period) {
    torch::Tensor ten_re=torch::empty_like(ten_x);
    return ten_re.squeeze();
}


PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def("TS_DELAY_FIXED_PERIOD", &TS_DELAY_FIXED_PERIOD,"TS_DELAY_FIXED_PERIOD kernel warpper");
    
}
`

test.py:
`
from torch.utils.cpp_extension import load
cuda_module = load(name="fm_oper", sources=["./oper.cu"], verbose=True, extra_cflags=['-O3'], extra_cuda_cflags=['-prec-sqrt=false','-O3'])
`
and I get:
/usr/local/cuda-12.0
/data/py_projects/pegasus/project/factor_mining/oper.cu
Using /root/.cache/torch_extensions/py39_cu117 as PyTorch extensions root...
Detected CUDA files, patching ldflags
Emitting ninja build file /root/.cache/torch_extensions/py39_cu117/fm_oper/build.ninja...
Building extension module fm_oper...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/2] /usr/local/cuda-12.0/bin/nvcc  -DTORCH_EXTENSION_NAME=fm_oper -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include/TH -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include/THC -isystem /usr/local/cuda-12.0/include -isystem /root/anaconda3/include/python3.9 -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --compiler-options '-fPIC' -prec-sqrt=false -O3 -std=c++17 -c /data/py_projects/pegasus/project/factor_mining/oper.cu -o oper.cuda.o 
FAILED: oper.cuda.o 
/usr/local/cuda-12.0/bin/nvcc  -DTORCH_EXTENSION_NAME=fm_oper -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include/TH -isystem /root/anaconda3/lib/python3.9/site-packages/torch/include/THC -isystem /usr/local/cuda-12.0/include -isystem /root/anaconda3/include/python3.9 -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --compiler-options '-fPIC' -prec-sqrt=false -O3 -std=c++17 -c /data/py_projects/pegasus/project/factor_mining/oper.cu -o oper.cuda.o 
/root/anaconda3/lib/python3.9/site-packages/torch/include/pybind11/cast.h: In function ‘typename pybind11::detail::type_caster<typename pybind11::detail::intrinsic_type<T>::type>::cast_op_type<T> pybind11::detail::cast_op(make_caster<T>&)’:
/root/anaconda3/lib/python3.9/site-packages/torch/include/pybind11/cast.h:42:120: error: expected template-name before ‘<’ token
   42 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                        ^
/root/anaconda3/lib/python3.9/site-packages/torch/include/pybind11/cast.h:42:120: error: expected identifier before ‘<’ token
/root/anaconda3/lib/python3.9/site-packages/torch/include/pybind11/cast.h:42:123: error: expected primary-expression before ‘>’ token
   42 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                           ^
/root/anaconda3/lib/python3.9/site-packages/torch/include/pybind11/cast.h:42:126: error: expected primary-expression before ‘)’ token
   42 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                              ^
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1893, in _run_ninja_build
    subprocess.run(
  File "/root/anaconda3/lib/python3.9/subprocess.py", line 528, 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 "/data/py_projects/pegasus/project/factor_mining/oper.py", line 567, in <module>
    instance = FM_OPER(o, h, l, c, v, i, amt, vwap, indus_dummies, expire)
  File "/data/py_projects/pegasus/project/factor_mining/oper.py", line 48, in __init__
    self.cuda_module = load(name="fm_oper", sources=[util.abspath("./oper.cu")], verbose=True, extra_cflags=['-O3'], extra_cuda_cflags=['-prec-sqrt=false','-O3'])
  File "/root/anaconda3/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1284, in load
    return _jit_compile(
  File "/root/anaconda3/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1509, in _jit_compile
    _write_ninja_file_and_build_library(
  File "/root/anaconda3/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1624, in _write_ninja_file_and_build_library
    _run_ninja_build(
  File "/root/anaconda3/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1909, in _run_ninja_build
    raise RuntimeError(message) from e




### Versions

wsl2 pytorch2.0 cuda11.7




cc @peterjc123 @mszhanyi @skyline75489 @nbcsm