@@ -24,36 +24,43 @@ function full_copy_so(){
fi
}
function patch_elf_depend_lib() {
echo "handle common depend lib"
function handle_copy_cuda_libs() {
TO_DIR=$1
if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
echo "handle cuda lib to ${TO_DIR}"
cp ${BUILD_DIR}/dnn/cuda-stub/libcuda_stub.so ${TO_DIR}
handle_strip ${TO_DIR}/libcuda_stub.so
cp /usr/local/cuda/lib64/libnvToolsExt.so.1 ${TO_DIR}
IFS=: read -a lib_name_array <<<"$CUDA_COPY_LIB_LIST"
append_rpath='$ORIGIN/.'
for lib_name in ${lib_name_array[@]};do
echo "cuda copy detail: ${lib_name} to ${TO_DIR}"
full_copy_so $lib_name ${TO_DIR} $lib_append_rpath
done
fi
}
function patch_elf_depend_lib_mgb_mge() {
echo "handle common depend lib for mgb or mge"
LIBS_DIR=${BUILD_DIR}/staging/megengine/core/lib
mkdir -p ${LIBS_DIR}
cp /usr/lib64/libatomic.so.1 ${LIBS_DIR}
patchelf --remove-rpath ${BUILD_DIR}/staging/megengine/core/_imperative_rt.so
patchelf --force-rpath --set-rpath '$ORIGIN/lib' ${BUILD_DIR}/staging/megengine/core/_imperative_rt.so
cp ${BUILD_DIR}/src/libmegengine_export.so ${LIBS_DIR}
patchelf --remove-rpath ${LIBS_DIR}/libmegengine_export.so
patchelf --force-rpath --set-rpath '$ORIGIN/.' ${LIBS_DIR}/libmegengine_export.so
handle_strip ${BUILD_DIR}/staging/megengine/core/_imperative_rt.so
cp ${BUILD_DIR}/src/libmegengine_export.so ${LIBS_DIR}
patchelf --remove-rpath ${LIBS_DIR}/libmegengine_export.so
patchelf --force-rpath --set-rpath '$ORIGIN/.' ${LIBS_DIR}/libmegengine_export.so
handle_strip ${LIBS_DIR}/libmegengine_export.so
if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
echo "handle cuda lib"
cp ${BUILD_DIR}/dnn/cuda-stub/libcuda_stub.so ${LIBS_DIR}
cp /usr/local/cuda/lib64/libnvToolsExt.so.1 ${LIBS_DIR}
IFS=: read -a lib_name_array <<<"$COPY_LIB_LIST"
append_rpath='$ORIGIN/.'
for lib_name in ${lib_name_array[@]};do
full_copy_so $lib_name ${LIBS_DIR} $lib_append_rpath
done
fi
# as some version of cudnn/trt libs have dlopen libs, so we can not use auditwheel
# TODO: PR for auditwheel to support args for dlopen libs
handle_copy_cuda_libs ${LIBS_DIR}
}
ALL_PYTHON=${ALL_PYTHON}
if [[ -z ${ALL_PYTHON} ]]
then
@@ -71,10 +78,9 @@ BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_OFF/MGE_INFERENCE_ONLY_OFF/Rel
if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
BUILD_DIR=${SRC_DIR}/build_dir/host/MGE_WITH_CUDA_ON/MGE_INFERENCE_ONLY_OFF/Release/build/
fi
NEW_LIB_PATH=core/lib
for ver in ${ALL_PYTHON}
do
USE_AUDITWHEEL="ON"
python_ver=${ver:0:2}
MAJOR=${python_ver:0:1}
MINOR=${ver:1}
@@ -87,6 +93,7 @@ do
export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DPYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python${MAJOR}.${MINOR}"
export EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DMGE_WITH_ATLAS=ON"
# TODO: after change to Ninja, only the fisrt loop need add -r to save build time
if [ ${BUILD_WHL_CPU_ONLY} = "OFF" ]; then
${SRC_DIR}/scripts/cmake-build/host_build.sh -c -t -r
else
@@ -99,38 +106,23 @@ do
cp -a imperative/python/{megengine,setup.py,requires.txt,requires-style.txt,requires-test.txt} staging/
handle_strip ${BUILD_DIR}/src/libmegengine_export.so
cd ${BUILD_DIR}/staging/megengine/core
handle_strip _imperative_rt.so
mkdir -p lib/ucx
if [ ${USE_AUDITWHEEL} = "OFF" ]; then
patch_elf_depend_lib
fi
patch_elf_depend_lib_mgb_mge
cd ${BUILD_DIR}/staging/
${PYTHON_DIR}/bin/python setup.py bdist_wheel
cd /home/output
if [ ${USE_AUDITWHEEL} = "ON" ]; then
LD_LIBRARY_PATH=${BUILD_DIR}/dnn/cuda-stub:$LD_LIBRARY_PATH auditwheel repair -L ${NEW_LIB_PATH} ${BUILD_DIR}/staging/dist/Meg*.whl
else
mkdir -p ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}
cd ${BUILD_DIR}/staging/dist/
org_whl_name=`ls Meg*${ver}*.whl`
compat_whl_name=`echo ${org_whl_name} | sed 's/linux/manylinux2014/'`
echo "org whl name: ${org_whl_name}"
echo "comapt whl name: ${compat_whl_name}"
mv ${org_whl_name} ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}/${compat_whl_name}
cd /home/output
fi
mkdir -p ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}
cd ${BUILD_DIR}/staging/dist/
org_whl_name=`ls Meg*${ver}*.whl`
compat_whl_name=`echo ${org_whl_name} | sed 's/linux/manylinux2014/'`
echo "org whl name: ${org_whl_name}"
echo "comapt whl name: ${compat_whl_name}"
mv ${org_whl_name} ${SRC_DIR}/scripts/whl/manylinux2014/output/wheelhouse/${SDK_NAME}/${compat_whl_name}
cd /home/output
chown -R ${UID}.${UID} .
# compat for root-less docker env to remove output at host side
chmod -R 777 .
echo "python $ver done"
done