Skip to content

Commit c733586

Browse files
committed
Switch to cmake for build
1 parent 4406a6b commit c733586

File tree

12 files changed

+281
-182
lines changed

12 files changed

+281
-182
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ commands:
4242
description: "installs tools required to build torchaudio"
4343
steps:
4444
- run:
45-
name: Install cmake and pkg-config
46-
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install cmake pkg-config wget
45+
name: Install pkg-config
46+
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install pkg-config wget
4747
# Disable brew auto update which is very slow
4848

4949
binary_common: &binary_common
@@ -433,7 +433,7 @@ jobs:
433433
resource_class: gpu.small
434434
environment:
435435
<<: *environment
436-
image_name: "pytorch/torchaudio_unittest_base:manylinux-cuda10.1"
436+
image_name: pytorch/torchaudio_unittest_base:manylinux-cuda10.1-cudnn7-20201203
437437
steps:
438438
- checkout
439439
- attach_workspace:

.circleci/config.yml.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ commands:
4242
description: "installs tools required to build torchaudio"
4343
steps:
4444
- run:
45-
name: Install cmake and pkg-config
46-
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install cmake pkg-config wget
45+
name: Install pkg-config
46+
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install pkg-config wget
4747
# Disable brew auto update which is very slow
4848

4949
binary_common: &binary_common
@@ -433,7 +433,7 @@ jobs:
433433
resource_class: gpu.small
434434
environment:
435435
<<: *environment
436-
image_name: "pytorch/torchaudio_unittest_base:manylinux-cuda10.1"
436+
image_name: pytorch/torchaudio_unittest_base:manylinux-cuda10.1-cudnn7-20201203
437437
steps:
438438
- checkout
439439
- attach_workspace:

.circleci/torchscript_bc_test/environment.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ dependencies:
77
- pytest
88
- pytest-cov
99
- codecov
10-
- librosa
10+
- librosa>=0.8.0
1111
- llvmlite==0.31 # See https://github.com/pytorch/audio/pull/766
1212
- pip
1313
- pip:
14+
- cmake
15+
- ninja
1416
- kaldi-io
1517
- scipy
1618
- parameterized

.circleci/unittest/linux/docker/build_and_push.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ if [ $# -ne 1 ]; then
77
exit 1
88
fi
99

10+
datestr="$(date "+%Y%m%d")"
1011
if [ "$1" = "cpu" ]; then
1112
base_image="ubuntu:18.04"
12-
image="pytorch/torchaudio_unittest_base:manylinux"
13-
elif [[ "$1" =~ ^(9.2|10.1)$ ]]; then
14-
base_image="nvidia/cuda:$1-runtime-ubuntu18.04"
15-
image="pytorch/torchaudio_unittest_base:manylinux-cuda$1"
13+
image="pytorch/torchaudio_unittest_base:manylinux-${datestr}"
1614
else
17-
printf "Unexpected <CUDA_VERSION> string: %s" "$1"
18-
exit 1;
15+
base_image="nvidia/cuda:$1-devel-ubuntu18.04"
16+
docker pull "${base_image}"
17+
image="pytorch/torchaudio_unittest_base:manylinux-cuda$1-${datestr}"
1918
fi
2019

2120
cd "$( dirname "${BASH_SOURCE[0]}" )"

.circleci/unittest/linux/scripts/setup_env.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# Do not install PyTorch and torchaudio here, otherwise they also get cached.
77

8-
set -e
8+
set -ex
99

1010
root_dir="$(git rev-parse --show-toplevel)"
1111
conda_dir="${root_dir}/conda"
@@ -41,11 +41,3 @@ conda activate "${env_dir}"
4141

4242
# 3. Install minimal build tools
4343
pip --quiet install cmake ninja
44-
45-
# 4. Buld codecs
46-
mkdir -p third_party/build
47-
(
48-
cd third_party/build
49-
cmake -GNinja ..
50-
cmake --build .
51-
)

CMakeLists.txt

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
3+
project(torchaudio)
4+
5+
option(BUILD_SOX "Build SoX and bind statically" OFF)
6+
option(BUILD_LIBTORCHAUDIO "Build C++ Library" ON)
7+
option(BUILD_PYTHON_EXTENSION "Build Python extension" OFF)
8+
9+
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard whose features are requested to build this target.")
10+
11+
find_package(Torch REQUIRED)
12+
# Set -D_GLIBCXX_USE_CXX11_ABI for third party builds
13+
if (DEFINED _GLIBCXX_USE_CXX11_ABI)
14+
set(CXXFLAGS "${CXXFLAGS} -D_GLIBCXX_USE_CXX11_ABI=${_GLIBCXX_USE_CXX11_ABI}")
15+
endif()
16+
17+
if (APPLE)
18+
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
19+
endif()
20+
21+
add_subdirectory(third_party)
22+
23+
################################################################################
24+
# Beginning of torchaudio extension configuration
25+
################################################################################
26+
27+
set(TORCHAUDIO_CSRC "${CMAKE_CURRENT_SOURCE_DIR}/torchaudio/csrc")
28+
29+
set(
30+
LIBTORCHAUDIO_SOURCES
31+
"${TORCHAUDIO_CSRC}/sox_io.cpp"
32+
"${TORCHAUDIO_CSRC}/sox_utils.cpp"
33+
"${TORCHAUDIO_CSRC}/sox_effects.cpp"
34+
"${TORCHAUDIO_CSRC}/sox_effects_chain.cpp"
35+
"${TORCHAUDIO_CSRC}/register.cpp"
36+
)
37+
38+
################################################################################
39+
# libtorchaudio.so
40+
################################################################################
41+
if(BUILD_LIBTORCHAUDIO)
42+
add_library(
43+
libtorchaudio
44+
SHARED
45+
${LIBTORCHAUDIO_SOURCES}
46+
)
47+
set_target_properties(libtorchaudio PROPERTIES PREFIX "")
48+
49+
target_include_directories(
50+
libtorchaudio
51+
PRIVATE
52+
${CMAKE_CURRENT_SOURCE_DIR}
53+
)
54+
55+
target_link_libraries(
56+
libtorchaudio
57+
"${TORCHAUDIO_THIRD_PARTIES}"
58+
"${TORCH_LIBRARIES}"
59+
)
60+
61+
install(
62+
TARGETS
63+
libtorchaudio
64+
)
65+
66+
set(TORCHAUDIO_LIBRARY -Wl,--no-as-needed libtorchaudio -Wl,--as-needed CACHE INTERNAL "")
67+
endif()
68+
69+
################################################################################
70+
# _torchaudio.so
71+
################################################################################
72+
if (BUILD_PYTHON_EXTENSION)
73+
add_library(
74+
_torchaudio
75+
SHARED
76+
${TORCHAUDIO_CSRC}/sox.cpp
77+
${LIBTORCHAUDIO_SOURCES}
78+
)
79+
80+
set_target_properties(_torchaudio PROPERTIES PREFIX "")
81+
82+
if (APPLE)
83+
# https://github.com/facebookarchive/caffe2/issues/854#issuecomment-364538485
84+
# https://github.com/pytorch/pytorch/commit/73f6715f4725a0723d8171d3131e09ac7abf0666
85+
set_target_properties(_torchaudio PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
86+
endif()
87+
88+
target_include_directories(
89+
_torchaudio
90+
PRIVATE
91+
${CMAKE_CURRENT_SOURCE_DIR}
92+
${Python_INCLUDE_DIR}
93+
)
94+
95+
# See https://github.com/pytorch/pytorch/issues/38122
96+
find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib")
97+
98+
target_link_libraries(
99+
_torchaudio
100+
${TORCHAUDIO_THIRD_PARTIES}
101+
${TORCH_LIBRARIES}
102+
${TORCH_PYTHON_LIBRARY}
103+
)
104+
105+
# We do not define install for _torchaudio.so
106+
# The location of installation is controlled by "CMAKE_LIBRARY_OUTPUT_DIRECTORY" and the
107+
# resulting file is handled by setuptools.
108+
endif()

0 commit comments

Comments
 (0)