Skip to content

Commit 1b46eb6

Browse files
committed
Adding af.info_str() function that mimics af.info()
- Currently uses information from af.device_info() - This will be replaced when upstream adds native function
1 parent c5fbdda commit 1b46eb6

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

arrayfire/device.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
from .library import *
14-
from .util import (safe_call, to_str)
14+
from .util import (safe_call, to_str, get_version)
1515

1616
def init():
1717
"""
@@ -82,6 +82,55 @@ def set_device(num):
8282
"""
8383
safe_call(backend.get().af_set_device(num))
8484

85+
def info_str(verbose = False):
86+
"""
87+
Returns information about the following as a string:
88+
- ArrayFire version number.
89+
- The number of devices available.
90+
- The names of the devices.
91+
- The current device being used.
92+
"""
93+
import platform
94+
res_str = 'ArrayFire'
95+
96+
major, minor, patch = get_version()
97+
dev_info = device_info()
98+
backend_str = dev_info['backend']
99+
100+
res_str += ' v' + str(major) + '.' + str(minor) + '.' + str(patch)
101+
res_str += ' (' + backend_str + ' ' + platform.architecture()[0] + ')\n'
102+
103+
num_devices = get_device_count()
104+
curr_device_id = get_device()
105+
106+
for n in range(num_devices):
107+
# To suppress warnings on CPU
108+
if (n != curr_device_id):
109+
set_device(n)
110+
111+
if (n == curr_device_id):
112+
res_str += '[%d] ' % n
113+
else:
114+
res_str += '-%d- ' % n
115+
116+
dev_info = device_info()
117+
118+
if (backend_str.lower() == 'opencl'):
119+
res_str += dev_info['toolkit']
120+
121+
res_str += ': ' + dev_info['device']
122+
123+
if (backend_str.lower() != 'cpu'):
124+
res_str += ' (Compute ' + dev_info['compute'] + ')'
125+
126+
res_str += '\n'
127+
128+
# To suppress warnings on CPU
129+
if (curr_device_id != get_device()):
130+
set_device(curr_device_id)
131+
132+
return res_str
133+
85134
def is_dbl_supported(device=None):
86135
"""
87136
Check if double precision is supported on specified device.

0 commit comments

Comments
 (0)