hi @jossevandelm,
no problem–this part of the compiler is a bit confusing. though the thing you are debugging is runtime::Module, CSourceModuleNode is a compiler-only data structure that holds C source code which needs to be compiled before it can be run. See Introduce Artifact, a container for generated code for a discussion about why there are runtime::Module here.
However, I don’t understand how I can find which PackedFunc is being constructed or in which way this is constructed.
This can be confusing, and it’s pretty hard to identify the PackedFunc unless you either:
- determine the arguments to the
GetFunction()call that produced it - step into the PackedFunc and see where it jumps to
1 is probably easiest.
I don’t get what the packedfunc at this point in the compilation progress is supposed to do? As I get it, it should just output C code in some string stream? No?
In this case, get_symbol is not a function invoked at runtime–instead it’s invoked during compilation (as you see) to feed data into the ConstLoaderModule. The return value of get_symbol should mostly be null, unless, on initialization, a runtime::Module needs to deserialize some NDArray. If so, get_symbol can return the name of a PackedFunc in that runtime::Module which should be called (prefixed with __init_) with the values returned from get_const_vars (those values extracted at compile time). This use is a bit of an overloading of the runtime::Module interface.
In practice this all applies when using code with the TVM C++ runtime and we don’t currently export any runtime::Module to the C runtime which are expected to use this interface (although CSourceModuleNodeimplements it, I don't believe it's actually used by thec` backend).
Correct. There is only one load path for CSourceModule from the C++ runtime’s POV (export, compile, load_library). This makes it a bit confusing to understand how the compiler generates these, since runtime::Module looks like it’s meant for the runtime when it’s really not (immediately) meant for it.
You only need to implement GetFunction if you are creating a new subclass of ModuleNode. So, you shouldn’t for CSourceModuleNode. Based on reading the code, it seems like func_names[0] is actually a different ObjectRef than String there–so perhaps see if you can figure out why that is.
hope this helps! Andrew