-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: model caching page update according to OpenVINO API 2.0 (#10981)
- Loading branch information
Showing
9 changed files
with
172 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <openvino/runtime/core.hpp> | ||
|
||
void part0() { | ||
std::string modelPath = "/tmp/myModel.xml"; | ||
std::string device = "GNA"; | ||
ov::AnyMap config; | ||
//! [ov:caching:part0] | ||
ov::Core core; // Step 1: create ov::Core object | ||
core.set_property(ov::cache_dir("/path/to/cache/dir")); // Step 1b: Enable caching | ||
auto model = core.read_model(modelPath); // Step 2: Read Model | ||
//... // Step 3: Prepare inputs/outputs | ||
//... // Step 4: Set device configuration | ||
auto compiled = core.compile_model(model, device, config); // Step 5: LoadNetwork | ||
//! [ov:caching:part0] | ||
if (!compiled) { | ||
throw std::runtime_error("error"); | ||
} | ||
} | ||
|
||
void part1() { | ||
std::string modelPath = "/tmp/myModel.xml"; | ||
std::string device = "GNA"; | ||
ov::AnyMap config; | ||
//! [ov:caching:part1] | ||
ov::Core core; // Step 1: create ov::Core object | ||
auto compiled = core.compile_model(modelPath, device, config); // Step 2: Compile model by file path | ||
//! [ov:caching:part1] | ||
if (!compiled) { | ||
throw std::runtime_error("error"); | ||
} | ||
} | ||
|
||
void part2() { | ||
std::string modelPath = "/tmp/myModel.xml"; | ||
std::string device = "GNA"; | ||
ov::AnyMap config; | ||
//! [ov:caching:part2] | ||
ov::Core core; // Step 1: create ov::Core object | ||
core.set_property(ov::cache_dir("/path/to/cache/dir")); // Step 1b: Enable caching | ||
auto compiled = core.compile_model(modelPath, device, config); // Step 2: Compile model by file path | ||
//! [ov:caching:part2] | ||
if (!compiled) { | ||
throw std::runtime_error("error"); | ||
} | ||
} | ||
|
||
void part3() { | ||
std::string deviceName = "GNA"; | ||
ov::AnyMap config; | ||
ov::Core core; | ||
//! [ov:caching:part3] | ||
// Get list of supported device capabilities | ||
std::vector<std::string> caps = core.get_property(deviceName, ov::device::capabilities); | ||
|
||
// Find 'EXPORT_IMPORT' capability in supported capabilities | ||
bool cachingSupported = std::find(caps.begin(), caps.end(), ov::device::capability::EXPORT_IMPORT) != caps.end(); | ||
//! [ov:caching:part3] | ||
if (!cachingSupported) { | ||
throw std::runtime_error("GNA should support model caching"); | ||
} | ||
} | ||
|
||
int main() { | ||
part0(); | ||
part1(); | ||
part2(); | ||
part3(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (C) 2018-2022 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
from openvino.runtime import Core | ||
|
||
device_name = 'GNA' | ||
xml_path = '/tmp/myModel.xml' | ||
# ! [ov:caching:part0] | ||
core = Core() | ||
core.set_property({'CACHE_DIR': '/path/to/cache/dir'}) | ||
model = core.read_model(model=xml_path) | ||
compiled_model = core.compile_model(model=model, device_name=device_name) | ||
# ! [ov:caching:part0] | ||
|
||
assert compiled_model | ||
|
||
# ! [ov:caching:part1] | ||
core = Core() | ||
compiled_model = core.compile_model(model_path=xml_path, device_name=device_name) | ||
# ! [ov:caching:part1] | ||
|
||
assert compiled_model | ||
|
||
# ! [ov:caching:part2] | ||
core = Core() | ||
core.set_property({'CACHE_DIR': '/path/to/cache/dir'}) | ||
compiled_model = core.compile_model(model_path=xml_path, device_name=device_name) | ||
# ! [ov:caching:part2] | ||
|
||
assert compiled_model | ||
|
||
# ! [ov:caching:part3] | ||
# Find 'EXPORT_IMPORT' capability in supported capabilities | ||
caching_supported = 'EXPORT_IMPORT' in core.get_property(device_name, 'OPTIMIZATION_CAPABILITIES') | ||
# ! [ov:caching:part3] |