
    ,ii                     t   d Z ddlZddlmZ ddlZddlZddlmZ ddlZ	ddl
mZmZ ddlmZmZmZ ddlmZmZmZmZmZmZ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!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+ ddl,m-Z- ddl.m/Z/m0Z0 ddl
m1Z1 ddl2m3Z4 ddl5m6Z7 ddl8m9Z9 ddlm:Z: ddl;m<Z<m=Z= ddl>m?Z?m@Z@ ddlAmBZB  G d de          ZCeCed<    G d de*          ZD e0            ZE G d de%          ZF G d  d!e           ZG eGd          ZH G d" d#e          ZIeIeed         <    G d$ d%e          ZJeJeed         <   eEK                    ejL                  d&             ZMeEN                    ejO        ejP                  d'             ZQeEK                    ejP                  d(             ZReEK                    ejS                  d)             ZT ed*          d+             ZU eejV        d*          d,             ZW G d- d.e          ZX G d/ d0e          ZYeZd1k    r ej[                     dS dS )2a  This tests the target extension API to ensure that rudimentary expected
behaviours are present and correct. It uses a piece of fake hardware as a
target, the Dummy Processing Unit (DPU), to do this. The DPU borrows a lot from
the CPU but is part of the GPU class of target. The DPU target has deliberately
strange implementations of fundamental operations so as to make it identifiable
in testing.    N)TestCase)cached_property)njittypes)overload	intrinsicoverload_classmethod)JitDecoratortarget_registrydispatcher_registryjit_registrytarget_overrideGPUresolve_dispatcher_from_str)utilsfastmathpasserrors)
Dispatcher)TargetDescriptor)cputypingcgutils)BaseContext)global_compiler_lock)callconv)
CPUCodegenJITCodeLibrary)PyCallWrapper)RegistryLoaderRegistry)_dynfunc)ir)rtsys)compiler)CompilerBaseDefaultPassBuilder)FunctionPassregister_pass)PreLowerStripPhisc                       e Zd ZdS )DPUN)__name__
__module____qualname__     _/var/www/html/speakWrite/venv/lib/python3.11/site-packages/numba/tests/test_target_extension.pyr+   r+   1   s        Cr0   r+   dpuc                   *    e Zd ZeZd Zd Zd Zd ZdS )JITDPUCodegenc                 l   |                                  |d<   t          j                                        j        }|                    d          rd}n|                    d          rd}nd}||d<   d|d	<   | j        |d
<   t          j        t          j        j	                  }d|j
        v rd|d<   d S d S )Nr   x86staticppcpicdefaultreloc
jitdefault	codemodelfeaturesjitT)_get_host_cpu_namellTargetfrom_default_triplename
startswith_tm_featuresr   pysignaturecreate_target_machine
parameters)selfoptionsarchreloc_modelsigs        r1   _customize_tm_optionsz#JITDPUCodegen._customize_tm_optionsA   s    0022y,,..3??5!! 	$"KK__U## 	$KK#K&+ #/
 	 ?@@CN""!GENNN #"r0   c                 *    |                                  S N)_get_host_cpu_featuresrJ   s    r1   _customize_tm_featuresz$JITDPUCodegen._customize_tm_featuresX   s    **,,,r0   c                 :    | j                             |           d S rQ   )_engine
add_module)rJ   modules     r1   _add_modulezJITDPUCodegen._add_module\   s    '''''r0   c                     | j                             |          }t          j        dz                      |          }t          j        t          |                    |d<   dS )zrSet the environment address.

        Update the GlobalVariable named *env_name* to the address of *env*.
           r   N)rV   get_global_value_addressctypesc_void_pfrom_addressid)rJ   env_nameenvgvaddrenvptrs        r1   set_envzJITDPUCodegen.set_env_   sP    
 66x@@/A%33F;;OBsGG,,q			r0   N)	r,   r-   r.   r   _library_classrO   rT   rY   re   r/   r0   r1   r4   r4   <   sW         $N" " ".- - -( ( (- - - - -r0   r4   c                       e Zd ZdZd Zed             Zd Zed             Z	d Z
ed             Zd Zd	 Zd
 Zd Z	 ddZd Zd ZdS )
DPUContextTc                 6    | j                             |          S rQ   )_internal_codegen_create_empty_module)rJ   rD   s     r1   create_modulezDPUContext.create_modules   s    %::4@@@r0   c                 ~    t          d          | _        t          j        |            |                                  d S )Nz
numba.exec)r4   rj   r#   
initializerefreshrS   s    r1   initzDPUContext.initv   s4    !.|!<!<r0   c                     t           }	 | j        |         }n)# t          $ r t          |          }|| j        |<   Y nw xY w|                     |           | j                                         d S rQ   )dpu_function_registry_registriesKeyErrorr   install_registrytyping_contextro   )rJ   registryloaders      r1   ro   zDPUContext.refresh}   s    (	0%h/FF 	0 	0 	0#H--F)/DX&&&	0 	h''' 	##%%%%%s    #==c                     | j         j        S rQ   )rj   target_datarS   s    r1   rz   zDPUContext.target_data   s    %11r0   c                     | j         S rQ   )rj   rS   s    r1   codegenzDPUContext.codegen   s    %%r0   c                 *    t          j        |           S rQ   )r   CPUCallConvrS   s    r1   	call_convzDPUContext.call_conv   s    #D)))r0   c                 ~    t          j        ||t          j        d                   }t	          j        | ||d          S )z
        From the given *envptr* (a pointer to a _dynfunc.Environment object),
        get a EnvBody allowing structured access to environment fields.
        offsetof_env_bodyT)refcast_ref)r   pointer_addr!   
_impl_infor   EnvBody)rJ   builderrd   body_ptrs       r1   get_env_bodyzDPUContext.get_env_body   sA    
 &VX01DE
 
 {4hFFFFr0   c                 b   |                      |j        |                     | j                            }|                    |          }|                     |          }|                    || j        j                   |                     ||          }|	                    | j
        ||          S )N)	debug_msg)declare_env_globalrX   get_env_namefndescloadget_python_apiemit_environment_sentryra   r   get_env_managerenvironment)rJ   r   envgvenvargpyapienv_bodys         r1   r   zDPUContext.get_env_manager   s    ''ND--dk::
 
 e$$##G,,%%dk2 	& 	
 	
 	
 $$Wf55$$T%5xHHHr0   c                 R    t          j        ||t          j        d         |          S )z~
        From the given *genptr* (a pointer to a _dynfunc.Generator object),
        get a pointer to its state area.
        offsetof_generator_state)return_type)r   r   r!   r   )rJ   r   genptrr   s       r1   get_generator_statezDPUContext.get_generator_state   s3    
 " :;#	
 
 
 	
r0   c                     | j         rt          j        || j                    |                    t          j                   d S rQ   )fastmathr   rewrite_moduleadd_linking_libraryr#   library)rJ   modr   s      r1   post_loweringzDPUContext.post_lowering   s=    = 	<'T];;;##EM22222r0   Fc           	      .   |                      d          }| j                            |j        |j                  }t          j        |||j                  }t          | ||||||          }	|		                                 |
                    |           d S )Nwrapper)call_helperrelease_gil)rl   r   get_function_typerestypeargtypesllirFunctionllvm_func_namer   buildadd_ir_module)
rJ   r   r   rb   r   r   wrapper_modulefntywrapper_calleer   s
             r1   create_cpython_wrapperz!DPUContext.create_cpython_wrapper   s     ++I66~//PPD&"7
 
  ##
 
 
 	n-----r0   c                     d S rQ   r/   )rJ   r   r   rb   r   s        r1   create_cfunc_wrapperzDPUContext.create_cfunc_wrapper   s    r0   c                 >   |                     |j                  }d|j        }t          j        |                                |j                            d          d         ||||f          }|j                            | 	                    |          |           |S )z
        Returns
        -------
        (cfunc, fnptr)

        - cfunc
            callable function (Can be None)
        - fnptr
            callable function address
        - env
            an execution environment (from _dynfunc)
        zcompiled wrapper for .)
get_pointer_to_functionllvm_cpython_wrapper_namequalnamer!   make_functionlookup_modulesplitr|   re   r   )rJ   r   r   rb   fnptrdoccfuncs          r1   get_executablezDPUContext.get_executable   s     //,
 
 ,2??<&  ""O!!#&&r*J
 
 	 1 1& 9 93???r0   N)F)r,   r-   r.   allow_dynamic_globalsrl   r   rp   ro   propertyrz   r|   r   r   r   r   r   r   r   r   r   r/   r0   r1   rh   rh   o   s        A A A   
& 
& 
& 2 2 X2& & & * * _*G G G
I 
I 
I

 

 

3 3 3 >C. . . .(      r0   rh   c                   t    e Zd Zej        Zed             Zed             Ze	d             Z
e	d             ZdS )	DPUTargetc                 6    t          | j        | j                  S rQ   )rh   rv   _target_namerS   s    r1   _toplevel_target_contextz"DPUTarget._toplevel_target_context   s     $-t/@AAAr0   c                 (    t          j                    S rQ   )r   ContextrS   s    r1   _toplevel_typing_contextz"DPUTarget._toplevel_typing_context   s     ~r0   c                     | j         S )z5
        The target context for DPU targets.
        )r   rS   s    r1   target_contextzDPUTarget.target_context      
 ,,r0   c                     | j         S )z5
        The typing context for CPU targets.
        )r   rS   s    r1   rv   zDPUTarget.typing_context  r   r0   N)r,   r-   r.   r   CPUTargetOptionsrK   r   r   r   r   r   rv   r/   r0   r1   r   r      s        "GB B _B     _  - - X- - - X- - -r0   r   c                       e Zd ZeZdS )DPUDispatcherN)r,   r-   r.   
dpu_targettargetdescrr/   r0   r1   r   r     s        KKKr0   r   c                   &    e Zd Zd Zd Zd Zd ZdS )djitc                 "    || _         || _        d S rQ   )_args_kwargs)rJ   argskwargss      r1   __init__zdjit.__init__%  s    
r0   c                     t          |          dk     sJ |r	|d         }n| j        d         }|| _        |                                 S )N   r   )lenr   py_funcdispatcher_wrapper)rJ   r   funcs      r1   __call__zdjit.__call__)  sL    4yy1}}}} 	!7DD:a=D&&(((r0   c                 2    t           t          d                  S )z(
        Returns the dispatcher
        r2   )r   r   rS   s    r1   get_dispatcherzdjit.get_dispatcher3  s     #?5#9::r0   c                     |                                  }i }d| j        v rd|d<   t          j        }d| j        v r| j        d         } || j        ||          S )NnopythonTpipeline_class)r   targetoptionsr   )r   r   r$   Compilerr   )rJ   disptoptr   s       r1   r   zdjit.dispatcher_wrapper9  sw    ""$$%%#D "*t|++!\*:;NtL)
 
 
 	
r0   N)r,   r-   r.   r   r   r   r   r/   r0   r1   r   r   $  sP          ) ) ); ; ;
 
 
 
 
r0   r   c                 *    |                                  S rQ   )get_dummy_value)contextr   typyvals       r1   constant_dummyr   U  s    ""$$$r0   c                 ~    |                      ||j        |j                  }|                     |||j        |          S rQ   )get_constant_genericliteral_typeliteral_valuecast)r   r   fromtytotyvallits         r1   literal_int_to_numberr   [  sA    

&
&$f&: C <<f&94@@@r0   c                 B    |                      |          } ||          S rQ   get_value_typer   r   r   r   ltys        r1   	const_intr  d  #    

 
 
$
$C3u::r0   c                 B    |                      |          } ||          S rQ   r   r  s        r1   const_floatr  k  r  r0   targetc                 (     |||          }d }||fS )Nc                      |j         | S rQ   subcgctxr   tyargsllargss       r1   r|   zintrin_add.<locals>.codegenv  s    w{F##r0   r/   tyctxxyrN   r|   s        r1   
intrin_addr  r  s,    
!Aq''C$ $ $ <r0   c                 |    t          | t          j                  rt          |t          j                  rd }|S d S d S )Nc                 "    t          | |          S rQ   )r  )r  r  s     r1   implzol_add.<locals>.impl  s    a###r0   )
isinstancer   Integer)r  r  r  s      r1   ol_addr  }  sS    !U]## 
1em(D(D 	$ 	$ 	$    r0   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )TestTargetHierarchySelectionzThis tests that the target hierarchy is scanned in the right order,
    that appropriate functions are selected based on what's available and that
    the DPU target is distinctly different to the CPUc                 6   |                      t          j                   |                      t          j                   |                     t          t          j                  d           |                     t          t          j                  d           dS )zChecks that the DPU registry only contains the things added

        This test must be first to execute among all tests in this file to
        ensure the no lazily loaded entries are added yet.
        r[      N)assertFalserr   	functionsgetattrsassertEqualr   casts	constantsrS   s    r1   test_0_dpu_registryz0TestTargetHierarchySelection.test_0_dpu_registry  s~     	.8999.788828991===2<==qAAAAAr0   c                 R   d t          d          d             }t          d          d             }t                      fd            }t                      fd            }|                      |            d	           |                      |            d
           d S )Nc                     d S rQ   r/   r  s    r1   my_funczATestTargetHierarchySelection.test_specialise_gpu.<locals>.my_func      Dr0   genericr  c                     d }|S )Nc                     d| z   S Nr[   r/   r)  s    r1   r  zSTestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func1.<locals>.impl      1ur0   r/   r  r  s     r1   ol_my_func1zETestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func1         Kr0   gpuc                     d }|S )Nc                     d| z   S N
   r/   r)  s    r1   r  zSTestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func2.<locals>.impl      Avr0   r/   r1  s     r1   ol_my_func2zETestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func2         Kr0   c                        d          S N   r/   r*  s   r1   dpu_foozATestTargetHierarchySelection.test_specialise_gpu.<locals>.dpu_foo      71::r0   c                        d          S r=  r/   r?  s   r1   cpu_foozATestTargetHierarchySelection.test_specialise_gpu.<locals>.cpu_foo  rA  r0   r     r   r   r   assertPreciseEqual)rJ   r2  r:  r@  rC  r*  s        @r1   test_specialise_gpuz0TestTargetHierarchySelection.test_specialise_gpu  s    	 	 	 
')	,	,	,	 	 
-	,	 
'%	(	(	(	 	 
)	(	 
	 	 	 	 
	 
	 	 	 	 
	
 			1---		1-----r0   c                    d t          d          d             }t          d          d             }t          d          d             }t                      fd	            }t                      fd
            }|                      |            d           |                      |            d           d S )Nc                     d S rQ   r/   r)  s    r1   r*  zATestTargetHierarchySelection.test_specialise_dpu.<locals>.my_func  r+  r0   r,  r  c                     d }|S )Nc                     d| z   S r/  r/   r)  s    r1   r  zSTestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func1.<locals>.impl  r0  r0   r/   r1  s     r1   r2  zETestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func1  r3  r0   r4  c                     d }|S )Nc                     d| z   S r7  r/   r)  s    r1   r  zSTestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func2.<locals>.impl  r9  r0   r/   r1  s     r1   r:  zETestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func2  r;  r0   r2   c                     d }|S )Nc                     d| z   S )Nd   r/   r)  s    r1   r  zSTestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func3.<locals>.impl  s    Qwr0   r/   r1  s     r1   ol_my_func3zETestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func3  s       Kr0   c                        d          S r=  r/   r?  s   r1   r@  zATestTargetHierarchySelection.test_specialise_dpu.<locals>.dpu_foo  rA  r0   c                        d          S r=  r/   r?  s   r1   rC  zATestTargetHierarchySelection.test_specialise_dpu.<locals>.cpu_foo  rA  r0   ]   rD  rE  )rJ   r2  r:  rQ  r@  rC  r*  s         @r1   test_specialise_dpuz0TestTargetHierarchySelection.test_specialise_dpu  s   	 	 	 
')	,	,	,	 	 
-	,	 
'%	(	(	(	 	 
)	(	 
'%	(	(	(	 	 
)	(	 
	 	 	 	 
	 
	 	 	 	 
	
 			2...		1-----r0   c                 x   d t          d          d             }t          d          fd            }t          j        t          j        f}|                     |          5 } |             d d d            n# 1 swxY w Y   g d}|D ]*}|                     |t          |j                             +d S )	Nc                     d S rQ   r/   r)  s    r1   r*  zJTestTargetHierarchySelection.test_no_specialisation_found.<locals>.my_func  r+  r0   cudar  c                     d S )Nc                     d S rQ   r/   r)  s    r1   <lambda>zdTestTargetHierarchySelection.test_no_specialisation_found.<locals>.ol_my_func_cuda.<locals>.<lambda>  s    T r0   r/   r)  s    r1   ol_my_func_cudazRTestTargetHierarchySelection.test_no_specialisation_found.<locals>.ol_my_func_cuda  s
    !>!r0   Tr   c                        d           d S r/  r/   r?  s   r1   r@  zJTestTargetHierarchySelection.test_no_specialisation_found.<locals>.dpu_foo  s    GAJJJJJr0   )8Function resolution cannot find any matches for functionz-test_no_specialisation_found.<locals>.my_funczfor the current target:z''numba.tests.test_target_extension.DPU')	r   r   r   UnsupportedErrorTypingErrorassertRaisesassertInstr	exception)rJ   r\  r@  acceptraisesmsgsmsgr*  s          @r1   test_no_specialisation_foundz9TestTargetHierarchySelection.test_no_specialisation_found  s=   	 	 	 
'&	)	)	)	" 	" 
*	)	" 
t				 	 	 	 
		
 )6+=>v&& 	&GIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	; ; ;
  	6 	6CMM#s6#3445555	6 	6s   'A>>BBc                    |                      t          j                  5 }t          d          d             } |             d d d            n# 1 swxY w Y   d}|                     |t          |j                             d S )Ninvalid_silicon)_targetc                      d S rQ   r/   r/   r0   r1   foozATestTargetHierarchySelection.test_invalid_target_jit.<locals>.foo  s    r0   1No target is registered against 'invalid_silicon')rb  r   NumbaValueErrorr   rc  rd  re  )rJ   rg  ro  ri  s       r1   test_invalid_target_jitz4TestTargetHierarchySelection.test_invalid_target_jit  s    v566 	&+,,,  -, CEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Bc3v/0011111s   $AAAc                 <   d |                      t          j                  5 }t          d          d             }t          fd            } |             d d d            n# 1 swxY w Y   d}|                     |t          |j                             d S )Nc                      d S rQ   r/   r/   r0   r1   barzFTestTargetHierarchySelection.test_invalid_target_overload.<locals>.bar  r+  r0   rl  r  c                      d S )Nc                      d S rQ   r/   r/   r0   r1   r[  z[TestTargetHierarchySelection.test_invalid_target_overload.<locals>.ol_bar.<locals>.<lambda>  s     r0   r/   r/   r0   r1   ol_barzITestTargetHierarchySelection.test_invalid_target_overload.<locals>.ol_bar  s
    $}$r0   c                                     d S rQ   r/   )ru  s   r1   ro  zFTestTargetHierarchySelection.test_invalid_target_overload.<locals>.foo  s    r0   rp  )rb  r   ra  r   r   rc  rd  re  )rJ   rg  rx  ro  ri  ru  s        @r1   test_invalid_target_overloadz9TestTargetHierarchySelection.test_invalid_target_overload  s   	 	 	
 v122 		fc"3444% % 54%     T CEEE		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 Bc3v/0011111s   7A''A+.A+c                    t          d          d             t          d          d             t          d          d             t          fd            }|                      |            d	           t          fd
            }|                      |            d           t          fd            }t          j        t          j        f}|                     |          5 } |             ddd           n# 1 swxY w Y   g d}|D ]*}|                     |t          |j	                             +t          d          fd            }|                      |            d           t          d          fd            }	|                      |	            d           t          d          fd            }
t          j        t          j        f}|                     |          5 } |
             ddd           n# 1 swxY w Y   g d}|D ]*}|                     |t          |j	                             +dS )z
        Test to make sure that targets can share generic implementations and
        cannot reach implementations that are not in their target hierarchy.
        r,  r  c                 (     |||          }d }||fS )Nc                      |j         | S rQ   )mulr  s       r1   r|   zcTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_generic.<locals>.codegen-      "w{F++r0   r/   r  s        r1   intrin_math_genericzRTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_generic)  ,    !Aq''C, , , <r0   r2   c                 (     |||          }d }||fS )Nc                      |j         | S rQ   r  r  s       r1   r|   z_TestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_dpu.<locals>.codegen6  r  r0   r/   r  s        r1   intrin_math_dpuzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_dpu2  r  r0   r   c                 (     |||          }d }||fS )Nc                      |j         | S rQ   )addr  s       r1   r|   z_TestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_cpu.<locals>.codegen?  r  r0   r/   r  s        r1   intrin_math_cpuzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_cpu;  r  r0   c                        dd          S Nr     r/   r  s   r1   cpu_foo_specificzOTestTargetHierarchySelection.test_intrinsic_selection.<locals>.cpu_foo_specificE      "?1a(((r0   r>  c                        dd          S r  r/   r  s   r1   cpu_foo_genericzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.cpu_foo_genericL      &&q!,,,r0      c                        dd          S r  r/   r  s   r1   cpu_foo_dpuzJTestTargetHierarchySelection.test_intrinsic_selection.<locals>.cpu_foo_dpuS  r  r0   N)r_  zintrinsic intrin_math_dpufor the current targetTr]  c                        dd          S r  r/   r  s   r1   dpu_foo_specificzOTestTargetHierarchySelection.test_intrinsic_selection.<locals>.dpu_foo_specificb  r  r0   r   c                        dd          S r  r/   r  s   r1   dpu_foo_genericzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.dpu_foo_generici  r  r0   c                        dd          S r  r/   r  s   r1   dpu_foo_cpuzJTestTargetHierarchySelection.test_intrinsic_selection.<locals>.dpu_foo_cpup  r  r0   )r_  zintrinsic intrin_math_cpur  )r   r   r#  r   r`  ra  rb  rc  rd  re  r   )rJ   r  r  r  rf  rg  rh  ri  r  r  r  r  r  r  s              @@@r1   test_intrinsic_selectionz5TestTargetHierarchySelection.test_intrinsic_selection"  s    
)	$	$	$	  	  
%	$	  
%	 	 	 	  	  
!	 	  
%	 	 	 	  	  
!	 	  
	) 	) 	) 	) 
	) 	))++Q/// 
	- 	- 	- 	- 
	- 	**B/// 
	) 	) 	) 	) 
	) )6+=>v&& 	&KMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	+ + +  	6 	6CMM#s6#3445555 
t				) 	) 	) 	) 
		) 	))++R000 
t				- 	- 	- 	- 
		- 	**B/// 
t				) 	) 	) 	) 
		) )6+=>v&& 	&KMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	+ + +  	6 	6CMM#s6#3445555	6 	6s$   .DD	D	;HHHc                   	
 d 	t          d          	fd            
t          t          j        ddddi          
fd	            }t	          t
          j        dddi          d
             }d t	          dddi          d             }ddlm}  |d          5  t          d          fd            } |            }d d d            n# 1 swxY w Y   ddl
m} |                     ||j                   d S )Nc                 J   |j         |j         k    r|S |j         |j         k     r)|                    ||                     |                    S |j        r)|                    ||                     |                    S |                    ||                     |                    S rQ   )bitwidthtruncr   signedsextzext)r   r   r   r   r   s        r1   cast_integerzKTestTargetHierarchySelection.test_overload_allocation.<locals>.cast_integer  s    }//
00}}S'*@*@*F*FGGG G||C)?)?)E)EFFF ||C)?)?)E)EFFFr0   r2   r  c                 x    fd}ddl m} t          j        t          j                  } ||||          }||fS )z;Intrinsic to call into the allocator for Array
            c                     |\  }} | |||j         d         t          j                  }| j                            |||          }|S r/  )r   r   uint32nrtmeminfo_alloc_aligned)	r   r   	signaturer   	allocsizealign	align_u32meminfor  s	           r1   r|   z\TestTargetHierarchySelection.test_overload_allocation.<locals>.intrin_alloc.<locals>.codegen  s[    %)"E )L'5)2):ELJ J	!+;;GY<EG Gr0   r   )r  )numba.core.typingr  r   MemInfoPointervoidptr)	typingctxr  r  r|   r  miprN   r  s          r1   intrin_alloczKTestTargetHierarchySelection.test_overload_allocation.<locals>.intrin_alloc  s_    	 	 	 	 	 433333&u}55C)CE22C<r0   	_allocater   T)r  jit_optionsc                     fd}|S )Nc                      ||          S rQ   r/   )clsr  r  r  s      r1   r  zaTestTargetHierarchySelection.test_overload_allocation.<locals>._ol_arr_allocate_dpu.<locals>.impl  s    #|Iu555r0   r/   )r  r  r  r  r  s       r1   _ol_arr_allocate_dpuzSTestTargetHierarchySelection.test_overload_allocation.<locals>._ol_arr_allocate_dpu  s!    6 6 6 6 6Kr0   c                     d }|S )Nc                 B    t           j                            | d          S r=  )r   Arrayr  )ns    r1   r  zZTestTargetHierarchySelection.test_overload_allocation.<locals>.ol_empty_impl.<locals>.impl  s    {,,Q222r0   r/   )r  r  s     r1   ol_empty_implzLTestTargetHierarchySelection.test_overload_allocation.<locals>.ol_empty_impl  s    3 3 3Kr0   c                      d S rQ   r/   r/   r0   r1   buffer_funczJTestTargetHierarchySelection.test_overload_allocation.<locals>.buffer_func  r+  r0   c                      d } | S )Nc                  *    t          j        d          S r7  )npemptyr/   r0   r1   r  z`TestTargetHierarchySelection.test_overload_allocation.<locals>.ol_buffer_func_impl.<locals>.impl  s    x||#r0   r/   )r  s    r1   ol_buffer_func_implzRTestTargetHierarchySelection.test_overload_allocation.<locals>.ol_buffer_func_impl  s    $ $ $Kr0   r   )r   r]  c                                    S rQ   r/   )r  s   r1   ro  zBTestTargetHierarchySelection.test_overload_allocation.<locals>.foo  s    "{}}$r0   )r  )r   r	   r   r  r   r  r  numba.core.target_extensionr   r   numba.core.runtimer  assertIsInstanceMemInfo)rJ   r  r  r  r   ro  rr  r  r  r  s           @@@r1   test_overload_allocationz5TestTargetHierarchySelection.test_overload_allocation~  s   	G 	G 	G 
%	 	 	 	  	  	  	  
!	 	 & 
ek;u+5d*;
= 
= 
=	 	 	 	
= 
=	
 
"(5z$6G	H	H	H	 	 
I	H	
	 	 	 
+e*T9J	K	K	K	 	 
L	K	
 	@????? _U## 	 	4   % % % % ! %A		 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 	+*****a-----s   $&CCCN)r,   r-   r.   __doc__r&  rG  rU  rj  rr  rz  r  r  r/   r0   r1   r  r    s        9 9B B B .  .  .D(. (. (.T6 6 68
2 
2 
22 2 2*Z6 Z6 Z6xC. C. C. C. C.r0   r  c                       e Zd ZdZd ZdS )TestTargetOffloada  In this use case the CPU compilation pipeline is extended with a new
     compilation pass that runs just prior to lowering. The pass looks for
     function calls and when it finds one it sees if there's a DPU function
     available that is a valid overload for the function call. If there is one
     then it swaps the CPU implementation out for a DPU implementation. This
     producing an "offload" effect.
    c                 b   dt          t          j        d          d             }t          d          d             }|                      |d          d	           t
          d
             }|                      |d          t          j        d                     t          dd           G fddt                                 G fddt                    }t          |          d             }|                      |d          d	t          j	        d          f           d S )NFr2   r  c                     d }|S )Nc                     dS )N    ,Ar/   r)  s    r1   dpu_sin_implzQTestTargetOffload.test_basic_offload.<locals>.ol_np_sin_DPU.<locals>.dpu_sin_impl  s    xr0   r/   )r  r  s     r1   ol_np_sin_DPUz;TestTargetOffload.test_basic_offload.<locals>.ol_np_sin_DPU  s           r0   Tr]  c                 *    t          j        |           S rQ   r  sinr)  s    r1   ro  z1TestTargetOffload.test_basic_offload.<locals>.foo      6!99r0      r  c                 *    t          j        |           S rQ   r  r)  s    r1   ro  z1TestTargetOffload.test_basic_offload.<locals>.foo  r  r0   )mutates_CFGanalysis_onlyc                   $    e Zd ZdZd Z fdZdS )@TestTargetOffload.test_basic_offload.<locals>.DispatcherSwitcherDispatcherSwitcherc                 .    t          j        |            d S rQ   )r'   r   rS   s    r1   r   zITestTargetOffload.test_basic_offload.<locals>.DispatcherSwitcher.__init__  s    %d+++++r0   c           
      t   |j         }d}|j                                        D ]}|                    d          D ]}|j        |j        j                 }d}t          |          5  	 |                    |j	        |j
        |         j        i           }t          |          }	|	j        j        }
|
                    ||           n># t           $ r1}rd| d| d| }t#          |           Y d }~d d d            d }~ww xY w|j        j        |
_        ||_        d}d d d            n# 1 swxY w Y   |S )NFcallr2   z+Failed to find and compile an overload for z for z due to T)func_irblocksvalues
find_exprstypemapr   rD   r   get_call_typer  	calltypesr   r   r   r   get_function	Exceptionprint	targetctx_codelib_stackr  )rJ   stater  mutatedblkr  functiontnamerN   r   hw_ctxeri  _DEBUGs                r1   run_passzITestTargetOffload.test_basic_offload.<locals>.DispatcherSwitcher.run_pass  s   -">0022 ++ ++C !$v 6 6 (+ (+#(=#@ % -U33 "+ "+)&.&<&<$)O$)OD$9$>$&'" '"
 (C5'I'I)-)9)H & 3 3Hc B B B B#, ) ) )#) !/)68@)6 )6GL)6 )623)6 )6 %(
 %*#JJJ ('"+ "+ "+ "+ "+ "+ "+) !& > #1 +0DK&*GE"+ "+ "+ "+ "+ "+ "+ "+ "+ "+ "+ "+ "+ "+ "+(+T s=   &D*(ACD*
D	C<	,D*<D	D**D.1D.N)r,   r-   r.   _namer   r  )r  s   r1   r  r    sB        (E, , ,0 0 0 0 0 0 0r0   r  c                       e Zd Z fdZdS )@TestTargetOffload.test_basic_offload.<locals>.DPUOffloadCompilerc                     t          j        | j                  }|                    t                     |                                 |gS rQ   )r&   define_nopython_pipeliner  add_pass_afterr)   finalize)rJ   pmr  s     r1   define_pipelineszQTestTargetOffload.test_basic_offload.<locals>.DPUOffloadCompiler.define_pipelines#  sA    '@LL!!"46GHHHtr0   N)r,   r-   r.   r  )r  s   r1   DPUOffloadCompilerr  "  s.              r0   r  )r   c                 R    t          j        |           t          j        |           fS rQ   )r  r  cosr)  s    r1   ro  z1TestTargetOffload.test_basic_offload.<locals>.foo+  s    6!99bfQii''r0   )
r   r  r  r   rF  r   r(   r'   r%   r  )rJ   r  ro  r  r  r  s       @@r1   test_basic_offloadz$TestTargetOffload.test_basic_offload  s    
"&	'	'	'	  	  
(	'	  
t				 	 
		 	A111 
	 	 
	 	Aq		222	5	>	>	>6	 6	 6	 6	 6	 6	 6	 6	 6	 
?	>6	r	 	 	 	 	 	 	 	 	 	 
/	0	0	0	( 	( 
1	0	( 	A26!99(=>>>>>r0   N)r,   r-   r.   r  r  r/   r0   r1   r  r    s2         b? b? b? b? b?r0   r  __main__)\r  unittestnumba.tests.supportr   r]   operator	functoolsr   numpyr  numbar   r   numba.extendingr   r   r	   r  r
   r   r   r   r   r   r   
numba.corer   r   r   numba.core.dispatcherr   numba.core.descriptorsr   r   r   r   numba.core.baser   numba.core.compiler_lockr   r   numba.core.codegenr   r   numba.core.callwrapperr   numba.core.imputilsr   r    r!   llvmlite.bindingbindingrA   llvmliter"   r   r  r#   r$   numba.core.compilerr%   r&   numba.core.compiler_machineryr'   r(   numba.core.typed_passesr)   r+   r4   rr   rh   r   r   r   r   lower_constantDummyr   
lower_castIntegerLiteralr  r   r  Floatr  r  r  r  r  r  r,   mainr/   r0   r1   <module>r%     sS     ( ( ( ( ( (   % % % % % %             E E E E E E E E E E                  3 2 2 2 2 2 2 2 2 2 , , , , , , 3 3 3 3 3 3 + + + + + + + + + + ' ' ' ' ' ' 9 9 9 9 9 9       9 9 9 9 9 9 9 9 0 0 0 0 0 0 8 8 8 8 8 8 8 8                   $ $ $ $ $ $       @ @ @ @ @ @ @ @ E E E E E E E E 5 5 5 5 5 5    #     
*- *- *- *- *-J *- *- *-\ !

 
E E E E E E E ER- - - - -  - - -: Yu
    J    /< OE* +
%
 %
 %
 %
 %
< %
 %
 %
T (,_U# $ %%ek22% % 32%
 !!%"6FFA A GFA %%em44  54 %%ek22  32 %   
(,u%%%  &%z. z. z. z. z.8 z. z. z.z	k? k? k? k? k? k? k? k?\ zHMOOOOO r0   