A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Typedefs
Memory Manager API
ArrayFire Functions by Category » Memory Management

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.
typedef af_err(* | af_memory_manager_shutdown_fn) (af_memory_manager handle)
| Called after a memory manager is unset and becomes unused.
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.
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.
typedef af_err(* | af_memory_manager_unlock_fn) (af_memory_manager handle, void *ptr, int user_unlock)
| Unlocks memory from use.
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.
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.
typedef af_err(* | af_memory_manager_user_lock_fn) (af_memory_manager handle, void *ptr)
| Called to lock a buffer as user-owned memory.
typedef af_err(* | af_memory_manager_user_unlock_fn) (af_memory_manager handle, void *ptr)
| Called to unlock a buffer from user-owned memory.
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.
typedef af_err(* | af_memory_manager_get_memory_pressure_fn) (af_memory_manager handle, float *pressure)
| Gets memory pressure for a memory manager.
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.
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)
typedef void(* | af_memory_manager_remove_memory_management_fn) (af_memory_manager handle, int id)
| Removes a device from the memory manager (OpenCL only)

## 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] | handle | a pointer to the active af_memory_manager handle
  [in] | id | the 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] | handle | a pointer to the active af_memory_manager handle
  [out] | ptr | pointer to the allocated buffer
  [in] | user_lock | a truthy value corresponding to whether or not the memory should have a user lock associated with it
  [in] | ndims | the number of dimensions associated with the allocated memory. This value is currently always 1
  [in,out] | dims | a 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_size | the 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] | handle | a pointer to the active af_memory_manager handle
  [out] | size | the size of the allocated memory for the pointer
  [in] | ptr | the 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] | handle | a pointer to the active af_memory_manager handle
  [out] | pressure | the 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] | handle | a 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] | handle | a pointer to the active af_memory_manager handle
  [out] | out | a truthy value corresponding to if the buffer is user locked
  [in] | ptr | pointer 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] | handle | a pointer to the active af_memory_manager handle
  [out] | out | a truthy value if too much memory pressure is exerted
  [in] | size | the 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] | handle | a pointer to the active af_memory_manager handle
  [out] | buffer | a buffer to which a message will be populated
  [in] | id | the 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] | handle | a pointer to the active af_memory_manager handle
  [in] | id | the 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] | handle | a 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] | handle | a 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] | handle | a pointer to the active af_memory_manager handle
  [out] | ptr | the pointer to query
  [in] | user_unlock | frees 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] | handle | a pointer to the active af_memory_manager handle
  [in] | ptr | pointer 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] | handle | a pointer to the active af_memory_manager handle
  [in] | ptr | pointer to the buffer to unlock

Returns
  AF_SUCCESS

Definition at line 151 of file memory.h.