lucifer1004 opened a new pull request, #813:
URL: https://github.com/apache/tvm-ffi/pull/813

   
   ## Why
   
   C and C++ callers pass tensors to tvm-ffi functions as borrowed `DLTensor*` 
(`kTVMFFIDLTensorPtr`), which is also how C++ `TensorView` arguments are passed 
on. The Rust `Tensor` only accepts `ffi.Tensor` objects, so a Rust function 
exported with `tvm_ffi_dll_export_typed_func!` fails for those callers with 
`Cannot convert from type 'DLTensor*' to 'ffi.Tensor'`. Python callers are not 
affected, because they pass `ffi.Tensor`.
   
   ## What
   
   `tvm_ffi::TensorView` mirrors C++ `tvm::ffi::TensorView`:
   - it accepts `DLTensor*` and `ffi.Tensor` arguments and is passed on as a 
`DLTensor*`;
   - it is non-owning: it holds a pointer to the `DLTensor`, and the caller 
keeps the tensor alive, as in C++;
   - its accessors follow `Tensor`'s: `data_ptr`, `device`, `dtype`, `ndim`, 
`shape`, `numel`, `strides`, `is_contiguous`. `strides` panics on null strides, 
which DLPack forbids since v1.2, as C++ `TensorView::strides` checks.
   
   Typed functions require `'static` argument types, so the view carries no 
lifetime. The alternative, borrow-checked views of call arguments, would need 
changes to typed-function argument conversion and is left for a follow-up 
discussion.
   
   ## Tests
   
   `rust/tvm-ffi/tests/test_tensor_view.rs`: the same typed function called 
with a `DLTensor*` built as a C caller would and with an `ffi.Tensor`, 
rejection of other types, contiguity, and the null-strides panic. `cargo test` 
passes against libtvm_ffi built from `main`.
   
   Also checked end to end: a Rust `cdylib` exporting a CUDA kernel entry with 
`TensorView` arguments, called from C with `DLTensor*` and from Python with 
torch tensors.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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

Reply via email to