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/28 15:05:48 UTC

[GitHub] [tvm] elphinkuo opened a new pull request #9142: BSR optimization in TOPI

elphinkuo opened a new pull request #9142:
URL: https://github.com/apache/tvm/pull/9142


   Add BSRMM and BSRMV in TOPI of Python layer.
   Add BSRNDArray in contrib of Python Python layer.
   
   This is the first submission of a series work, to support the BSR optimization in TVM. The first submission is is draft PR mode, as we are trying to follow the design principles and code styles. If there is any issue or modification we need to address, feel free to let us know.
   More details are in this paper https://arxiv.org/abs/2106.08846.
   
   @tqchen @yzhliu @vinx13 


-- 
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] jroesch commented on pull request #9142: BSR optimization in TOPI

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


   @elphinkuo can you update this PR?


-- 
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] vinx13 commented on a change in pull request #9142: BSR optimization in TOPI

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



##########
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:
       if this implementation is target specific, would be better to put it under target's directory e.g https://github.com/apache/tvm/blob/main/python/tvm/topi/x86/sparse.py




-- 
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] vinx13 commented on a change in pull request #9142: BSR optimization in TOPI

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



##########
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:
       if this implementation is target specific, would be better to put it under target's directory e.g https://github.com/apache/tvm/blob/main/python/tvm/topi/x86/sparse.py




-- 
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] tkonolige commented on pull request #9142: BSR optimization in TOPI

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


   Hi @elphinkuo, I implemented sparse matrix multiplication for the GPU in TVM. I can help review and provide feedback. You've marked this PR as a draft, do you want it reviewed right now or should I wait?


-- 
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] elphinkuo commented on pull request #9142: BSR optimization in TOPI

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


   > Hi @elphinkuo, I implemented sparse matrix multiplication for the GPU in TVM. I can help review and provide feedback. You've marked this PR as a draft, do you want it reviewed right now or should I wait?
   
   Thanks a lot for the quick reply! @tkonolige   We may improve this PR shortly and it is good to review at that time.


-- 
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] elphinkuo commented on a change in pull request #9142: BSR optimization in TOPI

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