
    xKg+                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	  edddg      Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)    N)
namedtupleIS_WIN32)find_lib	find_file_env_path_tuplebyinfoc                 (    | D ]  \  }}|	||fc S  y)zFind valid path from *options*, which is a list of 2-tuple of
    (name, path).  Return first pair where *path* is not None.
    If no valid path is found, return ('<unknown>', None)
    )z	<unknown>N )optionsr	   datas      Y/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/cuda/cuda_paths.py_find_valid_pathr      s&    
 Dt8O  !    c                      dt               fdt               fdt        dd      fdt        dd      fdt	               fg} t        |       \  }}||fS )NConda environment"Conda environment (NVIDIA package)	CUDA_HOMEnvvm	libdeviceSystemzDebian package)get_conda_ctkget_nvidia_libdevice_ctkget_cuda_homeget_system_ctkget_debian_pkg_libdevicer   r   r	   libdirs      r   _get_libdevice_path_decisionr       sc    	mo.	-/G/IJ	mFK89	>&+67	356G "'*JBv:r   c                      t         ryy)N)r   bin)r   lib64r   r   r   r   _nvvm_lib_dirr$   %   s    r   c                      dt               fdt               fdt        t                fdt	        t                fg} t        |       \  }}||fS Nr   r   r   r   )r   get_nvidia_nvvm_ctkr   r$   r   r   )r   r	   paths      r   _get_nvvm_path_decisionr)   ,   sV    	mo.	-/B/DE	m]_56	>=?34	G  (HBt8Or   c                      t               \  } }d}t        t        j                  |      |      }t	        |d       }t        | |      S )Nzlibdevice(\.\d+)*\.bc$)default)r    r   recompilemaxr   )r	   r   pat
candidatesouts        r   _get_libdevice_pathsr2   7   s@    -/JB
#C2::c?F3J
j$
'C2s##r   c                      t         ryy)Nr"   r#   r   r   r   r   _cudalib_pathr4   A   s    r   c                      t         ryy)N)libx64)r#   r   r   r   r   _cuda_home_static_cudalib_pathr8   H   s    r   c                      dt               fdt               fdt        t                     fdt	        t                     fg} t        |       \  }}||fS r&   )r   get_nvidia_cudalib_ctkr   r4   r   r   r   s      r   _get_cudalib_dir_path_decisionr;   O   sW    	mo.	-/E/GH	mMO45	>-/23	G "'*JBv:r   c                      dt               fdt               fdt        t                fdt	        t                     fg} t        |       \  }}||fS r&   )r   get_nvidia_static_cudalib_ctkr   r8   r   r4   r   r   s      r   %_get_static_cudalib_dir_path_decisionr>   Z   sY    	mo.	-/L/NO	m%C%EFG	>-/23	G "'*JBv:r   c                  4    t               \  } }t        | |      S N)r;   r   r	   r   s     r   _get_cudalib_dirrB   e   s    /1JB2v&&r   c                  4    t               \  } }t        | |      S r@   )r>   r   rA   s     r   _get_static_cudalib_dirrD   j   s    68JB2v&&r   c                      t         j                  j                  d      rBd}t        j                  j                  |      r t        j                  j                  |g|  S yy)zJReturn path to system-wide cudatoolkit; or, None if it doesn't exist.
    linuxz/usr/local/cudaN)sysplatform
startswithosr(   existsjoin)subdirsbases     r   r   r   o   sO     ||w' !77>>$77<</w//  	 (r   c                  
   t         j                  j                  t         j                  j                  t        j
                  d            } | syt        d      }|syt         j                  j                  t        |            S )MReturn path to directory containing the shared libraries of cudatoolkit.
    
conda-metaNr   )	rJ   r(   rK   rL   rG   prefixr   dirnamer.   )is_conda_envpathss     r   r   r   {   sV     77>>"'',,szz<"HILVE77??3u:&&r   c                     t         j                  j                  t         j                  j                  t        j
                  d            } | syt         j                  j                  t        j
                  dt                     }t         j                  j                  |      rt         j                  j                  |      swt         j                  j                  t        j
                  ddt                     }t         j                  j                  |      rt         j                  j                  |      syt        d|      }|syt         j                  j                  t        |            S )zAReturn path to directory containing the NVVM shared library.
    rQ   Nr   Library)r   )rJ   r(   rK   rL   rG   rR   r4   isdirr   rS   r.   )rT   r   rU   s      r   r'   r'      s     77>>"'',,szz<"HIL WW\\#**fmo>F77>>&!v)>cjj)V]_Mww~~f%RWW]]6-B VF+E77??3u:&&r   c                      t               } | syt        j                  j                  |       }t        j                  j	                  |d      S )z?Return path to directory containing the libdevice library.
    Nr   )r'   rJ   r(   rS   rL   )nvvm_ctknvvm_dirs     r   r   r      s9     #$Hwwx(H77<<+..r   c                      t               } | syt        j                  j                  t        j                  j                  |             }t        rdnd}t        j                  j                  ||      S )rP   Nr"   r6   )r'   rJ   r(   rS   r   rL   )rZ   env_dirsubdirs      r   r:   r:      sO     #$Hggoobggooh78GUEF77<<((r   c                      t               } | syt        rd| vrd}nd}t        j                  j	                  t        j                  j	                  |             }t        j                  j
                  |g| S )zMReturn path to directory containing the static libraries of cudatoolkit.
    NrW   )Libr7   )r6   )r'   r   rJ   r(   rS   rL   )rZ   dirsr]   s      r   r=   r=      s_     #$HYh. ggoobggooh78G77<<'$''r   c                      t         j                  j                  d      }|t         j                  j                  d      }| t        j                  j                  |g|  S y)zqGet paths of CUDA_HOME.
    If *subdirs* are the subdirectory name to be appended in the resulting
    path.
    r   N	CUDA_PATH)rJ   environgetr(   rL   )rM   	cuda_homes     r   r   r      sQ    
 

{+IJJNN;/	ww||I000 r   c                  j    t               \  } }t        d|      }|rt        |      nd }t        | |      S )Nr   )r)   r   r.   r   )r	   r(   r0   s      r   _get_nvvm_pathrh      s4    &(HB&$'J(3z?dD2t$$r   c                      t        t        d      rt        j                  S t               t	               t               t               d} | t        _        | S )a@  Returns a dictionary mapping component names to a 2-tuple
    of (source_variable, info).

    The returned dictionary will have the following keys and infos:
    - "nvvm": file_path
    - "libdevice": List[Tuple[arch, file_path]]
    - "cudalib_dir": directory_path

    Note: The result of the function is cached.
    _cached_result)r   r   cudalib_dirstatic_cudalib_dir)hasattrget_cuda_pathsrj   rh   r2   rB   rD   )ds    r   rn   rn      sK     ~/0,,, #$-/+-"9";	
 )*%r   c                  J    d} t         j                  j                  |       sy| S )z]
    Return the Debian NVIDIA Maintainers-packaged libdevice location, if it
    exists.
    z&/usr/lib/nvidia-cuda-toolkit/libdeviceN)rJ   r(   rK   )pkg_libdevice_locations    r   r   r      s%    
 F77>>01!!r   ) rG   r,   rJ   collectionsr   numba.core.configr   numba.misc.findlibr   r   r   r   r    r$   r)   r2   r4   r8   r;   r>   rB   rD   r   r   r'   r   r:   r=   r   rh   rn   r   r   r   r   <module>ru      s    
 	 	 " & 2 .v?	!	$'
'
	0''6/)($
1%6"r   