macOS_mojave_10.14.6下Tensorflow2.6的安装与SSE, AVX, FMA

作者: 引线小白-本文永久链接:http://www.limoncc.com/工程实践/2021-09-18-mac安装tensorflow2.6/
知识共享许可协议: 本博客采用署名-非商业-禁止演绎4.0国际许可证

一、下载源码

本人电脑macOS mojave 10.14.6, 编译tensorflow解决SSE4.1 SSE4.2 AVX指令集问题。

先下载,进入目录定位到v2.6.0

1
2
3
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v2.6.0

二、准备必要环境

准备必要环境,请安装好java,和minconda

1
2
3
4
5
6
7
8
brew install bazelisk 
conda create -n pencil python=3.8
conda activate pencil
pip install -U pip
pip install -U six
pip install numpy==1.19.5
pip install -U wheel
pip install -U keras_preprocessing --no-deps

三、开始编译

关键语句,-march=native会做cpu指令集优化

bazelisk build -c opt –copt=-march=native //tensorflow/tools/pip_package:build_pip_package

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
./configure
You have bazel 3.7.2 installed.
Please specify the location of python. [Default is /Users/xiaobai/miniconda/envs/dawn/bin/python3]:


Found possible Python library paths:
/Users/xiaobai/miniconda/envs/dawn/lib/python3.8/site-packages
Please input the desired Python library path to use. Default is [/Users/xiaobai/miniconda/envs/dawn/lib/python3.8/site-packages]

Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm 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.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]:


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Do you wish to build TensorFlow with iOS support? [y/N]: n
No iOS support will be enabled for TensorFlow.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
--config=mkl # Build with MKL support.
--config=mkl_aarch64 # Build with oneDNN and Compute Library for the Arm Architecture (ACL).
--config=monolithic # Config for mostly static monolithic build.
--config=numa # Build with NUMA support.
--config=dynamic_kernels # (Experimental) Build kernels into separate shared objects.
--config=v1 # Build with TensorFlow 1 API instead of TF 2 API.
Preconfigured Bazel build configs to DISABLE default on features:
--config=nogcp # Disable GCP support.
--config=nonccl # Disable NVIDIA NCCL support.
Configuration finished
bazelisk build -c opt --copt=-march=native //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

在/tmp/tensorflow_pkg找到wheel文件,pip安装即可。目前编译了这些,看官按需下载

下载链接
tensorflow-2.6.0-cp38-cp38-numpy_1.21.2-macosx_10_14_x86_64.whl
tensorflow-2.6.0-cp37-cp37m-macosx_10_14_x86_64.whl
tensorflow-2.6.0-cp38-cp38-macosx_10_14_x86_64.whl


版权声明
引线小白创作并维护的柠檬CC博客采用署名-非商业-禁止演绎4.0国际许可证。
本文首发于柠檬CC [ http://www.limoncc.com ] , 版权所有、侵权必究。
本文永久链接http://www.limoncc.com/工程实践/2021-09-18-mac安装tensorflow2.6/

'