Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions tools/metadata/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ def dynamic_metadata(
extra = os.environ.get("PYTORCH_EXTRA_INSTALL_REQUIREMENTS")
if extra:
deps.extend(r.strip() for r in extra.split("|") if r.strip())
elif _is_truthy(os.environ.get("USE_ROCM")) and not _is_truthy(
os.environ.get("PYTORCH_ROCM_EXTERNAL_SDK")
):
try:
rocm_version = version("rocm")
except PackageNotFoundError:
pass
else:
elif _is_truthy(os.environ.get("USE_ROCM")):
# Pin the ROCm SDK wheels the build used: PYTORCH_ROCM_SDK_VERSION when
# building against an unpacked SDK, else the installed rocm package.
rocm_version = os.environ.get("PYTORCH_ROCM_SDK_VERSION")
if not rocm_version:
try:
rocm_version = version("rocm")
except PackageNotFoundError:
rocm_version = None
if rocm_version:
deps.append(f"rocm[libraries]=={rocm_version}")

# cupti-python has no free-threaded wheels; PEP 508 cannot express this ABI constraint.
Expand Down
18 changes: 18 additions & 0 deletions torch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,24 @@ endif()

# _rocm_init.py is gitignored (injected by ROCm build scripts to bootstrap
# torch/__init__.py). See https://github.com/ROCm/TheRock/blob/main/docs/packaging/python_packaging.md
# When building against the ROCm SDK wheels, PYTORCH_ROCM_SDK_VERSION names
# their version: generate the file so `import torch` preloads the SDK's
# libraries from those wheels and checks that the installed SDK matches.
if(USE_ROCM AND NOT "$ENV{PYTORCH_ROCM_SDK_VERSION}" STREQUAL "")
set(_rocm_preloads
amd_comgr amd_smi amdhip64 hiprtc hipblas hipfft hiprand hipsparse
hipsparselt hipsolver hipblaslt miopen rocm_sysdeps_liblzma rocm-openblas
rocprofiler-sdk rocprofiler-sdk-roctx roctracer64 roctx64 rccl hipfile)
list(TRANSFORM _rocm_preloads PREPEND "'")
list(TRANSFORM _rocm_preloads APPEND "'")
list(JOIN _rocm_preloads ", " _rocm_preloads)
file(WRITE "${TORCH_SRC_DIR}/_rocm_init.py"
"def initialize():\n"
" import rocm_sdk\n"
" rocm_sdk.initialize_process(\n"
" preload_shortnames=[${_rocm_preloads}],\n"
" check_version='$ENV{PYTORCH_ROCM_SDK_VERSION}')\n")
endif()
# scikit-build-core won't include it via Python package collection. Install it
# explicitly via cmake instead.
if(SKBUILD AND USE_ROCM AND EXISTS "${TORCH_SRC_DIR}/_rocm_init.py")
Expand Down