提交 93310c0e 编写于 作者: M Megvii Engine Team

fix(mgb/gopt): fix cpu global layout transform fastrun error

GitOrigin-RevId: ea254297e5e46134490c9aa9f1e98861493ba015
上级 3ff5ca5f
......@@ -12,6 +12,7 @@
#pragma once
#include "megbrain_build_config.h"
#include "megdnn/oprs/base.h"
#if MGB_ENABLE_GETENV
#define MGB_GETENV ::std::getenv
......@@ -36,6 +37,11 @@ bool has_available_algo(Opr* opr, Args&&... args) {
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
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
......@@ -220,6 +220,28 @@ struct MultiAlgoOprTrait;
::megdnn::has_available_algo(megdnn_opr, args...), array_layouts); \
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(ConvBiasForward)
......@@ -365,6 +387,23 @@ bool has_available_algo(const VarNodeArray& i, const cg::OperatorNodeBase* opr)
#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 ret = false;
#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_no_naive_heuristic_algo(
const VarNodeArray& i, const cg::OperatorNodeBase* opr);
struct OprFormatInfo {
opr::Convolution::Param::Format opr_format;
struct TensorFormatsInfo {
......
......@@ -331,7 +331,8 @@ float ProfilerImpl::profile_operator(
opr::PoolingForward::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;
if (!m_opr_filter(opr, y->owner_opr()))
return PROFILE_TIME_OUT;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册