From 9d83624b35b2689ce085223eca0ef22215007ac5 Mon Sep 17 00:00:00 2001 From: HahaLan97 Date: Thu, 5 Oct 2023 15:38:41 +0200 Subject: [PATCH 1/6] [ignore] change of the name of clang and lld --- build-scalehls.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build-scalehls.sh b/build-scalehls.sh index 4c500326..e3432d07 100755 --- a/build-scalehls.sh +++ b/build-scalehls.sh @@ -48,9 +48,9 @@ if [ ! -f "CMakeCache.txt" ]; then -DMLIR_ENABLE_BINDINGS_PYTHON="${PYBIND:=OFF}" \ -DSCALEHLS_ENABLE_BINDINGS_PYTHON="${PYBIND:=OFF}" \ -DLLVM_PARALLEL_LINK_JOBS="${JOBS:=}" \ - -DLLVM_USE_LINKER=lld \ - -DCMAKE_C_COMPILER=clang \ - -DCMAKE_CXX_COMPILER=clang++ + -DLLVM_USE_LINKER=lld-16 \ + -DCMAKE_C_COMPILER=clang-16 \ + -DCMAKE_CXX_COMPILER=clang++-16 fi # Run building. @@ -77,9 +77,9 @@ if [ ! -f "CMakeCache.txt" ]; then -DCLANG_DIR="${SCALEHLS_DIR}/build/lib/cmake/clang" \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DCMAKE_BUILD_TYPE=DEBUG \ - -DLLVM_USE_LINKER=lld \ - -DCMAKE_C_COMPILER=clang \ - -DCMAKE_CXX_COMPILER=clang++ + -DLLVM_USE_LINKER=lld-16 \ + -DCMAKE_C_COMPILER=clang-16 \ + -DCMAKE_CXX_COMPILER=clang++-16 fi # Run building. From 5ed490a7f058acb9807d816eece0cb4d0d11f090 Mon Sep 17 00:00:00 2001 From: HahaLan97 Date: Thu, 5 Oct 2023 15:39:55 +0200 Subject: [PATCH 2/6] Fix the error of issue #58 in original repo. --- lib/Dialect/HLS/HLS.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Dialect/HLS/HLS.cpp b/lib/Dialect/HLS/HLS.cpp index 48211ae6..2996625b 100644 --- a/lib/Dialect/HLS/HLS.cpp +++ b/lib/Dialect/HLS/HLS.cpp @@ -1000,12 +1000,12 @@ void AffineSelectOp::print(OpAsmPrinter &p) { p.printOperand(getTrueValue()); p << ", "; p.printOperand(getFalseValue()); - p << " : "; - p.printType(getType()); // Print the attribute list. p.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/getConditionAttrStrName()); + p << " : "; + p.printType(getType()); } IntegerSet AffineSelectOp::getIntegerSet() { From b5f2518438ba4fba0d6ccccb27f0fdf266ad447a Mon Sep 17 00:00:00 2001 From: HahaLan97 Date: Thu, 5 Oct 2023 15:56:25 +0200 Subject: [PATCH 3/6] Add lsp server in tools. --- tools/CMakeLists.txt | 1 + tools/scalehls-lsp-server/CMakeLists.txt | 19 +++++++++++++++++++ .../scalehls-lsp-server.cpp | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tools/scalehls-lsp-server/CMakeLists.txt create mode 100644 tools/scalehls-lsp-server/scalehls-lsp-server.cpp diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b217d4a7..d521d092 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(pyscalehls) add_subdirectory(scalehls-opt) +add_subdirectory(scalehls-lsp-server) add_subdirectory(scalehls-translate) diff --git a/tools/scalehls-lsp-server/CMakeLists.txt b/tools/scalehls-lsp-server/CMakeLists.txt new file mode 100644 index 00000000..29790625 --- /dev/null +++ b/tools/scalehls-lsp-server/CMakeLists.txt @@ -0,0 +1,19 @@ +project(scalehls-lsp-server) + +add_executable(${PROJECT_NAME} + scalehls-lsp-server.cpp +) + +# Link all standard MLIR dialect and conversion libs. +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) +get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) +get_property(circt_dialect_libs GLOBAL PROPERTY CIRCT_DIALECT_LIBS) +target_link_libraries(${PROJECT_NAME} + PRIVATE + MLIRLspServerLib + + ${circt_dialect_libs} + + ${dialect_libs} + ${conversion_libs} +) \ No newline at end of file diff --git a/tools/scalehls-lsp-server/scalehls-lsp-server.cpp b/tools/scalehls-lsp-server/scalehls-lsp-server.cpp new file mode 100644 index 00000000..7b568a40 --- /dev/null +++ b/tools/scalehls-lsp-server/scalehls-lsp-server.cpp @@ -0,0 +1,17 @@ +#include "scalehls/InitAllDialects.h" +#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h" + +using namespace mlir; + +static int asMainReturnCode(LogicalResult r) +{ + return r.succeeded() ? EXIT_SUCCESS : EXIT_FAILURE; +} + +int main(int argc, char* argv[]) +{ + DialectRegistry registry; + scalehls::registerAllDialects(registry); + + return asMainReturnCode(MlirLspServerMain(argc, argv, registry)); +} From 004daad582a3efe629ee863b5d54a22f1dc064b0 Mon Sep 17 00:00:00 2001 From: HahaLan97 Date: Thu, 5 Oct 2023 16:44:56 +0200 Subject: [PATCH 4/6] A minor fix in the Ops.td. --- include/scalehls/Dialect/HLS/Ops.td | 1 + 1 file changed, 1 insertion(+) diff --git a/include/scalehls/Dialect/HLS/Ops.td b/include/scalehls/Dialect/HLS/Ops.td index e0e5b4ff..80d2554d 100644 --- a/include/scalehls/Dialect/HLS/Ops.td +++ b/include/scalehls/Dialect/HLS/Ops.td @@ -11,6 +11,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td" include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/IR/BuiltinAttributeInterfaces.td" include "mlir/IR/SymbolInterfaces.td" +include "scalehls/Dialect/HLS/HLS.td" include "scalehls/Dialect/HLS/Interfaces.td" //===----------------------------------------------------------------------===// From 3a3507508e2292f5eff49b2641a4f4f3f86afdf6 Mon Sep 17 00:00:00 2001 From: HahaLan97 Date: Wed, 15 May 2024 16:14:55 +0200 Subject: [PATCH 5/6] Misc chanegs --- build-scalehls.sh | 12 ++++++------ include/scalehls/Dialect/HLS/Ops.td | 1 - samples/pytorch/lenet/lenet.py | 5 +++-- samples/pytorch/resnet18/resnet18.py | 5 +++-- tools/scalehls-lsp-server/CMakeLists.txt | 2 +- .../scalehls-lsp-server/scalehls-lsp-server.cpp | 16 +++++++--------- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/build-scalehls.sh b/build-scalehls.sh index e3432d07..4c500326 100755 --- a/build-scalehls.sh +++ b/build-scalehls.sh @@ -48,9 +48,9 @@ if [ ! -f "CMakeCache.txt" ]; then -DMLIR_ENABLE_BINDINGS_PYTHON="${PYBIND:=OFF}" \ -DSCALEHLS_ENABLE_BINDINGS_PYTHON="${PYBIND:=OFF}" \ -DLLVM_PARALLEL_LINK_JOBS="${JOBS:=}" \ - -DLLVM_USE_LINKER=lld-16 \ - -DCMAKE_C_COMPILER=clang-16 \ - -DCMAKE_CXX_COMPILER=clang++-16 + -DLLVM_USE_LINKER=lld \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ fi # Run building. @@ -77,9 +77,9 @@ if [ ! -f "CMakeCache.txt" ]; then -DCLANG_DIR="${SCALEHLS_DIR}/build/lib/cmake/clang" \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DCMAKE_BUILD_TYPE=DEBUG \ - -DLLVM_USE_LINKER=lld-16 \ - -DCMAKE_C_COMPILER=clang-16 \ - -DCMAKE_CXX_COMPILER=clang++-16 + -DLLVM_USE_LINKER=lld \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ fi # Run building. diff --git a/include/scalehls/Dialect/HLS/Ops.td b/include/scalehls/Dialect/HLS/Ops.td index 80d2554d..e0e5b4ff 100644 --- a/include/scalehls/Dialect/HLS/Ops.td +++ b/include/scalehls/Dialect/HLS/Ops.td @@ -11,7 +11,6 @@ include "mlir/Interfaces/ControlFlowInterfaces.td" include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/IR/BuiltinAttributeInterfaces.td" include "mlir/IR/SymbolInterfaces.td" -include "scalehls/Dialect/HLS/HLS.td" include "scalehls/Dialect/HLS/Interfaces.td" //===----------------------------------------------------------------------===// diff --git a/samples/pytorch/lenet/lenet.py b/samples/pytorch/lenet/lenet.py index 9b612f6c..d005ec3c 100644 --- a/samples/pytorch/lenet/lenet.py +++ b/samples/pytorch/lenet/lenet.py @@ -6,6 +6,7 @@ import torch.nn as nn import torch.nn.functional as F import torch_mlir +import torch_mlir.torchscript class LeNet(nn.Module): @@ -31,7 +32,7 @@ def forward(self, x): return out -module = torch_mlir.compile(LeNet(), torch.ones( - 1, 3, 32, 32), output_type=torch_mlir.OutputType.LINALG_ON_TENSORS) +module = torch_mlir.torchscript.compile(LeNet(), torch.ones( + 1, 3, 32, 32), output_type=torch_mlir.torchscript.OutputType.LINALG_ON_TENSORS) print(module) diff --git a/samples/pytorch/resnet18/resnet18.py b/samples/pytorch/resnet18/resnet18.py index 2b683e5f..fd8fcdf3 100644 --- a/samples/pytorch/resnet18/resnet18.py +++ b/samples/pytorch/resnet18/resnet18.py @@ -6,6 +6,7 @@ import torch.nn as nn import torch.nn.functional as F import torch_mlir +import torch_mlir.torchscript class BasicBlock(nn.Module): @@ -71,7 +72,7 @@ def ResNet18(): return ResNet(BasicBlock, [2, 2, 2, 2]) -module = torch_mlir.compile(ResNet18(), torch.ones( - 1, 3, 32, 32), output_type=torch_mlir.OutputType.LINALG_ON_TENSORS) +module = torch_mlir.torchscript.compile(ResNet18(), torch.ones( + 1, 3, 32, 32), output_type=torch_mlir.torchscript.OutputType.LINALG_ON_TENSORS) print(module) diff --git a/tools/scalehls-lsp-server/CMakeLists.txt b/tools/scalehls-lsp-server/CMakeLists.txt index 29790625..c14a6ab8 100644 --- a/tools/scalehls-lsp-server/CMakeLists.txt +++ b/tools/scalehls-lsp-server/CMakeLists.txt @@ -16,4 +16,4 @@ target_link_libraries(${PROJECT_NAME} ${dialect_libs} ${conversion_libs} -) \ No newline at end of file +) diff --git a/tools/scalehls-lsp-server/scalehls-lsp-server.cpp b/tools/scalehls-lsp-server/scalehls-lsp-server.cpp index 7b568a40..d67f0cc1 100644 --- a/tools/scalehls-lsp-server/scalehls-lsp-server.cpp +++ b/tools/scalehls-lsp-server/scalehls-lsp-server.cpp @@ -1,17 +1,15 @@ -#include "scalehls/InitAllDialects.h" #include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h" +#include "scalehls/InitAllDialects.h" using namespace mlir; -static int asMainReturnCode(LogicalResult r) -{ - return r.succeeded() ? EXIT_SUCCESS : EXIT_FAILURE; +static int asMainReturnCode(LogicalResult r) { + return r.succeeded() ? EXIT_SUCCESS : EXIT_FAILURE; } -int main(int argc, char* argv[]) -{ - DialectRegistry registry; - scalehls::registerAllDialects(registry); +int main(int argc, char *argv[]) { + DialectRegistry registry; + scalehls::registerAllDialects(registry); - return asMainReturnCode(MlirLspServerMain(argc, argv, registry)); + return asMainReturnCode(MlirLspServerMain(argc, argv, registry)); } From 28ea6faf8de226d6f12b80427c56f0d9c1cae816 Mon Sep 17 00:00:00 2001 From: HahaLan97 Date: Wed, 15 May 2024 16:16:13 +0200 Subject: [PATCH 6/6] Fix fatal error of resnet18 example. --- lib/Transforms/FuncPreprocess.cpp | 20 ++++++++++---------- lib/Transforms/Memory/SimplifyCopy.cpp | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/Transforms/FuncPreprocess.cpp b/lib/Transforms/FuncPreprocess.cpp index b92dedb6..ae6d1865 100644 --- a/lib/Transforms/FuncPreprocess.cpp +++ b/lib/Transforms/FuncPreprocess.cpp @@ -98,15 +98,15 @@ struct AddIRaisePattern : public OpRewritePattern { return success(); } - if (auto rhs = add.getRhs().getDefiningOp(); - isValidDim(add.getLhs())) { + auto rhs = add.getRhs().getDefiningOp(); + if (rhs != nullptr && isValidDim(add.getLhs())) { r.replaceOpWithNewOp( add, r.getAffineDimExpr(0) + rhs.value(), add.getLhs()); return success(); } - if (auto lhs = add.getLhs().getDefiningOp(); - isValidDim(add.getRhs())) { + auto lhs = add.getLhs().getDefiningOp(); + if (lhs != nullptr && isValidDim(add.getRhs())) { r.replaceOpWithNewOp( add, lhs.value() + r.getAffineDimExpr(0), add.getRhs()); return success(); @@ -125,17 +125,17 @@ struct MulIRaisePattern : public OpRewritePattern { PatternRewriter &r) const override { r.setInsertionPoint(mul); - if (auto rhs = mul.getRhs().getDefiningOp(); - isValidDim(mul.getLhs())) { + auto rhs = mul.getRhs().getDefiningOp(); + if (rhs != nullptr && isValidDim(mul.getLhs())) { r.replaceOpWithNewOp( - mul, r.getAffineDimExpr(0) * rhs.value(), mul.getLhs()); + mul, r.getAffineDimExpr(0) + rhs.value(), mul.getLhs()); return success(); } - if (auto lhs = mul.getLhs().getDefiningOp(); - isValidDim(mul.getRhs())) { + auto lhs = mul.getLhs().getDefiningOp(); + if (lhs != nullptr && isValidDim(mul.getRhs())) { r.replaceOpWithNewOp( - mul, lhs.value() * r.getAffineDimExpr(0), mul.getRhs()); + mul, lhs.value() + r.getAffineDimExpr(0), mul.getRhs()); return success(); } return failure(); diff --git a/lib/Transforms/Memory/SimplifyCopy.cpp b/lib/Transforms/Memory/SimplifyCopy.cpp index 4e054b2b..2efa63a1 100644 --- a/lib/Transforms/Memory/SimplifyCopy.cpp +++ b/lib/Transforms/Memory/SimplifyCopy.cpp @@ -26,6 +26,10 @@ struct SplitElementwiseGenericOp : public OpRewritePattern { op.getNumOutputs() == 1) { auto &input = op->getOpOperand(0); auto &output = op->getOpOperand(1); + if (input.get().getType() != output.get().getType()) { + LLVM_DEBUG(llvm::dbgs() << "\nCurrent generic: " << op << "\n";); + return failure(); + } if (input.get() == output.get()) return failure();