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 2021/09/14 17:15:20 UTC

[GitHub] [tvm] Mousius commented on a change in pull request #8423: Implementation of relay_to_tir target hook

Mousius commented on a change in pull request #8423:
URL: https://github.com/apache/tvm/pull/8423#discussion_r708476290



##########
File path: src/relay/backend/te_compiler.cc
##########
@@ -185,16 +192,25 @@ class TECompilerImpl : public TECompilerNode {
     }
     cur_ccache_key_ = key;
 
-    // No need to lower external functions for now. We will invoke the external
-    // codegen tool once and lower all functions together.
     if (key->source_func->GetAttr<String>(attr::kCompiler).defined()) {
       auto ir_module = IRModule();
       const auto name_node = key->source_func->GetAttr<String>(tvm::attr::kGlobalSymbol);
       ICHECK(name_node.defined()) << "External function has not been attached a name yet.";
+
       auto func_name = GetUniqueName(name_node.value(), &name_map_);
       auto target = Target("ext_dev");
       auto global_var = GlobalVar(func_name);
       global_var->checked_type_ = key->source_func->checked_type();
+
+      auto code_gen_name = key->source_func->GetAttr<String>(attr::kCompiler).value();
+      auto target_kind = tvm::TargetKind::Get(code_gen_name);
+      auto custom_lowering_to_tir =
+          target_kind ? target_kind.value().GetRegisteredHook("relay_to_tir") : nullptr;
+      if (custom_lowering_to_tir != nullptr) {
+        target = key->target;
+        ir_module->Update((*custom_lowering_to_tir)(key->source_func, key->target));
+      }
+

Review comment:
       Regarding the `Target`, is your proposal an `AnnotateTargets` pass which goes through `device_context_map_` and annotates all the call sites ahead of `LowerTE` and other passes? If this was just implemented for `Call` would that be sufficient for current `LowerTE` ? We'd still need to explicitly annotate `host_target` on the `IRModule`.
   
   The `relay_to_runtime` in https://github.com/apache/tvm-rfcs/pull/10/files registers the external codegen (code name BYOC) as `Target` hooks and then it's a matter of changing `kCompiler` to `kTarget`, so I think that's included in implementation of that RFC :smile_cat: 




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