Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add with_musl compile option to support musl-linux #27798

Merged
merged 1 commit into from
Oct 12, 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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ option(WITH_LITE "Compile Paddle Fluid with Lite Engine" OFF)
option(WITH_NCCL "Compile PaddlePaddle with NCCL support" ON)
option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" ON)
option(WITH_ARM "Compile PaddlePaddle with arm support" OFF)
option(WITH_MUSL "Compile with musl libc instead of gblic" OFF)

# PY_VERSION
if(NOT PY_VERSION)
Expand Down
10 changes: 10 additions & 0 deletions cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ if(WIN32)
endif(NOT MSVC)
endif(WIN32)

if(WITH_MUSL)
add_definitions(-DPADDLE_WITH_MUSL)

message(STATUS, "Set compile option WITH_MKL=OFF when WITH_MUSL=ON")
SET(WITH_MKL OFF)

message(STATUS, "Set compile option WITH_GPU=OFF when WITH_MUSL=ON")
SET(WITH_GPU OFF)
endif()

if(WITH_PSLIB)
add_definitions(-DPADDLE_WITH_PSLIB)
endif()
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if(NOT APPLE AND NOT WIN32)
set_target_properties(paddle_fluid_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
# check symbol hidden
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/check_symbol.cmake
"execute_process(COMMAND bash -c \"${CMAKE_CURRENT_SOURCE_DIR}/check_symbol.sh"
"execute_process(COMMAND sh -c \"${CMAKE_CURRENT_SOURCE_DIR}/check_symbol.sh"
" ${CMAKE_CURRENT_BINARY_DIR}/libpaddle_fluid.so\" RESULT_VARIABLE symbol_res)\n"
"if(NOT \"\${symbol_res}\" STREQUAL \"0\")\n"
" message(FATAL_ERROR \"Check symbol failed.\")\n"
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/check_symbol.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

lib=$1
if [ $# -ne 1 ]; then echo "No input library"; exit -1 ; fi
Expand Down
11 changes: 8 additions & 3 deletions paddle/fluid/platform/enforce.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ limitations under the License. */
#include <type_traits>
#include <utility>

#if !defined(_WIN32) && !defined(PADDLE_WITH_MUSL)
#include <execinfo.h>
#endif

#define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h
#include "glog/logging.h"
#include "paddle/fluid/platform/errors.h"
Expand Down Expand Up @@ -236,13 +240,14 @@ inline std::string SimplifyDemangleStr(std::string str) {
}

inline std::string GetCurrentTraceBackString() {
static constexpr int TRACE_STACK_LIMIT = 100;
std::ostringstream sout;

sout << "\n\n--------------------------------------\n";
sout << "C++ Traceback (most recent call last):";
sout << "\n--------------------------------------\n";
#if !defined(_WIN32)
#if !defined(_WIN32) && !defined(PADDLE_WITH_MUSL)
static constexpr int TRACE_STACK_LIMIT = 100;

void* call_stack[TRACE_STACK_LIMIT];
auto size = backtrace(call_stack, TRACE_STACK_LIMIT);
auto symbols = backtrace_symbols(call_stack, size);
Expand All @@ -261,7 +266,7 @@ inline std::string GetCurrentTraceBackString() {
}
free(symbols);
#else
sout << "Windows not support stack backtrace yet.\n";
sout << "Not support stack backtrace yet.\n";
#endif
return sout.str();
}
Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/platform/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ limitations under the License. */
classname& operator=(classname&&) = delete
#endif

#ifndef PADDLE_WITH_MUSL
#if defined(__FLT_MAX__)
#define FLT_MAX __FLT_MAX__
#endif // __FLT_MAX__
#endif // PADDLE_WITH_MUSL
9 changes: 4 additions & 5 deletions paddle/fluid/platform/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@

#pragma once

#include <cstdio>
#include <stdexcept>

#include <time.h>

#include <cstdio>
#include <memory>
#include <stdexcept>
#include <string>

#define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h
#include "glog/logging.h"

#if !defined(_WIN32)
#include <dlfcn.h> // dladdr
#include <execinfo.h> // backtrace
#include <dlfcn.h> // dladdr
#include <sys/stat.h>
#include <sys/time.h>
#include <algorithm> // std::accumulate
Expand Down
26 changes: 17 additions & 9 deletions python/paddle/fluid/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,15 @@ def pre_load(dso_name):
load_dso(dso_path)


def get_glibc_ver():
return run_shell_command("ldd --version | awk '/ldd/{print $NF}'")
def get_libc_ver():
ldd_glibc = run_shell_command("ldd --version | awk '/ldd/{print $NF}'")
if ldd_glibc is not None:
return ("glibc", ldd_glibc)

ldd_musl = run_shell_command("ldd 2>&1 | awk '/Version/{print $NF}'")
if ldd_musl is not None:
return ("musl", ldd_musl)
return (None, None)


def less_than_ver(a, b):
Expand All @@ -231,13 +238,14 @@ def to_list(s):
# For paddle, the problem is that 'libgomp' is a DSO with static TLS, and it is loaded after 14 DSOs.
# So, here is a tricky way to solve the problem by pre load 'libgomp' before 'core_avx.so'.
# The final solution is to upgrade glibc to > 2.22 on the target system.
if platform.system().lower() == 'linux' and less_than_ver(get_glibc_ver(),
'2.23'):
try:
pre_load('libgomp')
except Exception as e:
# NOTE(zhiqiu): do not abort if failed, since it may success when import core_avx.so
sys.stderr.write('Error: Can not preload libgomp.so')
if platform.system().lower() == 'linux':
libc_type, libc_ver = get_libc_ver()
if libc_type == 'glibc' and less_than_ver(libc_ver, '2.23'):
try:
pre_load('libgomp')
except Exception as e:
# NOTE(zhiqiu): do not abort if failed, since it may success when import core_avx.so
sys.stderr.write('Error: Can not preload libgomp.so')

load_noavx = False

Expand Down