lucifer1004 opened a new pull request, #591:
URL: https://github.com/apache/tvm-ffi/pull/591
## Summary
Promotes the existing internal `LoadModuleFromBytes(kind, bytes)`
helper (`src/ffi/extra/library_module.cc`) to a public `Module` API,
registers it as the `ffi.ModuleLoadFromBytes` global, and adds the
matching Rust binding.
The internal helper has been around for a while as a C++ free function
used during binary deserialization. There was no public-API entry point
and no Rust / Python wrapper, so callers who already hold module
payload in memory (e.g. a PTX or CUBIN blob fetched from a registry)
had to materialize it to disk first and then go through
`ModuleLoadFromFile`.
## Changes
- `include/tvm/ffi/extra/module.h`: declares
`Module::LoadFromBytes(const String& kind, const Bytes& bytes)`.
- `src/ffi/extra/library_module.cc`: defines it as a thin wrapper
around the existing `LoadModuleFromBytes`.
- `src/ffi/extra/module.cc`: registers `ffi.ModuleLoadFromBytes` in
the static-init block alongside `ffi.ModuleLoadFromFile`.
- `rust/tvm-ffi/src/extra/module.rs`: adds
`tvm_ffi::Module::load_from_bytes(kind, bytes)` mirroring the
existing `load_from_file`.
The dispatch through `ffi.Module.load_from_bytes.<kind>` is unchanged;
existing loaders register exactly as before. The new API just gives
non-C++ callers a way in.
## Motivation
Use case: a project that fetches CUDA PTX / CUBIN payloads from a
registry already has the bytes in memory. The current
`Module::LoadFromFile` path forces a tempfile detour. With this API:
\`\`\`python
import tvm_ffi
mod = tvm_ffi.Module.load_from_bytes(\"cubin\", cubin_bytes)
fn = mod.get_function(\"my_kernel\")
\`\`\`
Or from Rust:
\`\`\`rust
let module = tvm_ffi::Module::load_from_bytes(\"cubin\", &bytes)?;
\`\`\`
## Test plan
- [x] Built locally; `apache-tvm-ffi 0.1.dev541+g<sha>` registers
`ffi.ModuleLoadFromBytes` correctly:
\`\`\`python
>>> import tvm_ffi
>>> tvm_ffi.get_global_func(\"ffi.ModuleLoadFromBytes\") is not None
True
\`\`\`
- [x] Existing `ffi.ModuleLoadFromFile` global continues to work.
- [x] Rust crate compiles + `Module::load_from_bytes` callable.
- [ ] A CUDA-specific loader registered as
`ffi.Module.load_from_bytes.ptx` (separate follow-up; this PR
only adds the dispatching entrypoint).
## Stacked on top of #590
This branch is logically stacked on #590 (the Rust macro fixes).
GitHub's UI will show both commits in the PR diff until #590 merges;
once it does, this PR's diff collapses to just the
\`Module::LoadFromBytes\` commit. Reviewers who have already approved
#590 can skip the first commit here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]