I have been spending a lot of time trying to understand the TensorFlow internals for a personal project by looking at source code and messing around in GDB. I know that Tensors are stored in the tensorflow::Tensor class which contains a shape, element count and a pointer to a tensorflow::TensorBuffer. TensorBuffer has a reference count for the actual data in the tensor and a pointer to the data. I have been able to find tensorflow::Tensors c++ data structures when messing around in GDB and am able to access their underlying buffers. However, I am struggling to find the data structures that manage the tensorflow::Tensors and how they are kept track of internally in a model.
For example, how do I associate a trainable variable in a model to its underlying in memory buffer?
When looking at how model.predict() works I know that the inputs to the execute function (TFE_Py_Execute) in quick_execute in tensorflow/python/eager/execute.py are passed in as tf.Tensor. When looking at the C++ code for TFE_Py_Execute in GDB the inputs are passed into that function as TFE_InputTensorHandles and an individual TFE_TensorHandle can be accessed with inputs->at(n) where n is any number below input size. Casting an individual TFE_TensorHandle to a tensorflow::TensorHandle in gdb lets me access the methods of the TensorHandle class for each TensorHandle.
However, there is no method that lets me pull out the data buffer for the TensorHandle and I seem to be missing some connection as when I go to access the data_ field of the TensorHandle which should contain a LocalTensorHandleData it is filled with info that I was not expecting. Where as a typical tensorflow::Tensor has a shape, element count, and pointer to a TensorBuffer which subsequently contains a pointer to a in memory buffer filled with tensor elements, the data_ for these TensorHandles is filled with a bunch of strings such as device string, localhost, a couple byte sections with 2c in them etc. I am not sure of what type this is and why this isnt just an in memory buffer.
So I would really like a clarification on what I am missing to more easily access the underlying tensorflow::Tensor data structure and its buffer as well as how I can maybe get from a model and its trainable variables to its underlying buffer.
Thanks!