You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/12/28 01:23:51 UTC

[GitHub] [tvm] jwfromm commented on a change in pull request #9797: DNNL-BYOC enhancement

jwfromm commented on a change in pull request #9797:
URL: https://github.com/apache/tvm/pull/9797#discussion_r775687563



##########
File path: tests/python/relay/test_pass_partition_graph.py
##########
@@ -989,7 +989,7 @@ def test_partition():
         # conv + relu, conv + relu -> no fusion, 4 partition each with a single op
         test_detect_pattern([conv2d_bias_relu_pat], False, False, 4)
         # conv + bn + sigmoid + relu, conv + sigmoid + relu -> no fusion
-        test_detect_pattern([conv2d_bias_relu_pat, conv2d_relu_pat], True, True, 5)
+        test_detect_pattern([conv2d_bias_relu_pat, conv2d_relu_pat], True, True, 7)

Review comment:
       Would it make sense to add a few tests here? You've done a great job with tests that confirm the correctness of graph partitioned for DNNL, but havent tested that the new patterns are properly fused. All your new tests would pass even if none of the new pattern matches were offloaded as far as I can tell.

##########
File path: tests/python/contrib/test_dnnl.py
##########
@@ -0,0 +1,358 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import numpy as np
+import pytest
+import itertools
+import tvm
+import tvm.relay.testing
+from tvm import relay
+from tvm.relay.op.contrib import dnnl
+import tvm.testing
+
+has_dnnl_codegen = pytest.mark.skipif(
+    not tvm.get_global_func("relay.ext.dnnl", True), reason="DNNL codegen not available"
+)
+
+run_module = tvm.testing.parameter(
+    pytest.param(False, marks=[has_dnnl_codegen, *tvm.testing.requires_llvm()]),
+    pytest.param(True, marks=[has_dnnl_codegen, *tvm.testing.requires_llvm()]),
+    ids=["compile", "run"],
+)
+
+
+def vmobj_to_list(o):
+    if isinstance(o, tvm.nd.NDArray):
+        return [o.numpy()]
+    elif isinstance(o, tvm.runtime.container.ADT) or isinstance(o, list):
+        return [vmobj_to_list(f) for f in o]
+    else:
+        raise RuntimeError("Unknown object type: %s" % type(o))
+
+
+def assert_result_dict_holds(result_dict):
+    for k1, k2 in itertools.combinations(result_dict, 2):
+        res1 = vmobj_to_list(result_dict[k1])
+        res2 = vmobj_to_list(result_dict[k2])
+        for r1, r2 in zip(res1, res2):
+            tvm.testing.assert_allclose(r1, r2, rtol=1e-3, atol=1e-3)
+
+
+def run_and_verify(mod, input, params, target, run_module):
+    def check_dnnl_used(mod):
+        num_dnnl_subgraphs = sum(
+            [1 if "dnnl" in gv.name_hint else 0 for gv in mod.get_global_vars()]
+        )
+        assert num_dnnl_subgraphs >= 1
+
+    dev = tvm.cpu()
+    result_dict = dict()
+    for mode in ["graph", "vm"]:
+        for use_dnnl in [False, True]:
+            result_key = mode + ("_dnnl" if use_dnnl else "")
+            if use_dnnl:
+                mod = dnnl.partition_for_dnnl(mod, params)
+                check_dnnl_used(mod)
+                with tvm.transform.PassContext(opt_level=3):
+                    func = relay.create_executor(
+                        mode, mod=mod, device=dev, target=target
+                    ).evaluate()
+            else:
+                with tvm.transform.PassContext(opt_level=3):

Review comment:
       Some unnecessary duplicated code here. I think you could have a shared compilation and just apply partitioning in the if.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org