
    i                         d Z ddlmZmZ ddlZddlmZmZ ddlm	Z	 ddee   de
eef   fd	Zddee   defd
Zddee   defdZddee   ddfdZg dZy)zKThis package adds support for device memory management implemented in MTIA.    )AnyOptionalN   )	_device_tis_initialized)_get_device_indexdevicereturnc                 n    t               si S t        j                  j                  t	        | d            S )a  Return a dictionary of MTIA memory allocator statistics for a given device.

    Args:
        device (torch.device, str, or int, optional) selected device. Returns
            statistics for the current device, given by current_device(),
            if device is None (default).
    Toptional)r   torch_C_mtia_memoryStatsr   r	   s    K/var/www/html/engine/venv/lib/python3.12/site-packages/torch/mtia/memory.pymemory_statsr      s,     	88%%&7&NOO    c                 n    t               syt        |       j                  dd      j                  dd      S )a  Return the maximum memory allocated in bytes for a given device.

    Args:
        device (torch.device, str, or int, optional) selected device. Returns
            statistics for the current device, given by current_device(),
            if device is None (default).
    r   dram
peak_bytesr   r   getr   s    r   max_memory_allocatedr      s2     ##FA.22<CCr   c                 n    t               syt        |       j                  dd      j                  dd      S )a?  Return the current MTIA memory occupied by tensors in bytes for a given device.

    Args:
        device (torch.device or int or str, optional): selected device. Returns
            statistic for the current device, given by :func:`~torch.mtia.current_device`,
            if :attr:`device` is ``None`` (default).
    r   r   allocated_bytesr   r   s    r   memory_allocatedr   '   s3     ##FA.223DaHHr   c                 n    t               syt        j                  j                  t	        | d             y)a  Reset the peak memory stats for a given device.


    Args:
        device (torch.device, str, or int, optional) selected device. Returns
            statistics for the current device, given by current_device(),
            if device is None (default).
    NTr   )r   r   r   _mtia_resetPeakMemoryStatsr   r   s    r   reset_peak_memory_statsr    4   s'     	HH''(9&4(PQr   )r   r   r   r    )N)__doc__typingr   r   r    r   r   _utilsr   dictstrr   intr   r   r    __all__ r   r   <module>r*      s    S    ' %
P), 
PS#X 
P
D)!4 
D 
D
IXi0 
IC 
IRHY$7 R4 Rr   