This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch refactor-s1 in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 71d119c1364aa76b0a5bd67c2cae5efb777733f6 Author: tqchen <[email protected]> AuthorDate: Sun Apr 13 16:23:26 2025 -0400 [FFI] 32bit robustness --- ffi/include/tvm/ffi/type_traits.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ffi/include/tvm/ffi/type_traits.h b/ffi/include/tvm/ffi/type_traits.h index cc913b2a9e..7ec340f59a 100644 --- a/ffi/include/tvm/ffi/type_traits.h +++ b/ffi/include/tvm/ffi/type_traits.h @@ -397,11 +397,14 @@ struct TypeTraits<DLTensor*> : public TypeTraitsBase { return static_cast<DLTensor*>(src->v_ptr); } else if (src->type_index == TypeIndex::kTVMFFINDArray) { // Conversion from NDArray pointer to DLTensor - // we rely on the fact that NDArray DLTensor field immediately - // follows the object header - // TODO(tqchen): followup once we bring NDArray related containers to FFI. - return reinterpret_cast<DLTensor*>(reinterpret_cast<char*>(src->v_obj) + - sizeof(TVMFFIObject)); + // use temp struct so we can calculate ABI offset on 32/64 bit platforms. + // TODO(tqchen): followup once we bring NDArray related containers to FFI + // and move DLTensor* to the right place. + struct Temp { + TVMFFIObject header; + DLTensor dl_tensor; + }; + return &(reinterpret_cast<Temp*>(src->v_obj)->dl_tensor); } return std::nullopt; }
