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/03/30 00:21:34 UTC

[GitHub] [tvm] junrushao1994 commented on a change in pull request #7765: [M1b] Scaffolding ScheduleState data structure

junrushao1994 commented on a change in pull request #7765:
URL: https://github.com/apache/tvm/pull/7765#discussion_r603696615



##########
File path: python/tvm/tir/schedule/block_scope.py
##########
@@ -0,0 +1,154 @@
+# 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.
+"""Definition of two pillar data structure for TensorIR scheduling: StmtSRef, BlockScope."""
+from __future__ import annotations
+
+from enum import IntEnum
+from typing import List, Optional, Union
+
+from tvm._ffi import register_object
+from tvm.runtime import Object
+from tvm.tir import Block, For
+
+from . import _ffi_api_schedule
+
+
+@register_object("tir.StmtSRef")
+class StmtSRef(Object):
+    """An object that refers to schedulable elements in the TensorIR, aka "sref".
+
+    Glossary
+    - Block sref: An StmtSref that points to a TensorIR block.
+    - Loop sref: An StmtSRef that points to a TensorIR for loop.
+    - Parent sref: The parent sref of an sref is the block/loop sref that points to its closest
+    schedulable statement of its ancestors on the TensorIR AST.
+    - Root sref: Sref to the root block. Every sref has exactly one parent sref
+    except for root sref.
+    - Sref tree: The parent-children-relationship of srefs that forms a tree,
+    uniquely determined by the TensorIR AST.
+    """
+
+    seq_index: int
+
+    @property
+    def stmt(self) -> Optional[Union[Block, For]]:
+        """The block/for stmt the object refers to"""
+        return _ffi_api_schedule.StmtSRefStmt(self)  # pylint: disable=no-member
+
+    @property
+    def parent(self) -> Optional[StmtSRef]:
+        """The parent sref"""
+        return _ffi_api_schedule.StmtSRefParent(self)  # pylint: disable=no-member
+
+    @staticmethod
+    def inline_mark() -> StmtSRef:
+        """A special StmtSRef, which doesn't point to any stmt in the AST,
+        only serving as a "mark" to hint compute-at to do the work of compute-inline"""
+        return _ffi_api_schedule.StmtSRefInlineMark()  # pylint: disable=no-member
+
+    @staticmethod
+    def root_mark() -> StmtSRef:
+        """A special StmtSRef, which doesn't point to any stmt in the AST,
+        only serving as a "mark" to hint compute-at to do nothing"""
+        return _ffi_api_schedule.StmtSRefRootMark()  # pylint: disable=no-member
+
+
+class DepKind(IntEnum):
+    """Type of dependency.
+
+    Attributes
+    ----------
+    RAW : int = 0
+        Read-after-write dependency
+    WAW : int = 1
+        Write-after-write dependency
+    WAR : int = 2
+        Write-after-read dependency. Not supported in TensorIR for now.
+    OPAQUE: int = 3
+        Opaque dependency
+    """
+
+    RAW = 0
+    WAW = 1
+    WAR = 2
+    OPAQUE = 3

Review comment:
       1. This is a slot we left for future "unknown" dependencies. Right now the codebase doesn't use this kind of dependency yet.
   2. Strictly speaking read-after-read is not a dependency, so we didn't have a slot for it right now




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