【问题标题】:Building tensorflow v1.X with SSE4.1, SSE4.2, and AVX instructions使用 SSE4.1、SSE4.2 和 AVX 指令构建 tensorflow v1.X
【发布时间】:2017-04-11 15:27:54
【问题描述】:

我正在使用 tensorflow(不支持 GPU),与预期相比,我发现性能受到了相当大的影响。所以,我认为是时候注意这些警告了:

W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

我看到有些人声称,按照这些说明进行构建,他们的速度提高了近 10 倍。

不过,我发现的有关执行此操作的说明似乎与旧版本的 TF (v

按照此处的说明在 Mac OSX 上安装 python3:https://www.tensorflow.org/install/install_sources 并选择“否”以获得 CUDA 支持。

并使用 bazel 命令:

bazel build --linkopt='-lrt' -c opt --copt=-march=native --copt=-mavx --copt=-msse4.2 --copt=-msse4.1 //tensorflow/tools/pip_package:build_pip_package

但是,这会导致许多页面的警告/错误...主要是以下形式:

target '//tensorflow/contrib/learn:learn' depends on deprecated target '//tensorflow/contrib/session_bundle:exporter': Use SavedModel Builder instead.

external/protobuf/python/google/protobuf/pyext/message_factory.cc:78:28: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]

编辑

我会注意到,我只看到了从源头构建速度的微小提高。

【问题讨论】:

  • 关于说明,官方文档正在关注最新的更新。该命令是文档bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package 中指定的命令。如果您在配置时将 SIMD 指令定义为默认值,例如-march=native 你不需要将其他人指定为msse4.2mavx 等,因为它应该在你的 CPU 架构中使用可用的优化进行编译。如果您确实设置了特定说明,但您需要在构建时定义相应的标志。
  • 嗨 @AdrianoCarmezim,运行基本的 bazel 命令 bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package 会为我抛出同样的错误
  • 你提到的是警告,不会阻止你构建 TF,是否有错误日志被发出?
  • 安装后我无法导入 tensorflow,但我现在看到这是一个单独的问题。你是对的,只使用 -march=native 从源代码构建正确优化了安装。
  • 很高兴它现在正在工作。对于导入问题,如果您仍然面临它,请随时在 Github 上打开一个问题,或者让我知道我是否可以提供更多帮助:) 如果其他人碰巧遇到同样的情况,我会留下答案。

标签: tensorflow bazel protobuf-c


【解决方案1】:

如 cmets 中所述,这些警告不会阻止构建 TensorFlow。

关于使用 bazel 构建 TensorFlow 的命令,如果在配置期间设置了 -march=native,则无需显式添加其他优化标志,因为 TensorFlow 已经使用 CPU 架构中可用的所有 SIMD 指令进行编译。

成功配置为您的架构 (-march=native) 的默认优化后,构建 TF 的命令是:

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

如果您碰巧选择了特定标志,则需要添加它们,例如:

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma //tensorflow/tools/pip_package:build_pip_package

参考:TensorFlow Docs

【讨论】:

    猜你喜欢
    • 2017-05-08
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多