Now we use the ace from VTR

This commit is contained in:
tangxifan 2019-07-16 17:00:09 -06:00
parent 954a8c14f7
commit d6dfc29508
6 changed files with 75 additions and 67 deletions

View File

@ -1,3 +1,6 @@
#include "vtr_assert.h"
#include "vtr_time.h" //For some reason this causes compilation errors if included below the std headers on with g++-5
#include "vtr_assert.h"
#include <stdio.h>
#include <inttypes.h>
@ -50,8 +53,7 @@ void print_status(Abc_Ntk_t * ntk) {
printf("%d: OLD\n", i);
break;
default:
printf("Invalid ABC object info status");
exit(1);
VTR_ASSERT_MSG(false, "Invalid ABC object info status");
}
}
}
@ -169,11 +171,11 @@ int ace_calc_activity(Abc_Ntk_t * ntk, int num_vectors, char * clk_name) {
{
info = Ace_ObjInfo(obj);
if (strcmp(Abc_ObjName(obj), clk_name) != 0) {
assert(info->static_prob >= 0 && info->static_prob <= 1.0);
assert(info->switch_prob >= 0 && info->switch_prob <= 1.0);
assert(info->switch_act >= 0 && info->switch_act <= 1.0);
assert(info->switch_prob <= 2.0 * (1.0 - info->static_prob));
assert(info->switch_prob <= 2.0 * info->static_prob);
VTR_ASSERT(info->static_prob >= 0 && info->static_prob <= 1.0);
VTR_ASSERT(info->switch_prob >= 0 && info->switch_prob <= 1.0);
VTR_ASSERT(info->switch_act >= 0 && info->switch_act <= 1.0);
VTR_ASSERT(info->switch_prob <= 2.0 * (1.0 - info->static_prob));
VTR_ASSERT(info->switch_prob <= 2.0 * info->static_prob);
}
info->status = ACE_DEF;
}
@ -233,11 +235,11 @@ int ace_calc_activity(Abc_Ntk_t * ntk, int num_vectors, char * clk_name) {
Ace_Obj_Info_t * info2 = Ace_ObjInfo(obj);
info2->switch_act = info2->switch_prob;
assert(info2->switch_act >= 0.0);
VTR_ASSERT(info2->switch_act >= 0.0);
}
Abc_NtkForEachPi(ntk, obj, i)
{
assert(Ace_ObjInfo(obj)->switch_act >= 0.0);
VTR_ASSERT(Ace_ObjInfo(obj)->switch_act >= 0.0);
}
/*------------- Calculate switching activities. ---------------------*/
@ -275,7 +277,7 @@ int ace_calc_activity(Abc_Ntk_t * ntk, int num_vectors, char * clk_name) {
Ace_Obj_Info_t * info2 = Ace_ObjInfo(obj);
//Ace_Obj_Info_t * fanin_info2;
assert(Abc_ObjType(obj) == ABC_OBJ_NODE);
VTR_ASSERT(Abc_ObjType(obj) == ABC_OBJ_NODE);
if (Abc_ObjFaninNum(obj) < 1) {
info2->switch_act = 0.0;
@ -284,7 +286,7 @@ int ace_calc_activity(Abc_Ntk_t * ntk, int num_vectors, char * clk_name) {
Vec_Ptr_t * literals = Vec_PtrAlloc(0);
Abc_Obj_t * fanin;
assert(obj->Type == ABC_OBJ_NODE);
VTR_ASSERT(obj->Type == ABC_OBJ_NODE);
Abc_ObjForEachFanin(obj, fanin, j)
{
@ -294,7 +296,7 @@ int ace_calc_activity(Abc_Ntk_t * ntk, int num_vectors, char * clk_name) {
literals);
Vec_PtrFree(literals);
}
assert(info2->switch_act >= 0);
VTR_ASSERT(info2->switch_act >= 0);
}
Vec_PtrFree(nodes_logic);
Vec_PtrFree(latches_in_cycles_vec);
@ -308,21 +310,22 @@ Ace_Obj_Info_t * Ace_ObjInfo(Abc_Obj_t * obj) {
if (st__lookup(ace_info_hash_table, (char *) obj, (char **) &info)) {
return info;
}
assert(0);
VTR_ASSERT(0);
return NULL;
}
void prob_epsilon_fix(double * d) {
if (*d < 0) {
assert(*d > 0 - EPSILON);
VTR_ASSERT(*d > 0 - EPSILON);
*d = 0;
} else if (*d > 1) {
assert(*d < 1 + EPSILON);
VTR_ASSERT(*d < 1 + EPSILON);
*d = 1.;
}
}
int main(int argc, char * argv[]) {
vtr::ScopedFinishTimer t("Ace");
FILE * BLIF = NULL;
FILE * IN_ACT = NULL;
FILE * OUT_ACT = stdout;
@ -351,7 +354,7 @@ int main(int argc, char * argv[]) {
ntk = Io_Read(blif_file_name, IO_FILE_BLIF, 1, 0);
assert(ntk);
VTR_ASSERT(ntk);
printf("Objects in network: %d\n", Abc_NtkObjNum(ntk));
printf("PIs in network: %d\n", Abc_NtkPiNum(ntk));
@ -383,7 +386,7 @@ int main(int argc, char * argv[]) {
// Check Depth
depth = ace_calc_network_depth(ntk);
printf("Max Depth: %d\n", depth);
assert(depth > 0);
VTR_ASSERT(depth > 0);
alloc_and_init_activity_info(ntk);

View File

@ -1,5 +1,7 @@
#include <inttypes.h>
#include "vtr_assert.h"
#include "ace.h"
#include "misc/vec/vecPtr.h"
#include "bdd.h"
@ -86,7 +88,7 @@ int ace_bdd_build_network_bdds(
int i;
Vec_Ptr_t * nodes;
assert(Vec_PtrSize(inputs) > 0);
VTR_ASSERT(Vec_PtrSize(inputs) > 0);
nodes = Abc_NtkDfsSeq(ntk);
@ -111,8 +113,8 @@ int ace_bdd_build_network_bdds(
switch (info->status)
{
case ACE_SIM:
assert (info->static_prob >= 0.0 && info->static_prob <= 1.0);
assert (info->switch_prob >= 0.0 && info->switch_prob <= 1.0);
VTR_ASSERT (info->static_prob >= 0.0 && info->static_prob <= 1.0);
VTR_ASSERT (info->switch_prob >= 0.0 && info->switch_prob <= 1.0);
if (!st_lookup(leaves, (char*) obj, NULL))
{
@ -128,7 +130,7 @@ int ace_bdd_build_network_bdds(
break;
case ACE_UNDEF:
assert(0);
VTR_ASSERT(0);
if (check_pi_status(obj))
{
while(1)
@ -149,14 +151,14 @@ int ace_bdd_build_network_bdds(
break;
case ACE_DEF:
assert(info->static_prob >= 0 && info->static_prob <= 1.0);
assert(info->switch_prob >= 0 && info->switch_prob <= 1.0);
VTR_ASSERT(info->static_prob >= 0 && info->static_prob <= 1.0);
VTR_ASSERT(info->switch_prob >= 0 && info->switch_prob <= 1.0);
break;
case ACE_NEW:
case ACE_OLD:
default:
assert(0);
VTR_ASSERT(0);
}
}
@ -192,7 +194,7 @@ double calc_cube_switch_prob_recur(DdManager * mgr, DdNode * bdd,
}
/* Get literal index for this bdd node. */
//assert(0);
//VTR_ASSERT(0);
i = Cudd_Regular(bdd)->index;
pi = (Abc_Obj_t*) Vec_PtrEntry((Vec_Ptr_t*) inputs, i);
@ -210,11 +212,11 @@ double calc_cube_switch_prob_recur(DdManager * mgr, DdNode * bdd,
then_prob = calc_cube_switch_prob_recur(mgr, bdd_if1, cube, inputs, visited,
phase);
assert(then_prob + EPSILON >= 0 && then_prob - EPSILON <= 1);
VTR_ASSERT(then_prob + EPSILON >= 0 && then_prob - EPSILON <= 1);
else_prob = calc_cube_switch_prob_recur(mgr, bdd_if0, cube, inputs, visited,
phase);
assert(else_prob + EPSILON >= 0 && else_prob - EPSILON <= 1);
VTR_ASSERT(else_prob + EPSILON >= 0 && else_prob - EPSILON <= 1);
switch (node_get_literal (cube->cube, i)) {
case ZERO:
@ -235,7 +237,7 @@ double calc_cube_switch_prob_recur(DdManager * mgr, DdNode * bdd,
st__insert(visited, (char *) bdd, (char *) current_prob);
assert(*current_prob + EPSILON >= 0 && *current_prob - EPSILON < 1.0);
VTR_ASSERT(*current_prob + EPSILON >= 0 && *current_prob - EPSILON < 1.0);
return (*current_prob);
}
@ -250,7 +252,7 @@ double calc_cube_switch_prob(DdManager * mgr, DdNode * bdd, ace_cube_t * cube,
st__free_table(visited);
assert(sp + EPSILON >= 0. && sp - EPSILON <= 1.0);
VTR_ASSERT(sp + EPSILON >= 0. && sp - EPSILON <= 1.0);
return (sp);
}
@ -264,9 +266,9 @@ double calc_switch_prob_recur(DdManager * mgr, DdNode * bdd_next, DdNode * bdd,
ace_cube_t * cube0, *cube1;
Ace_Obj_Info_t * info;
assert(inputs != NULL);
assert(Vec_PtrSize(inputs) > 0);
assert(P1 >= 0);
VTR_ASSERT(inputs != NULL);
VTR_ASSERT(Vec_PtrSize(inputs) > 0);
VTR_ASSERT(P1 >= 0);
if (bdd == Cudd_ReadLogicZero(mgr)) {
if (phase != 1)
@ -274,7 +276,7 @@ double calc_switch_prob_recur(DdManager * mgr, DdNode * bdd_next, DdNode * bdd,
prob = calc_cube_switch_prob(mgr, bdd_next, cube, inputs, phase);
prob *= P1;
assert(prob + EPSILON >= 0. && prob - EPSILON <= 1.);
VTR_ASSERT(prob + EPSILON >= 0. && prob - EPSILON <= 1.);
return (prob * P1);
} else if (bdd == Cudd_ReadOne(mgr)) {
if (phase != 0)
@ -282,7 +284,7 @@ double calc_switch_prob_recur(DdManager * mgr, DdNode * bdd_next, DdNode * bdd,
prob = calc_cube_switch_prob(mgr, bdd_next, cube, inputs, phase);
prob *= P1;
assert(prob + EPSILON >= 0. && prob - EPSILON <= 1.);
VTR_ASSERT(prob + EPSILON >= 0. && prob - EPSILON <= 1.);
return (prob * P1);
}
@ -315,8 +317,8 @@ double calc_switch_prob_recur(DdManager * mgr, DdNode * bdd_next, DdNode * bdd,
inputs, P1 * (1.0 - info->static_prob), phase);
ace_cube_free(cube0);
assert(switch_prob_t + EPSILON >= 0. && switch_prob_t - EPSILON <= 1.);
assert(switch_prob_e + EPSILON >= 0. && switch_prob_e - EPSILON <= 1.);
VTR_ASSERT(switch_prob_t + EPSILON >= 0. && switch_prob_t - EPSILON <= 1.);
VTR_ASSERT(switch_prob_e + EPSILON >= 0. && switch_prob_e - EPSILON <= 1.);
return (switch_prob_t + switch_prob_e);
}
@ -333,7 +335,7 @@ double ace_bdd_calc_switch_act(DdManager * mgr, Abc_Obj_t * obj,
DdNode * bdd;
d = info->depth;
assert(d > 0);
VTR_ASSERT(d > 0);
d = (int) d * 0.4;
if (d < 1) {
d = 1;
@ -361,10 +363,10 @@ double ace_bdd_calc_switch_act(DdManager * mgr, Abc_Obj_t * obj,
prob_epsilon_fix(&fanin_info->prob0to1);
prob_epsilon_fix(&fanin_info->prob1to0);
assert(
VTR_ASSERT(
fanin_info->prob0to1 + EPSILON >= 0.
&& fanin_info->prob0to1 - EPSILON <= 1.0);
assert(
VTR_ASSERT(
fanin_info->prob1to0 + EPSILON >= 0.
&& fanin_info->prob1to0 - EPSILON <= 1.0);
}

View File

@ -1,3 +1,4 @@
#include "vtr_assert.h"
#include "cube.h"
#include "bdd.h"
@ -16,8 +17,8 @@ ace_cube_t * ace_cube_dup(ace_cube_t * cube) {
int i;
ace_cube_t * cube_copy;
assert(cube != NULL);
assert(cube->num_literals > 0);
VTR_ASSERT(cube != NULL);
VTR_ASSERT(cube->num_literals > 0);
cube_copy = (ace_cube_t*) malloc(sizeof(ace_cube_t));
cube_copy->static_prob = cube->static_prob;
@ -63,8 +64,8 @@ ace_cube_t * ace_cube_new_dc(int num_literals) {
}
void ace_cube_free(ace_cube_t * cube) {
assert(cube != NULL);
assert(cube->cube != NULL);
VTR_ASSERT(cube != NULL);
VTR_ASSERT(cube->cube != NULL);
free(cube->cube);
free(cube);
}

View File

@ -1,3 +1,4 @@
#include "vtr_assert.h"
#include "cycle.h"
#include "ace.h"
@ -28,7 +29,7 @@ bool in_cycle(Abc_Ntk_t * ntk, int obj_id_to_find, Abc_Obj_t * starting_obj_ptr,
{
// Get BI of latch
fanin_ptr = Abc_ObjFanin0(Abc_ObjFanin0(starting_obj_ptr));
assert(fanin_ptr);
VTR_ASSERT(fanin_ptr);
return (in_cycle(ntk, obj_id_to_find, fanin_ptr, flag));
}

View File

@ -71,7 +71,7 @@ void ace_io_print_activity(Abc_Ntk_t * ntk, FILE * fp) {
default:
//printf("Unkown Type: %d\n", Abc_ObjType(obj));
//assert(0);
//VTR_ASSERT(0);
break;
}
@ -237,10 +237,10 @@ int ace_io_read_activity(Abc_Ntk_t * ntk, FILE * in_file_desc,
printf("Cannot open input file\n");
error = ACE_ERROR;
} else {
assert(p >= 0.0 && p <= 1.0);
assert(d >= 0.0 && d <= 1.0);
assert(d <= 2.0 * p);
assert(d <= 2.0 * (1.0 - p));
VTR_ASSERT(p >= 0.0 && p <= 1.0);
VTR_ASSERT(d >= 0.0 && d <= 1.0);
VTR_ASSERT(d <= 2.0 * p);
VTR_ASSERT(d <= 2.0 * (1.0 - p));
Abc_NtkForEachPi(ntk, obj_ptr, i)
{
@ -285,8 +285,8 @@ int ace_io_read_activity(Abc_Ntk_t * ntk, FILE * in_file_desc,
}
pi_obj_ptr = Abc_NtkObj(ntk, pi_obj_id);
assert(static_prob >= 0.0 && static_prob <= 1.0);
assert(switch_prob >= 0.0 && switch_prob <= 1.0);
VTR_ASSERT(static_prob >= 0.0 && static_prob <= 1.0);
VTR_ASSERT(switch_prob >= 0.0 && switch_prob <= 1.0);
info = Ace_ObjInfo(pi_obj_ptr);
info->static_prob = static_prob;
@ -338,7 +338,7 @@ int ace_io_read_activity(Abc_Ntk_t * ntk, FILE * in_file_desc,
error = ACE_ERROR;
break;
}
assert(strlen(vector) == num_Pi);
VTR_ASSERT(strlen(vector) == num_Pi);
if (num_vec == 0) {
Abc_NtkForEachPi(ntk, obj_ptr, i)
@ -373,7 +373,7 @@ int ace_io_read_activity(Abc_Ntk_t * ntk, FILE * in_file_desc,
if (!error) {
Abc_NtkForEachPi(ntk, obj_ptr, i)
{
assert(num_vec > 0);
VTR_ASSERT(num_vec > 0);
info = Ace_ObjInfo(obj_ptr);
info->static_prob = (double) high[i] / (double) num_vec;

View File

@ -1,3 +1,4 @@
#include "vtr_assert.h"
#include "ace.h"
#include "sim.h"
@ -60,7 +61,7 @@ void get_pi_values(Abc_Ntk_t * ntk, Vec_Ptr_t * /*nodes*/, int cycle) {
default:
printf("Bad Value\n");
assert(0);
VTR_ASSERT(0);
break;
}
}
@ -111,7 +112,7 @@ void get_pi_values(Abc_Ntk_t * ntk, Vec_Ptr_t * /*nodes*/, int cycle) {
default:
printf("Bad value\n");
assert(FALSE);
VTR_ASSERT(FALSE);
break;
}
}
@ -131,7 +132,7 @@ int * getFaninValues(Abc_Obj_t * obj_ptr) {
info = Ace_ObjInfo(fanin);
if (info->status == ACE_UNDEF) {
printf("Fan-in is undefined\n");
assert(FALSE);
VTR_ASSERT(FALSE);
} else if (info->status == ACE_NEW) {
break;
}
@ -210,15 +211,15 @@ void evaluate_circuit(Abc_Ntk_t * ntk, Vec_Ptr_t * node_vec, int /*cycle*/) {
case ACE_NEW:
if (Abc_ObjIsNode(obj)) {
faninValues = getFaninValues(obj);
assert(faninValues);
VTR_ASSERT(faninValues);
dd_node = Cudd_Eval((DdManager*) ntk->pManFunc, (DdNode*) obj->pData, faninValues);
assert(Cudd_IsConstant(dd_node));
VTR_ASSERT(Cudd_IsConstant(dd_node));
if (dd_node == Cudd_ReadOne((DdManager*) ntk->pManFunc)) {
value = 1;
} else if (dd_node == Cudd_ReadLogicZero((DdManager*) ntk->pManFunc)) {
value = 0;
} else {
assert(0);
VTR_ASSERT(0);
}
free(faninValues);
} else {
@ -240,12 +241,12 @@ void evaluate_circuit(Abc_Ntk_t * ntk, Vec_Ptr_t * node_vec, int /*cycle*/) {
info->num_ones += info->value;
break;
default:
assert(0);
VTR_ASSERT(0);
break;
}
break;
default:
assert(0);
VTR_ASSERT(0);
break;
}
}
@ -294,8 +295,8 @@ void ace_sim_activities(Abc_Ntk_t * ntk, Vec_Ptr_t * nodes, int max_cycles,
Ace_Obj_Info_t * info;
int i;
assert(max_cycles > 0);
assert(threshold > 0.0);
VTR_ASSERT(max_cycles > 0);
VTR_ASSERT(threshold > 0.0);
// srand((unsigned) time(NULL));
@ -326,12 +327,12 @@ void ace_sim_activities(Abc_Ntk_t * ntk, Vec_Ptr_t * nodes, int max_cycles,
{
info = Ace_ObjInfo(obj);
info->static_prob = info->num_ones / (double) max_cycles;
assert(info->static_prob >= 0.0 && info->static_prob <= 1.0);
VTR_ASSERT(info->static_prob >= 0.0 && info->static_prob <= 1.0);
info->switch_prob = info->num_toggles / (double) max_cycles;
assert(info->switch_prob >= 0.0 && info->switch_prob <= 1.0);
VTR_ASSERT(info->switch_prob >= 0.0 && info->switch_prob <= 1.0);
assert(info->switch_prob - EPSILON <= 2.0 * (1.0 - info->static_prob));
assert(info->switch_prob - EPSILON <= 2.0 * (info->static_prob));
VTR_ASSERT(info->switch_prob - EPSILON <= 2.0 * (1.0 - info->static_prob));
VTR_ASSERT(info->switch_prob - EPSILON <= 2.0 * (info->static_prob));
info->status = ACE_SIM;
}