TVM AOT C+BYOC compilation fails with `expected str but got Object`

Thanks for the additional information @JosseVanDelm ! It looks like one of the runtime::Module being exported in your compilation flow doesn’t implement get_symbol correctly. You might take a look at some gdb extensions developed by the community to help you inspect ObjectRef a bit more.

Here’s how i would debug this, though:

  • auto pf_sym = mod.GetFunction("get_symbol"); is looking up a PackedFunc inside the runtime::Module named mod. In effect his invokes a C++ function void GetFunction(std::string) on that Module.
  • GetFunction is expected to return a PackedFunc which is placed in pf_sym.
  • pf_sym() invokes the PackedFunc, passing 0 arguments (because PackedFunc args are always placed inside a C++ TVMArgs args array, the PackedFunc call will always have the same C++ signature unless implemented using TypedPackedFunc sugar).
  • To properly debug this, we need to find out which subclass of runtime::Module is in use here. The easiest way to do that is by inspecting ModuleNode::type_key(), which you should be able to do either with logging or from GDB: p mod->type_key().
  • From there, locate the GetFunction implementation for that Module. That function should contain a large if-else block:
    if (name == "get_const_var") {
      return PackedFunc([](TVMArgs args, TVMRetValue* rv) { ... });
    } else if (name == "get_...") { 
      return PackedFunc([](TVMArgs args, TVMRetValue* rv) { ... });
    } ...
    
  • The branch which implements get_symbol probably is returning a PackedFunc which itself doesn’t return a string. Fix that and I think it should unbreak you.