Пример #1
0
void bli_pool_reinit_if( dim_t   num_blocks_new,
                         siz_t   block_size_new,
                         siz_t   align_size_new,
                         pool_t* pool )
{
	const dim_t num_blocks = bli_pool_num_blocks( pool );
	const dim_t block_size = bli_pool_block_size( pool );
	const dim_t align_size = bli_pool_align_size( pool );

	// Reinitialize the pool, but only if one or more of new pool
	// parameters would require it. Otherwise, if only the number
	// of blocks has increased, we can skip a full reinit and just
	// grow the pool.
	if ( block_size_new >  block_size ||
	     align_size_new != align_size )
	{
		// Reinitialize the pool with the new parameters, in particular,
		// the new block size.
		bli_pool_reinit( num_blocks_new,
		                 block_size_new,
		                 align_size_new,
		                 pool );
	}
	else if ( num_blocks_new > num_blocks )
	{
		const dim_t num_blocks_add = num_blocks_new -
		                             num_blocks;

		bli_pool_grow( num_blocks_add, pool );
	}
}
Пример #2
0
err_t bli_check_requested_block_size_for_pool( siz_t req_size, pool_t* pool )
{
	err_t e_val = BLIS_SUCCESS;

	if ( bli_pool_block_size( pool ) < req_size )
		e_val = BLIS_REQUESTED_CONTIG_BLOCK_TOO_BIG;

	return e_val;
}
Пример #3
0
void bli_pool_print( pool_t* pool )
{
	pblk_t* block_ptrs     = bli_pool_block_ptrs( pool );
	dim_t   block_ptrs_len = bli_pool_block_ptrs_len( pool );
	dim_t   top_index      = bli_pool_top_index( pool );
	dim_t   num_blocks     = bli_pool_num_blocks( pool );
	dim_t   block_size     = bli_pool_block_size( pool );
	dim_t   align_size     = bli_pool_align_size( pool );
	dim_t   i;

	printf( "pool struct ---------------\n" );
	printf( "  block_ptrs:      %p\n", block_ptrs );
	printf( "  block_ptrs_len:  %ld\n", block_ptrs_len );
	printf( "  top_index:       %ld\n", top_index );
	printf( "  num_blocks:      %ld\n", num_blocks );
	printf( "  block_size:      %ld\n", block_size );
	printf( "  align_size:      %ld\n", align_size );
	printf( "  pblks   sys    align\n" );
	for ( i = 0; i < num_blocks; ++i )
	{
	printf( "  %ld: %p %p\n", i, bli_pblk_buf_sys(   &block_ptrs[i] ),
	                             bli_pblk_buf_align( &block_ptrs[i] ) );
	}
}
Пример #4
0
void bli_pool_grow( dim_t num_blocks_add, pool_t* pool )
{
	pblk_t* block_ptrs_cur;
	dim_t   block_ptrs_len_cur;
	dim_t   num_blocks_cur;

	pblk_t* block_ptrs_new;
	dim_t   num_blocks_new;

	siz_t   block_size;
	siz_t   align_size;
	dim_t   top_index;

	dim_t   i;

	// If the requested increase is zero (or negative), return early.
	if ( num_blocks_add < 1 ) return;

	// Query the allocated length of the block_ptrs array and also the
	// total number of blocks allocated.
	block_ptrs_len_cur = bli_pool_block_ptrs_len( pool );
	num_blocks_cur     = bli_pool_num_blocks( pool );

	// Compute the total number of allocated blocks that will exist
	// after we grow the pool.
	num_blocks_new = num_blocks_cur + num_blocks_add;

	// If the new total number of allocated blocks is larger than the
	// allocated length of the block_ptrs array, we need to allocate
	// a new (larger) block_ptrs array.
	if ( num_blocks_new > block_ptrs_len_cur )
	{
		// Query the current block_ptrs array.
		block_ptrs_cur = bli_pool_block_ptrs( pool );

		// Allocate a new block_ptrs array of length num_blocks_new.
		block_ptrs_new = bli_malloc( num_blocks_new * sizeof( pblk_t ) );

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

		// Copy the contents of the old block_ptrs array to the new/resized
		// array. Notice that we can begin with top_index since all entries
		// from 0 to top_index-1 have been checked out to threads.
		for ( i = top_index; i < num_blocks_cur; ++i ) 
		{
//printf( "bli_pool_grow: copying from %lu\n", top_index );
			block_ptrs_new[i] = block_ptrs_cur[i];
		}

//printf( "bli_pool_grow: bp_cur: %p\n", block_ptrs_cur );
		// Free the old block_ptrs array.
		bli_free( block_ptrs_cur );

		// Update the pool_t struct with the new block_ptrs array and
		// record its allocated length.
		bli_pool_set_block_ptrs( block_ptrs_new, pool );
		bli_pool_set_block_ptrs_len( num_blocks_new, pool );
	}

	// At this point, we are guaranteed to have enough unused elements
	// in the block_ptrs array to accommodate an additional num_blocks_add
	// blocks.

	// Query the current block_ptrs array (which was possibly just resized).
	block_ptrs_cur = bli_pool_block_ptrs( pool );

	// Query the block size and alignment size of the current pool.
	block_size = bli_pool_block_size( pool );
	align_size = bli_pool_align_size( pool );

	// Allocate the requested additional blocks in the resized array.
	for ( i = num_blocks_cur; i < num_blocks_new; ++i ) 
	{
//printf( "libblis: growing pool, block_size = %lu\n", block_size ); fflush( stdout );

		bli_pool_alloc_block( block_size, align_size, &(block_ptrs_cur[i]) );
	}

	// Update the pool_t struct with the new number of allocated blocks.
	// Notice that top_index remains unchanged, as do the block_size and
	// align_size fields.
	bli_pool_set_num_blocks( num_blocks_new, pool );
}