Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add compiled_with_cxx11_abi API #18836

Merged
merged 4 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -99,6 +100,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()
Expand Down
1 change: 1 addition & 0 deletions config/darwin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/distribution/darwin_cpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/distribution/linux_cpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/distribution/linux_cu100.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/distribution/linux_cu101.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/distribution/linux_cu102.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/distribution/linux_cu92.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/distribution/linux_native.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions config/linux_gpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
6 changes: 6 additions & 0 deletions include/mxnet/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions include/mxnet/libinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
#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
Expand Down Expand Up @@ -204,6 +210,7 @@ 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;
Expand Down
12 changes: 12 additions & 0 deletions python/mxnet/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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->cxx11_abi();
API_END();
}


int MXRandomSeed(int seed) {
API_BEGIN();
mxnet::RandomSeed(seed);
Expand Down
3 changes: 3 additions & 0 deletions src/libinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ 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;

Expand Down
3 changes: 3 additions & 0 deletions tests/python/unittest/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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