|
11 | 11 | """
|
12 | 12 |
|
13 | 13 | from .library import *
|
14 |
| -from .util import (safe_call, to_str) |
| 14 | +from .util import (safe_call, to_str, get_version) |
15 | 15 |
|
16 | 16 | def init():
|
17 | 17 | """
|
@@ -82,6 +82,55 @@ def set_device(num):
|
82 | 82 | """
|
83 | 83 | safe_call(backend.get().af_set_device(num))
|
84 | 84 |
|
| 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 | + |
85 | 134 | def is_dbl_supported(device=None):
|
86 | 135 | """
|
87 | 136 | Check if double precision is supported on specified device.
|
|
0 commit comments