Skip to content

Commit aa5c190

Browse files
committed
Add OpenMP support
1 parent 0f82217 commit aa5c190

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ option(BUILD_RNNT "Enable RNN transducer" ON)
5353
option(BUILD_TORCHAUDIO_PYTHON_EXTENSION "Build Python extension" OFF)
5454
option(USE_CUDA "Enable CUDA support" OFF)
5555
option(USE_ROCM "Enable ROCM support" OFF)
56-
56+
option(USE_OPENMP "Enable OpenMP support" OFF)
5757

5858
# check that USE_CUDA and USE_ROCM are not set at the same time
5959
if(USE_CUDA AND USE_ROCM)
@@ -74,6 +74,13 @@ endif()
7474

7575
find_package(Torch REQUIRED)
7676

77+
if(USE_OPENMP)
78+
find_package(OpenMP)
79+
if (NOT OpenMP_CXX_FOUND)
80+
message(WARNING "OpenMP support is disabled.")
81+
endif()
82+
endif()
83+
7784
# TORCH_CXX_FLAGS contains the same -D_GLIBCXX_USE_CXX11_ABI value as PyTorch
7885
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${TORCH_CXX_FLAGS}")
7986

build_tools/setup_helpers/extension.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def _get_build(var, default=False):
3939
_BUILD_RNNT = _get_build("BUILD_RNNT", True)
4040
_USE_ROCM = _get_build("USE_ROCM", torch.cuda.is_available() and torch.version.hip is not None)
4141
_USE_CUDA = _get_build("USE_CUDA", torch.cuda.is_available() and torch.version.hip is None)
42+
_USE_OPENMP = _get_build("USE_OPENMP", True) and 'ATen parallel backend: OpenMP' in torch.__config__.parallel_info()
4243
_TORCH_CUDA_ARCH_LIST = os.environ.get('TORCH_CUDA_ARCH_LIST', None)
4344

4445

@@ -90,6 +91,7 @@ def build_extension(self, ext):
9091
"-DBUILD_TORCHAUDIO_PYTHON_EXTENSION:BOOL=ON",
9192
f"-DUSE_ROCM:BOOL={'ON' if _USE_ROCM else 'OFF'}",
9293
f"-DUSE_CUDA:BOOL={'ON' if _USE_CUDA else 'OFF'}",
94+
f"-DUSE_OPENMP:BOOL={'ON' if _USE_OPENMP else 'OFF'}",
9395
]
9496
build_args = [
9597
'--target', 'install'

torchaudio/csrc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ if(USE_CUDA)
9090
)
9191
endif()
9292

93+
if(OpenMP_CXX_FOUND)
94+
target_link_libraries(libtorchaudio OpenMP::OpenMP_CXX)
95+
endif()
96+
9397
install(
9498
TARGETS libtorchaudio
9599
LIBRARY DESTINATION .

0 commit comments

Comments
 (0)