[docs]defis_available():r"""Returns whether PyTorch is built with MKL-DNN support."""returntorch._C.has_mkldnn
VERBOSE_OFF=0VERBOSE_ON=1VERBOSE_ON_CREATION=2
[docs]classverbose(object):""" On-demand oneDNN (former MKL-DNN) verbosing functionality To make it easier to debug performance issues, oneDNN can dump verbose messages containing information like kernel size, input data size and execution duration while executing the kernel. The verbosing functionality can be invoked via an environment variable named `DNNL_VERBOSE`. However, this methodology dumps messages in all steps. Those are a large amount of verbose messages. Moreover, for investigating the performance issues, generally taking verbose messages for one single iteration is enough. This on-demand verbosing functionality makes it possible to control scope for verbose message dumping. In the following example, verbose messages will be dumped out for the second inference only. .. highlight:: python .. code-block:: python import torch model(data) with torch.backends.mkldnn.verbose(torch.backends.mkldnn.VERBOSE_ON): model(data) Args: level: Verbose level - ``VERBOSE_OFF``: Disable verbosing - ``VERBOSE_ON``: Enable verbosing - ``VERBOSE_ON_CREATION``: Enable verbosing, including oneDNN kernel creation """def__init__(self,level):self.level=leveldef__enter__(self):ifself.level==VERBOSE_OFF:returnst=torch._C._verbose.mkldnn_set_verbose(self.level)assertst,"Failed to set MKLDNN into verbose mode. Please consider to disable this verbose scope."returnselfdef__exit__(self,exc_type,exc_val,exc_tb):torch._C._verbose.mkldnn_set_verbose(VERBOSE_OFF)returnFalse
defset_flags(_enabled):orig_flags=(torch._C._get_mkldnn_enabled(),)torch._C._set_mkldnn_enabled(_enabled)returnorig_flags@contextmanagerdefflags(enabled=False):with__allow_nonbracketed_mutation():orig_flags=set_flags(enabled)try:yieldfinally:with__allow_nonbracketed_mutation():set_flags(orig_flags[0])classMkldnnModule(PropModule):def__init__(self,m,name):super(MkldnnModule,self).__init__(m,name)enabled=ContextProp(torch._C._get_mkldnn_enabled,torch._C._set_mkldnn_enabled)# Cool stuff from torch/backends/cudnn/__init__.py and# https://stackoverflow.com/questions/2447353/getattr-on-a-module/7668273#7668273sys.modules[__name__]=MkldnnModule(sys.modules[__name__],__name__)
Docs
Access comprehensive developer documentation for PyTorch
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.