| 30 | } // namespace |
| 31 | |
| 32 | void CostModel::SuppressInfrequent() { |
| 33 | // Find the median of the non-zero counts, and use half of its value |
| 34 | // as the cutoff for a "normal" execution mode node. |
| 35 | if (count_.empty()) return; |
| 36 | std::vector<int32> non_zero; |
| 37 | for (auto v : count_) { |
| 38 | if (v > 0) non_zero.push_back(v); |
| 39 | } |
| 40 | const size_t sz = non_zero.size(); |
| 41 | if (sz > 0) { |
| 42 | std::nth_element(non_zero.begin(), non_zero.begin() + sz / 2, |
| 43 | non_zero.end()); |
| 44 | int32 median_value = non_zero[sz / 2]; |
| 45 | min_count_ = median_value / 2; |
| 46 | VLOG(1) << "num non_zero vals: " << non_zero.size() << " median_value " |
| 47 | << median_value; |
| 48 | } else { |
| 49 | min_count_ = 1; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void CostModel::MergeFromLocal(const Graph& g, const CostModel& cm) { |
| 54 | CHECK(is_global_); |