From 74da12c5b9e788b82a66eff4f48a1c480699d260 Mon Sep 17 00:00:00 2001 From: "Boblest Sebastian (ETAS-DEV/XPC-Fe1)" Date: Tue, 21 Jun 2022 14:04:24 +0200 Subject: [PATCH 1/5] changed x86/concat to use lists of ints instead of te.tensor.Tensor for loop extents and array offsets --- python/tvm/topi/x86/concat.py | 39 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/python/tvm/topi/x86/concat.py b/python/tvm/topi/x86/concat.py index 5cb3cd3f57d5..5804cd73200f 100644 --- a/python/tvm/topi/x86/concat.py +++ b/python/tvm/topi/x86/concat.py @@ -38,48 +38,45 @@ def concatenate(data: tvm.te.Tensor, axis: Optional[int] = 0): ret : tvm.te.Tensor """ - def gen_ir_1d(data_bufs, in_outers_tensor, in_cumsum_tensor, out_buf): + in_outers = [int(np.prod(i.shape[axis:])) for i in data] + in_outers_cumsum = [0, *np.cumsum(in_outers, dtype="int64")[0:-1]] + + def gen_ir_1d(data_bufs, out_buf): """Custom conactenation execution.""" i_b = tvm.tir.ir_builder.create() data_bufs1 = [i_b.buffer_ptr(data_buf) for data_buf in data_bufs] out_buf = i_b.buffer_ptr(out_buf) - outers = i_b.buffer_ptr(in_outers_tensor) - cumsum = i_b.buffer_ptr(in_cumsum_tensor) + for i in range(len(data)): - with i_b.for_range(0, outers[i], name="j") as j: - out_buf[cumsum[i] + j] = data_bufs1[i][j] + with i_b.for_range(0, in_outers[i], name="j") as j: + out_buf[in_outers_cumsum[i] + j] = data_bufs1[i][j] return i_b.get() - def gen_ir(data_bufs, in_outers_tensor, in_cumsum_tensor, out_buf, inner, outer): + def gen_ir(data_bufs, out_buf, inner, outer): """Common case of conactenation execution.""" i_b = tvm.tir.ir_builder.create() data_bufs1 = [i_b.buffer_ptr(data_buf) for data_buf in data_bufs] out_buf = i_b.buffer_ptr(out_buf) - outers = i_b.buffer_ptr(in_outers_tensor) - cumsum = i_b.buffer_ptr(in_cumsum_tensor) if inner > 1: with i_b.for_range(0, inner, name="inn", kind="parallel") as inn: pos = inn * outer for i in range(len(data)): - offset = inn * outers[i] - with i_b.for_range(0, outers[i], name="j") as j: - out_buf[pos + cumsum[i] + j] = data_bufs1[i][offset + j] + offset = inn * in_outers[i] + with i_b.for_range(0, in_outers[i], name="j") as j: + out_buf[pos + in_outers_cumsum[i] + j] = data_bufs1[i][offset + j] else: for i in range(len(data)): - with i_b.for_range(0, outers[i], name="j", kind="parallel") as j: - out_buf[cumsum[i] + j] = data_bufs1[i][j] + with i_b.for_range(0, in_outers[i], name="j", kind="parallel") as j: + out_buf[in_outers_cumsum[i] + j] = data_bufs1[i][j] return i_b.get() if axis < 0: axis += len(data[0].shape) concat_axis_sizes = [int(t.shape[axis]) for t in data] join_size = int(np.sum(concat_axis_sizes)) - in_outers = [int(np.prod(i.shape[axis:])) for i in data] - in_outers_cumsum = [0, *np.cumsum(in_outers, dtype="int64")[0:-1]] + dtype = data[0].dtype out_shape = data[0].shape[:axis] + [join_size] + data[0].shape[axis + 1 :] - in_outers_tensor = const_vector(in_outers) - in_cumsum_tensor = const_vector(in_outers_cumsum, name="cumsum") right_val = np.prod(out_shape[axis:]) left_val = np.prod(out_shape[:axis]) @@ -92,8 +89,8 @@ def gen_ir(data_bufs, in_outers_tensor, in_cumsum_tensor, out_buf, inner, outer) # badly parallelized case return te.extern( [out_shape], - list(data) + [in_outers_tensor, in_cumsum_tensor], - lambda ins, outs: gen_ir_1d(ins, ins[-2], ins[-1], outs[0]), + list(data), + lambda ins, outs: gen_ir_1d(ins, outs[0]), dtype=dtype, name="concatenate_ext", ) @@ -102,8 +99,8 @@ def gen_ir(data_bufs, in_outers_tensor, in_cumsum_tensor, out_buf, inner, outer) outer = get_const_int(int(right_val)) return te.extern( [out_shape], - list(data) + [in_outers_tensor, in_cumsum_tensor], - lambda ins, outs: gen_ir(ins, ins[-2], ins[-1], outs[0], inner, outer), + list(data), + lambda ins, outs: gen_ir(ins, outs[0], inner, outer), dtype=dtype, name="concatenate_ext", ) From 69a7027c05ad052439f04cbb6e5610b992099de0 Mon Sep 17 00:00:00 2001 From: "Boblest Sebastian (ETAS-DEV/XPC-Fe1)" Date: Tue, 21 Jun 2022 14:07:55 +0200 Subject: [PATCH 2/5] typos fixed --- python/tvm/topi/x86/concat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/tvm/topi/x86/concat.py b/python/tvm/topi/x86/concat.py index 5804cd73200f..14db9a2656cd 100644 --- a/python/tvm/topi/x86/concat.py +++ b/python/tvm/topi/x86/concat.py @@ -23,7 +23,8 @@ def concatenate(data: tvm.te.Tensor, axis: Optional[int] = 0): - """Join a sequence of arrays along an existing axis. Optimized for CPU exeution. + """Join a sequence of arrays along an existing axis. + Optimized for CPU execution. Parameters ---------- @@ -42,7 +43,7 @@ def concatenate(data: tvm.te.Tensor, axis: Optional[int] = 0): in_outers_cumsum = [0, *np.cumsum(in_outers, dtype="int64")[0:-1]] def gen_ir_1d(data_bufs, out_buf): - """Custom conactenation execution.""" + """Custom concatenation execution.""" i_b = tvm.tir.ir_builder.create() data_bufs1 = [i_b.buffer_ptr(data_buf) for data_buf in data_bufs] out_buf = i_b.buffer_ptr(out_buf) @@ -53,7 +54,7 @@ def gen_ir_1d(data_bufs, out_buf): return i_b.get() def gen_ir(data_bufs, out_buf, inner, outer): - """Common case of conactenation execution.""" + """Common case of concatenation execution.""" i_b = tvm.tir.ir_builder.create() data_bufs1 = [i_b.buffer_ptr(data_buf) for data_buf in data_bufs] out_buf = i_b.buffer_ptr(out_buf) From e4d3944b2fa6003a93f6b945c2146c59efdd07e1 Mon Sep 17 00:00:00 2001 From: "Boblest Sebastian (ETAS-DEV/XPC-Fe1)" Date: Tue, 21 Jun 2022 15:05:09 +0200 Subject: [PATCH 3/5] removed unused import --- python/tvm/topi/x86/concat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/topi/x86/concat.py b/python/tvm/topi/x86/concat.py index 14db9a2656cd..28f650bca95f 100644 --- a/python/tvm/topi/x86/concat.py +++ b/python/tvm/topi/x86/concat.py @@ -19,7 +19,7 @@ import tvm from tvm import te import numpy as np -from ..utils import get_const_int, const_vector +from ..utils import get_const_int def concatenate(data: tvm.te.Tensor, axis: Optional[int] = 0): From 97b99cc6f29d6a584eaac093f21285181fe69f7c Mon Sep 17 00:00:00 2001 From: "Boblest Sebastian (ETAS-DEV/XPC-Fe1)" Date: Tue, 21 Jun 2022 16:51:45 +0200 Subject: [PATCH 4/5] fixed micro model test --- tests/python/unittest/test_micro_model_library_format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/python/unittest/test_micro_model_library_format.py b/tests/python/unittest/test_micro_model_library_format.py index 0caae1cdd9d4..b7be2deb799f 100644 --- a/tests/python/unittest/test_micro_model_library_format.py +++ b/tests/python/unittest/test_micro_model_library_format.py @@ -460,7 +460,7 @@ def test_export_byoc_c_module(): "constants_size_bytes": 0, "device": 1, "io_size_bytes": 4800, - "workspace_size_bytes": 1264, + "workspace_size_bytes": 1200, } ] else: @@ -469,7 +469,7 @@ def test_export_byoc_c_module(): "constants_size_bytes": 0, "device": 1, "io_size_bytes": 4800, - "workspace_size_bytes": 1248, + "workspace_size_bytes": 1216, } ] From 1f7ffd0a38370831c5fa349db4b1e8b98e0ea41b Mon Sep 17 00:00:00 2001 From: "Boblest Sebastian (ETAS-DEV/XPC-Fe1)" Date: Tue, 21 Jun 2022 17:31:46 +0200 Subject: [PATCH 5/5] fixed micro model test --- tests/python/unittest/test_micro_model_library_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/unittest/test_micro_model_library_format.py b/tests/python/unittest/test_micro_model_library_format.py index b7be2deb799f..7be5037478b1 100644 --- a/tests/python/unittest/test_micro_model_library_format.py +++ b/tests/python/unittest/test_micro_model_library_format.py @@ -469,7 +469,7 @@ def test_export_byoc_c_module(): "constants_size_bytes": 0, "device": 1, "io_size_bytes": 4800, - "workspace_size_bytes": 1216, + "workspace_size_bytes": 1200, } ]