Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7437ec3
chore: add new algorithm to `HandshakePlaceBuffers.cpp`
ziadomalik Nov 14, 2025
2274e03
chore: add the skeleton files
ziadomalik Nov 14, 2025
1906a7e
chore: add check for the new FPGA24 algorithm
ziadomalik Nov 14, 2025
e08bd6a
chore: get the compiler to use our new algorithm
ziadomalik Nov 14, 2025
56d066d
chore: add CFC node printing.
ziadomalik Nov 15, 2025
cfcc740
chore: start
ziadomalik Nov 29, 2025
dc24fcc
chore: graph generated
ziadomalik Nov 29, 2025
36d37d3
chore: latest update with cleaned up reconvergent paths
ziadomalik Dec 5, 2025
012eb9e
feat: new generic dataflow graph ds that's acyclic
ziadomalik Dec 9, 2025
5d75a21
chore: add reconvergent paths back
ziadomalik Dec 9, 2025
87f1a77
chore: linting
ziadomalik Dec 9, 2025
648d130
chore: refactor code with the correct understanding of transitions
ziadomalik Dec 13, 2025
f2960ab
chore: refactor dataflow graph & separate the logic from the pathfinding
ziadomalik Dec 20, 2025
630ccaf
chore: remove the deprecated logic
ziadomalik Dec 21, 2025
6d1471c
chore: synchronizing cycle operation that compiles
ziadomalik Dec 22, 2025
5723838
chore: remove the synchronizing cycle implementation for now
ziadomalik Dec 23, 2025
818e8d0
chore: remove formatter added by vscode automatically
ziadomalik Dec 23, 2025
9bd0c6c
chore: remove the debugging setup
ziadomalik Dec 23, 2025
d59e64e
chore: bring back correct join definitons
ziadomalik Dec 23, 2025
3b61642
chore: clang format
ziadomalik Dec 23, 2025
2ffa65b
chore: rename class to `DataflowSubgraphBase`
ziadomalik Dec 27, 2025
bba462e
chore: turn `DataflowSubgraphBase` into a struct
ziadomalik Dec 27, 2025
d353c5a
chore: wrap debug messages in `LLVM_DEBUG`
ziadomalik Dec 27, 2025
9b11758
chore: better naming in `enumerateTransitionSequences`
ziadomalik Dec 27, 2025
4b48c3e
chore: remove static from `enumerateTransitionSequences`
ziadomalik Dec 27, 2025
7c9fe65
chore: add note for node indexing
ziadomalik Dec 27, 2025
d75e783
chore: remove templates for simplicity
ziadomalik Dec 27, 2025
16f2d9d
chore: clang-format
ziadomalik Dec 27, 2025
5f74846
chore: apply feedback
ziadomalik Dec 30, 2025
82ecc3f
chore: clang-format
ziadomalik Dec 30, 2025
855b6a4
chore: cosmetics
ziadomalik Jan 1, 2026
68f02b1
chore: add the synchronizing cycle code
ziadomalik Jan 4, 2026
8611307
chore: add comments explaining SC's and the algorithm
ziadomalik Jan 4, 2026
d8cc5b0
Merge branch 'main' into feat/ziad/synchronizing-cycles
ziadomalik Jan 4, 2026
91e3376
chore: remove const for `SimpleCycle`
ziadomalik Jan 5, 2026
f1c96ba
chore: explain `CycleCollector`
ziadomalik Jan 5, 2026
173d2fd
chore: add clarifying comment for `graphPaths`
ziadomalik Jan 5, 2026
7de91ff
chore: turn if into asserts also run `clang-format`
ziadomalik Jan 5, 2026
eed3634
chrore: redefine joins for SC's (not resolved) and move fork/join che…
ziadomalik Jan 5, 2026
efe56b9
chore: comment clarification for visited vector
ziadomalik Jan 5, 2026
f54c5ba
chore: name change for DFS functions
ziadomalik Jan 5, 2026
98fcdd7
chore: remove unnessesary outer loop
ziadomalik Jan 5, 2026
657976d
chore: add better comment explaining the bfs
ziadomalik Jan 5, 2026
460a8b3
chore: turn std::vec to llvm vector
ziadomalik Jan 5, 2026
2fd909e
chore: add NodeIdType
ziadomalik Jan 5, 2026
f88771f
chore: remove redundant revAdjList
ziadomalik Jan 5, 2026
1d37422
chore: refactor the SCCId vector and use `node.size()`
ziadomalik Jan 5, 2026
75a54b4
chore: remove the `data/aig`
ziadomalik Jan 6, 2026
f43a06c
chore: Fix submodule pointer
ziadomalik Jan 6, 2026
e0daca6
chore: use SmallVector instead of `std::vector` where possible
ziadomalik Jan 6, 2026
8a13204
chore: add `JoinLikeOpInterface` and better checking syntax
ziadomalik Jan 6, 2026
446d10a
chore: rename `dfs1` and `dfs2`
ziadomalik Jan 9, 2026
b7874cd
chore: add `JoinLikeOpInterface` to `ConditionalBranchOp`
ziadomalik Jan 9, 2026
4f55d37
chore: add good comment for `findEdgesToJoin`
ziadomalik Jan 9, 2026
cb72447
chore: simplify dumpAllReconvergentPaths
ziadomalik Jan 9, 2026
f995c70
chore: remove aig
ziadomalik Jan 9, 2026
97a4c16
chore: fresh start
ziadomalik Jan 9, 2026
eaf6e37
chore: not aig again ugh
ziadomalik Jan 10, 2026
d3336c7
chore: simplify input for debug function
ziadomalik Jan 10, 2026
33e0b7c
chore: typo
ziadomalik Jan 10, 2026
a1d416a
chore: define EdgeIdType
ziadomalik Jan 10, 2026
ffa647d
chore: good old clang-format
ziadomalik Jan 10, 2026
e281cb0
chore: aig somehow just made it in there AGAIN
ziadomalik Jan 10, 2026
7a32126
Merge branch 'feat/ziad/synchronizing-cycles' into feat/ziad/milp
ziadomalik Jan 10, 2026
0ff5364
chore: add function stubs and variables to constraint DB
ziadomalik Jan 14, 2026
50b0e0c
chore: add our algorithm
ziadomalik Jan 15, 2026
d2764bf
Merge remote-tracking branch 'origin/main' into feat/ziad/milp
ziadomalik Jan 15, 2026
687d098
chore: fix compilation error due to common issue
ziadomalik Jan 15, 2026
13ae250
chore: fix graph dumping error
ziadomalik Jan 16, 2026
4c5ca84
chore: add algorithm to `HandshakePlaceBuffers.cpp`
ziadomalik Jan 16, 2026
d8ad97d
chore: fix unrelated compiler errors introduced by sync with main
ziadomalik Jan 16, 2026
6130957
chore: add unit-vars that are not tied to CFDFCs to constraint DB
ziadomalik Jan 16, 2026
e22b8f1
chore: push working LP1, non-working LP2
ziadomalik Jan 16, 2026
b50b70b
chore: best I can do is `~3000` cycles without hacks and `~2000` cycl…
ziadomalik Jan 17, 2026
7e10fab
chore: clang-format
ziadomalik Jan 17, 2026
a5a1fbe
chore: more clang-format
ziadomalik Jan 17, 2026
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c- /GR-")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -frtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
endif ()

include(FindPackageHandleStandardArgs)
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ if [[ $SKIP_POLYGEIST -eq 0 ]]; then
-DLLVM_ENABLE_PROJECTS="mlir;clang;polly" \
-DLLVM_TARGETS_TO_BUILD="host" \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_ENABLE_EH=ON \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DLLVM_PARALLEL_LINK_JOBS=$LLVM_PARALLEL_LINK_JOBS \
Expand Down
2 changes: 1 addition & 1 deletion data/aig
Submodule aig updated 450 files
2 changes: 1 addition & 1 deletion experimental/include/experimental/Support/SubjectGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BaseSubjectGraph {
DenseMap<BaseSubjectGraph *, unsigned int> inputSubjectGraphToResultNumber;

// static map that holds all Operation/Subject Graph Pairs
static inline DenseMap<Operation *, BaseSubjectGraph *> moduleMap;
static inline DenseMap<Operation *, BaseSubjectGraph *> moduleMap{};

// A vector of all BaseSubjectGraphs. This is not a subset of the Values of
// moduleMap, since not all of the SubjectGraphs are created from Operations
Expand Down
1 change: 1 addition & 0 deletions include/dynamatic/Dialect/Handshake/HandshakeArithOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Handshake_Arith_Op<string mnemonic, list<Trait> traits = []> :
class Handshake_Arith_BinaryOp<string mnemonic, list<Trait> traits = []> :
Handshake_Arith_Op<mnemonic, traits # [
SameOperandsAndResultType,
JoinLikeOpInterface,
DeclareOpInterfaceMethods<NamedIOInterface, ["getOperandName", "getResultName"]>,
]> {
let arguments = (ins ChannelType:$lhs, ChannelType:$rhs);
Expand Down
7 changes: 7 additions & 0 deletions include/dynamatic/Dialect/Handshake/HandshakeInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def MergeLikeOpInterface : OpInterface<"MergeLikeOpInterface"> {
];
}

def JoinLikeOpInterface : OpInterface<"JoinLikeOpInterface"> {
let cppNamespace = "::dynamatic::handshake";
let description = [{
A two-input handshake operation that contains a join.
}];
}

def BufferLikeOpInterface : OpInterface<"BufferLikeOpInterface"> {
let cppNamespace = "::dynamatic::handshake";
let description = [{
Expand Down
1 change: 1 addition & 0 deletions include/dynamatic/Dialect/Handshake/HandshakeOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def BranchOp : Handshake_Op<"br", [
}

def ConditionalBranchOp : Handshake_Op<"cond_br", [
JoinLikeOpInterface,
AllTypesMatch<["dataOperand", "trueResult", "falseResult"]>,
AllExtraSignalsMatch<["conditionOperand", "dataOperand", "trueResult", "falseResult"]>,
IsIntSizedChannel<1, "conditionOperand">,
Expand Down
22 changes: 22 additions & 0 deletions include/dynamatic/Transforms/BufferPlacement/BufferPlacementMILP.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
#include "experimental/Support/SubjectGraph.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Value.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"

namespace dynamatic {
namespace buffer {
Expand All @@ -54,6 +56,8 @@ struct UnitVars {
/// Fluid retiming of tokens at unit's output. Identical to retiming at unit's
/// input if the latter is combinational (real).
CPVar retOut;
/// Occupancy contribution of this unit (real).
CPVar occupancy;
};

/// Holds MILP variables related to a specific signal (e.g., data, valid, ready)
Expand All @@ -78,6 +82,18 @@ struct ChannelVars {
CPVar dataLatency;
/// Usage of a shift register on the channel (binary).
CPVar shiftReg;

/// Extra latency to insert on this channel for balancing (integer).
CPVar extraLatency;
/// Whether the channel is stalled due to pattern imbalance (binary).
CPVar stalled;
/// Maximum token occupancy for this channel (real).
CPVar maxOccupancy;
};

struct SynchronizationPatternVars {
/// Whether the synchronization pattern is imbalanced (binary).
CPVar imbalanced;
};

/// Holds all variables associated to a CFDFC. These are a set of variables for
Expand All @@ -100,6 +116,12 @@ struct MILPVars {
llvm::MapVector<CFDFC *, CFDFCVars> cfdfcVars;
/// Mapping between channels and their related variables.
llvm::MapVector<Value, ChannelVars> channelVars;
/// Balancing variables for reconvergent paths.
SmallVector<SynchronizationPatternVars> reconvergentPathVars;
/// Balancing variables for synchronizing cycles.
SmallVector<SynchronizationPatternVars> syncCycleVars;
/// List of units in the function.
llvm::MapVector<Operation *, UnitVars> unitVars;
};

/// Abstract class holding the basic logic for the smart buffer placement pass,
Expand Down
144 changes: 144 additions & 0 deletions include/dynamatic/Transforms/BufferPlacement/FPGA24Buffers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//===- FPGA24Buffers.h ------------------------------------------------===//
//
// Dynamatic is under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===------------------------------------------------------------------===//
//
// TODO
//
//===------------------------------------------------------------------===//

#ifndef DYNAMATIC_TRANSFORMS_BUFFERPLACEMENT_FPGA24BUFFERS_H
#define DYNAMATIC_TRANSFORMS_BUFFERPLACEMENT_FPGA24BUFFERS_H

#include "dynamatic/Support/ConstraintProgramming/ConstraintProgramming.h"
#include "dynamatic/Support/TimingModels.h"
#include "dynamatic/Transforms/BufferPlacement/BufferPlacementMILP.h"
#include "dynamatic/Transforms/BufferPlacement/BufferingSupport.h"
#include "dynamatic/Transforms/BufferPlacement/CFDFC.h"
#include "dynamatic/Transforms/BufferPlacement/LatencyAndOccupancyBalancingSupport.h"

namespace dynamatic {
namespace buffer {
namespace fpga24 {

/// Latency Balancing MILP ///

/// Holds the result of the first LP for usage in the LP.
struct LatencyBalancingResult {
/// Map from channel to its computed extra latency.
DenseMap<Value, unsigned> channelExtraLatency;
/// Target intiation interval.
double targetII;
};

/// Helper struct that pairs a reconvergent path with its corresponding
/// transition graph. Since we're enumerating transition sequences, build graphs
/// from those and then in turn build reconvergent paths from those graphs, it's
/// better to pair them like this instead of playing around with indices.
struct ReconvergentPathWithGraph {
ReconvergentPath path;
const ReconvergentPathFinderGraph *graph;

ReconvergentPathWithGraph(ReconvergentPath p,
const ReconvergentPathFinderGraph *g)
: path(std::move(p)), graph(g) {}
};

class LatencyBalancingMILP : public BufferPlacementMILP {
public:
LatencyBalancingMILP(CPSolver::SolverKind solverKind, int timeout,
FuncInfo &funcInfo, const TimingDatabase &timingDB,
double targetPeriod,
ArrayRef<ReconvergentPathWithGraph> reconvergentPaths,
ArrayRef<SynchronizingCyclePair> syncCyclePairs,
const SynchronizingCyclesFinderGraph &syncGraph,
ArrayRef<CFDFC *> cfdfcs);

/// Extract latency results after solving.
LatencyBalancingResult extractLatencyResults();

protected:
/// Interpret solution - not used for buffer placement directly.
void extractResult(BufferPlacement &placement) override;

private:
ArrayRef<ReconvergentPathWithGraph> reconvergentPaths;
ArrayRef<SynchronizingCyclePair> syncCyclePairs;

/// Reference to synchronizing cycles graph.
const SynchronizingCyclesFinderGraph &syncGraph;

/// CFDFCs needed for cylce constraints.
ArrayRef<CFDFC *> cfdfcs;

void addLatencyVariables();

/// Add pattern imbalance constraints for reconvergent paths.
void addReconvergentPathConstraints();

/// Add pattern imbalance constraints for synchronizing cycles.
void addSyncCycleConstraints();

void addStallPropagationConstraints();

/// Add cycle time (II) constraints for each CFDFC cycle.
void addCycleTimeConstraints();

/// Minimize stalls first, then latency cost.
void setLatencyBalancingObjective();

/// Setups the entire MILP, creating all variables, constraints, and setting
/// the system's objective. Called by the constructor in the absence of prior
/// failures, after which the MILP is ready to be optimized.
void setup();
};

class OccupancyBalancingLP : public BufferPlacementMILP {
public:
OccupancyBalancingLP(CPSolver::SolverKind solverKind, int timeout,
FuncInfo &funcInfo, const TimingDatabase &timingDB,
double targetPeriod,
const LatencyBalancingResult &latencyResult,
ArrayRef<ReconvergentPathWithGraph> reconvergentPaths,
ArrayRef<CFDFC *> cfdfcs);

bool isUnsatisfiable() const { return unsatisfiable; }

void extractResult(BufferPlacement &placement) override;

private:
const LatencyBalancingResult &latencyResult;

ArrayRef<ReconvergentPathWithGraph> reconvergentPaths;
ArrayRef<CFDFC *> cfdfcs;

DenseMap<Value, CPVar> channelOccupancy;

void setup();
};

class FPGA24Buffers {
public:
FPGA24Buffers(CPSolver::SolverKind solverKind, int timeout,
FuncInfo &funcInfo, const TimingDatabase &timingDB,
double targetPeriod);

/// Run the complete algorithm and return placement.
LogicalResult solve(BufferPlacement &placement);

private:
CPSolver::SolverKind solverKind;
int timeout;
FuncInfo &funcInfo;
double targetPeriod;
const TimingDatabase &timingDB;
};

} // namespace fpga24
} // namespace buffer
} // namespace dynamatic

#endif /// DYNAMATIC_TRANSFORMS_BUFFERPLACEMENT_FPGA24BUFFERS_H
Loading
Loading