首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Caffe2上启用多线程

在Caffe2上启用多线程
EN

Stack Overflow用户
提问于 2021-02-22 11:55:04
回答 1查看 361关注 0票数 2

在使用Caffe2编译我的程序时,我会收到以下警告:

代码语言:javascript
复制
[E init_intrinsics_check.cc:43] CPU feature avx is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature avx2 is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature fma is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.

由于我确实希望获得对Caffe2的多线程支持,所以我搜索了该做什么。我发现Caffe2必须重新编译,在创建cmakeCMakeLists时设置一些参数。

由于我已经在pytorch env中安装了conda,所以我首先卸载了Caffe2:

代码语言:javascript
复制
pip uninstall -y caffe2

然后,我按照Caffe2文档的说明,从源代码构建它。我第一次按指示安装了依赖项。然后,我在我的pytorch env中下载了conda

代码语言:javascript
复制
git clone https://github.com/pytorch/pytorch.git && cd pytorch
git submodule update --init --recursive

此时,我认为是更改刚刚下载的pytorch\caffe2\CMakeLists文件的时候了。我已经读过,为了启用多线程支持,在这个CMakeLists中启用选项CMakeLists就足够了,但是我找不到这样的选项。也许我做错了什么。有什么想法吗?谢谢。

这里有一些关于我的平台的细节:

  • 我在macOS大苏尔
  • 我的python版本是3.8.5

更新:

要回答Nega这就是我得到的:

代码语言:javascript
复制
python3 -c 'import torch; print(torch.__config__.parallel_info())'
ATen/Parallel:
    at::get_num_threads() : 1
    at::get_num_interop_threads() : 4
OpenMP not found
Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications
    mkl_get_max_threads() : 4
Intel(R) MKL-DNN v0.21.1 (Git Hash 7d2fd500bc78936d1d648ca713b901012f470dbc)
std::thread::hardware_concurrency() : 8
Environment variables:
    OMP_NUM_THREADS : [not set]
    MKL_NUM_THREADS : [not set]
ATen parallel backend: OpenMP

更新2:

事实证明,XCode附带的Clang不支持OpenMP。我使用的gcc只是一个指向Clang的符号链接。实际上,在运行gcc --version之后,我得到了:

代码语言:javascript
复制
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

我从Homebrew gcc-10安装并设置了类似于这个alias gcc='gcc-10'的别名。实际上,现在使用gcc --version,这就是我得到的:

代码语言:javascript
复制
gcc-10 (Homebrew GCC 10.2.0_4) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我还尝试过使用8个线程为OpenMP创建一个简单的Hello,看起来一切都正常。但是,在重新运行命令之后:

代码语言:javascript
复制
python3 -c 'import torch; print(torch.__config__.parallel_info())'

我也得到了同样的结果。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-25 08:48:21

AVX、AVX2和FMA是CPU指令集,与多线程无关.如果pytorch/咖啡因2的pip包在不支持这些指令的CPU上使用这些指令,那么该软件就无法工作。Pytorch,通过pip安装,但带有多线程功能。您可以通过torch.__config__.parallel_info()确认这一点。

代码语言:javascript
复制
❯ python3 -c 'import torch; print(torch.__config__.parallel_info())'
ATen/Parallel:
    at::get_num_threads() : 6
    at::get_num_interop_threads() : 6
OpenMP 201107 (a.k.a. OpenMP 3.1)
    omp_get_max_threads() : 6
Intel(R) Math Kernel Library Version 2020.0.1 Product Build 20200208 for Intel(R) 64 architecture applications
    mkl_get_max_threads() : 6
Intel(R) MKL-DNN v1.6.0 (Git Hash 5ef631a030a6f73131c77892041042805a06064f)
std::thread::hardware_concurrency() : 12
Environment variables:
    OMP_NUM_THREADS : [not set]
    MKL_NUM_THREADS : [not set]
ATen parallel backend: OpenMP

话虽如此,如果您仍然希望继续从源构建py手电筒和caffe2,您所要寻找的标志,USE_NATIVE在pytorch/CMakeLists.txt中,比caffe2高一级。编辑该文件并将USE_NATIVE更改为ON。然后继续使用python3 setup.py build构建火炬。注意,标志USE_NATIVE没有执行您认为它所做的事情。它只允许构建带有CPU本地优化标志的MKL。它不会流到caffe2 (除非caffe2显然使用MKL)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66315250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档