使用virtualenv安裝了tensorflow烈菌,但運(yùn)行的時(shí)候發(fā)現(xiàn)CPU可以支持AVX2和FMV霉囚,但需要從源碼重新構(gòu)建。好吧,那就開(kāi)始吧~
參考:
1. 環(huán)境
系統(tǒng):macOS High Sierra 10.13.4
python:2.7.15(系統(tǒng)自帶)
2. 準(zhǔn)備
2.1 避免沖突
我在前面已經(jīng)用virtualenv創(chuàng)建了tensorflow的環(huán)境项乒,此前創(chuàng)建的目錄名稱(chēng)“tensorflow”,怕產(chǎn)生沖突梁沧,將虛擬環(huán)境的目錄名稱(chēng)修改為“vir-tensorflow”
2.2 克隆代碼庫(kù)
打開(kāi)終端檀何,輸入以下命令:
$ git clone https://github.com/tensorflow/tensorflow
此時(shí),會(huì)在用戶目錄下創(chuàng)建一個(gè)“tensorflow”的目錄(幸虧剛剛該虛擬環(huán)境目錄的命名了~~)
下載的時(shí)間比較長(zhǎng)廷支,請(qǐng)耐心等待~~快受不了公司的網(wǎng)速了F导!A蹬摹6饪住!
2.3 針對(duì)macOS準(zhǔn)備環(huán)境
2.3.1 安裝bazel
使用brew安裝:
brew install bazel? ? ? ? #安裝
bazel version? ? ? ? ? ? ? #查看是否安裝成功
brew upgrade bazel? ?#升級(jí)版本
2.3.2 安裝python依賴(lài)項(xiàng)
必須安裝軟件包:
six
numpy:數(shù)值處理
wheel:管理wheel格式的python壓縮包
使用pip來(lái)安裝:
$ sudo pip install six numpy wheel
當(dāng)前版本:
six——1.11.0施敢,numpy——1.14.3周荐,wheel——0.31.0
2.4 安裝配置
2.4.1 軟件包配置
克隆源碼庫(kù)到本地后,在根目錄中包含有一個(gè)名為“configure”的bash腳本僵娃。必須先運(yùn)行該腳本概作,然后才能創(chuàng)建pip軟件包并安裝TensorFlow。
$ cd /xxxx/tensorflow
$ ./configure
進(jìn)入tensorflow源碼樹(shù)的根目錄默怨,執(zhí)行configure的bash腳本讯榕。
此時(shí)configure腳本會(huì)向您提出若干問(wèn)題。我選擇默認(rèn)值先壕,針對(duì)本機(jī)CPU類(lèi)型優(yōu)化所生成的代碼瘩扼,但是這樣構(gòu)建出來(lái)的TensorFlow是無(wú)法在其他類(lèi)型的CPU上運(yùn)行的谆甜。
以下是我運(yùn)行configure腳本時(shí)的問(wèn)題選擇:
Extracting Bazel installation...
You have bazel 0.13.0-homebrew installed.
Please specify the location of python. [Default is /usr/local/opt/python@2/bin/python2.7]: /usr/bin/python2.7
Found possible Python library paths:
? /Library/Python/2.7/site-packages
Please input the desired Python library path to use.? Default is [/Library/Python/2.7/site-packages]
/Library/Python/2.7/site-packages
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: N
No Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: N
No Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: N
No Amazon S3 File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Apache Kafka Platform support? [Y/n]: N
No Apache Kafka Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: N
No XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: N
No GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: N
No VERBS support will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: N
No CUDA support will be enabled for TensorFlow.
Do you wish to download a fresh release of clang? (Experimental) [y/N]: N
Clang will not be downloaded.
Do you wish to build TensorFlow with MPI support? [y/N]: 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]: -march=native
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: 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
2.4.2 軟件包構(gòu)建
配置后垃僚,進(jìn)行構(gòu)建:
$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
報(bào)錯(cuò)了<隆!W还住T匝唷!
Starting local Bazel server and connecting to it...
................
WARNING: /private/var/tmp/_bazel_yujianwen/7cea4d7c61741771d65fc25d431ce59d/external/protobuf_archive/WORKSPACE:1: Workspace name in /private/var/tmp/_bazel_yujianwen/7cea4d7c61741771d65fc25d431ce59d/external/protobuf_archive/WORKSPACE (@com_google_protobuf) does not match the name given in the repository's definition (@protobuf_archive); this will cause a build error in future versions
ERROR: /private/var/tmp/_bazel_yujianwen/7cea4d7c61741771d65fc25d431ce59d/external/local_config_cc/BUILD:50:5: in apple_cc_toolchain rule @local_config_cc//:cc-compiler-armeabi-v7a: Xcode version must be specified to use an Apple CROSSTOOL. If your Xcode version has changed recently, try: "bazel clean --expunge" to re-run Xcode configuration
ERROR: While resolving toolchains for target //tensorflow/tools/pip_package:simple_console: Analysis of target '@local_config_cc//:cc-compiler-armeabi-v7a' failed; build aborted
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Analysis of target '@local_config_cc//:cc-compiler-armeabi-v7a' failed; build aborted
INFO: Elapsed time: 17.909s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (64 packages loaded)
? ? currently loading: tensorflow/python ... (3 packages)
Error: Xcode version must be specified to use an Apple CROSSTOOL
處理:
應(yīng)該是Xcode使用版本與系統(tǒng)版本不一致改淑,需要修改Xcode版本
本機(jī)Xocde版本:9.3.1
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
$ bazel clean --expunge
執(zhí)行以上指令后碍岔,重新構(gòu)建,沒(méi)有Error朵夏,可以往下執(zhí)行~~~
過(guò)了一個(gè)中午蔼啦,還是構(gòu)建過(guò)程還是出現(xiàn)error,一共20個(gè)仰猖。停止了~~~