o
    8ήc]                     @   s|   d dl mZ d dlmZ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 dZdd	d	g dd
d	fddZdd ZdS )    )warn)typesconfigsigutils)DeprecationErrorNumbaInvalidConfigWarning)declare_device_function)CUDADispatcherFakeCUDAKernelz`Deprecated keyword argument `{0}`. Signatures should be passed as the first positional argument.NFTc              	      s  r	t jr	tddrtdddur"td}t|ddur2td}t|ddurBtd}t|du rIt jndd	d
g rcrcd}tt	| rndrnt
dt| rt jrfdd}	|	S t| \ }
|
rs|
tjkrtd f	dd}|S | du rt jrfdd}|S fdd}|S t jrt| dS  }|d< |d< |d< |d< |d< |d
< t| |d}r|  |S )a  
    JIT compile a python function conforming to the CUDA Python specification.
    If a signature is supplied, then a function is returned that takes a
    function to compile.

    :param func_or_sig: A function to JIT compile, or a signature of a function
       to compile. If a function is supplied, then a
       :class:`numba.cuda.compiler.AutoJitCUDAKernel` is returned. If a
       signature is supplied, then a function is returned. The returned
       function accepts another function, which it will compile and then return
       a :class:`numba.cuda.compiler.AutoJitCUDAKernel`.

       .. note:: A kernel cannot have any return value.
    :param device: Indicates whether this is a device function.
    :type device: bool
    :param link: A list of files containing PTX source to link with the function
    :type link: list
    :param debug: If True, check for exceptions thrown when executing the
       kernel. Since this degrades performance, this should only be used for
       debugging purposes. If set to True, then ``opt`` should be set to False.
       Defaults to False.  (The default value can be overridden by setting
       environment variable ``NUMBA_CUDA_DEBUGINFO=1``.)
    :param fastmath: When True, enables fastmath optimizations as outlined in
       the :ref:`CUDA Fast Math documentation <cuda-fast-math>`.
    :param max_registers: Request that the kernel is limited to using at most
       this number of registers per thread. The limit may not be respected if
       the ABI requires a greater number of registers than that requested.
       Useful for increasing occupancy.
    :param opt: Whether to compile from LLVM IR to PTX with optimization
                enabled. When ``True``, ``-opt=3`` is passed to NVVM. When
                ``False``, ``-opt=0`` is passed to NVVM. Defaults to ``True``.
    :type opt: bool
    :param lineinfo: If True, generate a line mapping between source code and
       assembly code. This enables inspection of the source code in NVIDIA
       profiling tools and correlation with program counter sampling.
    :type lineinfo: bool
    :param cache: If True, enables the file-based cache for this function.
    :type cache: bool
    z Cannot link PTX in the simulatorboundscheckz)bounds checking is not supported for CUDAargtypesNrestypebindfastmathF
extensionsz{debug=True with opt=True (the default) is not supported by CUDA. This may result in a crash - set debug=False or opt=False.linkz(link keyword invalid for device functionc                       t |  dS Ndevicer   r
   funcr    </tmp/pip-target-vg8gfxp4/lib/python/numba/cuda/decorators.py
jitwrapperW   s   zjit.<locals>.jitwrapperz'CUDA kernel must have void return type.c                    s     }|d< |d< |d< |d< |d< |d< t| |d}r(|  rKdd	lm} || |  W d    n1 sEw   Y  n|  d
|_|	  |S )Ndebugr   optr   r   r   targetoptionsr   )	typeinferT)
copyr	   enable_caching
numba.corer    register_dispatchercompile_devicecompile_specializeddisable_compile)r   r   dispr    	r   cacher   r   r   r   kwsr   r   r   r   _jit`   s(   
zjit.<locals>._jitc                    r   r   r
   r   r   r   r   autojitwrapper~   s   zjit.<locals>.autojitwrapperc                    s   t | f dS )N)r   r   r   r   r+   )jitr   )r+   r   r   r,   r   r   r   r   r.      s
   r   r   r   r   r   )r   ENABLE_CUDASIMNotImplementedErrorget_msg_deprecated_signature_argformatr   CUDA_DEBUGINFO_DEFAULTr   r   
ValueErrorr   is_signaturenormalize_signaturer   void	TypeErrorr   r!   r	   r"   )func_or_sigr   inliner   r   r   r+   r,   msgr   r   r-   r.   r   r)   r   r*   r   r/      sf   
*




r/   c                 C   s.   t |\}}|du rd}t|t| ||S )a  
    Declare the signature of a foreign function. Returns a descriptor that can
    be used to call the function from a Python kernel.

    :param name: The name of the foreign function.
    :type name: str
    :param sig: The Numba signature of the function.
    Nz4Return type must be provided for device declarations)r   r8   r:   r   )namesigr   r   r=   r   r   r   declare_device   s
   	r@   )warningsr   r#   r   r   r   numba.core.errorsr   r   numba.cuda.compilerr   numba.cuda.dispatcherr	   numba.cuda.simulator.kernelr   r3   r/   r@   r   r   r   r   <module>   s    

 