Skip to content

Commit

Permalink
Reinstate sanity check in bli_pool_finalize. (#671)
Browse files Browse the repository at this point in the history
Details:
- Added a reinit argument to bli_pool_finalize(). This bool will signal
  whether or not the function is being called from bli_pool_reinit(). If
  it is not being called from _reinit(), we can safely check to confirm 
  that .top_index == 0 (i.e., all blocks have been checked in). But if 
  it *is* being called from _reinit(), then that check will be skipped
  since one of the predicted use cases for bli_pool_reinit() anticipates
  that some blocks are (probably) checked out when the pool_t is
  reinitialized.
- Updated existing invocations of bli_pool_finalize() to pass in either
  FALSE (from bli_apool_free_block() or bli_pba_finalize_pools()) or
  TRUE (from bli_pool_reinit()) for the new reinit argument.
  • Loading branch information
devinamatthews authored Oct 3, 2022
1 parent 63470b4 commit 76a23bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion frame/base/bli_apool.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void bli_apool_free_block
if ( pool != NULL )
{
// Finalize the pool.
bli_pool_finalize( pool );
bli_pool_finalize( pool, FALSE );

#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_apool_free_block(): pool_t %d: ", ( int )i );
Expand Down
6 changes: 3 additions & 3 deletions frame/base/bli_pba.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ void bli_pba_finalize_pools
pool_t* pool_c = bli_pba_pool( index_c, pba );

// Finalize the memory pools for A, B, and C.
bli_pool_finalize( pool_a );
bli_pool_finalize( pool_b );
bli_pool_finalize( pool_c );
bli_pool_finalize( pool_a, FALSE );
bli_pool_finalize( pool_b, FALSE );
bli_pool_finalize( pool_c, FALSE );
}

// -----------------------------------------------------------------------------
Expand Down
22 changes: 9 additions & 13 deletions frame/base/bli_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ void bli_pool_init

void bli_pool_finalize
(
pool_t* pool
pool_t* pool,
bool reinit
)
{
// NOTE: This implementation assumes that either:
Expand All @@ -129,24 +130,22 @@ void bli_pool_finalize
// Query the total number of blocks currently allocated.
const siz_t num_blocks = bli_pool_num_blocks( pool );

// NOTE: This sanity check has been disabled because bli_pool_reinit()
// is currently implemented in terms of bli_pool_finalize() followed by
// bli_pool_init(). If that _reinit() takes place when some blocks are
// checked out, then we would expect top_index != 0, and therefore this
// check is not universally appropriate.
#if 0
// Query the top_index of the pool.
const siz_t top_index = bli_pool_top_index( pool );

// Sanity check: The top_index should be zero.
if ( top_index != 0 )
// NOTE: This sanity check is disabled when called from bli_pool_reinit()
// because it is currently implemented in terms of bli_pool_finalize() followed by
// bli_pool_init(). If that _reinit() takes place when some blocks are
// checked out, then we would expect top_index != 0, and therefore this
// check is not universally appropriate.
if ( top_index != 0 && !reinit )
{
printf( "bli_pool_finalize(): final top_index == %d (expected 0); block_size: %d.\n",
( int )top_index, ( int )bli_pool_block_size( pool ) );
printf( "bli_pool_finalize(): Implication: not all blocks were checked back in!\n" );
bli_abort();
}
#endif

// Query the free() function pointer for the pool.
free_ft free_fp = bli_pool_free_fp( pool );
Expand Down Expand Up @@ -215,7 +214,7 @@ void bli_pool_reinit
// those blocks back into the pool. (This condition can be detected
// since the block size is encoded into each pblk, which is copied
// upon checkout.)
bli_pool_finalize( pool );
bli_pool_finalize( pool, TRUE );

// Reinitialize the pool with the new parameters, in particular,
// the new block size.
Expand Down Expand Up @@ -407,9 +406,6 @@ void bli_pool_grow
=
bli_malloc_intl( block_ptrs_len_new * sizeof( pblk_t ), &r_val );

// Query the top_index of the pool.
const siz_t top_index = bli_pool_top_index( pool );

// Copy the contents of the old block_ptrs array to the new/resized
// array. Notice that we copy the entire array, including elements
// corresponding to blocks that have been checked out. Those elements
Expand Down
3 changes: 2 additions & 1 deletion frame/base/bli_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ void bli_pool_init
);
void bli_pool_finalize
(
pool_t* pool
pool_t* pool,
bool reinit
);
void bli_pool_reinit
(
Expand Down

0 comments on commit 76a23bd

Please sign in to comment.