A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
deviceMemInfo
ArrayFire Functions | ArrayFire Functions by Category » Functions to create and modify Arrays » Managing devices in ArrayFire

Memory manager related functions More...

## Functions
AFAPI void | setMemStepSize (const size_t size)
| Set the resolution of memory chunks.
AFAPI size_t | getMemStepSize ()
| Get the resolution of memory chunks.
AFAPI af_err | af_device_mem_info (size_t *alloc_bytes, size_t *alloc_buffers, size_t *lock_bytes, size_t *lock_buffers)
| Get memory information from the memory manager.
AFAPI af_err | af_print_mem_info (const char *msg, const int device_id)
| Prints buffer details from the ArrayFire Device Manager.
AFAPI af_err | af_device_gc ()
| Call the garbage collection routine.
AFAPI af_err | af_set_mem_step_size (const size_t step_bytes)
| Set the minimum memory chunk size.
AFAPI af_err | af_get_mem_step_size (size_t *step_bytes)
| Get the minimum memory chunk size.
AFAPI af_err | af_lock_device_ptr (const af_array arr)
| Lock the device buffer in the memory manager.
AFAPI af_err | af_unlock_device_ptr (const af_array arr)
| Unlock device buffer in the memory manager.
AFAPI af_err | af_lock_array (const af_array arr)
| Lock the device buffer in the memory manager.
AFAPI af_err | af_unlock_array (const af_array arr)
| Unlock device buffer in the memory manager.
AFAPI af_err | af_is_locked_array (bool *res, const af_array arr)
| Query if the array has been locked by the user.
AFAPI af_err | af_get_device_ptr (void **ptr, const af_array arr)
| Get the device pointer and lock the buffer in memory manager.
AFAPI af_err | af_set_kernel_cache_directory (const char *path, int override_env)
| Sets the path where the kernels generated at runtime will be cached.
AFAPI af_err | af_get_kernel_cache_directory (size_t *length, char *path)
| Gets the path where the kernels generated at runtime will be cached.
AFAPI void | deviceMemInfo (size_t *alloc_bytes, size_t *alloc_buffers, size_t *lock_bytes, size_t *lock_buffers)
| Gets information about the memory manager.
AFAPI void | printMemInfo (const char *msg=NULL, const int device_id=-1)
| Prints buffer details from the ArrayFire Device Manager.
AFAPI void | deviceGC ()
| Call the garbage collection function in the memory manager.

## Detailed Description

Memory manager related functions

Memory manager related functions

## Function Documentation

## ◆ af_device_gc()

AFAPI af_err af_device_gc | ( |  | ) |

Call the garbage collection routine.

## ◆ af_device_mem_info()

AFAPI af_err af_device_mem_info | ( | size_t * | alloc_bytes,
|  | size_t * | alloc_buffers,
|  | size_t * | lock_bytes,
|  | size_t * | lock_buffers )

Get memory information from the memory manager.

## ◆ af_get_device_ptr()

AFAPI af_err af_get_device_ptr | ( | void ** | ptr,
|  | const af_array | arr )

Get the device pointer and lock the buffer in memory manager.

The device pointer `ptr` is notfreed by memory manager until af_unlock_device_ptr is called.

Note
  For OpenCL backend *ptr should be cast to cl_mem.

## ◆ af_get_kernel_cache_directory()

AFAPI af_err af_get_kernel_cache_directory | ( | size_t * | length,
|  | char * | path )

Gets the path where the kernels generated at runtime will be cached.

Gets the path where the kernels generated at runtime will be stored to cache for later use. The files in this directory can be safely deleted. The default location for these kernels is in $HOME/.arrayfire on Unix systems and in the ArrayFire temp directory on Windows.

Parameters

  [out] | length | The length of the path array. If `path` is NULL, the length of the current path is assigned to this pointer
  [out] | path | The path of the runtime generated kernel cache variable. If NULL, the current path length is assigned to `length`

Returns
  AF_SUCCESS if the variable is set. AF_ERR_ARG if path and length are null at the same time. AF_ERR_SIZE if `length` not sufficient enought to store the path

## ◆ af_get_mem_step_size()

AFAPI af_err af_get_mem_step_size | ( | size_t * | step_bytes | ) |

Get the minimum memory chunk size.

Works only with the default memory manager - returns an error if a custom memory manager is set.

## ◆ af_is_locked_array()

AFAPI af_err af_is_locked_array | ( | bool * | res,
|  | const af_array | arr )

Query if the array has been locked by the user.

An array can be locked by the user by calling `af_lock_array` or `af_get_device_ptr` or `af_get_raw_ptr` function.

## ◆ af_lock_array()

AFAPI af_err af_lock_array | ( | const af_array | arr | ) |

Lock the device buffer in the memory manager.

Locked buffers are not freed by memory manager until af_unlock_array is called.

## ◆ af_lock_device_ptr()

AFAPI af_err af_lock_device_ptr | ( | const af_array | arr | ) |

Lock the device buffer in the memory manager.

Locked buffers are not freed by memory manager until af_unlock_array is called.

## ◆ af_print_mem_info()

AFAPI af_err af_print_mem_info | ( | const char * | msg,
|  | const int | device_id )

Prints buffer details from the ArrayFire Device Manager.

The result is a table with several columns:

POINTER: The hex address of the array's device or pinned-memory pointer SIZE: Human-readable size of the array AF LOCK: Indicates whether ArrayFire is using this chunk of memory. If not, the chunk is ready for reuse. USER LOCK: If set, ArrayFire is prevented from freeing this memory. The chunk is not ready for re-use even if all ArrayFire's references to it go out of scope.

Parameters

  [in] | msg | A message to print before the table
  [in] | device_id | print the memory info of the specified device. -1 signifies active device.

Returns
  AF_SUCCESS if successful

## ◆ af_set_kernel_cache_directory()

AFAPI af_err af_set_kernel_cache_directory | ( | const char * | path,
|  | int | override_env )

Sets the path where the kernels generated at runtime will be cached.

Sets the path where the kernels generated at runtime will be stored to cache for later use. The files in this directory can be safely deleted. The default location for these kernels is in $HOME/.arrayfire on Unix systems and in the ArrayFire temp directory on Windows.

Parameters

  [in] | path | The location where the kernels will be stored
  [in] | override_env | if true this path will take precedence over the AF_JIT_KERNEL_CACHE_DIRECTORY environment variable. If false, the environment variable takes precedence over this path.

Returns
  AF_SUCCESS if the variable is set. AF_ERR_ARG if path is NULL.

## ◆ af_set_mem_step_size()

AFAPI af_err af_set_mem_step_size | ( | const size_t | step_bytes | ) |

Set the minimum memory chunk size.

Works only with the default memory manager - returns an error if a custom memory manager is set.

## ◆ af_unlock_array()

AFAPI af_err af_unlock_array | ( | const af_array | arr | ) |

Unlock device buffer in the memory manager.

This function will give back the control over the device pointer to the memory manager.

## ◆ af_unlock_device_ptr()

AFAPI af_err af_unlock_device_ptr | ( | const af_array | arr | ) |

Unlock device buffer in the memory manager.

This function will give back the control over the device pointer to the memory manager.

## ◆ deviceGC()

AFAPI void deviceGC | ( |  | ) |

Call the garbage collection function in the memory manager.

## ◆ deviceMemInfo()

AFAPI void deviceMemInfo | ( | size_t * | alloc_bytes,
|  | size_t * | alloc_buffers,
|  | size_t * | lock_bytes,
|  | size_t * | lock_buffers )

Gets information about the memory manager.

Parameters

  [out] | alloc_bytes | the number of bytes allocated by the memory
  [out] | alloc_buffers | the number of buffers created by the memory
  [out] | lock_bytes | The number of bytes in use
  [out] | lock_buffers | The number of buffers in use

Note
  This function performs a synchronization operation

## ◆ getMemStepSize()

AFAPI size_t getMemStepSize | ( |  | ) |

Get the resolution of memory chunks.

Works only with the default memory manager - throws if a custom memory manager is set.

## ◆ printMemInfo()

AFAPI void printMemInfo | ( | const char * | msg = NULL,
|  | const int | device_id = -1 )

Prints buffer details from the ArrayFire Device Manager.

Parameters

  [in] | msg | A message to print before the table
  [in] | device_id | print the memory info of the specified device. -1 signifies active device.

Note
  This function performs a synchronization operation

## ◆ setMemStepSize()

AFAPI void setMemStepSize | ( | const size_t | size | ) |

Set the resolution of memory chunks.

Works only with the default memory manager - throws if a custom memory manager is set.