| 936 | } |
| 937 | |
| 938 | void ChannelImpl::flush_apply_stack() { |
| 939 | m_applying = true; |
| 940 | auto& state = get_worker_state(); |
| 941 | while (!m_apply_stack.empty()) { |
| 942 | auto& [cmd, idx, recomp, reason] = |
| 943 | m_apply_stack.top(); // cmd.inputs[0~idx-1] is in memory |
| 944 | if (idx == 0) { |
| 945 | if (state.options.enable_dtr_auto_drop) { |
| 946 | m_dtr.pin(cmd.inputs); |
| 947 | } |
| 948 | if (recomp) { |
| 949 | MGB_RECORD_EVENT( |
| 950 | TensorCommandEvent, recomp->id, TensorCommandKind::ReGen); |
| 951 | } |
| 952 | } |
| 953 | bool regen = false; |
| 954 | for (size_t i = idx; i < cmd.inputs.size(); i++) { |
| 955 | auto&& p = cmd.inputs[i]; |
| 956 | if (state.options.enable_dtr_auto_drop) { |
| 957 | m_dtr.update_used_time(p); |
| 958 | } |
| 959 | if (!p->ptr && p->evict_type != EvictType::NONE) { |
| 960 | idx = i + 1; |
| 961 | regenerate(p); // add ApplyOp to the stack |
| 962 | regen = true; |
| 963 | break; |
| 964 | } |
| 965 | } |
| 966 | if (regen) |
| 967 | continue; |
| 968 | // the required input tensors are already in memory |
| 969 | auto [cmd_backup, recomp_backup, reason_backup] = |
| 970 | std::make_tuple(cmd, recomp, reason); |
| 971 | m_apply_stack.pop(); |
| 972 | do_apply_op(cmd_backup, reason_backup); |
| 973 | if (recomp_backup) { |
| 974 | MGB_RECORD_EVENT( |
| 975 | TensorCommandFinishEvent, recomp_backup->id, |
| 976 | TensorCommandKind::ReGen); |
| 977 | for (auto o : cmd_backup.outputs) { |
| 978 | if (o) { |
| 979 | m_dtr.update_dsu_after_recompute(o); |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | } |
| 984 | m_applying = false; |
| 985 | } |
| 986 | |
| 987 | bool ChannelImpl::auto_evict(size_t force_num) { |
| 988 | auto& state = get_worker_state(); |
nothing calls this directly
no test coverage detected