diff --git a/windows/arm64/bootstrap_apl.bat b/windows/arm64/bootstrap_apl.bat new file mode 100644 index 000000000..b21a0b643 --- /dev/null +++ b/windows/arm64/bootstrap_apl.bat @@ -0,0 +1,31 @@ +@echo off + +echo Dependency ARM Performance Libraries (APL) installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% + +:: Set download URL for the ARM Performance Libraries (APL) +set DOWNLOAD_URL="https://developer.arm.com/-/cdn-downloads/permalink/Arm-Performance-Libraries/Version_24.10/arm-performance-libraries_24.10_Windows.msi" +set INSTALLER_FILE=%DOWNLOADS_DIR%\arm-performance-libraries.msi + +:: Download installer +echo Downloading ARM Performance Libraries (APL)... +curl -L -o "%INSTALLER_FILE%" %DOWNLOAD_URL% + +:: Install ARM Performance Libraries (APL) +echo Installing ARM Performance Libraries (APL)... +msiexec /i "%INSTALLER_FILE%" /qn /norestart ACCEPT_EULA=1 INSTALLFOLDER="%DEPENDENCIES_DIR%" + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed to install ARM Performance Libraries (APL) components. (exitcode = %errorlevel%)" + exit /b 1 +) + +:: Add to environment +echo ARMPL_DIR=%DEPENDENCIES_DIR%\armpl_24.10\>> %GITHUB_ENV% +echo %DEPENDENCIES_DIR%\armpl_24.10\bin\>> %GITHUB_PATH% + +echo Dependency ARM Performance Libraries (APL) installation finished. \ No newline at end of file diff --git a/windows/arm64/bootstrap_buildtools.bat b/windows/arm64/bootstrap_buildtools.bat new file mode 100644 index 000000000..bda792572 --- /dev/null +++ b/windows/arm64/bootstrap_buildtools.bat @@ -0,0 +1,35 @@ +@echo off + +echo Dependency MSVC Build Tools with C++ with ARM64/ARM64EC components installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir "%DOWNLOADS_DIR%" +if not exist "%DEPENDENCIES_DIR%" mkdir "%DEPENDENCIES_DIR%" + +:: Set download URL for the Visual Studio Installer +set DOWNLOAD_URL=https://aka.ms/vs/17/release/vs_BuildTools.exe +set INSTALLER_FILE=%DOWNLOADS_DIR%\vs_BuildTools.exe + +:: Download installer +echo Downloading Visual Studio Build Tools with C++ installer... +curl -L -o "%INSTALLER_FILE%" %DOWNLOAD_URL% + +:: Install the Visual Studio Build Tools with C++ components +echo Installing Visual Studio Build Tools with C++ components... +"%INSTALLER_FILE%" --norestart --nocache --quiet --wait --installPath "%DEPENDENCIES_DIR%\VSBuildTools" ^ + --add Microsoft.VisualStudio.Component.Windows11SDK.22621 ^ + --add Microsoft.VisualStudio.Component.VC.ASAN ^ + --add Microsoft.VisualStudio.Component.VC.CMake.Project ^ + --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^ + --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 ^ + --add Microsoft.VisualStudio.Component.VC.14.40.17.10.ARM64 ^ + --add Microsoft.VisualStudio.Component.VC.14.36.17.6.ARM64 + + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed to install Visual Studio Build Tools with C++ components. (exitcode = %errorlevel%)" + exit /b 1 +) + +echo Dependency Visual Studio Build Tools with C++ installation finished. \ No newline at end of file diff --git a/windows/arm64/bootstrap_git.bat b/windows/arm64/bootstrap_git.bat new file mode 100644 index 000000000..a409e5494 --- /dev/null +++ b/windows/arm64/bootstrap_git.bat @@ -0,0 +1,37 @@ +:: we need to install newer version of Git manually as "-submodules" function is not supported in the default version of runner. + +@echo off + +echo Dependency Git installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% + +:: Set download URL for the Git +set DOWNLOAD_URL="https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/Git-2.46.0-64-bit.exe" +set INSTALLER_FILE=%DOWNLOADS_DIR%\Git-2.46.0-64-bit.exe + +:: Download installer +echo Downloading Git... +curl -L -o "%INSTALLER_FILE%" %DOWNLOAD_URL% + +:: Install Git +echo Installing Git... +"%INSTALLER_FILE%" /VERYSILENT /DIR="%DEPENDENCIES_DIR%\git" + +dir %DEPENDENCIES_DIR%\git + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed to install Git. (exitcode = %errorlevel%)" + exit /b 1 +) + +:: Enable long paths +call "%DEPENDENCIES_DIR%\git\cmd\git.exe" config --system core.longpaths true + +:: Add to PATH +echo %DEPENDENCIES_DIR%\git\cmd\;%DEPENDENCIES_DIR%\git\bin\>> %GITHUB_PATH% + +echo Dependency Git installation finished. \ No newline at end of file diff --git a/windows/arm64/bootstrap_python.bat b/windows/arm64/bootstrap_python.bat new file mode 100644 index 000000000..aacc211ee --- /dev/null +++ b/windows/arm64/bootstrap_python.bat @@ -0,0 +1,42 @@ + +@echo off + +echo Dependency Python installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% + +if "%PYTHON_VERSION%"=="Python312" ( + echo Python version is set to Python312 + set DOWNLOAD_URL="https://www.python.org/ftp/python/3.12.7/python-3.12.7-arm64.exe" +) else if "%PYTHON_VERSION%"=="Python311" ( + echo Python version is set to Python311 + set DOWNLOAD_URL="https://www.python.org/ftp/python/3.11.9/python-3.11.9-arm64.exe" +) else ( + echo PYTHON_VERSION not defined, Python version is set to Python312 + set DOWNLOAD_URL="https://www.python.org/ftp/python/3.12.7/python-3.12.7-arm64.exe" +) + +set INSTALLER_FILE=%DOWNLOADS_DIR%\python-installer.exe + +:: Download installer +echo Downloading Python... +curl -L -o "%INSTALLER_FILE%" %DOWNLOAD_URL% + +:: Install Python +echo Installing Python... +"%INSTALLER_FILE%" /quiet Include_debug=1 TargetDir="%DEPENDENCIES_DIR%\Python" + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed to install Git. (exitcode = %errorlevel%)" + exit /b 1 +) + +:: Add to PATH +echo %DEPENDENCIES_DIR%\Python\>> %GITHUB_PATH% +echo %DEPENDENCIES_DIR%\Python\scripts\>> %GITHUB_PATH% +echo %DEPENDENCIES_DIR%\Python\libs\>> %GITHUB_PATH% + +echo Dependency Python installation finished. \ No newline at end of file diff --git a/windows/arm64/bootstrap_rust.bat b/windows/arm64/bootstrap_rust.bat new file mode 100644 index 000000000..80a9803b1 --- /dev/null +++ b/windows/arm64/bootstrap_rust.bat @@ -0,0 +1,34 @@ + +@echo off + +echo Dependency Rust installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% + +set DOWNLOAD_URL="https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe" +set INSTALLER_FILE=%DOWNLOADS_DIR%\rustup-init.exe +set RUSTUP_HOME=%DEPENDENCIES_DIR%\rust +set CARGO_HOME=%DEPENDENCIES_DIR%\cargo + +:: Download installer +echo Downloading Rust... +curl -L -o "%INSTALLER_FILE%" %DOWNLOAD_URL% + +:: Install APL +echo Installing Rust... +"%INSTALLER_FILE%" -q -y --default-host aarch64-pc-windows-msvc --default-toolchain stable --profile default + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed to install Rust. (exitcode = %errorlevel%)" + exit /b 1 +) + +:: Add to PATH +echo %DEPENDENCIES_DIR%\cargo\bin\>> %GITHUB_PATH% +echo RUSTUP_HOME=%DEPENDENCIES_DIR%\rust>> %GITHUB_ENV% +echo CARGO_HOME=%DEPENDENCIES_DIR%\cargo>> %GITHUB_ENV% + +echo Dependency Rust installation finished. \ No newline at end of file diff --git a/windows/arm64/bootstrap_sccache.bat b/windows/arm64/bootstrap_sccache.bat new file mode 100644 index 000000000..a096d0ec6 --- /dev/null +++ b/windows/arm64/bootstrap_sccache.bat @@ -0,0 +1,33 @@ +@echo off + +echo Dependency sccache installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% + +:: Set download URL for the sccache +set DOWNLOAD_URL="https://github.com/mozilla/sccache/releases/download/v0.8.1/sccache-v0.8.1-x86_64-pc-windows-msvc.zip" +set INSTALLER_FILE=%DOWNLOADS_DIR%\sccache.zip + +:: Download installer +echo Downloading sccache.zip... +curl -L -o "%INSTALLER_FILE%" %DOWNLOAD_URL% + +:: Install sccache +echo Extracting sccache.zip... +tar -xf "%INSTALLER_FILE%" -C %DEPENDENCIES_DIR% +cd %DEPENDENCIES_DIR% +ren sccache-v0.8.1-x86_64-pc-windows-msvc sccache +cd .. + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed to install sccache. (exitcode = %errorlevel%)" + exit /b 1 +) + +:: Add to PATH +echo %DEPENDENCIES_DIR%\sccache\>> %GITHUB_PATH% + +echo Dependency sccache installation finished. diff --git a/windows/arm64/build_libtorch.bat b/windows/arm64/build_libtorch.bat new file mode 100644 index 000000000..d112fcfba --- /dev/null +++ b/windows/arm64/build_libtorch.bat @@ -0,0 +1,73 @@ +@echo on + +:: Set the CMAKE_BUILD_TYPE +set "CMAKE_BUILD_TYPE=%BUILD_TYPE%" + +:: activate visual studio +call "%DEPENDENCIES_DIR%\VSBuildTools\VC\Auxiliary\Build\vcvarsall.bat" arm64 -vcvars_ver=%MSVC_VERSION% +where cl.exe + +:: change to source directory +cd %PYTORCH_ROOT% + +:: create virtual environment +python -m venv .venv +echo * > .venv\.gitignore +call .\.venv\Scripts\activate +where python + +:: python install dependencies +python -m pip install --upgrade pip +pip install -r requirements.txt + +:: start sccache server and reset sccache stats +sccache --start-server +sccache --zero-stats +sccache --show-stats + +:: Prepare the environment +mkdir libtorch +mkdir libtorch\bin +mkdir libtorch\cmake +mkdir libtorch\include +mkdir libtorch\lib +mkdir libtorch\share +mkdir libtorch\test + +:: Call LibTorch build script +python ./tools/build_libtorch.py + +:: Check if there is an error +IF ERRORLEVEL 1 exit /b 1 +IF NOT ERRORLEVEL 0 exit /b 1 + +:: Move the files to the correct location +move /Y torch\bin\*.* libtorch\bin\ +move /Y torch\cmake\*.* libtorch\cmake\ +robocopy /move /e torch\include\ libtorch\include\ +move /Y torch\lib\*.* libtorch\lib\ +robocopy /move /e torch\share\ libtorch\share\ +move /Y torch\test\*.* libtorch\test\ +move /Y libtorch\bin\*.dll libtorch\lib\ + +:: Set version +echo %PYTORCH_BUILD_VERSION% > libtorch\build-version +git rev-parse HEAD > libtorch\build-hash + +:: Set LIBTORCH_PREFIX +IF "%DEBUG%" == "" ( + set LIBTORCH_PREFIX=libtorch-win-arm64-shared-with-deps +) ELSE ( + set LIBTORCH_PREFIX=libtorch-win-arm64-shared-with-deps-debug +) + +:: Create output +C:\Windows\System32\tar.exe -cvaf %LIBTORCH_PREFIX%-%PYTORCH_BUILD_VERSION%.zip -C libtorch * + +:: Copy output to target directory +if not exist ..\output mkdir ..\output +copy /Y "%LIBTORCH_PREFIX%-%PYTORCH_BUILD_VERSION%.zip" "%PYTORCH_FINAL_PACKAGE_DIR%\" +copy /Y "%LIBTORCH_PREFIX%-%PYTORCH_BUILD_VERSION%.zip" "%PYTORCH_FINAL_PACKAGE_DIR%\%LIBTORCH_PREFIX%-latest.zip" + +:: Cleanup raw data to save space +rmdir /s /q libtorch \ No newline at end of file diff --git a/windows/arm64/build_pytorch.bat b/windows/arm64/build_pytorch.bat new file mode 100644 index 000000000..c845678a7 --- /dev/null +++ b/windows/arm64/build_pytorch.bat @@ -0,0 +1,47 @@ +@echo on + +:: environment variables +set BLAS=APL +set USE_LAPACK=1 +set CMAKE_BUILD_TYPE=%BUILD_TYPE% +set CMAKE_C_COMPILER_LAUNCHER=sccache +set CMAKE_CXX_COMPILER_LAUNCHER=sccache +if defined PYTORCH_BUILD_VERSION ( + set PYTORCH_BUILD_VERSION=%PYTORCH_BUILD_VERSION% + set PYTORCH_BUILD_NUMBER=1 +) + +:: activate visual studio +call "%DEPENDENCIES_DIR%\VSBuildTools\VC\Auxiliary\Build\vcvarsall.bat" arm64 -vcvars_ver=%MSVC_VERSION% +where cl.exe + +:: change to source directory +cd %PYTORCH_ROOT% + +:: create virtual environment +python -m venv .venv +echo * > .venv\.gitignore +call .\.venv\Scripts\activate +where python + +:: python install dependencies +python -m pip install --upgrade pip +pip install wheel +pip install -r requirements.txt + +:: start sccache server and reset sccache stats +sccache --start-server +sccache --zero-stats +sccache --show-stats + +:: Call PyTorch build script +python setup.py bdist_wheel -d "%PYTORCH_FINAL_PACKAGE_DIR%" + +:: show sccache stats +sccache --show-stats + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed on build_pytorch. (exitcode = %errorlevel%)" + exit /b 1 +) \ No newline at end of file diff --git a/windows/arm64/smoke_test.bat b/windows/arm64/smoke_test.bat new file mode 100644 index 000000000..c7c7195c2 --- /dev/null +++ b/windows/arm64/smoke_test.bat @@ -0,0 +1,66 @@ +set "ORIG_PATH=%PATH%" + +if "%PACKAGE_TYPE%" == "wheel" goto wheel +if "%PACKAGE_TYPE%" == "libtorch" goto libtorch + +echo "unknown package type" +exit /b 1 + +:wheel +echo "install wheel package" + +%BUILDER_ROOT%\windows\arm64\bootstrap_python.bat +if errorlevel 1 exit /b 1 + +pip install -q --pre numpy protobuf +if errorlevel 1 exit /b 1 + +for /F "delims=" %%i in ('where /R "%PYTORCH_FINAL_PACKAGE_DIR:/=\%" *.whl') do pip install "%%i" +if errorlevel 1 exit /b 1 + +goto smoke_test + +:smoke_test +python -c "import torch" +if ERRORLEVEL 1 exit /b 1 + +echo Checking that basic RNN works +python %BUILDER_ROOT%\test_example_code\rnn_smoke.py +if ERRORLEVEL 1 exit /b 1 + +echo Checking that basic CNN works +python %BUILDER_ROOT%\test_example_code\cnn_smoke.py +if ERRORLEVEL 1 exit /b 1 + +goto end + +:libtorch +echo "install and test libtorch" + +%BUILDER_ROOT%\windows\arm64\bootstrap_buildtools.bat +if ERRORLEVEL 1 exit /b 1 + +for /F "delims=" %%i in ('where /R "%PYTORCH_FINAL_PACKAGE_DIR:/=\%" *-latest.zip') do 7z x "%%i" -otmp +if ERRORLEVEL 1 exit /b 1 + +pushd tmp\libtorch + +set VC_VERSION_LOWER=14 +set VC_VERSION_UPPER=36 + +call "%DEPENDENCIES_DIR%\VSBuildTools\VC\Auxiliary\Build\vcvarsall.bat" arm64 -vcvars_ver=%MSVC_VERSION% + +set install_root=%CD% +set INCLUDE=%INCLUDE%;%install_root%\include;%install_root%\include\torch\csrc\api\include +set LIB=%LIB%;%install_root%\lib +set PATH=%PATH%;%install_root%\lib + +cl %BUILDER_ROOT%\test_example_code\simple-torch-test.cpp c10.lib torch_cpu.lib /EHsc /std:c++17 +if ERRORLEVEL 1 exit /b 1 + +.\simple-torch-test.exe +if ERRORLEVEL 1 exit /b 1 + +:end +set "PATH=%ORIG_PATH%" +popd