Rendezvous

1. 定义在core/framework/rendezvous.h

2. A Rendezvous is an abstraction for passing a Tensor from a producer to a consumer where the consumer may safely request the Tensor before or after it has been produced.  A producer never blocks

when using a Rendezvous. A consumer has the choice of making a blocking call or providing a callback: in either case,

the consumer receives the Tensor as soon as it is available.

(简而言之:Nonblocking send, blocking receive)

3. A Rendezvous key encodes a single <producer, consumer> pair.  It is an error to call Send() or Recv*() more than once with the same key.

4. 在消息通信机制中,消息传递涉及到信箱容量问题。一个极端的情况是信箱容量为0,那么,当send在receive之前执行的话,则发送进程被阻塞,直到receive做完。

执行receive时信件可从发送者直接拷贝到接收者,不用任何中间缓冲。类似的,如果receive先被执行,接受者将被阻塞直到send发生。上述策略称为回合(rendezvous)原则。

5. tensorflow 的消息传递属于【发送不阻塞,接收阻塞】,实现场景有以下两种:

> LocalRendezvous (本地消息传递)

> RpcRemoteRendezvous (分布式消息传递)

> 另外一种特殊的通信形式是IntraProcessRendezvous  (rendezvous_mgr.h),用于本地不同设备间通信。

Buffering of Tensor values is delegated to a "local" Rendezvous obtained from NewLocalRendezvous().

This class just adds functionality to coordinate multiple process-local devices.

6. 在Op Kernels中,有SendOp和RecvOp两个类(kernels/sendrecv_ops.h),与Rendezvous结合使用。

7. 【Each node:port specified in inputs is  replaced with a feed node, which will pick up the provided input tensor from specially-initialized entries in a Rendezvous object used for the Run call】(from tensorflow white paper)

minix消息传递中rendezvous概念
符号编程
MXNet设计笔记之:深度学习的编程模式比较
命令式(灵活)
符号式(高效)
前向计算图(显式)  +  反向计算图(隐式)

Session

## 说明:A Session instance lets a caller drive a TensorFlow graph computation
## relate files:  /public/session.h,  /comm_rt/[[session.cc  session_factory.cc  session_factory.h   session_options.cc  session_state.cc]]
## 客户程序通过会话(Session)与TensorFlow系统进行交互。在Session建立时运算流图初始状态为空图。为创建运算流图,TensorFlow通过Session接口的

       Extend函数,把额外的节点和边扩充到当前的运算流图中。

      Run()是Session接口中另一个重要的函数。Run()函数的参数包括最终运算输出的变量名,及运算流图中涉及到的张量运算集。

为得到所期望的输出结果,运行过程中TensorFlow对所有节点进行传递闭包运算。并遵照节点间的运算依赖关系进行排序(具体细节将在3.1节中介绍)。

在大部分的TensorFlow应用中,一般构建一次Session,然后通过调用Run()对整个运算流图或是部分独立的子图进行多次运算。

表(1)TensorFlow核心库中的部分运算

附:传递闭包:即在数学中,在集合 X 上的二元关系 R 的传递闭包是包含 R 的 X 上的最小的传递关系。

设备及内存分配
tensorflow设备内存分配算法解析
1. tensorflow设备内存管理模块实现了一个best-fit with coalescing (bfc)算法
> bfc选择合适内存块的原则是:找到chunk size大于等于x的最小的那个空闲内存块
2. 每个 worker 负责一个或者多个设备,每个设备有一个设备类型和一个名字。设备名字由识别设备类型的部分,在 worker 中的设备索引,以及在分布式设定中,worker 的 job和任务(或者 localhost 当设备是和进程在同一机器时)的标志构成。一些例子如/job:localhost/device:cpu:0 或者 /job:worker/task:17/device:gpu:3。 每个设备对象负责管理分配和解除分配设备内存,对在 TensorFlow 实现中的更高层请求任意 kernel 的执行调度管理。
3. tensorflow中,基类Device的子类有【GPUDevice,   CPUDevice(即ThreadPoolDevice),  GPUCompatibleCPUDevice】
Graph
Graph describes a set of computations that are to be performed, as well as the dependencies between those computations. The basic model is a    DAG (directed acyclic graph) with 
* internal nodes representing computational operations to be performed;
* edges represent dependencies, indicating the target may only be    executed once the source has completed; 
> 正常边,正常边上可以流动数据,即正常边就是tensor
> 特殊边,又称作控制依赖,(control dependencies) 
* predefined "source" (start) and "sink" (finish) nodes -- the source    should be the only node that doesn't depend on anything, and the sink   should be the only node that nothing depends on.

* graph优化:
  • Common Subexpression Elimination (CSE,公共子表达式消除)

    • 如果一个表达式E已经计算过了,并且从先前的计算到现在的E中的变量都没有发生变化,那么E的此次出现就成为了公共子表达式。
    • 例如:x=(a+c)*12+(c+a)*2;  可优化为 x=E*14
  • 参考:编译器常用优化方法     Introduction to Compilers

* Control flow graph (CFG)

  • A control flow graph (CFG) in computer science is a representation, using graph notation, of all paths that might be traversed through a program during its execution.
Gradients
MXNet设计笔记之:深度学习的编程模式比较: (Backprop和AutoDiff的案例分析)


from "神经网络与深度学习"

目录
core/
----BUILD                      bazel编译文件,相关编译函数定义在.bzl文件中
----client                       
----common_runtime         
----debug                        
----distributed_runtime     
----example                         
----framework                      
----graph      DAG图相关
----kernels    核心Op,如【matmul, conv2d, argmax, batch_norm】等
----lib          基础公共库【core  gif  gtl  hash  histogram  io  jpeg  monitoring  png  random  strings  wav】
> /lib/gtl: (google template library),包含array_slice,iterator_range,  inlined_vector,   map_util, std_util,等基础库
----ops         均为.cc文件,为基本op操作,如【array_ops, math_ops,   image_ops,  function_ops,  random_ops, io_ops】
流运算【control_flow_ops,  data_flow_ops】  
以及定义了op梯度计算方式:【array_grad,   math_grad,   functional_grad,  nn_grad,   random_grad】
----platform     平台相关文件,如设备内存分配
----protobuf     均为.proto文件,用于数据传输时的结构序列化
----public         公共头文件,用于外部接口调用的API定义,主要是[session.h,   tensor_c_api.h]
----user_ops    用户自定义op           
----util          


stream_executor/      参考:https://github.com/henline/streamexecutordoc 
----cuda/            cuda函数封装。(CUDA-specific support for BLAS functionality)
StreamExecutor is currently used as the runtime for the vast majority of Google's internal GPGPU applications,
and a snapshot of it is included in the open-source TensorFlow project, where it serves as the GPGPU runtime. (Google Stream Executor team)
Register
ops_kernel注册: REGISTER_KERNEL_BUILDER("MatMul", MatMulOp);     (kernels/matmul_ops.cc)
ops_grad   注册:   REGISTER_OP_GRADIENT("MatMul", MatMulGrad);        (ops/math_grad.cc)
ops    注册:   (ops/math_ops.cc)

转载于:https://www.cnblogs.com/yao62995/p/5773184.html

[图解tensorflow源码] TF系统概述篇相关推荐

  1. [图解tensorflow源码] [原创] Tensorflow 图解分析 (Session, Graph, Kernels, Devices)

    TF Prepare [图解tensorflow源码] 入门准备工作 [图解tensorflow源码] TF系统概述篇 Session篇 [图解tensorflow源码] Session::Run() ...

  2. [图解tensorflow源码] 入门准备工作附常用的矩阵计算工具[转]

    [图解tensorflow源码] 入门准备工作 附常用的矩阵计算工具[转] Link: https://www.cnblogs.com/yao62995/p/5773142.html tensorfl ...

  3. Tensorflow源码编译

    相比源码编译各版本之间遇到的坑来说,pip安装真心省事.不过由于项目需要采用C++实现的整个感知模块,只能把DL前向传播这块也写成C++形式.这是我去年的编译过程,当时有不少坑没能记录下来,以后有机会 ...

  4. 生成对抗网络入门详解及TensorFlow源码实现--深度学习笔记

    生成对抗网络入门详解及TensorFlow源码实现–深度学习笔记 一.生成对抗网络(GANs) 生成对抗网络是一种生成模型(Generative Model),其背后最基本的思想就是从训练库里获取很多 ...

  5. 干货|TensorFlow开发环境搭建(Ubuntu16.04+GPU+TensorFlow源码编译)

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|机器学习算法工程师 安装平台 1 平台 目前Tensor ...

  6. Tensorflow源码解析1 -- 内核架构和源码结构

    1 主流深度学习框架对比 当今的软件开发基本都是分层化和模块化的,应用层开发会基于框架层.比如开发Linux Driver会基于Linux kernel,开发Android app会基于Android ...

  7. cuda 编译 linux,Linux下安装Tensorflow源码及编译

    下载Tensorflow源码 git clone https://github.com/tensorflow/tensorflow 如果无法下载也可以在github上直接下载tensorflow的打包 ...

  8. VUE源码学习第一篇--前言

    一.目的 前端技术的发展,现在以vue,react,angular为代表的MVVM模式以成为主流,这三个框架大有三分天下之势.react和angular有facebook与谷歌背书,而vue是以一己之 ...

  9. Go源码解析——Channel篇

    channel.map.slice作为golang的核心三剑客,对于使用golang作为主语言完成开发工作的程序猿来说是非常重要的.了解其设计和源码是使用的基础,因此笔者本专题会对这三种数据结构的源码 ...

  10. Tensorflow源码学习经历(一)

    前言 准研一学生,暑假开始学习tensorflow.导师让我学习的不是如何使用TenosrFlow构建机器学习模型,而是把目光放到TensorFlow框架本身上,了解tf框架内部的工作原理.翻阅各类书 ...

最新文章

  1. P1603 斯诺登的密码
  2. Spring DAO之Hibernate
  3. Java --Lamda表达式
  4. Hibernate -- Dao层 -- CURD -- 随记
  5. kattis ones简单题取模运算+枚举
  6. php beast linux安装,windows centos php-beast 安装
  7. Python GUI界面编程初步 01 - GUI库的特点和选择
  8. 无心剑随感《爱心教育》
  9. 常用的linux文件权限
  10. 毕马威_【毕马威快讯】毕马威发布个人信息保护法(草案)概览
  11. SSH应用之BBS之路-1、项目构设之数据库设计
  12. [转] VR-FORCES 介绍
  13. 安装好jdk后在cmd窗口输入Java 出现Error: could not open `D:\java2\lib\amd64\jvm.cfg'
  14. springboot社区再生资源上门回收平台毕业设计-附源码072049
  15. 基于PowerBuilder的病案统计系统的设计与实现
  16. C++程序设计语言学习笔记:异常处理
  17. 统计数组中英文大写字母,小写字母,数字,空格的个数。
  18. matlab kmeans 质心,KMeans_SPD_Matrices
  19. Python len()方法
  20. 新能源汽车——动力电池

热门文章

  1. springboot开启缓存_springBoot与缓存使用
  2. 自动驾驶 11-4: 优化状态估计 Optimizing State Estimation
  3. ubuntu mysql 连接数_ubuntu-阿里云下 Tomcat 应用无法连接数Mysql据库
  4. Redis Zadd 命令 Redis 有序集合(sorted set)Redis Zadd 命令用于将一个或多个成员元素及其分数值加入到有序集当中。如果某个成员已经是有序集的成员,那么更新
  5. 2021-09-06LS是交替最小二乘(alternating least squares)的简称,用交替最小二乘求解的一个协同推荐算法。
  6. 375.猜数字大小II
  7. 350.两个数组的交集II
  8. 80. 删除排序数组中的重复项 II
  9. 学计算机信息管理专业的感谢,2014年计算机信息管理专业自荐信
  10. python把float可以转变成int_在Python中将float转换为整数的最安全方法?