You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/02/13 18:09:57 UTC

[GitHub] apeforest commented on a change in pull request #14130: Refine runtime feature discovery python API and add documentation to …

apeforest commented on a change in pull request #14130: Refine runtime feature discovery python API and add documentation to …
URL: https://github.com/apache/incubator-mxnet/pull/14130#discussion_r256520957
 
 

 ##########
 File path: python/mxnet/runtime.py
 ##########
 @@ -28,21 +29,48 @@ class LibFeature(ctypes.Structure):
     Compile time feature description
     """
     _fields_ = [
-        ("name", ctypes.c_char_p),
+        ("_name", ctypes.c_char_p),
         ("index", ctypes.c_uint32),
         ("enabled", ctypes.c_bool)
     ]
 
+    @property
+    def name(self):
+        return self._name.decode()
+
+    def __repr__(self):
+        if self.enabled:
+            return "✔ {}".format(self.name)
+        else:
+            return "✖ {}".format(self.name)
+
 def libinfo_features():
     """
     Check the library for compile-time features. The list of features are maintained in libinfo.h and libinfo.cc
 
     Returns
     -------
-    A list of class LibFeature indicating which features are available and enabled
+    :return: list of class LibFeature indicating which features are available and enabled
     """
     lib_features = ctypes.POINTER(LibFeature)()
     lib_features_size = ctypes.c_size_t()
     check_call(_LIB.MXLibInfoFeatures(ctypes.byref(lib_features), ctypes.byref(lib_features_size)))
     feature_list = [lib_features[i] for i in range(lib_features_size.value)]
     return feature_list
+
+def is_enabled(tocheck):
+    """
+    Check for a particular feature by name
+
+    Parameters
+    ----------
+    :param x: str The name of a valid feature as string for example 'CUDA'
+
+    Returns
+    -------
+    :return: bool True if it's enabled, False if it's disabled, RuntimeError if the feature is not known
+    """
+    feature_dict = {f.name: f.enabled for f in libinfo_features()}
+    if tocheck not in feature_dict:
+        raise RuntimeError("Feature '{}' is unknown, known features are: {}".format(tocheck, list(feature_dict.keys())))
+    return feature_dict[tocheck]
 
 Review comment:
   Just curious is the index information useful to user? Why do we even need to expose index?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services