Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3b32f7b
Support implementation of architecture_spec config.
n0thingNoob Oct 4, 2025
3868937
Refactor code style: convert variables to snake_case and fix comments
n0thingNoob Oct 4, 2025
8b0fe95
Combine all configure Supported Operation
n0thingNoob Oct 5, 2025
9c51fd7
test modified by adding a test
n0thingNoob Oct 7, 2025
adc01bb
Merge branch 'main' into architecture_spec
n0thingNoob Oct 7, 2025
31c15f3
adding architecture spec to tests
n0thingNoob Oct 7, 2025
3eb9d0a
Adding port override for tiles
n0thingNoob Oct 7, 2025
57315e0
Fix some comments
n0thingNoob Oct 7, 2025
d803c06
Adding base topology support
n0thingNoob Oct 9, 2025
629ddb6
Merge branch 'main' into architecture_spec
n0thingNoob Oct 9, 2025
a7c8096
fix comments
n0thingNoob Oct 9, 2025
2f79da4
Merge branch 'architecture_spec' of github.com:coredac/dataflow into …
n0thingNoob Oct 9, 2025
31b8229
Merge remote-tracking branch 'origin/main' into architecture_spec
n0thingNoob Oct 9, 2025
016ed4a
Add spec to fusion test
n0thingNoob Oct 9, 2025
49d3e5e
modify the test.mlir spec path
n0thingNoob Oct 9, 2025
97be637
fix variable name
n0thingNoob Oct 9, 2025
4bb9a06
rename test_architecture_spec
n0thingNoob Oct 10, 2025
80d7624
modify the arch spec path for fusion
n0thingNoob Oct 10, 2025
7dc8158
Fix link storage safety issue and improve code comments
n0thingNoob Oct 10, 2025
4355b9f
Fix remaining comment formatting issues
n0thingNoob Oct 10, 2025
b59a4e4
Change tile container to map, modify the comments format
n0thingNoob Oct 10, 2025
f9c7787
Simplify function unit creation by using post-increment operator
n0thingNoob Oct 10, 2025
2e8d575
Move architecture.yaml to test/arch_spec/arch_spec_example.yaml
n0thingNoob Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/ArchitectureSpec/architecture.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
architecture:
name: "NeuraCGRA"
version: "1.0"
width: 4
height: 4
width: 8
height: 8

tile_defaults:
num_registers: 64
num_registers: 128
default_ports: ["N", "S", "W", "E"]
operations: ["add", "mul", "sub"] # default ALU instructions
operations: ["add", "mul", "sub", "div", "rem", "fadd", "fmul", "fsub", "fdiv", "or", "not", "icmp", "fcmp", "sel", "cast", "sext", "zext", "shl", "vfmul", "fadd_fadd", "fmul_fadd", "data_mov", "ctrl_mov", "reserve", "grant_predicate", "grant_once", "grant_always", "loop_control", "phi", "constant"] # comprehensive operation set

link_defaults:
latency: 1
Expand Down
111 changes: 84 additions & 27 deletions include/NeuraDialect/Architecture/Architecture.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef NEURA_ARCHITECTURE_H
#define NEURA_ARCHITECTURE_H

#include <algorithm>
#include <cassert>
#include <map>
#include <memory>
Expand Down Expand Up @@ -30,7 +31,32 @@ enum class FunctionUnitKind {
};

// Enum for supported operation types.
enum OperationKind { IAdd = 0, IMul = 1, FAdd = 2, FMul = 3 };
enum OperationKind {
// Integer arithmetic operations
IAdd = 0, IMul = 1, ISub = 2, IDiv = 3, IRem = 4,
// Floating-point arithmetic operations
FAdd = 5, FMul = 6, FSub = 7, FDiv = 8,
// Memory operations
ILoad = 9, IStore = 10, ILoadIndexed = 11, IStoreIndexed = 12, IAlloca = 13,
// Logical operations
IOr = 14, INot = 15, ICmp = 16, FCmp = 17, ISel = 18,
// Type conversion operations
ICast = 19, ISExt = 20, IZExt = 21, IShl = 22,
// Vector operations
VFMul = 23,
// Fused operations
FAddFAdd = 24, FMulFAdd = 25,
// Control flow operations
IReturn = 26, IPhi = 27,
// Data movement operations
IDataMov = 28, ICtrlMov = 29,
// Predicate operations
IReserve = 30, IGrantPredicate = 31, IGrantOnce = 32, IGrantAlways = 33,
// Loop control operations
ILoopControl = 34,
// Constant operations
IConstant = 35
};

//===----------------------------------------------------------------------===//
// BasicResource: abstract base class for Tile, Link, etc.
Expand Down Expand Up @@ -94,24 +120,6 @@ class FunctionUnit : public BasicResource {
Tile *tile;
};

class FixedPointAdder : public FunctionUnit {
public:
FixedPointAdder(int id) : FunctionUnit(id) {
supported_operations.insert(OperationKind::IAdd);
}
std::string getType() const override { return "fixed_point_adder"; }
ResourceKind getKind() const override { return ResourceKind::FunctionUnit; }
};

class FixedPointMultiplier : public FunctionUnit {
public:
FixedPointMultiplier(int id) : FunctionUnit(id) {
supported_operations.insert(OperationKind::IMul);
}
std::string getType() const override { return "fixed_point_multiplier"; }
ResourceKind getKind() const override { return ResourceKind::FunctionUnit; }
};

class CustomizableFunctionUnit : public FunctionUnit {
public:
CustomizableFunctionUnit(int id) : FunctionUnit(id) {}
Expand Down Expand Up @@ -143,6 +151,7 @@ class Tile : public BasicResource {
int getY() const;

void linkDstTile(Link *link, Tile *tile);
void unlinkDstTile(Link *link, Tile *tile);
const std::set<Tile *> &getDstTiles() const;
const std::set<Tile *> &getSrcTiles() const;
const std::set<Link *> &getOutLinks() const;
Expand All @@ -155,16 +164,20 @@ class Tile : public BasicResource {
functional_units.insert(functional_unit_storage.back().get());
}

void clearFunctionUnits() {
functional_unit_storage.clear();
functional_units.clear();
}

bool canSupportOperation(OperationKind operation) const {
for (FunctionUnit *fu : functional_units) {
if (fu->canSupportOperation(operation)) {
return true;
}
}
// TODO: Check if the tile can support the operation based on its
// capabilities.
// @Jackcuii, https://github.com/coredac/dataflow/issues/82.
return true;
// Checks if any function unit in this tile supports the operation.
// This is now properly implemented by checking all functional units.
return false;
}

void addRegisterFileCluster(RegisterFileCluster *register_file_cluster);
Expand All @@ -175,6 +188,17 @@ class Tile : public BasicResource {

const std::vector<Register *> getRegisters() const;

// Port management
const std::vector<std::string> &getPorts() const { return ports; }
void setPorts(const std::vector<std::string> &newPorts) { ports = newPorts; }
bool hasPort(const std::string &port) const {
return std::find(ports.begin(), ports.end(), port) != ports.end();
}

// Memory management
int getMemoryCapacity() const { return memory_capacity; }
void setMemoryCapacity(int capacity) { memory_capacity = capacity; }

private:
int id;
int x, y;
Expand All @@ -186,6 +210,10 @@ class Tile : public BasicResource {
functional_unit_storage; // Owns FUs.
std::set<FunctionUnit *> functional_units; // Non-owning, for fast lookup.
RegisterFileCluster *register_file_cluster = nullptr;

// Port and memory configuration
std::vector<std::string> ports;
int memory_capacity = -1; // -1 means not configured
};

//===----------------------------------------------------------------------===//
Expand All @@ -210,10 +238,18 @@ class Link : public BasicResource {

void connect(Tile *src, Tile *dst);

// Link properties
int getLatency() const { return latency; }
int getBandwidth() const { return bandwidth; }
void setLatency(int l) { latency = l; }
void setBandwidth(int b) { bandwidth = b; }

private:
int id;
Tile *src_tile;
Tile *dst_tile;
int latency = 1;
int bandwidth = 32;
};

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -318,11 +354,22 @@ struct PairHash {
}
};

// Forward declaration
struct TileDefaults;
struct TileOverride;
struct LinkDefaults;
struct LinkOverride;

// Describes the CGRA architecture template.
// TODO: Model architecture in detail (e.g., registers, ports).
// Now supports comprehensive configuration via YAML including ports, memory, and function units.
class Architecture {
public:
Architecture(int width, int height);
// Single constructor - handles all cases internally
Architecture(int width, int height,
const TileDefaults& tileDefaults,
const std::vector<TileOverride>& tileOverrides,
const LinkDefaults& linkDefaults,
const std::vector<LinkOverride>& linkOverrides);

Tile *getTile(int id);
Tile *getTile(int x, int y);
Expand All @@ -331,14 +378,24 @@ class Architecture {
int getHeight() const { return height; }

Link *getLink(int id);
void removeLink(int linkId);

int getNumTiles() const;
std::vector<Tile *> getAllTiles() const;
std::vector<Link *> getAllLinks() const;

private:
// TODO: Model architecture in detail, e.g., ports, registers, crossbars, etc.
// https://github.com/coredac/dataflow/issues/52.
// Helper methods for constructor initialization.
void initializeTiles(int width, int height);
void configureDefaultTileSettings(const TileDefaults& tileDefaults);
void applyTileOverrides(const std::vector<TileOverride>& tileOverrides);
void createLinks(const LinkDefaults& linkDefaults);
void applyLinkOverrides(const std::vector<LinkOverride>& linkOverrides);
void createRegisterFileCluster(Tile *tile, int num_registers, int &reg_id);
void recreateRegisterFileCluster(Tile *tile, int num_registers);

// Architecture components: tiles, links, and their mappings.
// Ports and memory are now modeled as part of Tile class.
std::vector<std::unique_ptr<Tile>> tile_storage;
std::vector<std::unique_ptr<Link>> link_storage;
std::unordered_map<int, Tile *> id_to_tile;
Expand Down
58 changes: 58 additions & 0 deletions include/NeuraDialect/Architecture/ArchitectureSpec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef NEURA_ARCHITECTURE_SPEC_H
#define NEURA_ARCHITECTURE_SPEC_H

#include <string>
#include <vector>

namespace mlir {
namespace neura {

// Structure to hold tile default configuration
struct TileDefaults {
int num_registers = 64; // default value
std::vector<std::string> default_ports = {"N", "S", "W", "E"}; // default ports
std::vector<std::string> operations = {"add", "mul", "sub"}; // default operations
};

// Structure to hold memory configuration
struct MemoryConfig {
int capacity = -1; // Memory capacity in bytes
};

// Structure to hold tile override configuration
struct TileOverride {
int id = -1;
int x = -1, y = -1;
std::vector<std::string> operations;
int num_registers = -1;
std::vector<std::string> ports;
MemoryConfig memory;
};

// Structure to hold link default configuration
struct LinkDefaults {
int latency = 1; // default latency
int bandwidth = 32; // default bandwidth
};

// Structure to hold link override configuration
struct LinkOverride {
int id = -1;
int latency = -1;
int bandwidth = -1;
int src_tile_id = -1;
int dst_tile_id = -1;
bool existence = true;
};

// Function to get the architecture specification file path
// This is set by the command line tool when a YAML file is provided
std::string getArchitectureSpecFile();

// Function to get tile defaults configuration
TileDefaults getTileDefaults();

} // namespace neura
} // namespace mlir

#endif // NEURA_ARCHITECTURE_SPEC_H
Loading
Loading