icemelon9 commented on a change in pull request #5357:
URL: https://github.com/apache/incubator-tvm/pull/5357#discussion_r419567958



##########
File path: python/tvm/relay/op/strategy/x86.py
##########
@@ -18,13 +18,17 @@
 # pylint: 
disable=invalid-name,unused-argument,wildcard-import,unused-wildcard-import
 import logging
 
+import re
 import topi
 from tvm.te import SpecializedCondition
 from .generic import *
 from .. import op as _op
 
 logger = logging.getLogger('strategy')
 
+_NCHWc_matcher = re.compile("^NCHW[0-9]+c$")
+_OIHWio_matcher = re.compile("^OIHW[0-9]+i[-+]?[0-9]+o$")

Review comment:
       ```suggestion
   _OIHWio_matcher = re.compile("^OIHW[0-9]+i[0-9]+o$")
   ```

##########
File path: python/tvm/relay/op/strategy/x86.py
##########
@@ -96,6 +99,12 @@ def conv2d_strategy_cpu(attrs, inputs, out_type, target):
                     wrap_compute_conv2d(topi.x86.conv2d_nchw),
                     wrap_topi_schedule(topi.x86.schedule_conv2d_nchw),
                     name="conv2d_nchw.x86")
+        if layout == "NCHW":
+            assert kernel_layout == "OIHW"
+            add_implementation_nchw()
+        elif _NCHWc_matcher.match(layout): # check if layout is NCHWxc
+            assert _OIHWio_matcher.match(kernel_layout) # check if kernel is 
OIHWio
+            add_implementation_nchw()

Review comment:
       Here you should directly add `topi.x86.conv2d_NCHWc` since the op 
already has NCHWc layout.

##########
File path: python/tvm/relay/op/strategy/x86.py
##########
@@ -128,6 +135,15 @@ def conv2d_strategy_cpu(attrs, inputs, out_type, target):
                     wrap_compute_conv2d(topi.nn.depthwise_conv2d_nchw),
                     
wrap_topi_schedule(topi.generic.schedule_depthwise_conv2d_nchw),
                     name="depthwise_conv2d_nchw.generic")
+        if layout == "NCHW":
+            assert kernel_layout == "OIHW"
+            channel_multiplier = get_const_tuple(inputs[1].shape)[1]
+            add_implementation_depthwise_nchw(channel_multiplier)
+        elif _NCHWc_matcher.match(layout): # check if layout is NCHWxc
+            assert _OIHWio_matcher.match(kernel_layout) # check if kernel is 
OIHWio
+            kernel_shape = get_const_tuple(inputs[1].shape)
+            channel_multiplier = kernel_shape[1] * kernel_shape[4]
+            add_implementation_depthwise_nchw(channel_multiplier)

Review comment:
       same here

##########
File path: topi/python/topi/x86/conv2d_alter_op.py
##########
@@ -31,6 +32,9 @@
 
 logger = logging.getLogger('topi')
 
+_NCHWc_matcher = re.compile("^NCHW[0-9]+c$")
+_OIHWio_matcher = re.compile("^OIHW[0-9]+i[-+]?[0-9]+o$")

Review comment:
       ```suggestion
   _OIHWio_matcher = re.compile("^OIHW[0-9]+i[0-9]+o$")
   ```




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to