[Module] Implement custom imported modules serialization#15666
Merged
tqchen merged 2 commits intoapache:mainfrom Sep 6, 2023
Merged
[Module] Implement custom imported modules serialization#15666tqchen merged 2 commits intoapache:mainfrom
tqchen merged 2 commits intoapache:mainfrom
Conversation
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_mblob` in 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_mblob` in it. The static initializer is the byte-by-byte hexadecimal represen- tation of the serialized modules. While working with Hexagon, this has presented us with two issues: 1. For most models, the embedded data is very large, taking significant amout of time to compile the auto-generated C source. 2. There are some models for which the C source size has exceeded clang's limits on the size of the input file, making it impossible to export the corresponding module. 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_mblob` by 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.
63e127a to
d641832
Compare
It seems like older toolchains may work as well, but the oldest supported SDK is 4.5.0.3, which contains toolchain version 8.5.08.
tqchen
approved these changes
Sep 6, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.