How to see C++ function invocations behind the SWIG interface, TensorFlow

1.1k views Asked by At

I'm working on TensorFlow and I want to know the relationship between each Python function and the correspondent C++ functions behind the SWIG interface. In other words, I want to be able to know exactly which C++ functions are invoked for every line of Python code of my TensorFlow application.

I already saw how to debug the Python code here and how to display at which line of code a segmentation fault happens here, but in these ways I'm able to see only where an error is, while instead I want to be able to know every C++ function invocation, even when there are no bugs in the code (At the moment debugging with gdb I'm able to see the system calls and the dynamic library calls, but not the C++ function invocations).

1

There are 1 answers

1
keveman On

The bulk of the code that most people write is for graph construction. Almost of all of graph construction happens completely in Python, which simply builds up the (Python) data structures such as Operation and Graph defined in ops.py. The one exception is shape inference, which happens when you create every operation. Shape inference calls out to C++ via the interface defined in cpp_shape_inference.i. After you built up the computational graph, you execute it by creating a Session and calling sess.run. These are all Python function wrapping TensorFlow's C API. The wrappers can be found in tf_session.i.