
    J/Ph_n                        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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/m0Z0m1Z1 ddl2m3Z3 ddl
m4Z4 ddl5m6Z7 ddl8m9Z: ddl;m<Z< ddlm=Z= ddl>m?Z?m@Z@ ddlAmBZBmCZC ddlDmEZE  G d de          ZFeFed<    G d de+          ZG e1            ZH G d d e&          ZI G d! d"e!          ZJ eJd          ZK G d# d$e          ZLeLeed         <    G d% d&e          ZMeMeed         <   eHN                    ejO                  d'             ZPeHQ                    ejR        ejS                  d(             ZTeHN                    ejS                  d)             ZUeHN                    ejV                  d*             ZW ed+          d,             ZX eejY        d+          d-             ZZ G d. d/e          Z[ G d0 d1e          Z\e]d2k    r ej^                     dS dS )3a  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overload_attributeoverload_classmethod	intrinsic)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)typeof)_dynfunc)ir)rtsys)compiler)CompilerBaseDefaultPassBuilder)FunctionPassregister_pass)PreLowerStripPhisc                       e Zd ZdS )DPUN)__name__
__module____qualname__     a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_target_extension.pyr-   r-   3   s        Cr2   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        r3   _customize_tm_optionsz#JITDPUCodegen._customize_tm_optionsC   s    0022y,,..3??5!! 	$"KK__U## 	$KK#K&+ #/
 	 ?@@CN""!GENNN #"r2   c                 *    |                                  S N)_get_host_cpu_featuresrL   s    r3   _customize_tm_featuresz$JITDPUCodegen._customize_tm_featuresZ   s    **,,,r2   c                 :    | j                             |           d S rS   )_engine
add_module)rL   modules     r3   _add_modulezJITDPUCodegen._add_module^   s    '''''r2   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)rX   get_global_value_addressctypesc_void_pfrom_addressid)rL   env_nameenvgvaddrenvptrs        r3   set_envzJITDPUCodegen.set_enva   sP    
 66x@@/A%33F;;OBsGG,,q			r2   N)	r.   r/   r0   r   _library_classrQ   rV   r[   rg   r1   r2   r3   r6   r6   >   sW         $N" " ".- - -( ( (- - - - -r2   r6   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 rS   )_internal_codegen_create_empty_module)rL   rF   s     r3   create_modulezDPUContext.create_moduleu   s    %::4@@@r2   c                 ~    t          d          | _        t          j        |            |                                  d S )Nz
numba.exec)r6   rl   r%   
initializerefreshrU   s    r3   initzDPUContext.initx   s4    !.|!<!<r2   c                     t           }	 | j        |         }n)# t          $ r t          |          }|| j        |<   Y nw xY w|                     |           | j                                         d S rS   )dpu_function_registry_registriesKeyErrorr    install_registrytyping_contextrq   )rL   registryloaders      r3   rq   zDPUContext.refresh   s    (	0%h/FF 	0 	0 	0#H--F)/DX&&&	0 	h''' 	##%%%%%s    #==c                     | j         j        S rS   )rl   target_datarU   s    r3   r|   zDPUContext.target_data   s    %11r2   c                     | j         S rS   )rl   rU   s    r3   codegenzDPUContext.codegen   s    %%r2   c                 *    t          j        |           S rS   )r   CPUCallConvrU   s    r3   	call_convzDPUContext.call_conv   s    #D)))r2   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)rL   builderrf   body_ptrs       r3   get_env_bodyzDPUContext.get_env_body   sA    
 &VX01DE
 
 {4hFFFFr2   c                 b   |                      |j        |                     | j                            }|                    |          }|                     |          }|                    || j        j                   |                     ||          }|	                    | j
        ||          S )N)	debug_msg)declare_env_globalrZ   get_env_namefndescloadget_python_apiemit_environment_sentryrc   r   get_env_managerenvironment)rL   r   envgvenvargpyapienv_bodys         r3   r   zDPUContext.get_env_manager   s    ''ND--dk::
 
 e$$##G,,%%dk2 	& 	
 	
 	
 $$Wf55$$T%5xHHHr2   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   )rL   r   genptrr   s       r3   get_generator_statezDPUContext.get_generator_state   s3    
 " :;#	
 
 
 	
r2   c                     | j         rt          j        || j                    |                    t          j                   d S rS   )fastmathr   rewrite_moduleadd_linking_libraryr%   library)rL   modr   s      r3   post_loweringzDPUContext.post_lowering   s=    = 	<'T];;;##EM22222r2   Fc           	      .   |                      d          }| j                            |j        |j                  }t          j        |||j                  }t          | ||||||          }	|		                                 |
                    |           d S )Nwrapper)call_helperrelease_gil)rn   r   get_function_typerestypeargtypesllirFunctionllvm_func_namer   buildadd_ir_module)
rL   r   r   rd   r   r   wrapper_modulefntywrapper_calleer   s
             r3   create_cpython_wrapperz!DPUContext.create_cpython_wrapper   s     ++I66~//PPD&"7
 
  ##
 
 
 	n-----r2   c                     d S rS   r1   )rL   r   r   rd   r   s        r3   create_cfunc_wrapperzDPUContext.create_cfunc_wrapper   s    r2   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~   rg   r   )rL   r   r   rd   fnptrdoccfuncs          r3   get_executablezDPUContext.get_executable   s     //,
 
 ,2??<&  ""O!!#&&r*J
 
 	 1 1& 9 93???r2   N)F)r.   r/   r0   allow_dynamic_globalsrn   r   rr   rq   propertyr|   r~   r   r   r   r   r   r   r   r   r   r1   r2   r3   rj   rj   q   s        A A A   
& 
& 
& 2 2 X2& & & * * _*G G G
I 
I 
I

 

 

3 3 3 >C. . . .(      r2   rj   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 rS   )rj   rx   _target_namerU   s    r3   _toplevel_target_contextz"DPUTarget._toplevel_target_context   s     $-t/@AAAr2   c                 (    t          j                    S rS   )r   ContextrU   s    r3   _toplevel_typing_contextz"DPUTarget._toplevel_typing_context  s     ~r2   c                     | j         S )z5
        The target context for DPU targets.
        )r   rU   s    r3   target_contextzDPUTarget.target_context      
 ,,r2   c                     | j         S )z5
        The typing context for CPU targets.
        )r   rU   s    r3   rx   zDPUTarget.typing_context  r   r2   N)r.   r/   r0   r   CPUTargetOptionsrM   r   r   r   r   r   rx   r1   r2   r3   r   r      s        "GB B _B     _  - - X- - - X- - -r2   r   c                   "     e Zd ZeZ fdZ xZS )DPUDispatcherc                     t          d          5  t                                          |          cd d d            S # 1 swxY w Y   d S )Nr4   )r   supercompile)rL   rP   	__class__s     r3   r   zDPUDispatcher.compile  s    U## 	( 	(77??3''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   !?AA)r.   r/   r0   
dpu_targettargetdescrr   __classcell__)r   s   @r3   r   r     s=        K( ( ( ( ( ( ( ( (r2   r   c                   &    e Zd Zd Zd Zd Zd ZdS )djitc                 "    || _         || _        d S rS   )_args_kwargs)rL   argskwargss      r3   __init__zdjit.__init__+  s    
r2   c                     t          |          dk     sJ |r	|d         }n| j        d         }|| _        |                                 S )N   r   )lenr   py_funcdispatcher_wrapper)rL   r   funcs      r3   __call__zdjit.__call__/  sL    4yy1}}}} 	!7DD:a=D&&(((r2   c                 2    t           t          d                  S )z(
        Returns the dispatcher
        r4   )r   r   rU   s    r3   get_dispatcherzdjit.get_dispatcher9  s     #?5#9::r2   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   )rL   disptoptr   s       r3   r   zdjit.dispatcher_wrapper?  sw    ""$$%%#D "*t|++!\*:;NtL)
 
 
 	
r2   N)r.   r/   r0   r   r   r   r   r1   r2   r3   r   r   *  sP          ) ) ); ; ;
 
 
 
 
r2   r   c                 *    |                                  S rS   )get_dummy_value)contextr   typyvals       r3   constant_dummyr   [  s    ""$$$r2   c                 ~    |                      ||j        |j                  }|                     |||j        |          S rS   )get_constant_genericliteral_typeliteral_valuecast)r   r   fromtytotyvallits         r3   literal_int_to_numberr  a  sA    

&
&$f&: C <<f&94@@@r2   c                 B    |                      |          } ||          S rS   get_value_typer   r   r   r   ltys        r3   	const_intr
  j  #    

 
 
$
$C3u::r2   c                 B    |                      |          } ||          S rS   r  r  s        r3   const_floatr  q  r  r2   targetc                 (     |||          }d }||fS )Nc                      |j         | S rS   subcgctxr   tyargsllargss       r3   r~   zintrin_add.<locals>.codegen|  s    w{F##r2   r1   tyctxxyrP   r~   s        r3   
intrin_addr  x  s,    
!Aq''C$ $ $ <r2   c                 |    t          | t          j                  rt          |t          j                  rd }|S d S d S )Nc                 "    t          | |          S rS   )r  )r  r  s     r3   implzol_add.<locals>.impl  s    a###r2   )
isinstancer   Integer)r  r  r  s      r3   ol_addr"    sS    !U]## 
1em(D(D 	$ 	$ 	$    r2   c                   H    e Zd 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)assertFalsert   	functionsgetattrsassertEqualr   casts	constantsrU   s    r3   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Ar2   c                 R   d t          d          d             }t          d          d             }t                      fd            }t                      fd            }|                      |            d	           |                      |            d
           d S )Nc                     d S rS   r1   r  s    r3   my_funczATestTargetHierarchySelection.test_specialise_gpu.<locals>.my_func      Dr2   genericr  c                     d }|S )Nc                     d| z   S Nr]   r1   r0  s    r3   r  zSTestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func1.<locals>.impl      1ur2   r1   r  r  s     r3   ol_my_func1zETestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func1         Kr2   gpuc                     d }|S )Nc                     d| z   S N
   r1   r0  s    r3   r  zSTestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func2.<locals>.impl      Avr2   r1   r8  s     r3   ol_my_func2zETestTargetHierarchySelection.test_specialise_gpu.<locals>.ol_my_func2         Kr2   c                        d          S N   r1   r1  s   r3   dpu_foozATestTargetHierarchySelection.test_specialise_gpu.<locals>.dpu_foo      71::r2   c                        d          S rD  r1   rF  s   r3   cpu_foozATestTargetHierarchySelection.test_specialise_gpu.<locals>.cpu_foo  rH  r2   r&     r   r   r   assertPreciseEqual)rL   r9  rA  rG  rJ  r1  s        @r3   test_specialise_gpuz0TestTargetHierarchySelection.test_specialise_gpu  s    	 	 	 
')	,	,	,	 	 
-	,	 
'%	(	(	(	 	 
)	(	 
	 	 	 	 
	 
	 	 	 	 
	
 			1---		1-----r2   c                    d t          d          d             }t          d          d             }t          d          d             }t                      fd	            }t                      fd
            }|                      |            d           |                      |            d           d S )Nc                     d S rS   r1   r0  s    r3   r1  zATestTargetHierarchySelection.test_specialise_dpu.<locals>.my_func  r2  r2   r3  r  c                     d }|S )Nc                     d| z   S r6  r1   r0  s    r3   r  zSTestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func1.<locals>.impl  r7  r2   r1   r8  s     r3   r9  zETestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func1  r:  r2   r;  c                     d }|S )Nc                     d| z   S r>  r1   r0  s    r3   r  zSTestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func2.<locals>.impl  r@  r2   r1   r8  s     r3   rA  zETestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func2  rB  r2   r4   c                     d }|S )Nc                     d| z   S )Nd   r1   r0  s    r3   r  zSTestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func3.<locals>.impl  s    Qwr2   r1   r8  s     r3   ol_my_func3zETestTargetHierarchySelection.test_specialise_dpu.<locals>.ol_my_func3  s       Kr2   c                        d          S rD  r1   rF  s   r3   rG  zATestTargetHierarchySelection.test_specialise_dpu.<locals>.dpu_foo  rH  r2   c                        d          S rD  r1   rF  s   r3   rJ  zATestTargetHierarchySelection.test_specialise_dpu.<locals>.cpu_foo  rH  r2   ]   rK  rL  )rL   r9  rA  rX  rG  rJ  r1  s         @r3   test_specialise_dpuz0TestTargetHierarchySelection.test_specialise_dpu  s   	 	 	 
')	,	,	,	 	 
-	,	 
'%	(	(	(	 	 
)	(	 
'%	(	(	(	 	 
)	(	 
	 	 	 	 
	 
	 	 	 	 
	
 			2...		1-----r2   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 rS   r1   r0  s    r3   r1  zJTestTargetHierarchySelection.test_no_specialisation_found.<locals>.my_func  r2  r2   cudar  c                     d S )Nc                     d S rS   r1   r0  s    r3   <lambda>zdTestTargetHierarchySelection.test_no_specialisation_found.<locals>.ol_my_func_cuda.<locals>.<lambda>  s    T r2   r1   r0  s    r3   ol_my_func_cudazRTestTargetHierarchySelection.test_no_specialisation_found.<locals>.ol_my_func_cuda  s
    !>!r2   Tr   c                        d           d S r6  r1   rF  s   r3   rG  zJTestTargetHierarchySelection.test_no_specialisation_found.<locals>.dpu_foo  s    GAJJJJJr2   )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)rL   rc  rG  acceptraisesmsgsmsgr1  s          @r3   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 rS   r1   r1   r2   r3   foozATestTargetHierarchySelection.test_invalid_target_jit.<locals>.foo
  s    r2   1No target is registered against 'invalid_silicon')ri  r   NonexistentTargetErrorr   rj  rk  rl  )rL   rn  rv  rp  s       r3   test_invalid_target_jitz4TestTargetHierarchySelection.test_invalid_target_jit  s    v<== 	+,,,  -, 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 rS   r1   r1   r2   r3   barzFTestTargetHierarchySelection.test_invalid_target_overload.<locals>.bar  r2  r2   rs  r  c                      d S )Nc                      d S rS   r1   r1   r2   r3   rb  z[TestTargetHierarchySelection.test_invalid_target_overload.<locals>.ol_bar.<locals>.<lambda>  s     r2   r1   r1   r2   r3   ol_barzITestTargetHierarchySelection.test_invalid_target_overload.<locals>.ol_bar  s
    $}$r2   c                                     d S rS   r1   )r|  s   r3   rv  zFTestTargetHierarchySelection.test_invalid_target_overload.<locals>.foo  s    r2   rw  )ri  r   rx  r   r   rj  rk  rl  )rL   rn  r  rv  rp  r|  s        @r3   test_invalid_target_overloadz9TestTargetHierarchySelection.test_invalid_target_overload  s   	 	 	
 v<== 		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.
        r3  r  c                 (     |||          }d }||fS )Nc                      |j         | S rS   )mulr  s       r3   r~   zcTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_generic.<locals>.codegen3      "w{F++r2   r1   r  s        r3   intrin_math_genericzRTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_generic/  ,    !Aq''C, , , <r2   r4   c                 (     |||          }d }||fS )Nc                      |j         | S rS   r  r  s       r3   r~   z_TestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_dpu.<locals>.codegen<  r  r2   r1   r  s        r3   intrin_math_dpuzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_dpu8  r  r2   r   c                 (     |||          }d }||fS )Nc                      |j         | S rS   )addr  s       r3   r~   z_TestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_cpu.<locals>.codegenE  r  r2   r1   r  s        r3   intrin_math_cpuzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.intrin_math_cpuA  r  r2   c                        dd          S Nr&     r1   r  s   r3   cpu_foo_specificzOTestTargetHierarchySelection.test_intrinsic_selection.<locals>.cpu_foo_specificK      "?1a(((r2   rE  c                        dd          S r  r1   r  s   r3   cpu_foo_genericzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.cpu_foo_genericR      &&q!,,,r2      c                        dd          S r  r1   r  s   r3   cpu_foo_dpuzJTestTargetHierarchySelection.test_intrinsic_selection.<locals>.cpu_foo_dpuY  r  r2   N)rf  zintrinsic intrin_math_dpufor the current targetTrd  c                        dd          S r  r1   r  s   r3   dpu_foo_specificzOTestTargetHierarchySelection.test_intrinsic_selection.<locals>.dpu_foo_specifich  r  r2   r   c                        dd          S r  r1   r  s   r3   dpu_foo_genericzNTestTargetHierarchySelection.test_intrinsic_selection.<locals>.dpu_foo_generico  r  r2   c                        dd          S r  r1   r  s   r3   dpu_foo_cpuzJTestTargetHierarchySelection.test_intrinsic_selection.<locals>.dpu_foo_cpuv  r  r2   )rf  zintrinsic intrin_math_cpur  )r
   r   r*  r   rg  rh  ri  rj  rk  rl  r   )rL   r  r  r  rm  rn  ro  rp  r  r  r  r  r  r  s              @@@r3   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 rS   )bitwidthtruncr  signedsextzext)r   r   r  r   r  s        r3   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Fr2   r4   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 r6  )r   r   uint32nrtmeminfo_alloc_aligned)	r   r   	signaturer   	allocsizealign	align_u32meminfor  s	           r3   r~   z\TestTargetHierarchySelection.test_overload_allocation.<locals>.intrin_alloc.<locals>.codegen  s[    %)"E )L'5)2):ELJ J	!+;;GY<EG Gr2   r   )r  )numba.core.typingr  r   MemInfoPointervoidptr)	typingctxr  r  r~   r  miprP   r  s          r3   intrin_alloczKTestTargetHierarchySelection.test_overload_allocation.<locals>.intrin_alloc  s_    	 	 	 	 	 433333&u}55C)CE22C<r2   	_allocater   T)r  jit_optionsc                     fd}|S )Nc                      ||          S rS   r1   )clsr  r  r  s      r3   r  zaTestTargetHierarchySelection.test_overload_allocation.<locals>._ol_arr_allocate_dpu.<locals>.impl  s    #|Iu555r2   r1   )r  r  r  r  r  s       r3   _ol_arr_allocate_dpuzSTestTargetHierarchySelection.test_overload_allocation.<locals>._ol_arr_allocate_dpu  s!    6 6 6 6 6Kr2   c                     d }|S )Nc                 B    t           j                            | d          S rD  )r   Arrayr  )ns    r3   r  zZTestTargetHierarchySelection.test_overload_allocation.<locals>.ol_empty_impl.<locals>.impl  s    {,,Q222r2   r1   )r  r  s     r3   ol_empty_implzLTestTargetHierarchySelection.test_overload_allocation.<locals>.ol_empty_impl  s    3 3 3Kr2   c                      d S rS   r1   r1   r2   r3   buffer_funczJTestTargetHierarchySelection.test_overload_allocation.<locals>.buffer_func  r2  r2   c                      d } | S )Nc                  *    t          j        d          S r>  )npemptyr1   r2   r3   r  z`TestTargetHierarchySelection.test_overload_allocation.<locals>.ol_buffer_func_impl.<locals>.impl  s    x||#r2   r1   )r  s    r3   ol_buffer_func_implzRTestTargetHierarchySelection.test_overload_allocation.<locals>.ol_buffer_func_impl  s    $ $ $Kr2   r   )r   rd  c                                    S rS   r1   )r  s   r3   rv  zBTestTargetHierarchySelection.test_overload_allocation.<locals>.foo  s    "{}}$r2   )r  )r
   r	   r   r  r   r  r  numba.core.target_extensionr   r   numba.core.runtimer  assertIsInstanceMemInfo)rL   r  r  r  r   rv  rr  r  r  r  s           @@@r3   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c                    |                                  \  }}t           |                      }t          |dd          d             }|                     t          j        d          5  t          t          j        |                    d             }d d d            n# 1 swxY w Y   t          t          j
        t          j        d d d         |                    d             }d S )	Ndpu_onlyr4   r  c                     d }|S )Nc                     dS )N*   r1   )objs    r3   impzcTestTargetHierarchySelection.test_overload_attribute_target.<locals>.ov_dummy_dpu_attr.<locals>.imp  s    rr2   r1   )r  r  s     r3   ov_dummy_dpu_attrzVTestTargetHierarchySelection.test_overload_attribute_target.<locals>.ov_dummy_dpu_attr  s       Jr2   zUnknown attribute 'dpu_only'c                     | j         S rS   r  r0  s    r3   illegal_target_attr_usez\TestTargetHierarchySelection.test_overload_attribute_target.<locals>.illegal_target_attr_use  s
    z!r2   r]   c                     |j         | d<   d S )Nr   r  )resdummys     r3   cuda_target_attr_usezYTestTargetHierarchySelection.test_overload_attribute_target.<locals>.cuda_target_attr_use  s    ^CFFFr2   )make_dummy_typer"   r   assertRaisesRegexr   rh  r   r   int64r   void)rL   MyDummyMyDummyTypemydummy_typer  r  r  s          r3   test_overload_attribute_targetz;TestTargetHierarchySelection.test_overload_attribute_target  s?   #3355ggii((	KE	B	B	B	 	 
C	B	 ##F$6$BD D 	" 	"%+l++,," " -,"	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 
ejSSqS)<88	9	9	$ 	$ 
:	9	$ 	$ 	$s   *+B!!B%(B%N)r.   r/   r0   __doc__r-  rN  r\  rq  ry  r  r  r  r  r1   r2   r3   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.J$ $ $ $ $r2   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 )NFr4   r  c                     d }|S )Nc                     dS )N    ,Ar1   r0  s    r3   dpu_sin_implzQTestTargetOffload.test_basic_offload.<locals>.ol_np_sin_DPU.<locals>.dpu_sin_impl  s    xr2   r1   )r  r  s     r3   ol_np_sin_DPUz;TestTargetOffload.test_basic_offload.<locals>.ol_np_sin_DPU  s           r2   Trd  c                 *    t          j        |           S rS   r  sinr0  s    r3   rv  z1TestTargetOffload.test_basic_offload.<locals>.foo      6!99r2      r  c                 *    t          j        |           S rS   r  r0  s    r3   rv  z1TestTargetOffload.test_basic_offload.<locals>.foo  r  r2   )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 rS   )r)   r   rU   s    r3   r   zITestTargetOffload.test_basic_offload.<locals>.DispatcherSwitcher.__init__  s    %d+++++r2   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callr4   z+Failed to find and compile an overload for z for z due to T)func_irblocksvalues
find_exprstypemapr   rF   r   get_call_typer  	calltypesr   r   r   r   get_function	Exceptionprint	targetctx_codelib_stackr  )rL   stater  mutatedblkr  functiontnamerP   r   hw_ctxerp  _DEBUGs                r3   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/   r0   _namer   r  )r  s   r3   r  r     sB        (E, , ,0 0 0 0 0 0 0r2   r  c                       e Zd Z fdZdS )@TestTargetOffload.test_basic_offload.<locals>.DPUOffloadCompilerc                     t          j        | j                  }|                    t                     |                                 |gS rS   )r(   define_nopython_pipeliner  add_pass_afterr+   finalize)rL   pmr  s     r3   define_pipelineszQTestTargetOffload.test_basic_offload.<locals>.DPUOffloadCompiler.define_pipelinesC  sA    '@LL!!"46GHHHtr2   N)r.   r/   r0   r"  )r  s   r3   DPUOffloadCompilerr  B  s.              r2   r#  )r   c                 R    t          j        |           t          j        |           fS rS   )r  r  cosr0  s    r3   rv  z1TestTargetOffload.test_basic_offload.<locals>.fooK  s    6!99bfQii''r2   )
r   r  r  r   rM  r   r*   r)   r'   r%  )rL   r  rv  r#  r  r  s       @@r3   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(=>>>>>r2   N)r.   r/   r0   r  r&  r1   r2   r3   r  r    s2         b? b? b? b? b?r2   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   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!   numba.core.typing.typeofr"   r#   llvmlite.bindingbindingrC   llvmliter$   r   r  r%   r&   numba.core.compilerr'   r(   numba.core.compiler_machineryr)   r*   numba.core.typed_passesr+   r-   r6   rt   rj   r   r   r   r   lower_constantDummyr   
lower_castIntegerLiteralr!  r  r
  Floatr  r  r  r"  r$  r  r.   mainr1   r2   r3   <module>rD     s     ( ( ( ( ( (   % % % % % %            > > > > > > > > > > > >                  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%%%  &%T$ T$ T$ T$ T$8 T$ T$ T$n
k? k? k? k? k? k? k? k?\ zHMOOOOO r2   