FrozenGene commented on a change in pull request #4847: Return empty
CSourceModule when no lowered_funcs exists in Relay mod
URL: https://github.com/apache/incubator-tvm/pull/4847#discussion_r380467063
##########
File path: src/relay/backend/build_module.cc
##########
@@ -437,28 +441,51 @@ class RelayBuildModule : public runtime::ModuleNode {
ret_.params = graph_codegen_->GetParams();
auto lowered_funcs = graph_codegen_->GetLoweredFunc();
+
+ // When there is no lowered_funcs due to reasons such as optimization,
+ // we first try to generate a dummy one if the target host is "llvm".
if (lowered_funcs.size() == 0) {
- LOG(WARNING) << "no lowered funcs exist in the compiled module";
+ // Decide first the target host
+ Target target_host_val = target_host_;
+ if (!target_host_.defined()) {
+ for (const auto &it : targets_) {
+ if (it.second->device_type == kDLCPU) {
+ target_host_val = it.second;
+ break;
+ }
+ }
+ }
+
+ // If no target_host has been set, we choose a default one, which is
+ // llvm if "codegen.build_llvm" is accessible.
+ const runtime::PackedFunc* pf =
runtime::Registry::Get("codegen.build_llvm");
+ if (!target_host_val.defined())
+ target_host_val = (pf != nullptr) ? target::llvm() : target::stackvm();
+
+ if (target_host_val.defined() && target_host_val->target_name == "llvm")
+ lowered_funcs.Set(
+ target_host_val->str(),
+ Array<LoweredFunc>({
+ MakeAPI(EvaluateNode::make(0), "__dummy__", Array<ObjectRef>(),
0, false) }));
Review comment:
Add one `__dummy__` is not elegant solution IMO. If we have this LLVM IR:
```
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.14.0"
```
Does this satisfy your need?
If it is, I think we could create one packed function in `llvm_module.cc`.
We could create this kind of empty llvm module. Then we could have`ret_.mod =
tvm::codegen::LLVMModuleCreate...` like CSourceModuleCreate.
----------------------------------------------------------------
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]
With regards,
Apache Git Services