Skip to content

Commit

Permalink
fix router bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulk29 committed Jan 2, 2024
1 parent 86c5219 commit 84acd2f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 31 deletions.
51 changes: 41 additions & 10 deletions libs/atoll/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ fn sorted2<T: PartialOrd>(a: T, b: T) -> (T, T) {
}

/// A fixed-size routing grid.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct RoutingState<L> {
pub(crate) grid: RoutingGrid<L>,
pub(crate) layers: Vec<Grid<PointState>>,
Expand Down Expand Up @@ -671,7 +671,7 @@ impl<L: AtollLayer + Clone> RoutingState<L> {
let (nx, ny) = layer.size();
for x in 0..nx {
for y in 0..ny {
if layer[(nx, ny)] == (PointState::Routed { net }) {
if layer[(x, y)] == (PointState::Routed { net }) {
return Some(GridCoord { layer: i, x, y });
}
}
Expand All @@ -688,6 +688,24 @@ impl<L: AtollLayer + Clone> RoutingState<L> {
}
}

#[inline]
pub(crate) fn is_available_for_net(&self, coord: GridCoord, net: NetId) -> bool {
match self[coord] {
PointState::Routed { net: grid_net } => self.roots[&net] == self.roots[&grid_net],

PointState::Available => true,
PointState::Blocked => false,
}
}

pub(crate) fn forms_new_connection_for_net(&self, coord: GridCoord, net: NetId) -> bool {
if let PointState::Routed { net: grid_net } = self[coord] {
self.roots[&net] == self.roots[&grid_net] && grid_net != net
} else {
false
}
}

/// The cost to traverse from `src` to `dst`.
///
/// Important: the two coordinates must be adjacent.
Expand All @@ -710,15 +728,18 @@ impl<L: AtollLayer + Clone> RoutingState<L> {
y: coord.y - 1,
..coord
};
let cost = self.cost(coord, next, net);
out.push((next, cost));
if self.is_available_for_net(next, net) {
out.push((next, self.cost(coord, next, net)));
}
}
if coord.y < layer.size().1 - 1 {
let next = GridCoord {
y: coord.y + 1,
..coord
};
out.push((next, self.cost(coord, next, net)));
if self.is_available_for_net(next, net) {
out.push((next, self.cost(coord, next, net)));
}
}
}

Expand All @@ -729,15 +750,18 @@ impl<L: AtollLayer + Clone> RoutingState<L> {
x: coord.x - 1,
..coord
};
let cost = self.cost(coord, next, net);
out.push((next, cost));
if self.is_available_for_net(next, net) {
out.push((next, self.cost(coord, next, net)));
}
}
if coord.x < layer.size().0 - 1 {
let next = GridCoord {
x: coord.x + 1,
..coord
};
out.push((next, self.cost(coord, next, net)));
if self.is_available_for_net(next, net) {
out.push((next, self.cost(coord, next, net)));
}
}
}

Expand Down Expand Up @@ -786,6 +810,7 @@ impl<L: AtollLayer + Clone> RoutingState<L> {
let up = self
.grid
.point_to_grid(pp, next_layer, RoundingMode::Up, RoundingMode::Up);
println!("coord = {coord:?}, pp = {pp:?}, dn = {dn:?}, up = {up:?}");
assert_eq!(dn.coord(!interp_dir), coord.coord(!interp_dir) as i64);
assert_eq!(up.coord(!interp_dir), coord.coord(!interp_dir) as i64);
assert!(dn.x >= 0 && dn.y >= 0);
Expand All @@ -796,7 +821,10 @@ impl<L: AtollLayer + Clone> RoutingState<L> {
x: dn.x as usize,
y: dn.y as usize,
};
successors.push((next, self.cost(coord, next, net)));
if self.is_available_for_net(next, net) {
println!("via up");
successors.push((next, self.cost(coord, next, net)));
}
}
}

Expand All @@ -821,7 +849,10 @@ impl<L: AtollLayer + Clone> RoutingState<L> {
x: dn.x as usize,
y: dn.y as usize,
};
successors.push((next, self.cost(coord, next, net)));
if self.is_available_for_net(next, net) {
println!("via down");
successors.push((next, self.cost(coord, next, net)));
}
}
}

Expand Down
31 changes: 15 additions & 16 deletions libs/atoll/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct GreedyBfsRouter;

impl Router for GreedyBfsRouter {
fn route(&self, mut state: RoutingState<PdkLayer>, to_connect: Vec<Vec<NetId>>) -> Vec<Path> {
println!("state = {state:?}, to_connect = {to_connect:?}");
// build roots map
let mut roots = HashMap::new();
for seq in to_connect.iter() {
Expand All @@ -29,32 +30,30 @@ impl Router for GreedyBfsRouter {
}
state.roots = roots;

let mut paths = Vec::new();
for group in to_connect.iter() {
for node in group.iter().skip(1) {
let start = state.find(*node).unwrap();
let start = match state.find(*node) {
Some(c) => c,
None => {
println!("no starting point found for {node:?}; skipping");
continue;
}
};
let (path, _) = dijkstra(
&start,
|s| state.successors(*s, *node),
|s| state.is_routed_for_net(*s, *node),
|s| state.forms_new_connection_for_net(*s, *node),
)
.expect("no path found");
for coord in path {
state[coord] = PointState::Routed { net: *node };
for coord in path.iter() {
state[*coord] = PointState::Routed { net: *node };
}
paths.push(path);
}
}

vec![vec![
GridCoord {
layer: 0,
x: 0,
y: 0,
},
GridCoord {
layer: 0,
x: 0,
y: 4,
},
]]
println!("paths = {paths:?}");
paths
}
}
7 changes: 2 additions & 5 deletions substrate/src/layout/tracks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Routing track management.
use geometry::span::Span;
use num::integer::div_floor;
use num::integer::{div_ceil, div_floor};
use serde::{Deserialize, Serialize};

/// A uniform set of tracks.
Expand Down Expand Up @@ -71,10 +71,7 @@ impl UniformTracks {
pub fn to_track_idx(&self, coord: i64, mode: RoundingMode) -> i64 {
match mode {
RoundingMode::Down => div_floor(coord - self.offset + self.line / 2, self.pitch()),
RoundingMode::Up => div_floor(
coord - self.offset + self.pitch() - 1 + self.line / 2,
self.pitch(),
),
RoundingMode::Up => div_ceil(coord - self.offset - self.line / 2, self.pitch()),
RoundingMode::Nearest => div_floor(
coord - self.offset + self.pitch() / 2 + self.line / 2,
self.pitch(),
Expand Down

0 comments on commit 84acd2f

Please sign in to comment.