Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
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
12 changes: 5 additions & 7 deletions windows/build_pytorch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ set PYTORCH_BUILD_NUMBER=%~3

:env_end

if not "%CUDA_VERSION%" == "cpu" (
set CUDA_PREFIX=cuda%CUDA_VERSION%
) else (
set CUDA_PREFIX=cpu
)
set CUDA_PREFIX=cuda%CUDA_VERSION%
if "%CUDA_VERSION%" == "cpu" set CUDA_PREFIX=cpu
if "%CUDA_VERSION%" == "xpu" set CUDA_PREFIX=xpu

if "%DESIRED_PYTHON%" == "" set DESIRED_PYTHON=3.5;3.6;3.7
set DESIRED_PYTHON_PREFIX=%DESIRED_PYTHON:.=%
Expand Down Expand Up @@ -72,7 +70,7 @@ if "%DEBUG%" == "1" (
set BUILD_TYPE=release
)

if not "%CUDA_VERSION%" == "cpu" (
if not "%CUDA_VERSION%" == "cpu" if not "%CUDA_VERSION%" == "xpu" (
rmdir /s /q magma_%CUDA_PREFIX%_%BUILD_TYPE%
del magma_%CUDA_PREFIX%_%BUILD_TYPE%.7z
curl -k https://s3.amazonaws.com/ossci-windows/magma_%MAGMA_VERSION%_%CUDA_PREFIX%_%BUILD_TYPE%.7z -o magma_%CUDA_PREFIX%_%BUILD_TYPE%.7z
Expand Down Expand Up @@ -120,7 +118,7 @@ for %%v in (%DESIRED_PYTHON_PREFIX%) do (
pip install ninja
@setlocal
:: Set Flags
if not "%CUDA_VERSION%"=="cpu" (
if not "%CUDA_VERSION%"=="cpu" if not "%CUDA_VERSION%" == "xpu" (
set MAGMA_HOME=%cd%\magma_%CUDA_PREFIX%_%BUILD_TYPE%
)
call %CUDA_PREFIX%.bat
Expand Down
3 changes: 3 additions & 0 deletions windows/internal/build_wheels.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ if errorlevel 1 exit /b 1
call windows/internal/cuda_install.bat
if errorlevel 1 exit /b 1

call windows/internal/xpu_install.bat
if errorlevel 1 exit /b 1

call windows/build_pytorch.bat %CUDA_VERSION% %PYTORCH_BUILD_VERSION% %PYTORCH_BUILD_NUMBER%
if errorlevel 1 exit /b 1
2 changes: 2 additions & 0 deletions windows/internal/check_opts.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ IF NOT ERRORLEVEL 1 (
set CMAKE_GENERATOR=Ninja
)

IF "%USE_SCCACHE%" == "0" goto sccache_end

where /q clcache.exe

IF NOT ERRORLEVEL 1 (
Expand Down
29 changes: 17 additions & 12 deletions windows/internal/clone.bat
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
@echo off

:: The conda and wheels jobs are separated on Windows, so we don't need to clone again.
if exist "%NIGHTLIES_PYTORCH_ROOT%" (
:: Attempt to fix infinite copy of ittapi recursive symlinks on non-ephemeral runners
if exist pytorch (
rmdir /s /q pytorch
)
:: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
:: Without symlink handling, robocopy could get into an infinite loop with ittapi. With /sl,
:: symlink is ignored so functorch/docs/source/notebooks won't work. The correct option is
:: /xj to exclude junction point (what the heck does that even mean Microsoft?)
robocopy "%NIGHTLIES_PYTORCH_ROOT%" pytorch\ /e /np /nfl /xjd
cd pytorch
if not exist "%NIGHTLIES_PYTORCH_ROOT%" goto clone_pytorch
:: XPU windows build can't work with long src path, use NIGHTLIES_PYTORCH_ROOT directly.
:: Refer https://github.com/pytorch/pytorch/issues/134956
if "%CUDA_VERSION%" == "xpu" (
cd "%NIGHTLIES_PYTORCH_ROOT%"
goto submodule
)
if exist "%NIGHTLIES_PYTORCH_ROOT%" goto submodule
:: Attempt to fix infinite copy of ittapi recursive symlinks on non-ephemeral runners
if exist pytorch rmdir /s /q pytorch
:: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
:: Without symlink handling, robocopy could get into an infinite loop with ittapi. With /sl,
:: symlink is ignored so functorch/docs/source/notebooks won't work. The correct option is
:: /xj to exclude junction point (what the heck does that even mean Microsoft?)
robocopy "%NIGHTLIES_PYTORCH_ROOT%" pytorch\ /e /np /nfl /xjd
cd pytorch
goto submodule

:clone_pytorch

git clone https://github.com/%PYTORCH_REPO%/%MODULE_NAME%

Expand Down
4 changes: 4 additions & 0 deletions windows/internal/cuda_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ if "%CUDA_VERSION%" == "cpu" (
echo Skipping for CPU builds
exit /b 0
)
if "%CUDA_VERSION%" == "xpu" (
echo Skipping for XPU builds
exit /b 0
)

set SRC_DIR=%~dp0\..

Expand Down
1 change: 1 addition & 0 deletions windows/internal/setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if NOT "%CXX%"=="" echo CXX=%CXX%
if NOT "%DISTUTILS_USE_SDK%"=="" echo DISTUTILS_USE_SDK=%DISTUTILS_USE_SDK%

set SRC_DIR=%~dp0\..
if exist "%NIGHTLIES_PYTORCH_ROOT%" if "%CUDA_VERSION%" == "xpu" set SRC_DIR=%NIGHTLIES_PYTORCH_ROOT%

IF "%VSDEVCMD_ARGS%" == "" (
call "%VS15VCVARSALL%" x64
Expand Down
9 changes: 8 additions & 1 deletion windows/internal/smoke_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ set SRC_DIR=%~dp0

pushd %SRC_DIR%\..

if not "%CUDA_VERSION%" == "cpu" call internal\driver_update.bat
if not "%CUDA_VERSION%" == "cpu" if not "%CUDA_VERSION%" == "xpu" call internal\driver_update.bat
if errorlevel 1 exit /b 1

if "%CUDA_VERSION%" == "xpu" (
call internal\xpu_install.bat
if errorlevel 1 exit /b 1
call "%ProgramFiles(x86)%\Intel\oneAPI\setvars.bat"
if errorlevel 1 exit /b 1
)

set "ORIG_PATH=%PATH%"

setlocal EnableDelayedExpansion
Expand Down
5 changes: 1 addition & 4 deletions windows/internal/vc_install_helper.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
if "%VC_YEAR%" == "2019" powershell windows/internal/vs2019_install.ps1
if "%VC_YEAR%" == "2022" (
echo "Upgrading MSVC to 2022 is not supported in the CI for reliability reason. Please contact PyTorch Dev Infra for more information"
set VC_YEAR=2019
)
if "%VC_YEAR%" == "2022" powershell windows/internal/vs2022_install.ps1

set VC_VERSION_LOWER=17
set VC_VERSION_UPPER=18
Expand Down
96 changes: 96 additions & 0 deletions windows/internal/xpu_install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
@echo on
REM Description: Install Intel Support Packages on Windows
REM BKM reference: https://www.intel.com/content/www/us/en/developer/articles/tool/pytorch-prerequisites-for-intel-gpu/2-5.html

if not "%CUDA_VERSION%" == "xpu" (
echo Skipping for non XPU builds
exit /b 0
)

set XPU_INSTALL_MODE=%~1
if "%XPU_INSTALL_MODE%"=="" goto xpu_bundle_install_start
if "%XPU_INSTALL_MODE%"=="bundle" goto xpu_bundle_install_start
if "%XPU_INSTALL_MODE%"=="driver" goto xpu_driver_install_start
if "%XPU_INSTALL_MODE%"=="all" goto xpu_driver_install_start

:arg_error

echo Illegal XPU installation mode. The value can be "bundle"/"driver"/"all"
echo If keep the value as space, will use default "bundle" mode
exit /b 1

:xpu_driver_install_start
:: TODO Need more testing for driver installation
set XPU_DRIVER_LINK=https://downloadmirror.intel.com/830975/gfx_win_101.5972.exe
curl -o xpu_driver.exe --retry 3 --retry-all-errors -k %XPU_DRIVER_LINK%
echo "XPU Driver installing..."
start /wait "Intel XPU Driver Installer" "xpu_driver.exe"
if errorlevel 1 exit /b 1
del xpu_driver.exe
if "%XPU_INSTALL_MODE%"=="driver" goto xpu_install_end

:xpu_bundle_install_start

set XPU_BUNDLE_PARENT_DIR=C:\Program Files (x86)\Intel\oneAPI
set XPU_BUNDLE_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/9d1a91e2-e8b8-40a5-8c7f-5db768a6a60c/w_intel-for-pytorch-gpu-dev_p_0.5.3.37_offline.exe
set XPU_PTI_URL=https://registrationcenter-download.intel.com/akdlm/IRC_NAS/9d1a91e2-e8b8-40a5-8c7f-5db768a6a60c/w_intel-pti-dev_p_0.9.0.37_offline.exe
set XPU_BUNDLE_VERSION=0.5.3+31
set XPU_PTI_VERSION=0.9.0+36
set XPU_BUNDLE_PRODUCT_NAME=intel.oneapi.win.intel-for-pytorch-gpu-dev.product
set XPU_PTI_PRODUCT_NAME=intel.oneapi.win.intel-pti-dev.product
set XPU_BUNDLE_INSTALLED=0
set XPU_PTI_INSTALLED=0
set XPU_BUNDLE_UNINSTALL=0
set XPU_PTI_UNINSTALL=0

:: Check if XPU bundle is target version or already installed
if exist "%XPU_BUNDLE_PARENT_DIR%\Installer\installer.exe" goto xpu_bundle_ver_check
goto xpu_bundle_install

:xpu_bundle_ver_check

"%XPU_BUNDLE_PARENT_DIR%\Installer\installer.exe" --list-products > xpu_bundle_installed_ver.log

for /f "tokens=1,2" %%a in (xpu_bundle_installed_ver.log) do (
if "%%a"=="%XPU_BUNDLE_PRODUCT_NAME%" (
echo %%a Installed Version: %%b
set XPU_BUNDLE_INSTALLED=1
if not "%XPU_BUNDLE_VERSION%"=="%%b" (
start /wait "Installer Title" "%XPU_BUNDLE_PARENT_DIR%\Installer\installer.exe" --action=remove --eula=accept --silent --product-id %XPU_BUNDLE_PRODUCT_NAME% --product-ver %%b --log-dir uninstall_bundle
set XPU_BUNDLE_UNINSTALL=1
)
)
if "%%a"=="%XPU_PTI_PRODUCT_NAME%" (
echo %%a Installed Version: %%b
set XPU_PTI_INSTALLED=1
if not "%XPU_PTI_VERSION%"=="%%b" (
start /wait "Installer Title" "%XPU_BUNDLE_PARENT_DIR%\Installer\installer.exe" --action=remove --eula=accept --silent --product-id %XPU_PTI_PRODUCT_NAME% --product-ver %%b --log-dir uninstall_bundle
set XPU_PTI_UNINSTALL=1
)
)
)
if errorlevel 1 exit /b 1
if exist xpu_bundle_installed_ver.log del xpu_bundle_installed_ver.log
if "%XPU_BUNDLE_INSTALLED%"=="0" goto xpu_bundle_install
if "%XPU_BUNDLE_UNINSTALL%"=="1" goto xpu_bundle_install
if "%XPU_PTI_INSTALLED%"=="0" goto xpu_pti_install
if "%XPU_PTI_UNINSTALL%"=="1" goto xpu_pti_install
goto xpu_install_end

:xpu_bundle_install

curl -o xpu_bundle.exe --retry 3 --retry-all-errors -k %XPU_BUNDLE_URL%
echo "XPU Bundle installing..."
start /wait "Intel Pytorch Bundle Installer" "xpu_bundle.exe" --action=install --eula=accept --silent --log-dir install_bundle
if errorlevel 1 exit /b 1
del xpu_bundle.exe

:xpu_pti_install

curl -o xpu_pti.exe --retry 3 --retry-all-errors -k %XPU_PTI_URL%
echo "XPU PTI installing..."
start /wait "Intel PTI Installer" "xpu_pti.exe" --action=install --eula=accept --silent --log-dir install_bundle
if errorlevel 1 exit /b 1
del xpu_pti.exe

:xpu_install_end
39 changes: 39 additions & 0 deletions windows/xpu.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@echo on

set MODULE_NAME=pytorch

IF NOT EXIST "setup.py" IF NOT EXIST "%MODULE_NAME%" (
call internal\clone.bat
cd %~dp0
) ELSE (
call internal\clean.bat
)
IF ERRORLEVEL 1 goto :eof

call internal\check_deps.bat
IF ERRORLEVEL 1 goto :eof

REM Check for optional components

echo Disabling CUDA
set USE_CUDA=0

call internal\check_opts.bat
IF ERRORLEVEL 1 goto :eof

if exist "%NIGHTLIES_PYTORCH_ROOT%" cd %NIGHTLIES_PYTORCH_ROOT%\..
call %~dp0\internal\copy_cpu.bat
IF ERRORLEVEL 1 goto :eof

echo Activate XPU Bundle env
set VS2022INSTALLDIR=%VS15INSTALLDIR%
call "%ProgramFiles(x86)%\Intel\oneAPI\setvars.bat"
IF ERRORLEVEL 1 goto :eof
set USE_KINETO=0
:: Workaround for https://github.com/pytorch/pytorch/issues/134989
set CMAKE_SHARED_LINKER_FLAGS=/FORCE:MULTIPLE
set CMAKE_MODULE_LINKER_FLAGS=/FORCE:MULTIPLE
set CMAKE_EXE_LINKER_FLAGS=/FORCE:MULTIPLE

call %~dp0\internal\setup.bat
IF ERRORLEVEL 1 goto :eof