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/09/30 17:14:35 UTC

[GitHub] [tvm] elphinkuo commented on a change in pull request #9142: BSR optimization in TOPI

elphinkuo commented on a change in pull request #9142:
URL: https://github.com/apache/tvm/pull/9142#discussion_r719607711



##########
File path: python/tvm/topi/bsrmm.py
##########
@@ -0,0 +1,146 @@
+# 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.
+"""TVM operator compute SpMM in BSR format.
+"""
+from __future__ import absolute_import
+import tvm
+from tvm import te
+from .. import tag
+from ..utils import simplify
+from ...tir.generic import cast
+
+
+def bsrmm_default(data, indices, indptr, blocksize, weight, bias=None):
+    # pylint: disable=invalid-name
+    """The default implementation of bsrmm in topi.
+
+    Parameters
+    ----------
+    data : tvm.te.Tensor
+        1-D with shape [nonzeros]
+
+    indices : tvm.te.Tensor
+        1-D with shape [nonzeros]
+
+    indptr : tvm.te.Tensor
+        1-D with shape [m+1]
+
+    blocksize: tvm.te.Tensor
+        Block size of the matrix
+        2-D with shape [bs_r, bs_c]
+
+    weight : tvm.te.Tensor
+        2-D with shape [k, n]
+
+    bias : tvm.te.Tensor, optional
+        1-D with shape [m]
+
+    Returns
+    -------
+    output : tvm.te.Tensor
+        2-D with shape [m, n]
+    """
+    assert (
+        len(data.shape) == 1
+        and len(indices.shape) == 1
+        and len(indptr.shape) == 1
+        and len(weight.shape) == 2
+    ), "only support 2-dim bsrmm"
+    assert isinstance(
+        weight, te.tensor.Tensor
+    ), "weight matrix is assumed to be tvm.te.Tensor, but weight is `%s`" % (type(weight))
+    assert (
+        data.dtype == weight.dtype
+    ), "Data and weight must have the same dtype, but they have %s and %s" % (
+        data.dtype,
+        weight.dtype,
+    )
+    if bias is not None:
+        assert len(bias.shape) == 1
+    M = simplify(indptr.shape[0] - 1)
+    _, N = weight.shape
+
+    def bsrmm_default_ir(data, indices, indptr, blocksize, weight, out):

Review comment:
       Got it! We will take your point into consideration. 
   Thanks a lot for the prompt response!




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