This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch refactor-s0 in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 5315cb9a3fd1919c9835a03d3c06dcacbeb60112 Author: tqchen <[email protected]> AuthorDate: Sun Mar 9 11:35:09 2025 -0400 Fix NDArray compile --- ffi/include/tvm/ffi/object.h | 2 +- include/tvm/runtime/container/shape_tuple.h | 2 +- include/tvm/runtime/ndarray.h | 21 +++++++++++---------- src/runtime/debug_compile.cc | 1 + 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ffi/include/tvm/ffi/object.h b/ffi/include/tvm/ffi/object.h index 4cb26f1c2b..a6f85be999 100644 --- a/ffi/include/tvm/ffi/object.h +++ b/ffi/include/tvm/ffi/object.h @@ -95,7 +95,7 @@ TVM_FFI_INLINE bool IsObjectInstance(int32_t object_type_index); * Which will automatically populate the type_index and deleter of the object. */ class Object { - private: + protected: /*! \brief header field that is the common prefix of all objects */ TVMFFIObject header_; diff --git a/include/tvm/runtime/container/shape_tuple.h b/include/tvm/runtime/container/shape_tuple.h index 1fb6248cc2..6532fe0fc9 100644 --- a/include/tvm/runtime/container/shape_tuple.h +++ b/include/tvm/runtime/container/shape_tuple.h @@ -48,7 +48,7 @@ class ShapeTupleObj : public Object { static constexpr const uint32_t _type_index = runtime::TypeIndex::kRuntimeShapeTuple; static constexpr const char* _type_key = "runtime.ShapeTuple"; - TVM_DECLARE_FINAL_OBJECT_INFO(ShapeTupleObj, Object); + TVM_FFI_DECLARE_STATIC_OBJECT_INFO(ShapeTupleObj, Object); private: /*! \brief ShapeTuple object which is moved from std::vector container. */ diff --git a/include/tvm/runtime/ndarray.h b/include/tvm/runtime/ndarray.h index fef61a7531..bd209f2c4c 100644 --- a/include/tvm/runtime/ndarray.h +++ b/include/tvm/runtime/ndarray.h @@ -308,7 +308,7 @@ class NDArray::Container : public Object, public NDArray::ContainerBase { /*! \brief default constructor */ Container() { // Initialize the type index. - type_index_ = Container::RuntimeTypeIndex(); + header_.type_index = Container::RuntimeTypeIndex(); dl_tensor.data = nullptr; dl_tensor.ndim = 0; dl_tensor.shape = nullptr; @@ -318,7 +318,7 @@ class NDArray::Container : public Object, public NDArray::ContainerBase { Container(void* data, ShapeTuple shape, DLDataType dtype, Device dev) { // Initialize the type index. - type_index_ = Container::RuntimeTypeIndex(); + header_.type_index = Container::RuntimeTypeIndex(); dl_tensor.data = data; shape_ = std::move(shape); dl_tensor.ndim = static_cast<int>(shape_.size()); @@ -332,19 +332,20 @@ class NDArray::Container : public Object, public NDArray::ContainerBase { * \brief Set the deleter field. * \param deleter The deleter. */ - void SetDeleter(FDeleter deleter) { deleter_ = deleter; } + void SetDeleter(void (*deleter)(void* self)) { header_.deleter = deleter; } // Expose DecRef and IncRef as public function // NOTE: they are only for developer purposes only. - using Object::DecRef; - using Object::IncRef; + // using Object::DecRef; + // using Object::IncRef; // Information for object protocol. static constexpr const uint32_t _type_index = TypeIndex::kRuntimeNDArray; static constexpr const uint32_t _type_child_slots = 0; static constexpr const uint32_t _type_child_slots_can_overflow = true; static constexpr const char* _type_key = "runtime.NDArray"; - TVM_DECLARE_BASE_OBJECT_INFO(NDArray::Container, Object); + static const constexpr bool _type_final = true; + TVM_FFI_DECLARE_STATIC_OBJECT_INFO(NDArray::Container, Object); protected: friend class RPCWrappedFunc; @@ -439,14 +440,14 @@ inline TVMArrayHandle NDArray::FFIGetHandle(const ObjectRef& nd) { return ptr; } -inline void NDArray::FFIDecRef(TVMArrayHandle handle) { - static_cast<NDArray::Container*>(reinterpret_cast<NDArray::ContainerBase*>(handle))->DecRef(); -} - inline Object* TVMArrayHandleToObjectHandle(TVMArrayHandle handle) { return static_cast<NDArray::Container*>(reinterpret_cast<NDArray::ContainerBase*>(handle)); } +inline void NDArray::FFIDecRef(TVMArrayHandle handle) { + details::ObjectUnsafe::DecRefObjectHandle(TVMArrayHandleToObjectHandle(handle)); +} + /*! \brief Magic number for NDArray file */ constexpr uint64_t kTVMNDArrayMagic = 0xDD5E40F096B4A13F; diff --git a/src/runtime/debug_compile.cc b/src/runtime/debug_compile.cc index 214302d80f..67a508dde5 100644 --- a/src/runtime/debug_compile.cc +++ b/src/runtime/debug_compile.cc @@ -26,6 +26,7 @@ #include <tvm/runtime/container/array.h> #include <tvm/runtime/container/map.h> #include <tvm/runtime/container/variant.h> +#include <tvm/runtime/ndarray.h> namespace tvm { namespace debug {
