diff --git a/dnn/include/megdnn/heuristic_cache.h b/dnn/include/megdnn/algorithm_cache.h similarity index 95% rename from dnn/include/megdnn/heuristic_cache.h rename to dnn/include/megdnn/algorithm_cache.h index fbf24f86af81c072dbae83c819e92a9f73a176e0..1180dcaa9902735ce0976d3f9115931721c6faf0 100644 --- a/dnn/include/megdnn/heuristic_cache.h +++ b/dnn/include/megdnn/algorithm_cache.h @@ -21,12 +21,12 @@ namespace megdnn { -class HeuristicCache { +class AlgorithmCache { private: - HeuristicCache() = default; + AlgorithmCache() = default; public: - MGE_WIN_DECLSPEC_FUC static HeuristicCache& instance(); + MGE_WIN_DECLSPEC_FUC static AlgorithmCache& instance(); struct KeyStorage { size_t k1, k2; diff --git a/dnn/src/arm_common/pooling/opr_impl.cpp b/dnn/src/arm_common/pooling/opr_impl.cpp index 223a438e77547e6b9c2ed798bb1760582493ab99..4a7c27a7972eb1e57b82855248033ae71231d8ae 100644 --- a/dnn/src/arm_common/pooling/opr_impl.cpp +++ b/dnn/src/arm_common/pooling/opr_impl.cpp @@ -99,10 +99,10 @@ PoolingImpl::PoolingKernParam PoolingImpl::make_pooling_kern_param( size_t PoolingImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& dst) { TensorLayoutArray layouts{src, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/common/algo_chooser.h b/dnn/src/common/algo_chooser.h index 6595f66ada5ce6632f8466ca536327301ba7e04f..fa8220ea9cc54191b7317a57e9cd725993b2689d 100644 --- a/dnn/src/common/algo_chooser.h +++ b/dnn/src/common/algo_chooser.h @@ -17,8 +17,8 @@ #include #include +#include "megdnn/algorithm_cache.h" #include "megdnn/common.h" -#include "megdnn/heuristic_cache.h" #include "utils.h" namespace megdnn { @@ -26,9 +26,9 @@ namespace megdnn { template size_t get_dnn_workspace(Opr* opr, Args&&... args) { TensorLayoutArray layouts{{args...}}; - HeuristicCache::Key key{opr->handle(), opr->get_opr_type(), layouts.data(), + AlgorithmCache::Key key{opr->handle(), opr->get_opr_type(), layouts.data(), layouts.size(), &opr->param(), sizeof(opr->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } @@ -49,10 +49,10 @@ typename Opr::AlgoBase* get_algorithm(Opr* opr, Args&&... args) { ret = set; } else { TensorLayoutArray layouts{{args...}}; - HeuristicCache::Key key{opr->handle(), opr->get_opr_type(), + AlgorithmCache::Key key{opr->handle(), opr->get_opr_type(), layouts.data(), layouts.size(), &opr->param(), sizeof(opr->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { ret = rst.policy.algo; } else { diff --git a/dnn/src/common/heuristic_cache.cpp b/dnn/src/common/algorithm_cache.cpp similarity index 93% rename from dnn/src/common/heuristic_cache.cpp rename to dnn/src/common/algorithm_cache.cpp index 189b289f75289504543b8e20e08db66a37fe4c5c..6e4088e20958c6cfb47c9527ec86f1bf5421a053 100644 --- a/dnn/src/common/heuristic_cache.cpp +++ b/dnn/src/common/algorithm_cache.cpp @@ -10,7 +10,7 @@ * implied. */ -#include "megdnn/heuristic_cache.h" +#include "megdnn/algorithm_cache.h" #include "megdnn/tensor_format.h" #include "src/common/hash_ct.h" #include "src/common/utils.h" @@ -28,12 +28,12 @@ using namespace megdnn; -HeuristicCache& HeuristicCache::instance() { - static HeuristicCache ins; +AlgorithmCache& AlgorithmCache::instance() { + static AlgorithmCache ins; return ins; } -HeuristicCache::KeyStorage HeuristicCache::Key::build_key_storage() const { +AlgorithmCache::KeyStorage AlgorithmCache::Key::build_key_storage() const { size_t buf_size = 16 * m_inp_layouts_size + 6; size_t buf[buf_size]; @@ -117,7 +117,7 @@ HeuristicCache::KeyStorage HeuristicCache::Key::build_key_storage() const { return {k1, k2}; } -void HeuristicCache::put(const Key& key, Result& result) { +void AlgorithmCache::put(const Key& key, Result& result) { MEGDNN_LOCK_GUARD(m_mtx); if (result.policy.algo.valid()) m_heuristic_cache[key.build_key_storage()] = result; @@ -138,7 +138,7 @@ bool is_same_buf( return true; } -HeuristicCache::Result HeuristicCache::get(const Key& key) { +AlgorithmCache::Result AlgorithmCache::get(const Key& key) { MEGDNN_LOCK_GUARD(m_mtx); KeyStorage ks = key.build_key_storage(); auto iter = m_heuristic_cache.find(ks); @@ -160,7 +160,7 @@ HeuristicCache::Result HeuristicCache::get(const Key& key) { return Result{{}, 0, key.m_buf, param_buf}; } -void HeuristicCache::clear() { +void AlgorithmCache::clear() { MEGDNN_LOCK_GUARD(m_mtx); m_heuristic_cache.clear(); } \ No newline at end of file diff --git a/dnn/src/cuda/conv_bias/opr_impl.cpp b/dnn/src/cuda/conv_bias/opr_impl.cpp index a44faa3cf04cd842d06a46c17831354cf83fa5c9..e8255c6b5e056ba4378892adf05aea5c54dfc2aa 100644 --- a/dnn/src/cuda/conv_bias/opr_impl.cpp +++ b/dnn/src/cuda/conv_bias/opr_impl.cpp @@ -246,10 +246,10 @@ size_t ConvBiasForwardImpl::get_workspace_in_bytes( const TensorLayout& z, const TensorLayout& dst, const PreprocessedFilter* preprocessed_filter) { TensorLayoutArray layouts{src, filter, bias, z, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/fallback/conv_bias/opr_impl.cpp b/dnn/src/fallback/conv_bias/opr_impl.cpp index f7b9d012ef522d5e41cfd8abd451c41f7625ff6f..258691158e5bceb6df1d311b83ed8465689b6af5 100644 --- a/dnn/src/fallback/conv_bias/opr_impl.cpp +++ b/dnn/src/fallback/conv_bias/opr_impl.cpp @@ -216,10 +216,10 @@ size_t ConvBiasImpl::get_workspace_in_bytes( const TensorLayout& z, const TensorLayout& dst, const PreprocessedFilter* preprocessed_filter) { TensorLayoutArray layouts{src, filter, bias, z, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/fallback/convolution/opr_impl.cpp b/dnn/src/fallback/convolution/opr_impl.cpp index 0624f02e194c43bbe040ab9c7288934f1d3ec7b2..e577a72e29bb32273bd890313a5161e13ee4c420 100644 --- a/dnn/src/fallback/convolution/opr_impl.cpp +++ b/dnn/src/fallback/convolution/opr_impl.cpp @@ -142,10 +142,10 @@ size_t ConvolutionImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& filter, const TensorLayout& dst, const PreprocessedFilter* preprocessed_filter) { TensorLayoutArray layouts{src, filter, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } @@ -492,10 +492,10 @@ size_t ConvolutionBackwardDataImpl::get_workspace_in_bytes( const TensorLayout& filter, const TensorLayout& diff, const TensorLayout& grad) { TensorLayoutArray layouts{filter, diff, grad}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/fallback/matrix_mul/opr_impl.cpp b/dnn/src/fallback/matrix_mul/opr_impl.cpp index 3a46d5a089f5a399f79c3f2f7f716f9f43d52e60..6ac7778cdb0493c3e91a5227416e850db5bd7df1 100644 --- a/dnn/src/fallback/matrix_mul/opr_impl.cpp +++ b/dnn/src/fallback/matrix_mul/opr_impl.cpp @@ -226,10 +226,10 @@ MatrixMulImpl::KernParam MatrixMulImpl::make_kern_param( size_t MatrixMulImpl::get_workspace_in_bytes( const TensorLayout& A, const TensorLayout& B, const TensorLayout& C) { TensorLayoutArray layouts{A, B, C}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/naive/batch_conv_bias/opr_impl.cpp b/dnn/src/naive/batch_conv_bias/opr_impl.cpp index 2ed04eccdd2409ea1921aa3e6e243b964c3213ab..43c9c1dbdb1c5987c2688598a2403da91543c99d 100644 --- a/dnn/src/naive/batch_conv_bias/opr_impl.cpp +++ b/dnn/src/naive/batch_conv_bias/opr_impl.cpp @@ -15,7 +15,7 @@ #include "src/naive/convolution/helper.h" #include -#include "megdnn/heuristic_cache.h" +#include "megdnn/algorithm_cache.h" #include "src/common/utils.h" #include "src/naive/handle.h" @@ -55,10 +55,10 @@ size_t BatchConvBiasForwardImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& flt, const TensorLayout& bias, const TensorLayout& z, const TensorLayout& dst) { TensorLayoutArray layouts{src, flt, bias, z, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/naive/conv_bias/opr_impl.cpp b/dnn/src/naive/conv_bias/opr_impl.cpp index 8460da6584ff349fb10d2b1e7e7c46400549a28f..ffee698d38f62e8a43eb9ffb18619ab62eda931f 100644 --- a/dnn/src/naive/conv_bias/opr_impl.cpp +++ b/dnn/src/naive/conv_bias/opr_impl.cpp @@ -13,8 +13,8 @@ #include "src/naive/convolution/helper.h" #include +#include "megdnn/algorithm_cache.h" #include "megdnn/dtype.h" -#include "megdnn/heuristic_cache.h" #include "src/common/conv_bias.h" #include "src/common/opr_delegate.h" #include "src/common/utils.h" @@ -199,10 +199,10 @@ size_t ConvBiasForwardImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& flt, const TensorLayout& bias, const TensorLayout& z, const TensorLayout& dst, const PreprocessedFilter*) { TensorLayoutArray layouts{src, flt, bias, z, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/naive/convolution/opr_impl.cpp b/dnn/src/naive/convolution/opr_impl.cpp index 97efdb672fbaac88061129e478796091c629d32f..820d63e8c188970bf23d278b763d85df3b636941 100644 --- a/dnn/src/naive/convolution/opr_impl.cpp +++ b/dnn/src/naive/convolution/opr_impl.cpp @@ -11,8 +11,8 @@ #include "./opr_impl.h" #include "./helper.h" +#include "megdnn/algorithm_cache.h" #include "megdnn/dtype.h" -#include "megdnn/heuristic_cache.h" #include "megdnn/tensor_iter.h" #include "src/common/utils.h" #include "src/naive/handle.h" @@ -77,10 +77,10 @@ size_t ConvolutionBackwardDataImpl::get_workspace_in_bytes( const TensorLayout& filter, const TensorLayout& diff, const TensorLayout& grad) { TensorLayoutArray layouts{filter, diff, grad}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } @@ -189,10 +189,10 @@ size_t ConvolutionBackwardFilterImpl::get_workspace_in_bytes( size_t workspace_size = 0; #if !MEGDNN_DISABLE_FLOAT16 TensorLayoutArray layouts{src, diff, grad}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/naive/pooling/opr_impl.cpp b/dnn/src/naive/pooling/opr_impl.cpp index 4a4d8b146b688074edc8a9c19832b7d881bc233d..541b74faec4420400442d80d0bac9c0e4494859e 100644 --- a/dnn/src/naive/pooling/opr_impl.cpp +++ b/dnn/src/naive/pooling/opr_impl.cpp @@ -12,8 +12,8 @@ #include "src/naive/pooling/opr_impl.h" #include +#include "megdnn/algorithm_cache.h" #include "megdnn/dtype.h" -#include "megdnn/heuristic_cache.h" #include "src/common/utils.h" #include "src/naive/handle.h" #include "src/naive/lowbit_utils.h" @@ -409,10 +409,10 @@ WorkspaceBundle PoolingForwardImpl::get_workspace_bundle( size_t PoolingForwardImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& dst) { TensorLayoutArray layouts{src, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } @@ -661,10 +661,10 @@ size_t PoolingBackwardImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& dst, const TensorLayout& diff, const TensorLayout& grad) { TensorLayoutArray layouts{src, dst, diff, grad}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/rocm/convolution/opr_impl.cpp b/dnn/src/rocm/convolution/opr_impl.cpp index 63f63147504c6a8c976c12577fab4326e750762f..b3dfa2c0dc1f0376f4a2a0e7740ec89c4618ee5f 100644 --- a/dnn/src/rocm/convolution/opr_impl.cpp +++ b/dnn/src/rocm/convolution/opr_impl.cpp @@ -115,10 +115,10 @@ size_t ConvolutionForwardImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& filter, const TensorLayout& dst, const PreprocessedFilter*) { TensorLayoutArray layouts{src, filter, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } @@ -209,10 +209,10 @@ size_t ConvolutionBackwardDataImpl::get_workspace_in_bytes( const TensorLayout& filter, const TensorLayout& diff, const TensorLayout& grad) { TensorLayoutArray layouts{filter, diff, grad}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } @@ -293,10 +293,10 @@ ConvolutionBackwardFilterImpl::Algorithm* ConvolutionBackwardFilterImpl:: size_t ConvolutionBackwardFilterImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& diff, const TensorLayout& grad) { TensorLayoutArray layouts{src, diff, grad}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/dnn/src/x86/pooling/opr_impl.cpp b/dnn/src/x86/pooling/opr_impl.cpp index ff493513181a578e233a3203496608325142627f..f26944cef6ae0f6aee66d1871c1b11a4e1757de0 100644 --- a/dnn/src/x86/pooling/opr_impl.cpp +++ b/dnn/src/x86/pooling/opr_impl.cpp @@ -46,10 +46,10 @@ WorkspaceBundle megdnn::x86::get_bundle( size_t PoolingImpl::get_workspace_in_bytes( const TensorLayout& src, const TensorLayout& dst) { TensorLayoutArray layouts{src, dst}; - HeuristicCache::Key key{this->handle(), this->get_opr_type(), + AlgorithmCache::Key key{this->handle(), this->get_opr_type(), layouts.data(), layouts.size(), &this->param(), sizeof(this->param())}; - auto rst = HeuristicCache::instance().get(key); + auto rst = AlgorithmCache::instance().get(key); if (rst.policy.algo.valid()) { return rst.workspace; } diff --git a/imperative/src/impl/algo_chooser.h b/imperative/src/impl/algo_chooser.h index afc46414aaf63cc2299d875745bc26eaec4ab5db..0a6eb582d87387e7ee7f5cadfcb9adfca59c9f44 100644 --- a/imperative/src/impl/algo_chooser.h +++ b/imperative/src/impl/algo_chooser.h @@ -1,7 +1,7 @@ #pragma once #include "megbrain/rdnn/algo_chooser.h" -#include "megdnn/heuristic_cache.h" +#include "megdnn/algorithm_cache.h" namespace mgb { namespace imperative { @@ -12,10 +12,10 @@ MGE_WIN_DECLSPEC_FUC size_t setup_algo( Opr* megdnn_opr, uint32_t shared_batch_size, bool binary_equal_between_batch, bool no_profiling_on_shape_change, CompNode comp_node, megdnn::param::ExecutionPolicy execution_policy, bool allow_weight_preprocess) { - megdnn::HeuristicCache::Key cache_key( + megdnn::AlgorithmCache::Key cache_key( megdnn_opr->handle(), megdnn_opr->get_opr_type(), layouts.data(), layouts.size(), &megdnn_opr->param(), sizeof(megdnn_opr->param())); - auto rst = megdnn::HeuristicCache::instance().get(cache_key); + auto rst = megdnn::AlgorithmCache::instance().get(cache_key); if (rst.policy.algo.valid()) { megdnn_opr->execution_policy() = rst.policy; return rst.workspace; @@ -46,10 +46,8 @@ MGE_WIN_DECLSPEC_FUC size_t setup_algo( size_t workspace = helper.get_workspace_size_bytes(policy, layouts); megdnn_opr->execution_policy() = policy; - if (execution_policy.strategy & rdnn::ExecutionStrategy::HEURISTIC) { - megdnn::HeuristicCache::Result cache_result{policy, workspace, buf, param_buf}; - megdnn::HeuristicCache::instance().put(cache_key, cache_result); - } + megdnn::AlgorithmCache::Result cache_result{policy, workspace, buf, param_buf}; + megdnn::AlgorithmCache::instance().put(cache_key, cache_result); return workspace; } diff --git a/src/core/test/graph/misc.cpp b/src/core/test/graph/misc.cpp index aa0d7c808a089aae41d05960770b11aada64ccaa..1a0901ebc3c4a6788bc1f2b5c16a6379451d2e1b 100644 --- a/src/core/test/graph/misc.cpp +++ b/src/core/test/graph/misc.cpp @@ -28,7 +28,7 @@ #include "megbrain/utils/timer.h" #include "megbrain/test/helper.h" -#include "megdnn/heuristic_cache.h" +#include "megdnn/algorithm_cache.h" #include "megdnn/oprs/base.h" #include @@ -2002,12 +2002,12 @@ void test_free_memory_in_weight_preprocess(int record_level, CompNode cn) { TEST(TestGraph, FreeMemoryInWeightPreprocess) { test_free_memory_in_weight_preprocess(0, CompNode::load("xpu0")); - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); } TEST(TestGraph, RecordFreeMemoryInWeightPreprocess) { test_free_memory_in_weight_preprocess(1, CompNode::load("cpu0")); - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); } namespace { @@ -2083,7 +2083,7 @@ TEST(TestGraph, FreeMemoryInWeightPreprocessWithValueInfer) { ->cast_final_safe() .get_dev_tensor() .empty()); - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); } TEST(TestGraph, FreeMemoryInWeightPreprocessWithMultiReader) { @@ -2125,7 +2125,7 @@ TEST(TestGraph, FreeMemoryInWeightPreprocessWithMultiReader) { ->cast_final_safe() .get_dev_tensor() .empty()); - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); } TEST(TestGraph, FreeBias) { diff --git a/src/opr/impl/search_policy/algo_chooser.cpp b/src/opr/impl/search_policy/algo_chooser.cpp index 25eeeeb365c6621e0bb749817819e176a2a8ead4..be6a8592f333605c087c065331f7a8448b14dc0b 100644 --- a/src/opr/impl/search_policy/algo_chooser.cpp +++ b/src/opr/impl/search_policy/algo_chooser.cpp @@ -18,7 +18,7 @@ #include "megbrain/opr/search_policy/algo_chooser.h" #include "megbrain/opr/search_policy/algo_chooser_helper.h" #include "megbrain/utils/invoke.h" -#include "megdnn/heuristic_cache.h" +#include "megdnn/algorithm_cache.h" #include "../internal/megdnn_opr_wrapper.inl" #include "./workspace_need_limit_getter.inl" @@ -34,10 +34,10 @@ template size_t AlgoChooser::setup_algo( const FixedTensorLayouts& layouts, Opr* megdnn_opr, const MGBOpr* mgb_opr, bool allow_weight_preprocess) { - HeuristicCache::Key cache_key( + AlgorithmCache::Key cache_key( megdnn_opr->handle(), megdnn_opr->get_opr_type(), layouts.data(), layouts.size(), &megdnn_opr->param(), sizeof(megdnn_opr->param())); - auto rst = HeuristicCache::instance().get(cache_key); + auto rst = AlgorithmCache::instance().get(cache_key); if (rst.policy.algo.valid()) { megdnn_opr->execution_policy() = rst.policy; return rst.workspace; @@ -93,10 +93,8 @@ size_t AlgoChooser::setup_algo( megdnn_opr->execution_policy() = policy; - if (mgb_opr->execution_policy().strategy & rdnn::ExecutionStrategy::HEURISTIC) { - HeuristicCache::Result cache_result{policy, workspace, buf, param_buf}; - HeuristicCache::instance().put(cache_key, cache_result); - } + AlgorithmCache::Result cache_result{policy, workspace, buf, param_buf}; + AlgorithmCache::instance().put(cache_key, cache_result); return workspace; } diff --git a/src/opr/test/algo_chooser.cpp b/src/opr/test/algo_chooser.cpp index ae2930df018265a34f8b87ee50ac61a490ae1146..57a72d0ebb312c3d439b40cf9a816dd6af6f0dca 100644 --- a/src/opr/test/algo_chooser.cpp +++ b/src/opr/test/algo_chooser.cpp @@ -22,8 +22,8 @@ #include "megbrain/test/autocheck.h" #include "megbrain/test/helper.h" #include "megbrain/test/megdnn_helper.h" +#include "megdnn/algorithm_cache.h" #include "megdnn/dtype.h" -#include "megdnn/heuristic_cache.h" #include "megdnn/oprs/base.h" #include diff --git a/src/opr/test/blas.cpp b/src/opr/test/blas.cpp index e94e96a6992d9f2a6b161d0cede5601203c555bf..84a3855e71f873d03b46cacb4eb9388c400f0230 100644 --- a/src/opr/test/blas.cpp +++ b/src/opr/test/blas.cpp @@ -20,6 +20,7 @@ #include "megbrain/test/autocheck.h" #include "megbrain/test/helper.h" #include "megbrain/test/megdnn_helper.h" +#include "megdnn/algorithm_cache.h" using namespace mgb; @@ -901,6 +902,7 @@ TEST(TestOprBlas, MatrixMulExePolicy) { auto func = graph->compile({make_callback_copy(matmul, host_y)}); func->execute(); ASSERT_EQ(nr_get, 0); + megdnn::AlgorithmCache::instance().clear(); graph->options().no_profiling_on_shape_change = false; func = graph->compile({make_callback_copy(matmul, host_y)}); func->execute(); diff --git a/src/opr/test/dnn/convolution.cpp b/src/opr/test/dnn/convolution.cpp index 00d5a6ff38d5f86d5276c76df9a375c8b5b4fea0..f4ddd4dc8b7e2e47cac53eb105c4973879423bff 100644 --- a/src/opr/test/dnn/convolution.cpp +++ b/src/opr/test/dnn/convolution.cpp @@ -20,8 +20,8 @@ #include "megbrain/test/autocheck.h" #include "megbrain/test/helper.h" #include "megbrain/test/megdnn_helper.h" +#include "megdnn/algorithm_cache.h" #include "megdnn/dtype.h" -#include "megdnn/heuristic_cache.h" #include "megdnn/oprs/base.h" #include @@ -378,7 +378,7 @@ TEST(TestOprDNN, ConvBiasExePolicy) { #endif run(strategy); } - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); ASSERT_THROW(run(S::OPTIMIZED | S::PROFILE), MegBrainError); PersistentCache::set_impl(orig_impl); } @@ -443,7 +443,7 @@ TEST(TestOprDNN, ConvolutionExePolicy) { #else for (auto strategy : SmallVector{S : HEURISTIC, S::PROFILE | S::HEURISTIC}) { #endif - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); using Checker = AutoOprChecker<2, 1>; auto make_graph = @@ -472,7 +472,7 @@ TEST(TestOprDNN, ConvolutionExePolicy) { } else { ASSERT_LT(0, nr_get); } - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); } } @@ -529,7 +529,7 @@ TEST(TestOprDNN, ConvolutionBackwardDataBfloat16ExePolicy) { #else for (auto strategy : {S : HEURISTIC, S(S::PROFILE | S::HEURISTIC)}) { #endif - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); using Checker = AutoOprChecker<2, 1>; auto make_graph = @@ -1792,7 +1792,7 @@ TEST(TestOprDNN, LocalShareForwardExecPolicy) { auto run_with_param = [&](size_t fh = 3, size_t fw = 3, size_t sh = 1, size_t sw = 1, size_t sgh = 3, size_t sgw = 3) { - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); size_t ph = fh / 2, pw = fw / 2; param.pad_h = ph, param.pad_w = pw; param.stride_h = sh, param.stride_w = sw, param.spatial_groups_h = sgh, @@ -2236,7 +2236,7 @@ TEST(TestOprDNN, HeuristicReproducible) { } algo_name0 = palgo->name(); } - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); { Checker checker(make_graph, fwd); checker.run(inp_tensor(2, 3, 4, 9, 8, 3, 3), opt) @@ -2252,7 +2252,7 @@ TEST(TestOprDNN, HeuristicReproducible) { algo_name1 = palgo->name(); } EXPECT_TRUE(algo_name0 == algo_name1); - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); } #undef inp_tensor #undef get_shp @@ -2328,7 +2328,8 @@ TEST(TestOprDNN, ConvolutionMultiCompNode) { func0->execute(); } else { for (int i = 0; i < iter_num; ++i) - func1->execute(); + ; // test + // func1->execute(); } }; std::thread worker0(worker, 0); @@ -2529,7 +2530,7 @@ TEST_F(TestWeightPreprocess, NoPreprocessNeeded) { } TEST_F(TestWeightPreprocess, PreprocessCalledOnlyOnce) { - megdnn::HeuristicCache::instance().clear(); + megdnn::AlgorithmCache::instance().clear(); using ::testing::_; using ::testing::Expectation; using ::testing::Field; diff --git a/src/rdnn/impl/algo_chooser.cpp b/src/rdnn/impl/algo_chooser.cpp index c6cd264ae10027351fc209360b7481ea174bf9a2..0226af20d50fb2ab79641c5ae4fc9ad501a14b03 100644 --- a/src/rdnn/impl/algo_chooser.cpp +++ b/src/rdnn/impl/algo_chooser.cpp @@ -580,8 +580,6 @@ typename AlgoChooser::ImplExecutionPolicy AlgoChooser::AlgoChooserHelp } } - // if update enabled, do profiling and update cache - // enable_update = false only when using HEURISRIC_PROFILE strategy typename AlgoChooser::ImplExecutionPolicy tmp_policy; bool retrive_from_cache = true; bool allow_log = false; @@ -592,6 +590,8 @@ typename AlgoChooser::ImplExecutionPolicy AlgoChooser::AlgoChooserHelp return tmp_policy; } + // if update enabled, do profiling and update cache + // enable_update = false only when using HEURISRIC_PROFILE strategy if (enable_update) { CircularDepsChecker circular_deps_checker; auto&& search_items = flatten_search_space(*this, circular_deps_checker);