o
    ߗiV                     @   sN  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dZeejd	seejd
r<J eejdrDJ eejdrLJ eejdrTJ 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d	Zdeddfdd
ZG dd dZdS )    N)CallableListOptional)Storage__all__namereturnc                    s    fdd}|S )Nc                     s   t d  d)Nz	torch._C.z" is not supported on this platform)RuntimeError)argskwargsr    L/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/torch/cuda/gds.pyfn   s   z_dummy_fn.<locals>.fnr   )r   r   r   r   r   	_dummy_fn   s   r   _gds_register_buffer_gds_deregister_buffer_gds_register_handle_gds_deregister_handle_gds_load_storage_gds_save_storagesc                 C      t j|  dS zLRegisters a buffer.

    Args:
        s (Storage): Buffer to register.
    N)torch_Cr   r   r   r   r   r   "      c                 C   r   r   )r   r   r   r   r   r   r   r   +   r   c                   @   sp   e Zd ZdZdedefddZddd	Zdd
dZdddZ	dde
deddfddZdde
deddfddZdS )_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                 C   sD   t jdkr	td|| _|| _t||tjB | _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    r   r   r   __init__B   s   
z_GdsFile.__init__r   Nc                 C   s"   | j d ur	|   t| j d S )N)r(   deregister_handler$   closer'   r*   r   r   r   __del__K   s   
z_GdsFile.__del__c                 C   s&   | j du s	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'   r.   r   r   r   r)   P   s   z_GdsFile.register_handlec                 C   s*   | j dus	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   r.   r   r   r   r,   Z   s
   
z_GdsFile.deregister_handler   storageoffsetc                 C   (   | j dus	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*   r0   r1   r   r   r   load_storagee      z_GdsFile.load_storagec                 C   r2   )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   r3   r   r   r   save_storaget   r5   z_GdsFile.save_storage)r   N)r   )__name__
__module____qualname____doc__strintr+   r/   r)   r,   r   r4   r6   r   r   r   r   r   4   s    
	


r   )r$   r"   typingr   r   r   r   torch.typesr   r   r;   __annotations__r   hasattrr   __dict__r   r   r   r   r   r   r   <module>   s,   
 		