Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further caching implementation #11

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8c79d41
Update Convert extender (#4409)
Feb 19, 2021
7e3289c
added condition for removing input ports (#4396)
yekruglov Feb 20, 2021
bf6b061
Fix MVN in MO (#4311)
mvafin Feb 20, 2021
434a517
* Fix for ia32 with sse42 issue. (#4433)
Feb 20, 2021
61f1950
Infer tool code style patch (#4429)
omartiny Feb 20, 2021
8397ed6
Enabled reduce tests (#4416)
ilyachur Feb 20, 2021
f66607a
Make Python bridge independent (#4436)
SDxKeeper Feb 20, 2021
2434190
Review leftovers (#4274)
Feb 20, 2021
f4bb288
Merge remote-tracking branch 'upstream/master' into mn_model_cache2
nosovmik Feb 20, 2021
5b1c151
Moved Cache Manager to public API
nosovmik Feb 23, 2021
559eb43
Documentation for CacheManager
nosovmik Feb 24, 2021
d630d1f
Removed unsupported doc tag
nosovmik Feb 24, 2021
5929dc3
Few more trivial fixes of style
nosovmik Feb 24, 2021
49d1fdc
Moved CacheManager from public API to private
nosovmik Feb 25, 2021
c90204f
LoadNetwork by model name implementation
nosovmik Feb 25, 2021
9465e44
Added -cache option to benchmark_appAlso added debug timestamps to my…
nosovmik Feb 25, 2021
2f5a46e
Functional tests for Loading networks with RemoteContext
nosovmik Feb 26, 2021
070d703
Functional test for Device architecture
nosovmik Feb 26, 2021
e9a3373
Cache dir changes:
nosovmik Feb 26, 2021
6ff31f7
Fixed cpplint and linux failures
nosovmik Feb 26, 2021
cdb2f98
2 more tests for throw on import and plugin without device architecture
nosovmik Feb 27, 2021
7d01f23
Removed OStreamAdapter as not needed anymore
nosovmik Feb 27, 2021
7791746
Revert "Removed OStreamAdapter as not needed anymore"
nosovmik Feb 28, 2021
442997f
Fixes for Hetero case
nosovmik Feb 28, 2021
9c43f65
Add check for correct DEVICE_ID in unit tests
nosovmik Feb 28, 2021
1050e85
Test for invalid cache dit
nosovmik Mar 1, 2021
bff6a24
Re-throw exception on failure of cache import and export
nosovmik Mar 1, 2021
d6d5c84
More ITT counters
nosovmik Mar 1, 2021
d213425
Add IMPORT_EXPORT_SUPPORT to GNA plugin
nosovmik Mar 1, 2021
86f8023
Disable serialization of network for hash calculation
nosovmik Mar 2, 2021
d52957c
Small fixes in GNA
nosovmik Mar 2, 2021
d911831
LoadFromFile - add hashing of file size and creation time
nosovmik Mar 3, 2021
41da16b
Fix error on exception of 'mkdir'
nosovmik Mar 4, 2021
25621d5
Reworked CompilationContext
nosovmik Mar 5, 2021
9d46efe
Revert OStreamAdapter changes
nosovmik Mar 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/template_plugin/src/template_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ InferenceEngine::Parameter Plugin::GetMetric(const std::string& name, const std:
METRIC_KEY(SUPPORTED_CONFIG_KEYS),
METRIC_KEY(FULL_DEVICE_NAME),
METRIC_KEY(OPTIMIZATION_CAPABILITIES),
METRIC_KEY(IMPORT_EXPORT_SUPPORT),
METRIC_KEY(DEVICE_ARCHITECTURE),
METRIC_KEY(RANGE_FOR_ASYNC_INFER_REQUESTS) };
IE_SET_METRIC_RETURN(SUPPORTED_METRICS, supportedMetrics);
Expand Down Expand Up @@ -270,6 +271,8 @@ InferenceEngine::Parameter Plugin::GetMetric(const std::string& name, const std:
// TODO: fill actual device architecture based on DEVICE_ID passed to `options`
std::string deviceArch = "TEMPLATE";
IE_SET_METRIC_RETURN(DEVICE_ARCHITECTURE, deviceArch);
} else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) {
IE_SET_METRIC_RETURN(IMPORT_EXPORT_SUPPORT, true);
} else if (METRIC_KEY(RANGE_FOR_ASYNC_INFER_REQUESTS) == name) {
// TODO: fill with actual values
using uint = unsigned int;
Expand Down
5 changes: 5 additions & 0 deletions inference-engine/include/ie_plugin_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ DECLARE_METRIC_KEY(NUMBER_OF_EXEC_INFER_REQUESTS, unsigned int);
*/
DECLARE_METRIC_KEY(DEVICE_ARCHITECTURE, std::string);

/**
* @brief Metric which defines support of import/export functions by plugin
*/
DECLARE_METRIC_KEY(IMPORT_EXPORT_SUPPORT, bool);

/**
* @brief Metric to get a name of network. String value is "NETWORK_NAME".
*/
Expand Down
2 changes: 1 addition & 1 deletion inference-engine/samples/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ int main(int argc, char *argv[]) {
for (auto&& item : config) {
ie.SetConfig(item.second, item.first);
}

ie.SetConfig({ {CONFIG_KEY(CACHE_DIR), "cacheBenchmark"} });
auto double_to_string = [] (const double number) {
std::stringstream ss;
ss << std::fixed << std::setprecision(2) << number;
Expand Down
6 changes: 3 additions & 3 deletions inference-engine/src/inference_engine/compilation_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ struct NetworkCompilationContext final {
} catch (const std::bad_cast &) {
// IR v7 or older is passed: cannot cast to CNNNetworkNGraphImpl
m_cachingIsAvailable = false;
std::cerr << "IR v7 is passed; skip import and export" << std::endl;
std::cerr << "mnosov: IR v7 is passed; skip import and export" << std::endl;
} catch (const ngraph::ngraph_error & ex) {
// failed to serialize the model - caching is not available
m_cachingIsAvailable = false;
std::cerr << ex.what() << std::endl;
std::cerr << "failed to serialize the model; skip import and export" << std::endl;
std::cerr << "mnosov: failed to serialize the model; skip import and export" << std::endl;
}

if (!m_cachingIsAvailable)
Expand Down Expand Up @@ -91,7 +91,7 @@ struct NetworkCompilationContext final {

// compute hash on weights if any
if (!m_weights.empty()) {
std::cerr << "Compute hash on weights" << std::endl;
std::cerr << "mnosov: Compute hash on weights" << std::endl;
for (const auto & c : m_weights) {
auto data = reinterpret_cast<const std::uint8_t *>(c->get_data_ptr());
auto data_size = c->get_element_type().size() * ngraph::shape_size(c->get_shape());
Expand Down
291 changes: 147 additions & 144 deletions inference-engine/src/inference_engine/ie_core.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions inference-engine/src/vpu/myriad_plugin/myriad_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ MyriadMetrics::MyriadMetrics() {
METRIC_KEY(RANGE_FOR_ASYNC_INFER_REQUESTS),
METRIC_KEY(DEVICE_THERMAL),
METRIC_KEY(DEVICE_ARCHITECTURE),
METRIC_KEY(IMPORT_EXPORT_SUPPORT),
};

IE_SUPPRESS_DEPRECATED_START
Expand Down
2 changes: 2 additions & 0 deletions inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ InferenceEngine::Parameter Engine::GetMetric(const std::string& name,
IE_SET_METRIC_RETURN(RANGE_FOR_ASYNC_INFER_REQUESTS, _metrics->RangeForAsyncInferRequests(_config));
} else if (name == METRIC_KEY(DEVICE_ARCHITECTURE)) {
IE_SET_METRIC_RETURN(DEVICE_ARCHITECTURE, _metrics->DeviceArchitecture());
} else if (name == METRIC_KEY(IMPORT_EXPORT_SUPPORT)) {
IE_SET_METRIC_RETURN(IMPORT_EXPORT_SUPPORT, true);
} else if (name == METRIC_KEY(DEVICE_THERMAL)) {
const auto& device = getDeviceByName(getSpecifiedDeviceName());
if (device != nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ class CachingInferencePlugin : public InferenceEngine::InferencePluginInternal {
public:
int m_loadNetworkCalled = 0;
int m_importNetworkCalled = 0;
mutable int m_getMetricCalled = 0;
int m_exportCalled = 0;
bool m_supportImportExport = true;

void resetCounters() {
m_loadNetworkCalled = 0;
m_importNetworkCalled = 0;
m_getMetricCalled = 0;
m_exportCalled = 0;
}

~CachingInferencePlugin() override = default;

ExecutableNetworkInternal::Ptr LoadExeNetworkImpl(const CNNNetwork& network,
Expand Down Expand Up @@ -79,7 +89,13 @@ class CachingInferencePlugin : public InferenceEngine::InferencePluginInternal {

Parameter GetMetric(const std::string& name, const std::map<std::string, InferenceEngine::Parameter>& options) const override {
if (METRIC_KEY(SUPPORTED_METRICS) == name) {
return std::vector<std::string> {};
std::vector<std::string> supportedMetrics = {
METRIC_KEY(IMPORT_EXPORT_SUPPORT)
};
return supportedMetrics;
} else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) {
m_getMetricCalled++;
return m_supportImportExport;
} else {
THROW_IE_EXCEPTION << "Unsupported device metric: " << name;
}
Expand Down Expand Up @@ -119,7 +135,6 @@ class CachingTest : public ::testing::Test {
FuncTestUtils::TestModel::generateTestModel(modelName, weightsName);

ie.RegisterPlugin(std::string("mock_engine") + IE_BUILD_POSTFIX, deviceName);
ie.SetConfig({ {CONFIG_KEY(CACHE_DIR), "testCache"} });
}

void TearDown() override {
Expand All @@ -132,6 +147,10 @@ class CachingTest : public ::testing::Test {
ie.UnregisterPlugin(deviceName);
}

void enableCacheConfig() {
ie.SetConfig({ {CONFIG_KEY(CACHE_DIR), "testCache"} });
}

private:
template <class T>
std::function<T> make_std_function(const std::string& functionName) {
Expand All @@ -141,6 +160,7 @@ class CachingTest : public ::testing::Test {
};

TEST_F(CachingTest, Test1) {
enableCacheConfig();
auto performReadAndLoad = [&] {
auto cnnNetwork = ie.ReadNetwork(modelName);
auto exeNet = ie.LoadNetwork(cnnNetwork, deviceName);
Expand All @@ -150,20 +170,83 @@ TEST_F(CachingTest, Test1) {
{ // Step 1: read and load network without cache
performReadAndLoad();

EXPECT_GT(m_plugin->m_loadNetworkCalled, 0); // verify: 'load was called'
EXPECT_GT(m_plugin->m_exportCalled, 0); // verify: 'export was called'
EXPECT_GT(m_plugin->m_getMetricCalled, 0); // verify: 'getMetric was called'
EXPECT_EQ(m_plugin->m_loadNetworkCalled, 1); // verify: 'load was called'
EXPECT_EQ(m_plugin->m_exportCalled, 1); // verify: 'export was called'
EXPECT_EQ(m_plugin->m_importNetworkCalled, 0); // verify: 'import was not called'
}

m_plugin->m_loadNetworkCalled = 0;
m_plugin->m_exportCalled = 0;
m_plugin->m_importNetworkCalled = 0;
m_plugin->resetCounters();

{ // Step 2: same load, but now cache must be available from Step 1
performReadAndLoad();

EXPECT_GT(m_plugin->m_getMetricCalled, 0); // verify: 'getMetric was called'
EXPECT_EQ(m_plugin->m_loadNetworkCalled, 0); // verify: 'load was not called' (optimization works)
EXPECT_EQ(m_plugin->m_exportCalled, 0); // verify: 'export was not called' (optimization works)
EXPECT_EQ(m_plugin->m_importNetworkCalled, 1); // verify: 'import was called instead of load + export'
}
}

TEST_F(CachingTest, TestLoadByName) {
enableCacheConfig();
auto performLoadByName = [&] {
auto exeNet = ie.LoadNetwork(modelName, deviceName);
(void)exeNet;
};

{ // Step 1: read and load network without cache
performLoadByName();

EXPECT_GT(m_plugin->m_getMetricCalled, 0); // verify: 'getMetric was called'
EXPECT_EQ(m_plugin->m_loadNetworkCalled, 1); // verify: 'load was called'
EXPECT_EQ(m_plugin->m_exportCalled, 1); // verify: 'export was called'
EXPECT_EQ(m_plugin->m_importNetworkCalled, 0); // verify: 'import was not called'
}

m_plugin->resetCounters();

{ // Step 2: same load, but now cache must be available from Step 1
performLoadByName();

EXPECT_GT(m_plugin->m_getMetricCalled, 0); // verify: 'getMetric was called'
EXPECT_EQ(m_plugin->m_loadNetworkCalled, 0); // verify: 'load was not called' (optimization works)
EXPECT_EQ(m_plugin->m_exportCalled, 0); // verify: 'export was not called' (optimization works)
EXPECT_GT(m_plugin->m_importNetworkCalled, 0); // verify: 'import was called instead of load + export'
EXPECT_EQ(m_plugin->m_importNetworkCalled, 1); // verify: 'import was called instead of load + export'
}
}

TEST_F(CachingTest, TestLoadByName_NoCacheSupported1) {
enableCacheConfig(); // Enable caching in global settings
m_plugin->m_supportImportExport = false; // but it is not supported by plugin

auto performLoadByName = [&] {
auto exeNet = ie.LoadNetwork(modelName, deviceName);
(void)exeNet;
};

{ // read and load network without cache
performLoadByName();

EXPECT_GT(m_plugin->m_getMetricCalled, 0); // verify: 'getMetric was called'
EXPECT_EQ(m_plugin->m_loadNetworkCalled, 1); // verify: 'load was called'
EXPECT_EQ(m_plugin->m_exportCalled, 0); // verify: 'export was not called'
EXPECT_EQ(m_plugin->m_importNetworkCalled, 0); // verify: 'import was not called'
}
}

TEST_F(CachingTest, TestLoadByName_NoCacheEnabled) {
auto performLoadByName = [&] {
auto exeNet = ie.LoadNetwork(modelName, deviceName);
(void)exeNet;
};

{ // read and load network without cache
performLoadByName();

EXPECT_EQ(m_plugin->m_getMetricCalled, 0); // verify: 'getMetric was not called when global cache is disabled'
EXPECT_EQ(m_plugin->m_loadNetworkCalled, 1); // verify: 'load was called'
EXPECT_EQ(m_plugin->m_exportCalled, 0); // verify: 'export was not called'
EXPECT_EQ(m_plugin->m_importNetworkCalled, 0); // verify: 'import was not called'
}
}