o
    ְi                     @   sR   d dl Z d dlZd dlZe ZG dd deZdd Zdd Ze j	dd	 Z
dS )
    Nc                       s"   e Zd ZdZd fdd	Z  ZS )DeviceSynchronizedzRaised when device synchronization is detected while disallowed.

    .. warning::

       This API has been deprecated in CuPy v10 and will be removed in future
       releases.

    .. seealso:: :func:`cupyx.allow_synchronize`

    Nc                    s   |d u rd}t  | d S )Nz5Device synchronization was detected while disallowed.)super__init__)selfmessage	__class__ I/home/ubuntu/.local/lib/python3.10/site-packages/cupy/_core/syncdetect.pyr      s   zDeviceSynchronized.__init__N)__name__
__module____qualname____doc__r   __classcell__r	   r	   r   r
   r   	   s    r   c                   C   s$   zt jW S  ty   dt _Y dS w )NT)_thread_localallowedAttributeErrorr	   r	   r	   r
   _is_allowed   s   r   c                   C   s   t  st d S r   )r   r   r	   r	   r	   r
   _declare_synchronize$   s   r   c                 c   s4    t d t }| t_z	dV  W |t_dS |t_w )a  Allows or disallows device synchronization temporarily in the current thread.

    .. warning::

       This API has been deprecated in CuPy v10 and will be removed in future
       releases.

    If device synchronization is detected, :class:`cupyx.DeviceSynchronized`
    will be raised.

    Note that there can be false negatives and positives.
    Device synchronization outside CuPy will not be detected.
    zucupyx.allow_synchronize will be removed in future releases as it is not possible to reliably detect synchronizations.N)warningswarnr   r   r   )allowoldr	   r	   r
   allow_synchronize+   s   r   )
contextlib	threadingr   localr   RuntimeErrorr   r   r   contextmanagerr   r	   r	   r	   r
   <module>   s    	