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 2022/08/24 11:32:05 UTC

[GitHub] [tvm] mbaret commented on a diff in pull request #12550: [AOT] Add AOTLowerMain pass to lower a Relay main into TIR

mbaret commented on code in PR #12550:
URL: https://github.com/apache/tvm/pull/12550#discussion_r953678416


##########
tests/python/relay/aot/test_pass_aot_lower_main.py:
##########
@@ -0,0 +1,435 @@
+# 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.
+import tvm
+import tvm.testing
+from tvm.script import tir as T
+from tvm.relay.backend.aot import AOTLowerMain, CallType
+
+import numpy as np
+import pytest
+
+
+def make_const(dtype, shape):
+    return tvm.relay.const(np.zeros(shape).astype(dtype))
+
+
+def make_consts(dtype, shapes):
+    return [make_const(dtype, shape) for shape in shapes]
+
+
+def transform(mod):
+    host_target = tvm.target.Target("llvm")
+    prim_target = tvm.target.Target("llvm", host=host_target)
+    ctxt = tvm.transform.PassContext()
+    config = tvm.target.make_compilation_config(ctxt, prim_target)
+    mod = tvm.relay.transform.PlanDevices(config)(mod)
+    mod = tvm.relay.transform.InferType()(mod)
+    if mod.get_attr("device_contexts") is None:

Review Comment:
   The idea with this is that if you add it in a test it won't be overwritten, but if you don't add it then it'll get set to a sensible default. I agree hiding this logic in a helper func reduces test clarity though, so will look into a more explicit function (or see below...)
   
   side note: I really hate these magic attributes in the compiler and they make tests unnecessarily hard to follow by essentially 'cheating' the IRModule->IRModule property. I'm going to take another look at the refactored pass to see if either I can make `device_contexts` an explicit argument to initialize the pass, or derive it from the IRModule directly.



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