Skip to content
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

Reuse common logic and migrate CUDA >= 10.1 jobs to VS 2019 for Windo… #2264

Merged
merged 8 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
212 changes: 119 additions & 93 deletions .circleci/config.yml

Large diffs are not rendered by default.

140 changes: 83 additions & 57 deletions .circleci/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ version: 2.1
# - Replace binary_linux_wheel_py3.7 with the name of the job you want to test.
# Job names are 'name:' key.

orbs:
win: circleci/windows@2.0.0

executors:
windows-gpu-prototype:
windows-cpu:
machine:
resource_class: windows.gpu.small.prototype
image: windows-server-2019-nvidia:201908-28
resource_class: windows.xlarge
image: windows-server-2019-vs2019:stable
shell: bash.exe

windows-gpu:
machine:
resource_class: windows.gpu.nvidia.medium
image: windows-server-2019-nvidia:stable
shell: bash.exe

commands:
Expand Down Expand Up @@ -75,31 +78,6 @@ binary_common: &binary_common
UNICODE_ABI: << parameters.unicode_abi >>
CU_VERSION: << parameters.cu_version >>

binary_windows: &binary_windows
parameters:
# Edit these defaults to do a release`
build_version:
description: "version number of release binary; by default, build a nightly"
type: string
default: ""
pytorch_version:
description: "PyTorch version to build against; by default, use a nightly"
type: string
default: ""
# Don't edit these
python_version:
description: "Python version to build against (e.g., 3.7)"
type: string
cu_version:
description: "CUDA version to build against, in CU format (e.g., cpu or cu100)"
type: string
environment:
DESIRED_PYTHON: << parameters.python_version >>
PYTORCH_VERSION: << parameters.pytorch_version >>
CUDA_VERSION: << parameters.cu_version >>
USE_SCCACHE: "1"
VC_YEAR: "2017"

jobs:
circleci_consistency:
docker:
Expand Down Expand Up @@ -248,71 +226,119 @@ jobs:

binary_win_conda:
<<: *binary_common
executor:
name: win/default
shell: bash.exe
executor: windows-cpu
steps:
- checkout_merge
- run:
command: |
choco install miniconda3
(& "C:\tools\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
set -ex
if [[ "$CU_VERSION" == "cu92" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS="-vcvars_ver=14.11"
powershell packaging/windows/internal/vs2017_install.ps1
elif [[ "$CU_VERSION" == "cu100" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS=""
powershell packaging/windows/internal/vs2017_install.ps1
else
export VC_YEAR=2019
export VSDEVCMD_ARGS=""
fi
eval "$('/C/tools/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
conda activate base
conda install -yq conda-build "conda-package-handling!=1.5.0"
bash packaging/build_conda.sh
shell: powershell.exe
packaging/build_conda.sh
- store_test_results:
path: build_results/

binary_win_conda_cuda:
<<: *binary_common
executor: windows-gpu-prototype
executor: windows-gpu
steps:
- checkout_merge
- run:
command: |
choco install miniconda3
(& "C:\tools\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
set -ex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a follow up PR but it'd be nice if this logic was just captured in a re-usable command or a script so that we don't have to copy / paste it everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable. Will fix.

if [[ "$CU_VERSION" == "cu92" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS="-vcvars_ver=14.11"
powershell packaging/windows/internal/vs2017_install.ps1
elif [[ "$CU_VERSION" == "cu100" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS=""
powershell packaging/windows/internal/vs2017_install.ps1
else
export VC_YEAR=2019
export VSDEVCMD_ARGS=""
fi
eval "$('/C/tools/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
conda activate base
conda install -yq conda-build "conda-package-handling!=1.5.0"
bash packaging/build_conda.sh
shell: powershell.exe
packaging/build_conda.sh

binary_win_conda_release:
<<: *binary_windows
executor:
name: win/default
shell: cmd.exe
<<: *binary_common
executor: windows-cpu
steps:
- checkout_merge
- run:
name: Build conda packages
command: |
call packaging/windows/internal/build_conda.bat
set -ex
if [[ "$CU_VERSION" == "cu92" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS="-vcvars_ver=14.11"
powershell packaging/windows/internal/vs2017_install.ps1
elif [[ "$CU_VERSION" == "cu100" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS=""
powershell packaging/windows/internal/vs2017_install.ps1
else
export VC_YEAR=2019
export VSDEVCMD_ARGS=""
fi
packaging/windows/internal/cuda_install.bat
eval "$('/C/tools/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
conda activate base
conda install -yq conda-build "conda-package-handling!=1.5.0"
packaging/build_conda.sh
rm /C/tools/miniconda3/conda-bld/win-64/vs2019*.tar.bz2
- store_artifacts:
path: packaging/windows/output
path: C:/tools/miniconda3/conda-bld/win-64
- persist_to_workspace:
root: packaging/windows/output
root: C:/tools/miniconda3/conda-bld/win-64
paths:
- "*"
- store_test_results:
path: build_results/

binary_win_wheel_release:
<<: *binary_windows
executor:
name: win/default
shell: cmd.exe
<<: *binary_common
executor: windows-cpu
steps:
- checkout_merge
- run:
name: Build wheel packages
command: |
call packaging/windows/internal/build_wheels.bat
set -ex
if [[ "$CU_VERSION" == "cu92" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS="-vcvars_ver=14.11"
powershell packaging/windows/internal/vs2017_install.ps1
elif [[ "$CU_VERSION" == "cu100" ]]; then
export VC_YEAR=2017
export VSDEVCMD_ARGS=""
powershell packaging/windows/internal/vs2017_install.ps1
else
export VC_YEAR=2019
export VSDEVCMD_ARGS=""
fi
packaging/windows/internal/cuda_install.bat
packaging/build_wheel.sh
- store_artifacts:
path: packaging/windows/output
path: dist
- persist_to_workspace:
root: packaging/windows/output
root: dist
paths:
- "*"
- store_test_results:
Expand Down
2 changes: 1 addition & 1 deletion .circleci/regenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def generate_base_workflow(base_workflow_name, python_version, cu_version,
d = {
"name": base_workflow_name,
"python_version": python_version,
"cu_version": cu_version.replace("cu", "") if os_type == "win" else cu_version,
"cu_version": cu_version,
}

if os_type != "win" and unicode:
Expand Down
29 changes: 29 additions & 0 deletions packaging/build_wheel.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@echo on

set VC_VERSION_LOWER=16
set VC_VERSION_UPPER=17
if "%VC_YEAR%" == "2017" (
set VC_VERSION_LOWER=15
set VC_VERSION_UPPER=16
)

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 (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to condense this as an extra step in the circleci config that runs only on windows wheel builds?

Seems like it'd be better to do that instead of having it completely shell out to a separate script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not easy to share an environment between Bash and CMD, especially when you want to activate the env in CMD and get the env back in Bash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I come up with an idea that we could create a utility to activate the env and do sth in CMD by passing arguments.

if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
set "VS15INSTALLDIR=%%i"
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
goto vswhere
)
)

:vswhere
if "%VSDEVCMD_ARGS%" == "" (
call "%VS15VCVARSALL%" x64 || exit /b 1
) else (
call "%VS15VCVARSALL%" x64 %VSDEVCMD_ARGS% || exit /b 1
)

@echo on

set DISTUTILS_USE_SDK=1

python setup.py bdist_wheel || exit /b 1
6 changes: 5 additions & 1 deletion packaging/build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ setup_wheel_python
pip_install numpy pyyaml future ninja
setup_pip_pytorch_version
python setup.py clean
IS_WHEEL=1 python setup.py bdist_wheel
if [[ "$OSTYPE" == "msys" ]]; then
IS_WHEEL=1 "$script_dir/build_wheel.bat"
else
IS_WHEEL=1 python setup.py bdist_wheel
fi
5 changes: 2 additions & 3 deletions packaging/pkg_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ retry () {
#
# Precondition: If Linux, you are in a soumith/manylinux-cuda* Docker image
setup_wheel_python() {
if [[ "$(uname)" == Darwin ]]; then
if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
eval "$(conda shell.bash hook)"
conda env remove -n "env$PYTHON_VERSION" || true
conda create -yn "env$PYTHON_VERSION" python="$PYTHON_VERSION"
Expand Down Expand Up @@ -285,8 +285,7 @@ setup_conda_cudatoolkit_constraint() {
# Build the proper compiler package before building the final package
setup_visual_studio_constraint() {
if [[ "$OSTYPE" == "msys" ]]; then
export VSTOOLCHAIN_PACKAGE=vs2019
export VSDEVCMD_ARGS=''
export VSTOOLCHAIN_PACKAGE=vs$VC_YEAR
conda build $CONDA_CHANNEL_FLAGS --no-anaconda-upload packaging/$VSTOOLCHAIN_PACKAGE
cp packaging/$VSTOOLCHAIN_PACKAGE/conda_build_config.yaml packaging/torchvision/conda_build_config.yaml
fi
Expand Down
21 changes: 0 additions & 21 deletions packaging/vs2019/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ outputs:
# VS 2019 is binary-compatible with VS 2017/vc 14.1 and 2015/vc14. Tools are "v142".
strong:
- vc{{ vcfeature }}
run_exports:
- vc {{ vcver }}
about:
summary: Activation and version verification of MSVC {{ vcver }} (VS {{ vsyear }}) compiler
license: BSD 3-clause
- name: vs{{ vsyear }}_runtime
script: install_runtime.bat
- name: vc
version: {{ vcver }}
track_features:
- vc{{ vcfeature }}
requirements:
run:
- {{ pin_subpackage('vs' ~ vsyear ~ '_runtime') }}
about:
home: https://github.com/conda/conda/wiki/VC-features
license: Modified BSD License (3-clause)
license_family: BSD
summary: A meta-package to track VC features.
description: |
This metapackage is used to activate vc features without
depending on Python.
doc_url: https://github.com/conda/conda/wiki/VC-features
dev_url: https://github.com/conda/conda/wiki/VC-features
2 changes: 1 addition & 1 deletion packaging/windows/internal/build_conda.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if "%VC_YEAR%" == "2017" set VSDEVCMD_ARGS=-vcvars_ver=14.11
if "%VC_YEAR%" == "2017" powershell packaging/windows/internal/vs_install.ps1
if "%VC_YEAR%" == "2017" powershell packaging/windows/internal/vs2017_install.ps1
if errorlevel 1 exit /b 1

call packaging/windows/internal/cuda_install.bat
Expand Down
2 changes: 1 addition & 1 deletion packaging/windows/internal/build_wheels.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if "%VC_YEAR%" == "2017" set VSDEVCMD_ARGS=-vcvars_ver=14.11
if "%VC_YEAR%" == "2017" powershell packaging/windows/internal/vs_install.ps1
if "%VC_YEAR%" == "2017" powershell packaging/windows/internal/vs2017_install.ps1
if errorlevel 1 exit /b 1

call packaging/windows/internal/cuda_install.bat
Expand Down
8 changes: 4 additions & 4 deletions packaging/windows/internal/cuda_install.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo on

if "%CUDA_VERSION%" == "cpu" (
if "%CU_VERSION%" == "cpu" (
echo Skipping for CPU builds
exit /b 0
)
Expand All @@ -9,9 +9,9 @@ set SRC_DIR=%~dp0\..

if not exist "%SRC_DIR%\temp_build" mkdir "%SRC_DIR%\temp_build"

set /a CUDA_VER=%CUDA_VERSION%
set CUDA_VER_MAJOR=%CUDA_VERSION:~0,-1%
set CUDA_VER_MINOR=%CUDA_VERSION:~-1,1%
set /a CUDA_VER=%CU_VERSION:cu=%
set CUDA_VER_MAJOR=%CUDA_VER:~0,-1%
set CUDA_VER_MINOR=%CUDA_VER:~-1,1%
set CUDA_VERSION_STR=%CUDA_VER_MAJOR%.%CUDA_VER_MINOR%

if %CUDA_VER% EQU 92 goto cuda92
Expand Down
21 changes: 21 additions & 0 deletions packaging/windows/internal/vs2019_install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$VS_DOWNLOAD_LINK = "https://aka.ms/vs/16/release/vs_buildtools.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.VC.CoreBuildTools",
"--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64")

curl.exe --retry 3 -kL $VS_DOWNLOAD_LINK --output vs_installer.exe
if ($LASTEXITCODE -ne 0) {
echo "Download of the VS 2019 installer failed"
exit 1
}

$process = Start-Process "${PWD}\vs_installer.exe" -ArgumentList $VS_INSTALL_ARGS -NoNewWindow -Wait -PassThru
Remove-Item -Path vs_installer.exe -Force
$exitCode = $process.ExitCode
if (($exitCode -ne 0) -and ($exitCode -ne 3010)) {
echo "VS 2019 installer exited with code $exitCode, which should be one of [0, 3010]."
exit 1
}