使用 SSE4.2 编译 TensorFlow,AVX 因 bazel 失败

Posted

技术标签:

【中文标题】使用 SSE4.2 编译 TensorFlow,AVX 因 bazel 失败【英文标题】:Compile TensorFlow with SSE4.2 and AVX fails with bazel 【发布时间】:2018-08-05 19:37:58 【问题描述】:

我已经安装了 Tensorflow Bazel 和 MSYS,我尝试使用 Win 中的以下命令编译 Tensorflow 以支持 CPU 扩展,例如 SSE4.1、SSE4.2、AVX、AVX2、FMA 10 命令提示符:

  bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=- 
  mfpmath=both --copt=-msse4.2 --config=cuda -k 
 //tensorflow/tools/pip_package:build_pip_package

但它失败并出现以下错误:

C:\WINDOWS\system32>bazel build -c opt --copt=-mavx --copt=-mavx2 
--copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda - 
 k //tensorflow/tools/pip_package:build_pip_package
 Bazel on Windows requires bash.exe and other Unix tools, but we 
could not find them.
If you do not have them installed, the easiest is to install 
 MSYS2 from
 http://repo.msys2.org/distrib/msys2-x86_64-latest.exe
 or git-on-Windows from
 https://git-scm.com/download/win

If you already have bash.exe installed but Bazel cannot find 
it,
set BAZEL_SH environment variable to its location:
set BAZEL_SH=c:\path\to\bash.exe
[bazel INFO src/main/cpp/blaze_util_windows.cc:1231] Cannot 
 open 
 HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1
 [bazel ERROR src/main/cpp/blaze_util_windows.cc:1303] bash.exe 
 not found on PATH
 [bazel INFO src/main/cpp/blaze_util_windows.cc:1328] BAZEL_SH 
 detection took 0 msec, found

MSYS 运行正常,如下图:

ippok@DESKTOP-4QMUDH4 MSYS ~
$

【问题讨论】:

难道你不应该运行命令bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=- mfpmath=both --copt=-msse4.2 --config=cuda -k //tensorflow/tools/pip_package:build_pip_package in MSYS 吗? Bazel 在 cmd.exe 上运行良好,无需从 MSYS 运行。 【参考方案1】:

错误信息告诉你该怎么做:将BAZEL_SH envvar 设置为 bash.exe 的路径。

要为当前的 cmd.exe 会话设置它,请使用:

set BAZEL_SH=c:\msys64\usr\bin\bash.exe

为所有未来 cmd.exe 会话(不是这个)设置它:

setx BAZEL_SH "c:\msys64\usr\bin\bash.exe"

如果您将 MSYS 安装在不同的位置,则相应地更改这些命令。

【讨论】:

以上是关于使用 SSE4.2 编译 TensorFlow,AVX 因 bazel 失败的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 SSE4.2 和 AVX 指令编译 Tensorflow?

如何使用 SSE4.2 和 AVX 指令编译 Tensorflow?

在win10里 为啥 Bazel 编译 tensorflow.dll 提示 /arch:SSE4.2 无效命令?要编译SSE4.2的参数怎么配置

not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA

如何生成sse4.2 popcnt机器指令

安装tensorflow遇到:Your CPU supports instructions that this TensorFlow binary was not compiled to use(示例