
    wg                         d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZ  G d	 d
e      Z G d d      Z e       Zd Zy)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                   (     e Zd ZdZ fdZd Z xZS )CudaRuntimeAPIErrorzP
    Raised when there is an error accessing a C API from the CUDA Runtime.
    c                 B    || _         || _        t        |   ||       y )N)codemsgsuper__init__)selfr   r   	__class__s      _/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/numba/cuda/cudadrv/runtime.pyr   zCudaRuntimeAPIError.__init__   s     	s#    c                 :    d| j                   d| j                  S )N[z] )r   r   r   s    r   __str__zCudaRuntimeAPIError.__str__   s     IItxx00r   )__name__
__module____qualname____doc__r   r   __classcell__)r   s   @r   r   r      s    $
1r   r   c                   P    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zed
        Zy)RuntimezA
    Runtime object that lazily binds runtime API functions.
    c                     d| _         y )NF)is_initializedr   s    r   r   zRuntime.__init__&   s
    #r   c                     t               at        j                  rd}t	        |      t        d      | _        d| _        y )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   _initializezRuntime._initialize)   s<     -%C #3'')"r   c                    	 t         |   }|d   }|dd  }| j                  s| j	                          | j                  |      }||_        ||_        | j                  ||      }t        | ||       |S # t        $ r t        |      w xY w)Nr      )
r	   KeyErrorAttributeErrorr"   r(   	_find_apirestypeargtypes_wrap_api_callsetattr)r   fnameprotor.   r/   libfn	safe_calls          r   __getattr__zRuntime.__getattr__7   s    	("5)E (9"" u%!''u5	eY'  	( ''	(s   	A1 1Bc                 J     t        j                         fd       }|S )Nc                  t    t         j                  dj                          |  }j                  |       y )Nzcall runtime api: %s)r%   debugr   _check_error)argsretcoder2   r4   r   s     r   safe_cuda_api_callz2Runtime._wrap_api_call.<locals>.safe_cuda_api_callM   s/    MM0%..ATlGeW-r   )	functoolswraps)r   r2   r4   r=   s   ``` r   r0   zRuntime._wrap_api_callL   s&    			. 
 	. "!r   c                     |t         j                  k7  r?t        j                  |d      }d|d|}t        j                  |       t        ||      y )NcudaErrorUnknownzCall to z results in )r
   CUDA_SUCCESSr   getr%   errorr   )r   r2   r<   errnamer   s        r   r:   zRuntime._check_errorT   sI    e(((mmG-?@G05w?CMM#%gs33	 )r   c                 x    	 t        | j                        S # t        $ r Y nw xY wfd}t        | |       |S )Nc                  $    d}t        |z        )Nzruntime missing function: %s.)r   )r;   kwsr   r2   s      r   absent_functionz*Runtime._find_api.<locals>.absent_functionc   s    1C"3;//r   )getattrr'   r,   r1   )r   r2   rI   s    ` r   r-   zRuntime._find_api[   sD    	488U++ 		
	0 	e_-s    	%%c                     t        j                         }| j                  t        j                  |             |j                  dz  }|j                  |dz  z
  dz  }||fS )zM
        Returns the CUDA Runtime version as a tuple (major, minor).
        i  
   )ctypesc_intcudaRuntimeGetVersionbyrefvalue)r   rtvermajorminors       r   get_versionzRuntime.get_versionj   sU     ""6<<#67t#-"4u~r   c                 :    | j                         | j                  v S )zJ
        Returns True if the CUDA Runtime is a supported version.
        )rU   supported_versionsr   s    r   is_supported_versionzRuntime.is_supported_versionu   s    
 !T%<%<<<r   c                 P    t         j                  dvst        j                  dk7  ryy)zzA tuple of all supported CUDA toolkit versions. Versions are given in
        the form ``(major_version, minor_version)``.)linuxwin32@    ))   r   )r^   r*   )r^      )r^      )r^      )r^      )r^      )r^      )sysplatformr   MACHINE_BITSr   s    r   rW   zRuntime.supported_versions|   s&     <<11V5H5HB5Nr   N)r   r   r   r   r   r(   r6   r0   r:   r-   rU   rX   propertyrW   r]   r   r   r    r    !   sC    $#*"4	=  r   r    c                  *    t         j                         S )zA
    Return the runtime version as a tuple of (major, minor)
    )runtimerU   r]   r   r   rU   rU      s       r   )r   rM   r>   re   
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    rj   rU   r]   r   r   <module>rq      sO      
  < G 0 3 $
1* 
1c cL )!r   