
    }Yh                        U d dl Z d dlZd dlmZmZ d dlZd dlmZ g dZe	e
         ed<   de
defdZ eej        d	          s eej        d
          rJ  eej        d          rJ  eej        d          rJ  eej        d          rJ  eej        d          rJ  ed	          ej        j        d	<    ed
          ej        j        d
<    ed          ej        j        d<    ed          ej        j        d<    ed          ej        j        d<    ed          ej        j        d<   deddfdZdeddfdZ G d d          ZdS )    N)CallableOptional)Storage)gds_register_buffergds_deregister_bufferGdsFile__all__namereturnc                       fd}|S )Nc                  *    t          d d          )Nz	torch._C.z" is not supported on this platform)RuntimeError)argskwargsr
   s     `/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/cuda/gds.pyfnz_dummy_fn.<locals>.fn   s    OtOOOPPP     )r
   r   s   ` r   	_dummy_fnr      s(    Q Q Q Q Q Ir   _gds_register_buffer_gds_deregister_buffer_gds_register_handle_gds_deregister_handle_gds_load_storage_gds_save_storagesc                 D    t           j                            |            dS )a:  Registers a storage on a CUDA device as a cufile buffer.

    Example::

        >>> # xdoctest: +SKIP("gds filesystem requirements")
        >>> src = torch.randn(1024, device="cuda")
        >>> s = src.untyped_storage()
        >>> gds_register_buffer(s)

    Args:
        s (Storage): Buffer to register.
    N)torch_Cr   r   s    r   r   r   &   s      
H!!!$$$$$r   c                 D    t           j                            |            dS )aw  Deregisters a previously registered storage on a CUDA device as a cufile buffer.

    Example::

        >>> # xdoctest: +SKIP("gds filesystem requirements")
        >>> src = torch.randn(1024, device="cuda")
        >>> s = src.untyped_storage()
        >>> gds_register_buffer(s)
        >>> gds_deregister_buffer(s)

    Args:
        s (Storage): Buffer to register.
    N)r   r   r   r    s    r   r   r   6   s      
H##A&&&&&r   c                   f    e Zd ZdZdedefdZddZddZdd	Z	dde
deddfdZdde
deddfdZdS )r   a  Wrapper around cuFile.

    cuFile is a file-like interface to the GPUDirect Storage (GDS) API.

    See the `cufile docs <https://docs.nvidia.com/gpudirect-storage/api-reference-guide/index.html#cufile-io-api>`_
    for more details.

    Args:
        filename (str): Name of the file to open.
        flags (int): Flags to pass to ``os.open`` when opening the file. ``os.O_DIRECT`` will
            be added automatically.

    Example::

        >>> # xdoctest: +SKIP("gds filesystem requirements")
        >>> src1 = torch.randn(1024, device="cuda")
        >>> src2 = torch.randn(2, 1024, device="cuda")
        >>> file = torch.cuda.gds.GdsFile(f, os.O_CREAT | os.O_RDWR)
        >>> file.save_storage(src1.untyped_storage(), offset=0)
        >>> file.save_storage(src2.untyped_storage(), offset=src1.nbytes)
        >>> dest1 = torch.empty(1024, device="cuda")
        >>> dest2 = torch.empty(2, 1024, device="cuda")
        >>> file.load_storage(dest1.untyped_storage(), offset=0)
        >>> file.load_storage(dest2.untyped_storage(), offset=src1.nbytes)
        >>> torch.equal(src1, dest1)
        True
        >>> torch.equal(src2, dest2)
        True

    filenameflagsc                     t           j        dk    rt          d          || _        || _        t          j        ||t
          j        z            | _        d | _	        | 
                                 d S )Nwin32z*GdsFile is not supported on this platform.)sysplatformr   r#   r$   osopenO_DIRECTfdhandleregister_handle)selfr#   r$   s      r   __init__zGdsFile.__init__g   se    <7""KLLL 
'(EBK$788%)r   r   Nc                 n    | j         |                                  t          j        | j                   d S )N)r-   deregister_handler)   closer,   r/   s    r   __del__zGdsFile.__del__p   s4    ;"""$$$
r   c                 z    | j         
J d            t          j                            | j                  | _         dS )zpRegisters file descriptor to cuFile Driver.

        This is a wrapper around ``cuFileHandleRegister``.
        Nz4Cannot register a handle that is already registered.)r-   r   r   r   r,   r4   s    r   r.   zGdsFile.register_handleu   s:     KA  h33DG<<r   c                 ~    | j         
J d            t          j                            | j                    d| _         dS )zvDeregisters file descriptor from cuFile Driver.

        This is a wrapper around ``cuFileHandleDeregister``.
        Nz2Cannot deregister a handle that is not registered.)r-   r   r   r   r4   s    r   r2   zGdsFile.deregister_handle   s@     K##? $##''444r   r   storageoffsetc                 t    | j         
J d            t          j                            | j         ||           dS )am  Loads data from the file into the storage.

        This is a wrapper around ``cuFileRead``. ``storage.nbytes()`` of data
        will be loaded from the file at ``offset`` into the storage.

        Args:
            storage (Storage): Storage to load data into.
            offset (int, optional): Offset into the file to start loading from. (Default: 0)
        Nz4Cannot load data from a file that is not registered.)r-   r   r   r   r/   r8   r9   s      r   load_storagezGdsFile.load_storage   s?     K##A $##""4;@@@@@r   c                 t    | j         
J d            t          j                            | j         ||           dS )aU  Saves data from the storage into the file.

        This is a wrapper around ``cuFileWrite``. All bytes of the storage
        will be written to the file at ``offset``.

        Args:
            storage (Storage): Storage to save data from.
            offset (int, optional): Offset into the file to start saving to. (Default: 0)
        Nz2Cannot save data to a file that is not registered.)r-   r   r   r   r;   s      r   save_storagezGdsFile.save_storage   s?     K##? $##""4;@@@@@r   )r   N)r   )__name__
__module____qualname____doc__strintr0   r5   r.   r2   r   r<   r>   r   r   r   r   r   G   s         > S       
= = = =	 	 	 	A AG AS A A A A AA AG AS A A A A A A Ar   r   )r)   r'   typingr   r   r   torch.typesr   r	   listrC   __annotations__r   hasattrr   __dict__r   r   r   r   r   r   <module>rK      sa   					 



 % % % % % % % %         c   C H     wux/00 Lwux!9:::::wux!788888wux!9:::::wux!455555wux!45555509	:P0Q0QEH,-2;)<T2U2UEH./09	:P0Q0QEH,-2;)<T2U2UEH./-6Y7J-K-KEH)*-6Y7J-K-KEH)*%7 %t % % % % 'W ' ' ' ' '"_A _A _A _A _A _A _A _A _A _Ar   