首页 文章

使用SSE4.1,SSE4.2和AVX指令构建tensorflow v1.X

提问于
浏览
0

我正在使用张量流(没有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 <1.0)有关 . 我想知道是否有人能指出我使用更新版本的tf构建正确的bazel命令?

按照此处的说明在Mac OSX上安装python3:https://www.tensorflow.org/install/install_sources并选择"No"以获得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]

Edit

我会注意到,我只看到从源头开始 Build 的速度略有增加 .

1 回答

  • 1

    正如评论中所述,这些警告不会阻止构建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

相关问题