Add abi flags to cpp_extension cache folder (#136890)

This is to avoid cache confusion between normal vs pydebug vs nogil builds in cpp extensions which can lead to catastrophic ABI issues.
This is rare today for people to run both normal and pydebug on the same machine, but we expect quite a few people will run normal and nogil on the same machine going forward.

This is tested locally by running each version alternatively.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/136890
Approved by: https://github.com/colesbury
This commit is contained in:
albanD
2024-09-28 00:49:53 +00:00
committed by PyTorch MergeBot
parent f42e88fea5
commit e4571e7025

View File

@ -2075,7 +2075,7 @@ def _get_build_directory(name: str, verbose: bool) -> str:
root_extensions_directory = get_default_build_root()
cu_str = ('cpu' if torch.version.cuda is None else
f'cu{torch.version.cuda.replace(".", "")}') # type: ignore[attr-defined]
python_version = f'py{sys.version_info.major}{sys.version_info.minor}'
python_version = f'py{sys.version_info.major}{sys.version_info.minor}{getattr(sys, "abiflags", "")}'
build_folder = f'{python_version}_{cu_str}'
root_extensions_directory = os.path.join(