
    )`i
                     N    d Z ddlmZmZ ddlmZmZ ddlZ G d de          ZdS )a3  
Copyright (c) 2025 by FlashInfer team.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    )ABCabstractmethod)OptionalAnyNc                       e Zd ZU dZeed<   eed<   eed<   dedefdZee	de
fd                        Ze	dd	            Ze		 dd
edededej        dee         defd            Zd ZdS )AllReduceFusionWorkspacez+Base class for AllReduce fusion workspaces.
world_sizerank
_destroyedc                 0    || _         || _        d| _        d S )NF)r	   r
   r   )selfr	   r
   s      r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/flashinfer/comm/workspace_base.py__init__z!AllReduceFusionWorkspace.__init__   s    $	    returnc                     dS )zReturn backend name.N r   s    r   backendz AllReduceFusionWorkspace.backend$   s	     	r   Nc                     dS )z
        Destroy workspace and free resources.

        This should be called explicitly when done using the workspace.
        Prefer using AllReduceFusionContext context manager for automatic cleanup.
        Nr   r   s    r   destroyz AllReduceFusionWorkspace.destroy*   s	     	r   tp_size
num_tokens
hidden_dimdtypeuse_oneshotc                     d S Nr   )r   r   r   r   r   r   s         r   is_buffer_size_sufficientz2AllReduceFusionWorkspace.is_buffer_size_sufficient4   s	     	r   c                 (   | j         sddl}|                    | j        j         dt
          d           	 |                                  dS # t          $ r8}|                    d| j        j         d| t
          d           Y d}~dS d}~ww xY wdS )a  
        Destructor - safety net if destroy() wasn't called explicitly.

        Warns if cleanup wasn't done properly. Not recommended to rely on this
        as __del__ timing is non-deterministic and can cause issues with
        distributed/CUDA resources.
        r   Nz was not explicitly destroyed. Call workspace.destroy() or use AllReduceFusionContext to ensure proper cleanup of distributed/CUDA resources.   )
stacklevelz"Error during automatic cleanup of z: )r   warningswarn	__class____name__ResourceWarningr   	Exception)r   r#   es      r   __del__z AllReduceFusionWorkspace.__del__?   s      	OOOMM>* A A A         W9PWWTUWW#           	 	s   A 
B-B

B)r   Nr   )r&   
__module____qualname____doc__int__annotations__boolr   propertyr   strr   r   torchr   r   r   r   r*   r   r   r   r   r      s(        55 OOO
III 3  c        
     ^ X    ^  &*   	
 { c] 
   ^    r   r   )	r-   abcr   r   typingr   r   r3   r   r   r   r   <module>r6      s      $ # # # # # # #                 B B B B Bs B B B B Br   