Browse Source

feat(lite/load_and_run): support put and get model redis cache

GitOrigin-RevId: 55c82e28c1
release-1.10
Megvii Engine Team 3 years ago
parent
commit
bde2efa3b5
7 changed files with 38 additions and 3 deletions
  1. +21
    -0
      lite/load_and_run/CMakeLists.txt
  2. +4
    -1
      lite/load_and_run/src/options/model_options.cpp
  3. +1
    -0
      lite/load_and_run/src/options/model_options.h
  4. +4
    -0
      lite/src/mge/network_impl.h
  5. +7
    -0
      src/core/include/megbrain/utils/infile_persistent_cache.h
  6. +0
    -2
      src/rdnn/impl/algo_chooser.cpp
  7. +1
    -0
      src/rdnn/include/megbrain/rdnn/algo_chooser.h

+ 21
- 0
lite/load_and_run/CMakeLists.txt View File

@@ -30,11 +30,24 @@ if(UNIX)
endif() endif()
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( install(
TARGETS load_and_run TARGETS load_and_run
EXPORT ${LITE_EXPORT_TARGETS} EXPORT ${LITE_EXPORT_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(BUILD_SHARED_LIBS) 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}) 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 lite_shared)
target_link_libraries(load_and_run_depends_shared gflags) target_link_libraries(load_and_run_depends_shared gflags)
@@ -58,6 +71,14 @@ if(BUILD_SHARED_LIBS)
endif() endif()
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( install(
TARGETS load_and_run_depends_shared TARGETS load_and_run_depends_shared
EXPORT ${MGE_EXPORT_TARGETS} EXPORT ${MGE_EXPORT_TARGETS}


+ 4
- 1
lite/load_and_run/src/options/model_options.cpp View File

@@ -10,9 +10,12 @@
#include "model_options.h" #include "model_options.h"
#include "device_options.h" #include "device_options.h"
#include "lite/pack_model.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 "misc.h"
#include "models/model_lite.h" #include "models/model_lite.h"
#include "models/model_mdl.h" #include "models/model_mdl.h"
#include "network_impl_base.h"


namespace lar { namespace lar {
template <typename ModelImpl> template <typename ModelImpl>
@@ -84,4 +87,4 @@ DEFINE_string(
"https://megengine.megvii-inc.com/user-guide/deployment/lite/advance/" "https://megengine.megvii-inc.com/user-guide/deployment/lite/advance/"
"pack-lite-model.html for more details."); "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);

+ 1
- 0
lite/load_and_run/src/options/model_options.h View File

@@ -9,6 +9,7 @@


#pragma once #pragma once
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include "megbrain/graph/operator_node.h"
#include "models/model.h" #include "models/model.h"
#include "option_base.h" #include "option_base.h"




+ 4
- 0
lite/src/mge/network_impl.h View File

@@ -176,6 +176,10 @@ public:
//! dump network after global layout transform optimization //! dump network after global layout transform optimization
void dump_layout_transform_model(std::string optimized_model_path); void dump_layout_transform_model(std::string optimized_model_path);


mgb::serialization::GraphLoader::LoadResult get_load_result() {
return m_load_result;
}

private: private:
//! construct the outputspec according to the m_network_io, and set the //! construct the outputspec according to the m_network_io, and set the
//! call_back to the outputspec //! call_back to the outputspec


+ 7
- 0
src/core/include/megbrain/utils/infile_persistent_cache.h View File

@@ -78,6 +78,13 @@ public:
MGE_WIN_DECLSPEC_FUC void put( MGE_WIN_DECLSPEC_FUC void put(
const std::string& category, const Blob& key, const Blob& value) override; const std::string& category, const Blob& key, const Blob& value) override;
bool support_dump_cache() override { return true; } bool support_dump_cache() override { return true; }

std::unordered_map<
std::string,
std::unordered_map<BlobStorage, BlobStorage, BlobStorage::Hash>>
get_cache() {
return std::move(m_cache);
}
}; };
} // namespace mgb } // namespace mgb




+ 0
- 2
src/rdnn/impl/algo_chooser.cpp View File

@@ -28,8 +28,6 @@ using namespace mgb;
// timeout delta to be added with fastest known algorithm for new algos // timeout delta to be added with fastest known algorithm for new algos
constexpr double TIMEOUT_TOLERANCE = 2; constexpr double TIMEOUT_TOLERANCE = 2;


#define CACHE_KEY_VERSION "v5"

namespace { namespace {


template <class MegDNNOpr> template <class MegDNNOpr>


+ 1
- 0
src/rdnn/include/megbrain/rdnn/algo_chooser.h View File

@@ -6,6 +6,7 @@
#include "megbrain/utils/persistent_cache.h" #include "megbrain/utils/persistent_cache.h"
#include "megdnn/oprs/base.h" #include "megdnn/oprs/base.h"


#define CACHE_KEY_VERSION "v5"
namespace mgb { namespace mgb {
namespace rdnn { namespace rdnn {




Loading…
Cancel
Save