GitOrigin-RevId: ea254297e5
tags/v1.8.0
@@ -12,6 +12,7 @@ | |||||
#pragma once | #pragma once | ||||
#include "megbrain_build_config.h" | #include "megbrain_build_config.h" | ||||
#include "megdnn/oprs/base.h" | |||||
#if MGB_ENABLE_GETENV | #if MGB_ENABLE_GETENV | ||||
#define MGB_GETENV ::std::getenv | #define MGB_GETENV ::std::getenv | ||||
@@ -36,6 +37,11 @@ bool has_available_algo(Opr* opr, Args&&... args) { | |||||
return !all_algos.empty(); | return !all_algos.empty(); | ||||
} | } | ||||
template <class Opr, typename... Args> | |||||
bool has_no_naive_heuristic_algo(Opr* opr, Args&&... args) { | |||||
auto&& algo = opr->get_algorithm_info_heuristic(std::forward<Args>(args)...); | |||||
return !static_cast<bool>(algo.attribute & detail::Algorithm::Attribute::NAIVE); | |||||
} | |||||
} // namespace megdnn | } // namespace megdnn | ||||
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}} | // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}} |
@@ -220,6 +220,28 @@ struct MultiAlgoOprTrait; | |||||
::megdnn::has_available_algo(megdnn_opr, args...), array_layouts); \ | ::megdnn::has_available_algo(megdnn_opr, args...), array_layouts); \ | ||||
MIDOUT_E \ | MIDOUT_E \ | ||||
} \ | } \ | ||||
static bool has_no_naive_heuristic_algo( \ | |||||
const VarNodeArray& i, const cg::OperatorNodeBase* opr_) { \ | |||||
MIDOUT_B( \ | |||||
midout_iv(MGB_HASH_STR(#_Opr)), \ | |||||
midout_iv(MGB_HASH_STR("has_no_naive_heuristic_algo"))) \ | |||||
auto&& opr = opr_->cast_final_safe<_Opr>(); \ | |||||
auto&& megdnn_opr = reinterpret_cast<MegDNNOpr*>(opr.megdnn_opr()); \ | |||||
FixedTensorLayouts array_layouts; \ | |||||
size_t in = i.size() - 1; \ | |||||
for (size_t idx = 0; idx < in; idx++) { \ | |||||
const auto& v = i[idx]; \ | |||||
array_layouts[idx] = \ | |||||
TensorLayout{v->shape(), v->dtype(), v->format()}; \ | |||||
} \ | |||||
const auto& v = i[in]; \ | |||||
array_layouts[arity - 1] = \ | |||||
TensorLayout{v->shape(), v->dtype(), v->format()}; \ | |||||
return APPLY( \ | |||||
::megdnn::has_no_naive_heuristic_algo(megdnn_opr, args...), \ | |||||
array_layouts); \ | |||||
MIDOUT_E \ | |||||
} \ | |||||
}; | }; | ||||
INST(Convolution) | INST(Convolution) | ||||
INST(ConvBiasForward) | INST(ConvBiasForward) | ||||
@@ -365,6 +387,23 @@ bool has_available_algo(const VarNodeArray& i, const cg::OperatorNodeBase* opr) | |||||
#undef cb | #undef cb | ||||
} | } | ||||
bool has_no_naive_heuristic_algo( | |||||
const VarNodeArray& i, const cg::OperatorNodeBase* opr) { | |||||
#define cb(_Opr) \ | |||||
if (opr->dyn_typeinfo() == _Opr::typeinfo()) { \ | |||||
MGB_MARK_USED_VAR(MultiAlgoOprTrait<_Opr>::has_algo); \ | |||||
VarNodeArray _ = i; \ | |||||
_.emplace_back(opr->output(0)); \ | |||||
return MultiAlgoOprTrait<_Opr>::has_no_naive_heuristic_algo(_, opr); \ | |||||
} else | |||||
cb(Convolution) cb(ConvBiasForward) cb(ConvolutionBackwardData) cb(PoolingForward) { | |||||
mgb_throw( | |||||
InternalError, "invalid multi-algo operator(got:%s)", | |||||
opr->dyn_typeinfo()->name); | |||||
} | |||||
#undef cb | |||||
} | |||||
bool has_opr_format(const cg::OperatorNodeBase* opr) { | bool has_opr_format(const cg::OperatorNodeBase* opr) { | ||||
bool ret = false; | bool ret = false; | ||||
#define cb(_Opr) ret |= opr->dyn_typeinfo() == _Opr::typeinfo(); | #define cb(_Opr) ret |= opr->dyn_typeinfo() == _Opr::typeinfo(); | ||||
@@ -27,6 +27,9 @@ namespace intl { | |||||
bool has_available_algo(const VarNodeArray& i, const cg::OperatorNodeBase* opr); | bool has_available_algo(const VarNodeArray& i, const cg::OperatorNodeBase* opr); | ||||
bool has_no_naive_heuristic_algo( | |||||
const VarNodeArray& i, const cg::OperatorNodeBase* opr); | |||||
struct OprFormatInfo { | struct OprFormatInfo { | ||||
opr::Convolution::Param::Format opr_format; | opr::Convolution::Param::Format opr_format; | ||||
struct TensorFormatsInfo { | struct TensorFormatsInfo { | ||||
@@ -331,7 +331,8 @@ float ProfilerImpl::profile_operator( | |||||
opr::PoolingForward::typeinfo(), | opr::PoolingForward::typeinfo(), | ||||
}; | }; | ||||
if (multi_algo_oprs.count(opr->dyn_typeinfo()) && | if (multi_algo_oprs.count(opr->dyn_typeinfo()) && | ||||
!mgb::gopt::intl::has_available_algo(new_inps, y->owner_opr())) | |||||
(!mgb::gopt::intl::has_available_algo(new_inps, y->owner_opr()) || | |||||
!mgb::gopt::intl::has_no_naive_heuristic_algo(new_inps, y->owner_opr()))) | |||||
return PROFILE_TIME_OUT; | return PROFILE_TIME_OUT; | ||||
if (!m_opr_filter(opr, y->owner_opr())) | if (!m_opr_filter(opr, y->owner_opr())) | ||||
return PROFILE_TIME_OUT; | return PROFILE_TIME_OUT; | ||||