[Module] Implement custom imported modules serialization #15666
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a module with imported modules is exported into a shared library, the imported modules are serialized and embedded inside of that library. This is done by generating a raw binary from the imported modules, which is then assigned to a symbol
__tvm_dev_mblobin the final shared library.The way it happens for targets that are not "llvm", is by creating a C source file, and defining a statically-initialized array
__tvm_dev_mblobin it. The static initializer is the byte-by-byte hexadecimal representation of the serialized modules. While working with Hexagon, this has presented us with two issues:This PR allows users to provide a custom serialization routine to
Module.export_library. We then apply it in Hexagon to build the ELF object file with__tvm_dev_mblobby using the objcopy tool from the Hexagon toolchain. This bypasses the C compilation altogether, avoiding both of the issues.Using the same custom mechanism, similar method can be implemented for many other targets which have utilities to manipulate object files directly.