U
    ¿|eDE ã                   @   sh  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZd dl	Z
d dlZd dlmZ d dlmZmZmZmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z( d dlm)Z) d dl*m+Z+ d d	l,m-Z-m.Z.m/Z/m0Z0 d d
l1m2Z2 G dd„ de)j3ƒZ4dd„ Z5dd„ Z6edddddddgdd�Z7dd„ Z8G dd„ de0ƒZ9dd„ Z:d d!„ Z;d"d#„ Z<d$d%„ Z=d&d'„ Z>d(d)„ Z?d*d+„ Z@d,d-„ ZAd.d/„ ZBd0d1„ ZCd2d3„ ZDd4d5„ ZEd6d7„ ZFd8d9„ ZGd:d;„ ZHd<d=„ ZId>d?„ ZJd@dA„ ZKdBdC„ ZLdDdE„ ZMdFdG„ ZNdHdI„ ZOdJdK„ ZPdLdM„ ZQdNdO„ ZRdPdQ„ ZSdRdS„ ZTdTdU„ ZUdVdW„ ZVdXdY„ ZWdZd[„ ZXd\d]„ ZYdS )^é    N)Úmake_dataclass)Úparfor)ÚtypesÚirÚconfigÚcompilerÚsigutilsÚcgutils)Úadd_offset_to_labelsÚreplace_var_namesÚremove_delsÚlegalize_namesÚrename_labelsÚget_name_var_tableÚvisit_vars_innerÚget_definitionÚguardÚget_call_tableÚis_pureÚget_np_ufunc_typÚget_unused_var_nameÚis_const_callÚfixup_var_define_in_scopeÚtransfer_scopeÚfind_max_labelÚget_global_func_typ)Ú	signature)Úlowering)Úensure_parallel_support)ÚNumbaParallelSafetyWarningÚNotDefinedErrorÚCompilerErrorÚInternalError)ÚParforLoweringBuilderc                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚParforLowerzlThis is a custom lowering class that extends standard lowering so as
    to accommodate parfor.Parfor nodes.c                    s(   t |tjƒrt| |ƒ ntƒ  |¡ d S ©N)Ú
isinstancer   ÚParforÚ_lower_parfor_parallelÚsuperÚ
lower_inst©ÚselfÚinst©Ú	__class__© úZ/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/parfors/parfor_lowering.pyr*   1   s    zParforLower.lower_inst)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   Ú__classcell__r0   r0   r.   r1   r$   ,   s   r$   c                 C   s$   |j d krt| |ƒS |  | |¡S d S r%   )ÚlowererÚ_lower_parfor_parallel_std)r7   r   r0   r0   r1   r(   8   s    

r(   c           F      C   s  ddl m} tƒ  | jj}| j}| j}| jj}t |¡| j_t	j
rVtd| jt| jƒƒ | jj}| j}t	j
rztdƒ | ¡  |jj}	|jj}
t	j
r¦td|jdt|jƒƒ |jjD ]}t	j
rÂtd|ƒ |  |¡ q®|jD ]0}||krÔ|| }t |
||	¡}|  |j|¡ qÔi }i }tjj ||j|| j||¡ t	j
�rFtd|ƒ td	|ƒ |jd
k	�sVt‚tjj  ||j¡}|j!|j" }}t	j
�r’td|ƒ td|ƒ t#|ƒ}i }g }|dk�rP|jj}
|jj}	t$| |
|	d�}|j%tj&j'j(j)t*tj&j'j(j)ƒdd�}|j+|j,|g d�t-j.dd�}t/|ƒD �]:}|| }| jj| }t |
||	¡}t0|ƒ}|j1}t	j
�rptd||||t- 2|¡|t|ƒƒ t3|t-j4j5ƒ�rŒ|j6d } nd} |j%t&j7t8t&j7ƒt- 9t-j.| ¡fdt- 2|¡id�}!|g}"t3|t-j4j5ƒ�r:|j+tj: ;|d|	¡t- 9t-j.|j6¡dd�}#t/|j6ƒD ]0}$|j+tj: <|#|$d
|	¡t-j.dd�}%|" =|%¡ �q|j>|"dd�}&|j? @|¡}'|jA|'t- 2|¡d�}(|j,|!|&|(gd�})|j+|)|dd�}*|*||j< | =|*¡ || jB}+|+d
k	�rHt3|t-j4j5ƒ�r6|j%t&jCt8t&jCƒt- 9t-j.|j6¡|fdt- 2|¡id�},|jA|+|dd�}-|j,|,|#|-|(gd�}.|j+|.|d d�}/| =|/¡ n|jA|+|d d�}/n€|}/t	jD�rÈd!tE|ƒ d" }0t- F|0¡}1|jA|0|1d#d�}2tjG|2|gd
|	d$�}3tHt-jI||2j ||j ƒ| jjJ|3< td%|3ƒ |  |3¡ ||j }4| K|4¡}5tL M||5¡}6|
 Nd&|	¡}7|4||7j< |6| j|7j< tLjO||  P|j¡|5d'��$}8| Q|8jR|6¡ |jS|*|7|/d(� W 5 Q R X �q|jT ¡ }9d)|9_U||jVd jWj }:|jVdd
… D ]};||;jWj |:k�s€t‚�q€d*tjj_Xz.tY| |||||9i tZ|ƒ|:|jƒ
\}<}=}>}?}@W 5 d+tjj_XX d,g|= }=t#|ƒ}At#|=ƒt#|ƒ |A }Bt	j
�rDtd-|=ƒ td.|Bƒ td/|ƒ td0|ƒ td1|Aƒ t[|j\|B|A|=|>|j|ƒ}Ct	j
�rntd2|Cƒ d3d4„ |jVD ƒ}Dt	j
�rœtd5|jVƒ td6|Dƒ t]| |<|C|>|=|?|D||||j|:|j|@ƒ |dk�rÜt^||| ||ƒ |D ]}E|  tj_|Ej|	d7�¡ �qà|| j_t	j
�rtd8ƒ d
S )9a  Lowerer that handles LLVM code generation for parfor.
    This function lowers a parfor IR node to LLVM.
    The general approach is as follows:
    1) The code from the parfor's init block is lowered normally
       in the context of the current function.
    2) The body of the parfor is transformed into a gufunc function.
    3) Code is inserted into the main function that calls do_scheduling
       to divide the iteration space for each thread, allocates
       reduction arrays, calls the gufunc function, and then invokes
       the reduction function across the reduction arrays to produce
       the final reduction values.
    r   )Úget_thread_countzlowerer.fndescr(   zinit_block = ú zlower init_block instr = Ú	alias_mapÚarg_aliasesNzparfor_redvars:zparfor_reddict:)r7   ÚscopeÚlocr0   )ÚfobjÚftypeÚargs)rA   Únum_threads_var)ÚrhsÚtypÚnameZreduction_infoé   Údtype)r?   r@   rA   ÚkwsÚshapeZredarr_shapeZredshapeonedimZtuple_size_var©rE   )ÚcvalrD   ÚredarrÚinit_val)rK   rD   rE   Úredtosetzres_print1 for redvar ú:Ú	str_const©rA   Úvarargr>   Zres_print_redvarz$loop_index)Úintp)ÚobjÚindexÚvalÚnumpyTFÚschedzfunc_args = znum_inputs = úparfor_outputs = úparfor_redvars = znum_reductions = zgu_signature = c                 S   s   g | ]}|j |j|jf‘qS r0   )ÚstartÚstopÚstep©Ú.0Úlr0   r0   r1   Ú
<listcomp>p  s     z._lower_parfor_parallel_std.<locals>.<listcomp>zloop_nests = úloop_ranges = )r>   z_lower_parfor_parallel done)`Únumba.np.ufunc.parallelr9   r   ÚcontextÚtyping_contextÚbuilderÚfndescÚtypemapÚcopyr   ÚDEBUG_ARRAY_OPTÚprintÚtypeÚvarmapÚdumpÚ
init_blockr>   r=   Úbodyr*   Úracesr   ÚVarÚ_alloca_varrE   ÚnumbaÚparforsr   Zfind_potential_aliases_parforÚparamsÚfunc_irÚAssertionErrorÚget_parfor_outputsÚredvarsÚreddictÚlenr#   Zbind_global_functionÚnpÚufuncÚparallelZ_iget_num_threadsr   ÚassignÚcallr   rS   ÚrangeÚredtyp_to_redarraytyperG   ÚDTyper&   ÚnpytypesÚArrayÚndimÚemptyr   ÚUniTupleÚExprÚgetattrÚstatic_getitemÚappendZmake_tuple_variableÚ
_typingctxÚresolve_value_typeZmake_const_variablerM   ÚfullÚDEBUG_ARRAY_OPT_RUNTIMEÚstrÚStringLiteralÚPrintr   ÚnoneÚ	calltypesÚget_value_typer	   Úalloca_onceÚredefineÚ	for_rangeÚloadvarÚstorerU   ÚsetitemÚflagsÚerror_modelÚ
loop_nestsÚindex_variableZsequential_parfor_loweringÚ_create_gufunc_for_parfor_bodyÚboolÚ_create_shape_signatureÚget_shape_classesÚcall_parallel_gufuncÚ#_parfor_lowering_finalize_reductionÚDel)Fr7   r   r9   Ú	typingctxÚ	targetctxrf   Zorig_typemaprh   rm   r>   r=   ÚinstrZracevarZrvtypÚrvr;   r<   Zparfor_output_arraysÚparfor_redvarsÚparfor_reddictÚnredvarsÚredarrsZ
to_cleanupZpfbdrÚget_num_threadsrB   ÚiZred_nameÚ
redvar_typZredvarZredarrvar_typZreddtypeÚ	redarrdimZglbl_np_emptyZsize_var_listZredshape_varÚjZ	onedimvarÚsize_varrK   ÚdtZ
empty_callÚ
redarr_varrM   Zfull_func_nodeZinit_val_varZ	full_callrN   Zres_print_strÚstrconsttypÚlhsÚ	res_printZnum_thread_typeZntllvm_typeZalloc_loop_varZnumba_ir_loop_index_varÚlooprž   Úindex_var_typr`   ÚfuncÚ	func_argsÚfunc_sigÚfunc_arg_typesÚexp_name_to_tuple_varÚnum_reductionsÚ
num_inputsÚgu_signatureÚloop_rangesÚvr0   r0   r1   r8   ?   s    

  ÿ

 ÿ



ýýøÿú	ýý ÿ  ÿ



þùý ÿýý
ý
 ÿþ






        þüü





ù

ò
    ÿr8   Ú_ReductionInfoÚredvar_infoÚredvar_namer³   r¸   Ú
redarr_typrM   T)Úfrozenc              	   C   st   |  ¡ D ]f\}}|jj| }|jj|j }| |¡}	t|| |||||	d�}
|
jjdk	r\tnt	}|| |||
ƒ qdS )zYEmit code to finalize the reduction from the intermediate values of
    each thread.
    )rÉ   rÊ   r³   r¸   rË   rM   N)
Úitemsrg   rh   rE   r›   rÈ   rÉ   ZredopÚ_lower_trivial_inplace_binopsÚ_lower_non_trivial_reduce)r   r°   r7   r®   Úthread_count_varrÊ   r¸   r³   rË   rM   Úreduce_infoÚhandlerr0   r0   r1   r§   ¢  s"    
ú

ÿþr§   c                       s   e Zd Z‡ fdd„Z‡  ZS )Ú ParforsUnexpectedReduceNodeErrorc                    s   t ƒ  d|› �¡ d S )Nz!Unknown reduce instruction node: )r)   Ú__init__r+   r.   r0   r1   rÔ   Ç  s    z)ParforsUnexpectedReduceNodeError.__init__)r2   r3   r4   rÔ   r6   r0   r0   r.   r1   rÓ   Æ  s   rÓ   c                 C   sž   |j jD ]b}t||ƒrn>t||jƒrN|jj}t||||ƒ}|j||j	j
d� nt|ƒ‚t| |||jƒr qlqtjrš|j}| | j› d|j› d|› d�|¡ dS )z+Lower trivial inplace-binop reduction.
    rJ   z	: parfor z reduction ú =N)rÉ   Úreduce_nodesÚ_lower_var_to_var_assignÚ!_is_inplace_binop_and_rhs_is_initrÊ   ÚvalueÚfnÚ_emit_binop_reduce_callÚstorevarÚtargetrE   rÓ   Ú_fix_redvar_name_ssa_mismatchr   r‘   Úprint_variabler>   r2   )r   r7   rÐ   rÑ   r-   rÚ   Úredvar_resultÚvarnamer0   r0   r1   rÎ   Ë  s.    
   ÿÿþrÎ   c           
   	      sô   |j › d�‰ |jj ˆ |j¡ | |j¡}t |j	|¡�Œ}|j
}|jjD ]v}t||ƒrXnRt|tjƒr¢t‡ fdd„| ¡ D ƒƒr¢t|||ƒ}| |ˆ ¡ | |¡ nt|ƒ‚t| |||j ƒrH qÀqHW 5 Q R X tjrð|j }	| | j› d|	› d�|	¡ dS )zFLower non-trivial reduction such as call to `functools.reduce()`.
    ú#initc                 3   s   | ]}|j ˆ kV  qd S r%   rJ   ©r_   Úvar©Z	init_namer0   r1   Ú	<genexpr>ú  s     z,_lower_non_trivial_reduce.<locals>.<genexpr>z: parfor non-trivial reduction rÕ   N)rÊ   rg   rh   Ú
setdefaultr³   r›   rE   r	   rš   rf   rU   rÉ   rÖ   r×   r&   r   ÚAssignÚanyÚ	list_varsÚ_emit_getitem_callrÜ   r*   rÓ   rÞ   r   r‘   rß   r>   )
r   r7   rÐ   rÑ   Znum_thread_llvalr¼   Útidr-   Úelemrá   r0   rå   r1   rÏ   é  s2    
ÿÿþrÏ   c                 C   sB   t |tjƒr>t |jtjƒr>|  |jj¡}| j||jjd� dS dS )zaLower Var->Var assignment.

    Returns True if-and-only-if `inst` is a Var->Var assignment.
    rJ   TF)	r&   r   rè   rÙ   rr   r›   rE   rÜ   rÝ   )r7   r-   Úloadedr0   r0   r1   r×     s
    r×   c                 C   sT   dd„ }|j }|j}|j}| |jj¡}|| f}t|j|tj	ƒ}	| 
|||	|¡}
|
S )z%Emit call to ``redarr_var[idx]``
    c                 S   s   | | S r%   r0   )rL   rU   r0   r0   r1   Úreducer_getitem  s    z+_emit_getitem_call.<locals>.reducer_getitem)rf   rd   rË   r›   r¸   rE   r   r³   r   rS   Úcompile_internal)Úidxr7   rÑ   rï   rf   ÚctxrË   Úarg_arrrA   Úsigrí   r0   r0   r1   rë     s    rë   c              
   C   sú   dd„ }dd„ }t j|t j|t j|t j|t j|i|  }|j}|j}|j}	| 	|j
j¡}
tjrº|j
j |j¡}tj|j
|gd|jd�}|jj}ttj||j
j ||j ƒ|jj|< | |¡ | 	|j¡}||
|jf}t|jtj|	|jƒ}| ||||¡}|S )z;Emit call to the ``binop`` for the reduction variable.
    c                 S   s"   |}t | ƒD ]}||| 7 }q|S r%   ©r‚   ©Zthread_countrL   ÚinitÚcr²   r0   r0   r1   Úreduction_add.  s    z._emit_binop_reduce_call.<locals>.reduction_addc                 S   s"   |}t | ƒD ]}||| 9 }q|S r%   rõ   rö   r0   r0   r1   Úreduction_mul4  s    z._emit_binop_reduce_call.<locals>.reduction_mulNrQ   )ÚoperatorÚiaddÚisubÚimulÚ	ifloordivÚitruedivrd   rf   rË   r›   r¸   rE   r   r‘   r=   ÚgetrÊ   r   r”   r>   rg   rh   r   r   r•   r–   r*   rM   r³   Úuintprð   )Úbinopr7   rÐ   rÑ   rù   rú   Úkernelrò   rf   rË   ró   Úinit_varr»   rh   Zarg_thread_countrA   rô   rà   r0   r0   r1   rÛ   *  sV         ûú þ 
þ
   ÿrÛ   c                 C   sN   t | tjƒsdS | j}t |tjƒs&dS |jdkr4dS |jj|› d�krJdS dS )zDIs ``inst`` an inplace-binop and the RHS is the reduction init?
    FÚinplace_binoprâ   T)r&   r   rè   rÙ   rŠ   ÚoprC   rE   )r-   rÊ   rC   r0   r0   r1   rØ   ^  s    
rØ   c           
      C   sŽ   | j j}t|tjƒrŠz| |¡}W n  tk
rB   ||jjk}Y nX |j	}|jj	}||k}|rŠ||jjkrŠ| 
|jj¡}	|j|	|d� dS dS )z5Fix reduction variable name mismatch due to SSA.
    rJ   TF)ro   r=   r&   r   rè   Ú	get_exactr    rÝ   rE   Úunversioned_namer›   rÜ   )
r   r7   r-   rÊ   r=   Zreduction_varZis_same_source_varZredvar_unver_nameZtarget_unver_namerV   r0   r0   r1   rÞ   m  s    rÞ   c              	      sÞ  t jrBtd|||ˆƒ |dd… D ]}td|t|ƒˆ|ˆd�ƒ q"t|ƒ| }‡‡‡fdd„|dd… D ƒ}	tƒ }
|	D ]}|rv|D ]}|
 |¡ q‚qv|
r¤t|
ƒd nd}|	 d|f¡ |
 |¡ |d }|
 |¡ i ‰t	d	ƒ}|
D ] }|dkrât
|ƒˆ|< |d7 }qât
|ƒ}d
|i‰ ‡ fdd„‰g }g }d}d}t j�rVtd|ƒ td|	ƒ td|ƒ t|	|ƒD ]t\}}|d }|�r�t‡‡fdd„|D ƒƒ}nd}||k�rÀ| t|gt|dd… ƒ ƒ¡ n| |¡ ||7 }�q`||fS )z&Create shape signature for GUFunc
    r¤   rF   NÚargument©rh   c                    s$   g | ]}|ˆkrˆ |ˆd �nd‘qS )r  )éÿÿÿÿr0   rã   )r¥   rq   rh   r0   r1   ra   ¡  s     z+_create_shape_signature.<locals>.<listcomp>r   ÚaÚlatest_alphac                    s0   | dkr||  S ˆ d  d7  < t ˆ d ƒS d S )Nr   r  rF   )Úchr)rø   Ú	class_map)Ú
alpha_dictr0   r1   Ú
bump_alpha·  s    z+_create_shape_signature.<locals>.bump_alphar0   rA   ÚclassesÚthreadcount_ordinalc                 3   s   | ]}ˆ |ˆƒV  qd S r%   r0   )r_   rø   )r  r  r0   r1   ræ   É  s     z*_create_shape_signature.<locals>.<genexpr>)r   rj   rk   rl   r|   ÚsetÚaddÚmaxÚinsertÚordr  ÚzipÚtupler�   Úlist)r¥   rÄ   rÃ   rA   rÀ   rq   rh   r²   Z
num_inoutsr  Z	class_setÚ_classZ	max_classZthread_num_classÚalphabetÚnr  Zgu_sinZgu_soutÚcountZsyms_sinÚclsÚargZdim_symsr0   )r  r  r  r¥   rq   rh   r1   r¤   �  sV    







"
r¤   c                 C   s&   t | jƒD ]\}}td|d|ƒ q
d S )Nú    r:   )Ú	enumeraterp   rk   )Úblockr²   r-   r0   r0   r1   Ú_print_blockÕ  s    r&  c                 C   s(   |   ¡ D ]\}}td|ƒ t|ƒ qdS )z%Pretty-print a set of IR blocks.
    zlabel: N)rÍ   rk   r&  )Z	body_dictÚlabelr%  r0   r0   r1   Ú_print_bodyÙ  s    
r(  c                 C   sF   |   ¡ }t| ¡ ƒ}t| ¡ ƒ}|| j}|| j t ||¡¡ |S r%   )	ri   ÚminÚkeysr  r>   rp   r�   r   ÚJump)Ú	loop_bodyÚblocksZfirst_labelÚ
last_labelr>   r0   r0   r1   Úwrap_loop_bodyá  s    
r/  c                 C   s(   t |  ¡ ƒ}| | jd d… | | _d S )Nr  )r  r*  rp   )r,  r.  r0   r0   r1   Úunwrap_loop_bodyé  s    r0  c                 C   s6   | |kr
n(| |kr(|  | ¡ | | ¡ n
|  | ¡ dS )a_  If the variable is already defined more than once, do nothing.
       Else if defined exactly once previously then transition this
       variable to the defined more than once set (remove it from
       def_once set and add to def_more set).
       Else this must be the first time we've seen this variable defined
       so add to def_once set.
    N)r  Úremove)Úa_defÚdef_onceÚdef_morer0   r0   r1   Úadd_to_def_once_setsí  s    
r5  c                 C   sP  |   tj¡}|D �]8}|jj}t|||ƒ |j}	t|	tjƒrVt|	jt	j
ƒrV|	jj||< t|	tjƒrŠ|	jdkrŠ|	jj|krŠ|	jj|	jf||< t|	tjƒrð|	jdkrð|	jj|krð||	jj \}
}|
|krä||
 }t||ƒsðt|
||ƒ nt|
||ƒ t|	tjƒr|	jdkr|	jD ]<}t|tjƒ�r$|j}|| }t|ddƒ�rt|||ƒ �qqdS )aË  Effect changes to the set of variables defined once or more than once
       for a single block.
       block - the block to process
       def_once - set of variable names known to be defined exactly once
       def_more - set of variable names known to be defined more than once
       getattr_taken - dict mapping variable name to tuple of object and attribute taken
       module_assigns - dict mapping variable name to the Global that they came from
    r‹   r�   ÚmutableFN)Ú
find_instsr   rè   rÝ   rE   r5  rÙ   r&   ÚGlobalÚpytypesÚ
ModuleTyper2   rŠ   r  Úattrr¾   r   rA   rr   r‹   )r%  r3  r4  Úgetattr_takenrh   Úmodule_assignsZassignmentsZ
one_assignr2  rC   Zbase_objZ	base_attrZbase_mod_nameZargvarZavtyper0   r0   r1   Úcompute_def_once_blocký  s0    

""

r>  c           	   	   C   sh   |   ¡ D ]Z\}}t||||||ƒ |jD ]8}t|tjƒr(t|j|||||ƒ t|j|||||ƒ q(qdS )zÞCompute the set of variables defined exactly once in the given set of blocks
       and use the given sets for storing which variables are defined once, more than
       once and which have had a getattr call on them.
    N)	rÍ   r>  rp   r&   r   r'   ro   Úcompute_def_once_internalr,  )	r,  r3  r4  r<  rh   r=  r'  r%  r-   r0   r0   r1   r?  ;  s    
r?  c                 C   s.   t ƒ }t ƒ }i }i }t| |||||ƒ ||fS )zRCompute the set of variables defined exactly once in the given set of blocks.
    )r  r?  )r,  rh   r3  r4  r<  r=  r0   r0   r1   Úcompute_def_onceM  s    r@  c                 C   s    t | tjƒst‚| | j¡ | S r%   )r&   r   rr   rx   r  rE   )rä   Zvarsetr0   r0   r1   Ú	find_varsW  s    rA  c           	      C   s8  | j j|kr4| | df¡ tjdkr0td| dƒ dS tƒ }t| jt	|ƒ | 
|¡}tjdkrntd| d|d|ƒ t|ƒd	krØt| jd |ƒrØtjdkr¦td
| || j j ƒ | | ¡ t|| j j tjjƒsÔ|| j jg7 }dS t|ƒd	k�r| | df¡ tjdk�r4td| dƒ n&| | df¡ tjdk�r4td| dƒ dS )Nzstored arrayrF   ÚInstructionz: could not be hoisted because the created array is stored.Fz_hoist_internal:zuses:zdiff:r   zWill hoist instructionTÚ
dependencyz. could not be hoisted because of a dependency.znot purez, could not be hoisted because it isn't pure.)rÝ   rE   r�   r   rj   rk   r  r   rÙ   rA  Ú
differencer|   r   r&   r   r…   r†   )	r-   Údep_on_paramÚ
call_tableÚhoistedÚnot_hoistedrh   Ústored_arraysÚusesÚdiffr0   r0   r1   Ú_hoist_internal\  s2    




rL  c                 C   s€   |j D ]t}t|tjtjfƒrN|  |jj¡ t||j	j ddƒrz| |j	j¡ qt|t
jƒrt| ||j|ƒ t| ||j|ƒ qd S )Nr6  F)rp   r&   r   ÚStaticSetItemÚSetItemr  rÝ   rE   r‹   rÙ   r   r'   Úfind_setitems_blockro   Úfind_setitems_bodyr,  )ÚsetitemsÚitemssetr%  rh   r-   r0   r0   r1   rO  {  s    
rO  c                 C   s$   |  ¡ D ]\}}t| |||ƒ qdS )z³
      Find the arrays that are written into (goes into setitems) and the
      mutable objects (mostly arrays) that are written into other arrays
      (goes into itemsset).
    N)rÍ   rO  )rQ  rR  r,  rh   r'  r%  r0   r0   r1   rP  ‰  s    rP  c                 C   sf   t | tjƒrbt | jtjƒrb| jjdkrb| jjj|krb|| jjj }|dtgkrbt	| ||||||ƒS dS )Nr�   rˆ   F)
r&   r   rè   rÙ   rŠ   r  r¾   rE   r}   rL  )r-   rE  rF  rG  rH  rh   rI  Ú	call_listr0   r0   r1   Úempty_container_allocator_hoist’  s    ÿ
þý
  ÿrT  c                 C   s¸  t   | ¡}g }g }t||ƒ\}}t|ƒ\}	}
tƒ }tƒ }t||||ƒ tt|ƒ |¡ƒ}tjdkr|t	d|d|d|d|d| ƒ
 |D ]}t
|||ƒ q€| ¡ D �]\}}g }|jD ]ø}t|||	||||ƒrÊq®nÒt|tjƒrú|jj|krút|||	||||ƒrøq®n¢t|tjƒ�rœg }tjdk�r(t	dƒ | ¡  |jjD ]b}t|||	||||ƒ�rP�q0n6t|tjƒ�r†|jj|k�r†t|||	||||ƒ�r†�q0| |¡ �q0||j_| |¡ q®||_qš||fS )NrF   zhoist - def_once:z	setitems:z	itemsset:zdep_on_param:zparfor_params:r   )ri   r@  r   r  rP  r  rD  r   rj   rk   r5  rÍ   rp   rT  r&   r   rè   rÝ   rE   rL  r   r'   rn   ro   r�   )Úparfor_paramsr,  rh   Úwrapped_blocksrE  rG  rH  r3  r4  rF  Úreverse_call_tablerQ  rR  Úsir'  r%  Ú	new_blockr-   Znew_init_blockZib_instr0   r0   r1   Úhoistž  sx    


   ÿ   ÿ    ÿ
ÿ   ÿrZ  c                 C   s   t | tjjƒ S r%   )r&   r   r…   r†   )Zredtyper0   r0   r1   Úredtyp_is_scalarÒ  s    r[  c                 C   s2   d}t | tjjƒr"|| j7 }| j} tj | |d¡S )ziGo from a reducation variable type to a reduction array type used to hold
       per-worker results.
    rF   ÚC)r&   r   r…   r†   r‡   rG   )Zredtypr´   r0   r0   r1   rƒ   Õ  s
    
rƒ   c                 C   s(   t | tjjƒst‚tj | j| j| j¡S )zYGiven a reduction array type, find the type of the reduction argument to the gufunc.
    )r&   r   r…   r†   rx   rG   r‡   Úlayout)Zredarraytypr0   r0   r1   Úredarraytype_to_sigá  s    r^  c                 C   s2   t | ƒ}| ¡ D ]\}}||kr|| ||< q|S )aQ   We use ir_utils.legalize_names to replace internal IR variable names
        containing illegal characters (e.g. period) with a legal character
        (underscore) so as to create legal variable names.
        The original variable names are in the typemap so we also
        need to add the legalized name to the typemap as well.
    )r   rÍ   )Únamesrh   ÚoutdictÚxÚyr0   r0   r1   Úlegalize_names_with_typemapç  s
    rc  c                 C   s    t | tjƒr| jdkr| jS | S )Nr   )r&   r   ÚArrayCompatibler‡   rG   )ra  r0   r0   r1   Úto_scalar_from_0d÷  s    
re  c
           e   
      sŒ  t jdkrtdƒ |jj}
t |j¡}t|ƒ t|j	ƒ}dd„ |j	D ƒ}|j
}tjj ||¡}| jj‰tjj | j||| jj¡\}}ttt|ƒt|ƒ t|ƒ ƒƒ}t jdkrötd|dt|ƒƒ td|dt|ƒƒ td|dt|ƒƒ td	|dt|ƒƒ g }i }i }d
}g }|D �]T}ˆ| }t|tjƒ�s8t|tjƒ�r¸|j}|j}|t jk�sTt‚g }t |ƒD ]B}dt!|ƒ }| "|¡ | "|¡ ||f||< |d7 }|ˆ|< �q`|||< | "|¡ nªt|tj#ƒ�sÔt|tj$ƒ�rX|j}|j}|t jk�sðt‚g }t |ƒD ]F}dt!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Iƒ tU|EjQƒd }JtV||Jƒ}tU|ƒd }Kt jL�rð| .¡ D �]\}L}M|M ¡ }N|N W¡  |Mj}
|MjS}O|MjXD ]Ö}P|N "|P¡ t|Pt;jYƒ�rˆ|PjZj@ tj[k�r@�qdY \|PjZj@¡}Qt ]|Q¡}R|O TdZ|
¡}St;jYt;j^|Q|
d[�|S|
d\�}T|Rˆ|Sj@< |N "|T¡ t;j_|S|PjZgd,|
d]�}U|N "|U¡ tj`ja btjcˆ|Sj@ ˆ|PjZj@ ¡}V|V| jj|U< �q|N||L< �qàt j�rtd^ƒ t,|ƒ td|ƒ}Wte||ˆ|Wƒ\}X}Y|EjQtf|EjQ g¡ ƒ }Z|ZjXd,d_… |X |ZjXd_ g |Z_Xth|ƒ | jid` }[|X|Ydaœ|[jj|jk< t j�r’tdbƒ t,|ƒ |EjQ .¡ D �]\}L}Mtl|MjXƒD ]â\}}Pt|Pt;jYƒ�r°|PjZj@|1k�r°|Pj}
|MjS}Ot; m|O|
¡}\|MjXd,|… |\_X|MjX|d d,… |M_Xtf| g¡ ƒ}]|\ "t; n|]|
¡¡ | .¡ D ]\}^}_to|_|Oƒ|EjQ|^< �q6tp| g¡ ƒ}`|M|EjQ|K< |\|EjQ|L< |EjQ|`  "t; n|K|
¡¡  �q˜�q°�qœ �q¢�qœt j�rºtdcƒ |E P¡  tq|EjQƒ|E_Qt|EjQƒ t j�rütddƒ |E P¡  tde|ƒ tdfˆƒ |jr}a|�st j�rtdgƒ d+|_rts|EjQƒ G dhdi„ ditNjtƒ}btNju|||E|Itjc|||bdj�}c|a|_rtbtjcf|IžŽ }dt j�r~tdk|dƒ |c|,|d|+|fS )la~  
    Takes a parfor and creates a gufunc function for its body.
    There are two parts to this function.
    1) Code to iterate across the iteration space as defined by the schedule.
    2) The parfor body that does the work for a single point in the iteration space.
    Part 1 is created as Python text for simplicity with a sentinel assignment to mark the point
    in the IR where the parfor body should be added.
    This Python text is 'exec'ed into existence and its IR retrieved with run_frontend.
    The IR is scanned for the sentinel assignment where that basic block is split and the IR
    for the parfor body inserted.
    rF   z'starting _create_gufunc_for_parfor_bodyc                 S   s   g | ]}|j j‘qS r0   )r¡   rE   r^   r0   r0   r1   ra      s     z2_create_gufunc_for_parfor_body.<locals>.<listcomp>zparfor_params = r:   rY   zparfor_inputs = rZ   r   Zexpanded_tuple_var_z$parfor_inputs post tuple handling = z‘Variable %s used in parallel loop may be written to simultaneously by multiple workers and may result in non-deterministic or unintended results.Ú_arrzloop_indices = zloop_body = zparam_dict = c                    s   g | ]}ˆ | ‘qS r0   r0   ©r_   rÇ   )Úind_dictr0   r1   ra   ¢  s     zind_dict = zlegal_loop_indices = zpd = z
pd type = c                    s   g | ]}t ˆ | ƒ‘qS r0   )re  rg  r  r0   r1   ra   ¯  s     c                    s   g | ]}ˆ | ‘qS r0   r0   rg  r  r0   r1   ra   ±  s     znew param_types:znew func_arg_types:c                    s   g | ]}ˆ | ‘qS r0   r0   rg  ©Ú
param_dictr0   r1   ra   »  s     FÚparamÚ__sentinel__zlegal parfor_params = z__numba_parfor_gufunc_%sú-Ú_zgufunc_name Ú zdef z(sched, z, z):
)r}   rt   r#  TNz	func_def:r�   znamed_tuple_def:zgval:ú(zname:z0Didn't find definition of namedtuple for globls.zCould not find definition of z = ú=ú,z = (c                    s   g | ]}ˆ | ‘qS r0   r0   ©r_   ra  ri  r0   r1   ra     s     z)
z = np.ascontiguousarray(Z!ParallelAcceleratorGufuncThreadIdz*numba.np.ufunc.parallel._iget_thread_id()
ú[z]
z<    print("thread id =", ParallelAcceleratorGufuncThreadId)
zF    print("initial reduction value",ParallelAcceleratorGufuncThreadId,z.shape)
z>    print("reduction array",ParallelAcceleratorGufuncThreadId,zfor z in range(sched[z	], sched[z] + np.uint8(1)):
zprint(ú"z",z = 0
zD    print("final reduction value",ParallelAcceleratorGufuncThreadId,zD    print("final reduction array",ParallelAcceleratorGufuncThreadId,z] = Ú
z    return None
zgufunc_txt = zglobls:zgufunc_func = zgufunc_ir dump zloop_body dump zgufunc_ir dump after renaming r\  zgufunc_param_types = z{} =rP   )rÙ   r>   )rÙ   rÝ   r>   rQ   zparfor loop bodyr  Úparfor_diagnostics)rG  rH  zAfter hoistingz#gufunc_ir last dump before renamingzgufunc_ir last dumprž   rh   z(No aliases found so adding noalias flag.c                   @   s   e Zd Zdd„ ZdS )z<_create_gufunc_for_parfor_body.<locals>.ParforGufuncCompilerc                 S   s\   ddl m} tj}|dƒ}| | j¡}|j |j¡ | | j¡}|j |j¡ | 	¡  |gS )Nr   )ÚPassManagerZfull_parfor_gufunc)
Únumba.core.compiler_machineryrx  r   ÚDefaultPassBuilderÚdefine_parfor_gufunc_pipelineÚstateÚpassesÚextendÚ/define_parfor_gufunc_nopython_lowering_pipelineÚfinalize)r,   rx  ÚdpbÚpmZparfor_gufunc_passesÚlowering_passesr0   r0   r1   Údefine_pipelines   s    zM_create_gufunc_for_parfor_body.<locals>.ParforGufuncCompiler.define_pipelinesN)r2   r3   r4   r„  r0   r0   r0   r1   ÚParforGufuncCompilerÿ  s   r…  )Úpipeline_classz5finished create_gufunc_for_parfor_body. kernel_sig = )vr   rj   rk   ro   r>   ri   r,  r   r|   r    rv   rt   ru   r   ry   rg   rh   Zget_parfor_reductionsrw   r–   Úsortedr  r  rl   r&   r   r‰   ÚNamedUniTupler   rG   ÚPARFOR_MAX_TUPLE_SIZErx   r‚   r’   r�   ÚTupleÚ
NamedTuplerD  ÚwarningsÚwarnr   Úreplace_var_with_arrayrƒ   r^  r(  rc  rÍ   r   r…   r†   r   r   ÚhexÚhashÚreplaceÚjoinr}   r   r   r   rŠ   r  r¾   ÚArgrE   r8  ÚFreeVarrÙ   Ú
containersÚBaseNamedTupleÚsplitÚinstance_classr!   r2   r  Úfieldsr‘   Úexecr   Úrun_frontendrn   r-  Úvaluesr=   r™   r   r
   Úclearrp   rè   rÝ   Únumber_domainÚformatr“   ÚConstr”   ÚcoreÚtypingr   r•   r/  rZ  r)  r*  r0  ÚmetadataZ
hoist_infoÚidr$  ÚBlockr+  r   r  r   Únoaliasr   ÚCompilerBaseÚ
compile_ir)er7   r   rh   r©   rª   rž   ÚlocalsZhas_aliasesr½   rq   r>   r,  Z
parfor_dimZloop_indicesrU  Zparfor_outputsr­   r®   Zparfor_inputsZtuple_expanded_parfor_inputsZtuple_var_to_expanded_namesZexpanded_name_to_tuple_varZnext_expanded_tuple_varZparfor_tuple_paramsÚpiZpi_typeZtuple_countZtuple_dtypeZthis_var_expansionr²   Zexpanded_nameZtuple_typesZraceÚmsgZparfor_redarrsZparfor_red_arg_typesrä   ÚarrZredarraytypeZ	redarrsigZlegal_loop_indicesÚpdÚparam_typesrÁ   Zparfor_argsZparfor_params_origZascontigÚpindexZloop_body_var_tableÚsentinel_nameZgufunc_nameZ
gufunc_txtZgloblsÚtup_varZ	exp_namesZtup_typeZ	named_tupZfunc_defZnamed_tuple_defÚgvalZnamed_tuple_namerE   Ú
field_nameZgufunc_thread_id_varZeachdimÚindentZ	sched_dimZloclsZgufunc_funcZ	gufunc_irÚ	var_tableÚnew_var_dictÚreserved_namesZgufunc_param_typesZgufunc_stub_last_labelÚ	new_labelr'  r%  rY  r=   r-   Ústrvalr¹   rº   Z
assign_lhsÚ
print_noderô   rV  rG  rH  Zstart_blockZdiagnosticsÚ
prev_blockÚbody_first_labelr`   ÚbZbody_last_labelÚ	old_aliasr…  Zkernel_funcZ
kernel_sigr0   )rh  rj  rh   r1   r¢   ý  sd   

   ÿÿþÿÿ





þ


ÿû	
ü




ÿþ

üÿÿÿÿ

ÿ
ÿ
 ÿ

ÿþÿ ÿÿÿ
ÿÿÿÿÿ $ÿþýüÿûù
	$ÿÿÿÿÿ



ÿÿ
  ÿÿü



 ÿ



þ 
ÿþ
þ



ÿ





ø

r¢   c                 C   s:  g }|j D �](}t|tjƒrø|jj| krø|j}|jj}t d|¡}| 	d|¡}	t
j||	j< t ||	|¡}
| |
¡ | 	d|¡}||jj ||j< | t |j||¡¡ t |j|	||¡}tt
jt
j ||jj dd¡t
j||jj ƒ||< | |¡ q
n2t|tjƒ�r*t| d|ji||ƒ t| |j||ƒ | |¡ q
|S )Nr   z$const_ind_0z$valrF   r\  )rp   r&   r   rè   rÝ   rE   r>   r=   r   r™   r   r  r�   rÙ   rN  r   r•   r…   r†   rS   r   r'   Úreplace_var_with_array_internalro   r,  )Úvarsr%  rh   r–   rY  r-   r>   r=   Z
const_nodeZ	const_varZconst_assignZval_varZsetitem_noder0   r0   r1   Úreplace_var_with_array_in_block  s6    
   
ÿ
rÁ  c                 C   s&   |  ¡ D ]\}}t| |||ƒ|_qd S r%   )rÍ   rÁ  rp   )rÀ  r,  rh   r–   r'  r%  r0   r0   r1   r¿  :  s    r¿  c                 C   sD   t | |||ƒ | D ],}|| }| |d ¡ tj |dd¡||< qd S )NrF   r\  )r¿  Úpopr   r…   r†   )rÀ  r,  rh   r–   rÇ   Zel_typr0   r0   r1   rŽ  >  s
    rŽ  c           ]         sØ  ˆj ‰ˆj‰ ddlm}m} tjrjtdƒ td|j|j	|j
|jƒ td|ƒ td|ƒ td|ƒ td|ƒ t |¡\}}|j |jj¡}|\}}|ƒ  |||||d	d
d�}|j}|j ¡  tjrÌtd||ƒ ‡‡fdd„}t|ƒ}t|ƒD ]x}|| \}}}||ƒ}||ƒ}|dk�st‚||ƒ}|||f||< tjrêtd |¡|||ƒ t ˆ d |¡|||¡ qêtj d¡}tj |¡}tj |¡}ˆ tj ¡} ˆ tj!¡}!tj | ¡}"tj |!¡}#ˆ "tj!d¡}$ˆ "tj!d¡}%|%j#}&ˆ $| ¡}'| %d¡ | %d¡}(tj�rtd|j&ƒ |j&�r| })|"}*n|!})|#}*tj'ˆ |)ˆ "tj!|¡dd�}+tj'ˆ |)ˆ "tj!|¡dd�},t|ƒD ]¨}|| \}}}|j#|&k�r�ˆ  (||&¡}|j#|&k�r¨ˆ  (||&¡}|j#|&k�rÀˆ  (||&¡}ˆ  )||%¡}ˆ  *|ˆ  +|+ˆ "tj!|¡g¡¡ ˆ  *|ˆ  +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F
    Adds the call to the gufunc function from the main function.
    r   )Úbuild_gufunc_wrapperÚ_launch_threadsZmake_parallel_loopzouter_sig = rb   Ú	expr_argsÚexpr_arg_typesrÅ   FT)ÚcacheZ
is_parforszparallel function = c                    s*   t | tjƒrˆ | j¡S ˆ  tj| ¡S d S r%   )r&   r   rr   r›   rE   Úget_constantr   r  )rÇ   )rd   r7   r0   r1   Ú
load_rangek  s    z(call_parallel_gufunc.<locals>.load_rangerF   z'call_parallel_gufunc loop_ranges[{}] = zloop range[{}]: %d %d (%d)
é   z%Parfor has potentially negative startÚ
dim_starts)ÚsizerE   Ú	dim_stopsÚget_parallel_chunksizerJ   Úset_parallel_chunksizer±   z<=znum_threads: %d
)z@Invalid number of threads. This likely indicates a bug in Numba.Úget_sched_sizeé   rX   Zdo_scheduling_signedZdo_scheduling_unsignedc                    s   g | ]}ˆ   ˆ| j¡‘qS r0   )r›   rE   rs  )r7   Ú
redarrdictr0   r1   ra   ð  s     z(call_parallel_gufunc.<locals>.<listcomp>c                    s<   | ˆkr.ˆ|  \}}ˆ  |¡}ˆ  ||¡}|S ˆ  | ¡S dS )a?  Given a variable name, if that variable is not a new name
           introduced as the extracted part of a tuple then just return
           the variable loaded from its name.  However, if the variable
           does represent part of a tuple, as recognized by the name of
           the variable being present in the exp_name_to_tuple_var dict,
           then we load the original tuple var instead that we get from
           the dict and then extract the corresponding element of the
           tuple, also stored and returned to use in the dict (i.e., offset).
        N)r›   Úextract_value)ra  Zorig_tupÚoffsetr±  Úres)rf   rÂ   r7   r0   r1   Úload_potential_tuple_varõ  s    

z6call_parallel_gufunc.<locals>.load_potential_tuple_varc                    s   g | ]}ˆ |ƒ‘qS r0   r0   rs  )rÖ  r0   r1   ra   	  s     NZpargszvar =zgu_sig =ztype =zi =zvar = z type = z
dim_sym = z, i = z = %d
ZpshapeZpstepszbefore calling kernel %p
zafter calling kernel %p
)Rrd   rf   rc   rÃ  rÄ  r   rj   rk   rA   Úreturn_typeÚrecvrÚpysigr   Únormalize_signatureÚlibraryÚget_functionrg   Úllvm_func_namerE   Z_ensure_finalizedr|   r‚   rx   rŸ  r	   ÚprintfÚllvmliter   ÚIntTypeÚPointerTyper—   r   rS   r  rÈ  rl   Úget_abi_sizeofrÂ  Úsignedr˜   ÚsextÚsubrœ   ÚgepÚget_or_insert_functionÚmoduleÚFunctionTypeÚVoidTypeÚbitwidthr�   Úif_unlikelyÚicmp_signedÚ	call_convÚreturn_user_excÚRuntimeErrorÚmulÚallocaÚbitcastr�   Ú
make_arrayÚunpack_tupleÚstridesr‡   Údatar&   rd  rG   ÚbooleanÚget_data_typeÚOptionalÚcastÚBooleanr  r…   r†   rI   Úget_null_valueÚactive_code_libraryÚadd_linking_libraryrÍ   ÚloadÚgetvar)]r7   ÚcresrÅ   Z	outer_sigrÅ  rÆ  rÆ   rz   r{   rÒ  ro   r½   rq   rÂ   rÃ  rÄ  rA   r×  Z	llvm_funcÚsinZsoutÚinfoZwrapper_namerÉ  Znum_dimr²   r[   r\   r]   Úbyte_tZ
byte_ptr_tZbyte_ptr_ptr_tÚintp_tZuintp_tZ
intp_ptr_tZuintp_ptr_tÚzeroÚoneZone_typeZsizeof_intpZ	sched_sigZ
sched_typeZsched_ptr_typerË  rÍ  Zget_chunksizeZset_chunksizer±   Únum_threadsZcurrent_chunksizeZget_sched_size_fntyrÐ  Znum_divisionsÚ
multiplierZ
sched_sizerX   Z
debug_flagZscheduling_fntyZdo_schedulingr°   r¯   ZninoutsÚall_argsÚnum_argsZnum_inpsZarray_stridesZrv_to_arg_dictr"  rä   ÚatyÚdstÚaryrö  rµ   rD   Zrv_argZunpacked_atyÚptrZsig_dim_dictZoccurrencesZgu_sigZdim_symÚshapesZnshapesÚ	num_stepsÚstepsÚstepsizer÷  ÚfntyrÚ   ÚkrÇ   Zonly_elem_ptrr0   )rf   rd   rÂ   rÖ  r7   rÒ  r1   r¦   E  sž    ÿ




 ÿ
 ÿ  ÿ


   ÿþ   ÿþ  ÿÿÿÿÿ
ýýýÿ
ÿýý ÿþþ ÿ    ÿýÿþú


ÿ
þ

ÿ
þ
ÿ
þ
  ÿ


  ÿÿÿÿ   ÿþÿ 
ÿÿÿ
 ÿÿr¦   )Zri   rû   r   r9  rŒ  Údataclassesr   Úllvmlite.irrß  rW   r}   rt   Únumba.parforsr   Ú
numba.corer   r   r   r   r	   Únumba.core.ir_utilsr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Únumba.core.typingr   r   Únumba.parfors.parforr   Únumba.core.errorsr   r    r!   r"   Z#numba.parfors.parfor_lowering_utilsr#   ÚLowerr$   r(   r8   rÈ   r§   rÓ   rÎ   rÏ   r×   rë   rÛ   rØ   rÞ   r¤   r&  r(  r/  r0  r5  r>  r?  r@  rA  rL  rO  rP  rT  rZ  r[  rƒ   r^  rc  re  r¢   rÁ  r¿  rŽ  r¦   r0   r0   r0   r1   Ú<module>   sŒ    P  Wúö$&4#E>
	4    %