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... | |
Functions for defining custom memory managers.
typedef void* af_memory_manager |
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)
[in] | handle | a pointer to the active af_memory_manager handle |
[in] | id | the id of the device to add |
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.
[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 |
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.
[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 |
typedef af_err(* af_memory_manager_get_memory_pressure_fn) (af_memory_manager handle, float *pressure) |
Gets memory pressure for a memory manager.
[in] | handle | a pointer to the active af_memory_manager handle |
[out] | pressure | the memory pressure value |
typedef af_err(* af_memory_manager_initialize_fn) (af_memory_manager handle) |
Called after a memory manager is set and becomes active.
[in] | handle | a pointer to the active af_memory_manager handle |
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.
[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 |
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.
[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 |
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.
[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 |
typedef void(* af_memory_manager_remove_memory_management_fn) (af_memory_manager handle, int id) |
Removes a device from the memory manager (OpenCL only)
[in] | handle | a pointer to the active af_memory_manager handle |
[in] | id | the id of the device to remove |
typedef af_err(* af_memory_manager_shutdown_fn) (af_memory_manager handle) |
Called after a memory manager is unset and becomes unused.
[in] | handle | a pointer to the active af_memory_manager handle |
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
[in] | handle | a pointer to the active af_memory_manager handle |
typedef af_err(* af_memory_manager_unlock_fn) (af_memory_manager handle, void *ptr, int user_unlock) |
Unlocks memory from use.
[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 |
typedef af_err(* af_memory_manager_user_lock_fn) (af_memory_manager handle, void *ptr) |
Called to lock a buffer as user-owned memory.
[in] | handle | a pointer to the active af_memory_manager handle |
[in] | ptr | pointer to the buffer to lock |
typedef af_err(* af_memory_manager_user_unlock_fn) (af_memory_manager handle, void *ptr) |
Called to unlock a buffer from user-owned memory.
[in] | handle | a pointer to the active af_memory_manager handle |
[in] | ptr | pointer to the buffer to unlock |