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: [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]