A high-performance general-purpose compute library

Functions for defining custom memory managers. More...

Typedefs

typedef void * af_memory_manager
 
typedef af_err(* af_memory_manager_initialize_fn) (af_memory_manager handle)
 Called after a memory manager is set and becomes active. More...
 
typedef af_err(* af_memory_manager_shutdown_fn) (af_memory_manager handle)
 Called after a memory manager is unset and becomes unused. More...
 
typedef af_err(* af_memory_manager_alloc_fn) (af_memory_manager handle, void **ptr, int user_lock, const unsigned ndims, dim_t *dims, const unsigned element_size)
 Function pointer that will be called by ArrayFire to allocate memory. More...
 
typedef af_err(* af_memory_manager_allocated_fn) (af_memory_manager handle, size_t *size, void *ptr)
 Checks the amount of allocated memory for a pointer. More...
 
typedef af_err(* af_memory_manager_unlock_fn) (af_memory_manager handle, void *ptr, int user_unlock)
 Unlocks memory from use. More...
 
typedef af_err(* af_memory_manager_signal_memory_cleanup_fn) (af_memory_manager handle)
 Called to signal the memory manager should free memory if possible. More...
 
typedef af_err(* af_memory_manager_print_info_fn) (af_memory_manager handle, char *buffer, int id)
 Populates a character array with human readable information about the current state of the memory manager. More...
 
typedef af_err(* af_memory_manager_user_lock_fn) (af_memory_manager handle, void *ptr)
 Called to lock a buffer as user-owned memory. More...
 
typedef af_err(* af_memory_manager_user_unlock_fn) (af_memory_manager handle, void *ptr)
 Called to unlock a buffer from user-owned memory. More...
 
typedef af_err(* af_memory_manager_is_user_locked_fn) (af_memory_manager handle, int *out, void *ptr)
 Queries if a buffer is user locked. More...
 
typedef af_err(* af_memory_manager_get_memory_pressure_fn) (af_memory_manager handle, float *pressure)
 Gets memory pressure for a memory manager. More...
 
typedef af_err(* af_memory_manager_jit_tree_exceeds_memory_pressure_fn) (af_memory_manager handle, int *out, size_t size)
 Called to query if additions to the JIT tree would exert too much memory pressure. More...
 
typedef void(* af_memory_manager_add_memory_management_fn) (af_memory_manager handle, int id)
 Adds a new device to the memory manager (OpenCL only) More...
 
typedef void(* af_memory_manager_remove_memory_management_fn) (af_memory_manager handle, int id)
 Removes a device from the memory manager (OpenCL only) More...
 

Detailed Description

Functions for defining custom memory managers.

Typedef Documentation

◆ af_memory_manager

typedef void* af_memory_manager

Definition at line 22 of file memory.h.

◆ af_memory_manager_add_memory_management_fn

typedef void(* af_memory_manager_add_memory_management_fn) (af_memory_manager handle, int id)

Adds a new device to the memory manager (OpenCL only)

Parameters
[in]handlea pointer to the active af_memory_manager handle
[in]idthe id of the device to add
Returns
AF_SUCCESS

Definition at line 215 of file memory.h.

◆ af_memory_manager_alloc_fn

typedef af_err(* af_memory_manager_alloc_fn) (af_memory_manager handle, void **ptr, int user_lock, const unsigned ndims, dim_t *dims, const unsigned element_size)

Function pointer that will be called by ArrayFire to allocate memory.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[out]ptrpointer to the allocated buffer
[in]user_locka truthy value corresponding to whether or not the memory should have a user lock associated with it
[in]ndimsthe number of dimensions associated with the allocated memory. This value is currently always 1
[in,out]dimsa dim_t containing the dimensions of the allocation by number of elements. After the function returns, the pointer contains the shape of the allocated tensor
[in]element_sizethe number of bytes per element of allocated memory
Returns
AF_SUCCESS

Definition at line 66 of file memory.h.

◆ af_memory_manager_allocated_fn

typedef af_err(* af_memory_manager_allocated_fn) (af_memory_manager handle, size_t *size, void *ptr)

Checks the amount of allocated memory for a pointer.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[out]sizethe size of the allocated memory for the pointer
[in]ptrthe pointer to query
Returns
AF_SUCCESS

Definition at line 82 of file memory.h.

◆ af_memory_manager_get_memory_pressure_fn

typedef af_err(* af_memory_manager_get_memory_pressure_fn) (af_memory_manager handle, float *pressure)

Gets memory pressure for a memory manager.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[out]pressurethe memory pressure value
Returns
AF_SUCCESS

Definition at line 176 of file memory.h.

◆ af_memory_manager_initialize_fn

typedef af_err(* af_memory_manager_initialize_fn) (af_memory_manager handle)

Called after a memory manager is set and becomes active.

Parameters
[in]handlea pointer to the active af_memory_manager handle
Returns
AF_SUCCESS

Definition at line 36 of file memory.h.

◆ af_memory_manager_is_user_locked_fn

typedef af_err(* af_memory_manager_is_user_locked_fn) (af_memory_manager handle, int *out, void *ptr)

Queries if a buffer is user locked.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[out]outa truthy value corresponding to if the buffer is user locked
[in]ptrpointer to the buffer to query
Returns
AF_SUCCESS

Definition at line 164 of file memory.h.

◆ af_memory_manager_jit_tree_exceeds_memory_pressure_fn

typedef af_err(* af_memory_manager_jit_tree_exceeds_memory_pressure_fn) (af_memory_manager handle, int *out, size_t size)

Called to query if additions to the JIT tree would exert too much memory pressure.

The ArrayFire JIT compiler will call this function to determine if the number of bytes referenced by the buffers in the JIT tree are causing too much memory pressure on the system.

If the memory manager decides that the pressure is too great, the JIT tree will be evaluated and this COULD result in some buffers being freed if they are not referenced by other af_arrays. If the memory pressure is not too great the JIT tree may not be evaluated and could continue to get bigger.

The default memory manager will trigger an evaluation if the buffers in the JIT tree account for half of all buffers allocated.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[out]outa truthy value if too much memory pressure is exerted
[in]sizethe total number of bytes allocated by all the buffer nodes in the current JIT tree
Returns
AF_SUCCESS

Definition at line 203 of file memory.h.

◆ af_memory_manager_print_info_fn

typedef af_err(* af_memory_manager_print_info_fn) (af_memory_manager handle, char *buffer, int id)

Populates a character array with human readable information about the current state of the memory manager.

Prints useful information about the memory manger and its state. No format is enforced and can include any information that could be useful to the user. This function is only called by af_print_mem_info.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[out]buffera buffer to which a message will be populated
[in]idthe device id for which to print memory
Returns
AF_SUCCESS

Definition at line 127 of file memory.h.

◆ af_memory_manager_remove_memory_management_fn

typedef void(* af_memory_manager_remove_memory_management_fn) (af_memory_manager handle, int id)

Removes a device from the memory manager (OpenCL only)

Parameters
[in]handlea pointer to the active af_memory_manager handle
[in]idthe id of the device to remove
Returns
AF_SUCCESS

Definition at line 227 of file memory.h.

◆ af_memory_manager_shutdown_fn

typedef af_err(* af_memory_manager_shutdown_fn) (af_memory_manager handle)

Called after a memory manager is unset and becomes unused.

Parameters
[in]handlea pointer to the active af_memory_manager handle
Returns
AF_SUCCESS

Definition at line 46 of file memory.h.

◆ af_memory_manager_signal_memory_cleanup_fn

typedef af_err(* af_memory_manager_signal_memory_cleanup_fn) (af_memory_manager handle)

Called to signal the memory manager should free memory if possible.

Called by some external functions that allocate their own memory if they receive an out of memory in order to free up other memory on a device

Parameters
[in]handlea pointer to the active af_memory_manager handle
Returns
AF_SUCCESS

Definition at line 109 of file memory.h.

◆ af_memory_manager_unlock_fn

typedef af_err(* af_memory_manager_unlock_fn) (af_memory_manager handle, void *ptr, int user_unlock)

Unlocks memory from use.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[out]ptrthe pointer to query
[in]user_unlockfrees the memory from user lock
Returns
AF_SUCCESS

Definition at line 95 of file memory.h.

◆ af_memory_manager_user_lock_fn

typedef af_err(* af_memory_manager_user_lock_fn) (af_memory_manager handle, void *ptr)

Called to lock a buffer as user-owned memory.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[in]ptrpointer to the buffer to lock
Returns
AF_SUCCESS

Definition at line 139 of file memory.h.

◆ af_memory_manager_user_unlock_fn

typedef af_err(* af_memory_manager_user_unlock_fn) (af_memory_manager handle, void *ptr)

Called to unlock a buffer from user-owned memory.

Parameters
[in]handlea pointer to the active af_memory_manager handle
[in]ptrpointer to the buffer to unlock
Returns
AF_SUCCESS

Definition at line 151 of file memory.h.