@@ -435,6 +435,10 @@ class EmbeddingVar : public ResourceBase {
435435 return storage_->CacheSize ();
436436 }
437437
438+ int64 MemoryUsage () const {
439+ return storage_->Size () * (sizeof (K) + feat_desc_->data_bytes ());
440+ }
441+
438442 int64 MinFreq () {
439443 return emb_config_.filter_freq ;
440444 }
@@ -516,6 +520,85 @@ class EmbeddingVar : public ResourceBase {
516520 }
517521 }
518522
523+ Status GetShardedSnapshot (std::vector<K>* key_list,
524+ std::vector<void *>* value_ptr_list,
525+ int partition_id, int partition_num) {
526+ return storage_->GetShardedSnapshot (key_list, value_ptr_list,
527+ partition_id, partition_num);
528+ }
529+
530+ void ExportAndRemove (K* key_list, V* value_list,
531+ int64* version_list, int64* freq_list,
532+ std::vector<K>& tot_keys_list,
533+ std::vector<void *>& tot_value_ptr_list) {
534+ bool save_unfiltered_features = true ;
535+ TF_CHECK_OK (ReadBoolFromEnvVar (
536+ " TF_EV_SAVE_FILTERED_FEATURES" , true , &save_unfiltered_features));
537+
538+ bool is_save_freq = emb_config_.is_save_freq ();
539+ bool is_save_version = emb_config_.is_save_version ();
540+
541+ for (int64 i = 0 ; i < tot_keys_list.size (); ++i) {
542+ auto & value_ptr = tot_value_ptr_list[i];
543+ if ((int64)value_ptr == embedding::ValuePtrStatus::IS_DELETED)
544+ continue ;
545+
546+ bool is_admit = feat_desc_->IsAdmit (value_ptr);
547+ bool is_in_dram = ((int64)value_ptr >> kDramFlagOffset == 0 );
548+
549+ if (!is_admit) {
550+ key_list[i] = tot_keys_list[i];
551+
552+ if (!is_in_dram) {
553+ auto tmp_value = value_list + i * value_len_;
554+ tmp_value = (V*)embedding::ValuePtrStatus::NOT_IN_DRAM;
555+ value_ptr = (void *)((int64)value_ptr & ((1L << kDramFlagOffset ) - 1 ));
556+ } else if (feat_desc_->GetEmbedding (value_ptr, 0 ) == nullptr ) {
557+ memcpy (value_list + i * value_len_, default_value_, sizeof (V) * value_len_);
558+ } else {
559+ V* val = feat_desc_->GetEmbedding (value_ptr, emb_config_.emb_index );
560+ memcpy (value_list + i * value_len_, val, sizeof (V) * value_len_);
561+ }
562+
563+ if (is_save_version) {
564+ int64 dump_version = feat_desc_->GetVersion (value_ptr);
565+ version_list[i] = dump_version;
566+ }
567+
568+ if (is_save_freq) {
569+ int64 dump_freq = feat_desc_->GetFreq (value_ptr);
570+ freq_list[i] = dump_freq;
571+ }
572+ } else {
573+ if (!save_unfiltered_features)
574+ return ;
575+ // TODO(JUNQI) : currently not export filtered keys
576+ }
577+
578+ if (emb_config_.is_primary ()) {
579+ Status s;
580+ s = storage_->Remove (tot_keys_list[i]);
581+ if (!s.ok ()) {
582+ LOG (ERROR) << " Remove keys error: " << s.error_message ();
583+ }
584+ feat_desc_->Deallocate (value_ptr);
585+ }
586+ }
587+ }
588+
589+ Status RestoreFromKeysAndValues (int64 key_num, int partition_id,
590+ int partition_num, const K* key_list,
591+ const V* value_list, const int64* version_list,
592+ const int64* freq_list,
593+ const Eigen::GpuDevice* device = nullptr ) {
594+ RestoreBuffer restore_buff ((char *)key_list, (char *)value_list,
595+ (char *)version_list, (char *)freq_list);
596+ return storage_->RestoreFeatures (key_num, kSavedPartitionNum ,
597+ partition_id, partition_num,
598+ value_len_, false /* is_filter*/ , false /* is_incr*/ ,
599+ emb_config_, device, filter_, restore_buff);
600+ }
601+
519602 mutex* mu () {
520603 return &mu_;
521604 }
@@ -537,6 +620,8 @@ class EmbeddingVar : public ResourceBase {
537620 }
538621 }
539622
623+ string Name () {return name_; }
624+
540625 V* GetDefaultValuePtr () {
541626 return default_value_;
542627 }
@@ -645,7 +730,6 @@ class EmbeddingVar : public ResourceBase {
645730 GPUHashTable<K, V>* HashTable () {
646731 return storage_->HashTable ();
647732 }
648-
649733 FilterPolicy<K, V, EmbeddingVar<K, V>>* GetFilter () const {
650734 return filter_;
651735 }
0 commit comments