| 985 | } |
| 986 | |
| 987 | bool 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 | |
| 1021 | void ChannelImpl::detach_users(TensorInfo* dest) { |
| 1022 | SmallVector<TensorInfo::ComputePath*> users = dest->users; |
nothing calls this directly
no test coverage detected