From 30187d6a5996ed1451d29d02115513fe7a560bf5 Mon Sep 17 00:00:00 2001 From: Jackcui Date: Wed, 30 Jul 2025 19:53:41 -0500 Subject: [PATCH 1/5] successfully built, read spec path from ENV --- .gitignore | 8 ++++ CMakeLists.txt | 4 +- .../NeuraDialect/Architecture/Architecture.h | 34 +++++++++++++++- .../Architecture/Architecture.cpp | 40 ++++++++++++++++++- lib/NeuraDialect/CMakeLists.txt | 4 ++ lib/NeuraDialect/Mapping/mapping_util.cpp | 32 ++++++++++++++- .../Transforms/MapToAcceleratorPass.cpp | 37 ++++++++++++++++- test/lit.cfg | 19 +++++++++ 8 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 test/lit.cfg diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..50cd11b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +build/ + +.vscode/ +*.swp +*.swo + +.DS_Store +Thumbs.db diff --git a/CMakeLists.txt b/CMakeLists.txt index 008e3eaa..9f5a76bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) -add_compile_options(-g) +add_compile_options(-g -fexceptions) # set(MLIR_DIR /home/lucas/llvm-project/build/lib/cmake/mlir) # set(LLVM_DIR /home/lucas/llvm-project/build/lib/cmake/llvm) @@ -20,6 +20,8 @@ message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") find_package(MLIR REQUIRED CONFIG) find_package(LLVM REQUIRED CONFIG) +find_package(yaml-cpp REQUIRED) + list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") include_directories(${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS}) diff --git a/include/NeuraDialect/Architecture/Architecture.h b/include/NeuraDialect/Architecture/Architecture.h index dfd81237..9b4b20f0 100644 --- a/include/NeuraDialect/Architecture/Architecture.h +++ b/include/NeuraDialect/Architecture/Architecture.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace mlir { namespace neura { @@ -35,7 +36,37 @@ enum OperationKind { IAdd = 0, IMul = 1, FAdd = 2, - FMul = 3 + FMul = 3, + ISub = 4, + FSub = 5, + IDiv = 6, + FDiv = 7, + FAddFAdd = 8, + FMulFAdd = 9, + VFMul = 10, + ICmp = 11, + FCmp = 12, + Not = 13, + Or = 14, + Sel = 15, + Cast = 16, + Phi = 17, + Load = 18, + LoadIndexed = 19, + Store = 20, + StoreIndexed = 21, + Br_ = 22, + CondBr_ = 23, + Return = 24, + LoopController = 25, + GrantAlways = 26, + GrantOnce = 27, + GrantPredicate = 28, + GEP_ = 29, + Constant = 30, + DataMov = 31, + CtrlMov = 32, + Reserve = 33 }; //===----------------------------------------------------------------------===// @@ -324,6 +355,7 @@ struct PairHash { class Architecture { public: Architecture(int width, int height); + Architecture(const YAML::Node& config); Tile* getTile(int id); Tile* getTile(int x, int y); diff --git a/lib/NeuraDialect/Architecture/Architecture.cpp b/lib/NeuraDialect/Architecture/Architecture.cpp index 0c08d9a8..8db37607 100644 --- a/lib/NeuraDialect/Architecture/Architecture.cpp +++ b/lib/NeuraDialect/Architecture/Architecture.cpp @@ -17,7 +17,7 @@ Tile::Tile(int id, int x, int y) { // TODO: Add function units based on architecture specs. // @Jackcuii, https://github.com/coredac/dataflow/issues/82. - addFunctionUnit(std::make_unique(0)); + // addFunctionUnit(std::make_unique(0)); } int Tile::getId() const { return id; } @@ -275,6 +275,44 @@ Architecture::Architecture(int width, int height) { } } +Architecture::Architecture(const YAML::Node& config) { + // Extract width and height from config + int width = 4; // default + int height = 4; // default + + if (config["architecture"] && config["architecture"]["width"] && config["architecture"]["height"]) { + width = config["architecture"]["width"].as(); + height = config["architecture"]["height"].as(); + } + + // Call the constructor with width and height. + *this = Architecture(width, height); + + // Add function units based on the architecture specs. + int num_tiles = width * height; + for (int i = 0; i < num_tiles; ++i) { + Tile *tile = getTile(i); + int fu_id = 0; + if (config["tile_overrides"][i]) { + // Override the default function units. + for (const auto& operation : config["tile_overrides"][i]["operations"]) { + if (operation.as() == "add") { + tile->addFunctionUnit(std::make_unique(++fu_id)); + // Add more function units here if more operations are supported. + } + } + } else if (config["tile_defaults"]) { + // Add default function units. + for (const auto& operation : config["tile_defaults"]["operations"]) { + if (operation.as() == "add") { + tile->addFunctionUnit(std::make_unique(++fu_id)); + } + } + } + } +} + + Tile *Architecture::getTile(int id) { auto it = id_to_tile.find(id); assert(it != id_to_tile.end() && "Tile with given ID not found"); diff --git a/lib/NeuraDialect/CMakeLists.txt b/lib/NeuraDialect/CMakeLists.txt index c1faae04..c0011c77 100644 --- a/lib/NeuraDialect/CMakeLists.txt +++ b/lib/NeuraDialect/CMakeLists.txt @@ -20,6 +20,10 @@ add_mlir_dialect_library(MLIRNeura MLIRIR MLIRSupport MLIRInferTypeOpInterface + yaml-cpp ) +# Enable exception handling for yaml-cpp +target_compile_options(MLIRNeura PRIVATE -fexceptions) + add_subdirectory(Transforms) \ No newline at end of file diff --git a/lib/NeuraDialect/Mapping/mapping_util.cpp b/lib/NeuraDialect/Mapping/mapping_util.cpp index f7e5030f..85ecdba5 100644 --- a/lib/NeuraDialect/Mapping/mapping_util.cpp +++ b/lib/NeuraDialect/Mapping/mapping_util.cpp @@ -20,8 +20,36 @@ inline OperationKind getOperationKindFromMlirOp(Operation *op) { if (isa(op)) return IMul; if (isa(op)) return FAdd; if (isa(op)) return FMul; - // TODO: Complete the list here. - // @Jackcuii, https://github.com/coredac/dataflow/issues/82. + if (isa(op)) return ISub; + if (isa(op)) return FSub; + if (isa(op)) return IDiv; + if (isa(op)) return FDiv; + if (isa(op)) return FAddFAdd; + if (isa(op)) return FMulFAdd; + if (isa(op)) return VFMul; + if (isa(op)) return ICmp; + if (isa(op)) return Not; + if (isa(op)) return Or; + if (isa(op)) return Sel; + if (isa(op)) return Cast; + if (isa(op)) return Load; + if (isa(op)) return LoadIndexed; + if (isa(op)) return Store; + if (isa(op)) return StoreIndexed; + if (isa(op)) return Br_; + if (isa(op)) return CondBr_; + if (isa(op)) return Return; + if (isa(op)) return LoopController; + if (isa(op)) return GrantAlways; + if (isa(op)) return GrantOnce; + if (isa(op)) return GrantPredicate; + if (isa(op)) return GEP_; + if (isa(op)) return Constant; + if (isa(op)) return Phi; + if (isa(op)) return DataMov; + if (isa(op)) return CtrlMov; + if (isa(op)) return Reserve; + // Default fallback return IAdd; } diff --git a/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp b/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp index 4f7cc627..d3a4a644 100644 --- a/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp +++ b/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp @@ -13,6 +13,9 @@ #include "mlir/Pass/Pass.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include using namespace mlir; using namespace mlir::neura; @@ -138,7 +141,39 @@ struct MapToAcceleratorPass } // AcceleratorConfig config{/*numTiles=*/8}; // Example - Architecture architecture(4, 4); + // Read architecture specification from environment variable + const char* arch_spec_path = std::getenv("DEFAULT_ARCH_SPEC"); + // Read from the environment variable for now. + YAML::Node config; + bool use_default_arch = false; + if (arch_spec_path) { + try { + std::ifstream file(arch_spec_path); + if (file.is_open()) { + config = YAML::Load(file); + if (config["architecture"]) { + llvm::outs() << "[MapToAcceleratorPass] Loaded architecture from " + << arch_spec_path << "\n"; + } else { + llvm::errs() << "[MapToAcceleratorPass] Invalid YAML format in " + << arch_spec_path << ", using default 4x4\n"; + } + } else { + llvm::errs() << "[MapToAcceleratorPass] Could not open architecture file " + << arch_spec_path << ", using default 4x4\n"; + use_default_arch = true; + } + } catch (const std::exception& e) { + llvm::errs() << "[MapToAcceleratorPass] Error parsing YAML file " + << arch_spec_path << ": " << e.what() << ", using default 4x4\n"; + } + } else { + use_default_arch = true; + llvm::errs() << "[MapToAcceleratorPass] DEFAULT_ARCH_SPEC not set, using default 4x4\n"; + } + + Architecture architecture = use_default_arch ? Architecture(4, 4) : Architecture(config); + int res_mii = calculateResMii(func, architecture); IntegerAttr res_mii_attr = IntegerAttr::get(IntegerType::get(func.getContext(), 32), res_mii); diff --git a/test/lit.cfg b/test/lit.cfg new file mode 100644 index 00000000..887d5be7 --- /dev/null +++ b/test/lit.cfg @@ -0,0 +1,19 @@ +import os +import lit.formats + +config.name = 'Neura Dialect Tests' +config.test_format = lit.formats.ShTest(True) +config.suffixes = ['.mlir'] +config.test_source_root = os.path.dirname(__file__) +config.test_exec_root = os.path.dirname(__file__) +config.excludes = ['samples'] + +# Tool substitutions from CMake +config.substitutions.append(('mlir-neura-opt', '/home/jackcui/Arch/MLiR/dataflow/build/tools/mlir-neura-opt/mlir-neura-opt')) +config.substitutions.append(('neura-interpreter', '/home/jackcui/Arch/MLiR/dataflow/build/tools/neura-interpreter/neura-interpreter')) +config.substitutions.append(('neura-compiler', '/home/jackcui/Arch/MLiR/dataflow/build/tools/neura-compiler/neura-compiler')) +config.substitutions.append(('FileCheck', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/FileCheck')) +config.substitutions.append(('mlir-opt', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/mlir-opt')) +config.substitutions.append(('mlir-translate', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/mlir-translate')) +config.substitutions.append(('llc', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/llc')) +config.substitutions.append(('clang', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/clang')) From db8d764811d267c7334ea8e888d6faac6696d230 Mon Sep 17 00:00:00 2001 From: Cui Bohan Date: Thu, 31 Jul 2025 13:13:42 -0500 Subject: [PATCH 2/5] Update main.yml to install yaml lib --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b4214ef0..c069578e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,7 +33,11 @@ jobs: run: | sudo apt-get install ccache sudo apt-get install lld - + + # install yaml library + - name: install yaml library + run: sudo apt-get install libyaml-dev + # setup LLVM - name: install a specific version of LLVM working-directory: ${{github.workspace}} From db24510c652c5ea54a3d5eb4fc71bd8f9a540c07 Mon Sep 17 00:00:00 2001 From: Jackcui Date: Wed, 6 Aug 2025 12:40:10 -0500 Subject: [PATCH 3/5] edit gitignore, reading spec from ENV -> cli parameters --- .gitignore | 4 +++ .../Transforms/MapToAcceleratorPass.cpp | 29 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 50cd11b6..cbb5873f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,9 @@ build/ *.swp *.swo +generated-instructions.json + .DS_Store Thumbs.db + +/test/lit.cfg \ No newline at end of file diff --git a/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp b/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp index d3a4a644..63130a04 100644 --- a/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp +++ b/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp @@ -49,6 +49,12 @@ struct MapToAcceleratorPass "max_loc=5, max_depth=3)"), llvm::cl::init("heuristic")}; + Option archSpecPath{ + *this, "arch-spec", + llvm::cl::desc("Path to the architecture specification YAML file. " + "If not specified, will use default 4x4 architecture."), + llvm::cl::init("")}; + void runOnOperation() override { ModuleOp module = getOperation(); @@ -141,35 +147,36 @@ struct MapToAcceleratorPass } // AcceleratorConfig config{/*numTiles=*/8}; // Example - // Read architecture specification from environment variable - const char* arch_spec_path = std::getenv("DEFAULT_ARCH_SPEC"); - // Read from the environment variable for now. + // Read architecture specification from command line option YAML::Node config; bool use_default_arch = false; - if (arch_spec_path) { + + if (!archSpecPath.getValue().empty()) { try { - std::ifstream file(arch_spec_path); + std::ifstream file(archSpecPath.getValue()); if (file.is_open()) { config = YAML::Load(file); if (config["architecture"]) { - llvm::outs() << "[MapToAcceleratorPass] Loaded architecture from " - << arch_spec_path << "\n"; + llvm::outs() << "\033[31m[MapToAcceleratorPass] Loaded architecture from " + << archSpecPath.getValue() << "\033[0m\n"; } else { llvm::errs() << "[MapToAcceleratorPass] Invalid YAML format in " - << arch_spec_path << ", using default 4x4\n"; + << archSpecPath.getValue() << ", using default 4x4\n"; + use_default_arch = true; } } else { llvm::errs() << "[MapToAcceleratorPass] Could not open architecture file " - << arch_spec_path << ", using default 4x4\n"; + << archSpecPath.getValue() << ", using default 4x4\n"; use_default_arch = true; } } catch (const std::exception& e) { llvm::errs() << "[MapToAcceleratorPass] Error parsing YAML file " - << arch_spec_path << ": " << e.what() << ", using default 4x4\n"; + << archSpecPath.getValue() << ": " << e.what() << ", using default 4x4\n"; + use_default_arch = true; } } else { use_default_arch = true; - llvm::errs() << "[MapToAcceleratorPass] DEFAULT_ARCH_SPEC not set, using default 4x4\n"; + llvm::errs() << "[MapToAcceleratorPass] No architecture specification provided, using default 4x4\n"; } Architecture architecture = use_default_arch ? Architecture(4, 4) : Architecture(config); From 2609389e492ab72802687264d5d924b43ad26ac7 Mon Sep 17 00:00:00 2001 From: Jackcui Date: Sun, 10 Aug 2025 19:50:01 -0500 Subject: [PATCH 4/5] fix for PR --- .gitignore | 12 --- .../NeuraDialect/Architecture/Architecture.h | 71 +++++++++--------- .../Architecture/Architecture.cpp | 4 +- lib/NeuraDialect/Mapping/mapping_util.cpp | 67 +++++++++-------- .../Transforms/MapToAcceleratorPass.cpp | 73 +++++++++++-------- test/lit.cfg | 19 ----- 6 files changed, 112 insertions(+), 134 deletions(-) delete mode 100644 .gitignore delete mode 100644 test/lit.cfg diff --git a/.gitignore b/.gitignore deleted file mode 100644 index cbb5873f..00000000 --- a/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -build/ - -.vscode/ -*.swp -*.swo - -generated-instructions.json - -.DS_Store -Thumbs.db - -/test/lit.cfg \ No newline at end of file diff --git a/include/NeuraDialect/Architecture/Architecture.h b/include/NeuraDialect/Architecture/Architecture.h index 9b4b20f0..87090d01 100644 --- a/include/NeuraDialect/Architecture/Architecture.h +++ b/include/NeuraDialect/Architecture/Architecture.h @@ -33,40 +33,39 @@ enum class FunctionUnitKind { // Enum for supported operation types. enum OperationKind { - IAdd = 0, - IMul = 1, - FAdd = 2, - FMul = 3, - ISub = 4, - FSub = 5, - IDiv = 6, - FDiv = 7, - FAddFAdd = 8, - FMulFAdd = 9, - VFMul = 10, - ICmp = 11, - FCmp = 12, - Not = 13, - Or = 14, - Sel = 15, - Cast = 16, - Phi = 17, - Load = 18, - LoadIndexed = 19, - Store = 20, - StoreIndexed = 21, - Br_ = 22, - CondBr_ = 23, - Return = 24, - LoopController = 25, - GrantAlways = 26, - GrantOnce = 27, - GrantPredicate = 28, - GEP_ = 29, - Constant = 30, - DataMov = 31, - CtrlMov = 32, - Reserve = 33 + OpIAdd = 0, + OpIMul = 1, + OpFAdd = 2, + OpFMul = 3, + OpISub = 4, + OpFSub = 5, + OpIDiv = 6, + OpFDiv = 7, + OpFAddFAdd = 8, + OpFMulFAdd = 9, + OpVFMul = 10, + OpICmp = 11, + OpFCmp = 12, + OpNot = 13, + OpOr = 14, + OpSel = 15, + OpCast = 16, + OpPhi = 17, + OpLoad = 18, + OpLoadIndexed = 19, + OpStore = 20, + OpStoreIndexed = 21, + OpBr = 22, + OpCondBr = 23, + OpReturn = 24, + OpLoopController = 25, + OpGrantAlways = 26, + OpGrantOnce = 27, + OpGrantPredicate = 28, + OpGEP_ = 29, + OpConstant = 30, + OpDataMov = 31, + OpCtrlMov = 32 }; //===----------------------------------------------------------------------===// @@ -134,7 +133,7 @@ class FunctionUnit : public BasicResource { class FixedPointAdder : public FunctionUnit { public: FixedPointAdder(int id) : FunctionUnit(id) { - supported_operations.insert(OperationKind::IAdd); + supported_operations.insert(OperationKind::OpIAdd); } std::string getType() const override { return "fixed_point_adder"; } ResourceKind getKind() const override { return ResourceKind::FunctionUnit; } @@ -143,7 +142,7 @@ class FixedPointAdder : public FunctionUnit { class FixedPointMultiplier : public FunctionUnit { public: FixedPointMultiplier(int id) : FunctionUnit(id) { - supported_operations.insert(OperationKind::IMul); + supported_operations.insert(OperationKind::OpIMul); } std::string getType() const override { return "fixed_point_multiplier"; } ResourceKind getKind() const override { return ResourceKind::FunctionUnit; } diff --git a/lib/NeuraDialect/Architecture/Architecture.cpp b/lib/NeuraDialect/Architecture/Architecture.cpp index 8db37607..749f76ad 100644 --- a/lib/NeuraDialect/Architecture/Architecture.cpp +++ b/lib/NeuraDialect/Architecture/Architecture.cpp @@ -297,7 +297,7 @@ Architecture::Architecture(const YAML::Node& config) { // Override the default function units. for (const auto& operation : config["tile_overrides"][i]["operations"]) { if (operation.as() == "add") { - tile->addFunctionUnit(std::make_unique(++fu_id)); + tile->addFunctionUnit(std::make_unique(fu_id++)); // Add more function units here if more operations are supported. } } @@ -305,7 +305,7 @@ Architecture::Architecture(const YAML::Node& config) { // Add default function units. for (const auto& operation : config["tile_defaults"]["operations"]) { if (operation.as() == "add") { - tile->addFunctionUnit(std::make_unique(++fu_id)); + tile->addFunctionUnit(std::make_unique(fu_id++)); } } } diff --git a/lib/NeuraDialect/Mapping/mapping_util.cpp b/lib/NeuraDialect/Mapping/mapping_util.cpp index 85ecdba5..de87eaa2 100644 --- a/lib/NeuraDialect/Mapping/mapping_util.cpp +++ b/lib/NeuraDialect/Mapping/mapping_util.cpp @@ -16,41 +16,40 @@ using namespace mlir::neura; namespace { inline OperationKind getOperationKindFromMlirOp(Operation *op) { - if (isa(op)) return IAdd; - if (isa(op)) return IMul; - if (isa(op)) return FAdd; - if (isa(op)) return FMul; - if (isa(op)) return ISub; - if (isa(op)) return FSub; - if (isa(op)) return IDiv; - if (isa(op)) return FDiv; - if (isa(op)) return FAddFAdd; - if (isa(op)) return FMulFAdd; - if (isa(op)) return VFMul; - if (isa(op)) return ICmp; - if (isa(op)) return Not; - if (isa(op)) return Or; - if (isa(op)) return Sel; - if (isa(op)) return Cast; - if (isa(op)) return Load; - if (isa(op)) return LoadIndexed; - if (isa(op)) return Store; - if (isa(op)) return StoreIndexed; - if (isa(op)) return Br_; - if (isa(op)) return CondBr_; - if (isa(op)) return Return; - if (isa(op)) return LoopController; - if (isa(op)) return GrantAlways; - if (isa(op)) return GrantOnce; - if (isa(op)) return GrantPredicate; - if (isa(op)) return GEP_; - if (isa(op)) return Constant; - if (isa(op)) return Phi; - if (isa(op)) return DataMov; - if (isa(op)) return CtrlMov; - if (isa(op)) return Reserve; + if (isa(op)) return OpIAdd; + if (isa(op)) return OpIMul; + if (isa(op)) return OpFAdd; + if (isa(op)) return OpFMul; + if (isa(op)) return OpISub; + if (isa(op)) return OpFSub; + if (isa(op)) return OpIDiv; + if (isa(op)) return OpFDiv; + if (isa(op)) return OpFAddFAdd; + if (isa(op)) return OpFMulFAdd; + if (isa(op)) return OpVFMul; + if (isa(op)) return OpICmp; + if (isa(op)) return OpNot; + if (isa(op)) return OpOr; + if (isa(op)) return OpSel; + if (isa(op)) return OpCast; + if (isa(op)) return OpLoad; + if (isa(op)) return OpLoadIndexed; + if (isa(op)) return OpStore; + if (isa(op)) return OpStoreIndexed; + if (isa(op)) return OpBr; + if (isa(op)) return OpCondBr; + if (isa(op)) return OpReturn; + if (isa(op)) return OpLoopController; + if (isa(op)) return OpGrantAlways; + if (isa(op)) return OpGrantOnce; + if (isa(op)) return OpGrantPredicate; + if (isa(op)) return OpGEP_; + if (isa(op)) return OpConstant; + if (isa(op)) return OpPhi; + if (isa(op)) return OpDataMov; + if (isa(op)) return OpCtrlMov; // Default fallback - return IAdd; + return OpIAdd; } // Returns true if the operation does not need CGRA tile placement. diff --git a/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp b/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp index 63130a04..2dc4c3c1 100644 --- a/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp +++ b/lib/NeuraDialect/Transforms/MapToAcceleratorPass.cpp @@ -55,6 +55,44 @@ struct MapToAcceleratorPass "If not specified, will use default 4x4 architecture."), llvm::cl::init("")}; +private: + // Loads architecture configuration from YAML file or returns default configuration + std::pair loadArchitectureConfig() const { + YAML::Node config; + bool use_default_arch = false; + + if (!archSpecPath.getValue().empty()) { + try { + std::ifstream file(archSpecPath.getValue()); + if (file.is_open()) { + config = YAML::Load(file); + if (config["architecture"]) { + llvm::outs() << "\033[31m[MapToAcceleratorPass] Loaded architecture from " + << archSpecPath.getValue() << "\033[0m\n"; + } else { + llvm::errs() << "[MapToAcceleratorPass] Invalid YAML format in " + << archSpecPath.getValue() << ", using default 4x4\n"; + use_default_arch = true; + } + } else { + llvm::errs() << "[MapToAcceleratorPass] Could not open architecture file " + << archSpecPath.getValue() << ", using default 4x4\n"; + use_default_arch = true; + } + } catch (const std::exception& e) { + llvm::errs() << "[MapToAcceleratorPass] Error parsing YAML file " + << archSpecPath.getValue() << ": " << e.what() << ", using default 4x4\n"; + use_default_arch = true; + } + } else { + use_default_arch = true; + llvm::errs() << "[MapToAcceleratorPass] No architecture specification provided, using default 4x4\n"; + } + + return {config, use_default_arch}; + } + +public: void runOnOperation() override { ModuleOp module = getOperation(); @@ -148,38 +186,11 @@ struct MapToAcceleratorPass // AcceleratorConfig config{/*numTiles=*/8}; // Example // Read architecture specification from command line option - YAML::Node config; - bool use_default_arch = false; + auto [config, use_default_arch] = loadArchitectureConfig(); - if (!archSpecPath.getValue().empty()) { - try { - std::ifstream file(archSpecPath.getValue()); - if (file.is_open()) { - config = YAML::Load(file); - if (config["architecture"]) { - llvm::outs() << "\033[31m[MapToAcceleratorPass] Loaded architecture from " - << archSpecPath.getValue() << "\033[0m\n"; - } else { - llvm::errs() << "[MapToAcceleratorPass] Invalid YAML format in " - << archSpecPath.getValue() << ", using default 4x4\n"; - use_default_arch = true; - } - } else { - llvm::errs() << "[MapToAcceleratorPass] Could not open architecture file " - << archSpecPath.getValue() << ", using default 4x4\n"; - use_default_arch = true; - } - } catch (const std::exception& e) { - llvm::errs() << "[MapToAcceleratorPass] Error parsing YAML file " - << archSpecPath.getValue() << ": " << e.what() << ", using default 4x4\n"; - use_default_arch = true; - } - } else { - use_default_arch = true; - llvm::errs() << "[MapToAcceleratorPass] No architecture specification provided, using default 4x4\n"; - } - - Architecture architecture = use_default_arch ? Architecture(4, 4) : Architecture(config); + constexpr int kWidth = 4; + constexpr int kHeight = 4; + Architecture architecture = use_default_arch ? Architecture(kWidth, kHeight) : Architecture(config); int res_mii = calculateResMii(func, architecture); IntegerAttr res_mii_attr = diff --git a/test/lit.cfg b/test/lit.cfg deleted file mode 100644 index 887d5be7..00000000 --- a/test/lit.cfg +++ /dev/null @@ -1,19 +0,0 @@ -import os -import lit.formats - -config.name = 'Neura Dialect Tests' -config.test_format = lit.formats.ShTest(True) -config.suffixes = ['.mlir'] -config.test_source_root = os.path.dirname(__file__) -config.test_exec_root = os.path.dirname(__file__) -config.excludes = ['samples'] - -# Tool substitutions from CMake -config.substitutions.append(('mlir-neura-opt', '/home/jackcui/Arch/MLiR/dataflow/build/tools/mlir-neura-opt/mlir-neura-opt')) -config.substitutions.append(('neura-interpreter', '/home/jackcui/Arch/MLiR/dataflow/build/tools/neura-interpreter/neura-interpreter')) -config.substitutions.append(('neura-compiler', '/home/jackcui/Arch/MLiR/dataflow/build/tools/neura-compiler/neura-compiler')) -config.substitutions.append(('FileCheck', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/FileCheck')) -config.substitutions.append(('mlir-opt', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/mlir-opt')) -config.substitutions.append(('mlir-translate', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/mlir-translate')) -config.substitutions.append(('llc', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/llc')) -config.substitutions.append(('clang', '/home/jackcui/Arch/MLiR/llvm-project/build/./bin/clang')) From 124f8cbec50936694acab214ec6a9ca7dbbe0fa2 Mon Sep 17 00:00:00 2001 From: Cui Bohan Date: Sun, 10 Aug 2025 20:46:19 -0500 Subject: [PATCH 5/5] Update main.yml update workflow to enable yaml cmake finding --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c069578e..8e801fd1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: # install yaml library - name: install yaml library - run: sudo apt-get install libyaml-dev + run: sudo apt-get install libyaml-cpp-dev # setup LLVM - name: install a specific version of LLVM