I have build a mxnet with MKLDNN and used in C code. But found that some models were slower than without MKLDNN. My question is that is there any method to activate MKLDNN or not, so I can activate MKLDNN dynamically according to models speed.
You can select MKLDNN by modifying your environment.
With python you can use:
import os os.environ['MXNET_SUBGRAPH_BACKEND'] = 'MKLDNN' import mxnet as mx
I just found environment MXNET_MKLDNN_ENABLED=0 can close MKLDNN, and tried something like the following code hope to close/open it dynamically, but it didn’t work.
os.environ['MXNET_MKLDNN_ENABLED'] = '0' or '1' importlib.reload(mxnet) or os.putenv('MXNET_MKLDNN_ENABLED', '0') importlib.reload(mxnet)
Did you take a look at these env variable settings: https://mxnet.apache.org/api/faq/env_var ?
In general, MXNET_MKLDNN_ENABLED is ON by default if mxnet has been compiled with MKLDNN (either with
pip install mxnet-mkl or built from source with
Yes, I found the var MXNET_MKLDNN_ENABLED from it yesterday. But this environment value only take effect before program startup in my tests. If program is startup and change its value in the program dynamically, it will not work.