
    ǄgV                        U d dl Z d dlZd dlmZmZmZ d dlZd dlmZ g 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y)    N)CallableListOptional)Storage__all__namereturnc                       fd}|S )Nc                  "    t        d d      )Nz	torch._C.z" is not supported on this platform)RuntimeError)argskwargsr   s     V/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/cuda/gds.pyfnz_dummy_fn.<locals>.fn   s    Ytf,NOPP     )r   r   s   ` r   	_dummy_fnr      s    Q Ir   _gds_register_buffer_gds_deregister_buffer_gds_register_handle_gds_deregister_handle_gds_load_storage_gds_save_storagesc                 B    t         j                  j                  |        yzLRegisters a buffer.

    Args:
        s (Storage): Buffer to register.
    N)torch_Cr   r   s    r   r   r   "   s     
HH!!!$r   c                 B    t         j                  j                  |        yr   )r   r   r   r   s    r   r   r   +   s     
HH##A&r   c                   d    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y)_GdsFilea  Wrapper around cuFile.

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

    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.

    .. _CUDA GPUDirect Storage Documentation:
        https://docs.nvidia.com/gpudirect-storage/api-reference-guide/index.html#cufile-io-api
    filenameflagsc                     t         j                  dk(  rt        d      || _        || _        t        j                  ||t
        j                  z        | _        d | _	        | j                          y )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__B   sV    <<7"KLL 
''(EBKK$78%)r   r	   Nc                 z    | j                   | j                          t        j                  | j                         y )N)r-   deregister_handler)   closer,   r/   s    r   __del__z_GdsFile.__del__K   s(    ;;"""$
r   c                     | j                   J d       t        j                  j                  | j                        | _         y)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_handleP   s:     KK	BA	Bhh33DGG<r   c                     | j                   J d       t        j                  j                  | j                          d| _         y)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_handleZ   s=     KK#	@?	@#''4r   storageoffsetc                     | j                   J d       t        j                  j                  | j                   ||       y)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_storagee   s:     KK#	BA	B#""4;;@r   c                     | j                   J d       t        j                  j                  | j                   ||       y)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_storaget   s:     KK#	@?	@#""4;;@r   )r	   N)r   )__name__
__module____qualname____doc__strintr0   r5   r.   r2   r   r<   r>   r   r   r   r"   r"   4   se     S 
=	AG AS A AAG AS A Ar   r"   )r)   r'   typingr   r   r   r   torch.typesr   r   rC   __annotations__r   hasattrr   __dict__r   r   r"   r   r   r   <module>rJ      s   	 
 + +   c C H  uxx/0uxx!9:::uxx!7888uxx!9:::uxx!4555uxx!455509:P0QEHH,-2;<T2UEHH./09:P0QEHH,-2;<T2UEHH./-67J-KEHH)*-67J-KEHH)*%G % %'g '$ 'MA MAr   