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 2019/12/04 04:32:32 UTC

[GitHub] [incubator-tvm] masahi commented on a change in pull request #4400: implement conv3d op

masahi commented on a change in pull request #4400: implement conv3d op
URL: https://github.com/apache/incubator-tvm/pull/4400#discussion_r353545341
 
 

 ##########
 File path: topi/python/topi/cuda/conv3d.py
 ##########
 @@ -0,0 +1,142 @@
+# 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.
+# pylint: disable=invalid-name
+"""Compute definition for conv3d with cuda backend"""
+import tvm
+from tvm import autotvm
+from tvm.contrib import cudnn
+
+from .. import nn, generic
+from ..util import get_const_tuple, traverse_inline
+
+from .conv3d_direct import schedule_direct_3d_cuda
+
+
+@autotvm.register_topi_compute(nn.conv3d, ['cuda', 'gpu'], ['direct'])
+def conv3d_cuda(cfg, data, kernel, strides, padding, dilation, layout='NCDHW', out_dtype='float32'):
+    """Conv3D operator for cuda backend.
+
+    Parameters
+    ----------
+    cfg: ConfigEntity
+        The config for this template
+
+    data : tvm.Tensor
+        5-D with shape [batch, in_channel, in_depth, in_height, in_width]
+
+    kernel : tvm.Tensor
+        5-D with shape [num_filter, in_channel, filter_depth, filter_height, filter_width]
+
+    strides : int or a list/tuple of three ints
+        stride size, or [stride_depth, stride_height, stride_width]
+
+    padding : int or a list/tuple of three ints
+        padding size, or [pad_depth, pad_height, pad_width]
+
+    dilation: int or a list/tuple of three ints
+        dilation size, or [dilation_depth, dilation_height, dilation_width]
+
+    layout : str
+        layout of data
+
+    out_dtype: str
+        The output type. This is used for mixed precision.
+
+    Returns
+    -------
+    output : tvm.Tensor
+        5-D with shape [batch, out_channel, out_depth, out_height, out_width]
+    """
+    target = tvm.target.current_target()
+
+    if "cudnn" in target.libs:
+        if layout == 'NCDHW':
+            tensor_format = 0 # CUDNN_TENSOR_NCHW
+            N, _, D, H, W = get_const_tuple(data.shape)
+        elif layout == 'NDHWC':
+            tensor_format = 1 # CUDNN_TENSOR_NHWC
+            N, D, H, W, _ = get_const_tuple(data.shape)
+        else:
+            raise ValueError("Unsupported layout %s in cudnn" % layout)
+        CO, CI, KD, KH, KW = get_const_tuple(kernel.shape)
+
+        # handle dilation
+        stride_d, stride_h, stride_w = (strides, strides, strides) if isinstance(strides, int) \
+            else strides
+        pad_d, pad_h, pad_w = (padding, padding, padding) if isinstance(padding, int) else padding
+        dilation_d, dilation_h, dilation_w = (dilation, dilation, dilation) if \
+            isinstance(dilation, int) else dilation
+
+        OD = (D + 2 * pad_d - KD) // stride_d + 1
+        OH = (H + 2 * pad_h - KH) // stride_h + 1
+        OW = (W + 2 * pad_w - KW) // stride_w + 1
+        cfg.add_flop(2 * N * OD * OH * OW * CO * CI * ((DH - 1) * dilation_d + 1) *\
+                    ((KH - 1) * dilation_h + 1) * ((KW - 1) * dilation_w + 1))
+
+        return cudnn.conv3d_forward(data,
 
 Review comment:
   this should be conv_forward

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services