o
    پi                     @   s   d dl Z d dlmZ zddlmZ W n ey& Z zeZW Y dZ[ndZ[ww dZedZ		dde
de
de
d	eeef fd
dZdde
d	e
fddZdS )    N)ExternalStream   )spatial_opszKFailed to load sgl_kernel.spatial_ops extension. Ensure CUDA Driver >= 12.4SM_aSM_b	device_idreturnc                 C   sr   t durtt |du rtj }tjj| ||}t|d t	d| d}t|d t	d| d}||fS )z
    Create two streams for greenctx.
    Args:
        sm_A (int): The SM of stream A.
        sm_B (int): The weight of stream B.
        device_id (int): The device id.
    Returns:
        tuple[ExternalStream, ExternalStream]: The two streams.
    Nr   zcuda:)
stream_ptrdevicer   )
_spatial_import_error_IMPORT_ERRORtorchcudacurrent_deviceops
sgl_kernelcreate_greenctx_stream_by_valuer   r
   )r   r   r   resstream_astream_b r   F/home/ubuntu/.local/lib/python3.10/site-packages/sgl_kernel/spatial.pyr      s   
r   c                 C   s6   t durtt | du rtj } tj| }|j}|S )z
    Get the SMs available on the device.
    Args:
        device_id (int): The device id.
    Returns:
        int: The SMs available.
    N)r   r   r   r   r   get_device_propertiesmulti_processor_count)r   device_propssm_countr   r   r   get_sm_available-   s   
r   )N)r   torch.cuda.streamsr    r   	Exception_er   ImportErrorr   inttupler   r   r   r   r   r   <module>   s.    

