Lunderberg commented on code in PR #16642:
URL: https://github.com/apache/tvm/pull/16642#discussion_r1504424495


##########
src/relax/transform/compute_prim_value.cc:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+
+#include <tvm/relax/expr_functor.h>
+#include <tvm/relax/transform.h>
+#include <tvm/tir/analysis.h>
+#include <tvm/tir/builtin.h>
+#include <tvm/tir/stmt_functor.h>
+
+namespace tvm {
+namespace relax {
+
+namespace {
+
+class PrimValueComputeInjector : public ExprMutator {
+ public:
+  IRModule Finalize() const { return builder_->Finalize(); }
+
+  using ExprMutator::VisitExpr_;
+
+  Expr VisitExpr_(const PrimValueNode* op) override {
+    auto node = Downcast<PrimValue>(ExprMutator::VisitExpr_(op));
+
+    if (node->value->IsInstance<tir::IntImmNode>() || 
node->value->IsInstance<tir::VarNode>()) {
+      return node;
+    }
+
+    auto ret_dtype = node->value->dtype;
+    auto param_vars = tir::UndefinedVars(node->value);

Review Comment:
   This call isn’t aware of the Relax scoping rules, but I don’t think there’s 
a benefit of checking it at this point.  Any well-formed input that only uses 
in-scope TIR variables would produce well-formed output.  Any ill-formed input 
that uses out-of-scope TIR variables would produce ill-formed output that still 
uses the out-of-scope TIR variables.
   
   Validating the relax scoping rules at this point would require additional 
tracking the in-scope variables, which would duplicate the functionality of the 
well-formed checker.  Since this pass wouldn’t make any ill-formed usage worse 
(and therefore harder to debug), I don’t think it’s worth duplicating the 
in-scope tracking here.



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