Skip to content

Commit a61ba93

Browse files
yubing.shen逸凡 陈
authored andcommitted
feat: Create a rearrangement logical operation
--Added dimensional degradation steps --Added 1D 2D 3D rearrangement operations --Reset the stride after rearrangement Change-Id: I981856dba956fbb893d9e80216a875990ed3781c
1 parent ab3ad6a commit a61ba93

28 files changed

Lines changed: 112 additions & 8 deletions

python/test/test_onnx.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def __init__(self,
5555
"AddBcast2": (self.test_AddBcast2, Y, Y, Y, N, Y, Y),
5656
"AddBcast3": (self.test_AddBcast3, N, N, N, N, N, N), # failed cases
5757
"AddBcast4": (self.test_AddBcast4, N, Y, Y, N, N, N),
58+
"AddNoRearrange": (self.test_AddNoRearrange, N, Y, Y, N, Y, N),
59+
"AddRearrange_1d": (self.test_AddRearrange_1d, N, Y, Y, N, Y, N),
60+
"AddRearrange_2d": (self.test_AddRearrange_2d, N, Y, Y, N, Y, N),
61+
"AddRearrange_3d": (self.test_AddRearrange_3d, N, Y, Y, N, Y, N),
5862
"Acos": (self.test_Arccos, Y, Y, Y, N, Y, Y),
5963
"Atan": (self.test_Arctan, N, Y, Y, N, Y, Y),
6064
"Atanh": (self.test_Arctanh, Y, Y, Y, N, Y, Y),
@@ -4387,6 +4391,106 @@ def test_AddBcast4(self, case_name):
43874391

43884392
self.onnx_and_test(graph_def, name=sub_case_name)
43894393

4394+
def test_AddRearrange_1d(self, case_name):
4395+
test_cases = [
4396+
([200], [1]),
4397+
([65536], [1]),
4398+
([4096, 16], [1, 1]),
4399+
([2, 20, 5], [1, 1, 1]),
4400+
([2, 10, 2, 5], [1, 1, 1, 1]),
4401+
]
4402+
4403+
for shape_a, shape_b in test_cases:
4404+
shape_a_str = ','.join(map(str, shape_a))
4405+
shape_b_str = ','.join(map(str, shape_b))
4406+
4407+
graph_txt = """
4408+
%s_row (float[%s] a, float[%s] b) => (float[%s] output)
4409+
{
4410+
output = Add(a, b)
4411+
}
4412+
""" % (case_name, shape_a_str, shape_b_str, shape_a_str)
4413+
graph_def = onnx.parser.parse_graph(graph_txt)
4414+
self.onnx_and_test(graph_def)
4415+
4416+
def test_AddRearrange_2d(self, case_name):
4417+
test_cases = [
4418+
([128, 64], [128, 1]),
4419+
([512, 128], [512, 1]),
4420+
([4, 128, 128], [4, 128, 1]),
4421+
([2, 2, 128, 128], [2, 2, 128, 1]),
4422+
([320, 192], [1, 192]),
4423+
([512, 128], [1, 128]),
4424+
([4, 128, 128], [1, 128, 128]),
4425+
([320, 1], [1, 192]),
4426+
([512, 1], [1, 128]),
4427+
]
4428+
4429+
for shape_a, shape_b in test_cases:
4430+
shape_a_str = ','.join(map(str, shape_a))
4431+
shape_b_str = ','.join(map(str, shape_b))
4432+
4433+
graph_txt = """
4434+
%s_row (float[%s] a, float[%s] b) => (float[%s] output)
4435+
{
4436+
output = Add(a, b)
4437+
}
4438+
""" % (case_name, shape_a_str, shape_b_str, shape_a_str)
4439+
graph_def = onnx.parser.parse_graph(graph_txt)
4440+
self.onnx_and_test(graph_def)
4441+
4442+
def test_AddRearrange_3d(self, case_name):
4443+
test_cases = [
4444+
([128, 50, 64], [128, 1, 64]),
4445+
([2, 64, 50, 32], [2, 64, 1, 32]),
4446+
([128, 6400, 64], [1, 6400, 1]),
4447+
([256, 128, 32], [1, 128, 1]),
4448+
([128, 50, 1], [128, 1, 64]),
4449+
([128, 6400, 1], [1, 6400, 64]),
4450+
([256, 128, 1], [1, 128, 32]),
4451+
([128, 1, 64], [1, 50, 64]),
4452+
([2, 64, 1, 32], [1, 50, 32]),
4453+
([128, 1, 64], [1, 50, 1]),
4454+
]
4455+
4456+
for shape_a, shape_b in test_cases:
4457+
shape_a_str = ','.join(map(str, shape_a))
4458+
shape_b_str = ','.join(map(str, shape_b))
4459+
4460+
graph_txt = """
4461+
%s_row (float[%s] a, float[%s] b) => (float[%s] output)
4462+
{
4463+
output = Add(a, b)
4464+
}
4465+
""" % (case_name, shape_a_str, shape_b_str, shape_a_str)
4466+
graph_def = onnx.parser.parse_graph(graph_txt)
4467+
self.onnx_and_test(graph_def)
4468+
4469+
def test_AddNoRearrange(self, case_name):
4470+
test_cases = [
4471+
([1, 96, 1, 1], [65536, 96, 1, 1], "unsupported_2d_cross"),
4472+
([1, 64, 1], [128, 1, 32], "unsupported_3d_cross"),
4473+
([10, 10], [1, 10], "small_elements_1d"),
4474+
([8, 8, 8], [1, 8, 8], "small_elements_2d"),
4475+
([4, 4, 4, 4], [1, 4, 4, 4], "small_elements_3d"),
4476+
([360, 11, 12, 7], [360, 1, 12, 7], "a_not_divisible"),
4477+
([100, 50, 32], [100, 1, 32], "3d_a_not_divisible"),
4478+
([4, 9, 10, 11, 12, 7], [4, 1, 10, 1, 12, 7], "6d_input"),
4479+
]
4480+
4481+
for shape_a, shape_b, desc in test_cases:
4482+
shape_a_str = ','.join(map(str, shape_a))
4483+
shape_b_str = ','.join(map(str, shape_b))
4484+
4485+
graph_txt = """
4486+
%s_%s (float[%s] a, float[%s] b) => (float[%s] output)
4487+
{
4488+
output = Add(a, b)
4489+
}
4490+
""" % (case_name, desc, shape_a_str, shape_b_str, shape_a_str)
4491+
graph_def = onnx.parser.parse_graph(graph_txt)
4492+
self.onnx_and_test(graph_def)
4493+
43904494
def test_AddWeight2(self, case_name):
43914495
input_shape = [1, 16, 8, 8]
43924496
wshape = [16, 1, 1]

third_party/nntoolchain/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ cp out/install/lib/libcmodel_1684.so /workspace/tpu-mlir/third_party/nntoolchain
1313
cp bmcompiler/libbackend/libbackend_1684.so /workspace/tpu-mlir/third_party/nntoolchain/lib/
1414
```
1515

16-
## TPU1684X/1688/BM1690/SG2380/CV184X/SGTPUV8 2025-09-25
16+
## TPU1684X/1688/BM1690/SG2380/CV184X/SGTPUV8 2025-10-23
1717
```bash
18-
#bm1684x sha256: 3e9a1bb80573ecfcb29f150c43466d80dd9200f0
18+
#bm1684x sha256: 376191048a4f4d04b2d89e3f46d19a9ef531ed3a
1919
cd TPU1686
2020
source scripts/envsetup.sh bm1684x
2121
debug: rebuild_backend_lib_cmodel
@@ -26,7 +26,7 @@ rebuild_firmware
2626
cp build/firmware_core/libfirmware_core.a /workspace/tpu-mlir/third_party/nntoolchain/lib/libbm1684x_kernel_module.a
2727
/workspace/tpu-mlir/lib/PplBackend/build.sh
2828

29-
#bm1688 sha256: 3e9a1bb80573ecfcb29f150c43466d80dd9200f0
29+
#bm1688 sha256: 376191048a4f4d04b2d89e3f46d19a9ef531ed3a
3030
cd TPU1686
3131
source scripts/envsetup.sh bm1686
3232
debug: rebuild_backend_lib_cmodel
@@ -37,7 +37,7 @@ rebuild_firmware
3737
cp build/firmware_core/libfirmware_core.a /workspace/tpu-mlir/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.a
3838
/workspace/tpu-mlir/lib/PplBackend/build.sh
3939

40-
#bm1690 sha256: 3e9a1bb80573ecfcb29f150c43466d80dd9200f0
40+
#bm1690 sha256: 376191048a4f4d04b2d89e3f46d19a9ef531ed3a
4141
cd TPU1686
4242
source scripts/envsetup.sh sg2260
4343
debug: rebuild_backend_lib_cmodel

0 commit comments

Comments
 (0)