From bde2efa3b58412b52b8be9d05be35f11b74ae906 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 15 Apr 2022 19:54:07 +0800 Subject: [PATCH] feat(lite/load_and_run): support put and get model redis cache GitOrigin-RevId: 55c82e28c197197dc1762ce5e5550f9d88087ae6 --- lite/load_and_run/CMakeLists.txt | 21 +++++++++++++++++++ .../src/options/model_options.cpp | 5 ++++- lite/load_and_run/src/options/model_options.h | 1 + lite/src/mge/network_impl.h | 4 ++++ .../megbrain/utils/infile_persistent_cache.h | 7 +++++++ src/rdnn/impl/algo_chooser.cpp | 2 -- src/rdnn/include/megbrain/rdnn/algo_chooser.h | 1 + 7 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lite/load_and_run/CMakeLists.txt b/lite/load_and_run/CMakeLists.txt index 87d8c9c2f..6940024f7 100644 --- a/lite/load_and_run/CMakeLists.txt +++ b/lite/load_and_run/CMakeLists.txt @@ -30,11 +30,24 @@ if(UNIX) endif() endif() +if(LITE_BUILD_WITH_MGE + AND LITE_WITH_CUDA + AND NOT WIN32) + # FXIME third_party cpp redis do not support build with clang-cl + target_include_directories(load_and_run PRIVATE ${CPP_REDIS_INCLUDES}) +endif() + install( TARGETS load_and_run EXPORT ${LITE_EXPORT_TARGETS} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(BUILD_SHARED_LIBS) + if(LITE_BUILD_WITH_MGE + AND LITE_WITH_CUDA + AND NOT WIN32) + # FXIME third_party cpp redis do not support build with clang-cl + list(APPEND SOURCES ${CPP_REDIS_SRCS}) + endif() add_executable(load_and_run_depends_shared ${SOURCES}) target_link_libraries(load_and_run_depends_shared lite_shared) target_link_libraries(load_and_run_depends_shared gflags) @@ -58,6 +71,14 @@ if(BUILD_SHARED_LIBS) endif() endif() + if(LITE_BUILD_WITH_MGE + AND LITE_WITH_CUDA + AND NOT WIN32) + # FXIME third_party cpp redis do not support build with clang-cl + target_include_directories(load_and_run_depends_shared + PRIVATE ${CPP_REDIS_INCLUDES}) + endif() + install( TARGETS load_and_run_depends_shared EXPORT ${MGE_EXPORT_TARGETS} diff --git a/lite/load_and_run/src/options/model_options.cpp b/lite/load_and_run/src/options/model_options.cpp index a04fe33ea..38fb332f6 100644 --- a/lite/load_and_run/src/options/model_options.cpp +++ b/lite/load_and_run/src/options/model_options.cpp @@ -10,9 +10,12 @@ #include "model_options.h" #include "device_options.h" #include "lite/pack_model.h" +#include "megbrain/opr/search_policy/algo_chooser.h" +#include "megbrain/utils/infile_persistent_cache.h" #include "misc.h" #include "models/model_lite.h" #include "models/model_mdl.h" +#include "network_impl_base.h" namespace lar { template @@ -84,4 +87,4 @@ DEFINE_string( "https://megengine.megvii-inc.com/user-guide/deployment/lite/advance/" "pack-lite-model.html for more details."); -REGIST_OPTION_CREATOR(pack_model, lar::PackModelOption::create_option); +REGIST_OPTION_CREATOR(pack_model, lar::PackModelOption::create_option); \ No newline at end of file diff --git a/lite/load_and_run/src/options/model_options.h b/lite/load_and_run/src/options/model_options.h index 3f8218e64..020f39661 100644 --- a/lite/load_and_run/src/options/model_options.h +++ b/lite/load_and_run/src/options/model_options.h @@ -9,6 +9,7 @@ #pragma once #include +#include "megbrain/graph/operator_node.h" #include "models/model.h" #include "option_base.h" diff --git a/lite/src/mge/network_impl.h b/lite/src/mge/network_impl.h index 78c5715da..4a99c9781 100644 --- a/lite/src/mge/network_impl.h +++ b/lite/src/mge/network_impl.h @@ -176,6 +176,10 @@ public: //! dump network after global layout transform optimization void dump_layout_transform_model(std::string optimized_model_path); + mgb::serialization::GraphLoader::LoadResult get_load_result() { + return m_load_result; + } + private: //! construct the outputspec according to the m_network_io, and set the //! call_back to the outputspec diff --git a/src/core/include/megbrain/utils/infile_persistent_cache.h b/src/core/include/megbrain/utils/infile_persistent_cache.h index 088f766a6..2d212049d 100644 --- a/src/core/include/megbrain/utils/infile_persistent_cache.h +++ b/src/core/include/megbrain/utils/infile_persistent_cache.h @@ -78,6 +78,13 @@ public: MGE_WIN_DECLSPEC_FUC void put( const std::string& category, const Blob& key, const Blob& value) override; bool support_dump_cache() override { return true; } + + std::unordered_map< + std::string, + std::unordered_map> + get_cache() { + return std::move(m_cache); + } }; } // namespace mgb diff --git a/src/rdnn/impl/algo_chooser.cpp b/src/rdnn/impl/algo_chooser.cpp index fae3aea97..6a8da7899 100644 --- a/src/rdnn/impl/algo_chooser.cpp +++ b/src/rdnn/impl/algo_chooser.cpp @@ -28,8 +28,6 @@ using namespace mgb; // timeout delta to be added with fastest known algorithm for new algos constexpr double TIMEOUT_TOLERANCE = 2; -#define CACHE_KEY_VERSION "v5" - namespace { template diff --git a/src/rdnn/include/megbrain/rdnn/algo_chooser.h b/src/rdnn/include/megbrain/rdnn/algo_chooser.h index 98defa7d1..40ff1ca0c 100644 --- a/src/rdnn/include/megbrain/rdnn/algo_chooser.h +++ b/src/rdnn/include/megbrain/rdnn/algo_chooser.h @@ -6,6 +6,7 @@ #include "megbrain/utils/persistent_cache.h" #include "megdnn/oprs/base.h" +#define CACHE_KEY_VERSION "v5" namespace mgb { namespace rdnn { -- GitLab