6
6
# The complete license agreement can be obtained at:
7
7
# http://arrayfire.com/licenses/BSD-3-Clause
8
8
########################################################
9
+ """
10
+ Functions to handle the available devices in the backend.
11
+ """
9
12
10
13
from .library import *
11
14
from .util import (safe_call , to_str )
12
15
13
16
def 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
+ """
14
24
safe_call (backend .get ().af_info ())
15
25
16
26
def 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
+ """
17
34
c_char_256 = ct .c_char * 256
18
35
device_name = c_char_256 ()
19
36
backend_name = c_char_256 ()
@@ -31,29 +48,80 @@ def device_info():
31
48
return dev_info
32
49
33
50
def get_device_count ():
51
+ """
52
+ Returns the number of devices available.
53
+ """
34
54
c_num = ct .c_int (0 )
35
55
safe_call (backend .get ().af_get_device_count (ct .pointer (c_num )))
36
56
return c_num .value
37
57
38
58
def get_device ():
59
+ """
60
+ Returns the id of the current device.
61
+ """
39
62
c_dev = ct .c_int (0 )
40
63
safe_call (backend .get ().af_get_device (ct .pointer (c_dev )))
41
64
return c_dev .value
42
65
43
66
def 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
+ """
44
75
safe_call (backend .get ().af_set_device (num ))
45
76
46
77
def 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
+ """
47
91
dev = device if device is not None else get_device ()
48
92
res = ct .c_bool (False )
49
93
safe_call (backend .get ().af_get_dbl_support (ct .pointer (res ), dev ))
50
94
return res .value
51
95
52
96
def 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
+ """
53
105
dev = device if device is not None else get_device ()
54
106
safe_call (backend .get ().af_sync (dev ))
55
107
56
108
def 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
+ """
57
125
alloc_bytes = ct .c_size_t (0 )
58
126
alloc_buffers = ct .c_size_t (0 )
59
127
lock_bytes = ct .c_size_t (0 )
0 commit comments