Skip to content

[Buffer] Add optimal latency and occupancy balancing LPs#782

Open
ziadomalik wants to merge 18 commits intomainfrom
feat/ziad/milp-with-stalls-fixed
Open

[Buffer] Add optimal latency and occupancy balancing LPs#782
ziadomalik wants to merge 18 commits intomainfrom
feat/ziad/milp-with-stalls-fixed

Conversation

@ziadomalik
Copy link
Collaborator

A cleaner version of #711, as I am unsure if I messed up the rebasing or not.

@ziadomalik
Copy link
Collaborator Author

ziadomalik commented Mar 11, 2026

Addressing Jiahui's Feedback

What's the difference between extraLatency and dataLatency?

The extraLatency is the result we determine based on LP1, and I am also using it to derive the occupancy in LP2 and as I understand it dataLatency just gives you the actual D/V buffer latency, so unless we do a bigger refactor, not sure if we can use only one.

Add a remark for the CPVars that are exclusive to FPGA24

Done.

Better names for ReconvergentPath and ReconvergentPathFinderGraph

Shall we call it CFGTransitionSequenceSubgraph (to match what is actually is)?

Sure, done!

Does it make more sense to put the edges already here (so we'll not need ReconvergentPathFinderGraph here anymore)? This could be implemented as a subgraph as well

We obtain the edges through that CFGTransitionSequenceSubgraph anyways, so we can split it, but we'll make use of it anyways, so not sure if it will make it cleaner (unless we just make it all one big class)

Remove ArrayRef as class members

Done!

Why do we set visited[current] = false

Becuase two simple paths may share the same node, but are not equal, keeping visited as true would block that node from ever being visited, disallowing us from getting all possible simple path combinations.

addLatencyVariables containing irrelevant code

I think you're referring to the setup code needed to add the variables, no? What would you propose we do to make it cleaner?

Purpose pathNumVars and pathNumEdges

They were just for printing debug information, removed it.

Why can't it be a single vector of edges?

  • You need to preserve which join each edge group belongs to, and
  • You need to preserve whether edges come from cycle one or cycle two.

@ziadomalik ziadomalik requested a review from Jiahui17 March 11, 2026 13:50
Comment on lines +85 to +86
/// [FPGA24] Extra latency to insert on this channel for balancing (integer).
CPVar extraLatency;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraLatency: should we just use dataLatency?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you rebase this correctly

Comment on lines +43 to +50
struct LatencyBalancingResult {
/// Map from channel to its computed extra latency.
DenseMap<Value, unsigned> channelExtraLatency;
/// Target intiation interval.
double targetII;
/// Target intiation interval per CFDFC.
DenseMap<CFDFC *, double> cfdfcTargetIIs;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MapVector<> to make sure that the result is deterministic

double targetPeriod,
ArrayRef<ReconvergentPathWithGraph> reconvergentPaths,
ArrayRef<SynchronizingCyclePair> syncCyclePairs,
const SynchronizingCyclesFinderGraph &syncGraph,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we still need the syncGraph if we already have the pairs?

Comment on lines +101 to +113
/// 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the policy is to put all the constraint writing functions into BufferPlacementMILP (which has a database of constraints)

Comment on lines +45 to +55
/// Big-M constant for imbalance constraints.
// (Paper: Section 4, Equation 2)
static constexpr double BIG_M = 1000.0;

/// Weight for stall penalty vs latency cost (>> LATENCY_WEIGHT to prioritize
/// stalls). See usage in (Paper: Section 4, Equation 7)
static constexpr double LATENCY_WEIGHT = 1.0;
static constexpr double STALL_WEIGHT = 1000.0;

/// Upper bound for occupancy
static constexpr double MAX_OCCUPANCY = 100.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the header?

Comment on lines +69 to +72
// LLVM_DEBUG(llvm::errs() << "Load Operation Latency: " << latency << "
// for " << opName.str() << "\n");
llvm::errs() << "Getting latency for load operation failed! For "
<< opName.str() << "\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug

Comment on lines +80 to +84
// LLVM_DEBUG(llvm::errs() << "Load Operation Latency: " << latency << " for
// " << opName.str() << "\n");
llvm::errs() << "Load Operation Latency: " << latency << " for "
<< opName.str() << "\n";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug

/// 1. Channels in synchronization patterns (for balancing).
/// 2. ALL channels in CFDFCs (for cycle time constraints).
/// Relevant: (Paper: Section 4, Equation 1, 5).
DenseSet<Value> allChannels;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ordered set to make sure that the result is deterministic

/// The latency variable L_c is the number of extra latencies to be added to a
/// channel. It will be used in the input of the occupancy balancing LP. Defined
/// in (Paper: Section 4, Table 1).
void LatencyBalancingMILP::addLatencyVariables() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. not just latency variables?
  2. why not just adding all variables

@Jiahui17
Copy link
Member

The extraLatency is the result we determine based on LP1, and I am also using it to derive the occupancy in LP2 and as I understand it dataLatency just gives you the actual D/V buffer latency, so unless we do a bigger refactor, not sure if we can use only one.

isn't the latency we determined from LP1 the actual D/V buffer latency that we gonna use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants