Skip to content

Commit

Permalink
Merge pull request #340 from aletempiac/acd_improvements
Browse files Browse the repository at this point in the history
Performance improvements to ACD
  • Loading branch information
alanminko authored Oct 21, 2024
2 parents a239dd8 + baf4ddb commit 498ec53
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
67 changes: 38 additions & 29 deletions src/map/if/acd/ac_decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class ac_decomposition_impl
pst->num_luts = best_multiplicity <= 2 ? 2 : best_multiplicity <= 4 ? 3
: best_multiplicity <= 8 ? 4
: 5;
pst->num_edges = ( pst->num_luts - 1 ) * ( num_vars - best_free_set ) + ( pst->num_luts - 1 ) + best_free_set;
}

return true;
Expand Down Expand Up @@ -510,8 +511,8 @@ class ac_decomposition_impl
}
} while ( combinations_offset_next( free_set_size, offset, pComb, pInvPerm, tt ) );

std::array<uint32_t, max_num_vars> res_perm = {0};
std::array<uint32_t, max_num_vars> res_perm;

if ( best_cost > ( 1 << ( ps.lut_size - free_set_size ) ) )
{
return std::make_tuple( local_best_tt, res_perm, UINT32_MAX );
Expand Down Expand Up @@ -543,7 +544,7 @@ class ac_decomposition_impl
}

/* enumerate combinations */
std::array<uint32_t, max_num_vars> res_perm = {0};
std::array<uint32_t, max_num_vars> res_perm;

do
{
Expand Down Expand Up @@ -803,31 +804,43 @@ class ac_decomposition_impl
}
}
support_minimization_encodings = std::vector<std::array<uint32_t, 2>>( num_combs );
generate_support_minimization_encodings_rec<false, true>( 0, 0, 0, count );
generate_support_minimization_encodings_rec<false, true>( 0, 0, 0, count, best_multiplicity >> 1, true );
assert( count == num_combs );
return;
}
else if ( best_multiplicity > 8 )

/* constraint the number of offset classes for a strict encoding */
int32_t min_set_size = 1;
if ( best_multiplicity <= 4 )
min_set_size = 2;
else if ( best_multiplicity <= 8 )
min_set_size = 4;
else
min_set_size = 8;
min_set_size = best_multiplicity - min_set_size;

if ( best_multiplicity > 8 )
{
/* combinations are 2^(mu - 1) */
num_combs = 1u << ( best_multiplicity - 1 );
/* distinct elements in 2 indistinct bins with at least `min_set_size` elements in the indistinct bins */
uint32_t class_sizes[13] = { 3, 3, 15, 25, 35, 35, 255, 501, 957, 1749, 3003, 4719, 6435 };
num_combs = class_sizes[best_multiplicity - 3];
support_minimization_encodings = std::vector<std::array<uint32_t, 2>>( num_combs );
generate_support_minimization_encodings_rec<false, false>( 0, 0, 0, count );
generate_support_minimization_encodings_rec<false, false>( 0, 0, 0, count, min_set_size, true );
}
else
{
/* combinations are 2*3^(mu - 1) */
for ( uint32_t i = 1; i < best_multiplicity; ++i )
{
num_combs = ( num_combs << 1 ) + num_combs;
}
/* distinct elements in 3 bins, of which 2 are indistinct, and with at least `min_set_size` elements in the indistinct bins */
uint32_t class_sizes[13] = { 6, 3, 90, 130, 105, 35, 9330, 23436, 48708, 78474, 91377, 70785, 32175 };
num_combs = class_sizes[best_multiplicity - 3];
support_minimization_encodings = std::vector<std::array<uint32_t, 2>>( num_combs );
generate_support_minimization_encodings_rec<true, false>( 0, 0, 0, count );
generate_support_minimization_encodings_rec<true, false>( 0, 0, 0, count, min_set_size, true );
}

assert( count == num_combs );
}

template<bool enable_dcset, bool equal_size_partition>
void generate_support_minimization_encodings_rec( uint32_t onset, uint32_t offset, uint32_t var, uint32_t& count )
void generate_support_minimization_encodings_rec( uint32_t onset, uint32_t offset, uint32_t var, uint32_t& count, int32_t min_set_size, bool first )
{
if ( var == best_multiplicity )
{
Expand All @@ -839,6 +852,11 @@ class ac_decomposition_impl
return;
}
}
else if ( __builtin_popcount( onset ) < min_set_size || __builtin_popcount( offset ) < min_set_size )
{
/* ON-set and OFF-set must be populated with at least min_set_size elements */
return;
}

support_minimization_encodings[count][0] = onset;
support_minimization_encodings[count][1] = offset;
Expand All @@ -849,23 +867,23 @@ class ac_decomposition_impl
/* var in DCSET */
if ( enable_dcset )
{
generate_support_minimization_encodings_rec<enable_dcset, equal_size_partition>( onset, offset, var + 1, count );
generate_support_minimization_encodings_rec<enable_dcset, equal_size_partition>( onset, offset, var + 1, count, min_set_size, first );
}

/* move var in ONSET */
onset |= 1 << var;
generate_support_minimization_encodings_rec<enable_dcset, equal_size_partition>( onset, offset, var + 1, count );
generate_support_minimization_encodings_rec<enable_dcset, equal_size_partition>( onset, offset, var + 1, count, min_set_size, false );
onset &= ~( 1 << var );

/* remove symmetries */
if ( var == 0 )
if ( first )
{
return;
}

/* move var in OFFSET */
offset |= 1 << var;
generate_support_minimization_encodings_rec<enable_dcset, equal_size_partition>( onset, offset, var + 1, count );
generate_support_minimization_encodings_rec<enable_dcset, equal_size_partition>( onset, offset, var + 1, count, min_set_size, false );
offset &= ~( 1 << var );
}

Expand Down Expand Up @@ -1016,15 +1034,6 @@ class ac_decomposition_impl
uint32_t const onset = support_minimization_encodings[i][0];
uint32_t const offset = support_minimization_encodings[i][1];

uint32_t ones_onset = __builtin_popcount( onset );
uint32_t ones_offset = __builtin_popcount( offset );

/* filter columns that do not distinguish pairs */
if ( ones_onset == 0 || ones_offset == 0 || ones_onset == best_multiplicity || ones_offset == best_multiplicity )
{
continue;
}

/* compute function and distinguishable seed dichotomies */
uint64_t column[2] = { 0, 0 };
STT tt;
Expand Down Expand Up @@ -1503,4 +1512,4 @@ class ac_decomposition_impl

ABC_NAMESPACE_CXX_HEADER_END

#endif // _ACD_H_
#endif // _ACD_H_
4 changes: 2 additions & 2 deletions src/map/if/acd/acdXX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ class acdXX_impl
: cost <= 32 ? 4
: 5;

if ( ss_vars_needed + free_set_size < 6 )
if ( ss_vars_needed + free_set_size < ps.lut_size )
{
/* look for a shared variable */
best_multiplicity = cost;
Expand Down Expand Up @@ -665,7 +665,7 @@ class acdXX_impl
: cost <= 32 ? 4
: 5;

if ( ss_vars_needed + free_set_size < 6 )
if ( ss_vars_needed + free_set_size < ps.lut_size )
{
/* look for a shared variable */
best_multiplicity = cost;
Expand Down

0 comments on commit 498ec53

Please sign in to comment.