MCPcopy Create free account
hub / github.com/apache/tvm-ffi / CopyFrom

Method CopyFrom

include/tvm/ffi/container/map_base.h:782–815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

780 */
781 template <typename MapObjType>
782 static ObjectPtr<Object> CopyFrom(DenseMapBaseObj* from) {
783 ObjectPtr<DenseMapBaseObj> p = make_object<DenseMapBaseObj>();
784 uint64_t n_blocks = CalcNumBlocks(from->NumSlots());
785 p->data_ = new Block[n_blocks];
786 // assign block deleter so even if we take re-alloc data
787 // in another shared-lib that may have different malloc/free behavior
788 // it will still be safe.
789 p->data_deleter_ = BlockDeleter;
790 p->SetSlotsAndDenseLayoutTag(from->NumSlots());
791 p->size_ = from->size_;
792 p->fib_shift_ = from->fib_shift_;
793 p->iter_list_head_ = from->iter_list_head_;
794 p->iter_list_tail_ = from->iter_list_tail_;
795 // manually set the type index to specialized subclass
796 // data layout is ensured to be the same except for the type index
797 static_assert(std::is_base_of_v<MapBaseObj, MapObjType>);
798 static_assert(sizeof(MapObjType) == sizeof(MapBaseObj));
799 p->header_.type_index = MapObjType::RuntimeTypeIndex();
800 for (uint64_t bi = 0; bi < n_blocks; ++bi) {
801 uint8_t* meta_ptr_from = from->GetBlock(bi)->bytes;
802 ItemType* data_ptr_from = reinterpret_cast<ItemType*>(from->GetBlock(bi)->bytes + kBlockCap);
803 uint8_t* meta_ptr_to = p->GetBlock(bi)->bytes;
804 ItemType* data_ptr_to = reinterpret_cast<ItemType*>(p->GetBlock(bi)->bytes + kBlockCap);
805 for (int j = 0; j < kBlockCap;
806 ++j, ++meta_ptr_from, ++data_ptr_from, ++meta_ptr_to, ++data_ptr_to) {
807 uint8_t& meta = *meta_ptr_to = *meta_ptr_from;
808 TVM_FFI_ICHECK(meta != kProtectedSlot);
809 if (meta != kEmptySlot) {
810 new (data_ptr_to) ItemType(*data_ptr_from);
811 }
812 }
813 }
814 return p;
815 }
816 /*!
817 * \brief InsertMaybeReHash an entry into the given hash map
818 * \param kv The entry to be inserted

Callers

nothing calls this directly

Calls 3

GetBlockMethod · 0.80
NumSlotsMethod · 0.45

Tested by

no test coverage detected