
\K]c           @@ s~  d  d l  m Z m Z d  d l Z d  d l m Z m Z d  d l Z d  d l 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 m Z m Z d  d l m Z m Z d  d l m Z m Z m Z m Z d  d l m Z d	 d
 l m Z d	 d l m  Z  d	 d l! m" Z" m# Z# m$ Z$ d	 d l% m& Z& d	 d l' m( Z( d	 d l) m* Z* e d    Z+ e e, e, e, g  e- d   Z. d e/ f d     YZ0 e, e, d  Z1 e2 e, d  Z3 d   Z4 d e/ f d     YZ5 d e/ f d     YZ6 d e/ f d     YZ7 d e/ f d     YZ8 d e/ f d      YZ9 d! e/ f d"     YZ: d# e8 f d$     YZ; d% Z< d& e8 f d'     YZ= d S((   i    (   t   absolute_importt   print_functionN(   t   reducet   wraps(   t   ctypes_support(   t   configt   compilert   typest   sigutils(   t   AbstractTemplatet   ConcreteTemplate(   t   funcdesct   typingt   utilst	   serialize(   t   global_compiler_locki   (   t	   AutoTuner(   t   get_context(   t   nvvmt   devicearrayt   driver(   t   normalize_kernel_dimensions(   t   get_current_device(   t   wrap_argc         C@ s   d d l  m } | j } | j } t j   } | j d  | j d  | rk | j d  | j d  n  | r | j d  n  t j d | d	 | d
 |  d | d | d | d i   }	 |	 j }
 |
 j	   |	 S(   Ni   (   t   CUDATargetDesct
   no_compilet   no_cpython_wrappert
   boundcheckt	   debuginfot   forceinlinet	   typingctxt	   targetctxt   funct   argst   return_typet   flagst   locals(
   t
   descriptorR   R   R   R   t   Flagst   sett   compile_extrat   libraryt   finalize(   t   pyfuncR"   R!   t   debugt   inlineR   R   R   R#   t   cresR)   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   compile_cuda   s*    				
c         C@ s   t  |  t j | d | d | } | j j }	 | j j | j |	 | j j	 d | \ }
 } t
 d |
 j d | j d | j j d | j j	 d | j d | d | d	 | j d
 | d | d |  } | S(   NR,   R-   t   llvm_modulet   namet   pretty_namet   argtypest   type_annotationt   linkt   call_helpert   fastmatht
   extensionst   max_registers(   R/   R   t   voidt   fndesct   llvm_func_namet   target_contextt   prepare_cuda_kernelR)   t	   signatureR!   t
   CUDAKernelt   _final_moduleR1   t   qualnameR4   R6   (   R+   R!   R5   R,   R-   R7   R8   R9   R.   t   fnamet   libt   kernelt   cukern(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   compile_kernel;   s"    !				t   DeviceFunctionTemplatec           B@ sM   e  Z d  Z d   Z d   Z e d    Z d   Z d   Z i  d  Z	 RS(   s#   Unmaterialized device function
    c         C@ s(   | |  _  | |  _ | |  _ i  |  _ d  S(   N(   t   py_funcR,   R-   t   _compileinfos(   t   selfR+   R,   R-   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   __init__U   s    			c         C@ sO   t  j |  j  } t  j |  j |  } |  j | |  j |  j f } t  j | f S(   N(   R   t#   _get_function_globals_for_reductionRI   t   _reduce_functiont	   __class__R,   R-   t   _rebuild_reduction(   RK   t   glblst   func_reducedR!   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt
   __reduce__[   s    c         C@ s%   t  j |   } t | d | d | S(   NR,   R-   (   R   t   _rebuild_functiont   compile_device_template(   t   clsRR   R,   R-   R    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   _rebuilda   s    c         C@ s   | |  j  k r t |  j d | d |  j d |  j } |  j  } | |  j  | <| j g } | r{ | j j |  | j	 |  q | j j
 |  | j	 |  n |  j  | } | S(   s   Compile the function for the given argument types.

        Each signature is compiled once by caching the compiled function inside
        this object.

        Returns the `CompileResult`.
        R,   R-   N(   RJ   R/   RI   t   NoneR,   R-   R)   R=   t   insert_user_functionR;   t   add_user_function(   RK   R!   R.   t   first_definitiont   libs(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   compilef   s    

c         C@ s#   |  j  | } | j j } t |  S(   s   Returns the LLVM-IR text compiled for *args*.

        Parameters
        ----------
        args: tuple[Type]
            Argument types.

        Returns
        -------
        llvmir : str
        (   RJ   R)   RA   t   str(   RK   R!   R.   t   mod(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   inspect_llvm   s    c   	      C@ s[   |  j  |  } t   } | j } | j } t j |   } t j | d d d | | } | S(   sL  Returns the PTX compiled for *args* for the currently active GPU

        Parameters
        ----------
        args: tuple[Type]
            Argument types.
        nvvm_options : dict; optional
            See `CompilationUnit.compile` in `numba/cuda/cudadrv/nvvm.py`.

        Returns
        -------
        ptx : bytes
        t   opti   t   arch(   R`   R   t   devicet   compute_capabilityR   t   get_arch_optiont   llvm_to_ptx(	   RK   R!   t   nvvm_optionst   llvmirt   cuctxRc   t   ccRb   t   ptx(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   inspect_ptx   s    			(
   t   __name__t
   __module__t   __doc__RL   RS   t   classmethodRW   R]   R`   Rl   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRH   R   s   				c         @ sa   d d l  m } t |  d | d |   d t f   f d     Y} | j } | j   |    S(   sc   Create a DeviceFunctionTemplate object and register the object to
    the CUDA typing context.
    i   (   R   R,   R-   t   device_function_templatec           @ s   e  Z   Z   f d    Z RS(   c         @ s   | s t     j |  j S(   N(   t   AssertionErrorR]   R?   (   RK   R!   t   kws(   t   dft(    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   generic   s    (   Rm   Rn   t   keyRu   (    (   Rt   (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRq      s   (   R%   R   RH   R	   R   RY   (   R+   R,   R-   R   Rq   R   (    (   Rt   s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRU      s    	c         C@ s   t  |  | | d t d t S(   NR-   R,   (   t   DeviceFunctiont   Truet   False(   R+   R"   R!   R-   R,   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   compile_device   s    c         @ s   d d l  m } | j } | j } t j | |   t |      d t f    f d     Y} t j	 d |  d | d |  } | j
   |  | j
   |    S(   Ni   (   R   Rq   c           @ s   e  Z   Z  g Z RS(    (   Rm   Rn   Rv   t   cases(    (   t   extfnt   sig(    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRq      s   R1   t   restypeR3   (   R%   R   R   R   R   R?   t   ExternFunctionR
   R   t   ExternalFunctionDescriptorRY   (   R1   R~   R3   R   R   R   Rq   R;   (    (   R|   R}   s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   declare_device_function   s    			Rw   c           B@ s2   e  Z d    Z d   Z e d    Z d   Z RS(   c         @ s   |  _  |  _ |  _ t  _ t  _ t  j   j  j d  j d  j      _ d t	 f    f d     Y}   j
 j  |    j j    j   j g  d  S(   NR,   R-   Rq   c           @ s   e  Z  Z   j g Z RS(    (   Rm   Rn   Rv   R?   R{   (    (   R.   RK   (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRq      s   (   RI   R"   R!   Rx   R-   Ry   R,   R/   R.   R
   t   typing_contextRY   R=   R;   R)   (   RK   R+   R"   R!   R-   R,   Rq   (    (   R.   RK   s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL      s    							
c         C@ s[   t  j |  j  } t  j |  j |  } |  j | |  j |  j |  j |  j f } t  j	 | f S(   N(
   R   RM   RI   RN   RO   R"   R!   R-   R,   RP   (   RK   t   globsRR   R!   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRS      s
    c         C@ s   |  t  j |   | | | |  S(   N(   R   RT   (   RV   RR   R"   R!   R-   R,   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRW      s    c         C@ s   d } | j  |  j |  j j  S(   Ns*   <DeviceFunction py_func={0} signature={1}>(   t   formatRI   R.   R?   (   RK   t   fmt(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   __repr__   s    (   Rm   Rn   RL   RS   Rp   RW   R   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRw      s   		R   c           B@ s   e  Z d    Z RS(   c         C@ s   | |  _  | |  _ d  S(   N(   R1   R}   (   RK   R1   R}   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL      s    	(   Rm   Rn   RL   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR      s   t   ForAllc           B@ s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C@ s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   RE   t   ntaskst   thread_per_blockt   streamt	   sharedmem(   RK   RE   R   t   tpbR   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL     s
    				c         G@ s   t  |  j t  r' |  j j |   } n	 |  j } |  j |  } | d } |  j | | } | j | | d |  j d |  j |   S(   Ni   R   R   (	   t
   isinstanceRE   t   AutoJitCUDAKernelt
   specializet   _compute_thread_per_blockR   t	   configureR   R   (   RK   R!   RE   R   t   tpbm1t   blkct(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   __call__	  s    	
c      	   C@ s   |  j  } | d k r | St   } t d | j j   d d   d |  j d d  } y | j |   \ } } Wn# t k
 r |  j |  }   n X| Sd  S(   Ni    R    t   b2d_funcc         S@ s   d S(   Ni    (    (   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   <lambda>   t    t   memsizet   blocksizelimiti   (	   R   R   t   dictt   _funct   getR   t   get_max_potential_block_sizet   AttributeErrort   _fallback_autotune_best(   RK   RE   R   t   ctxt   kwargst   _(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     s    					c         C@ s>   y | j  j   } Wn$ t k
 r9 t j d  d } n X| S(   Ns,   Could not autotune, using default tpb of 128i   (   t   autotunet   bestt
   ValueErrort   warningst   warn(   RK   RE   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   -  s    
(   Rm   Rn   RL   R   R   R   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     s   			t   CUDAKernelBasec           B@ s\   e  Z d  Z d   Z d   Z d d d  Z d   Z d d d d  Z d   Z d   Z	 RS(	   s.   Define interface for configurable kernels
    c         C@ s(   d |  _  d |  _ d |  _ d |  _ d  S(   Ni   i    (   i   i   (   i   i   i   (   t   griddimt   blockdimR   R   (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL   ;  s    			c         C@ s/   |  j  } | j |  } | j j |  j  | S(   s+   
        Shallow copy the instance
        (   RO   t   __new__t   __dict__t   update(   RK   RV   t   new(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   copyA  s    	i    c         C@ sU   t  | |  \ } } |  j   } t |  | _ t |  | _ | | _ | | _ | S(   N(   R   R   t   tupleR   R   R   R   (   RK   R   R   R   R   t   clone(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   M  s    		c         C@ s.   t  |  d k r! t d   n  |  j |   S(   Ni   i   i   s.   must specify at least the griddim and blockdim(   i   i   i   (   t   lenR   R   (   RK   R!   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   __getitem__W  s    c      	   C@ s   t  |  | d | d | d | S(   s   Returns a configured kernel for 1D kernel of given number of tasks
        ``ntasks``.

        This assumes that:
        - the kernel 1-to-1 maps global thread id ``cuda.grid(1)`` to tasks.
        - the kernel must check if the thread id is valid.R   R   R   (   R   (   RK   R   R   R   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   forall\  s    c         C@ s   |  j  |  j |  j f S(   s   
        Helper for serializing the grid, block and shared memory configuration.
        CUDA stream config is not serialized.
        (   R   R   R   (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   _serialize_configf  s    c         C@ s   | \ |  _  |  _ |  _ d S(   sc   
        Helper for deserializing the grid, block and shared memory
        configuration.
        N(   R   R   R   (   RK   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   _deserialize_configm  s    (
   Rm   Rn   Ro   RL   R   R   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   7  s   		
	
	t	   CachedPTXc           B@ s    e  Z d  Z d   Z d   Z RS(   s<   A PTX cache that uses compute capability as a cache key
    c         C@ s.   | |  _  | |  _ i  |  _ | j   |  _ d  S(   N(   R1   Rh   t   cacheR   t   _extra_options(   RK   R1   Rh   t   options(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL   x  s    			c         C@ s   t    } | j } | j } |  j j |  } | d	 k r t j |   } t j |  j	 d d d | |  j
 } | |  j | <t j r t d |  j j d d   t | j d   t d d  q n  | S(
   s9   
        Get PTX for the current active context.
        Ra   i   Rb   s   ASSEMBLY %siP   t   -s   utf-8t   =N(   R   Rc   Rd   R   R   RX   R   Re   Rf   Rh   R   R   t   DUMP_ASSEMBLYt   printR1   t   centert   decode(   RK   Ri   Rc   Rj   Rk   Rb   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   ~  s    				(   Rm   Rn   Ro   RL   R   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   u  s   	t   CachedCUFunctionc           B@ sA   e  Z d  Z d   Z d   Z d   Z d   Z e d    Z RS(   sk   
    Get or compile CUDA function for the current active context

    Uses device ID as key for cache.
    c         C@ s:   | |  _  | |  _ | |  _ i  |  _ i  |  _ | |  _ d  S(   N(   t
   entry_nameRk   t   linkingR   t   ccinfosR9   (   RK   R   Rk   R   R9   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL     s    					c         C@ s   t    } | j } |  j j | j  } | d  k r |  j j   } t j d |  j	  } | j
 |  x |  j D] } | j |  qn W| j   \ } } | j }	 | j |  }
 |
 j |  j  } | |  j | j <|	 |  j | j <n  | S(   NR9   (   R   Rc   R   R   t   idRX   Rk   R   t   LinkerR9   t   add_ptxR   t   add_file_guess_extt   completet   info_logt   create_module_imaget   get_functionR   R   (   RK   Ri   Rc   t   cufuncRk   t   linkert   patht   cubint   _sizet   compile_infot   module(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     s     			c         C@ s0   |  j    t   } | j } |  j | j } | S(   N(   R   R   Rc   R   R   (   RK   Ri   Rc   t   ci(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   get_info  s
    
		c         C@ sO   |  j  r d } t |   n  |  j |  j |  j |  j  |  j f } t j | f S(   s   
        Reduce the instance for serialization.
        Pre-compiled PTX code string is serialized inside the `ptx` (CachedPTX).
        Loaded CUfunctions are discarded. They are recreated when unserialized.
        sL   cannot pickle CUDA kernel function with additional libraries to link against(   R   t   RuntimeErrorRO   R   Rk   R9   R   RP   (   RK   t   msgR!   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRS     s
    	$c         C@ s   |  | | | |  S(   s&   
        Rebuild an instance.
        (    (   RV   R   Rk   R   R9   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRW     s    (	   Rm   Rn   Ro   RL   R   R   RS   Rp   RW   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     s   				R@   c           B@ s   e  Z d  Z d e e d g  d d  Z e d    Z d   Z d   Z	 d   Z
 e d    Z e d    Z d   Z d	   Z d d
  Z d d d  Z d   Z e d    Z e d    Z RS(   s   
    CUDA Kernel specialized for a given set of argument types. When called, this
    object will validate that the argument types match those for which it is
    specialized, and then launch the kernel on the device.
    c      
   C@ s   t  t |   j   i | d 6} | rQ | j t d t d t d t d t   n  t | t |  d | } t	 | | | |  } | |  _
 t |  |  _ t |  |  _ |	 |  _ | |  _ | |  _ | |  _ t |
  |  _ d  S(   NR,   t   ftzt	   prec_sqrtt   prec_divt   fmaR   (   t   superR@   RL   R   R   Rx   Ry   R   R^   R   R   R   t   argument_typesR   t   _type_annotationR   R,   R6   t   listR8   (   RK   R0   R1   R2   R3   R6   R5   R,   R7   R4   R8   R9   R   Rk   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL     s"    					c	   
      C@ s   |  j  |   }	 t |  |	  j   | |	 _ t |  |	 _ t |  |	 _ d |	 _ | |	 _	 | |	 _
 | |	 _ | |	 _ |	 j |  |	 S(   s&   
        Rebuild an instance.
        N(   R   R   RL   R   R   R   R   RX   R   R   R,   R6   R8   R   (
   RV   R1   R3   R   R5   R,   R6   R8   R   t   instance(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRW     s    						c      	   C@ sR   |  j    } |  j |  j |  j |  j |  j |  j |  j |  j | f	 } t	 j
 | f S(   s  
        Reduce the instance for serialization.
        Compiled definitions are serialized in PTX form.
        Type annotation are discarded.
        Thread, block and shared memory configuration are serialized.
        Stream information is discarded.
        (   R   RO   R   R   R   R   R,   R6   R8   R   RP   (   RK   R   R!   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRS     s
    c         O@ sE   | s t   |  j d | d |  j d |  j d |  j d |  j  d  S(   NR!   R   R   R   R   (   Rr   t   _kernel_callR   R   R   R   (   RK   R!   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     s    			c         C@ s   |  j  j   d S(   s7   
        Force binding to current CUDA context
        N(   R   R   (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   bind  s    c         C@ s   |  j  j j   j d  S(   s+   
        PTX code for this kernel.
        t   utf8(   R   Rk   R   R   (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRk   "  s    c         C@ s   t    S(   s,   
        Get current active context
        (   R   (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRc   )  s    c         C@ s   t  |  j j j  S(   s6   
        Returns the LLVM IR for this kernel.
        (   R^   R   Rk   Rh   (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR`   0  s    c         C@ s   |  j  j j   j d  S(   s7   
        Returns the PTX code for this kernel.
        t   ascii(   R   Rk   R   R   (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   inspect_asm6  s    c         C@ s   |  j  d k r t d   n  | d k r6 t j } n  t d |  j |  j f d | t d d d | t |  j  d | t d d d | d S(   s   
        Produce a dump of the Python source of this function annotated with the
        corresponding Numba IR and type information. The dump is written to
        *file*, or *sys.stdout* if *file* is *None*.
        s    Type annotation is not availables   %s %st   fileR   iP   R   N(   R   RX   R   t   syst   stdoutR   R   R   (   RK   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   inspect_types<  s     i    c         @ sU  |  j  j     |  j r}   j d }   j j |  \ } } | t j t j  k s[ t	  t j   }	 | j
 d d | n  g  }
 g  } x9 t |  j |  D]% \ } } |  j | | | |
 |  q W  j | | d | d | } | |   |  j r9t j t j |	  | |  |	 j d k r9  f d   } g  d D] } | d |  ^ q7} g  d D] } | d |  ^ qZ} |	 j } |  j j |  \ } } } | d  k rd	 } n4 | \ } } } t j j |  } d
 | | | f } d | | | f } | rd | | d f f | d } n	 | f } | |    q9n  x |
 D] } |   q@Wd  S(   Nt   __errcode__i    R   R   c         @ sT     j  j d   j |  f  \ } } t j   } t j t j |  | |  | j S(   Ns   %s__%s__(	   R   t   get_global_symbolR1   t   ctypest   c_intR   t   device_to_hostt	   addressoft   value(   R1   t   memt   szt   val(   R   (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   load_symbolj  s    t   zyxt   tidt   ctaidR   s"   In function %r, file %s, line %s, s   %stid=%s ctaid=%ss   %s: %si   (   R   R   R,   R1   R   R   R   t   sizeofR   Rr   t   memsett   zipR   t   _prepare_argsR   R   R   R   R   R6   t   get_exceptionRX   t   osR   t   relpath(   RK   R!   R   R   R   R   t   excnamet   excmemt   excszt   excvalt   retrt
   kernelargst   tt   vt   cu_funcR   t   iR   R   t   codet   excclst   exc_argst   loct   locinfot   symt   filepatht   linenot   prefixt   wb(    (   R   s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   M  sH    		
	##		"	c         @ s  x; t  |  j  D]* } | j |   d | d | \ }   q Wt | t j  rt | t j  r   j d  } | j   f d    t	 j
 d  } | j |  n t    j | |  } t	 j }	 t	 j
 d  }
 t	 j
 d  } |	 | j  } |	 | j j  } t	 j
 t j |   } | j |
  | j |  | j |  | j |  | j |  x1 t | j  D]  } | j |	 | j |   qoWxt | j  D]  } | j |	 | j |   qWnt | t j  rt t	 d |     } | j |  n| t j k r3t	 j    } | j |  ns| t j k rat	 j    } | j |  nE| t j k rt	 j t     } | j |  n| t j  k r| j t	 j   j!   | j t	 j   j"   n | t j# k r| j t	 j   j!   | j t	 j   j"   n t | t j$ t j% f  r]| j t	 j&   j' t( j)    nI t | t j*  rt    j | |  } | j |  n t+ |     d S(   sF   
        Convert arguments to ctypes and append to kernelargs
        R   R  t   gpuc           @ s     j  d  S(   NR  (   t   mark_changed(    (   R   (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     R   i    s   c_%sN(,   t   reversedR8   t   prepare_argsR   R   t   Arrayt   SmartArrayTypeR   t   appendR   t   c_void_pR   t	   to_devicet	   c_ssize_tt   sizet   dtypet   itemsizeR   t   device_pointert   ranget   ndimt   shapet   stridest   Integert   getattrt   float64t   c_doublet   float32t   c_floatt   booleant   c_uint8t   intt	   complex64t   realt   imagt
   complex128t
   NPDatetimet   NPTimedeltat   c_int64t   viewt   npt   int64t   Recordt   NotImplementedError(   RK   t   tyR   R   R  R  t	   extensiont   devaryt   outer_parentt   c_intpt   meminfot   parentt   nitemsR  t   datat   axt   cvalt   devrec(    (   R   s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     sh    	!%c         C@ s   t  j t j d  t  t |  d  } | rJ |  j j |  j k rJ |  j S|  j	 j
   } t d | j d | j j  } | |  _ |  j Sd S(   s8   Return the autotuner object associated with this kernel.R   t	   _autotunet   infoRj   N(   R   R   t   _deprec_warn_msgR   t   DeprecationWarningt   hasattrRF  t   dynsmemR   R   R   R   t   attrsRc   Rd   (   RK   t   has_autotuneR   t   at(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     s    	c         C@ sA   t  j t j d  t  t t j |  j d  } |  j	 j
 |  S(   s  Occupancy is the ratio of the number of active warps per multiprocessor to the maximum
        number of warps that can be active on the multiprocessor at once.
        Calculate the theoretical occupancy of the kernel given the
        current configuration.t	   occupancyi   (   R   R   RH  R   RI  R   t   operatort   mulR   R   t   closest(   RK   R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRO    s    (    N(   Rm   Rn   Ro   Ry   RX   RL   Rp   RW   RS   R   R   t   propertyRk   Rc   R`   R   R   R   R   R   RO  (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR@     s    					>	IsJ   The .{} attribute is is deprecated and will be removed in a future releaseR   c           B@ s   e  Z d  Z d   Z e d    Z d   Z d   Z d   Z d d d  Z
 d d d  Z d d  Z e d	    Z d
   Z RS(   s  
    CUDA Kernel object. When called, the kernel object will specialize itself
    for the given arguments (if no suitable specialized version already exists)
    & compute capability, and launch on the device associated with the current
    context.

    Kernel objects are not to be constructed by the user, but instead are
    created using the :func:`numba.cuda.jit` decorator.
    c         C@ sy   t  t |   j   | |  _ | |  _ i  |  _ | |  _ t |  j j d g    |  j d <d d l	 m
 } | j |  _ d  S(   NR8   i   (   R   (   R   R   RL   RI   R   t   definitionst   targetoptionsR   R   R%   R   R   (   RK   R    R   RU  R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRL     s    				"c         C@ s   |  j  d S(   sS  
        A list of objects that must have a `prepare_args` function. When a
        specialized kernel is called, each argument will be passed through
        to the `prepare_args` (from the last object in this list to the
        first). The arguments to `prepare_args` are:

        - `ty` the numba type of the argument
        - `val` the argument value itself
        - `stream` the CUDA stream used for the current call to the kernel
        - `retr` a list of zero-arg functions that you may want to append
          post-call cleanup work to.

        The `prepare_args` function must return a tuple `(ty, val)`, which
        will be passed in turn to the next right-most `extension`. After all
        the extensions have been called, the resulting `(ty, val)` will be
        passed into Numba's default argument marshalling logic.
        R8   (   RU  (   RK   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR8     s    c         G@ s?   |  j  |   } | |  j |  j |  j |  j f } | |   d S(   s@   
        Specialize and invoke this kernel with *args*.
        N(   R   R   R   R   R   (   RK   R!   RE   t   cfg(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   "  s    "c         G@ s>   t  g  | D] } |  j j |  ^ q
  } |  j |  } | S(   s|   
        Compile and bind to the current context a version of this kernel
        specialized for the given *args*.
        (   R   R   t   resolve_argument_typeR]   (   RK   R!   t   aR3   RE   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   *  s    (c         C@ s   t  j |  \ } } | d k s' t  t   j } |  j j | | f  } | d k r d |  j k rv d |  j d <n  t	 |  j
 | |  j  } | |  j | | f <|  j r | j   q n  | S(   s   
        Compile and bind to the current context a version of this kernel
        specialized for the given signature.
        R5   N(    (   R   t   normalize_signatureRX   Rr   R   Rd   RT  R   RU  RG   RI   R   (   RK   R}   R3   R"   Rj   RE   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR]   4  s    	c         C@ sV   | p t    j } | d k	 r5 |  j | | f j   St d   |  j j   D  Sd S(   s   
        Return the LLVM IR for all signatures encountered thus far, or the LLVM
        IR for a specific signature and compute_capability if given.
        c         s@ s'   |  ] \ } } | | j    f Vq d  S(   N(   R`   (   t   .0R}   t   defn(    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pys	   <genexpr>P  s   N(   R   Rd   RX   RT  R`   R   t   items(   RK   R?   Rd   Rj   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR`   G  s
    	c         C@ sV   | p t    j } | d k	 r5 |  j | | f j   St d   |  j j   D  Sd S(   s   
        Return the generated assembly code for all signatures encountered thus
        far, or the LLVM IR for a specific signature and compute_capability
        if given.
        c         s@ s'   |  ] \ } } | | j    f Vq d  S(   N(   R   (   RZ  R}   R[  (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pys	   <genexpr>]  s   N(   R   Rd   RX   RT  R   R   R\  (   RK   R?   Rd   Rj   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   S  s
    	c         C@ sO   | d k r t j } n  x0 t j |  j  D] \ } } | j d |  q+ Wd S(   s   
        Produce a dump of the Python source of this function annotated with the
        corresponding Numba IR and type information. The dump is written to
        *file*, or *sys.stdout* if *file* is *None*.
        R   N(   RX   R   R   R   t	   iteritemsRT  R   (   RK   R   R   R[  (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR   `  s    c         C@ s2   t  j |   } |  | | |  } | j |  | S(   s&   
        Rebuild an instance.
        (   R   RT   R   (   RV   RR   R   RU  R   R    R   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRW   l  s    c         C@ s^   t  j |  j  } t  j |  j |  } |  j   } |  j | |  j |  j | f } t  j | f S(   sd   
        Reduce the instance for serialization.
        Compiled definitions are discarded.
        (	   R   RM   RI   RN   R   RO   R   RU  RP   (   RK   RQ   RR   R   R!   (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyRS   v  s    	N(   Rm   Rn   Ro   RL   RS  R8   R   R   R]   RX   R`   R   R   Rp   RW   RS   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyR     s   				
	
(>   t
   __future__R    R   R   t	   functoolsR   R   RP  R   t	   threadingR   t   numpyR6  t   numbaR   R   R   R   R   R   t   numba.typing.templatesR	   R
   R   R   R   R   t   numba.compiler_lockR   t   cudadrv.autotuneR   t   cudadrv.devicesR   t   cudadrvR   R   R   t   errorsR   t   apiR   R!   R   R/   Ry   RX   RG   t   objectRH   RU   Rx   Rz   R   Rw   R   R   R   R   R   R@   RH  R   (    (    (    s2   lib/python2.7/site-packages/numba/cuda/compiler.pyt   <module>   sH   "" W	&6>A 