We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[CONTRIB] NNPack Test Flaky
http://ci.tvm.ai:8080/job/tvm/job/PR-2103/1/consoleText

cc @ajtulloch can you take a look?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/tvm/contrib/nnpack.py`
Content:
```
1 """External function interface to NNPACK libraroes."""
2 from __future__ import absolute_import as _abs
3 
4 from .. import api as _api
5 from .. import intrin as _intrin
6 from .._ffi.function import _init_api
7 
8 def config(nthreads):
9     """Configure the nnpack library.
10 
11     Parameters
12     ----------
13     nthreads : int
14         The threads number of nnpack thread pool, must be a nonnegative.
15 
16     """
17     _Config(nthreads)
18 
19 def fully_connected_inference(lhs, rhs, nthreads=1):
20     """Create an extern op that compute fully connected of 1D tensor lhs and
21     2D tensor rhs with nnpack.
22 
23     Parameters
24     ----------
25     lhs : Tensor
26         lhs 1D array input[input_channels] of FP32 elements
27     rhs : Tensor
28         lhs 2D matrix kernel[output_channels][input_channels] of FP32 elements
29 
30     Returns
31     -------
32     C : Tensor
33         lhs 1D array out[output_channels] of FP32 elements.
34     """
35     m = rhs.shape[0]
36     return _api.extern(
37         (m, ), [lhs, rhs],
38         lambda ins, outs: _intrin.call_packed(
39             "tvm.contrib.nnpack.fully_connected_inference",
40             ins[0], ins[1], outs[0], nthreads), name="C")
41 
42 def fully_connected_output(lhs, rhs, nthreads=1):
43     """Create an extern op that compute fully connected of 2D tensor lhs and
44     2D tensor rhs with nnpack.
45 
46     Parameters
47     ----------
48     lhs : Tensor
49         lhs 2D matrix input[batch_size][input_channels] of FP32 elements
50     rhs : Tensor
51         lhs 2D matrix kernel[output_channels][input_channels] of FP32 elements
52 
53     Returns
54     -------
55     C : Tensor
56         lhs 2D array out[batch_size][output_channels] of FP32 elements.
57     """
58     n = lhs.shape[0]
59     m = rhs.shape[0]
60     return _api.extern(
61         (n, m), [lhs, rhs],
62         lambda ins, outs: _intrin.call_packed(
63             "tvm.contrib.nnpack.fully_connected_output",
64             ins[0], ins[1], outs[0], nthreads), name="C")
65 
66 
67 class ConvolutionAlgorithm:
68     AUTO = 0
69     FFT_8x8 = 1
70     FFT_16x16 = 2
71     WT_8x8 = 3
72     IMPLICIT_GEMM = 4
73     DIRECT = 5
74     WT_8x8_FP16 = 6
75 
76 
77 class ConvolutionTransformStrategy:
78     COMPUTE = 1
79     PRECOMPUTE = 2
80 
81 
82 def convolution_inference(
83         data, kernel, bias, padding, stride, nthreads=1,
84         algorithm=ConvolutionAlgorithm.AUTO):
85     """Create an extern op to do inference convolution of 4D tensor data and
86     4D tensor kernel and 1D tensor bias with nnpack.
87 
88     Parameters
89     ----------
90     data : Tensor
91         data 4D tensor input[batch][input_channels][input_height][input_width] of
92         FP32 elements.
93     kernel : Tensor
94         kernel 4D tensor kernel[output_channels][input_channels][kernel_height]
95         [kernel_width] of FP32 elements.
96     bias : Tensor
97         bias 1D array bias[output_channels][input_channels][kernel_height]
98         [kernel_width] of FP32 elements.
99     padding : list
100         padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],
101         which indicates the padding around the feature map.
102     stride : list
103         stride A 2-dim list of [stride_height, stride_width], which indicates
104         the stride.
105 
106     Returns
107     -------
108     output : Tensor
109         output 4D tensor output[batch][output_channels][output_height][output_width]
110         of FP32 elements.
111     """
112 
113     assert isinstance(padding, list) and len(padding) == 4
114     assert isinstance(stride, list) and len(stride) == 2
115     batch, _, input_height, input_width = data.shape
116     output_channels, _, kernel_height, kernel_width = kernel.shape
117     output_height = (input_height + padding[0] + padding[1] - kernel_height) / stride[0] + 1
118     output_width = (input_width + padding[0] + padding[1] - kernel_width) / stride[1] + 1
119 
120     return _api.extern(
121         (batch, output_channels, output_height, output_width),
122         [data, kernel, bias] if bias is not None else [data, kernel],
123         lambda ins, outs: _intrin.call_packed(
124             "tvm.contrib.nnpack.convolution_inference",
125             ins[0],
126             ins[1],
127             ins[2] if bias is not None else 0,
128             outs[0], padding[0], padding[1], padding[2], padding[3],
129             stride[0], stride[1], nthreads, algorithm), name="C")
130 
131 def convolution_inference_without_weight_transform(
132         data, transformed_kernel, bias, padding, stride, nthreads=1,
133         algorithm=ConvolutionAlgorithm.AUTO):
134     """Create an extern op to do inference convolution of 4D tensor data and
135     4D pre-transformed tensor kernel and 1D tensor bias with nnpack.
136 
137     Parameters
138     ----------
139     data : Tensor
140         data 4D tensor input[batch][input_channels][input_height][input_width] of
141         FP32 elements.
142     transformed_kernel : Tensor
143         transformed_kernel 4D tensor kernel[output_channels][input_channels][tile]
144         [tile] of FP32 elements.
145     bias : Tensor
146         bias 1D array bias[output_channels][input_channels][kernel_height]
147         [kernel_width] of FP32 elements.
148     padding : list
149         padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],
150         which indicates the padding around the feature map.
151     stride : list
152         stride A 2-dim list of [stride_height, stride_width], which indicates
153         the stride.
154 
155     Returns
156     -------
157     output : Tensor
158         output 4D tensor output[batch][output_channels][output_height][output_width]
159         of FP32 elements.
160     """
161 
162     assert algorithm in (ConvolutionAlgorithm.WT_8x8,
163                          ConvolutionAlgorithm.WT_8x8_FP16)
164     assert isinstance(padding, list) and len(padding) == 4
165     assert isinstance(stride, list) and len(stride) == 2
166     batch, _, input_height, input_width = data.shape
167     output_channels, _, _, _ = transformed_kernel.shape
168     kernel_height, kernel_width = (3, 3)
169     output_height = (input_height + padding[0] + padding[1] - kernel_height) / stride[0] + 1
170     output_width = (input_width + padding[0] + padding[1] - kernel_width) / stride[1] + 1
171 
172     return _api.extern(
173         (batch, output_channels, output_height, output_width),
174         [data, transformed_kernel, bias] if bias is not None else [data, transformed_kernel],
175         lambda ins, outs: _intrin.call_packed(
176             "tvm.contrib.nnpack.convolution_inference_without_weight_transform",
177             ins[0],
178             ins[1],
179             ins[2] if bias is not None else 0,
180             outs[0], padding[0], padding[1], padding[2], padding[3],
181             stride[0], stride[1], nthreads, algorithm), name="C")
182 
183 def convolution_inference_weight_transform(
184         kernel, nthreads=1,
185         algorithm=ConvolutionAlgorithm.AUTO):
186     """Create an extern op to do inference convolution of 3D tensor data and
187     4D tensor kernel and 1D tensor bias with nnpack.
188 
189     Parameters
190     ----------
191     kernel : Tensor
192         kernel 4D tensor kernel[output_channels][input_channels][kernel_height]
193         [kernel_width] of FP32 elements.
194 
195     Returns
196     -------
197     output : Tensor
198         output 4D tensor output[output_channels][input_channels][tile][tile]
199         of FP32 elements.
200     """
201     assert algorithm in (ConvolutionAlgorithm.WT_8x8, ConvolutionAlgorithm.WT_8x8_FP16)
202     output_channels, input_channels, _, _ = kernel.shape
203 
204     transform_tile_size = 8
205     return _api.extern(
206         (output_channels, input_channels, transform_tile_size, transform_tile_size),
207         [kernel],
208         lambda ins, outs: _intrin.call_packed(
209             "tvm.contrib.nnpack.convolution_inference_weight_transform",
210             ins[0], outs[0], nthreads, algorithm), name="transform_kernel")
211 
212 def convolution_output(data, kernel, bias, padding, nthreads=1):
213     """Create an extern op to compute convolution of 4D tensor data and
214     4D tensor kernel and 1D tensor bias with nnpack.
215 
216     Parameters
217     ----------
218     data : Tensor
219         data 4D tensor input[batch_size][input_channels][input_height]
220         [input_width] of FP32 elements.
221     kernel : Tensor
222         kernel 4D tensor kernel[output_channels][input_channels][kernel_height]
223         [kernel_width] of FP32 elements.
224     bias : Tensor
225         bias 1D array bias[output_channels][input_channels][kernel_height]
226         [kernel_width] of FP32 elements.
227     padding : list
228         padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],
229         which indicates the padding around the feature map.
230 
231     Returns
232     -------
233     output : Tensor
234         output 4D tensor output[batch_size][output_channels][output_height]
235         [output_width] of FP32 elements.
236     """
237 
238     assert isinstance(padding, list) and len(padding) == 4
239     batch, _, input_height, input_width = data.shape
240     output_channels, _, kernel_height, kernel_width = kernel.shape
241     output_height = (input_height + padding[0] + padding[1] - kernel_height) + 1
242     output_width = (input_width + padding[0] + padding[1] - kernel_width) + 1
243 
244     return _api.extern(
245         (batch, output_channels, output_height, output_width), [data, kernel, bias],
246         lambda ins, outs: _intrin.call_packed(
247             "tvm.contrib.nnpack.convolution_output", ins[0], ins[1], ins[2],
248             outs[0], padding[0], padding[1], padding[2], padding[3], nthreads), name="C")
249 
250 
251 _init_api("tvm.contrib.nnpack")
252
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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

{"golden_diff": "diff --git a/python/tvm/contrib/nnpack.py b/python/tvm/contrib/nnpack.py\n--- a/python/tvm/contrib/nnpack.py\n+++ b/python/tvm/contrib/nnpack.py\n@@ -5,16 +5,11 @@\n from .. import intrin as _intrin\n from .._ffi.function import _init_api\n \n-def config(nthreads):\n-    \"\"\"Configure the nnpack library.\n-\n-    Parameters\n-    ----------\n-    nthreads : int\n-        The threads number of nnpack thread pool, must be a nonnegative.\n-\n+def is_available():\n+    \"\"\"Check whether NNPACK is available, that is, `nnp_initialize()`\n+    returns `nnp_status_success`.\n     \"\"\"\n-    _Config(nthreads)\n+    return _initialize() == 0\n \n def fully_connected_inference(lhs, rhs, nthreads=1):\n     \"\"\"Create an extern op that compute fully connected of 1D tensor lhs and\n", "issue": "[CONTRIB] NNPack Test Flaky\nhttp://ci.tvm.ai:8080/job/tvm/job/PR-2103/1/consoleText\r\n\r\ncc @ajtulloch can you take a look?\n", "before_files": [{"content": "\"\"\"External function interface to NNPACK libraroes.\"\"\"\nfrom __future__ import absolute_import as _abs\n\nfrom .. import api as _api\nfrom .. import intrin as _intrin\nfrom .._ffi.function import _init_api\n\ndef config(nthreads):\n    \"\"\"Configure the nnpack library.\n\n    Parameters\n    ----------\n    nthreads : int\n        The threads number of nnpack thread pool, must be a nonnegative.\n\n    \"\"\"\n    _Config(nthreads)\n\ndef fully_connected_inference(lhs, rhs, nthreads=1):\n    \"\"\"Create an extern op that compute fully connected of 1D tensor lhs and\n    2D tensor rhs with nnpack.\n\n    Parameters\n    ----------\n    lhs : Tensor\n        lhs 1D array input[input_channels] of FP32 elements\n    rhs : Tensor\n        lhs 2D matrix kernel[output_channels][input_channels] of FP32 elements\n\n    Returns\n    -------\n    C : Tensor\n        lhs 1D array out[output_channels] of FP32 elements.\n    \"\"\"\n    m = rhs.shape[0]\n    return _api.extern(\n        (m, ), [lhs, rhs],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.fully_connected_inference\",\n            ins[0], ins[1], outs[0], nthreads), name=\"C\")\n\ndef fully_connected_output(lhs, rhs, nthreads=1):\n    \"\"\"Create an extern op that compute fully connected of 2D tensor lhs and\n    2D tensor rhs with nnpack.\n\n    Parameters\n    ----------\n    lhs : Tensor\n        lhs 2D matrix input[batch_size][input_channels] of FP32 elements\n    rhs : Tensor\n        lhs 2D matrix kernel[output_channels][input_channels] of FP32 elements\n\n    Returns\n    -------\n    C : Tensor\n        lhs 2D array out[batch_size][output_channels] of FP32 elements.\n    \"\"\"\n    n = lhs.shape[0]\n    m = rhs.shape[0]\n    return _api.extern(\n        (n, m), [lhs, rhs],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.fully_connected_output\",\n            ins[0], ins[1], outs[0], nthreads), name=\"C\")\n\n\nclass ConvolutionAlgorithm:\n    AUTO = 0\n    FFT_8x8 = 1\n    FFT_16x16 = 2\n    WT_8x8 = 3\n    IMPLICIT_GEMM = 4\n    DIRECT = 5\n    WT_8x8_FP16 = 6\n\n\nclass ConvolutionTransformStrategy:\n    COMPUTE = 1\n    PRECOMPUTE = 2\n\n\ndef convolution_inference(\n        data, kernel, bias, padding, stride, nthreads=1,\n        algorithm=ConvolutionAlgorithm.AUTO):\n    \"\"\"Create an extern op to do inference convolution of 4D tensor data and\n    4D tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    data : Tensor\n        data 4D tensor input[batch][input_channels][input_height][input_width] of\n        FP32 elements.\n    kernel : Tensor\n        kernel 4D tensor kernel[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    bias : Tensor\n        bias 1D array bias[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    padding : list\n        padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],\n        which indicates the padding around the feature map.\n    stride : list\n        stride A 2-dim list of [stride_height, stride_width], which indicates\n        the stride.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[batch][output_channels][output_height][output_width]\n        of FP32 elements.\n    \"\"\"\n\n    assert isinstance(padding, list) and len(padding) == 4\n    assert isinstance(stride, list) and len(stride) == 2\n    batch, _, input_height, input_width = data.shape\n    output_channels, _, kernel_height, kernel_width = kernel.shape\n    output_height = (input_height + padding[0] + padding[1] - kernel_height) / stride[0] + 1\n    output_width = (input_width + padding[0] + padding[1] - kernel_width) / stride[1] + 1\n\n    return _api.extern(\n        (batch, output_channels, output_height, output_width),\n        [data, kernel, bias] if bias is not None else [data, kernel],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_inference\",\n            ins[0],\n            ins[1],\n            ins[2] if bias is not None else 0,\n            outs[0], padding[0], padding[1], padding[2], padding[3],\n            stride[0], stride[1], nthreads, algorithm), name=\"C\")\n\ndef convolution_inference_without_weight_transform(\n        data, transformed_kernel, bias, padding, stride, nthreads=1,\n        algorithm=ConvolutionAlgorithm.AUTO):\n    \"\"\"Create an extern op to do inference convolution of 4D tensor data and\n    4D pre-transformed tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    data : Tensor\n        data 4D tensor input[batch][input_channels][input_height][input_width] of\n        FP32 elements.\n    transformed_kernel : Tensor\n        transformed_kernel 4D tensor kernel[output_channels][input_channels][tile]\n        [tile] of FP32 elements.\n    bias : Tensor\n        bias 1D array bias[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    padding : list\n        padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],\n        which indicates the padding around the feature map.\n    stride : list\n        stride A 2-dim list of [stride_height, stride_width], which indicates\n        the stride.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[batch][output_channels][output_height][output_width]\n        of FP32 elements.\n    \"\"\"\n\n    assert algorithm in (ConvolutionAlgorithm.WT_8x8,\n                         ConvolutionAlgorithm.WT_8x8_FP16)\n    assert isinstance(padding, list) and len(padding) == 4\n    assert isinstance(stride, list) and len(stride) == 2\n    batch, _, input_height, input_width = data.shape\n    output_channels, _, _, _ = transformed_kernel.shape\n    kernel_height, kernel_width = (3, 3)\n    output_height = (input_height + padding[0] + padding[1] - kernel_height) / stride[0] + 1\n    output_width = (input_width + padding[0] + padding[1] - kernel_width) / stride[1] + 1\n\n    return _api.extern(\n        (batch, output_channels, output_height, output_width),\n        [data, transformed_kernel, bias] if bias is not None else [data, transformed_kernel],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_inference_without_weight_transform\",\n            ins[0],\n            ins[1],\n            ins[2] if bias is not None else 0,\n            outs[0], padding[0], padding[1], padding[2], padding[3],\n            stride[0], stride[1], nthreads, algorithm), name=\"C\")\n\ndef convolution_inference_weight_transform(\n        kernel, nthreads=1,\n        algorithm=ConvolutionAlgorithm.AUTO):\n    \"\"\"Create an extern op to do inference convolution of 3D tensor data and\n    4D tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    kernel : Tensor\n        kernel 4D tensor kernel[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[output_channels][input_channels][tile][tile]\n        of FP32 elements.\n    \"\"\"\n    assert algorithm in (ConvolutionAlgorithm.WT_8x8, ConvolutionAlgorithm.WT_8x8_FP16)\n    output_channels, input_channels, _, _ = kernel.shape\n\n    transform_tile_size = 8\n    return _api.extern(\n        (output_channels, input_channels, transform_tile_size, transform_tile_size),\n        [kernel],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_inference_weight_transform\",\n            ins[0], outs[0], nthreads, algorithm), name=\"transform_kernel\")\n\ndef convolution_output(data, kernel, bias, padding, nthreads=1):\n    \"\"\"Create an extern op to compute convolution of 4D tensor data and\n    4D tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    data : Tensor\n        data 4D tensor input[batch_size][input_channels][input_height]\n        [input_width] of FP32 elements.\n    kernel : Tensor\n        kernel 4D tensor kernel[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    bias : Tensor\n        bias 1D array bias[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    padding : list\n        padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],\n        which indicates the padding around the feature map.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[batch_size][output_channels][output_height]\n        [output_width] of FP32 elements.\n    \"\"\"\n\n    assert isinstance(padding, list) and len(padding) == 4\n    batch, _, input_height, input_width = data.shape\n    output_channels, _, kernel_height, kernel_width = kernel.shape\n    output_height = (input_height + padding[0] + padding[1] - kernel_height) + 1\n    output_width = (input_width + padding[0] + padding[1] - kernel_width) + 1\n\n    return _api.extern(\n        (batch, output_channels, output_height, output_width), [data, kernel, bias],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_output\", ins[0], ins[1], ins[2],\n            outs[0], padding[0], padding[1], padding[2], padding[3], nthreads), name=\"C\")\n\n\n_init_api(\"tvm.contrib.nnpack\")\n", "path": "python/tvm/contrib/nnpack.py"}], "after_files": [{"content": "\"\"\"External function interface to NNPACK libraroes.\"\"\"\nfrom __future__ import absolute_import as _abs\n\nfrom .. import api as _api\nfrom .. import intrin as _intrin\nfrom .._ffi.function import _init_api\n\ndef is_available():\n    \"\"\"Check whether NNPACK is available, that is, `nnp_initialize()`\n    returns `nnp_status_success`.\n    \"\"\"\n    return _initialize() == 0\n\ndef fully_connected_inference(lhs, rhs, nthreads=1):\n    \"\"\"Create an extern op that compute fully connected of 1D tensor lhs and\n    2D tensor rhs with nnpack.\n\n    Parameters\n    ----------\n    lhs : Tensor\n        lhs 1D array input[input_channels] of FP32 elements\n    rhs : Tensor\n        lhs 2D matrix kernel[output_channels][input_channels] of FP32 elements\n\n    Returns\n    -------\n    C : Tensor\n        lhs 1D array out[output_channels] of FP32 elements.\n    \"\"\"\n    m = rhs.shape[0]\n    return _api.extern(\n        (m, ), [lhs, rhs],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.fully_connected_inference\",\n            ins[0], ins[1], outs[0], nthreads), name=\"C\")\n\ndef fully_connected_output(lhs, rhs, nthreads=1):\n    \"\"\"Create an extern op that compute fully connected of 2D tensor lhs and\n    2D tensor rhs with nnpack.\n\n    Parameters\n    ----------\n    lhs : Tensor\n        lhs 2D matrix input[batch_size][input_channels] of FP32 elements\n    rhs : Tensor\n        lhs 2D matrix kernel[output_channels][input_channels] of FP32 elements\n\n    Returns\n    -------\n    C : Tensor\n        lhs 2D array out[batch_size][output_channels] of FP32 elements.\n    \"\"\"\n    n = lhs.shape[0]\n    m = rhs.shape[0]\n    return _api.extern(\n        (n, m), [lhs, rhs],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.fully_connected_output\",\n            ins[0], ins[1], outs[0], nthreads), name=\"C\")\n\n\nclass ConvolutionAlgorithm:\n    AUTO = 0\n    FFT_8x8 = 1\n    FFT_16x16 = 2\n    WT_8x8 = 3\n    IMPLICIT_GEMM = 4\n    DIRECT = 5\n    WT_8x8_FP16 = 6\n\n\nclass ConvolutionTransformStrategy:\n    COMPUTE = 1\n    PRECOMPUTE = 2\n\n\ndef convolution_inference(\n        data, kernel, bias, padding, stride, nthreads=1,\n        algorithm=ConvolutionAlgorithm.AUTO):\n    \"\"\"Create an extern op to do inference convolution of 4D tensor data and\n    4D tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    data : Tensor\n        data 4D tensor input[batch][input_channels][input_height][input_width] of\n        FP32 elements.\n    kernel : Tensor\n        kernel 4D tensor kernel[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    bias : Tensor\n        bias 1D array bias[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    padding : list\n        padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],\n        which indicates the padding around the feature map.\n    stride : list\n        stride A 2-dim list of [stride_height, stride_width], which indicates\n        the stride.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[batch][output_channels][output_height][output_width]\n        of FP32 elements.\n    \"\"\"\n\n    assert isinstance(padding, list) and len(padding) == 4\n    assert isinstance(stride, list) and len(stride) == 2\n    batch, _, input_height, input_width = data.shape\n    output_channels, _, kernel_height, kernel_width = kernel.shape\n    output_height = (input_height + padding[0] + padding[1] - kernel_height) / stride[0] + 1\n    output_width = (input_width + padding[0] + padding[1] - kernel_width) / stride[1] + 1\n\n    return _api.extern(\n        (batch, output_channels, output_height, output_width),\n        [data, kernel, bias] if bias is not None else [data, kernel],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_inference\",\n            ins[0],\n            ins[1],\n            ins[2] if bias is not None else 0,\n            outs[0], padding[0], padding[1], padding[2], padding[3],\n            stride[0], stride[1], nthreads, algorithm), name=\"C\")\n\ndef convolution_inference_without_weight_transform(\n        data, transformed_kernel, bias, padding, stride, nthreads=1,\n        algorithm=ConvolutionAlgorithm.AUTO):\n    \"\"\"Create an extern op to do inference convolution of 4D tensor data and\n    4D pre-transformed tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    data : Tensor\n        data 4D tensor input[batch][input_channels][input_height][input_width] of\n        FP32 elements.\n    transformed_kernel : Tensor\n        transformed_kernel 4D tensor kernel[output_channels][input_channels][tile]\n        [tile] of FP32 elements.\n    bias : Tensor\n        bias 1D array bias[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    padding : list\n        padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],\n        which indicates the padding around the feature map.\n    stride : list\n        stride A 2-dim list of [stride_height, stride_width], which indicates\n        the stride.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[batch][output_channels][output_height][output_width]\n        of FP32 elements.\n    \"\"\"\n\n    assert algorithm in (ConvolutionAlgorithm.WT_8x8,\n                         ConvolutionAlgorithm.WT_8x8_FP16)\n    assert isinstance(padding, list) and len(padding) == 4\n    assert isinstance(stride, list) and len(stride) == 2\n    batch, _, input_height, input_width = data.shape\n    output_channels, _, _, _ = transformed_kernel.shape\n    kernel_height, kernel_width = (3, 3)\n    output_height = (input_height + padding[0] + padding[1] - kernel_height) / stride[0] + 1\n    output_width = (input_width + padding[0] + padding[1] - kernel_width) / stride[1] + 1\n\n    return _api.extern(\n        (batch, output_channels, output_height, output_width),\n        [data, transformed_kernel, bias] if bias is not None else [data, transformed_kernel],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_inference_without_weight_transform\",\n            ins[0],\n            ins[1],\n            ins[2] if bias is not None else 0,\n            outs[0], padding[0], padding[1], padding[2], padding[3],\n            stride[0], stride[1], nthreads, algorithm), name=\"C\")\n\ndef convolution_inference_weight_transform(\n        kernel, nthreads=1,\n        algorithm=ConvolutionAlgorithm.AUTO):\n    \"\"\"Create an extern op to do inference convolution of 3D tensor data and\n    4D tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    kernel : Tensor\n        kernel 4D tensor kernel[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[output_channels][input_channels][tile][tile]\n        of FP32 elements.\n    \"\"\"\n    assert algorithm in (ConvolutionAlgorithm.WT_8x8, ConvolutionAlgorithm.WT_8x8_FP16)\n    output_channels, input_channels, _, _ = kernel.shape\n\n    transform_tile_size = 8\n    return _api.extern(\n        (output_channels, input_channels, transform_tile_size, transform_tile_size),\n        [kernel],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_inference_weight_transform\",\n            ins[0], outs[0], nthreads, algorithm), name=\"transform_kernel\")\n\ndef convolution_output(data, kernel, bias, padding, nthreads=1):\n    \"\"\"Create an extern op to compute convolution of 4D tensor data and\n    4D tensor kernel and 1D tensor bias with nnpack.\n\n    Parameters\n    ----------\n    data : Tensor\n        data 4D tensor input[batch_size][input_channels][input_height]\n        [input_width] of FP32 elements.\n    kernel : Tensor\n        kernel 4D tensor kernel[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    bias : Tensor\n        bias 1D array bias[output_channels][input_channels][kernel_height]\n        [kernel_width] of FP32 elements.\n    padding : list\n        padding A 4-dim list of [pad_top, pad_bottom, pad_left, pad_right],\n        which indicates the padding around the feature map.\n\n    Returns\n    -------\n    output : Tensor\n        output 4D tensor output[batch_size][output_channels][output_height]\n        [output_width] of FP32 elements.\n    \"\"\"\n\n    assert isinstance(padding, list) and len(padding) == 4\n    batch, _, input_height, input_width = data.shape\n    output_channels, _, kernel_height, kernel_width = kernel.shape\n    output_height = (input_height + padding[0] + padding[1] - kernel_height) + 1\n    output_width = (input_width + padding[0] + padding[1] - kernel_width) + 1\n\n    return _api.extern(\n        (batch, output_channels, output_height, output_width), [data, kernel, bias],\n        lambda ins, outs: _intrin.call_packed(\n            \"tvm.contrib.nnpack.convolution_output\", ins[0], ins[1], ins[2],\n            outs[0], padding[0], padding[1], padding[2], padding[3], nthreads), name=\"C\")\n\n\n_init_api(\"tvm.contrib.nnpack\")\n", "path": "python/tvm/contrib/nnpack.py"}]}