diff --git a/include/tpu_mlir/Backend/BM168x/Param.h b/include/tpu_mlir/Backend/BM168x/Param.h index fbed5f777..5daa8f290 100644 --- a/include/tpu_mlir/Backend/BM168x/Param.h +++ b/include/tpu_mlir/Backend/BM168x/Param.h @@ -1266,6 +1266,7 @@ typedef struct a16_matmul_spec { int weight_bits; bool has_zp; int q_group_size; + int use_multi_core; } a16_matmul_spec_t; typedef struct batch_matmul_common_spec { diff --git a/include/tpu_mlir/Support/Module.h b/include/tpu_mlir/Support/Module.h index 5dc4994d3..0183f4d4d 100644 --- a/include/tpu_mlir/Support/Module.h +++ b/include/tpu_mlir/Support/Module.h @@ -191,6 +191,7 @@ bool IsHdimIsBatch(Operation *Op); bool IsHdimIsBatch(Value value); bool isOpInCoreMatch(Operation *Op); bool isOpInCoreParallel(Operation *Op); +bool isOpInGroupParallel(Operation *Op); bool isOpInDevParallel(Operation *Op); bool isOpInBlock(Operation *op); FuncOp getFuncOp(ModuleOp module, StringRef func_name); diff --git a/lib/Dialect/Tpu/Interfaces/BM1684X/A16MatMul.cpp b/lib/Dialect/Tpu/Interfaces/BM1684X/A16MatMul.cpp index bf20bbfc9..3fcb616e3 100644 --- a/lib/Dialect/Tpu/Interfaces/BM1684X/A16MatMul.cpp +++ b/lib/Dialect/Tpu/Interfaces/BM1684X/A16MatMul.cpp @@ -26,8 +26,14 @@ void tpu::A16MatMulOp::codegen_global_bm1684x() { auto op = getOperation(); auto input_spec = BM168x::get_input_spec(op); auto output_spec = BM168x::get_output_spec(op); - BM168x::call_global_func("backend_api_a16_matmul_global", &spec, sizeof(spec), - input_spec->data(), output_spec->data()); + if (supportMultiCore(*this)){ + spec.use_multi_core = 1; + } else { + spec.use_multi_core = 0; + } + BM168x::call_global_func("backend_api_a16_matmul_global", &spec, + sizeof(spec), input_spec->data(), + output_spec->data()); } // ====================================== diff --git a/lib/Dialect/Tpu/Interfaces/Common/A16MatMul.cpp b/lib/Dialect/Tpu/Interfaces/Common/A16MatMul.cpp index 0c1b88504..6e3bfc543 100644 --- a/lib/Dialect/Tpu/Interfaces/Common/A16MatMul.cpp +++ b/lib/Dialect/Tpu/Interfaces/Common/A16MatMul.cpp @@ -493,4 +493,4 @@ ArrayAttr tpu::A16MatMulOp::getIndexingMaps() { return Builder(ctx).getAffineMapArrayAttr(indexingMaps); } -bool tpu::A16MatMulOp::support_multi_core() { return module::isSG2380(); } +bool tpu::A16MatMulOp::support_multi_core() { return (module::isSG2380() || module::isBM1690Family()) && !module::isOpInGroupParallel(*this);} diff --git a/lib/Support/Module.cpp b/lib/Support/Module.cpp index a3a5429aa..8eb289159 100644 --- a/lib/Support/Module.cpp +++ b/lib/Support/Module.cpp @@ -826,6 +826,17 @@ bool isOpInCoreParallel(Operation *Op) { return false; } +bool isOpInGroupParallel(Operation *Op) { + if (Op == nullptr) { + return false; + } + auto parent = Op->getParentOp(); + if (isa_and_nonnull(parent)) { + return true; + } + return false; +} + // op in [CoreBegin, CoreEnd] bool isOpInCoreMatch(Operation *op) { while (!op->use_empty()) { diff --git a/third_party/nntoolchain/README.md b/third_party/nntoolchain/README.md index ee7307922..ba88ced36 100755 --- a/third_party/nntoolchain/README.md +++ b/third_party/nntoolchain/README.md @@ -17,6 +17,7 @@ cp bmcompiler/libbackend/libbackend_1684.so /workspace/tpu-mlir/third_party/nnto #bm1684x sha256: b9653fd714815e33546701730698c4f14114b5dd # - yolov5s perf revive: 5fd5cfea836a56e91faf59ae669b1865959019a4 +# + a16matmul multi_core: ead92658fce9ad437a71a3a873600d968ded14db cd TPU1686 source scripts/envsetup.sh bm1684x debug: rebuild_backend_lib_cmodel @@ -29,6 +30,7 @@ cp build/firmware_core/libfirmware_core.a /workspace/tpu-mlir/third_party/nntool #bm1688 sha256: 8453b87d6b1ad8858692f8ca4cd2441e7b677f1e # - MDSR_x3/x4 perf revive: 253d8e58e7b2764d625bfcdd9d049d0184a0f602 +# + a16matmul multi_core: ead92658fce9ad437a71a3a873600d968ded14db cd TPU1686 source scripts/envsetup.sh bm1686 debug: rebuild_backend_lib_cmodel @@ -42,6 +44,7 @@ cp build/firmware_core/libfirmware_core.a /workspace/tpu-mlir/third_party/nntool #bm1690 sha256: 90428e6d47c53c73fab8f846a1f579af456862aa # + MaxPoolingWithMask optimize: 85e07f6a2e6059f84b1b591b2df40fe7e88f21dc # + RMSNorm global layer bugfix: d100aad8b3b7d6b9d262b5aaee7e1e0f46daef43 (not merged) +# + a16matmul multi_core: ead92658fce9ad437a71a3a873600d968ded14db cd TPU1686 source scripts/envsetup.sh sg2260 debug: rebuild_backend_lib_cmodel @@ -53,7 +56,7 @@ unset EXTRA_CONFIG && rebuild_firmware cp build/firmware_core/libfirmware_core.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libbm1690_kernel_module.so cp build/firmware_core/libfirmware_core.a /workspace/tpu-mlir/third_party/nntoolchain/lib/libbm1690_kernel_module.a -#sg2380 sha256: 8453b87d6b1ad8858692f8ca4cd2441e7b677f1e +#sg2380 sha256: ead92658fce9ad437a71a3a873600d968ded14db cd TPU1686 source scripts/envsetup.sh sg2380 debug: rebuild_backend_lib_cmodel @@ -61,7 +64,7 @@ elease: unset EXTRA_CONFIG && rebuild_backend_lib_release_cmodel cp build/backend_api/libbackend_sg2380.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libbackend_sg2380.so cp build_runtime/firmware_core/libcmodel_firmware.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libcmodel_sg2380.so -#mars3 sha256: 68a4781b8f0ab6bb38eab38e4d1fd9c6f8a426b4 +#mars3 sha256: ead92658fce9ad437a71a3a873600d968ded14db cd TPU1686 source scripts/envsetup.sh mars3 debug: rebuild_backend_lib_cmodel diff --git a/third_party/nntoolchain/lib/libbackend_1684x.so b/third_party/nntoolchain/lib/libbackend_1684x.so index ecbccd9a5..282b088b5 100755 Binary files a/third_party/nntoolchain/lib/libbackend_1684x.so and b/third_party/nntoolchain/lib/libbackend_1684x.so differ diff --git a/third_party/nntoolchain/lib/libbackend_1688.so b/third_party/nntoolchain/lib/libbackend_1688.so index 5b47090b0..cfbd71b23 100755 Binary files a/third_party/nntoolchain/lib/libbackend_1688.so and b/third_party/nntoolchain/lib/libbackend_1688.so differ diff --git a/third_party/nntoolchain/lib/libbackend_bm1690.so b/third_party/nntoolchain/lib/libbackend_bm1690.so index 5d11ccf42..377456518 100755 Binary files a/third_party/nntoolchain/lib/libbackend_bm1690.so and b/third_party/nntoolchain/lib/libbackend_bm1690.so differ diff --git a/third_party/nntoolchain/lib/libbackend_mars3.so b/third_party/nntoolchain/lib/libbackend_mars3.so index 653732f61..34eb524be 100755 Binary files a/third_party/nntoolchain/lib/libbackend_mars3.so and b/third_party/nntoolchain/lib/libbackend_mars3.so differ diff --git a/third_party/nntoolchain/lib/libbackend_sg2380.so b/third_party/nntoolchain/lib/libbackend_sg2380.so index 09ac6d93e..c393597cd 100755 Binary files a/third_party/nntoolchain/lib/libbackend_sg2380.so and b/third_party/nntoolchain/lib/libbackend_sg2380.so differ diff --git a/third_party/nntoolchain/lib/libbm1684x_kernel_module.a b/third_party/nntoolchain/lib/libbm1684x_kernel_module.a index 1d9d78075..9f3904cf8 100644 Binary files a/third_party/nntoolchain/lib/libbm1684x_kernel_module.a and b/third_party/nntoolchain/lib/libbm1684x_kernel_module.a differ diff --git a/third_party/nntoolchain/lib/libbm1684x_kernel_module.so b/third_party/nntoolchain/lib/libbm1684x_kernel_module.so index e0f850027..ea53f2e41 100755 Binary files a/third_party/nntoolchain/lib/libbm1684x_kernel_module.so and b/third_party/nntoolchain/lib/libbm1684x_kernel_module.so differ diff --git a/third_party/nntoolchain/lib/libbm1690_kernel_module.a b/third_party/nntoolchain/lib/libbm1690_kernel_module.a index e66285fb9..cb8c7ce8a 100644 Binary files a/third_party/nntoolchain/lib/libbm1690_kernel_module.a and b/third_party/nntoolchain/lib/libbm1690_kernel_module.a differ diff --git a/third_party/nntoolchain/lib/libbm1690_kernel_module.so b/third_party/nntoolchain/lib/libbm1690_kernel_module.so index 0cbcbf882..5d27badbf 100755 Binary files a/third_party/nntoolchain/lib/libbm1690_kernel_module.so and b/third_party/nntoolchain/lib/libbm1690_kernel_module.so differ diff --git a/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.a b/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.a index 2ebf46cfb..185e6ee87 100644 Binary files a/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.a and b/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.a differ diff --git a/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.so b/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.so index 36554ef2c..7009b3aed 100644 Binary files a/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.so and b/third_party/nntoolchain/lib/libbmtpulv60_kernel_module.so differ diff --git a/third_party/nntoolchain/lib/libcmodel_1684x.so b/third_party/nntoolchain/lib/libcmodel_1684x.so index ae258890e..fc59fe4f0 100755 Binary files a/third_party/nntoolchain/lib/libcmodel_1684x.so and b/third_party/nntoolchain/lib/libcmodel_1684x.so differ diff --git a/third_party/nntoolchain/lib/libcmodel_1688.so b/third_party/nntoolchain/lib/libcmodel_1688.so index 2e57cb930..c4cce5bd7 100755 Binary files a/third_party/nntoolchain/lib/libcmodel_1688.so and b/third_party/nntoolchain/lib/libcmodel_1688.so differ diff --git a/third_party/nntoolchain/lib/libcmodel_mars3.so b/third_party/nntoolchain/lib/libcmodel_mars3.so index 53b9ddba0..471e3a006 100755 Binary files a/third_party/nntoolchain/lib/libcmodel_mars3.so and b/third_party/nntoolchain/lib/libcmodel_mars3.so differ diff --git a/third_party/nntoolchain/lib/libcmodel_sg2380.so b/third_party/nntoolchain/lib/libcmodel_sg2380.so index 57cc0952b..631f27d48 100755 Binary files a/third_party/nntoolchain/lib/libcmodel_sg2380.so and b/third_party/nntoolchain/lib/libcmodel_sg2380.so differ diff --git a/third_party/nntoolchain/lib/libtpuv7_emulator.so b/third_party/nntoolchain/lib/libtpuv7_emulator.so index 78c2cd3c7..ac3aa789b 100755 Binary files a/third_party/nntoolchain/lib/libtpuv7_emulator.so and b/third_party/nntoolchain/lib/libtpuv7_emulator.so differ