ó
\K]c           @   s   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	 m
 Z
 m Z y d  d l m Z Wn e k
 r e Z n Xe Z e e d  Z d   Z d   Z e
 d	  d
 e e j f d     Y Z e d k rü e j   n  d S(   i˙˙˙˙N(   t   cuda(   t   unittest_support(   t   skip_on_cudasimt   SerialMixin(   t   ThreadPoolExecutort   get_contextc             s´   t  j d        f d   }  g  t d  D] } t j d  ^ q. } t j d  } | d c d 7<t d d  7 } x- | j |  |  D] } t j j | |  q WWd  QXd  S(   Nc         S   s   |  d c d 7<d  S(   Ni    i   (    (   t   x(    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   foo   s    c            s     |   |  S(   N(    (   R   (   R   (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   use_foo   s    
i
   i    i   t   max_workersi   (	   R    t   jitt   ranget   npt   arangeR   t   mapt   testingt   assert_equal(   R   t   it   arrayst   expectedt   et   ary(    (   R   sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   check_concurrent_compiling   s    (c         C   sU   y t    Wn6 t j   } |  j d j d d d | g   n X|  j d   d  S(   Ns   
t    t   =iP   (   R   t	   tracebackt
   format_exct   putt   joint   None(   t   qt   msg(    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   spawn_process_entry%   s    's   disabled for cudasimt   TestMultiThreadCompilingc           B   sR   e  Z e j e d   d    Z e j e d  d    Z d   Z d   Z	 RS(   s   no concurrent.futuresc         C   s   t    d  S(   N(   R   (   t   self(    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   test_concurrent_compiling2   s    s   no multiprocessing.get_contextc         C   s   t  j   t j d  } | j   } | j d t d | f  } | j   z | j   } Wd  | j	   X| d  k	 r t |   n  |  j | j d d  d  S(   Nt   spawnt   targett   argsi    s   test failed in child process(   R    t   get_current_devicet   multiprocessingR   t   Queuet   ProcessR    t   startt   getR   R   t   AssertionErrort   assertEqualt   exitcode(   R"   t   ctxR   t   pt   err(    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt!   test_spawn_concurrent_compilation6   s    

c         C   s   d   } t  j d d  } t  j |  } t j |  } t j d | d | | g  } | j   | j   t  j	 j
 | |  d  S(   Nc         S   s   |  j    | (d  S(   N(   t   copy_to_host(   t   arrt   out(    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   d2hI   s    i   i   R%   R&   (   R   R   t
   zeros_likeR    t	   to_devicet	   threadingt   ThreadR+   R   R   R   (   R"   R7   R5   R6   t   darrt   th(    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt#   test_invalid_context_error_with_d2hH   s    	

c         C   s   d   } t  j d  } t j |  } t j t  j | j d | j  } t j d | d | | g  } | j	   | j
   t  j j | j   |  d  S(   Nc         S   s   |  j  |  d  S(   N(   t   copy_to_device(   t   dstt   src(    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   d2dU   s    id   t   dtypeR%   R&   (   R   R   R    R9   t   zerost   shapeRC   R:   R;   R+   R   R   R   R4   (   R"   RB   R5   t   commonR<   R=   (    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt#   test_invalid_context_error_with_d2dT   s    	$

(
   t   __name__t
   __module__t   unittestt   skipIft   has_concurrent_futuresR#   t   has_mp_get_contextR3   R>   RG   (    (    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyR!   /   s   	t   __main__(   R   R:   R(   t   numpyR   t   numbaR    R   RJ   t   numba.cuda.testingR   R   t   concurrent.futuresR   t   ImportErrort   FalseRL   t   Truet   hasattrRM   R   R    t   TestCaseR!   RH   t   main(    (    (    sH   lib/python2.7/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyt   <module>   s$   
		
1