arrayfire.device module

Functions to handle the available devices in the backend.

arrayfire.device.alloc_device(num_bytes)[source]

Allocate a buffer on the device with specified number of bytes.

arrayfire.device.alloc_host(num_bytes)[source]

Allocate a buffer on the host with specified number of bytes.

arrayfire.device.alloc_pinned(num_bytes)[source]

Allocate a buffer on the host using pinned memory with specified number of bytes.

arrayfire.device.device_gc()[source]

Ask the garbage collector to free all unlocked memory

arrayfire.device.device_info()[source]
Returns a map with the following fields:
  • ‘device’: Name of the current device.

  • ‘backend’: The current backend being used.

  • ‘toolkit’: The toolkit version for the backend.

  • ‘compute’: The compute version of the device.

arrayfire.device.device_mem_info()[source]
Returns a map with the following fields:
  • ‘alloc’: Contains the map of the following
    • ‘buffers’ : Total number of buffers allocated by memory manager.

    • ‘bytes’ : Total number of bytes allocated by memory manager.

  • ‘lock’: Contains the map of the following
    • ‘buffers’ : Total number of buffers currently in scope.

    • ‘bytes’ : Total number of bytes currently in scope.

arrayfire.device.eval(*args)[source]

Evaluate one or more inputs together

Parameters
argsarguments to be evaluated

Examples

>>> a = af.constant(1, 3, 3)
>>> b = af.constant(2, 3, 3)
>>> c = a + b
>>> d = a - b
>>> af.eval(c, d) # A single kernel is launched here
>>> c
arrayfire.Array()
Type: float
[3 3 1 1]
3.0000     3.0000     3.0000
3.0000     3.0000     3.0000
3.0000     3.0000     3.0000
>>> d
arrayfire.Array()
Type: float
[3 3 1 1]
-1.0000    -1.0000    -1.0000
-1.0000    -1.0000    -1.0000
-1.0000    -1.0000    -1.0000
arrayfire.device.free_device(ptr)[source]

Free the device memory allocated by alloc_device

arrayfire.device.free_host(ptr)[source]

Free the host memory allocated by alloc_host

arrayfire.device.free_pinned(ptr)[source]

Free the pinned memory allocated by alloc_pinned

arrayfire.device.get_device()[source]

Returns the id of the current device.

arrayfire.device.get_device_count()[source]

Returns the number of devices available.

arrayfire.device.get_device_ptr(a)[source]

Get the raw device pointer of an array

Parameters
a: af.Array
  • A multi dimensional arrayfire array.

Returns
  • internal device pointer held by a
arrayfire.device.get_manual_eval_flag()[source]

Query the backend JIT engine to see if the user disabled heuristic evaluation of the JIT tree.

arrayfire.device.info()[source]
Displays the information about the following:
  • ArrayFire build and version number.

  • The number of devices available.

  • The names of the devices.

  • The current device being used.

arrayfire.device.info_str(verbose=False)[source]
Returns information about the following as a string:
  • ArrayFire version number.

  • The number of devices available.

  • The names of the devices.

  • The current device being used.

arrayfire.device.init()[source]
arrayfire.device.is_dbl_supported(device=None)[source]

Check if double precision is supported on specified device.

Parameters
device: optional: int. default: None.

id of the desired device.

Returns
  • True if double precision supported.
    • False if double precision not supported.

arrayfire.device.is_half_supported(device=None)[source]

Check if half precision is supported on specified device.

Parameters
device: optional: int. default: None.

id of the desired device.

Returns
  • True if half precision supported.
    • False if half precision not supported.

arrayfire.device.is_locked_array(a)[source]

Check if the input array is locked by the user.

Parameters
a: af.Array
  • A multi dimensional arrayfire array.

Returns
A bool specifying if the input array is locked.
arrayfire.device.lock_array(a)[source]

Ask arrayfire to not perform garbage collection on raw data held by an array.

Parameters
a: af.Array
  • A multi dimensional arrayfire array.

arrayfire.device.lock_device_ptr(a)[source]

This functions is deprecated. Please use lock_array instead.

arrayfire.device.print_mem_info(title='Memory Info', device_id=None)[source]

Prints the memory used for the specified device.

Parameters
title: optional. Default: “Memory Info”
  • Title to display before printing the memory info.

device_id: optional. Default: None
  • Specifies the device for which the memory info should be displayed.

  • If None, uses the current device.

Examples

>>> a = af.randu(5,5)
>>> af.print_mem_info()
Memory Info
---------------------------------------------------------
|     POINTER      |    SIZE    |  AF LOCK  | USER LOCK |
---------------------------------------------------------
|     0x706400000  |       1 KB |       Yes |        No |
---------------------------------------------------------
>>> b = af.randu(5,5)
>>> af.print_mem_info()
Memory Info
---------------------------------------------------------
|     POINTER      |    SIZE    |  AF LOCK  | USER LOCK |
---------------------------------------------------------
|     0x706400400  |       1 KB |       Yes |        No |
|     0x706400000  |       1 KB |       Yes |        No |
---------------------------------------------------------
>>> a = af.randu(1000,1000)
>>> af.print_mem_info()
Memory Info
---------------------------------------------------------
|     POINTER      |    SIZE    |  AF LOCK  | USER LOCK |
---------------------------------------------------------
|     0x706500000  |   3.815 MB |       Yes |        No |
|     0x706400400  |       1 KB |       Yes |        No |
|     0x706400000  |       1 KB |        No |        No |
---------------------------------------------------------
arrayfire.device.set_device(num)[source]

Change the active device to the specified id.

Parameters
num: int.

id of the desired device.

arrayfire.device.set_manual_eval_flag(flag)[source]

Tells the backend JIT engine to disable heuristics for determining when to evaluate a JIT tree.

Parameters
flagoptional: bool.
  • Specifies if the heuristic evaluation of the JIT tree needs to be disabled.

arrayfire.device.sync(device=None)[source]

Block until all the functions on the device have completed execution.

Parameters
device: optional: int. default: None.

id of the desired device.

arrayfire.device.unlock_array(a)[source]

Tell arrayfire to resume garbage collection on raw data held by an array.

Parameters
a: af.Array
  • A multi dimensional arrayfire array.

arrayfire.device.unlock_device_ptr(a)[source]

This functions is deprecated. Please use unlock_array instead.