-
Notifications
You must be signed in to change notification settings - Fork 16
Arch-aware Mapping (successfully built, read spec path from ENV) #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
30187d6
db8d764
db24510
38abb68
7333452
2609389
deef1c0
124f8cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| build/ | ||
|
|
||
| .vscode/ | ||
| *.swp | ||
| *.swo | ||
|
|
||
| generated-instructions.json | ||
|
|
||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| /test/lit.cfg |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| #include <set> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
| #include <yaml-cpp/yaml.h> | ||
|
|
||
| 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); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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<FixedPointAdder>(0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // addFunctionUnit(std::make_unique<FixedPointAdder>(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"]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
tancheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| width = config["architecture"]["width"].as<int>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| height = config["architecture"]["height"].as<int>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Call the constructor with width and height. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *this = Architecture(width, height); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add function units based on the architecture specs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| int num_tiles = width * height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+278
to
+292
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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<int>(); | |
| height = config["architecture"]["height"].as<int>(); | |
| } | |
| // Call the constructor with width and height. | |
| *this = Architecture(width, height); | |
| // Add function units based on the architecture specs. | |
| int num_tiles = width * height; | |
| Architecture::Architecture(const YAML::Node& config) | |
| : Architecture( | |
| config["architecture"] && config["architecture"]["width"] && config["architecture"]["height"] | |
| ? config["architecture"]["width"].as<int>() | |
| : 4, | |
| config["architecture"] && config["architecture"]["height"] | |
| ? config["architecture"]["height"].as<int>() | |
| : 4) { | |
| // Add function units based on the architecture specs. | |
| int num_tiles = getNumTiles(); |
Outdated
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable fu_id is pre-incremented before use, which means the first function unit will have ID 1 instead of 0. This inconsistency could cause issues if function unit IDs are expected to start from 0.
| tile->addFunctionUnit(std::make_unique<FixedPointAdder>(++fu_id)); | |
| tile->addFunctionUnit(std::make_unique<FixedPointAdder>(fu_id++)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think copilot's suggestion makes sense?
Outdated
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above - fu_id should be post-incremented or the logic should be adjusted to start from 0.
| tile->addFunctionUnit(std::make_unique<FixedPointAdder>(++fu_id)); | |
| tile->addFunctionUnit(std::make_unique<FixedPointAdder>(fu_id++)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -13,6 +13,9 @@ | |||
| #include "mlir/Pass/Pass.h" | ||||
| #include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||||
| #include "llvm/Support/raw_ostream.h" | ||||
| #include <cstdlib> | ||||
| #include <fstream> | ||||
| #include <yaml-cpp/yaml.h> | ||||
|
|
||||
| using namespace mlir; | ||||
| using namespace mlir::neura; | ||||
|
|
@@ -46,6 +49,12 @@ struct MapToAcceleratorPass | |||
| "max_loc=5, max_depth=3)"), | ||||
| llvm::cl::init("heuristic")}; | ||||
|
|
||||
| Option<std::string> 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(); | ||||
|
|
||||
|
|
@@ -140,7 +149,40 @@ struct MapToAcceleratorPass | |||
| func->setAttr("RecMII", rec_mii_attr); | ||||
|
|
||||
| // AcceleratorConfig config{/*numTiles=*/8}; // Example | ||||
| Architecture architecture(4, 4); | ||||
| // Read architecture specification from command line option | ||||
| 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; | ||||
|
||||
| use_default_arch = true; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put these into a function?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr int kWidth = 4;
constexpr int kHeight = 4;
Architecture architecture = use_default_arch ? Architecture(kWidth, kHeight) : Architecture(config);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the problems above are fixed, but I can still not reproduce the environment problem. (even in a locally deployed Docker) a bit strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean yaml-related env problem cannot be fixed?
-- Configuring incomplete, errors occurred!
By not providing "Findyaml-cpp.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "yaml-cpp",
but CMake did not find one.
Could not find a package configuration file provided by "yaml-cpp" with any
of the following names:
yaml-cppConfig.cmake
yaml-cpp-config.cmake
Add the installation prefix of "yaml-cpp" to CMAKE_PREFIX_PATH or set
"yaml-cpp_DIR" to a directory containing one of the above files. If
"yaml-cpp" provides a separate development package or SDK, be sure it has
been installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. The main problem is that even with a totally clean Docker env, the problem does not occurs. And I am not sure what the real path of them in a blackbox workflow env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw some one said libyaml-cpp-dev (instead of libyaml-dev) may work. Let me try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean yaml-related env problem cannot be fixed?
-- Configuring incomplete, errors occurred! By not providing "Findyaml-cpp.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "yaml-cpp", but CMake did not find one. Could not find a package configuration file provided by "yaml-cpp" with any of the following names: yaml-cppConfig.cmake yaml-cpp-config.cmake Add the installation prefix of "yaml-cpp" to CMAKE_PREFIX_PATH or set "yaml-cpp_DIR" to a directory containing one of the above files. If "yaml-cpp" provides a separate development package or SDK, be sure it has been installed.
Cool. It seems to work! (Still something to be fixed :D)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome~!
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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')) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| 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')) | |
| config.substitutions.append(('mlir-neura-opt', os.getenv('MLIR_NEURA_OPT_PATH', ''))) | |
| config.substitutions.append(('neura-interpreter', os.getenv('NEURA_INTERPRETER_PATH', ''))) | |
| config.substitutions.append(('neura-compiler', os.getenv('NEURA_COMPILER_PATH', ''))) | |
| config.substitutions.append(('FileCheck', os.getenv('FILECHECK_PATH', ''))) | |
| config.substitutions.append(('mlir-opt', os.getenv('MLIR_OPT_PATH', ''))) | |
| config.substitutions.append(('mlir-translate', os.getenv('MLIR_TRANSLATE_PATH', ''))) | |
| config.substitutions.append(('llc', os.getenv('LLC_PATH', ''))) | |
| config.substitutions.append(('clang', os.getenv('CLANG_PATH', ''))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't check in this file. Similarly, plz remove all the build files. avoid using git add .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't check in this file.