Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2017 16:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save apaszke/5397c16ef9b68316f55da7dadf19035f to your computer and use it in GitHub Desktop.
# Usage:
# LD_DEBUG=bindings <program> >bindings_dump 2>&1
# python bindings_dump
import sys
import os
from collections import defaultdict
class colors:
red = '\033[91m'
clear = '\033[0m'
# Detect PyTorch libs
torch_libs = set()
torch_libs_paths = set()
def register_lib(libpath):
if '/torch/' in libpath:
def color_lib(libname):
color = if libname in torch_libs else ''
return color + libname + colors.clear
# Parse the file
with open(sys.argv[1], 'r') as f:
lines ='\n')
lib_bindings = defaultdict(set)
for l in lines:
if 'binding file' not in l: continue
fields = l.split()
bound_lib_path = fields[3]
symbol_lib_path = fields[6]
symbol_name = fields[10]
bound_lib = os.path.basename(bound_lib_path)
symbol_lib = os.path.basename(symbol_lib_path)
if bound_lib != symbol_lib:
# Print lib imports
for lib, symbol_libs in lib_bindings.items():
print('{} imported symbols from:'.format(color_lib(lib)))
for slib in symbol_libs:
print('\t' + color_lib(slib))
# Warnings for PyTorch exports
for lib, symbol_libs in lib_bindings.items():
if lib in torch_libs: continue
for slib in symbol_libs:
if slib in torch_libs:
print('WARNING: non-torch lib {} imported symbols from torch lib {}'.format(lib, slib))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment