[Python] Support 32-bit host pointers in DLPack export (#25164) the pointer-size assertion rejects a 32-bit host even when the exported address fits. Replace it with a runtime check that the address plus offset fits the host pointer width. --------- Signed-off-by: anutosh491 <andersonbhat491@gmail.com>
diff --git a/runtime/bindings/python/hal.cc b/runtime/bindings/python/hal.cc index b07e286..aa1cd1e 100644 --- a/runtime/bindings/python/hal.cc +++ b/runtime/bindings/python/hal.cc
@@ -13,7 +13,9 @@ #include <algorithm> #include <iterator> +#include <limits> #include <optional> +#include <stdexcept> #include <utility> #include "./local_dlpack.h" @@ -771,8 +773,12 @@ alloc, buffer, IREE_HAL_EXTERNAL_BUFFER_TYPE_DEVICE_ALLOCATION, IREE_HAL_EXTERNAL_BUFFER_FLAG_NONE, &external_buffer), "Cannot export device buffer"); - static_assert(sizeof(dl_tensor.data) >= - sizeof(external_buffer.handle.device_allocation.ptr)); + constexpr auto max_address = std::numeric_limits<uintptr_t>::max(); + if (offset > max_address || + external_buffer.handle.device_allocation.ptr > max_address - offset) { + throw std::overflow_error( + "DLPack device address does not fit a host pointer"); + } // Set the data pointer to the offset, and the byte_offset to 0. // This SHOULD not be required, but some backends (torch GPU for example), // ignore the byte_offset entirely.