How to close MKLDNN dynamically?

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
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'

os.putenv('MXNET_MKLDNN_ENABLED', '0')

Did you take a look at these env variable settings: ?

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 USE_MKLDNN=1 )

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.