1
1
from setuptools import setup, Distribution, Extension
2
2
import subprocess
3
+ import shutil
4
+ import os
3
5
class BinaryDistribution(Distribution):
4
6
def has_ext_modules(foo):
5
7
return True
@@ -62,6 +64,7 @@ write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version.py')
62
64
63
65
64
66
packages=['paddle',
67
+ 'paddle.libs',
65
68
'paddle.utils',
66
69
'paddle.dataset',
67
70
'paddle.reader',
@@ -113,12 +116,33 @@ package_dir={
113
116
}
114
117
if '${WITH_FLUID_ONLY}'== 'OFF':
115
118
package_dir['py_paddle']='${PADDLE_BINARY_DIR}/python/py_paddle'
116
-
117
119
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)
122
146
123
147
setup(name='${PACKAGE_NAME}',
124
148
version='${PADDLE_VERSION}',
@@ -128,6 +152,5 @@ setup(name='${PACKAGE_NAME}',
128
152
ext_modules=[Extension('_foo', ['stub.cc'])],
129
153
package_data=package_data,
130
154
package_dir=package_dir,
131
- scripts=paddle_bins,
132
- data_files=[(paddle_rt_lib_dir, paddle_rt_libs)]
155
+ scripts=paddle_bins
133
156
)
0 commit comments