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/06/29 17:20:03 UTC

[GitHub] [tvm] Lunderberg commented on a change in pull request #8336: [Topi][Unittests] Parametrized tests in `test_topi_dense.py`, split out gpu-independent implementations

Lunderberg commented on a change in pull request #8336:
URL: https://github.com/apache/tvm/pull/8336#discussion_r660817079



##########
File path: python/tvm/topi/gpu/dense.py
##########
@@ -0,0 +1,218 @@
+# 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, unused-argument
+"""Schedule for dense operator"""
+
+import logging
+
+from tvm import autotvm, te
+from tvm.autotvm.task.space import SplitEntity
+
+from .. import nn
+from ..utils import traverse_inline, get_const_tuple
+
+logger = logging.getLogger("topi")
+
+
+@autotvm.register_topi_compute("dense_small_batch.gpu")
+def dense_small_batch(cfg, data, weight, bias=None, out_dtype=None):
+    """Dense operator on CUDA"""

Review comment:
       Thank you, and corrected.

##########
File path: python/tvm/topi/gpu/dense.py
##########
@@ -0,0 +1,218 @@
+# 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, unused-argument
+"""Schedule for dense operator"""
+
+import logging
+
+from tvm import autotvm, te
+from tvm.autotvm.task.space import SplitEntity
+
+from .. import nn
+from ..utils import traverse_inline, get_const_tuple
+
+logger = logging.getLogger("topi")
+
+
+@autotvm.register_topi_compute("dense_small_batch.gpu")
+def dense_small_batch(cfg, data, weight, bias=None, out_dtype=None):
+    """Dense operator on CUDA"""
+    return nn.dense(data, weight, bias, out_dtype)
+
+
+@autotvm.register_topi_schedule("dense_small_batch.gpu")
+def schedule_dense_small_batch(cfg, outs):
+    """Schedule float32/64 dense with small batch size"""
+    outs = [outs] if isinstance(outs, te.tensor.Tensor) else outs
+    s = te.create_schedule([x.op for x in outs])
+
+    def _callback(op):
+        if op.tag == "dense":
+            _schedule_dense_small_batch(cfg, s, op.output(0))
+
+    traverse_inline(s, outs[0].op, _callback)
+    return s
+
+
+def _schedule_dense_small_batch(cfg, s, C):
+    A, weights = C.op.input_tensors
+    _, in_dim_weights = get_const_tuple(weights.shape)
+    _, in_dim_A = get_const_tuple(A.shape)
+
+    if isinstance(in_dim_A, int):
+        in_dim = in_dim_A
+    elif isinstance(in_dim_weights, int):
+        in_dim = in_dim_weights
+    else:
+        in_dim = None
+
+    if in_dim is not None:
+        cfg.define_split("tile_k", in_dim, num_outputs=2)
+        if cfg.is_fallback:
+            cfg["tile_k"] = SplitEntity([-1, 64] if in_dim > 64 else [1, 64])
+        _, kf = cfg["tile_k"].apply(s, C, C.op.reduce_axis[0])
+    else:
+        tile_k = 64
+        _, kf = s[C].split(C.op.reduce_axis[0], tile_k)
+
+    CF = s.rfactor(C, kf)
+
+    if C.op in s.outputs:
+        Out = C
+    else:
+        Out = s.outputs[0].output(0)
+        s[C].compute_at(s[Out], s[Out].op.axis[1])
+    s[Out].bind(s[Out].op.axis[0], te.thread_axis("blockIdx.y"))
+    s[Out].bind(s[Out].op.axis[1], te.thread_axis("blockIdx.x"))
+
+    tx = s[C].op.reduce_axis[0]
+    thread_x = te.thread_axis("threadIdx.x")
+    s[C].bind(tx, thread_x)
+    s[CF].compute_at(s[C], tx)
+    s[C].set_store_predicate(thread_x.var.equal(0))
+    s[Out].set_store_predicate(thread_x.var.equal(0))
+
+
+@autotvm.register_topi_compute("dense_large_batch.gpu")
+def dense_large_batch(cfg, data, weight, bias=None, out_dtype=None):
+    """Dense operator on CUDA"""

Review comment:
       Thank you, and corrected.




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