From 8aa57c5d54bf7307c823d39fb9cc03a5e140dafb Mon Sep 17 00:00:00 2001 From: aletempiac Date: Thu, 16 Nov 2023 18:53:02 +0100 Subject: [PATCH] Decisions on late arrival --- src/acd/ac_decomposition.hpp | 46 +++++++++++++++++++++++++----------- src/acd/ac_wrapper.cpp | 3 ++- src/acd/ac_wrapper.h | 2 +- src/map/if/if.h | 2 +- src/map/if/ifDelay.c | 11 ++++----- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/acd/ac_decomposition.hpp b/src/acd/ac_decomposition.hpp index d59bf3d87..71caccff2 100644 --- a/src/acd/ac_decomposition.hpp +++ b/src/acd/ac_decomposition.hpp @@ -62,6 +62,9 @@ struct ac_decomposition_params /*! \brief Perform decomposition if support reducing. */ bool support_reducing_only{ true }; + + /*! \brief If decomposition with delay profile fails, ignore it. */ + bool try_no_late_arrival{ false }; }; /*! \brief Statistics for ac_decomposition */ @@ -157,28 +160,43 @@ public: } } - if ( best_multiplicity == UINT32_MAX ) + if ( best_multiplicity == UINT32_MAX && ( !ps.try_no_late_arrival || late_arriving == 0 ) ) return -1; - /* compute isets */ - // std::vector isets = compute_isets( free_set_size ); + /* try without the delay profile */ + if ( best_multiplicity == UINT32_MAX && ps.try_no_late_arrival ) + { + if ( ps.support_reducing_only ) + { + start = std::max( 1u, num_vars - ps.lut_size ); + } - // generate_support_minimization_encodings(); - // solve_min_support_exact( isets, free_set_size ); + for ( uint32_t i = start; i <= ps.lut_size - 1 && i <= 3; ++i ) + { + /* TODO: add shared set */ + auto evaluate_fn = [&]( STT const& tt ) { return column_multiplicity( tt, i ); }; + auto [tt_p, perm, cost] = enumerate_iset_combinations_offset( i, 0, evaluate_fn ); - /* unfeasible decomposition */ - // if ( best_bound_sets.empty() ) - // { - // return -1; - // } + /* additional cost if not support reducing */ + uint32_t additional_cost = ( num_vars - i > ps.lut_size ) ? 128 : 0; + /* check for feasible solution that improves the cost */ /* TODO: remove limit on cost */ + if ( cost <= ( 1 << ( ps.lut_size - i ) ) && cost + additional_cost < best_cost && cost < 10 ) + { + best_tt = tt_p; + permutations = perm; + best_multiplicity = cost; + best_cost = cost + additional_cost; + free_set_size = i; + } + } + } + + if ( best_multiplicity == UINT32_MAX ) + return -1; pst->num_luts = ps.lut_size - free_set_size; best_free_set = free_set_size; - /* TODO generate decomposition only when returning the result */ - // dec_result = generate_decomposition( free_set_size ); - - /* TODO: change return value */ return 0; } diff --git a/src/acd/ac_wrapper.cpp b/src/acd/ac_wrapper.cpp index aabe8e86f..821ab3f98 100644 --- a/src/acd/ac_wrapper.cpp +++ b/src/acd/ac_wrapper.cpp @@ -4,7 +4,7 @@ // ABC_NAMESPACE_IMPL_START -int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost ) +int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost, int try_no_late_arrival ) { using namespace mockturtle; @@ -17,6 +17,7 @@ int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, ac_decomposition_params ps; ps.lut_size = lutSize; + ps.try_no_late_arrival = static_cast( try_no_late_arrival ); ac_decomposition_stats st; ac_decomposition_impl acd( tt, nVars, ps, &st ); diff --git a/src/acd/ac_wrapper.h b/src/acd/ac_wrapper.h index cb22acf80..5e0af3787 100644 --- a/src/acd/ac_wrapper.h +++ b/src/acd/ac_wrapper.h @@ -12,7 +12,7 @@ extern "C" { #endif -int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost ); +int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost, int try_no_late_arrival ); int acd_decompose( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned char *decomposition ); #ifdef __cplusplus diff --git a/src/map/if/if.h b/src/map/if/if.h index 56f0bb7ed..05dc33949 100644 --- a/src/map/if/if.h +++ b/src/map/if/if.h @@ -700,7 +700,7 @@ extern int If_ManCountSpecialPos( If_Man_t * p ); extern void If_CutTraverse( If_Man_t * p, If_Obj_t * pRoot, If_Cut_t * pCut, Vec_Ptr_t * vNodes ); extern void If_ObjPrint( If_Obj_t * pObj ); -extern int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost ); +extern int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost, int try_no_late_arrival ); extern int acd_decompose( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned char *decomposition ); ABC_NAMESPACE_HEADER_END diff --git a/src/map/if/ifDelay.c b/src/map/if/ifDelay.c index fcd53e348..c1ecd7c08 100644 --- a/src/map/if/ifDelay.c +++ b/src/map/if/ifDelay.c @@ -471,12 +471,13 @@ int If_AcdEval( If_Man_t * p, If_Cut_t * pCut, int best_delay ) } /* remove from critical set */ - if ( !use_late_arrival ) + if ( !use_late_arrival && nLeafMax > LutSize / 2 ) + { uLeafMask = 0; + } - word *pTruth = If_CutTruthW( p, pCut ); - int val = acd_evaluate( pTruth, pCut->nLeaves, LutSize, &uLeafMask, &cost ); + int val = acd_evaluate( pTruth, pCut->nLeaves, LutSize, &uLeafMask, &cost, !use_late_arrival ); /* not feasible decomposition */ pCut->acdDelay = uLeafMask; @@ -507,10 +508,8 @@ int If_AcdReEval( If_Man_t * p, If_Cut_t * pCut ) } // int LutSize = p->pPars->pLutStruct[0] - '0'; - int LutSize = 6; int i, leaf_delay; - int DelayMax = -1, nLeafMax = 0; - unsigned uLeafMask = 0; + int DelayMax = -1; for ( i = 0; i < If_CutLeaveNum(pCut); i++ ) { leaf_delay = If_ObjCutBest(If_CutLeaf(p, pCut, i))->Delay;