You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "echuraev (via GitHub)" <gi...@apache.org> on 2026/07/01 20:48:42 UTC
[PR] [Metal] Let compile callback declare payload format via (payload, fmt) [tvm]
echuraev opened a new pull request, #19924:
URL: https://github.com/apache/tvm/pull/19924
A tvm_callback_metal_compile used purely for debugging/inspection may return the MSL source unchanged. Previously, merely registering the callback forced the module format to "metallib", so the runtime tried to load the text source as a binary metallib and failed with "Invalid library file" (issue #18798).
The callback may now return a (payload, format) pair to declare the payload format. A bare str/bytes return keeps the legacy metallib behavior. All kernels of a module share a single declared format, so a callback that mixes formats across kernels (including a legacy metallib return alongside a (payload, "metal") return) is rejected at codegen time instead of producing a module that fails to load.
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Metal] Let compile callback declare payload format via (payload, fmt) [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #19924:
URL: https://github.com/apache/tvm/pull/19924
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Metal] Let compile callback declare payload format via (payload, fmt) [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19924:
URL: https://github.com/apache/tvm/pull/19924#discussion_r3508983567
##########
src/backend/metal/codegen/codegen_metal.cc:
##########
@@ -495,7 +498,32 @@ ffi::Module BuildMetal(IRModule mod, Target target) {
std::string fsource = cg.Finish();
source_maker << fsource << "\n";
if (fmetal_compile) {
- fsource = (*fmetal_compile)(fsource, target).cast<std::string>();
+ ffi::Any ret = (*fmetal_compile)(fsource, target);
+ // Backward-compatible contract for tvm_callback_metal_compile:
+ // * returning a str/bytes -> treated as a compiled metallib payload
+ // * returning (payload, fmt) -> the callback declares the payload format
+ std::string kernel_fmt;
+ if (auto ret_tuple = ret.try_cast<ffi::Array<ffi::Any>>()) {
+ TVM_FFI_ICHECK_EQ(ret_tuple->size(), 2)
+ << "tvm_callback_metal_compile must return either a payload or a "
+ "(payload, format) pair, but got a tuple of size "
+ << ret_tuple->size();
+ fsource = (*ret_tuple)[0].cast<std::string>();
+ kernel_fmt = (*ret_tuple)[1].cast<std::string>();
+ TVM_FFI_ICHECK(kernel_fmt == "metal" || kernel_fmt == "metallib")
+ << "tvm_callback_metal_compile returned unsupported format \"" << kernel_fmt
+ << "\"; expected \"metal\" or \"metallib\"";
+ } else {
+ // Backwaard-compatible behavior
Review Comment:

There is a typo in the comment: "Backwaard-compatible" should be "Backward-compatible".
```suggestion
// Backward-compatible behavior
```
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org