Repository: apache/tvm

Issue:
[CONTRIB] NNPack Test Flaky
http://ci.tvm.ai:8080/job/tvm/job/PR-2103/1/consoleText

cc @ajtulloch can you take a look?


Discussion:
The error is nnp_status_unsupported_hardware, I’ll send a diff which exposes nnp_initialize() to TVM and add a check that nnp_initialize succeeds before invoking the rest of the test. Does that sound good?
that sounds good, we can expose it as a PackedFunc which can be used by the python side

Resolving patch:
diff --git a/python/tvm/contrib/nnpack.py b/python/tvm/contrib/nnpack.py
--- a/python/tvm/contrib/nnpack.py
+++ b/python/tvm/contrib/nnpack.py
@@ -5,16 +5,11 @@
 from .. import intrin as _intrin
 from .._ffi.function import _init_api
 
-def config(nthreads):
-    """Configure the nnpack library.
-
-    Parameters
-    ----------
-    nthreads : int
-        The threads number of nnpack thread pool, must be a nonnegative.
-
+def is_available():
+    """Check whether NNPACK is available, that is, `nnp_initialize()`
+    returns `nnp_status_success`.
     """
-    _Config(nthreads)
+    return _initialize() == 0
 
 def fully_connected_inference(lhs, rhs, nthreads=1):
     """Create an extern op that compute fully connected of 1D tensor lhs and


Test patch:
diff --git a/tests/python/contrib/test_nnpack.py b/tests/python/contrib/test_nnpack.py
--- a/tests/python/contrib/test_nnpack.py
+++ b/tests/python/contrib/test_nnpack.py
@@ -21,7 +21,9 @@ def verify(target="llvm"):
         if not tvm.get_global_func("tvm.contrib.nnpack.fully_connected_output", True):
             print("skip because extern function is not available")
             return
-        return
+        if not nnpack.is_available():
+            return
+
         ctx = tvm.cpu(0)
         f = tvm.build(s, [A, B, D, bias], target)
         a = tvm.nd.array(np.random.uniform(size=(n, l)).astype(A.dtype), ctx)
@@ -52,7 +54,9 @@ def verify(target="llvm"):
         if not tvm.get_global_func("tvm.contrib.nnpack.fully_connected_inference", True):
             print("skip because extern function is not available")
             return
-        return
+        if not nnpack.is_available():
+            return
+
         ctx = tvm.cpu(0)
         f = tvm.build(s, [A, B, D, bias], target)
         a = tvm.nd.array(np.random.uniform(size=(l)).astype(A.dtype), ctx)
@@ -130,7 +134,9 @@ def verify(target="llvm",
         if not tvm.get_global_func("tvm.contrib.nnpack.fully_connected_inference", True):
             print("skip because extern function is not available")
             return
-        return
+        if not nnpack.is_available():
+            return
+
         ctx = tvm.cpu(0)
         output = nnpack.convolution_inference(
             data, kernel, bias if with_bias else None,
@@ -192,7 +198,9 @@ def verify(target="llvm",
         if not tvm.get_global_func("tvm.contrib.nnpack.fully_connected_inference", True):
             print("skip because extern function is not available")
             return
-        return
+        if not nnpack.is_available():
+            return
+
         ctx = tvm.cpu(0)
         transformed_kernel = nnpack.convolution_inference_weight_transform(
             kernel, algorithm=algorithm)
@@ -249,7 +257,9 @@ def verify(target="llvm"):
         if not tvm.get_global_func("tvm.contrib.nnpack.fully_connected_inference", True):
             print("skip because extern function is not available")
             return
-        return
+        if not nnpack.is_available():
+            return
+
         ctx = tvm.cpu(0)
         f = tvm.build(s, [data, kernel, bias, output], target)