
    ΑiW                       % S SK Jr  S SKJrJr  S SKJr  S SKrS SKJ	r	  S SK
Jr  SSKJrJrJrJr  \(       a  S S	KJr  \\\\4   rS
\S'   / SQrS"S#S jjrS$S jr\" SSSSS9S"S%S jj5       rS&S jrS'S(S jjrS)S jrS"S%S jjrS"S%S jjrS"S*S jjrS"S*S jjr S"S%S jjr!S"S%S jjr"S"S%S jjr#S"S%S jjr$S"S+S jjr% S"     S,S  jjr&S-S! jr'g).    )annotations)TYPE_CHECKINGUnion)	TypeAliasN)core)
deprecated   )EventStreamcreate_eventcreate_stream)XPUPlacer   _XPUPlaceLike)r   r
   synchronizedevice_countset_debug_levelempty_cachemax_memory_allocatedmax_memory_reservedreset_max_memory_allocatedreset_max_memory_reservedmemory_allocatedmemory_reservedmemory_totalmemory_usedc                h   SnU b  [        U [        5      (       a  U nO[        U [        R                  5      (       a  U R	                  5       nOP[        U [
        5      (       a0  [        R                  R                  U 5      nUR	                  5       nO[        S5      e[        R                  " U5      $ )az  
Return the current XPU stream by the device.

Args:
    device(paddle.XPUPlace()|int|None, optional): The device or the ID of the device which want to get stream from.
            If device is None, the device is the current device. Default: None.

Returns:
        XPUStream: the stream to the device.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> s1 = paddle.device.xpu.current_stream()

        >>> s2 = paddle.device.xpu.current_stream(0)

        >>> s3 = paddle.device.xpu.current_stream(paddle.XPUPlace(0))

*device type must be int or paddle.XPUPlace)
isinstanceintr   r   get_device_idstrpaddledevice_convert_to_place
ValueError_xpu_get_current_stream)r$   	device_idplaces      Z/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/device/xpu/__init__.pycurrent_streamr+   5   s    4 Ifc""I..,,.I$$MM33F;E++-IIJJ''	22    c                   U c  [         R                  " 5       $ [        U [        5      (       a  U nO[        U [         R                  5      (       a  U R                  5       nO^[        U [        5      (       a7  U R                  S5      (       a  [        U SS 5      nO$[        SU  SU S35      e[        SU  SU S35      eUS	:  d   S
U S35       eU[        5       :  d   SU S[        5        35       eU$ )a_  
Return the id of the given xpu device. It is just a utility that will not be exposed to users.

Args:
    device(paddle.XPUPlace or int or str): The device, the id of the device or
        the string name of device like 'xpu:x'.
        Default: None.

Return:
    int: The id of the given device. If device is None, return the id of current device.
Nxpu:   The current string z is not expected. Because zR only support string which is like 'xpu:x'. Please input appropriate string again!zThe device type zQ only support int, str or paddle.XPUPlace. Please input appropriate device again!r   z4The device id must be not less than 0, but got id = .zThe device id z exceeds xpu card number )
r   get_xpu_current_device_idr   r    r   r!   r"   
startswithr&   r   )r$   op_namer(   s      r*   extract_xpu_device_idr5   _   s    ~--//&#		FDMM	*	*((*		FC	 	 V$$F12JI%fX-Gy Q9 9 
 vh&@	 J5 5
 	

 > 
>ykK> |~% 
#<\^<LM% r,   z2.5.0zpaddle.device.synchronizez:synchronize in paddle.device.xpu will be removed in future)since	update_tolevelreasonc                   SnU b  [        U [        5      (       a  U nO[        U [        R                  5      (       a  U R	                  5       nO][        U [
        5      (       a=  U R                  S5      (       a  [        U SS 5      nO#U S:X  a  SnO[        SU  S35      e[        S	5      e[        R                  " U5      $ )
a  
Wait for the compute on the given XPU device to finish.

Parameters:
    device(paddle.XPUPlace()|int, optional): The device or the ID of the device.
    If device is None, the device is the current device. Default: None.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')
        >>> paddle.device.xpu.synchronize()
        >>> paddle.device.xpu.synchronize(0)
        >>> paddle.device.xpu.synchronize(paddle.XPUPlace(0))

r   Nr.   r/   xpur   r0   z is not expected. Because paddle.device.cuda.synchronize only support string which is like 'xpu:x' or 'xpu'. Please input appropriate string again!r   )	r   r    r   r   r!   r"   r3   r&   _xpu_device_synchronize)r$   r(   s     r*   r   r      s    4 Ifc""I..,,.I$$  ((qr
O	5	 )& 2= =  IJJ''	22r,   c                 b    [        [        S5      (       a  [        R                  " 5       n U $ Sn U $ )z
Return the number of XPUs available.

Returns:
    int: the number of XPUs available.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> paddle.device.xpu.device_count()

get_xpu_device_countr   )hasattrr   r>   )num_xpuss    r*   r   r      s=    $ 4/00 	!!#  O   Or,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[         R                  " U 5        g)a^  
Set the debug level of XPUs' api. The default level is 0, which means no debug info.

Args:
    int: Debug level of XPUs available.
        Level 0x1 for trace (Print the invocation of the interface),
        0x10 for checksum (Print the checksum of the tensor),
        0x100 for dump (Save the tensor as a file in npy format),
        0x1000 for profiling (Record the execution time of each operator).

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> paddle.device.xpu.set_debug_level(1)
z!paddle.device.xpu.set_debug_levelThe API h is only supported in XPU PaddlePaddle. Please reinstall PaddlePaddle with XPU support to call this API.N)r   is_compiled_with_xpur&   set_xpu_debug_level)r8   names     r*   r   r      sH    ( /D$$&&tf  E  F
 	
 	  'r,   c                     Sn [         R                  " 5       (       d  [        SU  S35      e[         R                  " 5         g)az  
Releases idle cached memory held by the allocator so that those can be used in other XPU
application and visible in `xpu-smi`. In most cases you don't need to use this function,
Paddle does not release the memory back to the OS when you remove Tensors on the XPU,
Because it keeps xpu memory in a pool so that next allocations can be done much faster.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> tensor = paddle.randn([512, 512, 512], "float64")
        >>> del tensor
        >>> paddle.device.xpu.empty_cache()
zpaddle.device.xpu.empty_cacherB   rC   N)r   rD   r&   xpu_empty_cache)rF   s    r*   r   r      sF    $ +D$$&&tf  E  F
 	
 	r,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " SU5      $ )ai  
Return the peak size of xpu memory that is allocated to tensor of the given device.

Note:
    The size of XPU memory allocated to tensor is 256-byte aligned in Paddle, which may larger than the memory size that tensor actually need.
    For instance, a float32 0-D Tensor with shape [] in XPU will take up 256 bytes memory, even though storing a float32 data requires only 4 bytes.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Return:
    int: The peak size of xpu memory that is allocated to tensor of the given device, in bytes.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> max_memory_allocated_size = paddle.device.xpu.max_memory_allocated(paddle.XPUPlace(0))
        >>> max_memory_allocated_size = paddle.device.xpu.max_memory_allocated(0)
        >>> max_memory_allocated_size = paddle.device.xpu.max_memory_allocated("xpu:0")
z&paddle.device.xpu.max_memory_allocatedrB   rC   r4   	Allocatedr   rD   r&   r5   device_memory_stat_peak_valuer$   rF   r(   s      r*   r   r     sW    6 4D$$&&tf  E  F
 	
 &f;I--k9EEr,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " SU5      $ )a<  
Return the peak size of XPU memory that is held by the allocator of the given device.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Return:
    int: The peak size of XPU memory that is held by the allocator of the given device, in bytes.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> max_memory_reserved_size = paddle.device.xpu.max_memory_reserved(paddle.XPUPlace(0))
        >>> max_memory_reserved_size = paddle.device.xpu.max_memory_reserved(0)
        >>> max_memory_reserved_size = paddle.device.xpu.max_memory_reserved("xpu:0")
z%paddle.device.xpu.max_memory_reservedrB   rC   rJ   ReservedrL   rN   s      r*   r   r   0  sW    . 3D$$&&tf  E  F
 	
 &f;I--j)DDr,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " SU5        g)a  
Reset the peak size of XPU memory that is allocated to tensor of the given device.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> paddle.device.xpu.reset_max_memory_allocated(paddle.XPUPlace(0))
        >>> paddle.device.xpu.reset_max_memory_allocated(0)
        >>> paddle.device.xpu.reset_max_memory_allocated("xpu:0")
z,paddle.device.xpu.reset_max_memory_allocatedrB   rC   rJ   rK   Nr   rD   r&   r5   #device_memory_stat_reset_peak_valuerN   s      r*   r   r   P  sT    * :D$$&&tf  E  F
 	
 &f;I,,[)Dr,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " SU5        g)a  
Reset the peak size of XPU memory that is held by the allocator of the given device.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> paddle.device.xpu.reset_max_memory_reserved(paddle.XPUPlace(0))
        >>> paddle.device.xpu.reset_max_memory_reserved(0)
        >>> paddle.device.xpu.reset_max_memory_reserved("xpu:0")
z+paddle.device.xpu.reset_max_memory_reservedrB   rC   rJ   rP   NrR   rN   s      r*   r   r   n  sT    * 9D$$&&tf  E  F
 	
 &f;I,,ZCr,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " SU5      $ )aZ  
Return the current size of xpu memory that is allocated to tensor of the given device.

Note:
    The size of XPU memory allocated to tensor is 256-byte aligned in Paddle, which may be larger than the memory size that tensor actually need.
    For instance, a float32 0-D Tensor with shape [] in XPU will take up 256 bytes memory, even though storing a float32 data requires only 4 bytes.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Return:
    int: The current size of xpu memory that is allocated to tensor of the given device, in bytes.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> memory_allocated_size = paddle.device.xpu.memory_allocated(paddle.XPUPlace(0))
        >>> memory_allocated_size = paddle.device.xpu.memory_allocated(0)
        >>> memory_allocated_size = paddle.device.xpu.memory_allocated("xpu:0")
z"paddle.device.xpu.memory_allocatedrB   rC   rJ   rK   r   rD   r&   r5    device_memory_stat_current_valuerN   s      r*   r   r     sW    6 0D$$&&tf  E  F
 	
 &f;I00iHHr,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " SU5      $ )a*  
Return the current size of XPU memory that is held by the allocator of the given device.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Return:
    int: The current size of XPU memory that is held by the allocator of the given device, in bytes.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> memory_reserved_size = paddle.device.xpu.memory_reserved(paddle.XPUPlace(0))
        >>> memory_reserved_size = paddle.device.xpu.memory_reserved(0)
        >>> memory_reserved_size = paddle.device.xpu.memory_reserved("xpu:0")
z!paddle.device.xpu.memory_reservedrB   rC   rJ   rP   rV   rN   s      r*   r   r     sW    . /D$$&&tf  E  F
 	
 &f;I00YGGr,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " U5      $ )a  
Return the total size of XPU memory of the given device that is held by the XPU Runtime.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Return:
    int: The total size of XPU memory of the given device that is held by the XPU Runtime, in bytes.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> memory_total_size = paddle.device.xpu.memory_total(paddle.XPUPlace(0))
        >>> memory_total_size = paddle.device.xpu.memory_total(0)
        >>> memory_total_size = paddle.device.xpu.memory_total("xpu:0")
zpaddle.device.xpu.memory_totalrB   rC   rJ   )r   rD   r&   r5   get_xpu_device_total_memoryrN   s      r*   r   r     sU    . ,D$$&&tf  E  F
 	
 &f;I++I66r,   c                    Sn[         R                  " 5       (       d  [        SU S35      e[        XS9n[         R                  " U5      $ )a  
Return the used size of XPU memory of the given device that is held by the XPU Runtime.

Args:
    device(paddle.XPUPlace|int|str|None, optional): The device, the id of the device or
        the string name of device like 'xpu:x'. If device is None, the device is the current device.
        Default: None.

Return:
    int: The used size of XPU memory of the given device that is held by the XPU Runtime, in bytes.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.set_device('xpu')

        >>> memory_used_size = paddle.device.xpu.memory_used(paddle.XPUPlace(0))
        >>> memory_used_size = paddle.device.xpu.memory_used(0)
        >>> memory_used_size = paddle.device.xpu.memory_used("xpu:0")
zpaddle.device.xpu.memory_usedrB   rC   rJ   )r   rD   r&   r5   get_xpu_device_used_memoryrN   s      r*   r   r     sU    . +D$$&&tf  E  F
 	
 &f;I**955r,   c                (   [         R                  R                  U 5      n[        U[        R
                  5      (       a#  [        R                  " 5       R                  5       $ [        R                  " UR                  5       5      R                  5       $ )z
Get the random state for the default generator.

Returns:
    Tensor: The random state tensor.

Examples:

    .. code-block:: python

        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.get_rng_state()

)
r#   r$   device_to_placer   r   CPUPlacedefault_cpu_generator	get_statedefault_xpu_generatorr!   )r$   r)   s     r*   get_rng_staterc     sd      MM))&1E%''))+5577%%e&9&9&;<FFHHr,   c                0   [         R                  R                  U5      n[        U[        R
                  5      (       a%  [        R                  " 5       R                  U 5        g[        R                  " UR                  5       5      R                  U 5        g)a&  
Set the random number generator state of the specified device.

Args:
    new_state (core.GeneratorState): The desired RNG state to set.
        This should be a state object previously obtained from ``get_rng_state()``.
    device (DeviceLike, optional): The device to set the RNG state for.
        If not specified, uses the current default device (as returned by ``paddle.framework._current_expected_place_()``).
        Can be a device object, integer device ID, or device string.

Returns:
    None

Examples:
    .. code-block:: python

        >>> import paddle
        >>> # Save RNG state
        >>> state = paddle.device.get_rng_state()
        >>> # Do some random operations
        >>> x = paddle.randn([2, 3])
        >>> # Restore RNG state
        >>> paddle.device.set_rng_state(state)
N)
r#   r$   r^   r   r   r_   r`   	set_staterb   r!   )	new_stater$   r)   s      r*   set_rng_staterg   &  sb    6 MM))&1E%''""$..y9""5#6#6#89CCINr,   c                D   [        U 5      n [        R                  R                  5       n[	        U[
        R                  5      (       a%  [
        R                  " 5       R                  U 5        g[
        R                  " UR                  5       5      R                  U 5        g)a  Set the seed for generating random numbers for the current Device.

.. warning::
    If you are working with a multi-Device model, this function is insufficient
    to get determinism.  To seed all Devices, use :func:`manual_seed_all`.
    If current Device is CPU, this function will set the seed of the default CPU generator.

Sets the seed for global default generator, which manages the random number generation.

Args:
    seed(int): The random seed to set.

Returns:
    None

Examples:
    .. code-block:: python
        >>> # doctest: +REQUIRES(env:XPU)
        >>> import paddle
        >>> paddle.device.manual_seed(102)
        >>> # paddle.cuda.manual_seed(102) is equivalent to paddle.device.manual_seed(102)
        >>> paddle.cuda.manual_seed(102)

N)r    r#   	framework_current_expected_place_r   r   r_   r`   manual_seedrb   r!   )seedr)   s     r*   rk   rk   H  sk    2 t9D557E%''""$006""5#6#6#89EEdKr,   )N)r$   _XPUPlaceLike | Nonereturnzcore.XPUStream)r$   r   r4   r"   rn   r    )r$   rm   rn   r    )rn   r    )r   )r8   r    rn   None)rn   ro   )r$   rm   rn   ro   )r$   rm   rn   core.GeneratorState)rf   rp   r$   rm   rn   ro   )rl   r    rn   ro   )(
__future__r   typingr   r   typing_extensionsr   r#   paddle.baser   paddle.utilsr   streamsr
   r   r   r   r   r"   r    r   __annotations____all__r+   r5   r   r   r   r   r   r   r   r   r   r   r   r   rc   rg   rk    r,   r*   <module>rz      s    # ' '   # ? ?$	 M9 $'3T'T 
)
G	)3)3X2(:6!FHE@E<D<!IHH@7@6@I. DHO"O,@O	ODLr,   