diff --git a/0001-add-rocm_version-fallback.patch b/0001-add-rocm_version-fallback.patch new file mode 100644 index 0000000..25a0c67 --- /dev/null +++ b/0001-add-rocm_version-fallback.patch @@ -0,0 +1,36 @@ +From 1d35a0b1f5cb39fd0c44a486157dc739a02c71b6 Mon Sep 17 00:00:00 2001 +From: Tom Rix +Date: Wed, 20 Dec 2023 11:23:18 -0500 +Subject: [PATCH] add rocm_version fallback + +Signed-off-by: Tom Rix +--- + torch/utils/hipify/cuda_to_hip_mappings.py | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/torch/utils/hipify/cuda_to_hip_mappings.py b/torch/utils/hipify/cuda_to_hip_mappings.py +index 73586440e7..9354057a39 100644 +--- a/torch/utils/hipify/cuda_to_hip_mappings.py ++++ b/torch/utils/hipify/cuda_to_hip_mappings.py +@@ -57,6 +57,18 @@ if os.path.isfile(rocm_version_h): + if match: + patch = int(match.group(1)) + rocm_version = (major, minor, patch) ++else: ++ try: ++ hip_version = subprocess.check_output(["hipconfig", "--version"]).decode("utf-8") ++ hip_split = hip_version.split('.') ++ rocm_version = (int(hip_split[0]), int(hip_split[1]), 0) ++ except subprocess.CalledProcessError: ++ print(f"Warning: hipconfig --version failed") ++ except (FileNotFoundError, PermissionError, NotADirectoryError): ++ # Do not print warning. This is okay. This file can also be imported for non-ROCm builds. ++ pass ++ ++ + + # List of math functions that should be replaced inside device code only. + MATH_TRANSPILATIONS = collections.OrderedDict( +-- +2.43.0 + diff --git a/LoadHIP.cmake b/LoadHIP.cmake new file mode 100644 index 0000000..c8cc884 --- /dev/null +++ b/LoadHIP.cmake @@ -0,0 +1,66 @@ +set(PYTORCH_FOUND_HIP TRUE) + +torch_hip_get_arch_list(PYTORCH_ROCM_ARCH) +if(PYTORCH_ROCM_ARCH STREQUAL "") + message(FATAL_ERROR "No GPU arch specified for ROCm build. Please use PYTORCH_ROCM_ARCH environment variable to specify GPU archs to build for.") +endif() + + +find_package(ROCM CONFIG REQUIRED) + +set(CMAKE_MODULE_PATH "/usr/lib64/cmake/hip" ${CMAKE_MODULE_PATH}) + +# Find the HIP Package +find_package(HIP MODULE REQUIRED) +message("HIP Version: ${HIP_VERSION}") + +math(EXPR TORCH_HIP_VERSION "(${HIP_VERSION_MAJOR} * 100) + ${HIP_VERSION_MINOR}") +math(EXPR ROCM_VERSION_DEV_INT "(${HIP_VERSION_MAJOR} * 1000) + ${HIP_VERSION_MINOR} * 100") + + +set(CMAKE_HCC_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) +set(CMAKE_HCC_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) +### Remove setting of Flags when FindHIP.CMake PR #558 is accepted.### + +find_package(hsa-runtime64 REQUIRED) +find_package(amd_comgr REQUIRED) +find_package(rocrand REQUIRED) +find_package(hiprand REQUIRED) +find_package(rocblas REQUIRED) +find_package(hipblas REQUIRED) +find_package(miopen REQUIRED) +find_package(hipfft REQUIRED) +find_package(hipsparse REQUIRED) +#find_package(rccl) +find_package(rocprim REQUIRED) +find_package(hipcub REQUIRED) +find_package(rocthrust REQUIRED) +find_package(hipsolver REQUIRED) + +set(hip_library_name amdhip64) +message("HIP library name: ${hip_library_name}") + +# TODO: hip_hcc has an interface include flag "-hc" which is only +# recognizable by hcc, but not gcc and clang. Right now in our +# setup, hcc is only used for linking, but it should be used to +# compile the *_hip.cc files as well. +find_library(PYTORCH_HIP_HCC_LIBRARIES ${hip_library_name} HINTS /usr/lib64) +# TODO: miopen_LIBRARIES should return fullpath to the library file, +# however currently it's just the lib name +if(TARGET ${miopen_LIBRARIES}) + set(PYTORCH_MIOPEN_LIBRARIES ${miopen_LIBRARIES}) +else() + find_library(PYTORCH_MIOPEN_LIBRARIES ${miopen_LIBRARIES} HINTS /usr/lib64) +endif() +# TODO: rccl_LIBRARIES should return fullpath to the library file, +# however currently it's just the lib name +# if(TARGET ${rccl_LIBRARIES}) +# set(PYTORCH_RCCL_LIBRARIES ${rccl_LIBRARIES}) +# else() +# find_library(PYTORCH_RCCL_LIBRARIES ${rccl_LIBRARIES} HINTS /usr/lib64) +# endif() +# hiprtc is part of HIP +find_library(ROCM_HIPRTC_LIB ${hip_library_name} HINTS /usr/lib64) +# roctx is part of roctracer +# find_library(ROCM_ROCTX_LIB roctx64 HINTS /usr/lib64) + diff --git a/python-torch.spec b/python-torch.spec index ea111ea..4d342e4 100644 --- a/python-torch.spec +++ b/python-torch.spec @@ -19,9 +19,12 @@ # /usr/lib64/python3.12/site-packages/torch/bin/test_api, test_lazy %bcond_with test +# For testing rocm +%bcond_with rocm + Name: python-%{pypi_name} Version: 2.1.0 -Release: 11%{?dist} +Release: 12%{?dist} Summary: PyTorch AI/ML framework # See below for details License: BSD-3-Clause AND BSD-2-Clause AND 0BSD AND Apache-2.0 AND MIT AND BSL-1.0 AND GPL-3.0-or-later AND Zlib @@ -33,6 +36,12 @@ Source1: pyproject.toml %else Source0: %{forgeurl}/releases/download/v%{version}/pytorch-v%{version}.tar.gz %endif +%if %{with rocm} +# Public version is references the /opt install location +# Replace it with one that uses the system install location +Source100: LoadHIP.cmake +Patch100: 0001-add-rocm_version-fallback.patch +%endif # Misc cmake changes that would be difficult to upstream # * Use the system fmt @@ -95,6 +104,24 @@ BuildRequires: python3-typing-extensions BuildRequires: sleef-devel BuildRequires: valgrind-devel BuildRequires: xnnpack-devel +%if %{with rocm} +BuildRequires: hipblas-devel +BuildRequires: hipcub-devel +BuildRequires: hipfft-devel +BuildRequires: hipsparse-devel +BuildRequires: hipsolver-devel +BuildRequires: rocblas-devel +BuildRequires: rocprim-devel +BuildRequires: rocm-cmake +BuildRequires: rocm-comgr-devel +BuildRequires: rocm-hip-devel +BuildRequires: rocm-runtime-devel +BuildRequires: rocm-rpm-macros +BuildRequires: rocm-rpm-macros-modules +BuildRequires: rocthrust-devel + +Requires: rocm-rpm-macros-modules +%endif BuildRequires: python3-devel BuildRequires: python3dist(filelock) @@ -157,6 +184,13 @@ cp %{SOURCE1} . %else %autosetup -p1 -n pytorch-v%{version} +%if %{with rocm} +cp %{SOURCE100} cmake/public + +# hipify +./tools/amd_build/build_amd.py +%endif + # Release comes fully loaded with third party src # Remove what we can # @@ -238,7 +272,14 @@ export USE_NUMPY=ON export USE_OPENMP=OFF export USE_PYTORCH_QNNPACK=OFF export USE_QNNPACK=OFF +%if %{with rocm} +export USE_ROCM=ON +export USE_NCCL=OFF +export BUILD_NVFUSER=OFF +export HIP_PATH=%{_prefix} +%else export USE_ROCM=OFF +%endif export USE_SYSTEM_LIBS=ON export USE_TENSORPIPE=OFF export USE_XNNPACK=ON @@ -748,6 +789,9 @@ sed -i -f br.sed devel.files # aten/src/ATen/native/cpu/avx_mathfun.h %changelog +* Wed Dec 20 2023 Tom Rix - 2.1.0-12 +- Stub in rocm to test in flight packages + * Wed Dec 13 2023 Tom Rix - 2.1.0-11 - Move unversioned *.so's to main package