| 404 | } |
| 405 | |
| 406 | ProfilerImpl::ProfilingResult ProfilerImpl::profile(const Problem& problem) const { |
| 407 | ConstVarPropogate cvprop{ConstVarType::IMMUTABLE_AND_PARAM}; |
| 408 | { |
| 409 | auto cb = [&cvprop](OperatorNodeBase* opr) { cvprop.add_opr(opr); }; |
| 410 | DepOprIter iter{cb}; |
| 411 | for (auto&& o : problem.graph_partition().output()) { |
| 412 | iter.add(o->owner_opr()); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | static const ThinHashMap<Typeinfo*, size_t> format_aware_input_tensors = { |
| 417 | #define cb(_Opr, _arity) {_Opr::typeinfo(), _arity} |
| 418 | cb(Convolution, 2), |
| 419 | cb(ConvBiasForward, 4), |
| 420 | cb(ConvolutionBackwardData, 2), |
| 421 | cb(PoolingForward, 1), |
| 422 | cb(WarpPerspective, 1), |
| 423 | cb(Resize, 1), |
| 424 | #undef cb |
| 425 | }; |
| 426 | static const ThinHashSet<Typeinfo*> skip_opr_types = { |
| 427 | TypeCvt::typeinfo(), Elemwise::typeinfo(), ElemwiseMultiType::typeinfo()}; |
| 428 | ThinHashSet<VarNode*> vars; |
| 429 | ThinHashSet<OperatorNodeBase*> oprs; |
| 430 | ThinHashSet<OperatorNodeBase*> skip_oprs; |
| 431 | for (auto&& opr : problem.graph_partition().all_oprs()) { |
| 432 | if (cvprop.is_const(opr)) |
| 433 | continue; |
| 434 | bool skip = true; |
| 435 | for (auto&& i : opr->input()) { |
| 436 | skip &= problem.graph_partition().input().count(i) > 0 || |
| 437 | skip_oprs.count(i->owner_opr()) > 0; |
| 438 | } |
| 439 | auto find = format_aware_input_tensors.find(opr->dyn_typeinfo()); |
| 440 | skip &= find == format_aware_input_tensors.end(); |
| 441 | if (skip) |
| 442 | skip_oprs.insert(opr); |
| 443 | oprs.insert(opr); |
| 444 | if (find == format_aware_input_tensors.end()) { |
| 445 | for (auto&& i : opr->input()) { |
| 446 | if (!cvprop.is_const(i)) { |
| 447 | vars.insert(i); |
| 448 | } |
| 449 | } |
| 450 | } else { |
| 451 | size_t nr_input_tensor = std::min(find->second, opr->input().size()); |
| 452 | for (size_t i = 0; i < nr_input_tensor; ++i) { |
| 453 | if (!cvprop.is_const(opr->input(i))) { |
| 454 | vars.insert(opr->input(i)); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | for (auto&& ov : opr->usable_output()) { |
| 459 | vars.insert(ov); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | auto base_format = problem.base_format(); |