Skip to content

Commit 7a735f2

Browse files
luotao1tensor-tang
authored andcommitted
use -rpath to fix libmklml_intel.so not found (#11806)
* use -rpath to fix libmklml_intel.so not found * only remain $ORIGIN/../libs in rpath of core.so * test * test * add rpath of libmkldnn.so.0 * check return value of os.system * remove check return value of patchelf
1 parent 8b80d6d commit 7a735f2

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ENV HOME /root
2323
COPY ./paddle/scripts/docker/root/ /root/
2424

2525
RUN apt-get update && \
26-
apt-get install -y --allow-downgrades \
26+
apt-get install -y --allow-downgrades patchelf \
2727
git python-pip python-dev python-opencv openssh-server bison \
2828
libnccl2=2.1.2-1+cuda8.0 libnccl-dev=2.1.2-1+cuda8.0 \
2929
wget unzip unrar tar xz-utils bzip2 gzip coreutils ntp \

python/paddle/libs/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# used for setup.py.in to store the thirdparty shared libraries

python/setup.py.in

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from setuptools import setup, Distribution, Extension
22
import subprocess
3+
import shutil
4+
import os
35
class BinaryDistribution(Distribution):
46
def has_ext_modules(foo):
57
return True
@@ -62,6 +64,7 @@ write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version.py')
6264

6365

6466
packages=['paddle',
67+
'paddle.libs',
6568
'paddle.utils',
6669
'paddle.dataset',
6770
'paddle.reader',
@@ -113,12 +116,33 @@ package_dir={
113116
}
114117
if '${WITH_FLUID_ONLY}'== 'OFF':
115118
package_dir['py_paddle']='${PADDLE_BINARY_DIR}/python/py_paddle'
116-
117119

118-
paddle_rt_lib_dir = 'lib'
119-
paddle_rt_libs = ['${WARPCTC_LIBRARIES}']
120-
if '${MKL_SHARED_LIBS}'!= '':
121-
paddle_rt_libs += '${MKL_SHARED_LIBS}'.split(';')
120+
# put all thirdparty libraries in paddle.libs
121+
package_data['paddle.libs']=['libwarpctc.so']
122+
libs_path='${PADDLE_BINARY_DIR}/python/paddle/libs'
123+
shutil.copy('${WARPCTC_LIBRARIES}', libs_path)
124+
if '${WITH_MKL}' == 'ON':
125+
shutil.copy('${MKLML_LIB}', libs_path)
126+
shutil.copy('${MKLML_IOMP_LIB}', libs_path)
127+
package_data['paddle.libs']+=['libmklml_intel.so','libiomp5.so']
128+
if '${WITH_MKLDNN}' == 'ON':
129+
# change rpath of libmkldnn.so.0, add $ORIGIN/ to it.
130+
# The reason is that all thirdparty libraries in the same directory,
131+
# thus, libmkldnn.so.0 will find libmklml_intel.so and libiomp5.so.
132+
command = "patchelf --set-rpath '$ORIGIN/' ${MKLDNN_SHARED_LIB}"
133+
os.system(command)
134+
package_data['paddle.libs']+=['libmkldnn.so.0']
135+
shutil.copy('${MKLDNN_SHARED_LIB}', libs_path)
136+
# remove unused paddle/libs/__init__.py
137+
os.remove(libs_path+'/__init__.py')
138+
package_dir['paddle.libs']=libs_path
139+
140+
# change rpath of core.so, add $ORIGIN/../libs/ to it.
141+
# The reason is that libwarpctc.so, libiomp5.so etc are in paddle.libs, and
142+
# core.so is in paddle.fluid, thus paddle/fluid/../libs will pointer to above libraries.
143+
# This operation will fix https://github.com/PaddlePaddle/Paddle/issues/3213
144+
command = "patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/core.so"
145+
os.system(command)
122146

123147
setup(name='${PACKAGE_NAME}',
124148
version='${PADDLE_VERSION}',
@@ -128,6 +152,5 @@ setup(name='${PACKAGE_NAME}',
128152
ext_modules=[Extension('_foo', ['stub.cc'])],
129153
package_data=package_data,
130154
package_dir=package_dir,
131-
scripts=paddle_bins,
132-
data_files=[(paddle_rt_lib_dir, paddle_rt_libs)]
155+
scripts=paddle_bins
133156
)

0 commit comments

Comments
 (0)