Skip to content

Commit

Permalink
Scale HPLW cost function by sqrt(n).
Browse files Browse the repository at this point in the history
The HPWL cost function under-estimates net cost for nets with fan-out greater
than 3. The error grows at a rate proportional to sqrt(n). By scaling the cost
by this amount, the error is reduced for larger-fan-out nets.
  • Loading branch information
mossblaser committed Jun 16, 2016
1 parent 9b72217 commit e6cbcf6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The C library is tested using using the
[check](http://libcheck.github.io/check/) library. The test suite can be built
using the following command:

$ gcc -std=c99 -g -o run_tests -Irig_c_sa tests/*.c rig_c_sa/*.c -lm $(pkg-config --cflags --libs check)
$ gcc -std=c99 -g -o run_tests -Irig_c_sa tests/*.c rig_c_sa/sa.c -lm $(pkg-config --cflags --libs check)

The test suite should then be run under valgrind to ensure any memory leaks are found:

Expand Down
4 changes: 2 additions & 2 deletions rig_c_sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ double sa_get_net_cost(sa_state_t *state, sa_net_t *net) {
// From this we can work out the bounding box size and thus the HPWL.
bbox_width = (int)state->width - max_delta_x;
bbox_height = (int)state->height - max_delta_y;
return (bbox_width + bbox_height) * net->weight;
return sqrt(net->num_vertices) * (bbox_width + bbox_height) * net->weight;
} else {
// Non-toriodal network: Compute bounding box
min_x = net->vertices[0]->x;
Expand All @@ -550,7 +550,7 @@ double sa_get_net_cost(sa_state_t *state, sa_net_t *net) {
}

// Compute weighted HPWL
return ((max_x - min_x) + (max_y - min_y)) * net->weight;
return sqrt(net->num_vertices) * ((max_x - min_x) + (max_y - min_y)) * net->weight;
}
}

Expand Down
23 changes: 12 additions & 11 deletions tests/test_sa_algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ START_TEST (test_get_net_cost)

// Without wrap-around we have a 17x8 boundingbox at weight 2.0.
s->has_wrap_around_links = false;
ck_assert_msg(sa_get_net_cost(s, n) == (17.0 + 8.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), (17.0 + 8.0) * 2.0);
ck_assert_msg(sa_get_net_cost(s, n) == sqrt(4) * (17.0 + 8.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), sqrt(4) * (17.0 + 8.0) * 2.0);

// With wrap-around the bounding box wraps giving a 8x4 bounding box at
// weight 2.0
s->has_wrap_around_links = true;
ck_assert_msg(sa_get_net_cost(s, n) == (8.0 + 4.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), (8.0 + 4.0) * 2.0);
ck_assert_msg(sa_get_net_cost(s, n) == sqrt(4) * (8.0 + 4.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), sqrt(4) * (8.0 + 4.0) * 2.0);

/* Set alternative vertex positions. Note that:
* * The wrapping and non-wrapping bounding box is the same
Expand All @@ -153,11 +153,11 @@ START_TEST (test_get_net_cost)

// Without wrap-around we have a 2x2 boundingbox at weight 2.0.
s->has_wrap_around_links = false;
ck_assert_msg(sa_get_net_cost(s, n) == (2.0 + 2.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), (2.0 + 2.0) * 2.0);
ck_assert_msg(sa_get_net_cost(s, n) == sqrt(4) * (2.0 + 2.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), sqrt(4) * (2.0 + 2.0) * 2.0);
s->has_wrap_around_links = true;
ck_assert_msg(sa_get_net_cost(s, n) == (2.0 + 2.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), (2.0 + 2.0) * 2.0);
ck_assert_msg(sa_get_net_cost(s, n) == sqrt(4) * (2.0 + 2.0) * 2.0,
"%f != %f", sa_get_net_cost(s, n), sqrt(4) * (2.0 + 2.0) * 2.0);

sa_free(s);
}
Expand Down Expand Up @@ -207,7 +207,8 @@ START_TEST (test_get_swap_cost)

// Nets x and y should have their cost reduced by 1 for a total cost saving
// of 2.
ck_assert(sa_get_swap_cost(s, 0, 0, va, 1, 0, vb) == -2.0);
double swap_cost = sa_get_swap_cost(s, 0, 0, va, 1, 0, vb);
ck_assert(abs(swap_cost - (sqrt(2) * -2.0)) < 0.001);

sa_free(s);
}
Expand Down Expand Up @@ -344,7 +345,7 @@ START_TEST (test_step_bad_cost)
num_swapped++;

// Cost should have increased
ck_assert(cost == 1.0);
ck_assert(cost == sqrt(2) * 1.0);

// Vertices should have moved
ck_assert(sa_get_chip_vertex(s, 0, 0) == NULL);
Expand Down Expand Up @@ -451,7 +452,7 @@ START_TEST (test_run_steps)
ck_assert(cost_delta_sd < 1.0);

// The cost change overall should drop from 6 to 1.
ck_assert_msg(cost_delta == -5.0, "%f == %f", cost_delta, -5.0);
ck_assert_msg(abs(cost_delta - (sqrt(2) * -5.0)) < 0.001, "%f == %f", cost_delta, sqrt(2) * -5.0);

sa_free(s);
}
Expand Down

0 comments on commit e6cbcf6

Please sign in to comment.