From 7e02f539746a01d89ee121dd46985314e8991409 Mon Sep 17 00:00:00 2001 From: "eric-haibin-lin linhaibin.eric@gmail.com" Date: Fri, 31 Jul 2020 19:58:09 +0000 Subject: [PATCH 1/4] draft --- include/mxnet/c_api.h | 6 ++++++ include/mxnet/libinfo.h | 7 +++++++ src/c_api/c_api.cc | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/include/mxnet/c_api.h b/include/mxnet/c_api.h index 04d863991b48..2aa00861ff32 100644 --- a/include/mxnet/c_api.h +++ b/include/mxnet/c_api.h @@ -252,6 +252,12 @@ MXNET_DLL int MXLoadLib(const char *path, unsigned verbose); */ MXNET_DLL int MXLibInfoFeatures(const struct LibFeature **libFeature, size_t *size); +/*! + * \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); + /*! * \brief Seed all global random number generators in mxnet. * \param seed the random number seed. diff --git a/include/mxnet/libinfo.h b/include/mxnet/libinfo.h index dd7790059de1..7b326598cb2d 100644 --- a/include/mxnet/libinfo.h +++ b/include/mxnet/libinfo.h @@ -131,6 +131,10 @@ #define MXNET_USE_TVM_OP 0 #endif +#ifndef _GLIBCXX_USE_CXX11_ABI +#define MXNET_GLIBCXX_USE_CXX11_ABI 0 +#endif + namespace mxnet { namespace features { // Check compile flags such as CMakeLists.txt @@ -204,6 +208,9 @@ struct LibInfo { const std::array& getFeatures() { return m_lib_features; } + bool cxx11_abi() { + return MXNET_GLIBCXX_USE_CXX11_ABI == 0; + } private: std::array m_lib_features; static std::unique_ptr m_inst; diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index 3d73ceb03267..647f70131624 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1299,6 +1299,15 @@ int MXLibInfoFeatures(const struct LibFeature **lib_features, size_t *size) { API_END(); } +int MXLibInfoCompiledWithCXX11ABI(bool* result); + using namespace features; + API_BEGIN(); + LibInfo* lib_info = LibInfo::getInstance(); + // *result = lib_info->getFeatures().data(); + API_END(); +} + + int MXRandomSeed(int seed) { API_BEGIN(); mxnet::RandomSeed(seed); From 9fd39127bb39cdf3fd6d862e76c9208d6f40ab27 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 31 Jul 2020 22:57:41 +0000 Subject: [PATCH 2/4] add impl --- CMakeLists.txt | 6 ++++++ 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/libinfo.h | 6 +++--- python/mxnet/library.py | 12 ++++++++++++ src/c_api/c_api.cc | 4 ++-- src/libinfo.cc | 3 +++ 15 files changed, 36 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e302ac7b865c..eb5562480184 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,12 @@ 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 a65509f0ba1c..12fd034c07c9 100644 --- a/config/darwin.cmake +++ b/config/darwin.cmake @@ -128,3 +128,4 @@ 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 ed295efd33d2..f44e004eb420 100644 --- a/config/distribution/darwin_cpu.cmake +++ b/config/distribution/darwin_cpu.cmake @@ -32,3 +32,4 @@ 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 4579b42fce5c..83bb1b07f53e 100644 --- a/config/distribution/linux_cpu.cmake +++ b/config/distribution/linux_cpu.cmake @@ -30,3 +30,4 @@ 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 357ccd457593..b787c0666a4c 100644 --- a/config/distribution/linux_cu100.cmake +++ b/config/distribution/linux_cu100.cmake @@ -32,6 +32,7 @@ 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 29fdda2d6f0a..298b2a5e21e2 100644 --- a/config/distribution/linux_cu101.cmake +++ b/config/distribution/linux_cu101.cmake @@ -34,6 +34,7 @@ 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 4e7e0509e4f9..80ef2320d599 100644 --- a/config/distribution/linux_cu102.cmake +++ b/config/distribution/linux_cu102.cmake @@ -32,6 +32,7 @@ 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 8499421f91ec..4c767a2cc839 100644 --- a/config/distribution/linux_cu92.cmake +++ b/config/distribution/linux_cu92.cmake @@ -31,6 +31,7 @@ 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 09fb4956ae80..1be84ac79937 100644 --- a/config/distribution/linux_native.cmake +++ b/config/distribution/linux_native.cmake @@ -29,3 +29,4 @@ 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 84eecc2e9701..9104da142e63 100644 --- a/config/linux.cmake +++ b/config/linux.cmake @@ -127,3 +127,4 @@ 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 0dad43332978..baef45e4157b 100644 --- a/config/linux_gpu.cmake +++ b/config/linux_gpu.cmake @@ -127,3 +127,4 @@ 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/libinfo.h b/include/mxnet/libinfo.h index 7b326598cb2d..b1098b002dd7 100644 --- a/include/mxnet/libinfo.h +++ b/include/mxnet/libinfo.h @@ -133,6 +133,8 @@ #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 { @@ -208,9 +210,7 @@ struct LibInfo { const std::array& getFeatures() { return m_lib_features; } - bool cxx11_abi() { - return MXNET_GLIBCXX_USE_CXX11_ABI == 0; - } + bool cxx11_abi(); private: std::array m_lib_features; static std::unique_ptr m_inst; diff --git a/python/mxnet/library.py b/python/mxnet/library.py index e0c60d4588f9..9ce3f7b2223e 100644 --- a/python/mxnet/library.py +++ b/python/mxnet/library.py @@ -72,3 +72,15 @@ def load(path, verbose=True): for op in dir(mx_sym_op): 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. + + Returns + ------- + bool + Whether the library is compiled with cxx11 ABI. + """ + ret = ctypes.c_bool() + 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 647f70131624..011994b54c67 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1299,11 +1299,11 @@ int MXLibInfoFeatures(const struct LibFeature **lib_features, size_t *size) { API_END(); } -int MXLibInfoCompiledWithCXX11ABI(bool* result); +int MXLibInfoCompiledWithCXX11ABI(bool* result) { using namespace features; API_BEGIN(); LibInfo* lib_info = LibInfo::getInstance(); - // *result = lib_info->getFeatures().data(); + *result = lib_info->cxx11_abi(); API_END(); } diff --git a/src/libinfo.cc b/src/libinfo.cc index d14aaf5769b2..ce7f1266eaeb 100644 --- a/src/libinfo.cc +++ b/src/libinfo.cc @@ -126,6 +126,9 @@ LibInfo *LibInfo::getInstance() { m_inst = std::make_unique(); return m_inst.get(); } +bool LibInfo::cxx11_abi() { + return MXNET_GLIBCXX_USE_CXX11_ABI; +} std::unique_ptr LibInfo::m_inst = nullptr; From 376e9e92d845fb82a74cc27cc99c6b7f7353e0af Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 31 Jul 2020 23:07:05 +0000 Subject: [PATCH 3/4] add test --- tests/python/unittest/test_runtime.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/python/unittest/test_runtime.py b/tests/python/unittest/test_runtime.py index f1811554ba2d..d117ac0f4b30 100644 --- a/tests/python/unittest/test_runtime.py +++ b/tests/python/unittest/test_runtime.py @@ -49,3 +49,6 @@ def test_is_enabled_not_existing(): with pytest.raises(RuntimeError): features.is_enabled('this girl is on fire') +def test_cxx11_abi(): + abi = mx.library.compiled_with_cxx11_abi() + assert abi or not abi From 7f2d4a73fcca1185bb09cd32ee0cef1e6aca0f74 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 31 Jul 2020 23:49:16 +0000 Subject: [PATCH 4/4] set default val --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb5562480184..c9e2e1886f9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ 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)