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 6127599320e01cfe041041dbf729dac54c8f6da6 Author: tqchen <[email protected]> AuthorDate: Sun Mar 9 18:14:45 2025 -0400 clang format --- ffi/include/tvm/ffi/cast.h | 2 +- ffi/include/tvm/ffi/object.h | 33 +++++++++++------------ ffi/include/tvm/ffi/reflection.h | 10 +++---- include/tvm/runtime/container/array.h | 4 +-- include/tvm/runtime/container/map.h | 4 +-- include/tvm/runtime/memory.h | 2 +- include/tvm/runtime/object.h | 49 +++++++++++++++++------------------ include/tvm/runtime/packed_func.h | 6 +++-- src/runtime/debug_compile.cc | 12 ++++----- src/runtime/ndarray.cc | 11 ++++---- src/runtime/object.cc | 3 ++- src/runtime/relax_vm/rnn_state.cc | 3 +-- 12 files changed, 68 insertions(+), 71 deletions(-) diff --git a/ffi/include/tvm/ffi/cast.h b/ffi/include/tvm/ffi/cast.h index c7365a2f45..3d97d3a217 100644 --- a/ffi/include/tvm/ffi/cast.h +++ b/ffi/include/tvm/ffi/cast.h @@ -62,7 +62,7 @@ inline RefType GetRef(const ObjectType* ptr) { template <typename BaseType, typename ObjectType> inline ObjectPtr<BaseType> GetObjectPtr(ObjectType* ptr) { static_assert(std::is_base_of<BaseType, ObjectType>::value, - "Can only cast to the ref of same container type"); + "Can only cast to the ref of same container type"); return details::ObjectUnsafe::ObjectPtrFromUnowned<BaseType>(ptr); } diff --git a/ffi/include/tvm/ffi/object.h b/ffi/include/tvm/ffi/object.h index b2189fb7f5..b9e5df51d1 100644 --- a/ffi/include/tvm/ffi/object.h +++ b/ffi/include/tvm/ffi/object.h @@ -160,7 +160,7 @@ class Object { */ static int32_t _GetOrAllocRuntimeTypeIndex() { return TypeIndex::kTVMFFIObject; } - private: + private: /*! \brief increase reference count */ void IncRef() { details::AtomicIncrementRelaxed(&(header_.ref_counter)); } @@ -426,21 +426,20 @@ struct ObjectPtrEqual { } }; - // If dynamic type is enabled, we still need to register the runtime type of parent -#define TVM_FFI_REGISTER_STATIC_TYPE_INFO(TypeName, ParentType) \ - static constexpr int32_t _type_depth = ParentType::_type_depth + 1; \ - static int32_t _GetOrAllocRuntimeTypeIndex() { \ +#define TVM_FFI_REGISTER_STATIC_TYPE_INFO(TypeName, ParentType) \ + static constexpr int32_t _type_depth = ParentType::_type_depth + 1; \ + static int32_t _GetOrAllocRuntimeTypeIndex() { \ static_assert(!ParentType::_type_final, "ParentType marked as final"); \ static_assert(TypeName::_type_child_slots == 0 || ParentType::_type_child_slots == 0 || \ TypeName::_type_child_slots < ParentType::_type_child_slots, \ "Need to set _type_child_slots when parent specifies it."); \ - static int32_t tindex = TVMFFIGetOrAllocTypeIndex( \ - TypeName::_type_key, TypeName::_type_index, TypeName::_type_depth, \ - TypeName::_type_child_slots, TypeName::_type_child_slots_can_overflow, \ - ParentType::_GetOrAllocRuntimeTypeIndex()); \ - return tindex; \ - } \ + static int32_t tindex = TVMFFIGetOrAllocTypeIndex( \ + TypeName::_type_key, TypeName::_type_index, TypeName::_type_depth, \ + TypeName::_type_child_slots, TypeName::_type_child_slots_can_overflow, \ + ParentType::_GetOrAllocRuntimeTypeIndex()); \ + return tindex; \ + } \ static inline int32_t _register_type_index = _GetOrAllocRuntimeTypeIndex() /*! @@ -452,7 +451,6 @@ struct ObjectPtrEqual { static int32_t RuntimeTypeIndex() { return TypeName::_type_index; } \ TVM_FFI_REGISTER_STATIC_TYPE_INFO(TypeName, ParentType); - /* * \brief Define object reference methods. * \param TypeName The object type name @@ -505,14 +503,13 @@ struct ObjectPtrEqual { * \param ObjectName The type name of the object. */ #define TVM_FFI_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \ - explicit TypeName(::tvm::ffi::ObjectPtr<::tvm::ffi::Object> n) : ParentType(n) {} \ - TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \ - ObjectName* operator->() const { return static_cast<ObjectName*>(data_.get()); } \ - ObjectName* get() const { return operator->(); } \ - static constexpr bool _type_is_nullable = false; \ + explicit TypeName(::tvm::ffi::ObjectPtr<::tvm::ffi::Object> n) : ParentType(n) {} \ + TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \ + ObjectName* operator->() const { return static_cast<ObjectName*>(data_.get()); } \ + ObjectName* get() const { return operator->(); } \ + static constexpr bool _type_is_nullable = false; \ using ContainerType = ObjectName; - namespace details { template <typename TargetType> TVM_FFI_INLINE bool IsObjectInstance(int32_t object_type_index) { diff --git a/ffi/include/tvm/ffi/reflection.h b/ffi/include/tvm/ffi/reflection.h index d154522b9f..b29b3d919f 100644 --- a/ffi/include/tvm/ffi/reflection.h +++ b/ffi/include/tvm/ffi/reflection.h @@ -155,11 +155,11 @@ class ReflectionFieldGetter { */ #define TVM_FFI_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType) \ static constexpr int32_t _type_depth = ParentType::_type_depth + 1; \ - static int32_t _GetOrAllocRuntimeTypeIndex() { \ - static_assert(!ParentType::_type_final, "ParentType marked as final"); \ - static_assert(TypeName::_type_child_slots == 0 || ParentType::_type_child_slots == 0 || \ - TypeName::_type_child_slots < ParentType::_type_child_slots, \ - "Need to set _type_child_slots when parent specifies it."); \ + static int32_t _GetOrAllocRuntimeTypeIndex() { \ + static_assert(!ParentType::_type_final, "ParentType marked as final"); \ + static_assert(TypeName::_type_child_slots == 0 || ParentType::_type_child_slots == 0 || \ + TypeName::_type_child_slots < ParentType::_type_child_slots, \ + "Need to set _type_child_slots when parent specifies it."); \ static int32_t tindex = TVMFFIGetOrAllocTypeIndex( \ TypeName::_type_key, -1, TypeName::_type_depth, TypeName::_type_child_slots, \ TypeName::_type_child_slots_can_overflow, ParentType::_GetOrAllocRuntimeTypeIndex()); \ diff --git a/include/tvm/runtime/container/array.h b/include/tvm/runtime/container/array.h index f4e825f44f..d601309dbe 100644 --- a/include/tvm/runtime/container/array.h +++ b/include/tvm/runtime/container/array.h @@ -905,13 +905,13 @@ inline Array<T> Concat(Array<T> lhs, const Array<T>& rhs) { } // namespace runtime -namespace ffi{ +namespace ffi { // Specialize make_object<ArrayNode> to make sure it is correct. template <> inline ObjectPtr<tvm::runtime::ArrayNode> make_object() { return tvm::runtime::ArrayNode::Empty(); } -} +} // namespace ffi // expose the functions to the root namespace. using runtime::Array; using runtime::ArrayNode; diff --git a/include/tvm/runtime/container/map.h b/include/tvm/runtime/container/map.h index a24d61d4de..7daaf238c1 100644 --- a/include/tvm/runtime/container/map.h +++ b/include/tvm/runtime/container/map.h @@ -1251,8 +1251,8 @@ inline void MapNode::InsertMaybeReHash(const KVType& kv, ObjectPtr<Object>* map) } } -//template <> -//inline ObjectPtr<MapNode> make_object<>() = delete; +// template <> +// inline ObjectPtr<MapNode> make_object<>() = delete; #endif diff --git a/include/tvm/runtime/memory.h b/include/tvm/runtime/memory.h index 8429650421..04b4a1e7d4 100644 --- a/include/tvm/runtime/memory.h +++ b/include/tvm/runtime/memory.h @@ -28,8 +28,8 @@ namespace tvm { namespace runtime { -using tvm::ffi::make_object; using tvm::ffi::make_inplace_array_object; +using tvm::ffi::make_object; } // namespace runtime } // namespace tvm diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h index d956eebf1f..1edfae6abb 100644 --- a/include/tvm/runtime/object.h +++ b/include/tvm/runtime/object.h @@ -23,15 +23,15 @@ #ifndef TVM_RUNTIME_OBJECT_H_ #define TVM_RUNTIME_OBJECT_H_ -#include <tvm/ffi/object.h> #include <tvm/ffi/cast.h> +#include <tvm/ffi/object.h> #include <tvm/ffi/reflection.h> #include <tvm/runtime/c_runtime_api.h> namespace tvm { namespace runtime { -template<typename T> +template <typename T> class Optional; using tvm::ffi::Object; @@ -40,9 +40,8 @@ using tvm::ffi::ObjectPtrEqual; using tvm::ffi::ObjectPtrHash; using tvm::ffi::Downcast; -using tvm::ffi::GetRef; using tvm::ffi::GetObjectPtr; - +using tvm::ffi::GetRef; /*! * \brief Namespace for the list of type index. @@ -173,19 +172,19 @@ class ObjectRef : public tvm::ffi::ObjectRef { * * \endcode */ -#define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName) \ -static_assert(ObjectName::_type_final, \ - "TVM's CopyOnWrite may only be used for " \ - "Object types that are declared as final, " \ - "using the TVM_DECLARE_FINAL_OBJECT_INFO macro."); \ -ObjectName* CopyOnWrite() { \ - ICHECK(data_ != nullptr); \ - if (!data_.unique()) { \ - auto n = make_object<ObjectName>(*(operator->())); \ - ObjectPtr<Object>(std::move(n)).swap(data_); \ - } \ - return static_cast<ObjectName*>(data_.get()); \ -} +#define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName) \ + static_assert(ObjectName::_type_final, \ + "TVM's CopyOnWrite may only be used for " \ + "Object types that are declared as final, " \ + "using the TVM_DECLARE_FINAL_OBJECT_INFO macro."); \ + ObjectName* CopyOnWrite() { \ + ICHECK(data_ != nullptr); \ + if (!data_.unique()) { \ + auto n = make_object<ObjectName>(*(operator->())); \ + ObjectPtr<Object>(std::move(n)).swap(data_); \ + } \ + return static_cast<ObjectName*>(data_.get()); \ + } /* * \brief Define object reference methods. @@ -194,13 +193,12 @@ ObjectName* CopyOnWrite() { \ * \param ObjectName The type name of the object. */ #define TVM_DEFINE_OBJECT_REF_METHODS_WITHOUT_DEFAULT_CONSTRUCTOR(TypeName, ParentType, \ - ObjectName) \ -explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \ -TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \ -const ObjectName* operator->() const { return static_cast<const ObjectName*>(data_.get()); } \ -const ObjectName* get() const { return operator->(); } \ -using ContainerType = ObjectName; - + ObjectName) \ + explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \ + TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \ + const ObjectName* operator->() const { return static_cast<const ObjectName*>(data_.get()); } \ + const ObjectName* get() const { return operator->(); } \ + using ContainerType = ObjectName; #define TVM_DECLARE_BASE_OBJECT_INFO TVM_FFI_DECLARE_BASE_OBJECT_INFO #define TVM_DECLARE_FINAL_OBJECT_INFO TVM_FFI_DECLARE_FINAL_OBJECT_INFO @@ -208,7 +206,8 @@ using ContainerType = ObjectName; #define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS TVM_DEFINE_MUTABLE_NULLABLE_OBJECT_REF_METHODS #define TVM_DEFINE_OBJECT_REF_METHODS TVM_FFI_DEFINE_NULLABLE_OBJECT_REF_METHODS -#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS TVM_FFI_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS +#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS \ + TVM_FFI_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS #define TVM_STR_CONCAT_(__x, __y) __x##__y #define TVM_STR_CONCAT(__x, __y) TVM_STR_CONCAT_(__x, __y) diff --git a/include/tvm/runtime/packed_func.h b/include/tvm/runtime/packed_func.h index 912a15e976..d2141103f1 100644 --- a/include/tvm/runtime/packed_func.h +++ b/include/tvm/runtime/packed_func.h @@ -641,14 +641,16 @@ class TVMPODValue_ { return Module(ObjectPtr<Object>(nullptr)); } TVM_CHECK_TYPE_CODE(type_code_, kTVMModuleHandle); - return Module(ffi::details::ObjectUnsafe::ObjectPtrFromUnowned<Object>(static_cast<Object*>(value_.v_handle))); + return Module(ffi::details::ObjectUnsafe::ObjectPtrFromUnowned<Object>( + static_cast<Object*>(value_.v_handle))); } operator PackedFunc() const { if (type_code_ == kTVMNullptr) { return PackedFunc(ObjectPtr<Object>(nullptr)); } TVM_CHECK_TYPE_CODE(type_code_, kTVMPackedFuncHandle); - return PackedFunc(ffi::details::ObjectUnsafe::ObjectPtrFromUnowned<Object>(static_cast<Object*>(value_.v_handle))); + return PackedFunc(ffi::details::ObjectUnsafe::ObjectPtrFromUnowned<Object>( + static_cast<Object*>(value_.v_handle))); } operator Device() const { TVM_CHECK_TYPE_CODE(type_code_, kDLDevice); diff --git a/src/runtime/debug_compile.cc b/src/runtime/debug_compile.cc index 17f86d5f7f..96d220307a 100644 --- a/src/runtime/debug_compile.cc +++ b/src/runtime/debug_compile.cc @@ -21,16 +21,16 @@ * \file src/runtime/debug_compile.cc * \brief File used for debug migration */ -#include <tvm/runtime/container/string.h> -#include <tvm/runtime/container/optional.h> +#include <tvm/ir/expr.h> #include <tvm/runtime/container/array.h> #include <tvm/runtime/container/map.h> +#include <tvm/runtime/container/optional.h> +#include <tvm/runtime/container/string.h> #include <tvm/runtime/container/variant.h> +#include <tvm/runtime/disco/disco_worker.h> #include <tvm/runtime/ndarray.h> #include <tvm/runtime/packed_func.h> #include <tvm/runtime/registry.h> -#include <tvm/runtime/disco/disco_worker.h> -#include <tvm/ir/expr.h> #include <tvm/tir/expr.h> namespace tvm { @@ -41,5 +41,5 @@ String Test() { return value; } -} -} \ No newline at end of file +} // namespace debug +} // namespace tvm \ No newline at end of file diff --git a/src/runtime/ndarray.cc b/src/runtime/ndarray.cc index 63087fda6f..67b30bb0d1 100644 --- a/src/runtime/ndarray.cc +++ b/src/runtime/ndarray.cc @@ -105,8 +105,7 @@ struct NDArray::Internal { auto* ptr = static_cast<NDArray::Container*>(ptr_obj); if (ptr->manager_ctx != nullptr) { ffi::details::ObjectUnsafe::DecRefObjectHandle( - static_cast<NDArray::Container*>(ptr->manager_ctx) - ); + static_cast<NDArray::Container*>(ptr->manager_ctx)); } else if (ptr->dl_tensor.data != nullptr) { tvm::runtime::DeviceAPI::Get(ptr->dl_tensor.device) ->FreeDataSpace(ptr->dl_tensor.device, ptr->dl_tensor.data); @@ -179,7 +178,8 @@ struct NDArray::Internal { } // Delete dlpack object. static void NDArrayDLPackDeleter(DLManagedTensor* tensor) { - ffi::details::ObjectUnsafe::DecRefObjectHandle(static_cast<NDArray::Container*>(tensor->manager_ctx)); + ffi::details::ObjectUnsafe::DecRefObjectHandle( + static_cast<NDArray::Container*>(tensor->manager_ctx)); delete tensor; } }; @@ -368,9 +368,8 @@ void TVMNDArrayDLPackDeleter(DLManagedTensor* tensor) { int TVMArrayGetTypeIndex(TVMArrayHandle handle, unsigned* out_tindex) { API_BEGIN(); - *out_tindex = tvm::ffi::details::ObjectUnsafe::GetHeader( - TVMArrayHandleToObjectHandle(handle) - )->type_index; + *out_tindex = + tvm::ffi::details::ObjectUnsafe::GetHeader(TVMArrayHandleToObjectHandle(handle))->type_index; API_END(); } diff --git a/src/runtime/object.cc b/src/runtime/object.cc index 9c4356ef4c..095eee5f5e 100644 --- a/src/runtime/object.cc +++ b/src/runtime/object.cc @@ -71,7 +71,8 @@ int TVMObjectDerivedFrom(uint32_t child_type_index, uint32_t parent_type_index, const TVMFFITypeInfo* child_type_info = TVMFFIGetTypeInfo(child_type_index); const TVMFFITypeInfo* parent_type_info = TVMFFIGetTypeInfo(parent_type_index); return (child_type_info->type_depth > parent_type_info->type_depth && - child_type_info->type_acenstors[parent_type_info->type_depth] == static_cast<int32_t>(parent_type_index)); + child_type_info->type_acenstors[parent_type_info->type_depth] == + static_cast<int32_t>(parent_type_index)); }(); API_END(); } diff --git a/src/runtime/relax_vm/rnn_state.cc b/src/runtime/relax_vm/rnn_state.cc index c823cfbb98..0b26e93de4 100644 --- a/src/runtime/relax_vm/rnn_state.cc +++ b/src/runtime/relax_vm/rnn_state.cc @@ -454,8 +454,7 @@ class RNNStateImpObj : public RNNStateObj { } public: - - static constexpr const char* _type_key = "relax.vm.RNNStateImp"; + static constexpr const char* _type_key = "relax.vm.RNNStateImp"; TVM_DECLARE_FINAL_OBJECT_INFO(RNNStateImpObj, RNNStateObj); };
