Skip to content

[WIP] Build Windows ARM64 binaries cross-compiled on x64 #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14 changes: 9 additions & 5 deletions windows/condaenv.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ FOR %%v IN (%DESIRED_PYTHON%) DO (
)
endlocal


:: Install libuv
conda install -y -q -c conda-forge libuv=1.39
set libuv_ROOT=%CONDA_HOME%\Library
echo libuv_ROOT=%libuv_ROOT%
if "%CROSS_COMPILE_ARM64%" == "" (
:: Install libuv
conda install -y -q -c conda-forge libuv=1.39
set libuv_ROOT=%CONDA_HOME%\Library
echo libuv_ROOT=%libuv_ROOT%
) else (
:: Install protobuf
conda install -y -q -c conda-forge protobuf=3.13 python=3.8
)
5 changes: 4 additions & 1 deletion windows/internal/copy_cpu.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
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 "%CROSS_COMPILE_ARM64%" == "" (
copy "%libuv_ROOT%\bin\uv.dll" pytorch\torch\lib
)
15 changes: 13 additions & 2 deletions windows/internal/setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@
echo The flags after configuring:
echo USE_CUDA=%USE_CUDA%
echo CMAKE_GENERATOR=%CMAKE_GENERATOR%
echo CROSS_COMPILE_ARM64=%CROSS_COMPILE_ARM64%

if "%USE_CUDA%"=="" echo CUDA_PATH=%CUDA_PATH%
if NOT "%CC%"=="" echo CC=%CC%
if NOT "%CXX%"=="" echo CXX=%CXX%
if NOT "%DISTUTILS_USE_SDK%"=="" echo DISTUTILS_USE_SDK=%DISTUTILS_USE_SDK%

set SRC_DIR=%~dp0\..

if "%CROSS_COMPILE_ARM64%" == "" (
set VSDEVCMD_ARCH=x64
) else (
set VSDEVCMD_ARCH=x64_arm64
set CMAKE_TOOLCHAIN_FILE=cmake\Toolchains\msvc2022-x64-arm64.cmake
set USE_HOST_PROTOC=1
set PROTOC=%CONDA_HOME%\Library\bin\protoc.exe
)

IF "%VSDEVCMD_ARGS%" == "" (
call "%VS15VCVARSALL%" x64
call "%VS15VCVARSALL%" %VSDEVCMD_ARCH%
) ELSE (
call "%VS15VCVARSALL%" x64 %VSDEVCMD_ARGS%
call "%VS15VCVARSALL%" %VSDEVCMD_ARCH% %VSDEVCMD_ARGS%
)

pushd %SRC_DIR%
Expand Down
8 changes: 7 additions & 1 deletion windows/internal/smoke_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ IF "%VC_YEAR%" == "2019" (
set VC_VERSION_UPPER=17
)

if "%CROSS_COMPILE_ARM64%" == "" (
set VSDEVCMD_ARCH=x64
) else (
set VSDEVCMD_ARCH=x64_arm64
)

for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
set "VS15INSTALLDIR=%%i"
Expand All @@ -174,7 +180,7 @@ IF "%VS15VCVARSALL%"=="" (
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch test on Windows
exit /b 1
)
call "%VS15VCVARSALL%" x64
call "%VS15VCVARSALL%" %VSDEVCMD_ARCH%

set install_root=%CD%
set INCLUDE=%INCLUDE%;%install_root%\include;%install_root%\include\torch\csrc\api\include
Expand Down
24 changes: 15 additions & 9 deletions windows/internal/vs2022_install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
# 17.4.3 BuildTools
$VS_DOWNLOAD_LINK = "https://download.visualstudio.microsoft.com/download/pr/8f480125-28b8-4a2c-847c-c2b02a8cdd1b/64be21d4ada005d7d07896ed0b004c322409bd04d6e8eba4c03c9fa39c928e7a/vs_BuildTools.exe"
$COLLECT_DOWNLOAD_LINK = "https://aka.ms/vscollect.exe"
$VS_INSTALL_ARGS = @("--nocache","--quiet","--wait", "--add Microsoft.VisualStudio.Workload.VCTools",
"--add Microsoft.Component.MSBuild",
"--add Microsoft.VisualStudio.Component.Roslyn.Compiler",
"--add Microsoft.VisualStudio.Component.TextTemplating",
"--add Microsoft.VisualStudio.Component.VC.CoreIde",
"--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81")
$VS_INSTALL_ARGS = @(
"--nocache",
"--quiet",
"--wait",
"--add Microsoft.VisualStudio.Workload.VCTools",
"--add Microsoft.Component.MSBuild",
"--add Microsoft.VisualStudio.Component.Roslyn.Compiler",
"--add Microsoft.VisualStudio.Component.TextTemplating",
"--add Microsoft.VisualStudio.Component.VC.CoreIde",
"--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"--add Microsoft.VisualStudio.Component.VC.Tools.ARM64",
"--add Microsoft.VisualStudio.Component.Windows10SDK.20348"
)

curl.exe --retry 3 -kL $VS_DOWNLOAD_LINK --output vs_installer.exe
if ($LASTEXITCODE -ne 0) {
Expand Down