Skip to content

Commit

Permalink
Windows use mkl static lib (take 2) (#1798)
Browse files Browse the repository at this point in the history
resubmit #1790 with fix PR #1797.

From pytorch issue: pytorch/pytorch#124009 I found libtorch seems use shared mkl lib and missing some mkl dll files.
1. Currently pytorch Linux already use static mkl lib.
2. Windows can also support static mkl lib, I have validated as pytorch/pytorch#116946

Tested in https://github.com/pytorch/pytorch/actions/runs/8836875904/job/24264643410
  • Loading branch information
xuhancn committed Apr 26, 2024
1 parent d8a3ebd commit eebc2f0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 27 deletions.
7 changes: 1 addition & 6 deletions windows/build_pytorch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ echo "Failed to create conda env"
exit /B 1
:done


:: Install MKL
rmdir /s /q mkl
del mkl_2020.2.254.7z

:: Download MAGMA Files on CUDA builds
set MAGMA_VERSION=2.5.4

Expand Down Expand Up @@ -122,7 +117,7 @@ for %%v in (%DESIRED_PYTHON_PREFIX%) do (
) else (
set "PATH=%CONDA_HOME%\envs\%%v;%CONDA_HOME%\envs\%%v\scripts;%CONDA_HOME%\envs\%%v\Library\bin;%ORIG_PATH%"
)
pip install ninja mkl-include==2021.4.0 mkl-devel==2021.4.0
pip install ninja
@setlocal
:: Set Flags
if not "%CUDA_VERSION%"=="cpu" (
Expand Down
10 changes: 5 additions & 5 deletions windows/condaenv.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ FOR %%v IN (%DESIRED_PYTHON%) DO (
set PYTHON_VERSION_STR=%%v
set PYTHON_VERSION_STR=!PYTHON_VERSION_STR:.=!
conda remove -n py!PYTHON_VERSION_STR! --all -y || rmdir %CONDA_HOME%\envs\py!PYTHON_VERSION_STR! /s
if "%%v" == "3.8" call conda create -n py!PYTHON_VERSION_STR! -y -q numpy=1.11 "mkl=2020.2" pyyaml boto3 cmake ninja typing_extensions python=%%v
if "%%v" == "3.9" call conda create -n py!PYTHON_VERSION_STR! -y -q numpy>=1.11 "mkl=2020.2" pyyaml boto3 cmake ninja typing_extensions python=%%v
if "%%v" == "3.10" call conda create -n py!PYTHON_VERSION_STR! -y -q -c=conda-forge numpy=1.21.3 "mkl=2020.2" intel-openmp=2023.2.0 pyyaml boto3 "cmake=3.19.6" ninja typing_extensions python=%%v
if "%%v" == "3.11" call conda create -n py!PYTHON_VERSION_STR! -y -q -c=conda-forge numpy=1.23.4 "mkl=2020.2" intel-openmp=2023.2.0 pyyaml boto3 "cmake=3.19.6" ninja typing_extensions python=%%v
if "%%v" == "3.12" call conda create -n py!PYTHON_VERSION_STR! -y -q -c=conda-forge numpy=1.26.0 "mkl=2023.1" intel-openmp=2023.2.0 pyyaml boto3 "cmake=3.19.6" ninja typing_extensions python=%%v
if "%%v" == "3.8" call conda create -n py!PYTHON_VERSION_STR! -y -q numpy=1.11 intel::mkl-static intel::mkl-include pyyaml boto3 cmake ninja typing_extensions python=%%v
if "%%v" == "3.9" call conda create -n py!PYTHON_VERSION_STR! -y -q numpy>=1.11 intel::mkl-static intel::mkl-include pyyaml boto3 cmake ninja typing_extensions python=%%v
if "%%v" == "3.10" call conda create -n py!PYTHON_VERSION_STR! -y -q -c=conda-forge numpy=1.21.3 intel::mkl-static intel::mkl-include pyyaml boto3 cmake ninja typing_extensions python=%%v
if "%%v" == "3.11" call conda create -n py!PYTHON_VERSION_STR! -y -q -c=conda-forge numpy=1.23.4 intel::mkl-static intel::mkl-include pyyaml boto3 cmake ninja typing_extensions python=%%v
if "%%v" == "3.12" call conda create -n py!PYTHON_VERSION_STR! -y -q -c=conda-forge numpy=1.26.0 intel::mkl-static intel::mkl-include pyyaml boto3 cmake ninja typing_extensions python=%%v
)
endlocal

Expand Down
2 changes: 1 addition & 1 deletion windows/internal/check_deps.bat
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if %PYVER% LSS 35 (
echo Warning: PyTorch for Python 2 under Windows is experimental.
echo Python x64 3.5 or up is recommended to compile PyTorch on Windows
echo Maybe you can create a virual environment if you have conda installed:
echo ^> conda create -n test python=3.6 pyyaml mkl numpy
echo ^> conda create -n test python=3.6 pyyaml numpy
echo ^> activate test
)

Expand Down
5 changes: 1 addition & 4 deletions windows/internal/copy.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ copy "%CUDA_PATH%\extras\CUPTI\lib64\cupti64_*.dll*" pytorch\torch\lib

copy "C:\Program Files\NVIDIA Corporation\NvToolsExt\bin\x64\nvToolsExt64_1.dll*" pytorch\torch\lib
copy "%CONDA_LIB_PATH%\libiomp*5md.dll" pytorch\torch\lib
IF "%PACKAGE_TYPE%"=="libtorch" (
copy "%CONDA_LIB_PATH%\mkl_intel_thread.1.dll" pytorch\torch\lib
copy "%CONDA_LIB_PATH%\mkl_core.1.dll" pytorch\torch\lib
)

:: Should be set in build_pytorch.bat
copy "%libuv_ROOT%\bin\uv.dll" pytorch\torch\lib

Expand Down
7 changes: 1 addition & 6 deletions windows/internal/copy_cpu.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
copy "%CONDA_LIB_PATH%\libiomp*5md.dll" pytorch\torch\lib
:: Should be set in build_pytorch.bat
copy "%libuv_ROOT%\bin\uv.dll" pytorch\torch\lib

IF "%PACKAGE_TYPE%"=="libtorch" (
copy "%CONDA_LIB_PATH%\mkl_intel_thread.1.dll" pytorch\torch\lib
copy "%CONDA_LIB_PATH%\mkl_core.1.dll" pytorch\torch\lib
)
copy "%libuv_ROOT%\bin\uv.dll" pytorch\torch\lib
5 changes: 0 additions & 5 deletions windows/internal/static_lib_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ echo "install and test libtorch"
pip install cmake
echo "installing cmake"

curl https://s3.amazonaws.com/ossci-windows/mkl_2020.2.254.7z -k -O
7z x -aoa mkl_2020.2.254.7z -omkl
set LIB=%CD%\mkl\lib;%LIB%


if "%VC_YEAR%" == "2019" powershell internal\vs2019_install.ps1
if "%VC_YEAR%" == "2022" powershell internal\vs2022_install.ps1

Expand Down

0 comments on commit eebc2f0

Please sign in to comment.