I have written a multi-threaded module called fast_nn
in Cython
and compiled it with the following setup.py
:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
setup(
ext_modules = cythonize([
Extension("fast_nn", ["fast_nn.pyx"], language = 'c++', extra_compile_args = ['-O3', '-fopenmp'], extra_link_args = ['-fopenmp'], include_dirs = [numpy.get_include()])
])
)
In addition, I use the python bindings of the caffe
framework.
If I use my module alone or pycaffe
alone, everything is fine. However, the following combination is problematic:
import caffe.io
import fast_nn
On one machine, it does not lead to any problems. On another machine, I get the following exception:
Traceback (most recent call last):
File "test.py", line 2, in <module>
import fast_nn
ImportError: dlopen: cannot load any more object with static TLS
From this thread I understand that too many libraries with initial-exec static TLS have been loaded dynamically. But what can I do to work around this problem? Is there some way to compile my module with static TLS disabled or a better solution?
However, the output of readelf -a fast_nn.cpython-35m-x86_64-linux-gnu.so | grep TLS
does not show any TLS symbols in my library. But some dependent libraries contain such symbols.
Solutions tried so far
Changing the order of the two imports (i.e., importing caffe
after my cython
module) solves the problem. However, since my actual real-world case is much more complex and both modules are imported indirectly from other imports, I cannot change the order of imports.
Similarly, exporting the path of my compiled module library to LD_PRELOAD
has the same effect, but is not an elegant solution either.