Skip to content

Commit

Permalink
[Mars3][Sgtpuv8] update backend
Browse files Browse the repository at this point in the history
update and implemnet kernel module

Change-Id: I0b6e6c8d2fdc02daf64835cba2a56267253b442c
  • Loading branch information
daozhuo.feng authored and PostMalone1998 committed Jan 20, 2025
1 parent 1c6f5cb commit 362b8cd
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/tpu_mlir/Backend/BM168x/MARS3.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace backend {
#define BUFFER_SIZE (4 * 1024 * 1024)
class MARS3 : public BM1684X {
public:
static constexpr llvm::StringRef LIB_KERNEL_NAME = "libmars3_kernel_module.so";
static bool classof(const BM168x *bm168x) {
return bm168x->getTypeID() == TypeID::get<MARS3>();
}
Expand Down
2 changes: 2 additions & 0 deletions include/tpu_mlir/Backend/BM168x/SGTPUV8.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace backend {
#define BUFFER_SIZE (4 * 1024 * 1024)
class SGTPUV8 : public BM1684X {
public:
static constexpr llvm::StringRef LIB_KERNEL_NAME =
"libsgtpuv8_kernel_module.so";
static bool classof(const BM168x *bm168x) {
return bm168x->getTypeID() == TypeID::get<SGTPUV8>();
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Dialect/Tpu/Transforms/Codegen/BM168xCodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "tpu_mlir/Backend/BM168x/BM1690.h"
#include "tpu_mlir/Backend/BM168x/BackendInterfaces.h"
#include "tpu_mlir/Backend/BM168x/MARS3.h"
#include "tpu_mlir/Backend/BM168x/SGTPUV8.h"
#include "tpu_mlir/Support/GenericCpuFunc.h"
#include "tpu_mlir/Support/MathUtils.h"
#include <llvm/Support/MemoryBuffer.h>
Expand Down Expand Up @@ -91,8 +92,10 @@ void BMCodegen::init(ModuleOp m, const std::string &filename,
kernel_name = backend::BM1684X::LIB_KERNEL_NAME.str();
else if (module::isBM1688())
kernel_name = backend::BM1688::LIB_KERNEL_NAME.str();
else if (module::isMARS3() || module::isSGTPUV8())
else if (module::isMARS3())
kernel_name = backend::MARS3::LIB_KERNEL_NAME.str();
else if (module::isSGTPUV8())
kernel_name = backend::SGTPUV8::LIB_KERNEL_NAME.str();
else
kernel_name = backend::BM1690::LIB_KERNEL_NAME.str();
std::string root_path = getenv("TPUC_ROOT");
Expand Down
10 changes: 5 additions & 5 deletions python/test/test_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def __init__(self,
"Compare2": (self.test_Compare2, Y, N, N, N, N, N),
"Concat": (self.test_Concat, Y, Y, Y, Y, Y, Y),
"Concat2": (self.test_Concat2, Y, Y, Y, Y, Y, N),
"Concat3": (self.test_Concat3, N, Y, Y, N, Y, Y),
"ConstOfShape": (self.test_ConstOfShape, N, Y, Y, N, Y, Y),
"ConstantFillDyn": (self.test_ConstantFillDyn, N, Y, Y, N, Y, Y),
"Concat3": (self.test_Concat3, N, Y, Y, N, Y, N),
"ConstOfShape": (self.test_ConstOfShape, N, Y, Y, N, Y, N),
"ConstantFillDyn": (self.test_ConstantFillDyn, N, Y, Y, N, Y, N),
"Conv1d": (self.test_Conv1d, Y, Y, Y, Y, Y, Y),
"Conv1dbigd": (self.test_Conv1d_bigd, Y, N, N, N, N, N),
"Conv2d": (self.test_Conv2d, Y, Y, Y, Y, Y, Y),
Expand Down Expand Up @@ -184,9 +184,9 @@ def __init__(self,
"Round": (self.test_Round, N, Y, N, N, Y, Y),
"ScatterElements": (self.test_ScatterElements, N, Y, N, N, Y, N),
"ScatterND": (self.test_ScatterND, N, Y, Y, N, Y, N),
"Shape": (self.test_Shape, Y, Y, Y, N, Y, Y),
"Shape": (self.test_Shape, Y, Y, Y, N, Y, N),
"ShapeCast": (self.test_ShapeCast, N, N, N, N, N, N),
"ShapeSlice": (self.test_ShapeSlice, Y, N, N, N, N, Y),
"ShapeSlice": (self.test_ShapeSlice, Y, N, N, N, N, N),
"SiLU": (self.test_SiLU, Y, Y, Y, Y, Y, Y),
"Softmax": (self.test_Softmax, Y, Y, Y, Y, Y, Y),
"Softplus": (self.test_Softplus, Y, Y, Y, Y, Y, Y),
Expand Down
4 changes: 4 additions & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ install(FILES nntoolchain/lib/libbackend_1684.so
nntoolchain/lib/libbmtpulv60_kernel_module.a
nntoolchain/lib/libbm1690_kernel_module.so
nntoolchain/lib/libbm1690_kernel_module.a
nntoolchain/lib/libmars3_kernel_module.so
nntoolchain/lib/libmars3_kernel_module.a
nntoolchain/lib/libsgtpuv8_kernel_module.so
nntoolchain/lib/libsgtpuv8_kernel_module.a
nntoolchain/lib/liblibtorch_plugin.so
nntoolchain/lib/libmodel_combine.so
nntoolchain/lib/libtpuv7_rt.so
Expand Down
14 changes: 10 additions & 4 deletions third_party/nntoolchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,31 @@ release: 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: 99e2222e6982bee14e49a38f1499a04e28c6e1e8
#mars3 sha256: cd3898ba7118e5588ca02a289b9f661fed259b67
cd TPU1686
source scripts/envsetup.sh mars3
debug: rebuild_backend_lib_cmodel
release: unset EXTRA_CONFIG && rebuild_backend_lib_release_cmodel
cp build/backend_api/libbackend_mars3.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libbackend_mars3.so
cp build_runtime/firmware_core/libcmodel_firmware.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libcmodel_mars3.so
rebuild_firmware
cp build/firmware_core/libfirmware_core.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libmars3_kernel_module.so
cp build/firmware_core/libfirmware_core.a /workspace/tpu-mlir/third_party/nntoolchain/lib/libmars3_kernel_module.a

#SGTPUV8 sha256: 0c1f6c07eb4b8dc403edab264fec4bd57035bc2f
#SGTPUV8 sha256: cd3898ba7118e5588ca02a289b9f661fed259b67
cd TPU1686
source scripts/envsetup.sh sgtpuv8
debug: rebuild_backend_lib_cmodel
release: unset EXTRA_CONFIG && rebuild_backend_lib_release_cmodel
cp build/backend_api/libbackend_sgtpuv8.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libbackend_sgtpuv8.so
cp build_runtime/firmware_core/libcmodel_firmware.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libcmodel_sgtpuv8.so
rebuild_firmware
cp build/firmware_core/libfirmware_core.so /workspace/tpu-mlir/third_party/nntoolchain/lib/libsgtpuv8_kernel_module.so
cp build/firmware_core/libfirmware_core.a /workspace/tpu-mlir/third_party/nntoolchain/lib/libsgtpuv8_kernel_module.a
```

## tpu-runtime 2025-1-15
build from tpu-runtime 16b9614394b97273dc7a44bd0a57fee60f079ff1
## tpu-runtime 2025-1-17
build from tpu-runtime f2bd5f7ba035b624f25fb7d8b6792b3d2180177b
``` bash
pushd libsophon
mkdir -p build && cd build
Expand Down
Binary file modified third_party/nntoolchain/lib/libbackend_mars3.so
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libbackend_sgtpuv8.so
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libbmlib.so.0
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libbmrt.so.1.0
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libcmodel_mars3.so
Binary file not shown.
Binary file modified third_party/nntoolchain/lib/libcmodel_sgtpuv8.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 362b8cd

Please sign in to comment.