@@ -2421,7 +2421,6 @@ def _arrayexpr_to_parfor(self, equiv_set, lhs, arrayexpr, avail_vars):
24212421 expr = arrayexpr .expr
24222422 arr_typ = pass_states .typemap [lhs .name ]
24232423 el_typ = arr_typ .dtype
2424-
24252424 # generate loopnests and size variables from lhs correlations
24262425 size_vars = equiv_set .get_shape (lhs )
24272426 index_vars , loopnests = _mk_parfor_loops (
@@ -3788,6 +3787,46 @@ def _get_call_arg_types(expr, typemap):
37883787 return tuple (new_arg_typs ), new_kw_types
37893788
37903789
3790+ def _ufunc_to_parfor_instr (
3791+ typemap ,
3792+ op ,
3793+ avail_vars ,
3794+ loc ,
3795+ scope ,
3796+ func_ir ,
3797+ out_ir ,
3798+ arg_vars ,
3799+ typingctx ,
3800+ calltypes ,
3801+ expr_out_var ,
3802+ ):
3803+ func_var_name = _find_func_var (typemap , op , avail_vars , loc = loc )
3804+ func_var = ir .Var (scope , mk_unique_var (func_var_name ), loc )
3805+ typemap [func_var .name ] = typemap [func_var_name ]
3806+ func_var_def = copy .deepcopy (func_ir .get_definition (func_var_name ))
3807+ if (
3808+ isinstance (func_var_def , ir .Expr )
3809+ and func_var_def .op == "getattr"
3810+ and func_var_def .attr == "sqrt"
3811+ ):
3812+ g_math_var = ir .Var (scope , mk_unique_var ("$math_g_var" ), loc )
3813+ typemap [g_math_var .name ] = types .misc .Module (math )
3814+ g_math = ir .Global ("math" , math , loc )
3815+ g_math_assign = ir .Assign (g_math , g_math_var , loc )
3816+ func_var_def = ir .Expr .getattr (g_math_var , "sqrt" , loc )
3817+ out_ir .append (g_math_assign )
3818+ # out_ir.append(func_var_def)
3819+ ir_expr = ir .Expr .call (func_var , arg_vars , (), loc )
3820+ call_typ = typemap [func_var .name ].get_call_type (
3821+ typingctx , tuple (typemap [a .name ] for a in arg_vars ), {}
3822+ )
3823+ calltypes [ir_expr ] = call_typ
3824+ el_typ = call_typ .return_type
3825+ # signature(el_typ, el_typ)
3826+ out_ir .append (ir .Assign (func_var_def , func_var , loc ))
3827+ out_ir .append (ir .Assign (ir_expr , expr_out_var , loc ))
3828+
3829+
37913830def _arrayexpr_tree_to_ir (
37923831 func_ir ,
37933832 typingctx ,
@@ -3852,35 +3891,33 @@ def _arrayexpr_tree_to_ir(
38523891 # elif isinstance(op, (np.ufunc, DUFunc)):
38533892 # function calls are stored in variables which are not removed
38543893 # op is typing_key to the variables type
3855- func_var_name = _find_func_var (typemap , op , avail_vars , loc = loc )
3856- func_var = ir .Var (scope , mk_unique_var (func_var_name ), loc )
3857- typemap [func_var .name ] = typemap [func_var_name ]
3858- func_var_def = copy .deepcopy (
3859- func_ir .get_definition (func_var_name )
3860- )
3861- if (
3862- isinstance (func_var_def , ir .Expr )
3863- and func_var_def .op == "getattr"
3864- and func_var_def .attr == "sqrt"
3865- ):
3866- g_math_var = ir .Var (
3867- scope , mk_unique_var ("$math_g_var" ), loc
3868- )
3869- typemap [g_math_var .name ] = types .misc .Module (math )
3870- g_math = ir .Global ("math" , math , loc )
3871- g_math_assign = ir .Assign (g_math , g_math_var , loc )
3872- func_var_def = ir .Expr .getattr (g_math_var , "sqrt" , loc )
3873- out_ir .append (g_math_assign )
3874- # out_ir.append(func_var_def)
3875- ir_expr = ir .Expr .call (func_var , arg_vars , (), loc )
3876- call_typ = typemap [func_var .name ].get_call_type (
3877- typingctx , tuple (typemap [a .name ] for a in arg_vars ), {}
3894+ _ufunc_to_parfor_instr (
3895+ typemap ,
3896+ op ,
3897+ avail_vars ,
3898+ loc ,
3899+ scope ,
3900+ func_ir ,
3901+ out_ir ,
3902+ arg_vars ,
3903+ typingctx ,
3904+ calltypes ,
3905+ expr_out_var ,
38783906 )
3879- calltypes [ir_expr ] = call_typ
3880- el_typ = call_typ .return_type
3881- # signature(el_typ, el_typ)
3882- out_ir .append (ir .Assign (func_var_def , func_var , loc ))
3883- out_ir .append (ir .Assign (ir_expr , expr_out_var , loc ))
3907+ if hasattr (op , "is_dpnp_ufunc" ):
3908+ _ufunc_to_parfor_instr (
3909+ typemap ,
3910+ op ,
3911+ avail_vars ,
3912+ loc ,
3913+ scope ,
3914+ func_ir ,
3915+ out_ir ,
3916+ arg_vars ,
3917+ typingctx ,
3918+ calltypes ,
3919+ expr_out_var ,
3920+ )
38843921 elif isinstance (expr , ir .Var ):
38853922 var_typ = typemap [expr .name ]
38863923 if isinstance (var_typ , types .Array ):
0 commit comments