simplify torch.utils.cpp_extension.include_paths; use it in cpp_builder (#145480)

While working on conda-forge integration, I needed to look at the way the include paths are calculated, and noticed an avoidable duplication between `torch/utils/cpp_extension.py` and `torch/_inductor/cpp_builder.py`. The latter already imports the former anyway, so simply reuse the same function.

Furthermore, remove long-obsolete include-paths. AFAICT, the `/TH` headers have not existed since pytorch 1.11.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/145480
Approved by: https://github.com/ezyang
This commit is contained in:
H. Vetinari
2025-01-27 07:19:40 +00:00
committed by PyTorch MergeBot
parent e90cf4abcf
commit e6c1e6e20e
2 changed files with 2 additions and 13 deletions

View File

@ -762,16 +762,9 @@ def _get_build_args_of_chosen_isa(vec_isa: VecISA) -> tuple[list[str], list[str]
def _get_torch_related_args(
include_pytorch: bool, aot_mode: bool
) -> tuple[list[str], list[str], list[str]]:
from torch.utils.cpp_extension import _TORCH_PATH, TORCH_LIB_PATH
from torch.utils.cpp_extension import include_paths, TORCH_LIB_PATH
include_dirs = [
os.path.join(_TORCH_PATH, "include"),
os.path.join(_TORCH_PATH, "include", "torch", "csrc", "api", "include"),
# Some internal (old) Torch headers don't properly prefix their includes,
# so we need to pass -Itorch/lib/include/TH as well.
os.path.join(_TORCH_PATH, "include", "TH"),
os.path.join(_TORCH_PATH, "include", "THC"),
]
include_dirs = include_paths()
libraries_dirs = [TORCH_LIB_PATH]
libraries = []
if sys.platform != "darwin" and not config.is_fbcode():

View File

@ -1220,10 +1220,6 @@ def include_paths(device_type: str = "cpu") -> list[str]:
lib_include,
# Remove this once torch/torch.h is officially no longer supported for C++ extensions.
os.path.join(lib_include, 'torch', 'csrc', 'api', 'include'),
# Some internal (old) Torch headers don't properly prefix their includes,
# so we need to pass -Itorch/lib/include/TH as well.
os.path.join(lib_include, 'TH'),
os.path.join(lib_include, 'THC')
]
if device_type == "cuda" and IS_HIP_EXTENSION:
paths.append(os.path.join(lib_include, 'THH'))