
    J/Ph-                     .   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
 d dlZ	 d dlmZ dZn# e$ r dZY nw xY w eed          Zd Zd	 Z e	d
           ed           G d de
                                  Zedk    r ej                     dS dS )    N)cuda)skip_on_cudasimskip_under_cuda_memcheckCUDATestCase)ThreadPoolExecutorTFget_contextc                  |   t           j        d             fd} d t          d          D             }t          j        d          }|dxx         dz  cc<   t          d          5 }|                    | |          D ]"}t          j                            ||           #	 d d d            d S # 1 swxY w Y   d S )	Nc                 &    | dxx         dz  cc<   d S )Nr       )xs    i/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/cuda/tests/cudapy/test_multithreads.pyfooz'check_concurrent_compiling.<locals>.foo   s    	!	    c                 *     d         |            | S )N)r   r   r   )r   r   s    r   use_fooz+check_concurrent_compiling.<locals>.use_foo   s    D	!r   c                 Z    g | ](}t          j        t          j        d                     )S )
   )r   	to_devicenparange).0is     r   
<listcomp>z.check_concurrent_compiling.<locals>.<listcomp>   s*    ???dnRYr]]++???r   r   r   r      )max_workers)	r   jitranger   r   r   maptestingassert_equal)r   arraysexpectedearyr   s        @r   check_concurrent_compilingr&      s%   	X  X     @?U2YY???Fy}}HQKKK1KKK		*	*	* 3a55&)) 	3 	3CJ##C2222	33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   ):B11B58B5c                     	 t                       |                     d            d S #  t          j                    }|                     d                    dd|g                     Y d S xY w)N
 zP================================================================================)r&   put	traceback
format_excjoin)qmsgs     r   spawn_process_entryr0   &   sm    "$$$ 	
d	."$$	diiXs+,,------s
   ' A A*zHangs cuda-memcheckzdisabled for cudasimc                       e Zd Z ej        e d          d             Z ej        e d          d             Zd Z	d Z
dS )TestMultiThreadCompilingzno concurrent.futuresc                 "    t                       d S N)r&   )selfs    r   test_concurrent_compilingz2TestMultiThreadCompiling.test_concurrent_compiling5   s    "$$$$$r   zno multiprocessing.get_contextc                    t          j                     t          j        d          }|                                }|                    t          |f          }|                                 	 |                                }|	                                 n# |	                                 w xY w|t          |          |                     |j        dd           d S )Nspawntargetargsr   ztest failed in child process)r   get_current_devicemultiprocessingr   QueueProcessr0   startgetr-   AssertionErrorassertEqualexitcode)r5   ctxr.   perrs        r   !test_spawn_concurrent_compilationz:TestMultiThreadCompiling.test_spawn_concurrent_compilation9   s     	!!!)'22IIKKKK2!K>>					%%''CFFHHHHAFFHHHH? %%%Q(FGGGGGs   .B B-c                 F   d }t          j        dd          }t          j        |          }t          j        |          }t          j        |||g          }|                                 |                                 t           j	        
                    ||           d S )Nc                 8    |                                  |d d <   d S r4   )copy_to_host)arrouts     r   d2hzITestMultiThreadCompiling.test_invalid_context_error_with_d2h.<locals>.d2hL   s    %%''CFFFr   r   r   r9   )r   r   
zeros_liker   r   	threadingThreadr@   r-   r    r!   )r5   rN   rL   rM   darrths         r   #test_invalid_context_error_with_d2hz<TestMultiThreadCompiling.test_invalid_context_error_with_d2hK   s    	( 	( 	( i1oomC  ~c""Sc{;;;




			

S)))))r   c                    d }t          j        d          }t          j        |          }t          j        t          j        |j        |j                            }t          j        |||g          }|	                                 |
                                 t           j                            |                                |           d S )Nc                 0    |                      |           d S r4   )copy_to_device)dstsrcs     r   d2dzITestMultiThreadCompiling.test_invalid_context_error_with_d2d.<locals>.d2dX   s    s#####r   d   )dtyper9   )r   r   r   r   zerosshaper\   rP   rQ   r@   r-   r    r!   rK   )r5   rZ   rL   commonrR   rS   s         r   #test_invalid_context_error_with_d2dz<TestMultiThreadCompiling.test_invalid_context_error_with_d2dW   s    	$ 	$ 	$ inn$$~bhv|6<HHHIISf~>>>




			

 1 1 3 3S99999r   N)__name__
__module____qualname__unittestskipIfhas_concurrent_futuresr6   has_mp_get_contextrH   rT   r`   r   r   r   r2   r2   1   s         X_//1HII% % JI% X_++-MNNH H ONH"
* 
* 
*
: 
: 
: 
: 
:r   r2   __main__)r+   rP   r=   numpyr   numbar   numba.cuda.testingr   r   r   rd   concurrent.futuresr   rf   ImportErrorhasattrrg   r&   r0   r2   ra   mainr   r   r   <module>rp      s                        . . . . . . . . . . "555555 "  # # #"# W_m<< 3 3 3"   /00'((.: .: .: .: .:| .: .: )( 10.:b zHMOOOOO s   / 99