Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
9395ad64
Unverified
Commit
9395ad64
authored
Mar 05, 2021
by
Caroline Chen
Committed by
GitHub
Mar 05, 2021
Browse files
enable C++ extension on Windows (#1345)
parent
e868d24c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
245 additions
and
8 deletions
+245
-8
.circleci/unittest/windows/scripts/install.sh
.circleci/unittest/windows/scripts/install.sh
+2
-1
.circleci/unittest/windows/scripts/setup_env.sh
.circleci/unittest/windows/scripts/setup_env.sh
+3
-0
build_tools/setup_helpers/extension.py
build_tools/setup_helpers/extension.py
+11
-5
packaging/build_conda.sh
packaging/build_conda.sh
+1
-0
packaging/build_wheel.sh
packaging/build_wheel.sh
+1
-1
packaging/pkg_helpers.bash
packaging/pkg_helpers.bash
+10
-0
packaging/vc_env_helper.bat
packaging/vc_env_helper.bat
+39
-0
packaging/vs2019/activate.bat
packaging/vs2019/activate.bat
+44
-0
packaging/vs2019/conda_build_config.yaml
packaging/vs2019/conda_build_config.yaml
+24
-0
packaging/vs2019/install_activate.bat
packaging/vs2019/install_activate.bat
+30
-0
packaging/vs2019/install_runtime.bat
packaging/vs2019/install_runtime.bat
+49
-0
packaging/vs2019/meta.yaml
packaging/vs2019/meta.yaml
+24
-0
torchaudio/backend/sox_io_backend.py
torchaudio/backend/sox_io_backend.py
+1
-1
torchaudio/csrc/CMakeLists.txt
torchaudio/csrc/CMakeLists.txt
+6
-0
No files found.
.circleci/unittest/windows/scripts/install.sh
View file @
9395ad64
...
...
@@ -29,7 +29,8 @@ conda install ${CONDA_CHANNEL_FLAGS:-} -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorc
# 2. Install torchaudio
printf
"* Installing torchaudio
\n
"
python setup.py
install
git submodule update
--init
--recursive
"
$root_dir
/packaging/vc_env_helper.bat"
python setup.py
install
# 3. Install Test tools
printf
"* Installing test tools
\n
"
...
...
.circleci/unittest/windows/scripts/setup_env.sh
View file @
9395ad64
...
...
@@ -37,3 +37,6 @@ if [ ! -d "${env_dir}" ]; then
conda create
--prefix
"
${
env_dir
}
"
-y
python
=
"
${
PYTHON_VERSION
}
"
fi
conda activate
"
${
env_dir
}
"
# 3. Install minimal build tools
pip
--quiet
install
cmake ninja
build_tools/setup_helpers/extension.py
View file @
9395ad64
...
...
@@ -34,14 +34,12 @@ def _get_build(var, default=False):
return
False
_BUILD_SOX
=
_get_build
(
"BUILD_SOX"
)
_BUILD_KALDI
=
_get_build
(
"BUILD_KALDI"
,
True
)
_BUILD_SOX
=
False
if
platform
.
system
()
==
'Windows'
else
_get_build
(
"BUILD_SOX"
)
_BUILD_KALDI
=
False
if
platform
.
system
()
==
'Windows'
else
_get_build
(
"BUILD_KALDI"
,
True
)
_BUILD_TRANSDUCER
=
_get_build
(
"BUILD_TRANSDUCER"
)
def
get_ext_modules
():
if
platform
.
system
()
==
'Windows'
:
return
None
return
[
Extension
(
name
=
'torchaudio._torchaudio'
,
sources
=
[])]
...
...
@@ -82,8 +80,16 @@ class CMakeBuild(build_ext):
]
# Default to Ninja
if
'CMAKE_GENERATOR'
not
in
os
.
environ
:
if
'CMAKE_GENERATOR'
not
in
os
.
environ
or
platform
.
system
()
==
'Windows'
:
cmake_args
+=
[
"-GNinja"
]
if
platform
.
system
()
==
'Windows'
:
import
sys
python_version
=
sys
.
version_info
cmake_args
+=
[
"-DCMAKE_C_COMPILER=cl"
,
"-DCMAKE_CXX_COMPILER=cl"
,
f
"-DPYTHON_VERSION=
{
python_version
.
major
}
.
{
python_version
.
minor
}
"
,
]
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
...
...
packaging/build_conda.sh
View file @
9395ad64
...
...
@@ -9,4 +9,5 @@ export NO_CUDA_PACKAGE=1
setup_env 0.9.0
export
SOURCE_ROOT_DIR
=
"
$PWD
"
setup_conda_pytorch_constraint
setup_visual_studio_constraint
conda build
$CONDA_CHANNEL_FLAGS
--no-anaconda-upload
--python
"
$PYTHON_VERSION
"
packaging/torchaudio
packaging/build_wheel.sh
View file @
9395ad64
...
...
@@ -13,7 +13,7 @@ setup_pip_pytorch_version
python setup.py clean
if
[[
"
$OSTYPE
"
==
"msys"
]]
;
then
python_tag
=
"
$(
echo
"cp
$PYTHON_VERSION
"
|
tr
-d
'.'
)
"
python setup.py bdist_wheel
--plat-name
win_amd64
--python-tag
$python_tag
"
$script_dir
/vc_env_helper.bat"
python setup.py bdist_wheel
--plat-name
win_amd64
--python-tag
$python_tag
else
BUILD_TRANSDUCER
=
1
BUILD_SOX
=
1 python setup.py bdist_wheel
fi
packaging/pkg_helpers.bash
View file @
9395ad64
...
...
@@ -221,3 +221,13 @@ setup_conda_cudatoolkit_constraint() {
esac
fi
}
# 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
=
''
conda build
$CONDA_CHANNEL_FLAGS
--no-anaconda-upload
packaging/
$VSTOOLCHAIN_PACKAGE
cp
packaging/
$VSTOOLCHAIN_PACKAGE
/conda_build_config.yaml packaging/torchaudio/conda_build_config.yaml
fi
}
packaging/vc_env_helper.bat
0 → 100644
View file @
9395ad64
@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
"
%VS1
5VCVARSALL
%
"
x64
||
exit
/b
1
)
else
(
call
"
%VS1
5VCVARSALL
%
"
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
packaging/vs2019/activate.bat
0 → 100644
View file @
9395ad64
:: Set env vars that tell distutils to use the compiler that we put on path
SET
DISTUTILS_USE_SDK
=
1
SET
MSSdk
=
1
SET
"VS_VERSION=16.0"
SET
"VS_MAJOR=16"
SET
"VS_YEAR=2019"
set
"MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"
set
"MSYS2_ENV_CONV_EXCL=CL"
:: For Python 3.5+, ensure that we link with the dynamic runtime. See
:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info
set
"PY_VCRUNTIME_REDIST=
%PREFIX%
\\bin\\vcruntime140.dll"
for
/f
"usebackq tokens=*"
%%i
in
(
`"
%ProgramFiles
(x86)
%
\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [16
^,
17
^)
-property installationPath`
)
do
(
if
exist
"
%%i
"
if
exist
"
%%i
\VC\Auxiliary\Build\vcvarsall.bat"
(
set
"VSINSTALLDIR=
%%i
\"
goto
:vswhere
)
)
:vswhere
:: Shorten PATH to avoid the `input line too long` error.
SET
MyPath
=
%PATH%
setlocal
EnableDelayedExpansion
SET
TempPath
=
"
%MyPath
:;="
;
"
%
"
SET
var
=
FOR
%%a
IN
(
%TempPath%
)
DO
(
IF
EXIST
%%~sa
(
SET
"var=
!var!
;
%%~sa
"
)
)
set
"TempPath=
!
var:~1
!
"
endlocal
&
set
"PATH=
%TempPath%
"
:: Shorten current directory too
FOR
%%A
IN
(
.
)
DO
CD
"
%%~sA
"
:: other things added by install_activate.bat at package build time
packaging/vs2019/conda_build_config.yaml
0 → 100644
View file @
9395ad64
blas_impl
:
-
mkl
# [x86_64]
c_compiler
:
-
vs2019
# [win]
cxx_compiler
:
-
vs2019
# [win]
python
:
-
3.5
-
3.6
# This differs from target_platform in that it determines what subdir the compiler
# will target, not what subdir the compiler package will be itself.
# For example, we need a win-64 vs2008_win-32 package, so that we compile win-32
# code on win-64 miniconda.
cross_compiler_target_platform
:
-
win-64
# [win]
target_platform
:
-
win-64
# [win]
vc
:
-
14
zip_keys
:
-
# [win]
-
vc
# [win]
-
c_compiler
# [win]
-
cxx_compiler
# [win]
packaging/vs2019/install_activate.bat
0 → 100644
View file @
9395ad64
set
YEAR
=
2019
set
VER
=
16
mkdir
"
%PREFIX%
\etc\conda\activate.d"
COPY
"
%RECIPE_DIR%
\activate.bat"
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
IF
"
%cross_compiler_target_platform%
"
==
"win-64"
(
set
"target_platform=amd64"
echo
SET
"CMAKE_GENERATOR=Visual Studio
%VER%
%YEAR%
Win64"
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
pushd
"
%%VSINSTALLDIR%%
"
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
IF
"
%VSDEVCMD_ARGS%
"
==
""
(
echo
CALL
"VC\Auxiliary\Build\vcvarsall.bat"
x64
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
popd
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
pushd
"
%%VSINSTALLDIR%%
"
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
CALL
"VC\Auxiliary\Build\vcvarsall.bat"
x86_amd64
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
)
ELSE
(
echo
CALL
"VC\Auxiliary\Build\vcvarsall.bat"
x64
%VSDEVCMD_ARGS%
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
popd
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
pushd
"
%%VSINSTALLDIR%%
"
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
CALL
"VC\Auxiliary\Build\vcvarsall.bat"
x86_amd64
%VSDEVCMD_ARGS%
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
)
echo
popd
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
)
else
(
set
"target_platform=x86"
echo
SET
"CMAKE_GENERATOR=Visual Studio
%VER%
%YEAR%
"
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
pushd
"
%%VSINSTALLDIR%%
"
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
CALL
"VC\Auxiliary\Build\vcvars32.bat"
>>
"
%PREFIX%
\etc\conda\activate.d\vs
%YEAR%
_compiler_vars.bat"
echo
popd
)
packaging/vs2019/install_runtime.bat
0 → 100644
View file @
9395ad64
set
VC_PATH
=
x86
if
"
%ARCH%
"
==
"64"
(
set
VC_PATH
=
x64
)
set
MSC_VER
=
2019
rem :: This should always be present for VC installed with VS. Not sure about VC installed with Visual C++ Build Tools 2015
rem FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\Microsoft\DevDiv\VC\Servicing\14.0\IDE.x64" /v UpdateVersion`) DO (
rem set SP=%%A
rem )
rem if not "%SP%" == "%PKG_VERSION%" (
rem echo "Version detected from registry: %SP%"
rem echo "does not match version of package being built (%PKG_VERSION%)"
rem echo "Do you have current updates for VS 2015 installed?"
rem exit 1
rem )
REM ========== REQUIRES Win 10 SDK be installed, or files otherwise copied to location below!
robocopy
"C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\
%VC_PATH%
"
"
%LIBRARY_BIN%
"
*
.dll
/E
robocopy
"C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\
%VC_PATH%
"
"
%PREFIX%
"
*
.dll
/E
if
%ERRORLEVEL%
GEQ
8
exit
1
REM ========== This one comes from visual studio 2019
set
"VC_VER=142"
for
/f
"usebackq tokens=*"
%%i
in
(
`"
%ProgramFiles
(x86)
%
\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [16
^,
17
^)
-property installationPath`
)
do
(
if
exist
"
%%i
"
if
exist
"
%%i
\VC\Auxiliary\Build\vcvarsall.bat"
(
set
"VS15VCVARSALL=
%%i
\VC\Auxiliary\Build\vcvarsall.bat"
goto
:eof
)
)
@setlocal
call
"
%VS1
5VARSALL
%
"
x64
set
"REDIST_ROOT=
%VCToolsRedistDir%%
VC_PATH
%
"
robocopy
"
%REDIST_ROOT%
\Microsoft.VC
%VC_VER%
.CRT"
"
%LIBRARY_BIN%
"
*
.dll
/E
if
%ERRORLEVEL%
LSS
8
exit
0
robocopy
"
%REDIST_ROOT%
\Microsoft.VC
%VC_VER%
.CRT"
"
%PREFIX%
"
*
.dll
/E
if
%ERRORLEVEL%
LSS
8
exit
0
robocopy
"
%REDIST_ROOT%
\Microsoft.VC
%VC_VER%
.OpenMP"
"
%LIBRARY_BIN%
"
*
.dll
/E
if
%ERRORLEVEL%
LSS
8
exit
0
robocopy
"
%REDIST_ROOT%
\Microsoft.VC
%VC_VER%
.OpenMP"
"
%PREFIX%
"
*
.dll
/E
if
%ERRORLEVEL%
LSS
8
exit
0
@endlocal
packaging/vs2019/meta.yaml
0 → 100644
View file @
9395ad64
{
%
set vcver="14.2" %
}
{
%
set vcfeature="14" %
}
{
%
set vsyear="2019" %
}
{
%
set fullver="15.4.27004.2010" %
}
package
:
name
:
vs{{ vsyear }}
version
:
{{
fullver
}}
build
:
skip
:
True [not win]
script_env
:
-
VSDEVCMD_ARGS
# [win]
outputs
:
-
name
:
vs{{ vsyear }}_{{ cross_compiler_target_platform }}
script
:
install_activate.bat
track_features
:
# VS 2019 is binary-compatible with VS 2017/vc 14.1 and 2015/vc14. Tools are "v142".
strong
:
-
vc{{ vcfeature }}
about
:
summary
:
Activation and version verification of MSVC {{ vcver }} (VS {{ vsyear }}) compiler
license
:
BSD 3-clause
torchaudio/backend/sox_io_backend.py
View file @
9395ad64
...
...
@@ -315,7 +315,7 @@ def save(
filepath
,
src
,
sample_rate
,
channels_first
,
compression
,
format
,
encoding
,
bits_per_sample
)
@
_mod_utils
.
requires_
module
(
'torchaudio._torchaudio'
)
@
_mod_utils
.
requires_
sox
(
)
@
_mod_utils
.
deprecated
(
'Please use "torchaudio.load".'
,
'0.9.0'
)
def
load_wav
(
filepath
:
str
,
...
...
torchaudio/csrc/CMakeLists.txt
View file @
9395ad64
...
...
@@ -103,11 +103,17 @@ if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
# See https://github.com/pytorch/pytorch/issues/38122
find_library
(
TORCH_PYTHON_LIBRARY torch_python PATHS
"
${
TORCH_INSTALL_PREFIX
}
/lib"
)
if
(
WIN32
)
find_package
(
Python3
${
PYTHON_VERSION
}
EXACT COMPONENTS Development
)
set
(
ADDITIONAL_ITEMS Python3::Python
)
endif
()
target_link_libraries
(
_torchaudio
${
TORCH_LIBRARIES
}
${
TORCH_PYTHON_LIBRARY
}
${
TORCHAUDIO_THIRD_PARTIES
}
${
ADDITIONAL_ITEMS
}
)
install
(
TARGETS _torchaudio LIBRARY DESTINATION
${
CMAKE_INSTALL_PREFIX
}
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment