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/23 02:16:38 UTC

[GitHub] [tvm] crazydemo opened a new pull request #9797: DNNL-BYOC enhancement

crazydemo opened a new pull request #9797:
URL: https://github.com/apache/tvm/pull/9797


   - add more patterns in `dnnl.py`.
   - add test cases, which have covered the support ops and patterns, in `test_dnnl.py`.
   - add implementation of new added ops and patterns in `dnnl_json_runtime.cc`.
   - add support to `dilated conv2d` with dnnl backend.


-- 
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



[GitHub] [tvm] crazydemo commented on pull request #9797: DNNL-BYOC enhancement

Posted by GitBox <gi...@apache.org>.
crazydemo commented on pull request #9797:
URL: https://github.com/apache/tvm/pull/9797#issuecomment-1001891824


   > Thanks for this change, it looks really excellent. I have a few small comments but am curious if youve done any benchmarking with this new pattern fusion. If so, how much do these changes speed up models you tried?
   
   Thank you for your comments. We do have done some benchmark, and the related results are posted on [RFC](https://discuss.tvm.apache.org/t/rfc-byoc-intel-r-onednn-integration/11582).
   
   Note that, the results in `RFC`  are collected with the `registered pattern` and optimization from `alter_op_layout pass`.
   We are going to submit another two `layout transform` related PRs to fully support the performance gain claimed in `RFC`.


-- 
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



[GitHub] [tvm] masahi merged pull request #9797: DNNL-BYOC enhancement

Posted by GitBox <gi...@apache.org>.
masahi merged pull request #9797:
URL: https://github.com/apache/tvm/pull/9797


   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
crazydemo commented on a change in pull request #9797:
URL: https://github.com/apache/tvm/pull/9797#discussion_r775745371



##########
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:
       Sure, more tests are added.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
crazydemo commented on a change in pull request #9797:
URL: https://github.com/apache/tvm/pull/9797#discussion_r775745250



##########
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:
       Fixed.




-- 
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