o
    "jy                     @   s  d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
mZ ddlmZmZ g dZdadd Zd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  ZG d!d" d"ZG d#d$ d$Zd-d%d&Z d'd( Z!G d)d* d*Z"d-d+d,Z#dS ).    N)core	framework)is_compiled_with_cinnis_compiled_with_cudais_compiled_with_distributeis_compiled_with_rocm   )cudaxpu)get_cudnn_version
set_device
get_deviceXPUPlaceIPUPlaceis_compiled_with_xpuis_compiled_with_ipur   r   r   r   is_compiled_with_custom_deviceget_all_device_typeget_all_custom_device_typeget_available_deviceget_available_custom_deviceStreamEventcurrent_stream
set_streamstream_guardsynchronizec                 C   
   t | S )a  

    Whether paddle was built with Paddle_CUSTOM_DEVICE .

    Args:
        device_type (str): the registered device type, like "npu".

    Return:
        bool, ``True`` if CustomDevice is supported, otherwise ``False``.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> support_npu = paddle.device.is_compiled_with_custom_device("npu")

    )r   r   )device_type r   W/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/device/__init__.pyr   >      
r   c                   C      t  S )a  

    Whether paddle was built with WITH_IPU=ON to support Graphcore IPU.

    Returns (bool): `True` if IPU is supported, otherwise `False`.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> support_ipu = paddle.is_compiled_with_ipu()

    )r   r   r   r   r   r    r   S      r   c                   C   r"   )a  

    Return a Graphcore IPU Place

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:IPU)

            >>> import paddle
            >>> paddle.device.set_device('ipu')
            >>> place = paddle.device.IPUPlace()

    )r   r   r   r   r   r    r   d   s   r   c                   C   r"   )a  

    Whether paddle was built with WITH_XPU=ON to support Baidu Kunlun

    Returns (bool): whether paddle was built with WITH_XPU=ON

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> support_xpu = paddle.device.is_compiled_with_xpu()

    )r   r   r   r   r   r    r   v   r#   r   c                 C   r   )a<  

    Return a Baidu Kunlun Place

    Args:
        dev_id(int): Baidu Kunlun device id

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:XPU)

            >>> import paddle
            >>> paddle.device.set_device('xpu')
            >>> place = paddle.device.XPUPlace(0)

    )r   r   )dev_idr   r   r    r      r!   r   c                  C   s8   t  sdS tdu rtt  } | atdk rdS | S tS )a  

    This function return the version of cudnn. the retuen value is int which represents the
    cudnn version. For example, if it return 7600, it represents the version of cudnn is 7.6.

    Returns:
        int: A int value which represents the cudnn version. If cudnn version is not installed, it return None.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> cudnn_version = paddle.device.get_cudnn_version()



    Nr   )r   r   _cudnn_versionintcudnn_version)r'   r   r   r    r      s   r   c           
   	   C   s  |   }| t v r%td|  ddd}t|d }t| |}|S |dkr/t }|S |dkrFt	 s;t
dttj j}|S |d	krht sRt
d
tddd}t|d }t|}|S |dkrzt stt
dt }|S td|}td|}|rt	 st
d|| dd}|d }t|}t|}|rt st
d|| dd}|d }t|}t|}|s|s| dd}|d }	|	t v r|d }t|}t|	|}|S t
dddd g dt  D |S )NZFLAGS_selected_s0,r   cpugpuzLThe device should not be 'gpu', since PaddlePaddle is not compiled with CUDAr
   zKThe device should not be 'xpu', since PaddlePaddle is not compiled with XPUZFLAGS_selected_xpusZipuzKThe device should not be 'ipu', since PaddlePaddle is not compiled with IPUzgpu:\d+zxpu:\d+zIThe device should not be {}, since PaddlePaddle is not compiled with CUDA:r   zHThe device should not be {}, since PaddlePaddle is not compiled with XPUz3The device must be a string which is like 'cpu', {}z, c                 s   s"    | ]}d | d| dV  qdS )'z', 'z:x'Nr   ).0xr   r   r    	<genexpr>   s
    
z$_convert_to_place.<locals>.<genexpr>)r,   r
   Znpu)lowerr   r   osgetenvsplitr&   CustomPlaceCPUPlacer   
ValueError	CUDAPlacepaddledistributedZParallelEnvr$   r   r   r   r   rematchformatjoin)
deviceZlower_deviceZselected_devices	device_idplaceZselected_xpusZavaliable_gpu_deviceZavaliable_xpu_deviceZdevice_info_listr   r   r   r    _convert_to_place   s   B@9
0)


	rC   c                 C   s   t | }t| |S )a]  

    Paddle supports running calculations on various types of devices, including CPU, GPU, XPU, NPU and IPU.
    They are represented by string identifiers. This function can specify the global device
    which the OP will run.

    Args:
        device(str): This parameter determines the specific running device.
            It can be ``cpu``, ``gpu``, ``xpu``, ``npu``, ``gpu:x``, ``xpu:x``, ``npu:x`` and ``ipu``,
            where ``x`` is the index of the GPUs, XPUs or NPUs.

    Returns:
        Place,the Place to set.

    Examples:

        .. code-block:: python

            >>> import paddle

            >>> paddle.device.set_device("cpu")
            >>> x1 = paddle.ones(name='x1', shape=[1, 2], dtype='int32')
            >>> x2 = paddle.zeros(name='x2', shape=[1, 2], dtype='int32')
            >>> data = paddle.stack([x1,x2], axis=1)

    )rC   r   _set_expected_placer@   rB   r   r   r    r   	  s   
r   c                  C   s   d} t  }t|tjrd} | S t|tjr"| }dt| } | S t|tjr4| }dt| } | S t|tj	rPt
 }d|d  d} d|d  d} | S t|tjrh| }| }|d t| } | S td	| d
)a  

    This function can get the current global device of the program is running.
    It's a string which is like 'cpu', 'gpu:x', 'xpu:x' and 'npu:x'. if the global device is not
    set, it will return a string which is 'gpu:x' when cuda is avaliable or it
    will return a string which is 'cpu' when cuda is not avaliable.

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> device = paddle.device.get_device()

     r+   zgpu:zxpu:zipus:{0-r   }r-   zThe device specification z is invalid)r   Z_current_expected_place_
isinstancer   r7   r9   get_device_idstrr   r   Zget_ipu_device_countr6   get_device_typer8   )r@   rB   rA   Znum_devicesr   r   r   r    r   )  s0   r   c                   C   r"   )aI  

    Get all available device types.

    Returns:
        A list of all available device types.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> paddle.device.get_all_device_type()

            >>> # Case 1: paddlepaddle-cpu package installed, and no custom device registerd.
            >>> # Output: ['cpu']

            >>> # Case 2: paddlepaddle-gpu package installed, and no custom device registerd.
            >>> # Output: ['cpu', 'gpu']

            >>> # Case 3: paddlepaddle-cpu package installed, and custom deivce 'CustomCPU' is registerd.
            >>> # Output: ['cpu', 'CustomCPU']

            >>> # Case 4: paddlepaddle-gpu package installed, and custom deivce 'CustomCPU' and 'CustomGPU' is registerd.
            >>> # Output: ['cpu', 'gpu', 'CustomCPU', 'CustomGPU']

    )r   r   r   r   r   r    r   Q     r   c                   C   r"   )a+  

    Get all available custom device types.

    Returns:
        A list of all available custom device types.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> paddle.device.get_all_custom_device_type()

            >>> # Case 1: paddlepaddle-gpu package installed, and no custom device registerd.
            >>> # Output: None

            >>> # Case 2: paddlepaddle-gpu package installed, and custom deivce 'CustomCPU' and 'CustomGPU' is registerd.
            >>> # Output: ['CustomCPU', 'CustomGPU']

    )r   r   r   r   r   r    r   o     r   c                   C   r"   )ag  

    Get all available devices.

    Returns:
        A list of all available devices.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> paddle.device.get_available_device()

            >>> # Case 1: paddlepaddle-cpu package installed, and no custom device registerd.
            >>> # Output: ['cpu']

            >>> # Case 2: paddlepaddle-gpu package installed, and no custom device registerd.
            >>> # Output: ['cpu', 'gpu:0', 'gpu:1']

            >>> # Case 3: paddlepaddle-cpu package installed, and custom deivce 'CustomCPU' is registerd.
            >>> # Output: ['cpu', 'CustomCPU']

            >>> # Case 4: paddlepaddle-gpu package installed, and custom deivce 'CustomCPU' and 'CustomGPU' is registerd.
            >>> # Output: ['cpu', 'gpu:0', 'gpu:1', 'CustomCPU', 'CustomGPU:0', 'CustomGPU:1']

    )r   r   r   r   r   r    r     rL   r   c                   C   r"   )a2  

    Get all available custom devices.

    Returns:
       A list of all available custom devices.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> paddle.device.get_available_custom_device()

            >>> # Case 1: paddlepaddle-gpu package installed, and no custom device registerd.
            >>> # Output: None

            >>> # Case 2: paddlepaddle-gpu package installed, and custom deivce 'CustomCPU' and 'CustomGPU' is registerd.
            >>> # Output: ['CustomCPU', 'CustomGPU:0', 'CustomGPU:1']

    )r   r   r   r   r   r    r     rM   r   c                   @   sL   e Zd ZdZ				dddZdddZdd	 Zd
d Zdd Zdd Z	dS )r   a  

    A device event wrapper around StreamBase.

    Args:
        device(str|paddle.CUDAPlace(n)|paddle.CustomPlace(n)): Which device the stream runn on. If device is None, the device is the current device. Default: None.
            It can be ``gpu``, ``gpu:x``, ``custom_device``, ``custom_device:x``, where ``custom_device`` is the name of CustomDevicec,
            where ``x`` is the index of the GPUs, XPUs. And it can be paddle.CUDAPlace(n) or paddle.CustomPlace(n).
        enable_timing (bool, optional): indicates if the event should measure time, default is False
        blocking (bool, optional): if True, ``wait`` will be blocking, default is False
        interprocess (bool): if True, the event can be shared between processes, default is False

    Returns:
        Event: The event.

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
            >>> import paddle

            >>> paddle.set_device('custom_cpu')
            >>> e1 = paddle.device.Event()
            >>> e2 = paddle.device.Event('custom_cpu')
            >>> e3 = paddle.device.Event('custom_cpu:0')
            >>> e4 = paddle.device.Event(paddle.CustomPlace('custom_cpu', 0))

    NFc                 C   s   |d u rt j | _nt|trt j|| _n|| _t  r0t| jt jr0t	
|||| _d S t| jt jrIt	| j | j |||| _d S tddt j )Ndevice should be gpu, xpu, {}r*   )r:   r   _current_expected_placer@   rH   rJ   rC   r   r9   r   Z	CUDAEvent
event_baser6   ZCustomDeviceEventrK   rI   	TypeErrorr>   r?   r   )selfr@   Zenable_timingblockingZinterprocessr   r   r    __init__  s0   



zEvent.__init__c                 C   s$   |du r	t | j}| j|j dS )a\  

        Records the event in a given stream.

        Args:
            stream(Stream, optional): The given stream. By default, stream is None,
            event will be recorded in current_stream.

        Returns:
            None.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> e = paddle.device.Event()
                >>> e.record()

                >>> s = paddle.device.Stream()
                >>> e.record(s)

        N)r   r@   rP   recordstream_baserR   streamr   r   r    rU     s   
zEvent.recordc                 C   
   | j  S )a  

        Checks if all work currently captured by event has completed.

        Returns:
            bool: Whether all work currently captured by event has completed.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> e = paddle.device.Event()
                >>> e.record()
                >>> e.query()

        )rP   queryrR   r   r   r    rZ     s   
zEvent.queryc                 C   s   dS )aF  

        Returns the time elapsed in milliseconds after the event was
        recorded and before the end_event was recorded.

        Returns:
            int: The time.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> e1 = paddle.device.Event()
                >>> e1.record()

                >>> e2 = paddle.device.Event()
                >>> e2.record()
                >>> e1.elapsed_time(e2)

        r   r   )rR   Z	end_eventr   r   r    elapsed_time3  s   zEvent.elapsed_timec                 C      | j   dS )a4  

        Waits for the event to complete.
        Waits until the completion of all work currently captured in this event.
        This prevents the CPU thread from proceeding until the event completes.

        Returns:
            None.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> e = paddle.device.Event()
                >>> e.record()
                >>> e.synchronize()

        N)rP   r   r[   r   r   r    r   M  s   zEvent.synchronizec                 C   s   | j S N)rP   r[   r   r   r    __repr__e  s   zEvent.__repr__)NFFFr^   )
__name__
__module____qualname____doc__rT   rU   rZ   r\   r   r_   r   r   r   r    r     s    

#r   c                       sp   e Zd ZdZdddZdd Zdd	 Zdd
dZdd Zdd Z	e
dd Z fddZdd Zdd Z  ZS )r   a^  

    A device stream wrapper around StreamBase.

    Args:
        device(str|paddle.CUDAPlace(n)|paddle.CustomPlace(n)): Which device the stream runn on. If device is None, the device is the current device. Default: None.
            It can be ``gpu``, ``gpu:x``, ``custom_device``, ``custom_device:x``, where ``custom_device`` is the name of CustomDevicec,
            where ``x`` is the index of the GPUs, XPUs. And it can be paddle.CUDAPlace(n) or paddle.CustomPlace(n).
        priority(int, optional): priority of the CUDA stream. Can be either
            1 (high priority) or 2 (low priority). By default, streams have
            priority 2.

    Returns:
        Stream: The stream.

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
            >>> import paddle

            >>> paddle.set_device('custom_cpu')
            >>> s1 = paddle.device.Stream()
            >>> s2 = paddle.device.Stream('custom_cpu')
            >>> s3 = paddle.device.Stream('custom_cpu:0')
            >>> s4 = paddle.device.Stream(paddle.CustomPlace('custom_cpu', 0))

    N   c                 C   s   |d urt |tjtjfr|| _|j| _d S td|d u r%tj	
 | _nt |tr2tj|| _n|| _t rLt | jtjrLt| j || _d S t | jtjretj| j | j |dd| _d S tddtj )Nz4stream_base should be CUDAStream, CustomDeviceStreamF)rS   rN   r*   )rH   r   
CUDAStreamZCustomDeviceStreamrV   rB   r@   rQ   r:   r   rO   rJ   rC   r   r9   rI   r6   rK   r>   r?   r   )rR   r@   priorityrV   r   r   r    rT     sB   



zStream.__init__c                 C   s   | j |j dS )aV  

        Makes all future work submitted to the stream wait for an event.

        Args:
            event (Event): an event to wait for.

        Returns:
            None.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> s1 = paddle.device.Stream()
                >>> s2 = paddle.device.Stream()
                >>> e = paddle.device.Event()
                >>> e.record(s1)
                >>> s2.wait_event(e)

        N)rV   
wait_eventrP   rR   eventr   r   r    rg        zStream.wait_eventc                 C   s   | j |j  dS )a~  

        Synchronizes with another stream.
        All future work submitted to this stream will wait until all kernels
        submitted to a given stream at the time of call complete.

        Args:
            stream (Stream): a stream to synchronize.

        Returns:
            None.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> s1 = paddle.device.Stream()
                >>> s2 = paddle.device.Stream()
                >>> s1.wait_stream(s2)

        N)rV   wait_streamrW   r   r   r    rk     rj   zStream.wait_streamc                 C   s    |du r	t | j}||  |S )aP  

        Records an event.

        Args:
            event (Event, optional): event to record. If not given, a new one
            will be allocated.

        Returns:
            Event: Recorded event.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> s = paddle.device.Stream()
                >>> e1 = s.record_event()

                >>> e2 = paddle.device.Event()
                >>> s.record_event(e2)

        N)r   r@   rU   rh   r   r   r    record_event  s   

zStream.record_eventc                 C   rY   )a  

        Checks if all the work submitted has been completed.

        Returns:
            bool: Whether all kernels in this stream are completed.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> s = paddle.device.Stream()
                >>> s.query()

        )rV   rZ   r[   r   r   r    rZ     s   
zStream.queryc                 C   r]   )a  

        Wait for all the kernels in this stream to complete.

        Returns:
            None.

        Examples:
            .. code-block:: python

                >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
                >>> import paddle

                >>> paddle.set_device('custom_cpu')
                >>> s = paddle.device.Stream()
                >>> s.synchronize()

        N)rV   r   r[   r   r   r    r     s   zStream.synchronizec                 C   s*   t | jtjrt| jjS t| jjS r^   )rH   rV   r   re   ctypesc_void_pZcuda_streamZ
raw_streamr[   r   r   r    _as_parameter_.  s   zStream._as_parameter_c                    s   t |trt |S dS )NF)rH   r   super__eq__)rR   o	__class__r   r    rq   5  s   
zStream.__eq__c                 C   s   t | j| jfS r^   )hashrV   r@   r[   r   r   r    __hash__:  s   zStream.__hash__c                 C   s   d | j| jjS )Nz-<paddle.device.Stream device={} stream={:#x}>)r>   r@   ro   valuer[   r   r   r    r_   =  s   
zStream.__repr__)Nrd   Nr^   )r`   ra   rb   rc   rT   rg   rk   rl   rZ   r   propertyro   rq   rv   r_   __classcell__r   r   rs   r    r   i  s    
(

r   c                 C   s   | du r
t j }nt| trt j| }n| }t  r,t|t jr,t	t
| dS t|t jr?t	t
| | dS tddt j )a  

    Return the current stream by the device.

    Args:
        device(str|paddle.CUDAPlace(n)|paddle.CustomPlace(n)): The device which want to get stream from.  If device is None, the device is the current device. Default: None.
            It can be ``gpu``, ``gpu:x``, ``custom_device``, ``custom_device:x``, where ``custom_device`` is the name of CustomDevicec,
            where ``x`` is the index of the GPUs, CustomDevicecs. And it can be paddle.CUDAPlace(n) or paddle.CustomPlace(n).

    Returns:
        Stream: The stream to the device.

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
            >>> import paddle

            >>> paddle.set_device('custom_cpu')
            >>> s1 = paddle.device.current_stream()
            >>> s2 = paddle.device.current_stream("custom_cpu:0")
            >>> place = paddle.CustomPlace('custom_cpu', 0)
            >>> s3 = paddle.device.current_stream(place)

    N)rV   rN   r*   )r:   r   rO   rH   rJ   r@   rC   r   r9   r   r   Z_get_current_streamrI   r6   Z!_get_current_custom_device_streamrK   rQ   r>   r?   r   rE   r   r   r    r   C  s(   
r   c                 C   s   t | jj}t rt| jjtjrt| j |S t| jjtj	r4t
| jj | jj | j |S tddtj )a  

    Set the current stream.

    Args:
        stream(Stream): The selected stream.

    Returns:
        Stream: The previous stream.

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
            >>> import paddle

            >>> paddle.set_device('custom_cpu')
            >>> s = paddle.device.Stream()
            >>> paddle.device.set_stream(s)

    rN   r*   )r   rV   rB   r:   r   rH   r9   r   Z_set_current_streamr6   Z!_set_current_custom_device_streamrK   rI   rQ   r>   r?   r@   r   )rX   Zprev_streamr   r   r    r   v  s$   



r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   a(  

    Notes:
        This API only supports dynamic graph mode currently.
    A context manager that specifies the current stream context by the given stream.

    Args:
        stream(Stream, optional): the selected stream. If stream is None, just yield.

    Returns:
        None.

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
            >>> import paddle

            >>> paddle.set_device('custom_cpu')
            >>> s = paddle.device.Stream()
            >>> data1 = paddle.ones(shape=[20])
            >>> data2 = paddle.ones(shape=[20])
            >>> data3 = data1 + data2
            >>> with paddle.device.stream_guard(s):
            ...     s.wait_stream(paddle.device.default_stream())
            ...     data4 = data1 + data3

    Nc                 C   s
   || _ d S r^   )rX   rW   r   r   r    rT     s   
zstream_guard.__init__c                 C   sn   | j }|d u r	d S t|j| _| jj|jkr1tjj | _tjj	|j t|j| _
t| d S t| d S r^   )rX   r   r@   src_prev_streamr:   baser   rO   	tmp_placerD   dst_prev_streamr   )rR   
cur_streamr   r   r    	__enter__  s   zstream_guard.__enter__c                 G   sV   | j }|d u r	d S | jj|jkr$t| j tjj| j	 t| j d S t| j d S r^   )
rX   rz   r@   r   r}   r:   r{   r   rD   r|   )rR   argsr~   r   r   r    __exit__  s   
zstream_guard.__exit__r^   )r`   ra   rb   rc   rT   r   r   r   r   r   r    r     s
    
r   c                 C   s   | du r
t j }nt| trt j| }n| }t  r+t|t jr+t	
|  dS t  r>t|t jr>t	|  dS t|t jrPt	| |  dS tddt j )a  

    Wait for the compute on the given device to finish.

    Args:
        device(str|paddle.CUDAPlace(n)|paddle.XPUPlace(n)|paddle.CustomPlace(n)): The device which want to wait for.  If device is None, the device is the current device. Default: None.
            It can be ``gpu``, ``gpu:x``, ``xpu``, ``xpu:x``, ``custom_device``, ``custom_device:x``, where ``custom_device`` is the name of CustomDevicec,
            where ``x`` is the index of the GPUs, XPUs. And it can be paddle.CUDAPlace(n) or paddle.XPUPlace(n) or paddle.CustomPlace(n).

    Examples:
        .. code-block:: python

            >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
            >>> import paddle

            >>> paddle.set_device('custom_cpu')
            >>> paddle.device.synchronize()
            >>> paddle.device.synchronize("custom_cpu:0")
            >>> place = paddle.CustomPlace('custom_cpu', 0)
            >>> paddle.device.synchronize(place)

    NrN   r*   )r:   r   rO   rH   rJ   r@   rC   r   r9   r   Z_device_synchronizerI   r   r   Z_xpu_device_synchronizer6   Z_synchronize_custom_devicerK   rQ   r>   r?   r   rE   r   r   r    r     s$   
r   r^   )$rm   r3   r<   r:   Zpaddle.baser   r   Zpaddle.base.frameworkr   r   r   r   rF   r	   r
   __all__r%   r   r   r   r   r   r   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    <module>   s<   !L ( - 
[3-<