spectrometerHBH commented on a change in pull request #6227:
URL: https://github.com/apache/incubator-tvm/pull/6227#discussion_r467515790



##########
File path: python/tvm/hybrid/scope_handler.py
##########
@@ -0,0 +1,91 @@
+# 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.
+"""Hybrid Script Parser Scope Handler Functions
+
+This module provides the functions registered into parser under with_scope or 
for_scope category.
+Scope handler nodes are StmtNodes with body, which are used to handle such 
scenarios.
+
+.. code-block:: python
+
+    for x in tir.name():
+    with tir.name():
+    tir.name() # with scope handlers + concise scoping
+
+"""
+# pylint: disable=redefined-builtin, unused-argument, invalid-name
+import tvm.tir
+from .registry import register_scope_handler
+from .registry import Category
+
+# With scope handler
+
+
+@register_scope_handler(Category.WITH_SCOPE, concise=False)
+def Assert(parser, node, condition, message, body):
+    """ With scope handler function assert(condition, message, body) """
+
+    return tvm.tir.AssertStmt(condition, tvm.runtime.convert(message), body)
+
+
+@register_scope_handler(Category.WITH_SCOPE, concise=False)
+def let(parser, node, var, value, body):
+    """ With scope handler function let(var, value, body) """
+
+    return tvm.tir.LetStmt(var, value, body)
+
+
+@register_scope_handler(Category.WITH_SCOPE, concise=True)
+def realize(parser, node, buffer_bounds, body, condition=True):
+    """ With scope handler function realize(buffer_bounds, condition, body) """
+
+    buffer, bounds = buffer_bounds
+    return tvm.tir.BufferRealize(buffer, bounds, condition, body)
+
+
+@register_scope_handler(Category.WITH_SCOPE, concise=True)
+def attr(parser, node, attr_node, attr_key, value, body):
+    """ With scope handler function attr(attr_node, attr_key, value, body) """
+
+    return tvm.tir.AttrStmt(attr_node, attr_key, tvm.runtime.convert(value), 
body)
+
+
+@register_scope_handler(Category.WITH_SCOPE, concise=True)
+def allocate(parser, node, buffer_var, dtype, extents, body, condition=True):
+    """ With scope handler function allocate(buffer_var, dtype, extents, 
condition, body) """
+
+    return tvm.tir.Allocate(buffer_var, dtype, extents, 
tvm.runtime.convert(condition), body)
+
+
+# For scope handler
+
+
+@register_scope_handler(Category.FOR_SCOPE)
+def range(parser, node, begin, end, for_type="serial"):

Review comment:
       Yes. That's what I mean.




----------------------------------------------------------------
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:
[email protected]


Reply via email to