You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2025/03/10 22:56:19 UTC
(tvm) 27/37: pass packed func compile
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 8e7df79382c7c615900ddfd2ae5eb4db8b3bea53
Author: tqchen <ti...@gmail.com>
AuthorDate: Sun Mar 9 11:50:32 2025 -0400
pass packed func compile
---
include/tvm/runtime/module.h | 2 +-
include/tvm/runtime/object.h | 2 ++
include/tvm/runtime/packed_func.h | 21 ++++++++++-----------
src/runtime/debug_compile.cc | 1 +
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/include/tvm/runtime/module.h b/include/tvm/runtime/module.h
index 308c936d62..c4763c2d75 100644
--- a/include/tvm/runtime/module.h
+++ b/include/tvm/runtime/module.h
@@ -257,7 +257,7 @@ class TVM_DLL ModuleNode : public Object {
static constexpr const char* _type_key = "runtime.Module";
// NOTE: ModuleNode can still be sub-classed
//
- TVM_DECLARE_FINAL_OBJECT_INFO(ModuleNode, Object);
+ TVM_FFI_DECLARE_STATIC_OBJECT_INFO(ModuleNode, Object);
protected:
friend class Module;
diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h
index 8fc296519f..b84cf1914b 100644
--- a/include/tvm/runtime/object.h
+++ b/include/tvm/runtime/object.h
@@ -145,6 +145,8 @@ class ObjectRef : public tvm::ffi::ObjectRef {
#define TVM_DECLARE_FINAL_OBJECT_INFO TVM_FFI_DECLARE_FINAL_OBJECT_INFO
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS TVM_FFI_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS
+#define TVM_DEFINE_OBJECT_REF_METHODS TVM_FFI_DEFINE_NULLABLE_OBJECT_REF_METHODS
+
} // namespace runtime
} // namespace tvm
#endif // TVM_RUNTIME_OBJECT_H_
diff --git a/include/tvm/runtime/packed_func.h b/include/tvm/runtime/packed_func.h
index 07a6848bfe..804fd3b98e 100644
--- a/include/tvm/runtime/packed_func.h
+++ b/include/tvm/runtime/packed_func.h
@@ -79,7 +79,8 @@ class PackedFuncObj : public Object {
static constexpr const uint32_t _type_index = TypeIndex::kRuntimePackedFunc;
static constexpr const char* _type_key = "runtime.PackedFunc";
- TVM_DECLARE_FINAL_OBJECT_INFO(PackedFuncObj, Object);
+ static const constexpr bool _type_final = true;
+ TVM_FFI_DECLARE_STATIC_OBJECT_INFO(PackedFuncObj, Object);
protected:
/*!
@@ -640,14 +641,14 @@ class TVMPODValue_ {
return Module(ObjectPtr<Object>(nullptr));
}
TVM_CHECK_TYPE_CODE(type_code_, kTVMModuleHandle);
- return Module(ObjectPtr<Object>(static_cast<Object*>(value_.v_handle)));
+ return Module(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(ObjectPtr<Object>(static_cast<Object*>(value_.v_handle)));
+ return PackedFunc(details::ObjectUnsafe::ObjectPtrFromUnowned<Object>(static_cast<Object*>(value_.v_handle)));
}
operator Device() const {
TVM_CHECK_TYPE_CODE(type_code_, kDLDevice);
@@ -1195,12 +1196,10 @@ class TVMRetValue : public TVMPODValue_CRTP_<TVMRetValue> {
}
}
void SwitchToObject(int type_code, ObjectPtr<Object> other) {
- if (other.data_ != nullptr) {
+ if (other != nullptr) {
this->Clear();
type_code_ = type_code;
- // move the handle out
- value_.v_handle = other.data_;
- other.data_ = nullptr;
+ value_.v_handle = details::ObjectUnsafe::MoveTVMFFIObjectPtrFromObjectPtr(&other);
} else {
SwitchToPOD(kTVMNullptr);
value_.v_handle = nullptr;
@@ -1214,18 +1213,18 @@ class TVMRetValue : public TVMPODValue_CRTP_<TVMRetValue> {
delete ptr<std::string>();
break;
case kTVMPackedFuncHandle:
- static_cast<Object*>(value_.v_handle)->DecRef();
+ details::ObjectUnsafe::DecRefObjectHandle(static_cast<Object*>(value_.v_handle));
break;
case kTVMNDArrayHandle: {
NDArray::FFIDecRef(static_cast<TVMArrayHandle>(value_.v_handle));
break;
}
case kTVMModuleHandle: {
- static_cast<Object*>(value_.v_handle)->DecRef();
+ details::ObjectUnsafe::DecRefObjectHandle(static_cast<Object*>(value_.v_handle));
break;
}
case kTVMObjectHandle: {
- static_cast<Object*>(value_.v_handle)->DecRef();
+ details::ObjectUnsafe::DecRefObjectHandle(static_cast<Object*>(value_.v_handle));
break;
}
}
@@ -2439,7 +2438,7 @@ inline TVMMovableArgValue_::operator T() const {
if (type_code_ == kTVMObjectRValueRefArg) {
auto** ref = static_cast<Object**>(value_.v_handle);
if (ObjectTypeChecker<T>::Check(*ref)) {
- return T(ObjectPtr<Object>::MoveFromRValueRefArg(ref));
+ return T(details::ObjectUnsafe::MoveObjectPtrFromRValueRef<Object>(ref));
}
}
// fallback
diff --git a/src/runtime/debug_compile.cc b/src/runtime/debug_compile.cc
index 67a508dde5..e04c0b0003 100644
--- a/src/runtime/debug_compile.cc
+++ b/src/runtime/debug_compile.cc
@@ -27,6 +27,7 @@
#include <tvm/runtime/container/map.h>
#include <tvm/runtime/container/variant.h>
#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/packed_func.h>
namespace tvm {
namespace debug {