66# The complete license agreement can be obtained at:
77# http://arrayfire.com/licenses/BSD-3-Clause
88########################################################
9+ """
10+ Functions to handle the available devices in the backend.
11+ """
912
1013from .library import *
1114from .util import (safe_call , to_str )
1215
1316def info ():
17+ """
18+ Displays the information about the following:
19+ - ArrayFire build and version number.
20+ - The number of devices available.
21+ - The names of the devices.
22+ - The current device being used.
23+ """
1424 safe_call (backend .get ().af_info ())
1525
1626def device_info ():
27+ """
28+ Returns a map with the following fields:
29+ - 'device': Name of the current device.
30+ - 'backend': The current backend being used.
31+ - 'toolkit': The toolkit version for the backend.
32+ - 'compute': The compute version of the device.
33+ """
1734 c_char_256 = ct .c_char * 256
1835 device_name = c_char_256 ()
1936 backend_name = c_char_256 ()
@@ -31,29 +48,80 @@ def device_info():
3148 return dev_info
3249
3350def get_device_count ():
51+ """
52+ Returns the number of devices available.
53+ """
3454 c_num = ct .c_int (0 )
3555 safe_call (backend .get ().af_get_device_count (ct .pointer (c_num )))
3656 return c_num .value
3757
3858def get_device ():
59+ """
60+ Returns the id of the current device.
61+ """
3962 c_dev = ct .c_int (0 )
4063 safe_call (backend .get ().af_get_device (ct .pointer (c_dev )))
4164 return c_dev .value
4265
4366def set_device (num ):
67+ """
68+ Change the active device to the specified id.
69+
70+ Parameters
71+ ---------
72+ num: int.
73+ id of the desired device.
74+ """
4475 safe_call (backend .get ().af_set_device (num ))
4576
4677def is_dbl_supported (device = None ):
78+ """
79+ Check if double precision is supported on specified device.
80+
81+ Parameters
82+ ---------
83+ device: optional: int. default: None.
84+ id of the desired device.
85+
86+ Returns
87+ --------
88+ - True if double precision supported.
89+ - False if double precision not supported.
90+ """
4791 dev = device if device is not None else get_device ()
4892 res = ct .c_bool (False )
4993 safe_call (backend .get ().af_get_dbl_support (ct .pointer (res ), dev ))
5094 return res .value
5195
5296def sync (device = None ):
97+ """
98+ Block until all the functions on the device have completed execution.
99+
100+ Parameters
101+ ---------
102+ device: optional: int. default: None.
103+ id of the desired device.
104+ """
53105 dev = device if device is not None else get_device ()
54106 safe_call (backend .get ().af_sync (dev ))
55107
56108def device_mem_info ():
109+ """
110+ Returns a map with the following fields:
111+ - 'alloc': Contains the map of the following
112+ - 'buffers' : Total number of buffers allocated by memory manager.
113+ - 'bytes' : Total number of bytes allocated by memory manager.
114+ - 'lock': Contains the map of the following
115+ - 'buffers' : Total number of buffers currently in scope.
116+ - 'bytes' : Total number of bytes currently in scope.
117+
118+ Note
119+ -----
120+ ArrayFire does not free memory when array goes out of scope. The memory is marked for reuse.
121+ - The difference between alloc buffers and lock buffers equals the number of free buffers.
122+ - The difference between alloc bytes and lock bytes equals the number of free bytes.
123+
124+ """
57125 alloc_bytes = ct .c_size_t (0 )
58126 alloc_buffers = ct .c_size_t (0 )
59127 lock_bytes = ct .c_size_t (0 )
0 commit comments