NicolaLancellotti commented on a change in pull request #10344:
URL: https://github.com/apache/tvm/pull/10344#discussion_r816961090



##########
File path: python/tvm/relay/backend/contrib/ethosu/tir/passes.py
##########
@@ -64,13 +65,16 @@ def ReplaceOperators():
         "ethosu_identity": get_identity_params,
         "ethosu_unary_elementwise": get_unary_elementwise_params,
     }
-    pointer_to_producer = {}
-    pointer_to_consumer = {}
+    producers_consumers = ProducersConsumers()
     replace_output_pointer = {}
     pointer_to_extents = {}
 
     ReplaceInfo = namedtuple("ReplaceInfo", ["pointer", "reallocate"])
 
+    def _pointer_to_extend(stmt):

Review comment:
       Done.

##########
File path: python/tvm/relay/backend/contrib/ethosu/tir/producers_consumers.py
##########
@@ -0,0 +1,77 @@
+# 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
+"""The ProducersConsumers class"""
+from typing import Optional
+from collections.abc import KeysView
+import tvm
+
+
+class ProducersConsumers:
+    """It associates pointers with the loop nest that produces
+    their values and with the loop nest that consumes their values."""
+
+    def __init__(self) -> None:
+        self.indices: dict[tvm.tir.AttrStmt, int] = {}
+        self.producers: list[(tvm.tir.AttrStmt, tvm.tir.expr.Var)] = []
+        self.consumers: list[(tvm.tir.AttrStmt, list[tvm.tir.expr.Var])] = []
+
+    def add_producer(self, var: tvm.tir.expr.Var, attr: tvm.tir.AttrStmt) -> 
None:
+        """Add the attribute statement attr as producer of the variable var."""
+        self.indices[attr] = len(self.producers)
+        self.producers.append((attr, var))
+
+    def get_producer(
+        self, var: tvm.tir.expr.Var, attr: tvm.tir.AttrStmt
+    ) -> Optional[tvm.tir.AttrStmt]:
+        """Get the last attribute statement which produces the variable var 
when
+        the current attribute statement is attr."""
+        if var not in self.allocate_variables:
+            return None
+
+        index = self.indices[attr]
+        for i in list(reversed(range(index + 1))):
+            if self.producers[i][1] == var:
+                return self.producers[i][0]
+        return None
+
+    def get_last_producer(self, var: tvm.tir.expr.Var) -> 
Optional[tvm.tir.AttrStmt]:
+        """Get the last attribute statement which produces the variable var."""
+        return self.get_producer(var, self.producers[-1][0])
+
+    def add_allocate_variables(self, allocate_variables: KeysView) -> None:
+        """Add the allocated variables."""
+        self.allocate_variables = allocate_variables

Review comment:
       Done.

##########
File path: python/tvm/relay/backend/contrib/ethosu/tir/transform.py
##########
@@ -21,19 +21,16 @@
 from .utils import get_base_address, get_op_attrs
 
 
-def get_copy_params(stmt, producers, consumers):
+def get_copy_params(stmt, producers_consumers):

Review comment:
       No, we cannot. All functions in `ReplaceOperators`'s `op_map` must have 
the same signature.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to