
    )`i]                     L   U d Z ddlZddlZddlmZ ddlmZ defdZ	defdZ
 ej         ej        d	ej                                                                                            Zej        ed
<   edz  dz  Zej        ed<    ej        e                                          j        d         Zej        ed<   d Z e            Zej        ed<   d Z e            Zej        ed<   dej        fdZ e            Zej        ed<   edz  Zej        ed<   edz  Zej        ed<   edz  Zej        ed<   edz  dz  Zej        ed<   edz  dz  Z ej        ed<   edz  d z  dz  edz  d z  d!z  d"z  dz  gZ!e"ej                 ed#<   edz  d$z  dz  Z#ej        ed%<   d& Z$d' Z%dS )(a3  
Copyright (c) 2024 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.
    N   )CompilationContext)__version__returnc                  B    ddl } | j                            d          duS )z
    Check if flashinfer_jit_cache module is available.

    Returns:
        True if flashinfer_jit_cache exists, False otherwise
    r   Nflashinfer_jit_cacheimportlib.utilutil	find_spec	importlibs    f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/flashinfer/jit/env.pyhas_flashinfer_jit_cacher      s,     >##$:;;4GG    c                  B    ddl } | j                            d          duS )z
    Check if flashinfer_cubin module is available.

    Returns:
        True if flashinfer_cubin exists, False otherwise
    r   Nflashinfer_cubinr	   r   s    r   has_flashinfer_cubinr   '   s,     >##$677tCCr   FLASHINFER_WORKSPACE_BASEFLASHINFER_BASE_DIRz.cache
flashinferFLASHINFER_CACHE_DIR   _package_rootc                  \   t                      rkddl} | j        }t          j        d          s&t
          |k    rt          d| dt
           d          t          j        | 	                                          S t          j        d          }|rt          j        |          S t          dz  S )	z
    Get the cubin directory path with the following priority:
    1. flashinfer-cubin package if installed
    2. Environment variable FLASHINFER_CUBIN_DIR
    3. Default cache directory
    r   N FLASHINFER_DISABLE_VERSION_CHECKzflashinfer-cubin version (%) does not match flashinfer version (q). Please install the same version of both packages. Set FLASHINFER_DISABLE_VERSION_CHECK=1 to bypass this check.FLASHINFER_CUBIN_DIRcubins)r   r   r   osgetenvflashinfer_versionRuntimeErrorpathlibPathget_cubin_dirr   )r   flashinfer_cubin_versionenv_dirs      r   _get_cubin_dirr*   ;   s      >#3#?  	<==		"&>>>O-E O O'9O O O   |,::<<=== i.//G %|G$$$  (**r   r   c                  ,   t                      rzddl} | j        }t          j        d          s5|                    t                    st          d| dt           d          t          j	        | 
                                          S t          dz  dz  S )	z
    Get the AOT directory path with the following priority:
    1. flashinfer-jit-cache package if installed
    2. Default fallback to _package_root / "data" / "aot"
    r   Nr   zflashinfer-jit-cache version (r   r   dataaot)r   r   r   r!   r"   
startswithr#   r$   r%   r&   get_jit_cache_dirr   )r   flashinfer_jit_cache_versions     r   _get_aot_dirr1   a   s      !! F####';'G$ y.
 
 	.99:LMM	 O1M O O'9O O O   |0BBDDEEE 6!E))r   FLASHINFER_AOT_DIRc                      t                      } d                    d t          | j                  D                       }t          t
          z  |z  S )N_c              3   (   K   | ]\  }}| | V  d S )N ).0majorminors      r   	<genexpr>z*_get_workspace_dir_name.<locals>.<genexpr>   sE        E5 %     r   )r   joinsortedTARGET_CUDA_ARCHSr   r#   )compilation_contextarchs     r   _get_workspace_dir_namer@      s^    ,.. 88  "#6#HII    D  "44t;;r   FLASHINFER_WORKSPACE_DIR
cached_opsFLASHINFER_JIT_DIR	generatedFLASHINFER_GEN_SRC_DIRr,   FLASHINFER_DATAincludeFLASHINFER_INCLUDE_DIRcsrcFLASHINFER_CSRC_DIRcutlasstoolsr   CUTLASS_INCLUDE_DIRSspdlogSPDLOG_INCLUDE_DIRc                      t           j                            d          } | )d |                     t           j                  D             S dd l}t          j        |j        j	        d                   dz  }|gS )NNVSHMEM_INCLUDE_PATHc                 :    g | ]}|t          j        |          S r6   r%   r&   r7   ps     r   
<listcomp>z,get_nvshmem_include_dirs.<locals>.<listcomp>   %    FFFAAFQFFFr   r   rG   
r!   environgetsplitpathsepnvidia.nvshmemr%   r&   nvshmem__path__pathsnvidiapaths      r   get_nvshmem_include_dirsrd      so    JNN122EFFRZ)@)@FFFF</233i?D6Mr   c                      t           j                            d          } | )d |                     t           j                  D             S dd l}t          j        |j        j	        d                   dz  }|gS )NNVSHMEM_LIBRARY_PATHc                 :    g | ]}|t          j        |          S r6   rS   rT   s     r   rV   z(get_nvshmem_lib_dirs.<locals>.<listcomp>   rW   r   r   librX   r`   s      r   get_nvshmem_lib_dirsri      so    JNN122EFFRZ)@)@FFFF</233e;D6Mr   )&__doc__r!   r%   r>   r   versionr   r#   boolr   r   r&   r"   homeas_posixr   __annotations__r   __file__resolveparentsr   r*   r   r1   r2   r@   rA   rC   rE   rF   rH   rJ   rM   listrO   rd   ri   r6   r   r   <module>rt      s    ( 
			  4 4 4 4 4 4 7 7 7 7 7 7	H$ 	H 	H 	H 	H	Dd 	D 	D 	D 	D %1GLBI)7<+<+<+>+>+G+G+I+IJJ% % W\    &98%Cl%R gl R R R*gl844<<>>FqIw| I I I +  +  +F &4^%5%5 gl 5 5 5* * *< $0<>> GL 1 1 1	< 	< 	< 	< 	< *A)@)B)B ', B B B#;l#J GL J J J'?+'M  M M M - 6 6 6 6'4v'=	'I  I I I$1F$:V$C W\ C C C FY&2FY&069IE, d7<(    $16#9H#Dy#P GL P P P      r   