
    sgU                         U d dl Z d dlmZ d dlmZ d dlZd dlmZmZm	Z	 d Z
d ZdZdZ G d d	      Zdd
Zedd       Z G d de	      Zer
eed<   eed<    ee j&                  e   e      e j&                  e<   y)    N)contextmanager)TYPE_CHECKING)__allow_nonbracketed_mutationContextProp
PropModulec                  6    t         j                  j                  S )z5Return whether PyTorch is built with MKL-DNN support.)torch_C_has_mkldnn     Q/var/www/html/venv/lib/python3.12/site-packages/torch/backends/mkldnn/__init__.pyis_availabler   
   s    88r         c                   "    e Zd ZdZd Zd Zd Zy)verbosea  
    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
    c                     || _         y N)level)selfr   s     r   __init__zverbose.__init__2   s	    
r   c                     | j                   t        k(  ry t        j                  j                  j                  | j                         }|sJ d       | S )NzVFailed to set MKLDNN into verbose mode. Please consider to disable this verbose scope.)r   VERBOSE_OFFr	   r
   _verbosemkldnn_set_verbose)r   sts     r   	__enter__zverbose.__enter__5   sI    ::$XX11$**=	dc	dr   c                 ^    t         j                  j                  j                  t               y)NF)r	   r
   r   r   r   )r   exc_typeexc_valexc_tbs       r   __exit__zverbose.__exit__>   s    ,,[9r   N)__name__
__module____qualname____doc__r   r   r#   r   r   r   r   r      s    :r   r   c                     t         j                  j                         t         j                  j                         f}t         j                  j	                  |        |t         j                  j                  |       |S r   )r	   r
   _get_mkldnn_enabled_get_mkldnn_deterministic_set_mkldnn_enabled_set_mkldnn_deterministic)_enabled_deterministic
orig_flagss      r   	set_flagsr0   C   sV    ((..0%((2T2T2VWJ	HH  *!**>:r   c              #     K   t               5  t        | |      }d d d        	 d  t               5  t          d d d        y # 1 sw Y   *xY w# 1 sw Y   y xY w# t               5  t          d d d        w # 1 sw Y   w xY wxY wwr   )r   r0   )enableddeterministicr/   s      r   flagsr4   K   s     	&	( 7w6
7#*, 	#z"	# 	#7 7
	# 	#*, 	#z"	# 	# 	#s_   BABA 
B	A	BABABB&	A8/	B8B=BBc                        e Zd Z fdZ eej                  j                  ej                  j                        Z	 eej                  j                  ej                  j                        Z xZS )MkldnnModulec                 &    t         |   ||       y r   )superr   )r   mname	__class__s      r   r   zMkldnnModule.__init__W   s    D!r   )r$   r%   r&   r   r   r	   r
   r)   r+   r2   r*   r,   r3   __classcell__)r;   s   @r   r6   r6   V   sM    " %((668T8TUG**EHH,N,NMr   r6   r2   r3   r   )FF)sys
contextlibr   typingr   r	   torch.backendsr   r   r   r   r   
VERBOSE_ONVERBOSE_ON_CREATIONr   r0   r4   r6   __annotations__modulesr$   r   r   r   <module>rE      s    
 %    Q Q 
 
 , ,^ # #:  $S[[%:HEH r   