wweic commented on a change in pull request #4581: [REFACTOR][RUNTIME] Update
NDArray use the Unified Object System
URL: https://github.com/apache/incubator-tvm/pull/4581#discussion_r361600433
##########
File path: include/tvm/runtime/ndarray.h
##########
@@ -315,49 +254,38 @@ class NDArray::Container {
dl_tensor.byte_offset = 0;
dl_tensor.ctx = ctx;
}
-
- /*! \brief developer function, increases reference counter */
- void IncRef() {
- ref_counter_.fetch_add(1, std::memory_order_relaxed);
- }
- /*! \brief developer function, decrease reference counter */
- void DecRef() {
- if (ref_counter_.fetch_sub(1, std::memory_order_release) == 1) {
- std::atomic_thread_fence(std::memory_order_acquire);
- if (this->deleter != nullptr) {
- (*this->deleter)(this);
- }
- }
+ /*!
+ * \brief Set the deleter field.
+ * \param deleter The deleter.
+ */
+ void SetDeleter(FDeleter deleter) {
+ deleter_ = deleter;
}
-};
-// implementations of inline functions
-// the usages of functions are documented in place.
-inline NDArray::NDArray(Container* data)
- : data_(data) {
- if (data != nullptr) {
- data_->IncRef();
- }
-}
+ // Expose DecRef and IncRef as public function
+ // NOTE: they are only for developer purposes only.
+ using Object::DecRef;
+ using Object::IncRef;
-inline NDArray::NDArray(const NDArray& other)
- : data_(other.data_) {
- if (data_ != nullptr) {
- data_->IncRef();
- }
-}
+ // Information for object protocol.
+ static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
+ 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 = "NDArray";
+ TVM_DECLARE_BASE_OBJECT_INFO(NDArray::Container, Object);
-inline void NDArray::reset() {
- if (data_ != nullptr) {
- data_->DecRef();
- data_ = nullptr;
- }
-}
+ protected:
+ friend class RPCWrappedFunc;
+ friend class NDArray;
+};
+
+// implementations of inline functions
+// the usages of functions are documented in place.a
Review comment:
```suggestion
// the usages of functions are documented in place.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services