areusch commented on a change in pull request #8023:
URL: https://github.com/apache/tvm/pull/8023#discussion_r638107204



##########
File path: src/relay/backend/aot_executor_codegen.cc
##########
@@ -564,21 +582,21 @@ class AOTExecutorCodegen : public ExprVisitor {
 
  public:
   AOTExecutorCodegen(runtime::Module* mod, const TargetsMap& targets, Target 
target_host)
-      : mod_(mod), return_sid_() {
+      : mod_(mod), use_typed_operators_(true) {

Review comment:
       why do you double-initialize?

##########
File path: src/driver/driver_api.cc
##########
@@ -200,8 +200,15 @@ std::pair<IRModule, IRModule> SplitDevHostFuncs(IRModule 
mod_mixed, const Target
   mixed_pass_list.push_back(tir::transform::ThreadSync("warp"));
   mixed_pass_list.push_back(tir::transform::InferFragment());
   mixed_pass_list.push_back(tir::transform::LowerThreadAllreduce());
-  mixed_pass_list.push_back(tir::transform::MakePackedAPI(0));
+
+  if (target->GetAttr<Bool>("typed-operators").value_or(Bool(true))) {

Review comment:
       at the Target level, `--typed-operators` reads pretty generically and 
could imply something like "operator + is aware of the types of its arguments." 
but that's always true.
   
   i'd suggest two modifications:
   1. given we are abusing Target to hold runtime-specific information, let's 
choose a name for which the default 0 value preserves the existing behavior. 
`--typed-operators` defaults `true` here, but we can't document that properly 
(in `target_kind.cc`) since we are abusing Target.
   2. let's choose a more specific name, such as 
`--dltensor-only-function-signatures`. or alternatively, something that 
references "call_unpacked," maybe `--unpacked-api`? i don't know that 
`--typed-signatures` fully encapsulates the effect of the flag, since it not 
only removes `type_code` but also assumes there is a `DLTensor` for each 
argument.

##########
File path: src/tir/transforms/make_unpacked_api.cc
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file make_unpacked_api.cc Lower PrimFunc to a standard C function API.
+ */
+#include <tvm/runtime/container.h>
+#include <tvm/runtime/device_api.h>
+#include <tvm/runtime/registry.h>
+#include <tvm/target/target.h>
+#include <tvm/tir/analysis.h>
+#include <tvm/tir/buffer.h>
+#include <tvm/tir/builtin.h>
+#include <tvm/tir/expr.h>
+#include <tvm/tir/stmt_functor.h>
+#include <tvm/tir/transform.h>
+
+#include <unordered_set>
+#include <utility>
+#include <vector>
+
+#include "arg_binder.h"
+#include "ir_utils.h"
+
+namespace tvm {
+namespace tir {
+
+PrimFunc MakeUnpackedAPI(PrimFunc&& func) {
+  auto global_symbol = func->GetAttr<String>(tvm::attr::kGlobalSymbol);
+  ICHECK(global_symbol) << "MakeUnpackedAPI: Expect PrimFunc to have the 
global_symbol attribute";
+
+  auto target = func->GetAttr<Target>(tvm::attr::kTarget);
+  ICHECK(target.defined()) << "MakeUnpackedAPI: Require the target attribute";
+
+  auto* func_ptr = func.CopyOnWrite();
+
+  // Setup device context
+  int target_device_type = target.value()->kind->device_type;
+  Integer device_type(target_device_type);
+  Integer device_id(0);
+  PrimExpr node = StringImm("default");
+  const Stmt nop = Evaluate(0);
+  std::vector<Stmt> device_init;
+
+  // Create arg to buffer binder
+  std::unordered_map<const VarNode*, PrimExpr> vmap;
+  ArgBinder binder(&vmap);
+
+  // Collect variables and buffers to map between
+  Array<Var> args;
+  std::vector<std::pair<Var, Var>> var_def;
+  std::vector<std::pair<Var, Buffer>> buffer_def;
+
+  for (int i = 0; i < static_cast<int>(func_ptr->params.size()); ++i) {
+    Var param = func_ptr->params[i];

Review comment:
       i'm not sure if we should ICHECK on the parameter type 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.

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


Reply via email to