今天在虚拟机里安装keras和tensorflow，但是tensorflow出现问题，无奈自己编译tensorflowTensorflow源码编译一、本文简要说明[scode type="blue"]本文首先对tensorflow进行了简要介绍，接着介绍以下目前编译的环境和准备工作，最后记录以下tensorflow编译的方法，最后测试。[/scode]二、Tensorflow简要介绍[collapse title="Tensorflow简要介绍，可略过" status="false"]TensorFlow™ 是一个采用数据流图（data flow graphs），用于数值计算的开源软件库。节点（Nodes）在图中表示数学操作，图中的线（edges）则表示在节点间相互联系的多维数据数组，即张量（tensor）。它灵活的架构让你可以在多种平台上展开计算，例如台式计算机中的一个或多个CPU（或GPU），服务器，移动设备等等。TensorFlow 最初由Google大脑小组（隶属于Google机器智能研究机构）的研究员和工程师们开发出来，用于机器学习和深度神经网络方面的研究，但这个系统的通用性使其也可广泛用于其他计算领域。[/collapse]三、Tensorflow编译环境3.1 虚拟机配置4核4G3.2 系统环境Centos7_X86-64四、编译前的准备[scode type="yellow"]我要安装python3的tensorfow，因此需要先安装python3[/scode]4.1 基本环境安装[root@Centos7 ~]#yum install epel-release -y #安装EPEL [root@Centos7 ~]#yum install python36 python36-pip -y #安装python3和pip3 [root@Centos7 ~]#yum install wget git gcc gcc-c++ python36-devel.x86_64 python-devel.x86_64 patch -y #安装基础环境 [root@Centos7 ~]#ln -s /usr/local/lib/python3.6/site-packages/pip /usr/bin/pip3 #做一下软链接 [root@Centos7 ~]#pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy #安装numpy4.2 准备bazel偷点懒，直接从github上下载编译好的bazel吧。[scode type="yellow"]注意：我安装的是1.13，bazel版本不能超过0.20，因此我选的是0.20版本的bazel[/scode][root@Centos7 ~]#wget https://github.com/bazelbuild/bazel/releases/download/0.20.0/bazel-0.20.0-linux-x86_64 #下载编译好的bazel [root@Centos7 ~]#chmod +x bazel-0.20.0-linux-x86_64 [root@Centos7 ~]#cp bazel-0.20.0-linux-x86_64 /usr/bin/bazel #把bazel放到/usr/bin里4.3 准备Tensorflow[root@Centos7 ~]#git clone https://github.com/tensorflow/tensorflow.git #从github上拉tensorflow源代码 [root@Centos7 ~]#git checkout v1.13.1 #切换1.13版本五、编译tensorflow5.1 配置tensorflow编译选项[root@Centos7 ~]#./configure #选择tensorflow编译选项[collapse title="Tensorflow配置选项" status="false"] ./configure You have bazel 0.20.0 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3.6 Found possible Python library paths: /usr/local/lib/python3.6/dist-packages /usr/lib/python3.6/dist-packages Please input the desired Python library path to use. Default is [/usr/lib/python3.6/dist-packages] Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: jemalloc as malloc support will be enabled for TensorFlow. Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: Google Cloud Platform support will be enabled for TensorFlow. Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: Hadoop File System support will be enabled for TensorFlow. Do you wish to build TensorFlow with Amazon AWS Platform support? [Y/n]: Amazon AWS Platform support will be enabled for TensorFlow. Do you wish to build TensorFlow with Apache Kafka Platform support? [Y/n]: Apache Kafka Platform support will be enabled for TensorFlow. Do you wish to build TensorFlow with XLA JIT support? [y/N]: No XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with GDR support? [y/N]: No GDR support will be enabled for TensorFlow. Do you wish to build TensorFlow with VERBS support? [y/N]: No VERBS support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: Y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 9.0]: 9.0 Please specify the location where CUDA 9.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.0 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Do you wish to build TensorFlow with TensorRT support? [y/N]: No TensorRT support will be enabled for TensorFlow. Please specify the NCCL version you want to use. If NCLL 2.2 is not installed, then you can use version 1.3 that can be fetched automatically but it may have worse performance with multiple GPUs. [Default is 2.2]: 1.3 Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 3.5,7.0] 6.1 Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. Configuration finished[/collapse]5.2 编译[scode type="yellow"]如果内存不足，请加如限制--local_resources 2048,.5,1.0，因为我是虚拟机4核4G，因此我就加上限制，防止出错[/scode][root@Centos7 ~]#cd tensorflow [root@Centos7 ~]#bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package --local_resources 2048,.5,1.0 #开始编译
本文主要内容是编译OpenVSwitch，当做自己的一个编译记录。OVS源码编译OpenVSwitch介绍[collapse title="OpenVSwitch介绍" status="true"]Open vSwitch是在开源的Apache2.0许可下的产品级质量的多层虚拟交换标准！它旨在通过编程扩展，使庞大的网络自动化（配置、管理、维护），同时还支持标准的管理接口和协议（如NetFlow， sFlow， SPAN， RSPAN， CLI， LACP， 802.1ag）。[/collapse]OVS编译[scode type="blue"]下载OVS源代码[/scode]wget http://openvswitch.org/releases/openvswitch-版本.tar.gz[scode type="blue"]具体的可以去OVS官网查看版本[/scode][scode type="blue"]解压并生成配置文件[/scode]tar -xvzf openvswitch-版本.tar.gz cd openvswitch-版本 ./configure --with-linux=/lib/modules/$(uname -r)/build[scode type="blue"]直接编译安装可以使用make -j $number[/scode]make # 或者make -j 16 make install make modules_install[scode type="blue"]加载模块[/scode]modprobe openvswitch #不要使用insmod openvswitch[scode type="blue"]因为openvswitch模块与linux的bridge模块冲突，所以如果发生冲突，不能加载ovs的内核模块时，先卸载掉bridge模块。[/scode]rmmod bridge modprobe openvswitch[scode type="blue"]使用lsmod查看已加载的所有模块，验证是否加载ovs的内核模块成功。 使用dmesg查看模块加载报错信息[/scode]lsmod | grep openvswitch[scode type="blue"]如果一直加载模块不成功，可以用命令modinfo openvswitch查看该模块的信息，内核版本以及依赖关系等。或者用dmesg | tail查看kernel的日志信息。[/scode]OVS编译成功