Skip to content

Commit

Permalink
[tpu-mlir] fix matmul for bm168x
Browse files Browse the repository at this point in the history
1. fix hdim_is_batch bias_merge_izp size error
2. fix has_izp && r_trans buffer size to capable with backend
3. enable mobilebert_tf

Change-Id: Ifc0bd15630170484252a8fed8dc89497605ea1db
  • Loading branch information
chen.chen committed May 19, 2023
1 parent 2fc9217 commit dd3a276
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/Dialect/Top/Canonicalize/MatMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,5 @@ struct NoKeepDimsAddReshape : public OpRewritePattern<MatMulOp> {

void MatMulOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
// results.insert<MatMulWithBias, NoKeepDimsAddReshape>(context);
results.insert<MatMulWithBias>(context);
results.insert<MatMulWithBias, NoKeepDimsAddReshape>(context);
}
3 changes: 3 additions & 0 deletions lib/Dialect/Tpu/Interfaces/BM1684X/MatMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ int64_t tpu::MatMulOp::getBufferSize_bm1684x(
buffer_size +=
align_up(p.hdim_is_batch ? w1 : h1, BM168x::eu_num(sizeof(int32_t))) *
sizeof(int32_t);
if (p.right_transpose) {
buffer_size += ceiling_func(c1, BM168x::NPU_NUM) * align_up(1, BM168x::eu_num(sizeof(int32_t))) * sizeof(int32_t);
}
}

return buffer_size;
Expand Down
5 changes: 5 additions & 0 deletions lib/Dialect/Tpu/Interfaces/Common/MatMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ matmul_attr_t tpu::MatMulOp::parseParam() {
if (p.hdim_is_batch) {
p.K = b_s[b_dims - 3];
p.N = b_s[b_dims - 1];
// fix bias_merge_izp size for bm1684x
if (module::isBM1684XFamily()) {
p.N = b_s[b_dims - 3];
p.K = b_s[b_dims - 1];
}
} else {
// trans hw
p.N = b_s[b_dims - 2];
Expand Down
2 changes: 1 addition & 1 deletion regression/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"resnet50_tf": (N, Y, Y, N, N, N, N),
"ssd_mobilenet_v1_tf": (N, Y, Y, N, N, N, N),
"yolov5s_tf": (N, Y, Y, N, N, N, N),
"mobilebert_tf": (N, Y, N, N, N, N, N),
"mobilebert_tf": (N, Y, Y, N, N, N, N),
######## PaddlePaddle ## ##############
"pp_humanseg": (N, Y, Y, N, N, N, N),
"pp_liteseg": (N, Y, Y, N, N, N, N),
Expand Down
4 changes: 2 additions & 2 deletions third_party/nntoolchain/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
2023-05-09
build from TPU1684 f39362b8611e2de88a5d079b2bde3b676d5d0e5a
2023-05-18
build from TPU1686 90f054ad7fa651f24613f479fc2a564054993a54
2023-05-19
build from TPU1686 d77ddc530e52648c2ce186892fa6310543eb126a
2023-04-12
build from tpu-runtime 9e9d9a7d983305cb15c36b5774f9dd3259d6b970
2023-03-03
Expand Down
Binary file modified third_party/nntoolchain/lib/libbackend_1684x.so
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libbackend_1686.so
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libcmodel_1684x.so
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libcmodel_1686.so
Binary file not shown.

0 comments on commit dd3a276

Please sign in to comment.