mirror of
https://github.com/amd/blis.git
synced 2026-05-11 01:30:00 +00:00
Implemented developer-configurable malloc()/free().
Details: - Replaced all instances of bli_malloc() and bli_free() with one of: - bli_malloc_pool()/bli_free_pool() - bli_malloc_user()/bli_free_user() - bli_malloc_intl()/bli_free_intl() each of which can be configured to call malloc()/free() substitutes, so long as the substitute functions have the same function type signatures as malloc() and free() defined by C's stdlib.h. The _pool() function is called when allocating blocks for the memory pools (used for packing buffers, primarily), the _user() function is called when obj_t's are created (via bli_obj_create() and friends), and the _intl() function is called for internal use by BLIS, such as when creating control tree nodes or temporary buffers for manipulating internal data structures. Substitutes for any of the three types of bli_malloc() may be specified by #defining the following pairs of cpp macros in bli_kernel.h: - BLIS_MALLOC_POOL/BLIS_FREE_POOL - BLIS_MALLOC_USER/BLIS_FREE_USER - BLIS_MALLOC_INTL/BLIS_FREE_INTL to be the name of the substitute functions. (Obviously, the object code that contains these functions must be provided at link-time.) These macros default to malloc() and free(). Subsitute functions are also automatically prototyped by BLIS (in bli_malloc_prototypes.h). - Removed definitions for bli_malloc() and bli_free(). - Note that bli_malloc_pool() and bli_malloc_user() are now defined in terms of a new function, bli_malloc_align(), which aligns memory to an arbitrary (power of two) alignment boundary, but does so manually, whereas before alignment was performed behind the scenes by posix_memalign(). Currently, bli_malloc_intl() is defined in terms of bli_malloc_noalign(), which serves as a simple wrapper to the designated function that is passed in (e.g. BLIS_MALLOC_INTL). Similarly, there are bli_free_align() and bli_free_noalign(), which are used in concert with their bli_malloc_*() counterparts.
This commit is contained in:
@@ -38,8 +38,49 @@
|
||||
|
||||
// -- MEMORY ALLOCATION --------------------------------------------------------
|
||||
|
||||
// Size of a virtual memory page. This is used to align certain memory
|
||||
// buffers which are allocated and used internally.
|
||||
// Memory allocation functions. These macros define the three types of
|
||||
// malloc()-style functions, and their free() counterparts: one for each
|
||||
// type of memory to be allocated.
|
||||
// NOTE: ANY ALTERNATIVE TO malloc()/free() USED FOR ANY OF THE FOLLOWING
|
||||
// THREE PAIRS OF MACROS MUST USE THE SAME FUNCTION PROTOTYPE AS malloc()
|
||||
// and free():
|
||||
//
|
||||
// void* malloc( size_t size );
|
||||
// void free( void* p );
|
||||
//
|
||||
|
||||
// This allocation function is called to allocate memory for blocks within
|
||||
// BLIS's internal memory pools.
|
||||
#ifndef BLIS_MALLOC_POOL
|
||||
#define BLIS_MALLOC_POOL malloc
|
||||
#endif
|
||||
|
||||
#ifndef BLIS_FREE_POOL
|
||||
#define BLIS_FREE_POOL free
|
||||
#endif
|
||||
|
||||
// This allocation function is called to allocate memory for internally-
|
||||
// used objects and structures, such as control tree nodes.
|
||||
#ifndef BLIS_MALLOC_INTL
|
||||
#define BLIS_MALLOC_INTL malloc
|
||||
#endif
|
||||
|
||||
#ifndef BLIS_FREE_INTL
|
||||
#define BLIS_FREE_INTL free
|
||||
#endif
|
||||
|
||||
// This allocation function is called to allocate memory for objects
|
||||
// created by user-level API functions, such as bli_obj_create().
|
||||
#ifndef BLIS_MALLOC_USER
|
||||
#define BLIS_MALLOC_USER malloc
|
||||
#endif
|
||||
|
||||
#ifndef BLIS_FREE_USER
|
||||
#define BLIS_FREE_USER free
|
||||
#endif
|
||||
|
||||
// Size of a virtual memory page. This is used to align blocks within the
|
||||
// memory pools.
|
||||
#ifndef BLIS_PAGE_SIZE
|
||||
#define BLIS_PAGE_SIZE 4096
|
||||
#endif
|
||||
@@ -76,17 +117,16 @@
|
||||
// functions.
|
||||
#define BLIS_STACK_BUF_ALIGN_SIZE BLIS_SIMD_ALIGN_SIZE
|
||||
|
||||
// Alignment size used when allocating memory dynamically from the operating
|
||||
// system (eg: posix_memalign()). To disable heap alignment and just use
|
||||
// malloc() instead, set this to 1.
|
||||
// Alignment size used when allocating memory via BLIS_MALLOC_USER.
|
||||
// To disable heap alignment, set this to 1.
|
||||
#define BLIS_HEAP_ADDR_ALIGN_SIZE BLIS_SIMD_ALIGN_SIZE
|
||||
|
||||
// Alignment size used when sizing leading dimensions of dynamically
|
||||
// allocated memory.
|
||||
// Alignment size used when sizing leading dimensions of memory allocated
|
||||
// via BLIS_MALLOC_USER.
|
||||
#define BLIS_HEAP_STRIDE_ALIGN_SIZE BLIS_SIMD_ALIGN_SIZE
|
||||
|
||||
// Alignment size used when allocating blocks to the internal memory
|
||||
// pool (for packing buffers).
|
||||
// pool, via BLIS_MALLOC_POOL.
|
||||
#define BLIS_POOL_ADDR_ALIGN_SIZE BLIS_PAGE_SIZE
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user