You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by ha...@apache.org on 2020/08/06 15:54:40 UTC

[incubator-mxnet] branch master updated: Fix MXLibInfoCompiledWithCXX11ABI (#18864)

This is an automated email from the ASF dual-hosted git repository.

haibin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new a3eabf0  Fix MXLibInfoCompiledWithCXX11ABI (#18864)
a3eabf0 is described below

commit a3eabf0d29eaeb03766dd52ef403650a4804f369
Author: Leonard Lausen <la...@amazon.com>
AuthorDate: Thu Aug 6 15:52:52 2020 +0000

    Fix MXLibInfoCompiledWithCXX11ABI (#18864)
    
    * Fix MXLibInfoCompiledWithCXX11ABI
    
    * Fix test
---
 CMakeLists.txt                         |  7 -------
 config/darwin.cmake                    |  1 -
 config/distribution/darwin_cpu.cmake   |  1 -
 config/distribution/linux_cpu.cmake    |  1 -
 config/distribution/linux_cu100.cmake  |  1 -
 config/distribution/linux_cu101.cmake  |  1 -
 config/distribution/linux_cu102.cmake  |  1 -
 config/distribution/linux_cu92.cmake   |  1 -
 config/distribution/linux_native.cmake |  1 -
 config/linux.cmake                     |  1 -
 config/linux_gpu.cmake                 |  1 -
 include/mxnet/c_api.h                  |  2 +-
 include/mxnet/libinfo.h                |  7 -------
 python/mxnet/library.py                | 19 ++++++++++++++-----
 src/c_api/c_api.cc                     | 10 ++++++----
 src/libinfo.cc                         |  3 ---
 tests/python/unittest/test_runtime.py  |  4 ++--
 17 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2c86dd9..c1b722c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -89,7 +89,6 @@ cmake_dependent_option(ENABLE_TESTCOVERAGE "Enable compilation with test coverag
 option(USE_INT64_TENSOR_SIZE "Use int64_t to represent the total number of elements in a tensor" OFF)
 option(BUILD_CYTHON_MODULES "Build cython modules." OFF)
 option(LOG_FATAL_THROW "Log exceptions but do not abort" ON)
-option(USE_CXX11_ABI "Build with GLIBCXX_USE_CXX11_ABI" ON)
 cmake_dependent_option(USE_SPLIT_ARCH_DLL "Build a separate DLL for each Cuda arch (Windows only)." ON "MSVC" OFF)
 cmake_dependent_option(USE_CCACHE "Attempt using CCache to wrap the compilation" ON "UNIX" OFF)
 
@@ -100,12 +99,6 @@ message(STATUS "CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}")
 
 message(STATUS "CMAKE_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}")
 
-if(USE_CXX11_ABI)
-  add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
-else()
-  add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
-endif()
-
 if(USE_TVM_OP)
   add_definitions(-DMXNET_USE_TVM_OP=1)
 endif()
diff --git a/config/darwin.cmake b/config/darwin.cmake
index 12fd034..a65509f 100644
--- a/config/darwin.cmake
+++ b/config/darwin.cmake
@@ -128,4 +128,3 @@ set(USE_NCCL "Use NVidia NCCL with CUDA" OFF)
 set(NCCL_ROOT "" CACHE BOOL "NCCL install path. Supports autodetection.")
 set(ENABLE_CUDA_RTC ON CACHE BOOL "Build with CUDA runtime compilation support")
 set(USE_NVTX ON CACHE BOOL "Build with NVTX support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
diff --git a/config/distribution/darwin_cpu.cmake b/config/distribution/darwin_cpu.cmake
index f44e004..ed295ef 100644
--- a/config/distribution/darwin_cpu.cmake
+++ b/config/distribution/darwin_cpu.cmake
@@ -32,4 +32,3 @@ set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
 set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
 set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
 set(USE_DIST_KVSTORE ON CACHE BOOL "Build with DIST_KVSTORE support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
diff --git a/config/distribution/linux_cpu.cmake b/config/distribution/linux_cpu.cmake
index 83bb1b0..4579b42 100644
--- a/config/distribution/linux_cpu.cmake
+++ b/config/distribution/linux_cpu.cmake
@@ -30,4 +30,3 @@ set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
 set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
 set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
 set(USE_DIST_KVSTORE ON CACHE BOOL "Build with DIST_KVSTORE support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
diff --git a/config/distribution/linux_cu100.cmake b/config/distribution/linux_cu100.cmake
index b787c06..357ccd4 100644
--- a/config/distribution/linux_cu100.cmake
+++ b/config/distribution/linux_cu100.cmake
@@ -32,7 +32,6 @@ set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
 set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
 set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
 set(USE_DIST_KVSTORE ON CACHE BOOL "Build with DIST_KVSTORE support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
 
 set(CUDACXX "/usr/local/cuda-10.0/bin/nvcc" CACHE STRING "Cuda compiler")
 set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0" CACHE STRING "Cuda architectures")
diff --git a/config/distribution/linux_cu101.cmake b/config/distribution/linux_cu101.cmake
index 298b2a5..29fdda2 100644
--- a/config/distribution/linux_cu101.cmake
+++ b/config/distribution/linux_cu101.cmake
@@ -34,7 +34,6 @@ set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
 set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
 set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
 set(USE_DIST_KVSTORE ON CACHE BOOL "Build with DIST_KVSTORE support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
 
 set(CUDACXX "/usr/local/cuda-10.1/bin/nvcc" CACHE STRING "Cuda compiler")
 set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0" CACHE STRING "Cuda architectures")
diff --git a/config/distribution/linux_cu102.cmake b/config/distribution/linux_cu102.cmake
index 80ef232..4e7e050 100644
--- a/config/distribution/linux_cu102.cmake
+++ b/config/distribution/linux_cu102.cmake
@@ -32,7 +32,6 @@ set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
 set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
 set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
 set(USE_DIST_KVSTORE ON CACHE BOOL "Build with DIST_KVSTORE support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
 
 set(CUDACXX "/usr/local/cuda-10.2/bin/nvcc" CACHE STRING "Cuda compiler")
 set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0" CACHE STRING "Cuda architectures")
diff --git a/config/distribution/linux_cu92.cmake b/config/distribution/linux_cu92.cmake
index 4c767a2..8499421 100644
--- a/config/distribution/linux_cu92.cmake
+++ b/config/distribution/linux_cu92.cmake
@@ -31,7 +31,6 @@ set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.")
 set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
 set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
 set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
 
 set(CUDACXX "/usr/local/cuda-9.2/bin/nvcc" CACHE STRING "Cuda compiler")
 set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0" CACHE STRING "Cuda architectures")
diff --git a/config/distribution/linux_native.cmake b/config/distribution/linux_native.cmake
index 1be84ac..09fb495 100644
--- a/config/distribution/linux_native.cmake
+++ b/config/distribution/linux_native.cmake
@@ -29,4 +29,3 @@ set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.")
 set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support")
 set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support")
 set(USE_LIBJPEG_TURBO ON CACHE BOOL "Build with libjpeg-turbo")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
diff --git a/config/linux.cmake b/config/linux.cmake
index 9104da1..84eecc2 100644
--- a/config/linux.cmake
+++ b/config/linux.cmake
@@ -127,4 +127,3 @@ set(USE_NCCL "Use NVidia NCCL with CUDA" OFF)
 set(NCCL_ROOT "" CACHE BOOL "NCCL install path. Supports autodetection.")
 set(ENABLE_CUDA_RTC ON CACHE BOOL "Build with CUDA runtime compilation support")
 set(USE_NVTX ON CACHE BOOL "Build with NVTX support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
diff --git a/config/linux_gpu.cmake b/config/linux_gpu.cmake
index baef45e..0dad433 100644
--- a/config/linux_gpu.cmake
+++ b/config/linux_gpu.cmake
@@ -127,4 +127,3 @@ set(USE_NCCL "Use NVidia NCCL with CUDA" OFF)
 set(NCCL_ROOT "" CACHE BOOL "NCCL install path. Supports autodetection.")
 set(ENABLE_CUDA_RTC ON CACHE BOOL "Build with CUDA runtime compilation support")
 set(USE_NVTX ON CACHE BOOL "Build with NVTX support")
-set(USE_CXX11_ABI ON CACHE BOOL "Build with GLIBCXX_USE_CXX11_ABI")
diff --git a/include/mxnet/c_api.h b/include/mxnet/c_api.h
index 2aa0086..01ce188 100644
--- a/include/mxnet/c_api.h
+++ b/include/mxnet/c_api.h
@@ -256,7 +256,7 @@ MXNET_DLL int MXLibInfoFeatures(const struct LibFeature **libFeature, size_t *si
  * \brief return whether the mxnet library is compiled with cxx11 abi
  * \return whether mxnet is built with cxx11 abi
  */
-MXNET_DLL int MXLibInfoCompiledWithCXX11ABI(bool* result);
+MXNET_DLL int MXLibInfoCompiledWithCXX11ABI(int* result);
 
 /*!
  * \brief Seed all global random number generators in mxnet.
diff --git a/include/mxnet/libinfo.h b/include/mxnet/libinfo.h
index b1098b0..dd77900 100644
--- a/include/mxnet/libinfo.h
+++ b/include/mxnet/libinfo.h
@@ -131,12 +131,6 @@
 #define MXNET_USE_TVM_OP 0
 #endif
 
-#ifndef _GLIBCXX_USE_CXX11_ABI
-#define MXNET_GLIBCXX_USE_CXX11_ABI 0
-#else
-#define MXNET_GLIBCXX_USE_CXX11_ABI _GLIBCXX_USE_CXX11_ABI
-#endif
-
 namespace mxnet {
 namespace features {
 // Check compile flags such as CMakeLists.txt
@@ -210,7 +204,6 @@ struct LibInfo {
   const std::array<LibFeature, MAX_FEATURES>& getFeatures() {
     return m_lib_features;
   }
-  bool cxx11_abi();
  private:
   std::array<LibFeature, MAX_FEATURES> m_lib_features;
   static std::unique_ptr<LibInfo>  m_inst;
diff --git a/python/mxnet/library.py b/python/mxnet/library.py
index 9ce3f7b..487fff9 100644
--- a/python/mxnet/library.py
+++ b/python/mxnet/library.py
@@ -73,14 +73,23 @@ def load(path, verbose=True):
         func = getattr(mx_sym_op, op)
         setattr(mx_sym, op, func)
 
-def compiled_with_cxx11_abi():
-    """Check if the library is compiled with cxx11 ABI.
+
+def compiled_with_gcc_cxx11_abi():
+    """Check if the library is compiled with _GLIBCXX_USE_CXX11_ABI.
+
+    Please see
+    https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html for
+    more information. When building libraries relying on MXNet C++ headers, it
+    is required to use the same C++ ABI in the library as well as in libmxnet.
 
     Returns
     -------
-    bool
-        Whether the library is compiled with cxx11 ABI.
+    int
+        1 If compiled with _GLIBCXX_USE_CXX11_ABI=1
+        0 If compiled with _GLIBCXX_USE_CXX11_ABI=0
+       -1 If compiled with a compiler that does not support _GLIBCXX_USE_CXX11_ABI
+
     """
-    ret = ctypes.c_bool()
+    ret = ctypes.c_int()
     check_call(_LIB.MXLibInfoCompiledWithCXX11ABI(ctypes.byref(ret)))
     return ret.value
diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc
index 011994b..ab367b9 100644
--- a/src/c_api/c_api.cc
+++ b/src/c_api/c_api.cc
@@ -1299,11 +1299,13 @@ int MXLibInfoFeatures(const struct LibFeature **lib_features, size_t *size) {
   API_END();
 }
 
-int MXLibInfoCompiledWithCXX11ABI(bool* result) {
-  using namespace features;
+int MXLibInfoCompiledWithCXX11ABI(int* result) {
   API_BEGIN();
-  LibInfo* lib_info = LibInfo::getInstance();
-  *result = lib_info->cxx11_abi();
+#ifdef _GLIBCXX_USE_CXX11_ABI
+  *result = _GLIBCXX_USE_CXX11_ABI;
+#else
+  *result = -1;
+#endif
   API_END();
 }
 
diff --git a/src/libinfo.cc b/src/libinfo.cc
index ce7f126..d14aaf5 100644
--- a/src/libinfo.cc
+++ b/src/libinfo.cc
@@ -126,9 +126,6 @@ LibInfo *LibInfo::getInstance() {
         m_inst = std::make_unique<LibInfo>();
     return m_inst.get();
 }
-bool LibInfo::cxx11_abi() {
-  return MXNET_GLIBCXX_USE_CXX11_ABI;
-}
 
 std::unique_ptr<LibInfo> LibInfo::m_inst = nullptr;
 
diff --git a/tests/python/unittest/test_runtime.py b/tests/python/unittest/test_runtime.py
index d117ac0..13f992a 100644
--- a/tests/python/unittest/test_runtime.py
+++ b/tests/python/unittest/test_runtime.py
@@ -50,5 +50,5 @@ def test_is_enabled_not_existing():
         features.is_enabled('this girl is on fire')
 
 def test_cxx11_abi():
-    abi = mx.library.compiled_with_cxx11_abi()
-    assert abi or not abi
+    abi = mx.library.compiled_with_gcc_cxx11_abi()
+    assert abi in (-1, 0, 1)