Skip to content

Commit b3bb7bc

Browse files
authored
[STABLE ABI] Verify that torchaudio is torch ABI stable. (#4142)
* [STABLE ABI] Specify TORCH_TARGET_VERSION to verify that torchaudio is torch ABI stable. * Undefine TORCH_TARGET_VERSION for pybind.
1 parent dca045a commit b3bb7bc

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ else()
152152
endif()
153153
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warning_flags} ${TORCH_CXX_FLAGS}")
154154

155+
# Ensure that torchaudio is torch ABI stable.
156+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTORCH_TARGET_VERSION=0x020a000000000000")
157+
155158
find_program(CCACHE_PROGRAM ccache)
156159
if(CCACHE_PROGRAM)
157160
message(STATUS "Found ccache")

src/libtorchaudio/cuctc/src/python_binding.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,25 @@
2323
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2424
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
// It is safe to temporarily disable TORCH_TARGET_VERSION for pybind11
28+
// as it is a header-only library.
29+
#ifdef TORCH_TARGET_VERSION
30+
#define SAVE_TORCH_TARGET_VERSION TORCH_TARGET_VERSION
31+
#undef TORCH_TARGET_VERSION
32+
#endif
2633
#include <pybind11/pybind11.h>
2734
#include <pybind11/stl.h>
35+
#ifdef SAVE_TORCH_TARGET_VERSION
36+
#define TORCH_TARGET_VERSION SAVE_TORCH_TARGET_VERSION
37+
#undef SAVE_TORCH_TARGET_VERSION
38+
#endif
39+
2840
#include <tuple>
2941
#include <utility>
3042
#include <vector>
3143
#include "include/ctc_prefix_decoder.h"
44+
3245
namespace py = pybind11;
3346

3447
std::tuple<size_t, std::vector<std::vector<std::pair<float, std::vector<int>>>>>

src/libtorchaudio/pybind/pybind.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#include <libtorchaudio/utils.h>
2+
3+
// It is safe to temporarily disable TORCH_TARGET_VERSION for pybind11
4+
// as it is a header-only library.
5+
#ifdef TORCH_TARGET_VERSION
6+
#define SAVE_TORCH_TARGET_VERSION TORCH_TARGET_VERSION
7+
#undef TORCH_TARGET_VERSION
8+
#endif
29
#include <pybind11/pybind11.h>
310
#include <pybind11/stl.h>
11+
#ifdef SAVE_TORCH_TARGET_VERSION
12+
#define TORCH_TARGET_VERSION SAVE_TORCH_TARGET_VERSION
13+
#undef SAVE_TORCH_TARGET_VERSION
14+
#endif
415

516
namespace torchaudio {
617
namespace {

0 commit comments

Comments
 (0)