【轉(zhuǎn)載請注明出處】:http://www.reibang.com/p/e21e660960a4
1咖熟、環(huán)境準備
- JDK安裝
- python版本確認逊拍,我的版本是3.6广恢,具體升級過程可以參考http://www.reibang.com/p/09a37fce4ba6
- 安裝Bazel
我的電腦安裝了homebrew觉吭,直接執(zhí)行
brew install bazel
安裝完之后驗證
bazel version
其他的安裝方式可以參考官網(wǎng)蛋欣。
- 安裝Numpy
pip install numpy scipy matplotlib ipython jupyter pandas sympy nose
其他方式可以參考官網(wǎng)芬首。
2熄诡、下載源碼
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
--recurse-submodules
參數(shù)是必須的临燃,用于獲取 tensorflow 依賴的 protobuf 庫浴捆。下載完之后
image.png
3蒜田、編譯源碼
進入源碼目錄,執(zhí)行
./configure
然后選擇要支持的模塊
Please specify the location of python. [Default is /usr/bin/python]: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
##選擇python路徑
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]:
##支持GCP选泻,普通用戶沒必要
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]:
##是否支持HDFS冲粤,這個比較有用
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]:
##是否支持亞馬遜的S3文件系統(tǒng),普通用戶沒必要
Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]:
##是否支持kafka
Do you wish to build TensorFlow with XLA JIT support? [y/N]:
##是否支持XLA(Accelerated Linear Algebra/加速線性代數(shù))JIT(just-in-time/即時編譯 )页眯,加速線性代數(shù)(融合可組合運算來提升性能, 通過極端專門化減小可執(zhí)行文件大小)梯捕,運行時的優(yōu)化
Do you wish to build TensorFlow with GDR support? [y/N]:
##是否支持GDR,如果你不支持CUDA窝撵,就不要選這個了傀顾。這個是要硬件支持的。如果支持碌奉,可以使用grpc+gdr交換參數(shù)
Do you wish to build TensorFlow with VERBS support? [y/N]:
##和GDR類似短曾,使用verbs庫來交換參數(shù)寒砖,也就是remote direct memory access(RDMA)。如果你使用了InfiniBand的卡错英,可以啟用入撒。
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]:
##OpenCL不建議啟用, 這是一個開發(fā)的計算框架,但異構(gòu)計算的事實標準是CUDA椭岩,如果你啟用了OpenCL茅逮,還要安裝下面的ConputeCPP for SYCL 1.2
Please specify which C++ compiler should be used as the host C++ compiler. [Default is /usr/bin/g++]:
Please specify which C compiler should be used as the hostC compiler. [Default is /usr/bin/gcc]:
Do you wish to build TensorFlow with ComputeCPP support? [Y/n]:
##使用SYCL將c++應用程序引入到廣泛的OpenCL加速器中
Do you wish to build TensorFlow with CUDA support? [y/N]:
##是否支持CUDA,需要硬件支持
Do you wish to build TensorFlow with MPI support? [y/N]:
##是否支持MPI判哥,和GDR, VERBS的作用是一樣的
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:
image.png
到這里献雅,就可以編譯安裝包了。
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
image.png
編譯完之后打包到目錄/tmp/tensorflow_pkg
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip包打包成功就可以安裝了
pip install /tmp/tensorflow_pkg/tensorflow-1.5.0rc1-cp36-cp36m-macosx_10_6_intel.whl
4塌计、驗證
打開一個 python 終端:
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>
【轉(zhuǎn)載請注明出處】:http://www.reibang.com/p/e21e660960a4