python3Packages.torch: fix MKL build

PyTorch failed to build with the BLAS implementation set to MKL, because
CMake install tried to set an rpath that is incorrect for Nix. This
change simply removes the offending code to make the build succeed and
get correct rpaths.

(cherry picked from commit 746f6ce73f)
This commit is contained in:
Daniël de Kok 2024-11-23 20:47:38 +01:00 committed by github-actions[bot]
parent d7b510c05f
commit 71ba921579
2 changed files with 23 additions and 0 deletions

View File

@ -256,6 +256,12 @@ buildPythonPackage rec {
# Propagate CUPTI to Kineto by overriding the search path with environment variables.
# https://github.com/pytorch/pytorch/pull/108847
./pytorch-pr-108847.patch
]
++ lib.optionals (lib.getName blas.provider == "mkl") [
# The CMake install tries to add some hardcoded rpaths, incompatible
# with the Nix store, which fails. Simply remove this step to get
# rpaths that point to the Nix store.
./disable-cmake-mkl-rpath.patch
];
postPatch =

View File

@ -0,0 +1,17 @@
diff --git a/cmake/public/mkl.cmake b/cmake/public/mkl.cmake
index 2f6d1fd905..f30464be07 100644
--- a/cmake/public/mkl.cmake
+++ b/cmake/public/mkl.cmake
@@ -16,12 +16,6 @@ foreach(MKL_LIB IN LISTS MKL_LIBRARIES)
endif()
endforeach()
-# TODO: This is a hack, it will not pick up architecture dependent
-# MKL libraries correctly; see https://github.com/pytorch/pytorch/issues/73008
-set_property(
- TARGET caffe2::mkl PROPERTY INTERFACE_LINK_DIRECTORIES
- ${MKL_ROOT}/lib ${MKL_ROOT}/lib/intel64 ${MKL_ROOT}/lib/intel64_win ${MKL_ROOT}/lib/win-x64)
-
if(UNIX)
if(USE_STATIC_MKL)
foreach(MKL_LIB_PATH IN LISTS MKL_LIBRARIES)