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

Method find_best_tensor

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

Source from the content-addressed store, hash-verified

1624}
1625
1626TensorInfo* ChannelImpl::DynamicSublinear::find_best_tensor(
1627 bool enable_dtr_sqrt_sampling = false) {
1628 if (candidates.empty())
1629 return nullptr;
1630
1631 double min_msps = -1;
1632 TensorInfo* best = nullptr;
1633 size_t sz = 1;
1634 if (enable_dtr_sqrt_sampling) {
1635 while (sz * sz <= candidates.size())
1636 sz++;
1637 sz--;
1638 } else {
1639 sz = candidates.size();
1640 }
1641
1642 size_t ti = rand() % sz;
1643 for (size_t vi = 0; vi < sz; vi++) {
1644 if (!enable_dtr_sqrt_sampling) {
1645 ti = vi;
1646 }
1647 auto i = candidates[ti];
1648 if (i->producer && i->ptr && i->evict_type == EvictType::NONE) {
1649 double neighbor_cost = estimate_neighbor_cost(i);
1650 size_t begin_ptr =
1651 reinterpret_cast<size_t>(i->ptr->blob()->storage().get());
1652 auto side_info = i->ptr->comp_node().get_free_left_and_right(
1653 begin_ptr, begin_ptr + i->ptr->blob()->size());
1654 double free_mem = side_info.first + side_info.second;
1655 double msps = i->eval_func(
1656 neighbor_cost, free_mem, estimate_timestamp, 1.0, 1.0, 1.0, 1.0001);
1657 if (min_msps < 0 || msps < min_msps) {
1658 min_msps = msps;
1659 best = i;
1660 }
1661 }
1662 if (enable_dtr_sqrt_sampling) {
1663 ti += rand() % sz;
1664 if (ti > candidates.size())
1665 break;
1666 }
1667 }
1668 return best;
1669}
1670
1671void ChannelImpl::DynamicSublinear::merge(
1672 std::shared_ptr<DsuNode>& x, std::shared_ptr<DsuNode>& y) {

Callers 1

auto_evictMethod · 0.80

Calls 8

storageMethod · 0.80
blobMethod · 0.80
eval_funcMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
comp_nodeMethod · 0.45

Tested by

no test coverage detected