MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / auto_evict

Method auto_evict

imperative/src/impl/interpreter/interpreter_impl.cpp:987–1019  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

985}
986
987bool ChannelImpl::auto_evict(size_t force_num) {
988 auto& state = get_worker_state();
989 if (!m_dtr.comp_node.valid()) {
990 return false;
991 }
992 size_t current_memory = m_dtr.comp_node.get_used_memory();
993 size_t flag = false;
994 while ((state.options.dtr_eviction_threshold > 0 &&
995 current_memory > state.options.dtr_eviction_threshold) ||
996 force_num > 0) {
997 MGB_RECORD_EVENT(AutoEvictEvent);
998 sample_on_device(m_dtr.comp_node, false);
999 auto best = m_dtr.find_best_tensor(state.options.enable_dtr_sqrt_sampling);
1000 if (!best) {
1001 MGB_RECORD_EVENT(AutoEvictFinishEvent);
1002 break;
1003 }
1004 if (best->ptr.unique() && best->ptr->blob().unique()) {
1005 current_memory -= best->memory;
1006 if (force_num > 0) {
1007 force_num--;
1008 }
1009 flag = true;
1010 }
1011 do_drop(best);
1012 if (best->evict_type == EvictType::DROP) {
1013 m_dtr.update_dsu_after_evict(best);
1014 }
1015 sample_on_device(m_dtr.comp_node, false);
1016 MGB_RECORD_EVENT(AutoEvictFinishEvent);
1017 }
1018 return flag;
1019}
1020
1021void ChannelImpl::detach_users(TensorInfo* dest) {
1022 SmallVector<TensorInfo::ComputePath*> users = dest->users;

Callers

nothing calls this directly

Calls 6

find_best_tensorMethod · 0.80
uniqueMethod · 0.80
blobMethod · 0.80
validMethod · 0.45
get_used_memoryMethod · 0.45

Tested by

no test coverage detected