[Runtime] Introduce runtime module property#14406
Conversation
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment. Generated by tvm-bot |
| */ | ||
| namespace property { | ||
| /*! \brief Binary serializable runtime module */ | ||
| constexpr const uint8_t kBinarySerializable = 0b001; |
There was a problem hiding this comment.
let us use int to keep things simple, make it an enum
enum class ModulePropertyMask : int
There was a problem hiding this comment.
Used enum ModulePropertyMask : int instead for implicit casting.
echuraev
left a comment
There was a problem hiding this comment.
Thank you for the PR. I have one question. Where is it planned to use these properties? In this PR I see only adding these properties but no use-cases. Probably a simple unit test will be helpful to understand what should be achieved after enabling these properties.
|
I think a good first step is to replace the current usage of the IsDSOExportable in the module.export_library using the flag, and report error when we encounter something that is neither DSOExportable or BinarySerializable |
|
Thank you, @echuraev for the review. As @tqchen pointed out, this PR changes the way we achieve the same functionality but with a more refined manner. This PR was motivated by the discussion in my outstanding PR #14337 about roundtrip-abilty and with this change, we can offer more systematic error message when we cannot guarantee this. I initially thought passing the existing tests would be sufficient since it does not introduce any new behavior or feature. But, if you think it is still good to have a unit test about it, I can definitely add one. :) |
|
@sunggg Thank you for your reply! It is a nice summary and the reason why we did it starts to be much clearer for me. I'm ok with current tests but agree with @junrushao that creating some documentation might be very useful. |
|
@junrushao @echuraev Thank you for the suggestion. Addition to the official tutorial also sounds great to me. By reflecting @tqchen's suggestion, I also added some unit tests and assertion in export_library. |
383be34 to
8dc164e
Compare
|
@tvm-bot rerun |
Following apache#14406, this PR adds the runtime module property mask for Metal and Vulkan backend, which were left before.
Following apache#14406, this PR adds the runtime module property mask for Metal and Vulkan backend, which were left before.
Following #14406, this PR adds the runtime module property mask for Metal and Vulkan backend, which were left before.
…kan (apache#14524) (apache#180) Following apache#14406, this PR adds the runtime module property mask for Metal and Vulkan backend, which were left before.
…kan (apache#14524) (apache#180) Following apache#14406, this PR adds the runtime module property mask for Metal and Vulkan backend, which were left before.
Currently, we only classify whether the runtime module is DSO-exportable.
This PR further classifies each runtime module into the properties as follows:
kBinarySerializable: we can serialize the module to the stream of bytes. CUDA/OpenCL/JSON runtime are representative examples.kRunnable: we can run the module directly. LLVM/CUDA/JSON runtime, executors (e.g, virtual machine) runtimes are runnable. Non-runnable modules, such as CSourceModule, requires a few extra steps (e.g,. compilation, link) to make it runnable.kBinaryExportable: when the module is kBinarySerializable and kRunnable, we consider this module as binary exportable. A binary exportable module can be integrated into final runtime artifact by being serialized as data into the artifact, then deserialzied at runtime. This class of modules must implementSaveToBinary, and have a matching deserializer registered asruntime.module.loadbinary_<type_key>.kDSOExportable: we can export the module as DSO. A DSO exportable module (e.g., a CSourceModuleNode of type_key 'c') can be incorporated into the final runtime artifact (ie shared library) by compilation and/or linking using the external compiler (llvm, nvcc, etc). DSO exportable modules must implementSaveToFile.Please note that
kDSOExportableis a mutual exclusive property withkBinaryExportable.To represent each category, the following status bits are defined.
Edit based on the review
This PR further classifies each runtime module into the properties as follows:
kBinarySerializable: we can serialize the module to the stream of bytes. CUDA/OpenCL/JSON runtime are representative examples. A binary exportable module can be integrated into final runtime artifact by being serialized as data into the artifact, then deserialized at runtime. This class of modules must implementSaveToBinary, and have a matching deserializer registered asruntime.module.loadbinary_<type_key>.kRunnable: we can run the module directly. LLVM/CUDA/JSON runtime, executors (e.g, virtual machine) runtimes are runnable. Non-runnable modules, such asCSourceModule, requires a few extra steps (e.g,. compilation, link) to make it runnable.kDSOExportable: we can export the module as DSO. A DSO exportable module (e.g., aCSourceModuleNodeof type_key 'c') can be incorporated into the final runtime artifact (ie shared library) by compilation and/or linking using the external compiler (llvm, nvcc, etc). DSO-exportable modules must implementSaveToFile. In general, DSO exportable modules are not runnable unless there is a special support like JIT forLLVMModule.To represent each category, the following status bits are defined.
cc. @tqchen