【Tensorflow 2.x】检验MKL

时间:2022-07-22
本文章向大家介绍【Tensorflow 2.x】检验MKL,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Tensorflow 2.x 关于 MKL 验证的方法移到了其他 Module 下,所以原来检验的方法换掉了。按照 Intel 官网的提示 Tensorflow 1.x 的检验语法是 python -c"import tensorflow; print(tensorflow.pywrap_tensorflow.IsMklEnabled())",这在 Tensorflow 2.x 里会报错,需要改成 python -c "from tensorflow.python.framework import test_util;print(test_util.IsMklEnabled())"。前后两种方法的日志如下。

(base) [root@b5e5d2467796 /]#python -c"import tensorflow; print(tensorflow.pywrap_tensorflow.IsMklEnabled())"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'pywrap_tensorflow'
(base) [root@b5e5d2467796 /]#python -c "from tensorflow.python.framework import test_util;print(test_util.IsMklEnabled())"
False

另外,通过 Conda 安装 tensorflow-mkl 的方法如下。

conda install -c anaconda tensorflow-mkl

安装的过程,和最后检验 IsMklEnabled() 的结果如下。

(base) [root@b5e5d2467796 /]#conda install -c anaconda tensorflow-mkl
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.8.2
  latest version: 4.8.3

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /opt/anaconda3

  added / updated specs:
    - tensorflow-mkl


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _tflow_select-2.3.0        |              mkl           2 KB  anaconda
    absl-py-0.9.0              |           py37_0         165 KB  anaconda
    astunparse-1.6.3           |             py_0          17 KB  anaconda
    blinker-1.4                |           py37_0          21 KB  anaconda
    c-ares-1.15.0              |    h7b6447c_1001         102 KB  anaconda
    ca-certificates-2020.1.1   |                0         132 KB  anaconda
    cachetools-4.1.0           |             py_1          15 KB  anaconda
    certifi-2019.11.28         |           py37_0         156 KB  anaconda
    conda-4.8.3                |           py37_0         3.0 MB  anaconda
    gast-0.3.3                 |             py_0          14 KB  anaconda
    google-auth-1.14.1         |             py_0          58 KB  anaconda
    google-auth-oauthlib-0.4.1 |             py_2          21 KB  anaconda
    google-pasta-0.2.0         |             py_0          44 KB  anaconda
    grpcio-1.27.2              |   py37hf8bcb03_0         1.4 MB  anaconda
    keras-preprocessing-1.1.0  |             py_1          36 KB  anaconda
    libprotobuf-3.12.3         |       hd408876_0         4.8 MB  anaconda
    markdown-3.1.1             |           py37_0         113 KB  anaconda
    oauthlib-3.1.0             |             py_0          88 KB  anaconda
    openssl-1.1.1d             |       h7b6447c_4         3.7 MB  anaconda
    opt_einsum-3.1.0           |             py_0          54 KB  anaconda
    protobuf-3.12.3            |   py37he6710b0_0         711 KB  anaconda
    pyasn1-0.4.8               |             py_0          58 KB  anaconda
    pyasn1-modules-0.2.7       |             py_0          63 KB  anaconda
    pyjwt-1.7.1                |           py37_0          32 KB  anaconda
    requests-oauthlib-1.3.0    |             py_0          22 KB  anaconda
    rsa-4.0                    |             py_0          30 KB  anaconda
    tensorboard-2.2.1          |     pyh532a8cf_0         2.5 MB  anaconda
    tensorboard-plugin-wit-1.6.0|             py_0         663 KB  anaconda
    tensorflow-2.2.0           |mkl_py37h6e9ce2d_0           4 KB  anaconda
    tensorflow-base-2.2.0      |mkl_py37hd506778_0       276.4 MB  anaconda
    tensorflow-estimator-2.2.0 |     pyh208ff02_0         276 KB  anaconda
    tensorflow-mkl-2.2.0       |       h4fcabd2_0           2 KB  anaconda
    termcolor-1.1.0            |           py37_1           7 KB  anaconda
    ------------------------------------------------------------
                                           Total:       294.8 MB

The following NEW packages will be INSTALLED:

  _tflow_select      anaconda/linux-64::_tflow_select-2.3.0-mkl
  absl-py            anaconda/linux-64::absl-py-0.9.0-py37_0
  astunparse         anaconda/noarch::astunparse-1.6.3-py_0
  blinker            anaconda/linux-64::blinker-1.4-py37_0
  c-ares             anaconda/linux-64::c-ares-1.15.0-h7b6447c_1001
  cachetools         anaconda/noarch::cachetools-4.1.0-py_1
  gast               anaconda/noarch::gast-0.3.3-py_0
  google-auth        anaconda/noarch::google-auth-1.14.1-py_0
  google-auth-oauth~ anaconda/noarch::google-auth-oauthlib-0.4.1-py_2
  google-pasta       anaconda/noarch::google-pasta-0.2.0-py_0
  grpcio             anaconda/linux-64::grpcio-1.27.2-py37hf8bcb03_0
  keras-preprocessi~ anaconda/noarch::keras-preprocessing-1.1.0-py_1
  libprotobuf        anaconda/linux-64::libprotobuf-3.12.3-hd408876_0
  markdown           anaconda/linux-64::markdown-3.1.1-py37_0
  oauthlib           anaconda/noarch::oauthlib-3.1.0-py_0
  opt_einsum         anaconda/noarch::opt_einsum-3.1.0-py_0
  protobuf           anaconda/linux-64::protobuf-3.12.3-py37he6710b0_0
  pyasn1             anaconda/noarch::pyasn1-0.4.8-py_0
  pyasn1-modules     anaconda/noarch::pyasn1-modules-0.2.7-py_0
  pyjwt              anaconda/linux-64::pyjwt-1.7.1-py37_0
  requests-oauthlib  anaconda/noarch::requests-oauthlib-1.3.0-py_0
  rsa                anaconda/noarch::rsa-4.0-py_0
  tensorboard        anaconda/noarch::tensorboard-2.2.1-pyh532a8cf_0
  tensorboard-plugi~ anaconda/noarch::tensorboard-plugin-wit-1.6.0-py_0
  tensorflow         anaconda/linux-64::tensorflow-2.2.0-mkl_py37h6e9ce2d_0
  tensorflow-base    anaconda/linux-64::tensorflow-base-2.2.0-mkl_py37hd506778_0
  tensorflow-estima~ anaconda/noarch::tensorflow-estimator-2.2.0-pyh208ff02_0
  tensorflow-mkl     anaconda/linux-64::tensorflow-mkl-2.2.0-h4fcabd2_0
  termcolor          anaconda/linux-64::termcolor-1.1.0-py37_1

The following packages will be UPDATED:

  conda                       pkgs/main::conda-4.8.2-py37_0 --> anaconda::conda-4.8.3-py37_0

The following packages will be SUPERSEDED by a higher-priority channel:

  ca-certificates                                 pkgs/main --> anaconda
  certifi                                         pkgs/main --> anaconda
  openssl                                         pkgs/main --> anaconda


Proceed ([y]/n)? y


Downloading and Extracting Packages
pyasn1-0.4.8         | 58 KB     | ############################################################################################################################################## | 100%
rsa-4.0              | 30 KB     | ############################################################################################################################################## | 100%
protobuf-3.12.3      | 711 KB    | ############################################################################################################################################## | 100%
openssl-1.1.1d       | 3.7 MB    | ############################################################################################################################################## | 100%
tensorflow-estimator | 276 KB    | ############################################################################################################################################## | 100%
tensorflow-mkl-2.2.0 | 2 KB      | ############################################################################################################################################## | 100%
absl-py-0.9.0        | 165 KB    | ############################################################################################################################################## | 100%
markdown-3.1.1       | 113 KB    | ############################################################################################################################################## | 100%
pyjwt-1.7.1          | 32 KB     | ############################################################################################################################################## | 100%
astunparse-1.6.3     | 17 KB     | ############################################################################################################################################## | 100%
pyasn1-modules-0.2.7 | 63 KB     | ############################################################################################################################################## | 100%
grpcio-1.27.2        | 1.4 MB    | ############################################################################################################################################## | 100%
libprotobuf-3.12.3   | 4.8 MB    | ############################################################################################################################################## | 100%
google-auth-1.14.1   | 58 KB     | ############################################################################################################################################## | 100%
blinker-1.4          | 21 KB     | ############################################################################################################################################## | 100%
conda-4.8.3          | 3.0 MB    | ############################################################################################################################################## | 100%
c-ares-1.15.0        | 102 KB    | ############################################################################################################################################## | 100%
cachetools-4.1.0     | 15 KB     | ############################################################################################################################################## | 100%
ca-certificates-2020 | 132 KB    | ############################################################################################################################################## | 100%
opt_einsum-3.1.0     | 54 KB     | ############################################################################################################################################## | 100%
google-pasta-0.2.0   | 44 KB     | ############################################################################################################################################## | 100%
certifi-2019.11.28   | 156 KB    | ############################################################################################################################################## | 100%
_tflow_select-2.3.0  | 2 KB      | ############################################################################################################################################## | 100%
tensorboard-plugin-w | 663 KB    | ############################################################################################################################################## | 100%
oauthlib-3.1.0       | 88 KB     | ############################################################################################################################################## | 100%
tensorboard-2.2.1    | 2.5 MB    | ############################################################################################################################################## | 100%
termcolor-1.1.0      | 7 KB      | ############################################################################################################################################## | 100%
requests-oauthlib-1. | 22 KB     | ############################################################################################################################################## | 100%
tensorflow-base-2.2. | 276.4 MB  | ############################################################################################################################################## | 100%
google-auth-oauthlib | 21 KB     | ############################################################################################################################################## | 100%
keras-preprocessing- | 36 KB     | ############################################################################################################################################## | 100%
tensorflow-2.2.0     | 4 KB      | ############################################################################################################################################## | 100%
gast-0.3.3           | 14 KB     | ############################################################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(base) [root@b5e5d2467796 /]#python -c "from tensorflow.python.framework import test_util;print(test_util.IsMklEnabled())"
True

Reference

  1. https://software.intel.com/content/www/us/en/develop/articles/intel-optimization-for-tensorflow-installation-guide.html
  2. https://github.com/tensorflow/tensorflow/pull/32342
  3. https://anaconda.org/anaconda/tensorflow-mkl