numba-cuda 0.21.1__cp313-cp313-win_amd64.whl → 0.24.0__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- numba_cuda/VERSION +1 -1
- numba_cuda/numba/cuda/__init__.py +4 -1
- numba_cuda/numba/cuda/_compat.py +47 -0
- numba_cuda/numba/cuda/api.py +4 -1
- numba_cuda/numba/cuda/cext/_dispatcher.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_dispatcher.cpp +8 -40
- numba_cuda/numba/cuda/cext/_hashtable.cpp +5 -0
- numba_cuda/numba/cuda/cext/_helperlib.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_pymodule.h +1 -1
- numba_cuda/numba/cuda/cext/_typeconv.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_typeof.cpp +56 -119
- numba_cuda/numba/cuda/cext/mviewbuf.c +7 -1
- numba_cuda/numba/cuda/cext/mviewbuf.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cloudpickle/cloudpickle.py +4 -5
- numba_cuda/numba/cuda/codegen.py +46 -12
- numba_cuda/numba/cuda/compiler.py +15 -9
- numba_cuda/numba/cuda/core/analysis.py +29 -21
- numba_cuda/numba/cuda/core/annotations/pretty_annotate.py +1 -1
- numba_cuda/numba/cuda/core/annotations/type_annotations.py +4 -4
- numba_cuda/numba/cuda/core/base.py +12 -11
- numba_cuda/numba/cuda/core/bytecode.py +21 -13
- numba_cuda/numba/cuda/core/byteflow.py +336 -90
- numba_cuda/numba/cuda/core/compiler.py +3 -4
- numba_cuda/numba/cuda/core/compiler_machinery.py +3 -3
- numba_cuda/numba/cuda/core/config.py +5 -7
- numba_cuda/numba/cuda/core/consts.py +1 -1
- numba_cuda/numba/cuda/core/controlflow.py +17 -9
- numba_cuda/numba/cuda/core/cuda_errors.py +917 -0
- numba_cuda/numba/cuda/core/errors.py +4 -912
- numba_cuda/numba/cuda/core/inline_closurecall.py +82 -67
- numba_cuda/numba/cuda/core/interpreter.py +334 -160
- numba_cuda/numba/cuda/core/ir.py +191 -119
- numba_cuda/numba/cuda/core/ir_utils.py +149 -128
- numba_cuda/numba/cuda/core/postproc.py +8 -8
- numba_cuda/numba/cuda/core/pythonapi.py +3 -0
- numba_cuda/numba/cuda/core/rewrites/ir_print.py +6 -3
- numba_cuda/numba/cuda/core/rewrites/static_binop.py +1 -1
- numba_cuda/numba/cuda/core/rewrites/static_getitem.py +5 -5
- numba_cuda/numba/cuda/core/rewrites/static_raise.py +3 -3
- numba_cuda/numba/cuda/core/ssa.py +5 -5
- numba_cuda/numba/cuda/core/transforms.py +29 -16
- numba_cuda/numba/cuda/core/typed_passes.py +10 -10
- numba_cuda/numba/cuda/core/typeinfer.py +42 -27
- numba_cuda/numba/cuda/core/untyped_passes.py +82 -65
- numba_cuda/numba/cuda/cpython/unicode.py +2 -2
- numba_cuda/numba/cuda/cpython/unicode_support.py +1 -3
- numba_cuda/numba/cuda/cudadecl.py +0 -13
- numba_cuda/numba/cuda/cudadrv/devicearray.py +10 -9
- numba_cuda/numba/cuda/cudadrv/driver.py +142 -519
- numba_cuda/numba/cuda/cudadrv/dummyarray.py +4 -0
- numba_cuda/numba/cuda/cudadrv/nvrtc.py +87 -32
- numba_cuda/numba/cuda/cudaimpl.py +0 -12
- numba_cuda/numba/cuda/debuginfo.py +25 -0
- numba_cuda/numba/cuda/descriptor.py +1 -1
- numba_cuda/numba/cuda/device_init.py +4 -7
- numba_cuda/numba/cuda/deviceufunc.py +3 -6
- numba_cuda/numba/cuda/dispatcher.py +39 -49
- numba_cuda/numba/cuda/intrinsics.py +150 -1
- numba_cuda/numba/cuda/libdeviceimpl.py +1 -2
- numba_cuda/numba/cuda/lowering.py +36 -29
- numba_cuda/numba/cuda/memory_management/nrt.py +10 -14
- numba_cuda/numba/cuda/np/arrayobj.py +61 -9
- numba_cuda/numba/cuda/np/numpy_support.py +32 -9
- numba_cuda/numba/cuda/np/polynomial/polynomial_functions.py +4 -3
- numba_cuda/numba/cuda/printimpl.py +20 -0
- numba_cuda/numba/cuda/serialize.py +10 -0
- numba_cuda/numba/cuda/stubs.py +0 -11
- numba_cuda/numba/cuda/testing.py +4 -8
- numba_cuda/numba/cuda/tests/benchmarks/test_kernel_launch.py +21 -4
- numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +1 -2
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +195 -51
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +6 -2
- numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +3 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_events.py +1 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +6 -7
- numba_cuda/numba/cuda/tests/cudadrv/test_module_callbacks.py +11 -12
- numba_cuda/numba/cuda/tests/cudadrv/test_nvjitlink.py +53 -23
- numba_cuda/numba/cuda/tests/cudapy/test_analysis.py +61 -9
- numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +6 -0
- numba_cuda/numba/cuda/tests/cudapy/test_caching.py +47 -0
- numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +22 -1
- numba_cuda/numba/cuda/tests/cudapy/test_complex.py +13 -0
- numba_cuda/numba/cuda/tests/cudapy/test_copy_propagate.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_debug.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +94 -0
- numba_cuda/numba/cuda/tests/cudapy/test_device_array_capture.py +243 -0
- numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +3 -3
- numba_cuda/numba/cuda/tests/cudapy/test_extending.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_numba_interop.py +35 -0
- numba_cuda/numba/cuda/tests/cudapy/test_print.py +51 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +37 -35
- numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +117 -1
- numba_cuda/numba/cuda/tests/doc_examples/test_globals.py +111 -0
- numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +61 -0
- numba_cuda/numba/cuda/tests/nrt/test_nrt.py +31 -0
- numba_cuda/numba/cuda/tests/support.py +11 -0
- numba_cuda/numba/cuda/types/cuda_functions.py +1 -1
- numba_cuda/numba/cuda/typing/asnumbatype.py +37 -2
- numba_cuda/numba/cuda/typing/context.py +3 -1
- numba_cuda/numba/cuda/typing/typeof.py +51 -2
- {numba_cuda-0.21.1.dist-info → numba_cuda-0.24.0.dist-info}/METADATA +4 -13
- {numba_cuda-0.21.1.dist-info → numba_cuda-0.24.0.dist-info}/RECORD +106 -105
- numba_cuda/numba/cuda/cext/_devicearray.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_devicearray.cpp +0 -159
- numba_cuda/numba/cuda/cext/_devicearray.h +0 -29
- numba_cuda/numba/cuda/intrinsic_wrapper.py +0 -41
- {numba_cuda-0.21.1.dist-info → numba_cuda-0.24.0.dist-info}/WHEEL +0 -0
- {numba_cuda-0.21.1.dist-info → numba_cuda-0.24.0.dist-info}/licenses/LICENSE +0 -0
- {numba_cuda-0.21.1.dist-info → numba_cuda-0.24.0.dist-info}/licenses/LICENSE.numba +0 -0
- {numba_cuda-0.21.1.dist-info → numba_cuda-0.24.0.dist-info}/top_level.txt +0 -0
|
@@ -54,8 +54,8 @@ enable_inline_arraycall = True
|
|
|
54
54
|
def callee_ir_validator(func_ir):
|
|
55
55
|
"""Checks the IR of a callee is supported for inlining"""
|
|
56
56
|
for blk in func_ir.blocks.values():
|
|
57
|
-
for stmt in blk.find_insts(ir.
|
|
58
|
-
if isinstance(stmt.value, ir.
|
|
57
|
+
for stmt in blk.find_insts(ir.assign_types):
|
|
58
|
+
if isinstance(stmt.value, ir.yield_types):
|
|
59
59
|
msg = "The use of yield in a closure is unsupported."
|
|
60
60
|
raise errors.UnsupportedError(msg, loc=stmt.loc)
|
|
61
61
|
|
|
@@ -100,9 +100,9 @@ class InlineClosureCallPass(object):
|
|
|
100
100
|
while work_list:
|
|
101
101
|
_label, block = work_list.pop()
|
|
102
102
|
for i, instr in enumerate(block.body):
|
|
103
|
-
if isinstance(instr, ir.
|
|
103
|
+
if isinstance(instr, ir.assign_types):
|
|
104
104
|
expr = instr.value
|
|
105
|
-
if isinstance(expr, ir.
|
|
105
|
+
if isinstance(expr, ir.expr_types) and expr.op == "call":
|
|
106
106
|
call_name = guard(find_callname, self.func_ir, expr)
|
|
107
107
|
func_def = guard(
|
|
108
108
|
get_definition, self.func_ir, expr.func
|
|
@@ -212,7 +212,8 @@ class InlineClosureCallPass(object):
|
|
|
212
212
|
|
|
213
213
|
def _inline_closure(self, work_list, block, i, func_def):
|
|
214
214
|
require(
|
|
215
|
-
isinstance(func_def, ir.
|
|
215
|
+
isinstance(func_def, ir.expr_types)
|
|
216
|
+
and func_def.op == "make_function"
|
|
216
217
|
)
|
|
217
218
|
inline_closure_call(
|
|
218
219
|
self.func_ir,
|
|
@@ -235,7 +236,9 @@ def check_reduce_func(func_ir, func_var):
|
|
|
235
236
|
"Reduce function cannot be found for njit \
|
|
236
237
|
analysis"
|
|
237
238
|
)
|
|
238
|
-
if isinstance(reduce_func,
|
|
239
|
+
if isinstance(reduce_func, ir.freevar_types) or isinstance(
|
|
240
|
+
reduce_func, ir.global_types
|
|
241
|
+
):
|
|
239
242
|
if HAS_NUMBA:
|
|
240
243
|
from numba.core.registry import CPUDispatcher
|
|
241
244
|
|
|
@@ -341,10 +344,10 @@ class InlineWorker(object):
|
|
|
341
344
|
# Always copy the callee IR, it gets mutated
|
|
342
345
|
def copy_ir(the_ir):
|
|
343
346
|
kernel_copy = the_ir.copy()
|
|
344
|
-
kernel_copy.blocks = {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
347
|
+
kernel_copy.blocks = {
|
|
348
|
+
block_label: copy.deepcopy(block)
|
|
349
|
+
for block_label, block in the_ir.blocks.items()
|
|
350
|
+
}
|
|
348
351
|
return kernel_copy
|
|
349
352
|
|
|
350
353
|
callee_ir = copy_ir(callee_ir)
|
|
@@ -658,7 +661,10 @@ def inline_closure_call(
|
|
|
658
661
|
cellget.argtypes = (ctypes.py_object,)
|
|
659
662
|
items = tuple(cellget(x) for x in closure)
|
|
660
663
|
else:
|
|
661
|
-
assert
|
|
664
|
+
assert (
|
|
665
|
+
isinstance(closure, ir.expr_types)
|
|
666
|
+
and closure.op == "build_tuple"
|
|
667
|
+
)
|
|
662
668
|
items = closure.items
|
|
663
669
|
assert len(callee_code.co_freevars) == len(items)
|
|
664
670
|
_replace_freevars(callee_blocks, items)
|
|
@@ -786,18 +792,18 @@ def _get_callee_args(call_expr, callee, loc, func_ir):
|
|
|
786
792
|
if isinstance(callee_defaults, tuple): # Python 3.5
|
|
787
793
|
defaults_list = []
|
|
788
794
|
for x in callee_defaults:
|
|
789
|
-
if isinstance(x, ir.
|
|
795
|
+
if isinstance(x, ir.var_types):
|
|
790
796
|
defaults_list.append(x)
|
|
791
797
|
else:
|
|
792
798
|
# this branch is predominantly for kwargs from
|
|
793
799
|
# inlinable functions
|
|
794
800
|
defaults_list.append(ir.Const(value=x, loc=loc))
|
|
795
801
|
args = args + defaults_list
|
|
796
|
-
elif isinstance(callee_defaults, ir.
|
|
802
|
+
elif isinstance(callee_defaults, ir.var_types) or isinstance(
|
|
797
803
|
callee_defaults, str
|
|
798
804
|
):
|
|
799
805
|
default_tuple = func_ir.get_definition(callee_defaults)
|
|
800
|
-
assert isinstance(default_tuple, ir.
|
|
806
|
+
assert isinstance(default_tuple, ir.expr_types)
|
|
801
807
|
assert default_tuple.op == "build_tuple"
|
|
802
808
|
const_vals = [
|
|
803
809
|
func_ir.get_definition(x) for x in default_tuple.items
|
|
@@ -828,7 +834,7 @@ def _debug_dump(func_ir):
|
|
|
828
834
|
def _get_all_scopes(blocks):
|
|
829
835
|
"""Get all block-local scopes from an IR."""
|
|
830
836
|
all_scopes = []
|
|
831
|
-
for
|
|
837
|
+
for block in blocks.values():
|
|
832
838
|
if block.scope not in all_scopes:
|
|
833
839
|
all_scopes.append(block.scope)
|
|
834
840
|
return all_scopes
|
|
@@ -838,10 +844,10 @@ def _replace_args_with(blocks, args):
|
|
|
838
844
|
"""
|
|
839
845
|
Replace ir.Arg(...) with real arguments from call site
|
|
840
846
|
"""
|
|
841
|
-
for
|
|
842
|
-
assigns = block.find_insts(ir.
|
|
847
|
+
for block in blocks.values():
|
|
848
|
+
assigns = block.find_insts(ir.assign_types)
|
|
843
849
|
for stmt in assigns:
|
|
844
|
-
if isinstance(stmt.value, ir.
|
|
850
|
+
if isinstance(stmt.value, ir.arg_types):
|
|
845
851
|
idx = stmt.value.index
|
|
846
852
|
assert idx < len(args)
|
|
847
853
|
stmt.value = args[idx]
|
|
@@ -851,13 +857,13 @@ def _replace_freevars(blocks, args):
|
|
|
851
857
|
"""
|
|
852
858
|
Replace ir.FreeVar(...) with real variables from parent function
|
|
853
859
|
"""
|
|
854
|
-
for
|
|
855
|
-
assigns = block.find_insts(ir.
|
|
860
|
+
for block in blocks.values():
|
|
861
|
+
assigns = block.find_insts(ir.assign_types)
|
|
856
862
|
for stmt in assigns:
|
|
857
|
-
if isinstance(stmt.value, ir.
|
|
863
|
+
if isinstance(stmt.value, ir.freevar_types):
|
|
858
864
|
idx = stmt.value.index
|
|
859
865
|
assert idx < len(args)
|
|
860
|
-
if isinstance(args[idx], ir.
|
|
866
|
+
if isinstance(args[idx], ir.var_types):
|
|
861
867
|
stmt.value = args[idx]
|
|
862
868
|
else:
|
|
863
869
|
stmt.value = ir.Const(args[idx], stmt.loc)
|
|
@@ -867,11 +873,11 @@ def _replace_returns(blocks, target, return_label):
|
|
|
867
873
|
"""
|
|
868
874
|
Return return statement by assigning directly to target, and a jump.
|
|
869
875
|
"""
|
|
870
|
-
for
|
|
876
|
+
for block in blocks.values():
|
|
871
877
|
casts = []
|
|
872
878
|
for i in range(len(block.body)):
|
|
873
879
|
stmt = block.body[i]
|
|
874
|
-
if isinstance(stmt, ir.
|
|
880
|
+
if isinstance(stmt, ir.return_types):
|
|
875
881
|
assert i + 1 == len(block.body)
|
|
876
882
|
block.body[i] = ir.Assign(stmt.value, target, stmt.loc)
|
|
877
883
|
block.body.append(ir.Jump(return_label, stmt.loc))
|
|
@@ -880,8 +886,8 @@ def _replace_returns(blocks, target, return_label):
|
|
|
880
886
|
if cast.target.name == stmt.value.name:
|
|
881
887
|
cast.value = cast.value.value
|
|
882
888
|
elif (
|
|
883
|
-
isinstance(stmt, ir.
|
|
884
|
-
and isinstance(stmt.value, ir.
|
|
889
|
+
isinstance(stmt, ir.assign_types)
|
|
890
|
+
and isinstance(stmt.value, ir.expr_types)
|
|
885
891
|
and stmt.value.op == "cast"
|
|
886
892
|
):
|
|
887
893
|
casts.append(stmt)
|
|
@@ -892,7 +898,7 @@ def _add_definitions(func_ir, block):
|
|
|
892
898
|
Add variable definitions found in a block to parent func_ir.
|
|
893
899
|
"""
|
|
894
900
|
definitions = func_ir._definitions
|
|
895
|
-
assigns = block.find_insts(ir.
|
|
901
|
+
assigns = block.find_insts(ir.assign_types)
|
|
896
902
|
for stmt in assigns:
|
|
897
903
|
definitions[stmt.target.name].append(stmt.value)
|
|
898
904
|
|
|
@@ -910,27 +916,27 @@ def _find_arraycall(func_ir, block):
|
|
|
910
916
|
i = 0
|
|
911
917
|
while i < len(block.body):
|
|
912
918
|
instr = block.body[i]
|
|
913
|
-
if isinstance(instr, ir.
|
|
919
|
+
if isinstance(instr, ir.del_types):
|
|
914
920
|
# Stop the process if list_var becomes dead
|
|
915
921
|
if list_var and array_var and instr.value == list_var.name:
|
|
916
922
|
list_var_dead_after_array_call = True
|
|
917
923
|
break
|
|
918
924
|
pass
|
|
919
|
-
elif isinstance(instr, ir.
|
|
925
|
+
elif isinstance(instr, ir.assign_types):
|
|
920
926
|
# Found array_var = array(list_var)
|
|
921
927
|
lhs = instr.target
|
|
922
928
|
expr = instr.value
|
|
923
929
|
if guard(find_callname, func_ir, expr) == (
|
|
924
930
|
"array",
|
|
925
931
|
"numpy",
|
|
926
|
-
) and isinstance(expr.args[0], ir.
|
|
932
|
+
) and isinstance(expr.args[0], ir.var_types):
|
|
927
933
|
list_var = expr.args[0]
|
|
928
934
|
array_var = lhs
|
|
929
935
|
array_stmt_index = i
|
|
930
936
|
array_kws = dict(expr.kws)
|
|
931
937
|
elif (
|
|
932
|
-
isinstance(instr, ir.
|
|
933
|
-
and isinstance(instr.value, ir.
|
|
938
|
+
isinstance(instr, ir.setitem_types)
|
|
939
|
+
and isinstance(instr.value, ir.var_types)
|
|
934
940
|
and not list_var
|
|
935
941
|
):
|
|
936
942
|
list_var = instr.value
|
|
@@ -958,16 +964,17 @@ def _find_iter_range(func_ir, range_iter_var, swapped):
|
|
|
958
964
|
range_iter_def = get_definition(func_ir, range_iter_var)
|
|
959
965
|
debug_print("range_iter_var = ", range_iter_var, " def = ", range_iter_def)
|
|
960
966
|
require(
|
|
961
|
-
isinstance(range_iter_def, ir.
|
|
967
|
+
isinstance(range_iter_def, ir.expr_types)
|
|
968
|
+
and range_iter_def.op == "getiter"
|
|
962
969
|
)
|
|
963
970
|
range_var = range_iter_def.value
|
|
964
971
|
range_def = get_definition(func_ir, range_var)
|
|
965
972
|
debug_print("range_var = ", range_var, " range_def = ", range_def)
|
|
966
|
-
require(isinstance(range_def, ir.
|
|
973
|
+
require(isinstance(range_def, ir.expr_types) and range_def.op == "call")
|
|
967
974
|
func_var = range_def.func
|
|
968
975
|
func_def = get_definition(func_ir, func_var)
|
|
969
976
|
debug_print("func_var = ", func_var, " func_def = ", func_def)
|
|
970
|
-
require(isinstance(func_def, ir.
|
|
977
|
+
require(isinstance(func_def, ir.global_types) and func_def.value is range)
|
|
971
978
|
nargs = len(range_def.args)
|
|
972
979
|
swapping = [('"array comprehension"', "closure of"), range_def.func.loc]
|
|
973
980
|
if nargs == 1:
|
|
@@ -1082,20 +1089,23 @@ def _inline_arraycall(
|
|
|
1082
1089
|
dtype_def = None
|
|
1083
1090
|
dtype_mod_def = None
|
|
1084
1091
|
if "dtype" in array_kws:
|
|
1085
|
-
require(isinstance(array_kws["dtype"], ir.
|
|
1092
|
+
require(isinstance(array_kws["dtype"], ir.var_types))
|
|
1086
1093
|
# We require that dtype argument to be a constant of getattr Expr, and
|
|
1087
1094
|
# we'll remember its definition for later use.
|
|
1088
1095
|
dtype_def = get_definition(func_ir, array_kws["dtype"])
|
|
1089
|
-
require(
|
|
1096
|
+
require(
|
|
1097
|
+
isinstance(dtype_def, ir.expr_types) and dtype_def.op == "getattr"
|
|
1098
|
+
)
|
|
1090
1099
|
dtype_mod_def = get_definition(func_ir, dtype_def.value)
|
|
1091
1100
|
|
|
1092
1101
|
list_var_def = get_definition(func_ir, list_var)
|
|
1093
1102
|
debug_print("list_var = ", list_var, " def = ", list_var_def)
|
|
1094
|
-
if isinstance(list_var_def, ir.
|
|
1103
|
+
if isinstance(list_var_def, ir.expr_types) and list_var_def.op == "cast":
|
|
1095
1104
|
list_var_def = get_definition(func_ir, list_var_def.value)
|
|
1096
1105
|
# Check if the definition is a build_list
|
|
1097
1106
|
require(
|
|
1098
|
-
isinstance(list_var_def, ir.
|
|
1107
|
+
isinstance(list_var_def, ir.expr_types)
|
|
1108
|
+
and list_var_def.op == "build_list"
|
|
1099
1109
|
)
|
|
1100
1110
|
# The build_list must be empty
|
|
1101
1111
|
require(len(list_var_def.items) == 0)
|
|
@@ -1112,12 +1122,12 @@ def _inline_arraycall(
|
|
|
1112
1122
|
continue
|
|
1113
1123
|
block = func_ir.blocks[label]
|
|
1114
1124
|
debug_print("check loop body block ", label)
|
|
1115
|
-
for stmt in block.find_insts(ir.
|
|
1125
|
+
for stmt in block.find_insts(ir.assign_types):
|
|
1116
1126
|
expr = stmt.value
|
|
1117
|
-
if isinstance(expr, ir.
|
|
1127
|
+
if isinstance(expr, ir.expr_types) and expr.op == "call":
|
|
1118
1128
|
func_def = get_definition(func_ir, expr.func)
|
|
1119
1129
|
if (
|
|
1120
|
-
isinstance(func_def, ir.
|
|
1130
|
+
isinstance(func_def, ir.expr_types)
|
|
1121
1131
|
and func_def.op == "getattr"
|
|
1122
1132
|
and func_def.attr == "append"
|
|
1123
1133
|
):
|
|
@@ -1146,9 +1156,9 @@ def _inline_arraycall(
|
|
|
1146
1156
|
iter_vars = []
|
|
1147
1157
|
iter_first_vars = []
|
|
1148
1158
|
loop_header = func_ir.blocks[loop.header]
|
|
1149
|
-
for stmt in loop_header.find_insts(ir.
|
|
1159
|
+
for stmt in loop_header.find_insts(ir.assign_types):
|
|
1150
1160
|
expr = stmt.value
|
|
1151
|
-
if isinstance(expr, ir.
|
|
1161
|
+
if isinstance(expr, ir.expr_types):
|
|
1152
1162
|
if expr.op == "iternext":
|
|
1153
1163
|
iter_def = get_definition(func_ir, expr.value)
|
|
1154
1164
|
debug_print("iter_def = ", iter_def)
|
|
@@ -1175,7 +1185,7 @@ def _inline_arraycall(
|
|
|
1175
1185
|
removed = []
|
|
1176
1186
|
|
|
1177
1187
|
def is_removed(val, removed):
|
|
1178
|
-
if isinstance(val, ir.
|
|
1188
|
+
if isinstance(val, ir.var_types):
|
|
1179
1189
|
for x in removed:
|
|
1180
1190
|
if x.name == val.name:
|
|
1181
1191
|
return True
|
|
@@ -1184,7 +1194,7 @@ def _inline_arraycall(
|
|
|
1184
1194
|
# Skip list construction and skip terminator, add the rest to stmts
|
|
1185
1195
|
for i in range(len(loop_entry.body) - 1):
|
|
1186
1196
|
stmt = loop_entry.body[i]
|
|
1187
|
-
if isinstance(stmt, ir.
|
|
1197
|
+
if isinstance(stmt, ir.assign_types) and (
|
|
1188
1198
|
stmt.value is list_def or is_removed(stmt.value, removed)
|
|
1189
1199
|
):
|
|
1190
1200
|
removed.append(stmt.target)
|
|
@@ -1306,8 +1316,9 @@ def _inline_arraycall(
|
|
|
1306
1316
|
)
|
|
1307
1317
|
|
|
1308
1318
|
# Add back removed just in case they are used by something else
|
|
1309
|
-
|
|
1310
|
-
|
|
1319
|
+
stmts.extend(
|
|
1320
|
+
_new_definition(func_ir, var, array_var, loc) for var in removed
|
|
1321
|
+
)
|
|
1311
1322
|
|
|
1312
1323
|
# Add back terminator
|
|
1313
1324
|
stmts.append(terminator)
|
|
@@ -1319,7 +1330,7 @@ def _inline_arraycall(
|
|
|
1319
1330
|
# when range doesn't start from 0, index_var becomes loop index
|
|
1320
1331
|
# (iter_first_var) minus an offset (range_def[0])
|
|
1321
1332
|
terminator = loop_header.terminator
|
|
1322
|
-
assert isinstance(terminator, ir.
|
|
1333
|
+
assert isinstance(terminator, ir.branch_types)
|
|
1323
1334
|
# find the block in the loop body that header jumps to
|
|
1324
1335
|
block_id = terminator.truebr
|
|
1325
1336
|
blk = func_ir.blocks[block_id]
|
|
@@ -1377,7 +1388,9 @@ def _inline_arraycall(
|
|
|
1377
1388
|
# replace array call, by changing "a = array(b)" to "a = b"
|
|
1378
1389
|
stmt = func_ir.blocks[exit_block].body[array_call_index]
|
|
1379
1390
|
# stmt can be either array call or SetItem, we only replace array call
|
|
1380
|
-
if isinstance(stmt, ir.
|
|
1391
|
+
if isinstance(stmt, ir.assign_types) and isinstance(
|
|
1392
|
+
stmt.value, ir.expr_types
|
|
1393
|
+
):
|
|
1381
1394
|
stmt.value = array_var
|
|
1382
1395
|
func_ir._definitions[stmt.target.name] = [stmt.value]
|
|
1383
1396
|
|
|
@@ -1386,10 +1399,10 @@ def _inline_arraycall(
|
|
|
1386
1399
|
|
|
1387
1400
|
def _find_unsafe_empty_inferred(func_ir, expr):
|
|
1388
1401
|
unsafe_empty_inferred
|
|
1389
|
-
require(isinstance(expr, ir.
|
|
1402
|
+
require(isinstance(expr, ir.expr_types) and expr.op == "call")
|
|
1390
1403
|
callee = expr.func
|
|
1391
1404
|
callee_def = get_definition(func_ir, callee)
|
|
1392
|
-
require(isinstance(callee_def, ir.
|
|
1405
|
+
require(isinstance(callee_def, ir.global_types))
|
|
1393
1406
|
_make_debug_print("_find_unsafe_empty_inferred")(callee_def.value)
|
|
1394
1407
|
return callee_def.value == unsafe_empty_inferred
|
|
1395
1408
|
|
|
@@ -1411,7 +1424,7 @@ def _fix_nested_array(func_ir):
|
|
|
1411
1424
|
"""
|
|
1412
1425
|
arr_def = get_definition(func_ir, arr)
|
|
1413
1426
|
_make_debug_print("find_array_def")(arr, arr_def)
|
|
1414
|
-
if isinstance(arr_def, ir.
|
|
1427
|
+
if isinstance(arr_def, ir.expr_types):
|
|
1415
1428
|
if guard(_find_unsafe_empty_inferred, func_ir, arr_def):
|
|
1416
1429
|
return arr_def
|
|
1417
1430
|
elif arr_def.op == "getitem":
|
|
@@ -1430,7 +1443,7 @@ def _fix_nested_array(func_ir):
|
|
|
1430
1443
|
defined = set()
|
|
1431
1444
|
for i in range(len(body)):
|
|
1432
1445
|
inst = body[i]
|
|
1433
|
-
if isinstance(inst, ir.
|
|
1446
|
+
if isinstance(inst, ir.assign_types):
|
|
1434
1447
|
defined.add(inst.target.name)
|
|
1435
1448
|
if inst.value is expr:
|
|
1436
1449
|
new_varlist = []
|
|
@@ -1446,7 +1459,7 @@ def _fix_nested_array(func_ir):
|
|
|
1446
1459
|
else:
|
|
1447
1460
|
debug_print(var.name, " not yet defined")
|
|
1448
1461
|
var_def = get_definition(func_ir, var.name)
|
|
1449
|
-
if isinstance(var_def, ir.
|
|
1462
|
+
if isinstance(var_def, ir.const_types):
|
|
1450
1463
|
loc = var.loc
|
|
1451
1464
|
new_var = scope.redefine("new_var", loc)
|
|
1452
1465
|
new_const = ir.Const(var_def.value, loc)
|
|
@@ -1475,8 +1488,8 @@ def _fix_nested_array(func_ir):
|
|
|
1475
1488
|
3. replace the definition of
|
|
1476
1489
|
rhs = numba.unsafe.ndarray.empty_inferred(...) with rhs = lhs[idx]
|
|
1477
1490
|
"""
|
|
1478
|
-
require(isinstance(stmt, ir.
|
|
1479
|
-
require(isinstance(stmt.value, ir.
|
|
1491
|
+
require(isinstance(stmt, ir.setitem_types))
|
|
1492
|
+
require(isinstance(stmt.value, ir.var_types))
|
|
1480
1493
|
debug_print = _make_debug_print("fix_array_assign")
|
|
1481
1494
|
debug_print("found SetItem: ", stmt)
|
|
1482
1495
|
lhs = stmt.target
|
|
@@ -1485,14 +1498,16 @@ def _fix_nested_array(func_ir):
|
|
|
1485
1498
|
debug_print("found lhs_def: ", lhs_def)
|
|
1486
1499
|
rhs_def = get_definition(func_ir, stmt.value)
|
|
1487
1500
|
debug_print("found rhs_def: ", rhs_def)
|
|
1488
|
-
require(isinstance(rhs_def, ir.
|
|
1501
|
+
require(isinstance(rhs_def, ir.expr_types))
|
|
1489
1502
|
if rhs_def.op == "cast":
|
|
1490
1503
|
rhs_def = get_definition(func_ir, rhs_def.value)
|
|
1491
|
-
require(isinstance(rhs_def, ir.
|
|
1504
|
+
require(isinstance(rhs_def, ir.expr_types))
|
|
1492
1505
|
require(_find_unsafe_empty_inferred(func_ir, rhs_def))
|
|
1493
1506
|
# Find the array dimension of rhs
|
|
1494
1507
|
dim_def = get_definition(func_ir, rhs_def.args[0])
|
|
1495
|
-
require(
|
|
1508
|
+
require(
|
|
1509
|
+
isinstance(dim_def, ir.expr_types) and dim_def.op == "build_tuple"
|
|
1510
|
+
)
|
|
1496
1511
|
debug_print("dim_def = ", dim_def)
|
|
1497
1512
|
extra_dims = [
|
|
1498
1513
|
get_definition(func_ir, x, lhs_only=True) for x in dim_def.items
|
|
@@ -1501,7 +1516,7 @@ def _fix_nested_array(func_ir):
|
|
|
1501
1516
|
# Expand size tuple when creating lhs_def with extra_dims
|
|
1502
1517
|
size_tuple_def = get_definition(func_ir, lhs_def.args[0])
|
|
1503
1518
|
require(
|
|
1504
|
-
isinstance(size_tuple_def, ir.
|
|
1519
|
+
isinstance(size_tuple_def, ir.expr_types)
|
|
1505
1520
|
and size_tuple_def.op == "build_tuple"
|
|
1506
1521
|
)
|
|
1507
1522
|
debug_print("size_tuple_def = ", size_tuple_def)
|
|
@@ -1719,13 +1734,13 @@ def _inline_const_arraycall(block, func_ir, context, typemap, calltypes):
|
|
|
1719
1734
|
state = State()
|
|
1720
1735
|
|
|
1721
1736
|
for inst in block.body:
|
|
1722
|
-
if isinstance(inst, ir.
|
|
1723
|
-
if isinstance(inst.value, ir.
|
|
1737
|
+
if isinstance(inst, ir.assign_types):
|
|
1738
|
+
if isinstance(inst.value, ir.var_types):
|
|
1724
1739
|
if inst.value.name in state.list_vars:
|
|
1725
1740
|
state.list_vars.append(inst.target.name)
|
|
1726
1741
|
state.stmts.append(inst)
|
|
1727
1742
|
continue
|
|
1728
|
-
elif isinstance(inst.value, ir.
|
|
1743
|
+
elif isinstance(inst.value, ir.expr_types):
|
|
1729
1744
|
expr = inst.value
|
|
1730
1745
|
if expr.op == "build_list":
|
|
1731
1746
|
# new build_list encountered, reset state
|
|
@@ -1745,7 +1760,7 @@ def _inline_const_arraycall(block, func_ir, context, typemap, calltypes):
|
|
|
1745
1760
|
):
|
|
1746
1761
|
state.modified = True
|
|
1747
1762
|
continue
|
|
1748
|
-
elif isinstance(inst, ir.
|
|
1763
|
+
elif isinstance(inst, ir.del_types):
|
|
1749
1764
|
removed_var = inst.value
|
|
1750
1765
|
if removed_var in state.list_items:
|
|
1751
1766
|
state.dels.append(inst)
|
|
@@ -1764,10 +1779,10 @@ def _inline_const_arraycall(block, func_ir, context, typemap, calltypes):
|
|
|
1764
1779
|
body = []
|
|
1765
1780
|
for inst in state.stmts:
|
|
1766
1781
|
if (
|
|
1767
|
-
isinstance(inst, ir.
|
|
1782
|
+
isinstance(inst, ir.assign_types)
|
|
1768
1783
|
and inst.target.name in state.dead_vars
|
|
1769
1784
|
) or (
|
|
1770
|
-
isinstance(inst, ir.
|
|
1785
|
+
isinstance(inst, ir.del_types)
|
|
1771
1786
|
and inst.value in state.dead_vars
|
|
1772
1787
|
):
|
|
1773
1788
|
continue
|