Skip to content

Commit

Permalink
simplify torch.utils.cpp_extension.include_paths; use it in cpp_build…
Browse files Browse the repository at this point in the history
…er (pytorch#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: pytorch#145480
Approved by: https://github.com/ezyang
  • Loading branch information
h-vetinari authored and nWEIdia committed Jan 27, 2025
1 parent 2775da4 commit cfdfdd4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
13 changes: 3 additions & 10 deletions torch/_inductor/cpp_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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"),
]
from torch.utils.cpp_extension import include_paths, TORCH_LIB_PATH

include_dirs = include_paths()
libraries_dirs = [TORCH_LIB_PATH]
libraries = []
if sys.platform != "darwin" and not config.is_fbcode():
Expand Down
4 changes: 0 additions & 4 deletions torch/utils/cpp_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit cfdfdd4

Please sign in to comment.