
    shu                         S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	J
r
  SSKJr  \R                  S:X  a  SrS	rO\R                  S
:X  a  SrSrOSrSrS rS rSS jrS rS rSS jrS rg)a  CUDA Toolkit libraries lookup utilities.

CUDA Toolkit libraries can be available via either:

- the `cuda-nvcc` and `cuda-nvrtc` conda packages for CUDA 12,
- the `cudatoolkit` conda package for CUDA 11,
- a user supplied location from CUDA_HOME,
- a system wide location,
- package-specific locations (e.g. the Debian NVIDIA packages),
- or can be discovered by the system loader.
    N)find_lib)get_cuda_paths)locate_driver_and_loaderload_driver)CudaSupportErrorwin32z%s.dllz%s.libdarwinzlib%s.dylibzlib%s.azlib%s.soc                  8    [        5       n U S   R                  nU$ )N	libdevice)r   info)dpathss     k/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/cuda/cudadrv/libs.pyget_libdevicer   "   s    AkNEL    c                      [        [        5       S5       n U R                  5       sS S S 5        $ ! , (       d  f       g = f)Nrb)openr   read)bcfiles    r   open_libdevicer   (   s%    	mot	${{} 
%	$	$s   /
=c                    U S:X  a'  [        5       S   R                  =(       d	    [        S-  $ U(       a  SOSn[        5       U   R                  n[        XUS9nU(       a  [        O[        nU(       a  [        U5      $ XP-  $ )z
Find the path of a CUDA library based on a search of known locations. If
the search fails, return a generic filename for the library (e.g.
'libnvvm.so' for 'nvvm') so that we may attempt to load it using the system
loader's search mechanism.
nvvmstatic_cudalib_dircudalib_dirstatic)r   r   _dllnamepatternr   _staticnamepatternmax)libr   dir_typelibdir
candidatesnamepatterns         r   get_cudalibr&   -   sp     f}',,H&0HH+1'}!(+00#f5J(.$OK(3z??k.??r   c                 D    [        U 5      n[        R                  " U5      $ )N)r&   ctypesCDLL)r!   paths     r   open_cudalibr+   ?   s    sD;;tr   c                 h    [         R                  R                  U 5      (       d  [        U  S35      eg )Nz
 not found)osr*   isfileFileNotFoundError)r*   s    r   check_static_libr0   D   s,    77>>$4&
 344  r   c                     U S:X  a  [        5       S   R                  $ U S:X  a  [        5       S   R                  $ U(       a  SOSn[        5       U   R                  $ )Nr   r   r   r   )r   by)r!   r   r"   s      r   _get_source_variabler3   I   sW    
f}'***		,///+1'}),,,r   c            
         Sn  [        5       u  p[        S5        U H  n[        SU 35        M     [        SU 35        [        SSS9  [        X5      u  pE[        S5        [        S	U 35        [        R
                  S:X  a  U (       d  [        R                  " 5       n[        R                  R                  [        R                  R                  SU S5      n [        U5       n	U	R                  5       n
SSS5        [        S W
R                  5        5       5      n[        S5        U H  n[        SU 35        M     SR                  5       nU H_  n[!        U5      n[        SR#                  U[%        U5      5      5        [        SU5         [        SSS9  ['        U5        [        S5        Ma     Sn[!        USS9n[        SR#                  U[%        USS95      5        [        SU5         [        SSS9  [)        U5        [        S5        [%        S5      n[        S U 35        [-        5       n[        SU5         [        SSS9  [)        U5        [        S5        U (       + $ ! [         a  n[        S
U 35        Sn  SnAGNSnAff = f! , (       d  f       GN= f! [         a    [        SU S35         GN~f = f! [         a!  n[        SU< SU< 35        Sn  SnAGM  SnAff = f! [*         a   n[        SU< SU< 35        Sn  SnAGNSnAff = f! [*         a%  n[        SU< SU< 35        Sn  SnAU (       + $ SnAff = f)!z:Test library lookup.  Path info is printed to stdout.
    FzFinding driver from candidates:	zUsing loader z	Trying to load driverz...)endz	okz		Loaded from z	ERROR: failed to open driver: TNlinuxprocmapsc              3   6   #    U  H  nS U;   d  M  Uv   M     g7f)z
libcuda.soN ).0ss     r   	<genexpr>test.<locals>.<genexpr>   s     I|!|q7HAA|s   
	z	Mapped libcuda.so paths:z		z	ERROR: Could not open z) to determine absolute path to libcuda.soznvvm nvrtc cudartzFinding {} from {}z	Located atz	Trying to open libraryz	ERROR: failed to open z:
	cudadevrtr   z	Checking libraryz	ERROR: failed to find r   zFinding libdevice from )r   printr   r   sysplatformr-   getpidr*   joinsepr   r   setsplitOSErrorr&   formatr3   r+   r0   r/   r   )faileddlloaderr$   locationdllr*   epidmapsfilefr9   	locationslibsr!   wheres                  r   testrV   S   s    F79/0"HBxj/" #hZ()'U35	f '( ||wviik77<<VuvF	)h1vvx   Itzz|III./%XJ'( & $$&D3"))#/CC/HIJnd#	,%8&M  Cs4(D	

%
%c+?GK,M N O	.$".f !-E	#E7
+,?D	.$".f
 :[  045  
  	( ,XJ 7' ' (		(2  	sA>?F	  3:;  3:;:	s   A,I* J$ 'J8J$  K3 K2  L *
J4J

J
J!J$ $K K
K/K**K/2
L<LL
M)M		M)F)__doc__r-   rB   r(   numba.misc.findlibr   numba.cuda.cuda_pathsr   numba.cuda.cudadrv.driverr   r   numba.cuda.cudadrv.errorr   rC   r   r   r   r   r&   r+   r0   r3   rV   r;   r   r   <module>r\      s   
 
 
  ' 0 K 5 <<7O!\\X#O" O"
@$
5
-]r   