[图解tensorflow源码] 入门准备工作


附常用的矩阵计算工具[转]

Link: https://www.cnblogs.com/yao62995/p/5773142.html

 tensorflow使用了自动化构建工具bazel、脚本语言调用c或cpp的包裹工具swig使用EIGEN作为矩阵处理工具、Nvidia-cuBLAS GPU加速计算库、结构化数据存储格式protobuf

Swig

     

1. Simplified Wrapper and Interface Generator (SWIG) ,基本思想就是向脚本语言接口公开 C/C++ 代码。SWIG 允许您向广泛的脚本语言公开 C/C++ 代码,包括 Ruby、Perl、Tcl 和 Python。

 
 

参考:

1. 使用SWIG实现Python调用C/C++代码

  

Bazel

1. bazel假定每个目录为[package]单元,目录里面包含了源文件和一个描述文件BUILD,描述文件中指定了如何将源文件转换成构建的输出。

 
 

1. name属性来命名规则,deps属性来描述规则之间的依赖关系
2. 使用冒号来分隔包名和规则名;如果某条规则所依赖的规则在其他目录下,就用"//"开头,如果在同一目录下,可以忽略包名而用冒号开头。
依赖关系:

  

3. bazel命令:

     > bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

4. 调试模式:

     >  bazel build -c dbg

参考:

1. 安装bazel

   > yum install java-1.8.0-openjdk

   > yum install java-1.8.0-openjdk-devel

   > https://github.com/google/bazel/ 下载最新版本bazel_xxx.sh安装

2. 使用bazel构建系统

 
 

3. bazel 命令手册

  

 
 

  

EIGEN

1. Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms. http://eigen.tuxfamily.org/  

  • 支持整数、浮点数、复数,使用模板编程,可以为特殊的数据结构提供矩阵操作。比如在用ceres-solver进行做优化问题(比如bundle adjustment)的时候,有时候需要用模板编程写一个目标函数,ceres可以将模板自动替换为内部的一个可以自动求微分的特殊的double类型。而如果要在这个模板函数中进行矩阵计算,使用Eigen就会非常方便。
  • 支持逐元素、分块、和整体的矩阵操作。
  • 内含大量矩阵分解算法包括LU,LDLt,QR、SVD等等。
  • 支持使用Intel MKL加速
  • 部分功能支持多线程
  • 稀疏矩阵支持良好,到今年新出的Eigen3.2,已经自带了SparseLU、SparseQR、共轭梯度(ConjugateGradient solver)、bi conjugate gradient stabilized solver等解稀疏矩阵的功能。同时提供SPQRUmfPack等外部稀疏矩阵库的接口。
  • 支持常用几何运算,包括旋转矩阵、四元数、矩阵变换、AngleAxis(欧拉角与Rodrigues变换)等等。
  • 更新活跃,用户众多(Google、WilliowGarage也在用),使用Eigen的比较著名的开源项目有ROS(机器人操作系统)、PCL(点云处理库)、Google Ceres(优化算法)。OpenCV自带到Eigen的接口。

2. 常用的矩阵计算工具有blas, cublas(caffe)、atlas、openblas(mxnet)、eigen,还有lapack、mkl(intel)、Armadillo(matlab)

 
 

3. Eigen库包含 Eigen模块和unsupported模块,其中Eigen模块为official module,unsupported模块为开源贡献者开发的,没有official support。

1. 矩阵运算库blas, cblas, openblas, atlas, lapack, mkl
2. eigen 参考文档

https://eigen.tuxfamily.org/dox/

 
 

C++矩阵运算库推荐

 

protobuf

 
 

1. Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化。它很适合做数据存储或 RPC 数据交换格式。可用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的序列化结构数据格式。

2. 使用
      > 编写.proto文件,编译后生成 .pb.h / .pb.cc文件

      > Writer: SerializeToOstream(),   Reader: ParseFromIstream()

      > required:一个格式良好的消息一定要含有1个这种字段;

      > optional:消息格式中该字段可以有0个或1个值(不超过1个)。

      > repeated:在一个格式良好的消息中,这种字段可以重复任意多次(包括0次)。相当于java中的List。

3. 

 
 

4. grpc需要理解4个方面(service,stub,channel,observer)

  • service,
  • stub:客户端调用 stub 对象,所谓 stub 对象就是具有声明好的方法的 fake object。stub 对象将请求用 protobuf 方式序列化成字节流,用于线上传输,到 server 端后调用真正的实现对象处理。
  • channel,指定连接的服务器地址和端口,用于stub连接到service
  • observer,服务端,观察处理返回和关闭通道

 Protobuf 语法指南

gRPC 入门及源码分析

  

Stream

Executor 

> google stream executor team: work on parallel programming models for CPUs, GPUs and other platforms.
StreamExecutor is a unified wrapper around the CUDA and OpenCL host-side programming models (runtimes). 
>StreamExecutor and libomptarget are libraries that are both meant to solve the problem of providing runtime support for offloading computational work to an accelerator device. The libomptarget library is already hosted within the OpenMP LLVM subproject, and there is currently a proposal to create another LLVM subproject containing StreamExecutor. 
> 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.

https://github.com/henline/streamexecutordoc

https://github.com/henline/streamexecutordoc/blob/master/se_and_openmp.rst

 
 

  

TF C++

1. TF源码安装: following the instructions here

2. example:  tensorflow/cc/tutorials/example_trainer.cc

3. 自定义的op Kernel tutorial for adding a new op in C++.

4. TF c++ 调试: debugging Tensorflow's C++ code behind the SWIG interface

         > The simplest interface between Python and C++ is the pure-C API in tensor_c_api.h

  

 

 

[图解tensorflow源码] 入门准备工作附常用的矩阵计算工具[转]的更多相关文章

  1. [图解tensorflow源码] 入门准备工作

     tensorflow使用了自动化构建工具bazel.脚本语言调用c或cpp的包裹工具swig.使用EIGEN作为矩阵处理工具.Nvidia-cuBLAS GPU加速计算库.结构化数据存储格式prot ...

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

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

  3. [图解tensorflow源码] TF系统概述篇

    Rendezvous 1. 定义在core/framework/rendezvous.h 2. A Rendezvous is an abstraction for passing a Tensor  ...

  4. 图解tensorflow 源码分析

    http://www.cnblogs.com/yao62995/p/5773578.html https://github.com/yao62995/tensorflow

  5. [图解tensorflow源码] [转载] tensorflow设备内存分配算法解析 (BFC算法)

    转载自 http://weibo.com/p/1001603980563068394770   @ICT_吴林阳 tensorflow设备内存管理模块实现了一个best-fit with coales ...

  6. [图解tensorflow源码] Graph 图优化 (graph optimizer)

  7. [图解tensorflow源码] Graph 图构建 (Graph Constructor)

  8. [图解tensorflow源码] Graph 图模块 —— Graph Loading

  9. [图解tensorflow源码] Graph 图模块 (UML视图)

随机推荐

  1. 通过mapreduce把mysql的数据读取到hdfs

    前面讲过了怎么通过mapreduce把mysql的一张表的数据放到另外一张表中,这次讲的是把mysql的数据读取到hdfs里面去 具体怎么搭建环境我这里就不多说了.参考 通过mapreduce把mys ...

  2. 用Python进行人脸识别

    本文的模型使用了C++工具箱 dlib 基于深度学习的最新人脸识别方法,基于户外脸部数据测试库Labeled Faces in the Wild 的基准水平来说,达到了99.38%的准确率. dlib ...

  3. day19常用模块2

    常用模块21 shelve模块  也是一种序列化方式    使用方法        1.open     sl = shelve.open("shelvetest.txt")   ...

  4. 在mvc中动态加载菜单

    最近做了一个项目, 要在客户端动态的显示菜单,也就是这些菜单是保存在数据库中的, 在客户端动态加载菜单,这样做的好处很明显,就是菜单很容易修改,直接在后台进行维护,再也不会直接在前面的 视图页面中进行 ...

  5. 最小化安装CentOS 7后,图形界面的安装(GNOME、KDE等)

    安装图形化界面: 1.首先安装X(X Window System),命令为 yum groupinstall "X Window System" 2.检查一下我们已经安装的软件以及 ...

  6. apt-get 常用命令总结

    apt-get  高级包装工具(英语:Advanced Packaging Tools,简称:APT)是Debian及其衍生发行版(如:ubuntu)的软件包管理器.APT可以自动下载,配置,安装二进 ...

  7. ROS-by-example的安装

    在这里我之前用的VM12安装成功之后,仿真器机器人会有问题,故把电脑做成双系统的形式来重新安装: 环境:Ubuntu14.04 LTS 32bits ROS版本:ROS Indigo 在学习本部分之后 ...

  8. iPhone may be running a version of iOS that is not supported by this version of Xcode

    Xcode6.0.1对ios8.1真机不识别,升级Xcode6.0.1为Xcode6.1,就行了.也可以,降低手机版本为以前的版本,想要降低手机版本请看我的另一片博客<iphone手机版本降级& ...

  9. MySQL把文件导入表中

    1. Mysql 把本地文件导入表中 drop table if exists wufangzhai_caigou_group; create table wufangzhai_caigou_grou ...

  10. python语言程序设计-北京理工大学-嵩天等课件代码整理

    #TempConvert.py TempStr = input("请输入带有符号的温度值: ") if TempStr[-1] in ['F', 'f']: C = (eval(T ...