From bcceaff0f271c095935c4a81602571e88b84bf1f Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sat, 18 Sep 2021 01:29:03 -0700 Subject: [PATCH 01/20] enable windows cudatests --- .circleci/config.yml | 7 +++ .circleci/config.yml.in | 7 +++ .circleci/unittest/windows/scripts/install.sh | 6 ++- .../unittest/windows/scripts/run_test.sh | 5 +- .../unittest/windows/scripts/set_cuda_envs.sh | 50 +++++++++++++++++++ packaging/windows/internal/cuda_install.bat | 7 +++ packaging/windows/internal/driver_update.bat | 25 ++++++++++ 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 .circleci/unittest/windows/scripts/set_cuda_envs.sh create mode 100644 packaging/windows/internal/driver_update.bat diff --git a/.circleci/config.yml b/.circleci/config.yml index 739388f156..0a5b0ead91 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -518,6 +518,7 @@ jobs: environment: <<: *environment CUDA_VERSION: "10.2" + TORCHAUDIO_TEST_FORCE_CUDA: 1 steps: - checkout - designate_upload_channel @@ -525,6 +526,12 @@ jobs: - run: name: Setup command: .circleci/unittest/windows/scripts/setup_env.sh + - run: + name: Install CUDA + command: packaging/windows/internal/cuda_install.bat + - run: + name: Update CUDA driver + command: packaging/windows/internal/driver_update.bat - run: name: Install torchaudio command: .circleci/unittest/windows/scripts/install.sh diff --git a/.circleci/config.yml.in b/.circleci/config.yml.in index 4ec63b6c0a..6a1eb14247 100644 --- a/.circleci/config.yml.in +++ b/.circleci/config.yml.in @@ -518,6 +518,7 @@ jobs: environment: <<: *environment CUDA_VERSION: "10.2" + TORCHAUDIO_TEST_FORCE_CUDA: 1 steps: - checkout - designate_upload_channel @@ -525,6 +526,12 @@ jobs: - run: name: Setup command: .circleci/unittest/windows/scripts/setup_env.sh + - run: + name: Install CUDA + command: packaging/windows/internal/cuda_install.bat + - run: + name: Update CUDA driver + command: packaging/windows/internal/driver_update.bat - run: name: Install torchaudio command: .circleci/unittest/windows/scripts/install.sh diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 4a459a2357..14b1c0b79a 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -5,7 +5,7 @@ unset PYTORCH_VERSION # so no need to set PYTORCH_VERSION. # In fact, keeping PYTORCH_VERSION forces us to hardcode PyTorch version in config. -set -e +set -ex root_dir="$(git rev-parse --show-toplevel)" conda_dir="${root_dir}/conda" @@ -27,6 +27,10 @@ fi printf "Installing PyTorch with %s\n" "${cudatoolkit}" conda install ${CONDA_CHANNEL_FLAGS:-} -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}::pytorch" ${cudatoolkit} +python -c "import torch; print(torch.cuda.is_available())" + +source "$this_dir/set_cuda_envs.sh" + # 2. Install torchaudio printf "* Installing torchaudio\n" git submodule update --init --recursive diff --git a/.circleci/unittest/windows/scripts/run_test.sh b/.circleci/unittest/windows/scripts/run_test.sh index c6e7ffd37f..f5ec80e043 100644 --- a/.circleci/unittest/windows/scripts/run_test.sh +++ b/.circleci/unittest/windows/scripts/run_test.sh @@ -1,10 +1,13 @@ #!/usr/bin/env bash -set -e +set -ex eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')" conda activate ./env +this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source "$this_dir/set_cuda_envs.sh" + python -m torch.utils.collect_env cd test pytest --cov=torchaudio --junitxml=../test-results/junit.xml -v --durations 20 torchaudio_unittest diff --git a/.circleci/unittest/windows/scripts/set_cuda_envs.sh b/.circleci/unittest/windows/scripts/set_cuda_envs.sh new file mode 100644 index 0000000000..27e79cfb93 --- /dev/null +++ b/.circleci/unittest/windows/scripts/set_cuda_envs.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -ex + +echo CU_VERSION is "${CU_VERSION}" +echo CUDA_VERSION is "${CUDA_VERSION}" + +# Currenly, CU_VERSION and CUDA_VERSION are not consistent. +# to understand this code, please checck out https://github.com/pytorch/vision/issues/4443 +version="cpu" +if [[ ! -z "${CUDA_VERSION}" ]] ; then + version="$CUDA_VERSION" +else + if [[ ${#CU_VERSION} -eq 5 ]]; then + version="${CU_VERSION:2:2}.${CU_VERSION:4:1}" + fi +fi + +# Don't use if [[ "$version" == "cpu" ]]; then exit 0 fi. +# It would exit the shell. One result is cpu tests would not run if the shell exit. +# Unless there's an error, Don't exit. +if [[ "$version" != "cpu" ]]; then + # set cuda envs + export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${version}/bin:/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${version}/libnvvp:$PATH" + export CUDA_PATH_V${version/./_}="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${version}" + export CUDA_PATH="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${version}" + + if [ ! -d "$CUDA_PATH" ] + then + echo "$CUDA_PATH" does not exist + exit 1 + fi + + if [ ! -f "${CUDA_PATH}\include\nvjpeg.h" ] + then + echo "nvjpeg does not exist" + exit 1 + fi + + # check cuda driver version + for path in '/c/Program Files/NVIDIA Corporation/NVSMI/nvidia-smi.exe' /c/Windows/System32/nvidia-smi.exe; do + if [[ -x "$path" ]]; then + "$path" || echo "true"; + break + fi + done + + which nvcc + nvcc --version + env | grep CUDA +fi diff --git a/packaging/windows/internal/cuda_install.bat b/packaging/windows/internal/cuda_install.bat index 1ddd6c7734..27cf4e0c99 100644 --- a/packaging/windows/internal/cuda_install.bat +++ b/packaging/windows/internal/cuda_install.bat @@ -9,6 +9,13 @@ set SRC_DIR=%~dp0\.. if not exist "%SRC_DIR%\temp_build" mkdir "%SRC_DIR%\temp_build" +rem in unit test workflow, we get CUDA_VERSION, for example 11.1 +if defined CUDA_VERSION ( + set CUDA_VER=%CUDA_VERSION:.=% +) else ( + set CUDA_VER=%CU_VERSION:cu=% +) + set /a CUDA_VER=%CU_VERSION:cu=% set CUDA_VER_MAJOR=%CUDA_VER:~0,-1% set CUDA_VER_MINOR=%CUDA_VER:~-1,1% diff --git a/packaging/windows/internal/driver_update.bat b/packaging/windows/internal/driver_update.bat new file mode 100644 index 0000000000..00b43affc0 --- /dev/null +++ b/packaging/windows/internal/driver_update.bat @@ -0,0 +1,25 @@ +set "DRIVER_DOWNLOAD_LINK=https://ossci-windows.s3.amazonaws.com/461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe" +curl --retry 3 -kL %DRIVER_DOWNLOAD_LINK% --output 461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe +if errorlevel 1 exit /b 1 + +start /wait 461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe -s -noreboot +if errorlevel 1 exit /b 1 + +del 461.09-data-center-tesla-desktop-winserver-2019-2016-international.exe || ver > NUL + +setlocal EnableDelayedExpansion +set NVIDIA_GPU_EXISTS=0 +for /F "delims=" %%i in ('wmic path win32_VideoController get name') do ( + set GPUS=%%i + if not "x!GPUS:NVIDIA=!" == "x!GPUS!" ( + SET NVIDIA_GPU_EXISTS=1 + goto gpu_check_end + ) +) +:gpu_check_end +endlocal & set NVIDIA_GPU_EXISTS=%NVIDIA_GPU_EXISTS% + +if "%NVIDIA_GPU_EXISTS%" == "0" ( + echo "CUDA Driver installation Failed" + exit /b 1 +) From 42d9b33ef7aafa14166cbca347628df7ca1ae9b5 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sat, 18 Sep 2021 01:42:28 -0700 Subject: [PATCH 02/20] add this dir --- .circleci/unittest/windows/scripts/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 14b1c0b79a..fe05b09492 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -29,6 +29,7 @@ conda install ${CONDA_CHANNEL_FLAGS:-} -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorc python -c "import torch; print(torch.cuda.is_available())" +this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source "$this_dir/set_cuda_envs.sh" # 2. Install torchaudio From 00402a13897a603804993a346465eb36d595cc63 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sat, 18 Sep 2021 01:58:54 -0700 Subject: [PATCH 03/20] minor change --- .circleci/unittest/windows/scripts/set_cuda_envs.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.circleci/unittest/windows/scripts/set_cuda_envs.sh b/.circleci/unittest/windows/scripts/set_cuda_envs.sh index 27e79cfb93..37b53d020d 100644 --- a/.circleci/unittest/windows/scripts/set_cuda_envs.sh +++ b/.circleci/unittest/windows/scripts/set_cuda_envs.sh @@ -30,12 +30,6 @@ if [[ "$version" != "cpu" ]]; then exit 1 fi - if [ ! -f "${CUDA_PATH}\include\nvjpeg.h" ] - then - echo "nvjpeg does not exist" - exit 1 - fi - # check cuda driver version for path in '/c/Program Files/NVIDIA Corporation/NVSMI/nvidia-smi.exe' /c/Windows/System32/nvidia-smi.exe; do if [[ -x "$path" ]]; then From b02ca3a3ba45fd935a0c7cc005c5285ac3bc3a77 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sat, 18 Sep 2021 09:48:29 -0700 Subject: [PATCH 04/20] vs integration --- packaging/windows/internal/cuda_install.bat | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packaging/windows/internal/cuda_install.bat b/packaging/windows/internal/cuda_install.bat index 27cf4e0c99..7e91bbcf29 100644 --- a/packaging/windows/internal/cuda_install.bat +++ b/packaging/windows/internal/cuda_install.bat @@ -194,7 +194,13 @@ start /wait setup.exe -s %ARGS% popd echo Installing VS integration... -xcopy /Y "%SRC_DIR%\temp_build\cuda\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\BuildCustomizations" +rem It's for VS 2019 +if "%CUDA_VER_MAJOR%" == "10" ( + xcopy /Y "%SRC_DIR%\temp_build\cuda\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations" +) +if "%CUDA_VER_MAJOR%" == "11" ( + xcopy /Y "%SRC_DIR%\temp_build\cuda\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations" +) echo Installing NvToolsExt... 7z x %SRC_DIR%\temp_build\NvToolsExt.7z -o"%SRC_DIR%\temp_build\NvToolsExt" From b2170195bf71e2082f0865c6cdb550dd1515a5fd Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sun, 19 Sep 2021 01:37:19 +0800 Subject: [PATCH 05/20] Update cuda_install.bat --- packaging/windows/internal/cuda_install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/windows/internal/cuda_install.bat b/packaging/windows/internal/cuda_install.bat index 7e91bbcf29..3c5adc8833 100644 --- a/packaging/windows/internal/cuda_install.bat +++ b/packaging/windows/internal/cuda_install.bat @@ -229,7 +229,7 @@ xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\lib\x64\*.*" "%ProgramFiles%\NVIDIA GP xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\include\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\include" echo Installing GPU driver DLLs -7z x %SRC_DIR%\temp_build\gpu_driver_dlls.zip -o"C:\Windows\System32" +7z x %SRC_DIR%\temp_build\gpu_driver_dlls.zip -aoa -o"C:\Windows\System32" echo Cleaning temp files rd /s /q "%SRC_DIR%\temp_build" || ver > nul From e48fed79825128baec77c3cd2a7f332c97770aaa Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sun, 19 Sep 2021 05:02:16 -0700 Subject: [PATCH 06/20] add logs --- .circleci/unittest/windows/scripts/install.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index fe05b09492..8fdf3311b7 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -17,6 +17,9 @@ cd "${root_dir}" eval "$("${conda_dir}/Scripts/conda.exe" 'shell.bash' 'hook')" conda activate "${env_dir}" +this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source "$this_dir/set_cuda_envs.sh" + # 1. Install PyTorch if [ -z "${CUDA_VERSION:-}" ] ; then cudatoolkit="cpuonly" @@ -25,12 +28,11 @@ else cudatoolkit="cudatoolkit=${version}" fi printf "Installing PyTorch with %s\n" "${cudatoolkit}" -conda install ${CONDA_CHANNEL_FLAGS:-} -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}::pytorch" ${cudatoolkit} -python -c "import torch; print(torch.cuda.is_available())" +conda install -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest -this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -source "$this_dir/set_cuda_envs.sh" +export torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") +echo torch.cuda.is_available is $torch_cuda # 2. Install torchaudio printf "* Installing torchaudio\n" From 9b8e85a08961f91edcb611cb266386f76e1fad17 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sun, 19 Sep 2021 07:11:23 -0700 Subject: [PATCH 07/20] minor change --- .circleci/unittest/windows/scripts/install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 8fdf3311b7..46269ba398 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -10,6 +10,7 @@ set -ex root_dir="$(git rev-parse --show-toplevel)" conda_dir="${root_dir}/conda" env_dir="${root_dir}/env" +this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd "${root_dir}" @@ -17,7 +18,7 @@ cd "${root_dir}" eval "$("${conda_dir}/Scripts/conda.exe" 'shell.bash' 'hook')" conda activate "${env_dir}" -this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + source "$this_dir/set_cuda_envs.sh" # 1. Install PyTorch @@ -31,7 +32,7 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}" conda install -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest -export torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") +torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") echo torch.cuda.is_available is $torch_cuda # 2. Install torchaudio From 876f1244afe5489513121fd3e4dd8715a80d1e93 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Tue, 21 Sep 2021 23:18:43 -0700 Subject: [PATCH 08/20] minor change --- .circleci/unittest/windows/scripts/install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 46269ba398..75e2138341 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -18,7 +18,6 @@ cd "${root_dir}" eval "$("${conda_dir}/Scripts/conda.exe" 'shell.bash' 'hook')" conda activate "${env_dir}" - source "$this_dir/set_cuda_envs.sh" # 1. Install PyTorch From d39191307afa622b79a940209f452cbbfa4ae100 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 22 Sep 2021 00:10:14 -0700 Subject: [PATCH 09/20] cp vision conda activate --- .circleci/unittest/windows/scripts/install.sh | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 75e2138341..c95f5e9fba 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -7,18 +7,20 @@ unset PYTORCH_VERSION set -ex -root_dir="$(git rev-parse --show-toplevel)" -conda_dir="${root_dir}/conda" -env_dir="${root_dir}/env" -this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +#root_dir="$(git rev-parse --show-toplevel)" +#conda_dir="${root_dir}/conda" +#env_dir="${root_dir}/env" +#this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd "${root_dir}" +#cd "${root_dir}" # 0. Activate conda env -eval "$("${conda_dir}/Scripts/conda.exe" 'shell.bash' 'hook')" -conda activate "${env_dir}" +#eval "$("${conda_dir}/Scripts/conda.exe" 'shell.bash' 'hook')" +#conda activate "${env_dir}" -source "$this_dir/set_cuda_envs.sh" +this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')" +conda activate ./env # 1. Install PyTorch if [ -z "${CUDA_VERSION:-}" ] ; then @@ -34,6 +36,8 @@ conda install -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}"::pyt torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") echo torch.cuda.is_available is $torch_cuda +source "$this_dir/set_cuda_envs.sh" + # 2. Install torchaudio printf "* Installing torchaudio\n" git submodule update --init --recursive From abb0ec3b849dbb2016c4a60d33c6775844b4ab13 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 22 Sep 2021 00:28:14 -0700 Subject: [PATCH 10/20] mv vc_env_helper.bat --- .../windows/scripts/vc_env_helper.bat | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .circleci/unittest/windows/scripts/vc_env_helper.bat diff --git a/.circleci/unittest/windows/scripts/vc_env_helper.bat b/.circleci/unittest/windows/scripts/vc_env_helper.bat new file mode 100644 index 0000000000..9410135677 --- /dev/null +++ b/.circleci/unittest/windows/scripts/vc_env_helper.bat @@ -0,0 +1,39 @@ +@echo on + +set VC_VERSION_LOWER=16 +set VC_VERSION_UPPER=17 + +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" + 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 + +set args=%1 +shift +:start +if [%1] == [] goto done +set args=%args% %1 +shift +goto start + +:done +if "%args%" == "" ( + echo Usage: vc_env_helper.bat [command] [args] + echo e.g. vc_env_helper.bat cl /c test.cpp +) + +%args% || exit /b 1 From e61745bdbccb54803f66f91e5da7e89aee58eb5e Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 22 Sep 2021 00:58:33 -0700 Subject: [PATCH 11/20] minor change --- .circleci/unittest/windows/scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index c95f5e9fba..3be755116e 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -41,7 +41,7 @@ source "$this_dir/set_cuda_envs.sh" # 2. Install torchaudio printf "* Installing torchaudio\n" git submodule update --init --recursive -"$root_dir/packaging/vc_env_helper.bat" python setup.py install +"$this_dir/vc_env_helper.bat" python setup.py install # 3. Install Test tools printf "* Installing test tools\n" From 8fea67748b50f0a852eba6a6c2bf955e5f15a8e8 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 22 Sep 2021 01:58:36 -0700 Subject: [PATCH 12/20] exit if cuda not avaiable --- .circleci/unittest/windows/scripts/install.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 3be755116e..bbc740976f 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -22,6 +22,8 @@ this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')" conda activate ./env +source "$this_dir/set_cuda_envs.sh" + # 1. Install PyTorch if [ -z "${CUDA_VERSION:-}" ] ; then cudatoolkit="cpuonly" @@ -31,12 +33,17 @@ else fi printf "Installing PyTorch with %s\n" "${cudatoolkit}" -conda install -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest +conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") echo torch.cuda.is_available is $torch_cuda -source "$this_dir/set_cuda_envs.sh" +if [ ! -z "${CUDA_VERSION:-}" ] ; then + if [ "$torch_cuda" == "False" ]; then + echo "torch with cuda installed but torch.cuda.is_available() is False" + exit 1 + fi +fi # 2. Install torchaudio printf "* Installing torchaudio\n" From 43badc93b84d071cbc525ade1afe9b4f697195b1 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 22 Sep 2021 22:28:24 +0800 Subject: [PATCH 13/20] install numpy --- .circleci/unittest/windows/scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index bbc740976f..03e0258deb 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -33,7 +33,7 @@ else fi printf "Installing PyTorch with %s\n" "${cudatoolkit}" -conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest +conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" numpy pytest torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") echo torch.cuda.is_available is $torch_cuda From c50d0fd96ca619e5d6db37979112bc93a33a209a Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 23 Sep 2021 01:22:47 -0700 Subject: [PATCH 14/20] improt CMakeLists --- CMakeLists.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b1b7c8aba..d121e895fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,9 +26,18 @@ if(env_cxx_standard GREATER -1) WARNING "C++ standard version definition detected in environment variable." "PyTorch requires -std=c++14. Please remove -std=c++ settings in your environment.") endif() + set(CMAKE_CXX_STANDARD 14) set(CMAKE_C_STANDARD 11) +# https://developercommunity.visualstudio.com/t/VS-16100-isnt-compatible-with-CUDA-11/1433342 +if(MSVC) + if(USE_CUDA) + set(CMAKE_CXX_STANDARD 17) + endif() +endif() + + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -50,6 +59,7 @@ endif() option(BUILD_SOX "Build libsox statically" ON) option(BUILD_KALDI "Build kaldi statically" ON) option(BUILD_RNNT "Enable RNN transducer" ON) +option(BUILD_LIBTORCHAUDIO "Build C++ Library" ON) option(BUILD_TORCHAUDIO_PYTHON_EXTENSION "Build Python extension" OFF) option(USE_CUDA "Enable CUDA support" OFF) option(USE_ROCM "Enable ROCM support" OFF) @@ -74,6 +84,45 @@ endif() find_package(Torch REQUIRED) +# https://github.com/pytorch/pytorch/issues/54174 +function(CUDA_CONVERT_FLAGS EXISTING_TARGET) + get_property(old_flags TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS) + if(NOT "${old_flags}" STREQUAL "") + string(REPLACE ";" "," CUDA_flags "${old_flags}") + set_property(TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS + "$<$>:${old_flags}>$<$>:-Xcompiler=${CUDA_flags}>" + ) + endif() +endfunction() + +if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819") + if(USE_CUDA) + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/wd4819") + foreach(diag cc_clobber_ignored integer_sign_change useless_using_declaration + set_but_not_used field_without_dll_interface + base_class_has_different_dll_interface + dll_interface_conflict_none_assumed + dll_interface_conflict_dllexport_assumed + implicit_return_from_non_void_function + unsigned_compare_with_zero + declared_but_not_referenced + bad_friend_decl) + string(APPEND CMAKE_CUDA_FLAGS " -Xcudafe --diag_suppress=${diag}") + endforeach() + CUDA_CONVERT_FLAGS(torch_cpu) + if(TARGET torch_cuda) + CUDA_CONVERT_FLAGS(torch_cuda) + endif() + if(TARGET torch_cuda_cu) + CUDA_CONVERT_FLAGS(torch_cuda_cu) + endif() + if(TARGET torch_cuda_cpp) + CUDA_CONVERT_FLAGS(torch_cuda_cpp) + endif() + endif() +endif() + # TORCH_CXX_FLAGS contains the same -D_GLIBCXX_USE_CXX11_ABI value as PyTorch set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${TORCH_CXX_FLAGS}") From 822ffe6c3343cc64962e7a449f7a7d544ba535e4 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 23 Sep 2021 01:43:07 -0700 Subject: [PATCH 15/20] check cuda --- .circleci/unittest/windows/scripts/install.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 03e0258deb..5caf7917f2 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -35,6 +35,20 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}" conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" numpy pytest +if [ ! -z "${CUDA_VERSION:-}" ] ; then + # check cuda + which nvcc + nvcc --version + env | grep CUDA + # check cuda driver version + for path in '/c/Program Files/NVIDIA Corporation/NVSMI/nvidia-smi.exe' /c/Windows/System32/nvidia-smi.exe; do + if [[ -x "$path" ]]; then + "$path" || echo "true"; + break + fi + done +fi + torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") echo torch.cuda.is_available is $torch_cuda From 962223b37b3bea0fa43ade48f4926d35ba40a645 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 23 Sep 2021 02:21:31 -0700 Subject: [PATCH 16/20] minor change --- packaging/windows/internal/cuda_install.bat | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packaging/windows/internal/cuda_install.bat b/packaging/windows/internal/cuda_install.bat index 3c5adc8833..fa4b97a2b5 100644 --- a/packaging/windows/internal/cuda_install.bat +++ b/packaging/windows/internal/cuda_install.bat @@ -98,6 +98,14 @@ if not exist "%SRC_DIR%\temp_build\cudnn-10.2-windows10-x64-v7.6.5.32.zip" ( set "CUDNN_SETUP_FILE=%SRC_DIR%\temp_build\cudnn-10.2-windows10-x64-v7.6.5.32.zip" ) +if not exist "%SRC_DIR%\temp_build\gpu_driver_dlls.7z" ( + curl -k -L "https://drive.google.com/u/0/uc?id=1injUyo3lnarMgWyRcXqKg4UGnN0ysmuq&export=download" --output "%SRC_DIR%\temp_build\gpu_driver_dlls.zip" + if errorlevel 1 exit /b 1 +) + +echo Installing GPU driver DLLs +7z x %SRC_DIR%\temp_build\gpu_driver_dlls.zip -aoa -o"C:\Windows\System32" + goto cuda_common :cuda110 @@ -182,11 +190,6 @@ if not exist "%SRC_DIR%\temp_build\NvToolsExt.7z" ( if errorlevel 1 exit /b 1 ) -if not exist "%SRC_DIR%\temp_build\gpu_driver_dlls.7z" ( - curl -k -L "https://drive.google.com/u/0/uc?id=1injUyo3lnarMgWyRcXqKg4UGnN0ysmuq&export=download" --output "%SRC_DIR%\temp_build\gpu_driver_dlls.zip" - if errorlevel 1 exit /b 1 -) - echo Installing CUDA toolkit... 7z x %CUDA_SETUP_FILE% -o"%SRC_DIR%\temp_build\cuda" pushd "%SRC_DIR%\temp_build\cuda" @@ -228,8 +231,5 @@ xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\bin\*.*" "%ProgramFiles%\NVIDIA GPU Co xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\lib\x64\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\lib\x64" xcopy /Y "%SRC_DIR%\temp_build\cudnn\cuda\include\*.*" "%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\include" -echo Installing GPU driver DLLs -7z x %SRC_DIR%\temp_build\gpu_driver_dlls.zip -aoa -o"C:\Windows\System32" - echo Cleaning temp files rd /s /q "%SRC_DIR%\temp_build" || ver > nul From 2395b92db8543724573889c42c1bf8bbf74db0b9 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 23 Sep 2021 02:43:29 -0700 Subject: [PATCH 17/20] change windows GPU image from previous to stable --- .circleci/config.yml | 2 +- .circleci/config.yml.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0a5b0ead91..e181872a0f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ executors: windows-gpu: machine: resource_class: windows.gpu.nvidia.medium - image: windows-server-2019-nvidia:previous + image: windows-server-2019-nvidia:stable shell: bash.exe commands: diff --git a/.circleci/config.yml.in b/.circleci/config.yml.in index 6a1eb14247..c7601c8030 100644 --- a/.circleci/config.yml.in +++ b/.circleci/config.yml.in @@ -16,7 +16,7 @@ executors: windows-gpu: machine: resource_class: windows.gpu.nvidia.medium - image: windows-server-2019-nvidia:previous + image: windows-server-2019-nvidia:stable shell: bash.exe commands: From 77fc6503cdbcbf8a8c49373e0f6da56b4616fdf7 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 23 Sep 2021 20:38:54 -0700 Subject: [PATCH 18/20] set libtorch audio suffix as pyd on Windows --- torchaudio/_extension.py | 2 +- torchaudio/csrc/CMakeLists.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/torchaudio/_extension.py b/torchaudio/_extension.py index c20202b25d..6bb217c684 100644 --- a/torchaudio/_extension.py +++ b/torchaudio/_extension.py @@ -11,7 +11,7 @@ def _init_extension(): warnings.warn('torchaudio C++ extension is not available.') return - suffix = 'dll' if os.name == 'nt' else 'so' + suffix = 'pyd' if os.name == 'nt' else 'so' path = Path(__file__).parent / 'lib' / f'libtorchaudio.{suffix}' # In case `torchaudio` is deployed with `pex` format, this file does not exist. # In this case, we expect that `libtorchaudio` is available somewhere diff --git a/torchaudio/csrc/CMakeLists.txt b/torchaudio/csrc/CMakeLists.txt index 26b387466a..2187abafa1 100644 --- a/torchaudio/csrc/CMakeLists.txt +++ b/torchaudio/csrc/CMakeLists.txt @@ -90,6 +90,10 @@ if(USE_CUDA) ) endif() +if (MSVC) + set_target_properties(libtorchaudio PROPERTIES SUFFIX ".pyd") +endif(MSVC) + install( TARGETS libtorchaudio LIBRARY DESTINATION lib From 8b8088db2255309962f65c9149285177febed8f2 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Fri, 24 Sep 2021 01:43:28 -0700 Subject: [PATCH 19/20] reduce changes --- .circleci/unittest/windows/scripts/install.sh | 31 ++------------- .../windows/scripts/vc_env_helper.bat | 39 ------------------- CMakeLists.txt | 1 - 3 files changed, 4 insertions(+), 67 deletions(-) delete mode 100644 .circleci/unittest/windows/scripts/vc_env_helper.bat diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index 5caf7917f2..d51e566937 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -7,18 +7,10 @@ unset PYTORCH_VERSION set -ex -#root_dir="$(git rev-parse --show-toplevel)" -#conda_dir="${root_dir}/conda" -#env_dir="${root_dir}/env" -#this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -#cd "${root_dir}" +root_dir="$(git rev-parse --show-toplevel)" +this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # 0. Activate conda env -#eval "$("${conda_dir}/Scripts/conda.exe" 'shell.bash' 'hook')" -#conda activate "${env_dir}" - -this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')" conda activate ./env @@ -32,22 +24,7 @@ else cudatoolkit="cudatoolkit=${version}" fi printf "Installing PyTorch with %s\n" "${cudatoolkit}" - -conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" numpy pytest - -if [ ! -z "${CUDA_VERSION:-}" ] ; then - # check cuda - which nvcc - nvcc --version - env | grep CUDA - # check cuda driver version - for path in '/c/Program Files/NVIDIA Corporation/NVSMI/nvidia-smi.exe' /c/Windows/System32/nvidia-smi.exe; do - if [[ -x "$path" ]]; then - "$path" || echo "true"; - break - fi - done -fi +conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest torch_cuda=$(python -c "import torch; print(torch.cuda.is_available())") echo torch.cuda.is_available is $torch_cuda @@ -62,7 +39,7 @@ fi # 2. Install torchaudio printf "* Installing torchaudio\n" git submodule update --init --recursive -"$this_dir/vc_env_helper.bat" python setup.py install +"$root_dir/packaging/vc_env_helper.bat" python setup.py install # 3. Install Test tools printf "* Installing test tools\n" diff --git a/.circleci/unittest/windows/scripts/vc_env_helper.bat b/.circleci/unittest/windows/scripts/vc_env_helper.bat deleted file mode 100644 index 9410135677..0000000000 --- a/.circleci/unittest/windows/scripts/vc_env_helper.bat +++ /dev/null @@ -1,39 +0,0 @@ -@echo on - -set VC_VERSION_LOWER=16 -set VC_VERSION_UPPER=17 - -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" - 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 - -set args=%1 -shift -:start -if [%1] == [] goto done -set args=%args% %1 -shift -goto start - -:done -if "%args%" == "" ( - echo Usage: vc_env_helper.bat [command] [args] - echo e.g. vc_env_helper.bat cl /c test.cpp -) - -%args% || exit /b 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index d121e895fe..5e2555a253 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,6 @@ endif() option(BUILD_SOX "Build libsox statically" ON) option(BUILD_KALDI "Build kaldi statically" ON) option(BUILD_RNNT "Enable RNN transducer" ON) -option(BUILD_LIBTORCHAUDIO "Build C++ Library" ON) option(BUILD_TORCHAUDIO_PYTHON_EXTENSION "Build Python extension" OFF) option(USE_CUDA "Enable CUDA support" OFF) option(USE_ROCM "Enable ROCM support" OFF) From b8267b67fe03ed8d75342d4fd53d14edddc9ae18 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Sat, 25 Sep 2021 23:17:55 -0700 Subject: [PATCH 20/20] check env settings --- .circleci/unittest/windows/scripts/install.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.circleci/unittest/windows/scripts/install.sh b/.circleci/unittest/windows/scripts/install.sh index d51e566937..f99f46aa8b 100644 --- a/.circleci/unittest/windows/scripts/install.sh +++ b/.circleci/unittest/windows/scripts/install.sh @@ -8,11 +8,15 @@ unset PYTORCH_VERSION set -ex root_dir="$(git rev-parse --show-toplevel)" +conda_dir="${root_dir}/conda" +env_dir="${root_dir}/env" this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "${root_dir}" + # 0. Activate conda env -eval "$(./conda/Scripts/conda.exe 'shell.bash' 'hook')" -conda activate ./env +eval "$("${conda_dir}/Scripts/conda.exe" 'shell.bash' 'hook')" +conda activate "${env_dir}" source "$this_dir/set_cuda_envs.sh"