Skip to content

Commit 51475d8

Browse files
Keep topology capacity opt-in
1 parent 5a53018 commit 51475d8

4 files changed

Lines changed: 35 additions & 11 deletions

File tree

lib/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ export class TinyHyperGraphSolver extends BaseSolver {
14461446
),
14471447
MAX_NEGOTIATION_PASSES: maxNegotiationPasses,
14481448
SKIP_UNROUTABLE_ROUTES: true,
1449+
USE_TOPOLOGY_CAPACITY: true,
14491450
})
14501451
regionPathSolver.solve()
14511452

lib/region-graph/graph.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface RegionGraph {
1818
regionWidth: Float64Array
1919
regionHeight: Float64Array
2020
regionCapacity: Float64Array
21+
regionTrackCapacity: Int32Array
2122
regionMetadata?: any[]
2223
edges: RegionGraphEdge[]
2324
incidentEdges: RegionGraphEdge[][]
@@ -155,7 +156,7 @@ export const createRegionGraph = (
155156
incidentEdges[edge.regionIdB]!.push(edge)
156157
}
157158

158-
const regionCapacity = Float64Array.from(
159+
const regionTrackCapacity = Int32Array.from(
159160
{ length: topology.regionCount },
160161
(_, regionId) => {
161162
const boundaryPortCount = incidentEdges[regionId]!.reduce(
@@ -177,7 +178,15 @@ export const createRegionGraph = (
177178
regionCenterY: topology.regionCenterY,
178179
regionWidth: topology.regionWidth,
179180
regionHeight: topology.regionHeight,
180-
regionCapacity,
181+
regionCapacity: Float64Array.from(
182+
{ length: topology.regionCount },
183+
(_, regionId) =>
184+
Math.max(
185+
1e-6,
186+
topology.regionWidth[regionId] * topology.regionHeight[regionId],
187+
),
188+
),
189+
regionTrackCapacity,
181190
regionMetadata: topology.regionMetadata,
182191
edges,
183192
incidentEdges,

lib/region-graph/region-path-solver.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface RegionPathSolverOptions {
2020
USE_TOPOLOGY_CAPACITY?: boolean
2121
MAX_NEGOTIATION_PASSES?: number
2222
SKIP_UNROUTABLE_ROUTES?: boolean
23+
USE_TOPOLOGY_CAPACITY?: boolean
2324
}
2425

2526
export interface RegionPathCandidate {
@@ -78,6 +79,7 @@ export class RegionPathSolver extends BaseSolver {
7879
USE_TOPOLOGY_CAPACITY = false
7980
MAX_NEGOTIATION_PASSES = 4
8081
SKIP_UNROUTABLE_ROUTES = false
82+
USE_TOPOLOGY_CAPACITY = false
8183
skippedRouteIds: RouteId[] = []
8284
negotiationPass = 0
8385

@@ -108,6 +110,9 @@ export class RegionPathSolver extends BaseSolver {
108110
if (options?.SKIP_UNROUTABLE_ROUTES !== undefined) {
109111
this.SKIP_UNROUTABLE_ROUTES = options.SKIP_UNROUTABLE_ROUTES
110112
}
113+
if (options?.USE_TOPOLOGY_CAPACITY !== undefined) {
114+
this.USE_TOPOLOGY_CAPACITY = options.USE_TOPOLOGY_CAPACITY
115+
}
111116

112117
this.state = {
113118
regionUsage: new Int32Array(this.regionGraph.regionCount),
@@ -325,7 +330,8 @@ export class RegionPathSolver extends BaseSolver {
325330
? 0
326331
: 1)
327332
const regionCapacity = this.regionGraph.regionCapacity[regionId]
328-
const overflow = Math.max(0, nextUsage - regionCapacity)
333+
const trackCapacity = this.getRegionCapacity(regionId)
334+
const overflow = Math.max(0, nextUsage - trackCapacity)
329335
return (
330336
(nextUsage / regionCapacity) * this.MM_COST_FOR_FULL_REGION +
331337
overflow * this.getOverCapacityCost() +
@@ -334,6 +340,8 @@ export class RegionPathSolver extends BaseSolver {
334340
}
335341

336342
computeEdgeEntryCost(edgeId: number): number {
343+
if (!this.USE_TOPOLOGY_CAPACITY) return 0
344+
337345
const currentNetId = this.state.currentRouteNetId
338346
const nextUsage =
339347
this.state.edgeUsage[edgeId] +
@@ -344,23 +352,29 @@ export class RegionPathSolver extends BaseSolver {
344352
const edgeCapacity = this.regionGraph.edges[edgeId]!.portIds.length
345353
const overflow = Math.max(0, nextUsage - edgeCapacity)
346354
return (
347-
(nextUsage / edgeCapacity) * this.MM_COST_FOR_FULL_REGION +
348355
overflow * this.getOverCapacityCost() +
349356
this.state.edgeHistoricalCost[edgeId]
350357
)
351358
}
352359

360+
getRegionCapacity(regionId: RegionId): number {
361+
return this.USE_TOPOLOGY_CAPACITY
362+
? this.regionGraph.regionTrackCapacity[regionId]!
363+
: this.regionGraph.regionCapacity[regionId]!
364+
}
365+
353366
getOverCapacityCost(): number {
354367
// A simple path visits at most one region and one boundary per graph hop.
355368
// This makes one overflow more expensive than any capacity-respecting path.
356369
return this.regionGraph.regionCount * this.MM_COST_FOR_FULL_REGION * 2
357370
}
358371

359372
hasOverloadedResources(): boolean {
373+
if (!this.USE_TOPOLOGY_CAPACITY) return false
374+
360375
for (let regionId = 0; regionId < this.regionGraph.regionCount; regionId++) {
361376
if (
362-
this.state.regionUsage[regionId] >
363-
this.regionGraph.regionCapacity[regionId]
377+
this.state.regionUsage[regionId] > this.getRegionCapacity(regionId)
364378
) {
365379
return true
366380
}
@@ -377,7 +391,7 @@ export class RegionPathSolver extends BaseSolver {
377391
for (let regionId = 0; regionId < regionGraph.regionCount; regionId++) {
378392
const overflow = Math.max(
379393
0,
380-
state.regionUsage[regionId] - regionGraph.regionCapacity[regionId],
394+
state.regionUsage[regionId] - this.getRegionCapacity(regionId),
381395
)
382396
state.regionHistoricalCost[regionId] += overflow * overCapacityCost
383397
}
@@ -477,7 +491,7 @@ export class RegionPathSolver extends BaseSolver {
477491

478492
for (let regionId = 0; regionId < regionGraph.regionCount; regionId++) {
479493
const usage = state.regionUsage[regionId]
480-
const utilization = usage / regionGraph.regionCapacity[regionId]
494+
const utilization = usage / this.getRegionCapacity(regionId)
481495
maxRegionUsage = Math.max(maxRegionUsage, usage)
482496
maxUtilization = Math.max(maxUtilization, utilization)
483497
}

lib/region-graph/visualizeRegionGraph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const getRegionFill = (
165165
regionId: RegionId,
166166
) => {
167167
const regionUsage = usage.regionUsage[regionId]
168-
const capacity = solver.regionGraph.regionCapacity[regionId]
168+
const capacity = solver.getRegionCapacity(regionId)
169169
const utilization = clamp01(regionUsage / capacity)
170170
const red = Math.round(216 + (239 - 216) * utilization)
171171
const green = Math.round(240 - 112 * utilization)
@@ -181,7 +181,7 @@ const getRegionLabel = (
181181
regionId: RegionId,
182182
) => {
183183
const regionUsage = usage.regionUsage[regionId]
184-
const capacity = solver.regionGraph.regionCapacity[regionId]
184+
const capacity = solver.getRegionCapacity(regionId)
185185
const utilization = regionUsage / capacity
186186
const reservedNetId = solver.regionProblem.regionNetId[regionId]
187187
const assignedRoutes = solver.state.regionAssignedRoutes[regionId]
@@ -265,7 +265,7 @@ const pushSmallGraphRegionLabels = (
265265
{
266266
x: center.x,
267267
y: center.y,
268-
text: `${usage.regionUsage[regionId]}/${solver.regionGraph.regionCapacity[regionId]} nets`,
268+
text: `${usage.regionUsage[regionId]}/${solver.getRegionCapacity(regionId)} nets`,
269269
fontSize: 0.11,
270270
color: "rgb(15, 23, 42)",
271271
anchorSide: "center",

0 commit comments

Comments
 (0)