
    `ih                     D   d dl Z d dlmZ d dlmZmZmZmZ d dlm	Z	 d dl
Z
ddZe j        j        fdeee j                 e j        f         defd	Zed
e j        j        e j        j        e j        j        fdedede j        de j        de j        de j        fd            ZdS )    N)contextmanager)OptionalListUnionCallablewraps   c                       fd}|S )zCustom caching decorator that uses a provided key function

    Args:
        key_fn: Function that generates cache key from the input arguments
        maxsize: Maximum size of the cache
    c                 J     i t                      fd            }|S )Nc                       | i |}|v r|         S  | i |}t                    k    r/                    t          t                                         ||<   |S )N)lenpopnextiter)argskwargskeyresultcachefunckey_fnmaxsizes       _/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cudnn/graph.pywrapperz/graph_cache.<locals>.decorator.<locals>.wrapper   s}    &$)&))Ce||Sz!T4*6**F5zzW$$		$tE{{++,,,E#JM    r   )r   r   r   r   r   s   ` @r   	decoratorzgraph_cache.<locals>.decorator   sI    	t
	 
	 
	 
	 
	 
	 
	 

	 r    )r   r   r   s   `` r   graph_cacher      s*         $ r   
heur_modesreturnc                 B     t           t                    s g  fd}|S )a  
    Decorator that automatically builds a graph with specified heuristic modes.

    Args:
        heur_modes: Single heuristic mode or list of modes for graph building.
        **kwargs: Additional configuration options for graph building.

    Returns:
        Callable: Decorated context manager function that returns (graph, tensor_uids).

    Example:
        >>> handle = cudnn.create_handle()
        >>> @cudnn.jit(heur_modes=[cudnn.heur_mode.A, cudnn.heur_mode.B])
        ... def my_graph():
        ...     with graph(handle) as g:
        ...         X = g.tensor(name="X", dim=[8, 64, 56, 56],
        ...                     stride=[56*56*64, 1, 56*64, 64])
        ...         return g, [X]  # Return graph and list of tensors to get UIDs for
    c                 @     t                      fd            }|S )Nc                       | i |\  }}|                                 dk    r|                               |d |D             fS )Nr   c                 6    g | ]}|                                 S r   )get_uid).0ts     r   
<listcomp>z;jit.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>E   s     444qqyy{{444r   )get_execution_plan_countbuild)r   r   gtensorsr   r    s       r   r   z'jit.<locals>.decorator.<locals>.wrapper@   s^    t.v..JAw))++q00
###44G44444r   r   )r   r   r    s   ` r   r   zjit.<locals>.decorator?   s9    	t	5 	5 	5 	5 	5 
	5 r   )
isinstancelist)r    r   r   s   `  r   jitr0   %   s?    . j$'' " \
     r   cudnn_graphhandlenameio_data_typeintermediate_data_typecompute_data_typec              #   H   K   t          j        | ||||          }|g fV  dS )a  
    Context manager for creating and managing a CUDNN graph object.

    Args:
        handle: CUDNN handle created with cudnn.create_handle().
        name: Name of the graph for debugging purposes.
        io_data_type: Data type for input/output tensors.
        compute_data_type: Data type for computation.

    Yields:
        Tuple[cudnn.pygraph, List]: (graph object, list of tensors to get UIDs for)
    )r2   r3   r4   r5   r6   N)cudnnpygraph)r2   r3   r4   r5   r6   r,   s         r   graphr:   L   s@      ( 	!5+	 	 	A R%KKKKKr   )r
   )r8   
contextlibr   typingr   r   r   r   	functoolsr	   warningsr   	heur_modeAr0   	data_typeHALFFLOATobjectstrr9   r:   r   r   r   <module>rF      sJ    % % % % % % 2 2 2 2 2 2 2 2 2 2 2 2          < AF@Q$ $d5?+U_<=$ $ $ $ $N  $)O$8.3o.C).)> 
 / "O	
  ]     r   