零、資料集合
- 知乎專欄:Bob學步
- 知乎提問:如何高效的學習 TensorFlow 代碼?.
- 大佬劉光聰(Github,簡書)
- 開源書:TensorFlow Internals,強烈推薦(本博客參考書)
- TensorFlow架構與設計:編程模型
- TensorFlow架構與設計:概述
- TensorFlow架構與設計:會話生命周期
- TensorFlow架構與設計:圖模塊
- TensorFlow架構與設計:OP本質論
- TensorFlow架構與設計:變量初始化
- 大佬姚健(Github)
- 系列文章(圖片?):圖解tensorflow源碼
- 『深度長文』Tensorflow代碼解析(一)
- 『深度長文』Tensorflow代碼解析(二)
- 『深度長文』Tensorflow代碼解析(三):Op/Kernel相關
- 『深度長文』Tensorflow代碼解析(四):Graph相關
- 『深度長文』Tensorflow代碼解析(五):Session相關
- TensorFlow Kernels Registration 源碼解析:TensorFlow的介紹寫在paddle的wiki里。
- 網上某大佬博客(強烈推薦)
- TensorFlow 拆包(一):Session.Run()
- TensorFlow 拆包(二):TF 的數據流模型實現以及自動求導
- TensorFlow 拆包(三):Graph 和 Node
- TensorFlow 拆包(四):Device
- TensorFlow 拆包(五):Distributed
- TensorFlow 拆包(六):RDMA
- TensorFlow 拆包(七):Profiling 踩坑 & Benchmark
- TensorFlow 拆包(八):Dynamic Control Flow in Large-Scale Machine Learning
- 知乎某大佬專欄
- 其他
另附:
一、代碼獲取
克隆源碼:
git clone https://github.com/tensorflow/tensorflow.git
切換到r1.4穩定分支:
cd tensorflow
git check r1.4
二、源碼結構
tree -d -L 1 ./tensorflow

| 目錄 | 說明 |
|---|---|
| /c | C++ API,也是一些 Python API 與 C 層的接口部分 |
| /cc | |
| /compiler | 即時編譯的工具內容 |
| /contrib | 一些額外的庫,大部分由第三方添加,其中一些正式確定的內容會移出去 |
| /core | TensorFlow 的核心運行時代碼 |
| /core/distributed_runtime | 分布式運行時代碼 |
| /core/framework | 運行時中相對最底層的架構部分,涉及到很多基礎結構的定義、與 Protobuf 的結合部分等等 |
| /core/graph | 運行時中對計算圖的定義和處理 |
| /core/kernels | 計算圖中 Op 的核心計算部分(即 Op 的 Kernel 函數) |
| /core/lib | 運行時中調用的其他庫的接口? |
| /core/ops | C 部分的 Op 分成兩個部分,核心計算函數在前面的 /kernels 目錄中,這里存的是 Op 面向上層 Python 運行時的注冊部分內容。 詳見 TensorFlow 拆包(三):Graph 和 Node |
| /core/platform | 針對不同平台的額外內容 |
| /core/profiler | 運行時的調優工具? |
| /core/protobuf | Protobuf 的定義 |
| /core/util | 其他的一些工具 |
| /python | TensorFlow Python 部分的運行時和 API |
重點文件夾如下:
core
內核的源碼,C++實現。
python
接口API,python實現。
contrib
第三方庫,實驗性,當 contrib 標准化,並從 中,並正式對外發布。
stream_executor
提速組件,並行化、分布式相關。
compiler
優化計算圖,主要優化OP的分解組合方式,找到盡可能好的圖構建方式,能夠分析運行時的計算圖,將多個 OP 融
合在一起,並生成更高效的本地機器代碼,提升計算圖的執行效率。
三、邏輯構架圖

