File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed
build_tools/setup_helpers Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ option(BUILD_RNNT "Enable RNN transducer" ON)
5353option (BUILD_TORCHAUDIO_PYTHON_EXTENSION "Build Python extension" OFF )
5454option (USE_CUDA "Enable CUDA support" OFF )
5555option (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
5959if (USE_CUDA AND USE_ROCM)
@@ -74,6 +74,13 @@ endif()
7474
7575find_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
7885set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${TORCH_CXX_FLAGS} " )
7986
Original file line number Diff line number Diff 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'
Original file line number Diff line number Diff line change @@ -90,6 +90,10 @@ if(USE_CUDA)
9090 )
9191endif ()
9292
93+ if (OpenMP_CXX_FOUND)
94+ target_link_libraries (libtorchaudio OpenMP::OpenMP_CXX)
95+ endif ()
96+
9397install (
9498 TARGETS libtorchaudio
9599 LIBRARY DESTINATION .
You can’t perform that action at this time.
0 commit comments