Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion lib/solvers/ChipPartitionsSolver/ChipPartitionsSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export class ChipPartitionsSolver extends BaseSolver {
}
}
// Only add a partition if there are at least two caps present in the inputProblem
if (capsOnly.length >= 2) {
// We disabled this to allow PlaceDecouplingCapsSolver to place them around the main chip
if (false) {
decapGroupPartitions.push(capsOnly)
// Mark these caps as handled by decoupling-cap partitions
for (const capId of capsOnly) {
Expand Down
23 changes: 23 additions & 0 deletions lib/solvers/LayoutPipelineSolver/LayoutPipelineSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { GraphicsObject } from "graphics-debug"
import { BaseSolver } from "lib/solvers/BaseSolver"
import { ChipPartitionsSolver } from "lib/solvers/ChipPartitionsSolver/ChipPartitionsSolver"
import { IdentifyDecouplingCapsSolver } from "lib/solvers/IdentifyDecouplingCapsSolver/IdentifyDecouplingCapsSolver"
import { PlaceDecouplingCapsSolver } from "lib/solvers/PlaceDecouplingCapsSolver/PlaceDecouplingCapsSolver"
import {
PackInnerPartitionsSolver,
type PackedPartition,
Expand Down Expand Up @@ -50,6 +51,7 @@ function definePipelineStep<

export class LayoutPipelineSolver extends BaseSolver {
identifyDecouplingCapsSolver?: IdentifyDecouplingCapsSolver
placeDecouplingCapsSolver?: PlaceDecouplingCapsSolver
chipPartitionsSolver?: ChipPartitionsSolver
packInnerPartitionsSolver?: PackInnerPartitionsSolver
partitionPackingSolver?: PartitionPackingSolver
Expand Down Expand Up @@ -77,6 +79,22 @@ export class LayoutPipelineSolver extends BaseSolver {
},
},
),
definePipelineStep(
"placeDecouplingCapsSolver",
PlaceDecouplingCapsSolver,
() => [
{
inputProblem: this.inputProblem,
decouplingCapGroups:
this.identifyDecouplingCapsSolver?.outputDecouplingCapGroups || [],
},
],
{
onSolved: (_layoutSolver) => {
// Decoupling caps placed around main chip
},
},
),
definePipelineStep(
"chipPartitionsSolver",
ChipPartitionsSolver,
Expand Down Expand Up @@ -196,6 +214,7 @@ export class LayoutPipelineSolver extends BaseSolver {

const identifyDecouplingCapsViz =
this.identifyDecouplingCapsSolver?.visualize()
const placeDecouplingCapsViz = this.placeDecouplingCapsSolver?.visualize()
const chipPartitionsViz = this.chipPartitionsSolver?.visualize()
const packInnerPartitionsViz = this.packInnerPartitionsSolver?.visualize()
const partitionPackingViz = this.partitionPackingSolver?.visualize()
Expand All @@ -207,6 +226,7 @@ export class LayoutPipelineSolver extends BaseSolver {
const visualizations = [
inputViz,
identifyDecouplingCapsViz,
placeDecouplingCapsViz,
chipPartitionsViz,
packInnerPartitionsViz,
partitionPackingViz,
Expand Down Expand Up @@ -262,6 +282,9 @@ export class LayoutPipelineSolver extends BaseSolver {
if (this.chipPartitionsSolver?.solved) {
return this.chipPartitionsSolver.visualize()
}
if (this.placeDecouplingCapsSolver?.solved) {
return this.placeDecouplingCapsSolver.visualize()
}
if (this.identifyDecouplingCapsSolver?.solved) {
return this.identifyDecouplingCapsSolver.visualize()
}
Expand Down
123 changes: 123 additions & 0 deletions lib/solvers/PlaceDecouplingCapsSolver/PlaceDecouplingCapsSolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { BaseSolver } from "../BaseSolver"
import type { InputProblem, ChipId, NetId, Chip } from "lib/types/InputProblem"
import type { DecouplingCapGroup } from "../IdentifyDecouplingCapsSolver/IdentifyDecouplingCapsSolver"
import type { GraphicsObject } from "graphics-debug"

export class PlaceDecouplingCapsSolver extends BaseSolver {
inputProblem: InputProblem
decouplingCapGroups: DecouplingCapGroup[]

constructor(params: {
inputProblem: InputProblem
decouplingCapGroups: DecouplingCapGroup[]
}) {
super()
this.inputProblem = params.inputProblem
this.decouplingCapGroups = params.decouplingCapGroups
}

override _step() {
// Determine placement for each decoupling capacitor
const GAP = 0.5
// To avoid overlapping caps on the same pin, keep track of how many caps we've placed per pin
const pinCapCount: Record<string, number> = {}

for (const group of this.decouplingCapGroups) {
const mainChip = this.inputProblem.chipMap[group.mainChipId]
if (!mainChip) continue

// Set the main chip to be fixed at 0,0 if it isn't already fixed
if (!mainChip.fixedPosition) {
mainChip.fixedPosition = { x: 0, y: 0 }
}

for (const capId of group.decouplingCapChipIds) {
const cap = this.inputProblem.chipMap[capId]
if (!cap) continue

// Find the pin on the main chip that this cap is strongly connected to
let connectedPinOnMainChip: string | null = null

for (const capPinId of cap.pins) {
for (const [connKey, isConnected] of Object.entries(
this.inputProblem.pinStrongConnMap,
)) {
if (!isConnected) continue
const [p1, p2] = connKey.split("-")
if (p1 === capPinId && p2?.startsWith(`${group.mainChipId}.`)) {
connectedPinOnMainChip = p2
break
}
if (p2 === capPinId && p1?.startsWith(`${group.mainChipId}.`)) {
connectedPinOnMainChip = p1
break
}
}
if (connectedPinOnMainChip) break
}

if (connectedPinOnMainChip) {
const mainPin = this.inputProblem.chipPinMap[connectedPinOnMainChip]
if (mainPin) {
const side = mainPin.side
const offset = mainPin.offset
const mainChipPos = mainChip.fixedPosition

pinCapCount[connectedPinOnMainChip] =
(pinCapCount[connectedPinOnMainChip] || 0) + 1
const count = pinCapCount[connectedPinOnMainChip]!
const shift = (count - 1) * (Math.max(cap.size.x, cap.size.y) + 0.2)

let capX = mainChipPos.x + offset.x
let capY = mainChipPos.y + offset.y
let rotation = 0

if (side === "x-") {
capX -= cap.size.x / 2 + GAP
capY += shift
} else if (side === "x+") {
capX += cap.size.x / 2 + GAP
capY += shift
} else if (side === "y+") {
capY += cap.size.y / 2 + GAP
capX += shift
rotation = 90
} else if (side === "y-") {
capY -= cap.size.y / 2 + GAP
capX += shift
rotation = 90
}

cap.fixedPosition = { x: capX, y: capY }
if (!cap.availableRotations) {
cap.availableRotations = [rotation as any]
} else {
cap.availableRotations = [rotation as any]
}
}
}
}
}

this.solved = true
}

override visualize(): GraphicsObject {
return {
points: [],
rects: [],
lines: [],
circles: [],
texts: [],
}
}

override getConstructorParams() {
return [
{
inputProblem: this.inputProblem,
decouplingCapGroups: this.decouplingCapGroups,
},
]
}
}
Loading
Loading