Skip to content

Commit 3b9a1ac

Browse files
committed
fix undefined symbol: _ZTIN10tensorflow8OpKernelE, more debug info
https://travis-ci.org/rwth-i6/returnn/jobs/296331208 tensorflow/tensorflow#13607
1 parent 13145e3 commit 3b9a1ac

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

TFUtil.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -2111,16 +2111,19 @@ class OpCodeCompiler(NativeCodeCompiler):
21112111
"""
21122112
Helper class to compile TF ops on-the-fly, similar as Theano.
21132113
https://www.tensorflow.org/versions/master/how_tos/adding_an_op/
2114+
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/extend/adding_an_op.md
21142115
"""
21152116

21162117
CacheDirName = "returnn_tf_cache/ops"
21172118

2118-
def __init__(self, use_cuda_if_available=True, include_paths=(), **kwargs):
2119+
def __init__(self, use_cuda_if_available=True, include_paths=(), ld_flags=(), **kwargs):
21192120
self._cuda_env = use_cuda_if_available and CudaEnv.get_instance()
21202121
tf_include = tf.sysconfig.get_include() # e.g. "...python2.7/site-packages/tensorflow/include"
21212122
tf_include_nsync = tf_include + "/external/nsync/public" # https://github.com/tensorflow/tensorflow/issues/2412
21222123
include_paths = list(include_paths) + [tf_include, tf_include_nsync]
2123-
super(OpCodeCompiler, self).__init__(include_paths=include_paths, **kwargs)
2124+
# https://github.com/tensorflow/tensorflow/issues/13607
2125+
ld_flags = list(ld_flags) + ["-L%s" % tf.sysconfig.get_lib(), "-ltensorflow_framework"]
2126+
super(OpCodeCompiler, self).__init__(include_paths=include_paths, ld_flags=ld_flags, **kwargs)
21242127
self._tf_mod = None
21252128

21262129
_relevant_info_keys = NativeCodeCompiler._relevant_info_keys + ("tf_version", "with_cuda")
@@ -2151,10 +2154,6 @@ def load_tf_module(self):
21512154
if self._tf_mod:
21522155
return self._tf_mod
21532156
self._maybe_compile()
2154-
# https://github.com/tensorflow/tensorflow/issues/6568
2155-
if hasattr(sys, "getdlopenflags") and hasattr(sys, "setdlopenflags"):
2156-
import ctypes
2157-
sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
21582157
self._tf_mod = tf.load_op_library(self._so_filename)
21592158
return self._tf_mod
21602159

tests/test_TFNativeOp.py

+54-17
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,60 @@
2525
session = tf.InteractiveSession()
2626

2727

28-
def dump_info():
29-
numpy_path = os.path.dirname(numpy.__file__)
30-
print("Numpy path: %r" % numpy_path)
31-
so_files = Util.sysexecOut("find %s | grep \"\.so\"" % numpy_path, shell=True)
32-
print("Numpy so files:\n---\n%s\n---\n" % so_files)
33-
so_files = [f for f in so_files.splitlines() if f]
28+
def sys_exec(*args, shell=False):
29+
print("$ %s" % " ".join(args))
30+
out = Util.sysexecOut(*args, shell=shell)
31+
print(out)
32+
33+
34+
def debug_lib_so(f, syms=()):
3435
ldd = "ldd"
3536
if sys.platform == "darwin":
3637
ldd = "otool -L"
3738
objdump = "objdump -T"
3839
if sys.platform == "darwin":
3940
objdump = "otool -IHGv"
41+
cmd = "%s %s" % (ldd, f)
42+
sys_exec(cmd, shell=True)
43+
for sym in syms:
44+
cmd = "%s %s | { grep %s || true; }" % (objdump, f, sym)
45+
sys_exec(cmd, shell=True)
46+
47+
48+
def dump_info():
49+
# Some generic stuff.
50+
sys_exec("g++", "--version")
51+
print("TF include:", tf.sysconfig.get_include())
52+
print("TF lib:", tf.sysconfig.get_lib())
53+
tf_lib_so = tf.sysconfig.get_lib() + "/libtensorflow_framework.so"
54+
tf_pywrap_so = tf.sysconfig.get_lib() + "/python/_pywrap_tensorflow_internal.so"
55+
sys_exec("ls", "-la", tf.sysconfig.get_lib())
56+
if os.path.exists(tf_lib_so):
57+
print("TF lib so exists:", tf_lib_so)
58+
debug_lib_so(tf_lib_so, ["_ZTIN10tensorflow8OpKernelE"])
59+
else:
60+
print("TF lib so does not(!) exist:", tf_lib_so)
61+
if os.path.exists(tf_pywrap_so):
62+
print("TF pywrap so exists:", tf_pywrap_so)
63+
debug_lib_so(tf_pywrap_so, ["_ZTIN10tensorflow8OpKernelE"])
64+
else:
65+
print("TF pywrap so does not(!) exist:", tf_pywrap_so)
66+
# See OpCodeCompiler. Is already not used anymore but still maybe relevant.
67+
if hasattr(sys, "getdlopenflags") and hasattr(sys, "setdlopenflags"):
68+
print("have (set|get)dlopenflags")
69+
import ctypes
70+
print("Cur flags: %r, RTLD_GLOBAL is set: %r" % (sys.getdlopenflags(), sys.getdlopenflags() & ctypes.RTLD_GLOBAL))
71+
if os.path.exists("/proc"):
72+
print("Have /proc")
73+
sys_exec("cat", "/proc/%i/maps" % os.getpid())
74+
# Numpy stuff, debugging if sgemm was not found:
75+
numpy_path = os.path.dirname(numpy.__file__)
76+
print("Numpy path: %r" % numpy_path)
77+
so_files = Util.sysexecOut("find %s | grep \"\.so\"" % numpy_path, shell=True)
78+
print("Numpy so files:\n---\n%s\n---\n" % so_files)
79+
so_files = [f for f in so_files.splitlines() if f]
4080
for f in so_files:
41-
cmd = "%s %s" % (ldd, f)
42-
print("$ %s" % cmd)
43-
out = Util.sysexecOut(cmd, shell=True)
44-
print(out)
45-
cmd = "%s %s | { grep sgemm || true; }" % (objdump, f)
46-
print("$ %s" % cmd)
47-
out = Util.sysexecOut(cmd, shell=True)
48-
print(out)
81+
debug_lib_so(f, ["sgemm"])
4982

5083

5184
def test_dummy():
@@ -55,7 +88,7 @@ def test_dummy():
5588

5689
def test_make_lstm_op_auto_cuda():
5790
try:
58-
make_lstm_op()
91+
make_lstm_op(compiler_opts={"verbose": True})
5992
except tf.errors.NotFoundError:
6093
dump_info()
6194
raise
@@ -64,7 +97,7 @@ def test_make_lstm_op_auto_cuda():
6497
def test_make_lstm_op_no_cuda():
6598
try:
6699
OpMaker.with_cuda = False
67-
make_lstm_op()
100+
make_lstm_op(compiler_opts={"verbose": True})
68101
except tf.errors.NotFoundError:
69102
dump_info()
70103
raise
@@ -930,8 +963,12 @@ def test_fast_bw_uniform():
930963
if k.startswith("test_"):
931964
print("-" * 40)
932965
print("Executing: %s" % k)
933-
v()
966+
try:
967+
v()
968+
except unittest.SkipTest as exc:
969+
print("SkipTest: %s" % exc)
934970
print("-" * 40)
971+
print("All passed.")
935972
else:
936973
assert len(sys.argv) >= 2
937974
for arg in sys.argv[1:]:

0 commit comments

Comments
 (0)