
    sh                         S r SSKrSSKrSSKrSSKJr  SSKJrJr  SSK	J
r
Jr  SSKJr  SSKJr  SSKJr   " S	 S
\5      r " S S5      r\" 5       rS rg)z
CUDA Runtime wrapper.

This provides a very minimal set of bindings, since the Runtime API is not
really used in Numba except for querying the Runtime version.
    N)config)	ERROR_MAPmake_logger)CudaSupportErrorCudaRuntimeError)open_cudalib)API_PROTOTYPES)enumsc                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )CudaRuntimeAPIError   zH
Raised when there is an error accessing a C API from the CUDA Runtime.
c                 <   > Xl         X l        [        TU ]  X5        g )N)codemsgsuper__init__)selfr   r   	__class__s      n/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/cuda/cudadrv/runtime.pyr   CudaRuntimeAPIError.__init__   s    	#    c                 >    SU R                   < SU R                  < 3$ )N[z] r   r   r   s    r   __str__CudaRuntimeAPIError.__str__   s     IItxx00r   r   )	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classcell__)r   s   @r   r   r      s    $
1 1r   r   c                   X    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 r\S 5       rSrg)Runtime!   z9
Runtime object that lazily binds runtime API functions.
c                     SU l         g )NF)is_initializedr   s    r   r   Runtime.__init__&   s
    #r   c                     [        5       q[        R                  (       a  Sn[	        U5      e[        S5      U l        SU l        g )NzzCUDA is disabled due to setting NUMBA_DISABLE_CUDA=1 in the environment, or because CUDA is unsupported on 32-bit systems.cudartT)r   _loggerr   DISABLE_CUDAr   r   libr)   )r   r   s     r   _initializeRuntime._initialize)   s<     -%C #3'')"r   c                     [         U   nUS   nUSS  nU R                  (       d  U R	                  5         U R                  U5      nX5l        XEl        U R                  X5      n[        XU5        U$ ! [         a    [        U5      ef = f)Nr      )
r	   KeyErrorAttributeErrorr)   r0   	_find_apirestypeargtypes_wrap_api_callsetattr)r   fnameprotor7   r8   libfn	safe_calls          r   __getattr__Runtime.__getattr__7   s    	("5)E (9"" u%!''5	Y'  	( ''	(s   	A2 2Bc                 N   ^ ^^ [         R                  " T5      UUU 4S j5       nU$ )Nc                  t   > [         R                  STR                  5        T" U 6 nTR                  TU5        g )Nzcall runtime api: %s)r-   debugr   _check_error)argsretcoder;   r=   r   s     r   safe_cuda_api_call2Runtime._wrap_api_call.<locals>.safe_cuda_api_callM   s/    MM0%..ATlGeW-r   )	functoolswraps)r   r;   r=   rG   s   ``` r   r9   Runtime._wrap_api_callL   s&    			. 
 	. "!r   c                     U[         R                  :w  aA  [        R                  " US5      nSU< SU< 3n[        R                  U5        [        X$5      eg )NcudaErrorUnknownzCall to z results in )r
   CUDA_SUCCESSr   getr-   errorr   )r   r;   rF   errnamer   s        r   rD   Runtime._check_errorT   sG    e(((mmG-?@G05w?CMM#%g33	 )r   c                 |   ^  [        U R                  T5      $ ! [         a     Of = fU4S jn[        U TU5        U$ )Nc                  $   > Sn[        UT-  5      e)Nzruntime missing function: %s.)r   )rE   kwsr   r;   s      r   absent_function*Runtime._find_api.<locals>.absent_functionc   s    1C"3;//r   )getattrr/   r5   r:   )r   r;   rV   s    ` r   r6   Runtime._find_api[   sD    	488U++ 		
	0 	e_-s    
&&c                     [         R                  " 5       nU R                  [         R                  " U5      5        UR                  S-  nUR                  US-  -
  S-  nX#4$ )z=
Returns the CUDA Runtime version as a tuple (major, minor).
i  
   )ctypesc_intcudaRuntimeGetVersionbyrefvalue)r   rtvermajorminors       r   get_versionRuntime.get_versionj   sS     ""6<<#67t#-"4~r   c                 <    U R                  5       U R                  ;   $ )z:
Returns True if the CUDA Runtime is a supported version.
)rd   supported_versionsr   s    r   is_supported_versionRuntime.is_supported_versionu   s    
 !T%<%<<<r   c                 V    [         R                  S;  d  [        R                  S:w  a  gg)zrA tuple of all supported CUDA toolkit versions. Versions are given in
the form ``(major_version, minor_version)``.)linuxwin32@    ))   r   )ro   r3   )ro      )ro      )ro      )ro      )ro      )ro      )sysplatformr   MACHINE_BITSr   s    r   rg   Runtime.supported_versions|   s&     <<11V5H5HB5Nr   )r)   r/   N)r   r   r    r!   r"   r   r0   r?   r9   rD   r6   rd   rh   propertyrg   r#   rn   r   r   r&   r&   !   sC    $#*"4	=  r   r&   c                  *    [         R                  5       $ )z9
Return the runtime version as a tuple of (major, minor)
)runtimerd   rn   r   r   rd   rd      s       r   )r"   r\   rI   rv   
numba.corer   numba.cuda.cudadrv.driverr   r   numba.cuda.cudadrv.errorr   r   numba.cuda.cudadrv.libsr   numba.cuda.cudadrv.rtapir	   numba.cuda.cudadrvr
   r   r&   r|   rd   rn   r   r   <module>r      sO      
  < G 0 3 $
1* 
1c cL )!r   