ó
\K]c           @` sü  d  Z  d d l m Z m Z m 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 d d l Z d d l	 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 y e e d ƒ e ƒ Z Wn e k
 rd „  Z n Xd „  Z d „  Z d „  Z d e f d „  ƒ  YZ  d e  f d „  ƒ  YZ! e d „  ƒ Z" d e  f d „  ƒ  YZ# d e f d „  ƒ  YZ$ d e  e j% f d „  ƒ  YZ& d e d „ Z' d e d „ Z( d „  Z) d Z* d „  Z+ d e, d  „ Z- d! „  Z. d S("   sÑ   
A CUDA ND Array is recognized by checking the __cuda_memory__ attribute
on the object.  If it exists and evaluate to True, it must define shape,
strides, dtype and size attributes similar to a NumPy ndarray.
i    (   t   print_functiont   absolute_importt   divisionN(   t   six(   t   c_void_pi   (   t   driver(   t   devices(   t
   dummyarrayt   typest   numpy_support(   t   to_fixed_tuplet	   lru_cachec         C` s   |  S(   N(    (   t   func(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR      s    c         C` s   t  |  d t ƒ S(   s$   Check if an object is a CUDA ndarrayt   __cuda_ndarray__(   t   getattrt   False(   t   obj(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   is_cuda_ndarray   s    c         ` sW   t  ˆ  ƒ ‡  f d †  } | d t ƒ | d t ƒ | d t j ƒ | d t j ƒ d S(   s,   Verify the CUDA ndarray interface for an objc         ` sS   t  ˆ  |  ƒ s t |  ƒ ‚ n  t t ˆ  |  ƒ | ƒ sO t d |  | f ƒ ‚ n  d  S(   Ns   %s must be of type %s(   t   hasattrt   AttributeErrort
   isinstanceR   (   t   attrt   typ(   R   (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   requires_attr(   s    t   shapet   stridest   dtypet   sizeN(   t   require_cuda_ndarrayt   tuplet   npR   R   t   integer_types(   R   R   (    (   R   s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   verify_cuda_ndarray_interface$   s    
c         C` s   t  |  ƒ s t d ƒ ‚ n  d S(   s9   Raises ValueError is is_cuda_ndarray(obj) evaluates Falses   require an cuda ndarray objectN(   R   t
   ValueError(   R   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR   4   s    t   DeviceNDArrayBasec           B` s  e  Z d  Z e Z e Z d d d d „ Z e d „  ƒ Z	 d d „ Z
 e d „  ƒ Z d d „ Z d „  Z e d „  ƒ Z e d	 „  ƒ Z e j d d
 „ ƒ Z e j d d d „ ƒ Z d d „ Z d d „ Z d „  Z d „  Z d d d „ Z d „  Z e d „  ƒ Z RS(   s$   A on GPU NDArray representation
    i    c         C` sœ  t  | t j ƒ r | f } n  t  | t j ƒ r< | f } n  t | ƒ |  _ t | ƒ |  j k ro t d ƒ ‚ n  t j j d | | | j	 ƒ |  _
 t | ƒ |  _ t | ƒ |  _ t j | ƒ |  _ t t j |  j ƒ ƒ |  _ |  j d k rJ| d k r5t j |  j |  j |  j j	 ƒ |  _ t j ƒ  j |  j ƒ } q}t j | ƒ |  _ n3 t j d t j ƒ  d t d ƒ d d ƒ } d |  _ | |  _ | |  _ | |  _ d S(   sN  
        Args
        ----

        shape
            array shape.
        strides
            array strides.
        dtype
            data type as np.dtype.
        stream
            cuda stream.
        writeback
            Deprecated.
        gpu_data
            user provided device memory for the ndarray data buffer
        s   strides not match ndimi    t   contextt   pointerR   N(    R   R   R   t   lent   ndimR!   R   t   Arrayt	   from_desct   itemsizet   _dummyR   R   R   R   R   t   intt   prodR   t   Nonet   _drivert   memory_size_from_infot
   alloc_sizeR   t   get_contextt   memalloct   device_memory_sizet   MemoryPointerR   t   gpu_datat   _DeviceNDArrayBase__writebackt   stream(   t   selfR   R   R   R7   t	   writebackR5   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   __init__@   s4    			c         C` sK   i t  |  j ƒ d 6t  |  j ƒ d 6|  j j t f d 6|  j j d 6d d 6S(   NR   R   t   datat   typestri   t   version(   R   R   R   t   device_ctypes_pointert   valueR   R   t   str(   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   __cuda_array_interface__t   s    c         C` s   t  j  |  ƒ } | | _ | S(   s   Bind a CUDA stream to this object so that all subsequent operation
        on this array defaults to the given stream.
        (   t   copyR7   (   R8   R7   t   clone(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   bind~   s    	c         C` s
   |  j  ƒ  S(   N(   t	   transpose(   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   T†   s    c         C` sª   | r+ t  | ƒ t  t |  j ƒ ƒ k r+ |  S|  j d k rI t d ƒ ‚ n] | d  k	 rŒ t | ƒ t t |  j ƒ ƒ k rŒ t d | f ƒ ‚ n d d l m } | |  ƒ Sd  S(   Ni   s2   transposing a non-2D DeviceNDArray isn't supporteds   invalid axes list %ri    (   RE   (	   R   t   rangeR&   t   NotImplementedErrorR-   t   setR!   t   numba.cuda.kernels.transposeRE   (   R8   t   axesRE   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRE   Š   s    '-c         C` s   | s |  j  S| S(   N(   R7   (   R8   R7   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   _default_stream•   s    c         C` s(   t  j |  j ƒ } t j | |  j d ƒ S(   sn   
        Magic attribute expected by Numba to get the numba type that
        represents this object.
        t   A(   R	   t
   from_dtypeR   R   R'   R&   (   R8   R   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   _numba_type_˜   s    c         C` s'   |  j  d k r t d ƒ S|  j  j Sd S(   s:   Returns the ctypes pointer to the GPU data buffer
        i    N(   R5   R-   R   R>   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR>   ¡   s    
c      	   C` só   | j  d k r d St |  ƒ |  j | ƒ } t |  ƒ t | ƒ } } t j | ƒ rŠ t | ƒ t | | ƒ t j |  | |  j d | ƒne t	 j
 | d | j d r© d n d d t d	 | j d
 ƒ} t | | ƒ t j |  | |  j d | ƒd S(   sŸ   Copy `ary` to `self`.

        If `ary` is a CUDA memory, perform a device-to-device transfer.
        Otherwise, perform a a host-to-device transfer.
        i    NR7   t   ordert   C_CONTIGUOUSt   Ct   Ft   subokRB   t	   WRITEABLE(   R   t   sentry_contiguousRL   t
   array_coreR.   t   is_device_memoryt   check_array_compatibilityt   device_to_deviceR0   R   t   arrayt   flagst   Truet   host_to_device(   R8   t   aryR7   t	   self_coret   ary_core(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   copy_to_deviceª   s     

c      	   C` sH  t  d „  |  j Dƒ ƒ r: d } t | j |  j ƒ ƒ ‚ n  |  j d k sU t d ƒ ‚ |  j | ƒ } | d
 k r‘ t j	 d |  j d t j
 ƒ } n t |  | ƒ | } |  j d k rÒ t j | |  |  j d | ƒn  | d
 k rD|  j d k rt j d |  j d |  j d | ƒ } qDt j d |  j d |  j d	 |  j d | ƒ } n  | S(   s^  Copy ``self`` to ``ary`` or create a new Numpy ndarray
        if ``ary`` is ``None``.

        If a CUDA ``stream`` is given, then the transfer will be made
        asynchronously as part as the given stream.  Otherwise, the transfer is
        synchronous: the function returns after the copy is finished.

        Always returns the host array.

        Example::

            import numpy as np
            from numba import cuda

            arr = np.arange(1000)
            d_arr = cuda.to_device(arr)

            my_kernel[100, 100](d_arr)

            result_array = d_arr.copy_to_host()
        c         s` s   |  ] } | d  k  Vq d S(   i    N(    (   t   .0t   s(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pys	   <genexpr>ß   s    s2   D->H copy not implemented for negative strides: {}i    s   Negative memory sizeR   R   R7   t   bufferR   N(   t   anyR   RH   t   formatR0   t   AssertionErrorRL   R-   R   t   emptyt   byteRY   R.   t   device_to_hostR   t   ndarrayR   R   (   R8   R_   R7   t   msgt   hostary(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   copy_to_hostÈ   s$    !c         C` sW   |  j  | ƒ } t j d t ƒ |  j d  k r= t d ƒ ‚ n  |  j |  j d | ƒd  S(   Ns+   to_host() is deprecated and will be removeds   no associated writeback arrayR7   (   RL   t   warningst   warnt   DeprecationWarningR6   R-   R!   Ro   (   R8   R7   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   to_hostö   s    	c      
   c` s  |  j  | ƒ } |  j d k r- t d ƒ ‚ n  |  j d |  j j k rU t d ƒ ‚ n  t t j t	 |  j
 ƒ | ƒ ƒ } |  j } |  j j } x t | ƒ D]s } | | } t | | |  j
 ƒ } | | f }	 |  j j | | | | ƒ }
 t |	 | d |  j d | d |
 ƒVq™ Wd S(	   sž   Split the array into equal partition of the `section` size.
        If the array cannot be equally divided, the last section will be
        smaller.
        i   s   only support 1d arrayi    s   only support unit strideR   R7   R5   N(   RL   R&   R!   R   R   R)   R+   t   matht   ceilt   floatR   RG   t   minR5   t   viewt   DeviceNDArray(   R8   t   sectionR7   t   nsectR   R)   t   it   begint   endR   R5   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   splitþ   s    "	
c         C` s   |  j  S(   sE   Returns a device memory object that is used as the argument.
        (   R5   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   as_cuda_arg  s    c         C` sO   t  j ƒ  j |  j ƒ } t d |  j d |  j d |  j ƒ } t d | d | ƒ S(   sÌ   
        Returns a *IpcArrayHandle* object that is safe to serialize and transfer
        to another process to share the local allocation.

        Note: this feature is only available on Linux.
        R   R   R   t
   ipc_handlet
   array_desc(	   R   R1   t   get_ipc_handleR5   t   dictR   R   R   t   IpcArrayHandle(   R8   t   ipcht   desc(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRƒ     s    $c         C` sU   |  j  j d | ƒ \ } } t d | j d | j d |  j d |  j | ƒ d |  j ƒ S(   s(  
        Remove axes of size one from the array shape.

        Parameters
        ----------
        axis : None or int or tuple of ints, optional
            Subset of dimensions to remove. A `ValueError` is raised if an axis with
            size greater than one is selected. If `None`, all axes with size one are
            removed.
        stream : cuda stream or 0, optional
            Default stream for the returned view of the array.

        Returns
        -------
        DeviceNDArray
            Squeezed view into the array.

        t   axisR   R   R   R7   R5   (   R*   t   squeezeRy   R   R   R   RL   R5   (   R8   Rˆ   R7   t	   new_dummyt   _(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR‰   #  s    			c         C` sd   t  j | ƒ } | j |  j j k r3 t d ƒ ‚ n  t d |  j d |  j d | d |  j d |  j ƒ S(   se   Returns a new object by reinterpretting the dtype without making a
        copy of the data.
        s    new dtype itemsize doesn't matchR   R   R   R7   R5   (	   R   R   R)   t	   TypeErrorRy   R   R   R7   R5   (   R8   R   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRx   ?  s    			c         C` s   |  j  j |  j S(   N(   R   R)   R   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   nbytesN  s    N(   t   __name__t
   __module__t   __doc__R]   t   __cuda_memory__R   R-   R:   t   propertyRA   RD   RF   RE   RL   RO   R>   R   t   require_contextRb   Ro   Rs   R   R€   Rƒ   R‰   Rx   R   (    (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR"   :   s.   3
			-			t   DeviceRecordc           B` s;   e  Z d  Z d d d „ Z e d „  ƒ Z e d „  ƒ Z RS(   s   
    An on-GPU record type
    i    c         C` s2   d } d } t  t |  ƒ j | | | | | ƒ d  S(   N(    (    (   t   superR”   R:   (   R8   R   R7   R5   R   R   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR:   Z  s    c         C` s   t  |  j j ƒ S(   sÿ   
        For `numpy.ndarray` compatibility. Ideally this would return a
        `np.core.multiarray.flagsobj`, but that needs to be constructed
        with an existing `numpy.ndarray` (as the C- and F- contiguous flags
        aren't writeable).
        (   R„   R*   R\   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR\   `  s    c         C` s   t  j |  j ƒ S(   sn   
        Magic attribute expected by Numba to get the numba type that
        represents this object.
        (   R	   RN   R   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRO   j  s    N(   RŽ   R   R   R-   R:   R’   R\   RO   (    (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR”   V  s   
c         ` s/   d d l  m ‰  ˆ  j ‡  ‡ f d †  ƒ } | S(   sÙ   
    A separate method so we don't need to compile code every assignment (!).

    :param ndim: We need to have static array sizes for cuda.local.array, so
        bake in the number of dimensions into the kernel
    i    (   t   cudac         ` s  ˆ  j  d ƒ } d } x( t |  j ƒ D] } | |  j | 9} q% W| | k rP d  Sˆ  j j d d ˆ f d t j ƒ } xv t ˆ d d d ƒ D]^ } | |  j | | d | f <| |  j | | j | d k | d | f <| |  j | } q‹ W| t | d ˆ ƒ |  t | d ˆ ƒ <d  S(   Ni   R   i   R   iÿÿÿÿi    (	   t   gridRG   R&   R   t   localR[   R   t   int64R
   (   t   lhst   rhst   locationt
   n_elementsR|   t   idx(   R–   R&   (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   kernel}  s    ,(   t   numbaR–   t   jit(   R&   RŸ   (    (   R–   R&   s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   _assign_kernels  s    Ry   c           B` s°   e  Z d  Z d „  Z e d „  ƒ Z d „  Z d d „ Z d „  Z	 d „  Z
 d d d	 „ Z e j d
 „  ƒ Z d d „ Z d d „ Z e j d „  ƒ Z d d „ Z d d „ Z RS(   s   
    An on-GPU array type
    c         C` s
   |  j  j S(   sA   
        Return true if the array is Fortran-contiguous.
        (   R*   t   is_f_contig(   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   is_f_contiguousœ  s    c         C` s   t  |  j j ƒ S(   sÿ   
        For `numpy.ndarray` compatibility. Ideally this would return a
        `np.core.multiarray.flagsobj`, but that needs to be constructed
        with an existing `numpy.ndarray` (as the C- and F- contiguous flags
        aren't writeable).
        (   R„   R*   R\   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR\   ¢  s    c         C` s
   |  j  j S(   s;   
        Return true if the array is C-contiguous.
        (   R*   t   is_c_contig(   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   is_c_contiguous¬  s    c         C` s   |  j  ƒ  j | ƒ S(   sE   
        :return: an `numpy.ndarray`, so copies to the host.
        (   Ro   t	   __array__(   R8   R   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR§   ²  s    c         C` s   |  j  d S(   Ni    (   R   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   __len__¸  s    c      	   O` sé   t  | ƒ d k r8 t | d t t f ƒ r8 | d } n  t |  ƒ } | |  j k r~ | d |  j d |  j d |  j d |  j ƒ S|  j	 j
 | | Ž  \ } } | |  j	 j g k rÙ | d | j d | j d |  j d |  j ƒ St d ƒ ‚ d S(	   s¶   
        Reshape the array without changing its contents, similarly to
        :meth:`numpy.ndarray.reshape`. Example::

            d_arr = d_arr.reshape(20, 50, order='F')
        i   i    R   R   R   R5   s   operation requires copyingN(   R%   R   R   t   listt   typeR   R   R   R5   R*   t   reshapet   extentRH   (   R8   t   newshapet   kwst   clst   newarrt   extents(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR«   »  s    +RR   i    c         C` sŒ   |  j  | ƒ } t |  ƒ } |  j j d | ƒ \ } } | |  j j g k r| | d | j d | j d |  j d |  j d | ƒ St	 d ƒ ‚ d S(	   sr   
        Flatten the array without changing its contents, similar to
        :meth:`numpy.ndarray.ravel`.
        RP   R   R   R   R5   R7   s   operation requires copyingN(
   RL   Rª   R*   t   ravelR¬   R   R   R   R5   RH   (   R8   RP   R7   R¯   R°   R±   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR²   Ó  s    c         C` s   |  j  | ƒ S(   N(   t   _do_getitem(   R8   t   item(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   __getitem__ä  s    c         C` s   |  j  | | ƒ S(   s0   Do `__getitem__(item)` with CUDA stream
        (   R³   (   R8   R´   R7   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   getitemè  s    c         C` s0  |  j  | ƒ } |  j j | ƒ } t | j ƒ  ƒ } t |  ƒ } t | ƒ d k ré |  j j | d Œ  } | j	 s¸ t
 j d d |  j ƒ} t j d | d | d |  j j d | ƒ | d S| d | j d	 | j d |  j d
 | d | ƒ SnC |  j j | j Œ  } | d | j d	 | j d |  j d
 | d | ƒ Sd  S(   Ni   i    R   t   dstt   srcR   R7   R   R   R5   (   RL   R*   Rµ   R©   t   iter_contiguous_extentRª   R%   R5   Rx   t   is_arrayR   Ri   R   R.   Rk   R)   R   R   R¬   (   R8   R´   R7   t   arrR±   R¯   t   newdataRn   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR³   í  s"    	c         C` s   |  j  | | ƒ S(   N(   t   _do_setitem(   R8   t   keyR?   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   __setitem__  s    c         C` s   |  j  | | | ƒ S(   s6   Do `__setitem__(key, value)` with CUDA stream
        (   t   _so_getitem(   R8   R¾   R?   R7   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   setitem	  s    c         C` sÇ  |  j  | ƒ } |  j j | ƒ } |  j j | j Œ  } t | t j ƒ r` d	 } |  j	 j
 f } n | j } | j } t |  ƒ d | d | d |  j	 d | d | ƒ } t | d | ƒ\ }	 }
 |	 j | j k rë t d |	 j | j f ƒ ‚ n  t j | j d t j ƒ} |	 j | |	 j )|	 j | Œ  }	 xc t t | j |	 j ƒ ƒ D]F \ } \ } } | d k rB| | k rBt d | | | f ƒ ‚ qBqBWt j | j ƒ } t | j ƒ j | d | ƒ| |	 ƒ d  S(
   Ni   R   R   R   R5   R7   s$   Can't assign %s-D array to %s-D selfsC   Can't copy sequence with size %d to array axis %d with dimension %d(   i   (   RL   R*   Rµ   R5   Rx   R¬   R   R   t   ElementR   R)   R   R   Rª   t   auto_deviceR&   R!   R   t   onesR™   R«   t	   enumeratet   zipR,   R¢   t   forall(   R8   R¾   R?   R7   R»   R¼   R   R   Rš   R›   R‹   t	   rhs_shapeR|   t   lt   rR   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR½     s<    				.N(   RŽ   R   R   R¤   R’   R\   R¦   R-   R§   R¨   R«   R²   R   R“   Rµ   R¶   R³   R¿   RÁ   R½   (    (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRy   ˜  s   	
			R…   c           B` s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s"  
    An IPC array handle that can be serialized and transfer to another process
    in the same machine for share a GPU allocation.

    On the destination process, use the *.open()* method to creates a new
    *DeviceNDArray* object that shares the allocation from the original process.
    To release the resources, call the *.close()* method.  After that, the
    destination can no longer use the shared array object.  (Note: the
    underlying weakref to the resource is now dead.)

    This object implements the context-manager interface that calls the
    *.open()* and *.close()* method automatically::

        with the_ipc_array_handle as ipc_array:
            # use ipc_array here as a normal gpu array object
            some_code(ipc_array)
        # ipc_array is dead at this point
    c         C` s   | |  _  | |  _ d  S(   N(   t   _array_desct   _ipc_handle(   R8   R   R‚   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR:   P  s    	c         C` s+   |  j  j t j ƒ  ƒ } t d | |  j  S(   s˜   
        Returns a new *DeviceNDArray* that shares the allocation from the
        original process.  Must not be used on the original process.
        R5   (   RÌ   t   openR   R1   Ry   RË   (   R8   t   dptr(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRÍ   T  s    c         C` s   |  j  j ƒ  d S(   s5   
        Closes the IPC handle to the array.
        N(   RÌ   t   close(   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRÏ   \  s    c         C` s
   |  j  ƒ  S(   N(   RÍ   (   R8   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt	   __enter__b  s    c         C` s   |  j  ƒ  d  S(   N(   RÏ   (   R8   Rª   R?   t	   traceback(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   __exit__e  s    (   RŽ   R   R   R:   RÍ   RÏ   RÐ   RÒ   (    (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyR…   =  s   				t   MappedNDArrayc           B` s   e  Z d  Z d d „ Z RS(   s4   
    A host array that uses CUDA mapped memory.
    i    c         C` s   | |  _  d  S(   N(   R5   (   R8   R5   R7   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   device_setupn  s    (   RŽ   R   R   RÔ   (    (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRÓ   i  s   c      
   C` sL   |  j  d k r! |  j d ƒ }  n  t |  j |  j |  j d |  d | d | ƒS(   s/   Create a DeviceNDArray object that is like ary.i    i   R9   R7   R5   (   R&   R«   Ry   R   R   R   (   R_   R7   R5   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   from_array_liker  s    c         C` s   t  |  j d | d | ƒS(   s.   Create a DeviceRecord object that is like rec.R7   R5   (   R”   R   (   t   recR7   R5   (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   from_record_likez  s    c         C` sZ   |  j  s |  Sg  } x6 |  j  D]+ } | j | d k r; d n	 t d ƒ ƒ q W|  t | ƒ S(   sG  
    Extract the repeated core of a broadcast array.

    Broadcast arrays are by definition non-contiguous due to repeated
    dimensions, i.e., dimensions with stride 0. In order to ascertain memory
    contiguity and copy the underlying data from such arrays, we must create
    a view without the repeated dimensions.

    i    N(   R   t   appendt   sliceR-   R   (   R_   t
   core_indext   stride(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRW     s    
	)s™   Array contains non-contiguous buffer and cannot be transferred as a single memory region. Please ensure contiguous buffer with numpy .ascontiguousarray()c         C` s;   t  |  ƒ } | j d r7 | j d r7 t t ƒ ‚ n  d  S(   NRQ   t   F_CONTIGUOUS(   RW   R\   R!   t   errmsg_contiguous_buffer(   R_   t   core(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRV   —  s    c         C` sÆ   t  j |  ƒ r |  t f St |  d ƒ r> t j j |  ƒ t f St |  t j	 ƒ re t
 |  d | ƒ} n7 t j |  d t d t ƒ}  t |  ƒ t |  d | ƒ} | r¸ | j |  d | ƒn  | t f Sd S(   sº   
    Create a DeviceRecord or DeviceArray like obj and optionally copy data from
    host to device. If obj already represents device memory, it is returned and
    no copy is made.
    RA   R7   RB   RT   N(   R.   RX   R   R   R    R–   t   as_cuda_arrayR   R   t   voidR×   R[   R]   RV   RÕ   Rb   (   R   R7   RB   t   devobj(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRÃ     s    
	
c         C` s°   |  j  ƒ  | j  ƒ  } } |  j | j k rJ t d |  j | j f ƒ ‚ n  | j | j k r{ t d |  j | j f ƒ ‚ n  | j | j k r¬ t d |  j | j f ƒ ‚ n  d  S(   Ns   incompatible dtype: %s vs. %ss   incompatible shape: %s vs. %ss   incompatible strides: %s vs. %s(   R‰   R   RŒ   R   R!   R   (   t   ary1t   ary2t   ary1sqt   ary2sq(    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyRY   »  s    (/   R   t
   __future__R    R   R   Rp   Rt   t	   functoolsRB   R    R   t   ctypesR   t   numpyR   t    R   R.   R   R   R   R	   t   numba.unsafe.ndarrayR
   R   R-   R   R   R   R    R   t   objectR"   R”   R¢   Ry   R…   Rl   RÓ   RÕ   R×   RW   RÝ   RV   R]   RÃ   RY   (    (    (    s=   lib/python2.7/site-packages/numba/cuda/cudadrv/devicearray.pyt   <module>   sD   			ÿ %¥,			