[python-arrayfire] 193/250: Adding af.info_str() function that mimics af.info()

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.

commit 1b46eb67ac3d5ee9367fc2bc680f5f70511b1282
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Mon Dec 14 17:58:57 2015 -0500

    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
---
 arrayfire/device.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/arrayfire/device.py b/arrayfire/device.py
index ff2eb88..f84404f 100644
--- a/arrayfire/device.py
+++ b/arrayfire/device.py
@@ -11,7 +11,7 @@ Functions to handle the available devices in the backend.
 """
 
 from .library import *
-from .util import (safe_call, to_str)
+from .util import (safe_call, to_str, get_version)
 
 def init():
     """
@@ -82,6 +82,55 @@ def set_device(num):
     """
     safe_call(backend.get().af_set_device(num))
 
+def info_str(verbose = False):
+    """
+    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.
+    """
+    import platform
+    res_str = 'ArrayFire'
+
+    major, minor, patch = get_version()
+    dev_info = device_info()
+    backend_str = dev_info['backend']
+
+    res_str += ' v' + str(major) + '.' + str(minor) + '.' + str(patch)
+    res_str += ' (' + backend_str + ' ' + platform.architecture()[0] + ')\n'
+
+    num_devices = get_device_count()
+    curr_device_id = get_device()
+
+    for n in range(num_devices):
+        # To suppress warnings on CPU
+        if (n != curr_device_id):
+            set_device(n)
+
+        if (n == curr_device_id):
+            res_str += '[%d] ' % n
+        else:
+            res_str += '-%d- ' % n
+
+        dev_info = device_info()
+
+        if (backend_str.lower() == 'opencl'):
+            res_str += dev_info['toolkit']
+
+        res_str += ': ' + dev_info['device']
+
+        if (backend_str.lower() != 'cpu'):
+            res_str += ' (Compute ' + dev_info['compute'] + ')'
+
+        res_str += '\n'
+
+    # To suppress warnings on CPU
+    if (curr_device_id != get_device()):
+        set_device(curr_device_id)
+
+    return res_str
+
 def is_dbl_supported(device=None):
     """
     Check if double precision is supported on specified device.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list