-
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.
Added openvino executable network API
- Loading branch information
1 parent
07f7061
commit 4082246
Showing
5 changed files
with
272 additions
and
6 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
155 changes: 155 additions & 0 deletions
155
inference-engine/src/inference_engine/include/openvino/runtime/executable_network.hpp
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,155 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
/** | ||
* @brief A header file that provides ExecutableNetwork class | ||
* | ||
* @file ie_executable_network.hpp | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <ostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "ie_parameter.hpp" | ||
#include "infer_request.hpp" | ||
#include "remote_context.hpp" | ||
|
||
namespace InferenceEngine { | ||
class IExecutableNetworkInternal; | ||
class RemoteContext; | ||
} // namespace InferenceEngine | ||
namespace ngraph { | ||
namespace op { | ||
namespace v0 { | ||
class Parameter; | ||
class Result; | ||
} // namespace v0 | ||
} // namespace op | ||
} // namespace ngraph | ||
namespace ov { | ||
class Function; | ||
namespace runtime { | ||
|
||
class Core; | ||
|
||
/** | ||
* @brief This is an interface of an executable network | ||
*/ | ||
class INFERENCE_ENGINE_API_CLASS(ExecutableNetwork) { | ||
std::shared_ptr<SharedObject> _so; | ||
std::shared_ptr<InferenceEngine::IExecutableNetworkInternal> _impl; | ||
|
||
/** | ||
* @brief Constructs ExecutableNetwork from the initialized std::shared_ptr | ||
* @param so Plugin to use. This is required to ensure that ExecutableNetwork can work properly even if plugin | ||
* object is destroyed. | ||
* @param impl Initialized shared pointer | ||
*/ | ||
ExecutableNetwork(const std::shared_ptr<SharedObject>& so, | ||
const std::shared_ptr<ie::IExecutableNetworkInternal>& impl); | ||
friend class ov::runtime::Core; | ||
|
||
public: | ||
/** | ||
* @brief A default constructor. | ||
*/ | ||
ExecutableNetwork() = default; | ||
|
||
/** | ||
* @brief Get executable graph information from a device | ||
* | ||
* @return Function containing Executable Graph Info | ||
*/ | ||
std::shared_ptr<const Function> get_function() const; | ||
|
||
/** | ||
* @brief Get parameters of executeble graph function | ||
* | ||
* @return vector of paramter nodes | ||
*/ | ||
std::vector<std::shared_ptr<ngraph::op::v0::Parameter>> get_parameters() const; | ||
|
||
/** | ||
* @brief Get results of executeble graph function | ||
* | ||
* @return vector of result nodes | ||
*/ | ||
std::vector<std::shared_ptr<ngraph::op::v0::Result>> get_results() const; | ||
|
||
/** | ||
* @brief Creates an inference request object used to infer the network. | ||
* | ||
* The created request has allocated input and output blobs (that can be changed later). | ||
* | ||
* @return InferRequest object | ||
*/ | ||
InferRequest create_infer_request(); | ||
|
||
/** | ||
* @brief Exports the current executable network. | ||
* | ||
* @see Core::ImportNetwork | ||
* | ||
* @param networkModel Network model output stream | ||
*/ | ||
void export_model(std::ostream& networkModel); | ||
|
||
/** | ||
* @brief Sets configuration for current executable network | ||
* | ||
* @param config Map of pairs: (config parameter name, config parameter value) | ||
*/ | ||
void set_config(const ie::ParamMap& config); | ||
|
||
/** @brief Gets configuration for current executable network. | ||
* | ||
* The method is responsible to extract information | ||
* which affects executable network execution. The list of supported configuration values can be extracted via | ||
* ExecutableNetwork::get_metric with the SUPPORTED_CONFIG_KEYS key, but some of these keys cannot be changed | ||
* dynamically, e.g. DEVICE_ID cannot changed if an executable network has already been compiled for particular | ||
* device. | ||
* | ||
* @param name config key, can be found in ie_plugin_config.hpp | ||
* @return Configuration parameter value | ||
*/ | ||
ie::Parameter get_config(const std::string& name) const; | ||
|
||
/** | ||
* @brief Gets general runtime metric for an executable network. | ||
* | ||
* It can be network name, actual device ID on | ||
* which executable network is running or all other properties which cannot be changed dynamically. | ||
* | ||
* @param name metric name to request | ||
* @return Metric parameter value | ||
*/ | ||
ie::Parameter get_metric(const std::string& name) const; | ||
|
||
/** | ||
* @brief Returns pointer to plugin-specific shared context | ||
* on remote accelerator device that was used to create this ExecutableNetwork | ||
* @return A context | ||
*/ | ||
std::shared_ptr<ie::RemoteContext> get_context() const; | ||
|
||
/** | ||
* @brief Checks if current ExecutableNetwork object is not initialized | ||
* @return true if current ExecutableNetwork object is not initialized, false - otherwise | ||
*/ | ||
bool operator!() const noexcept; | ||
|
||
/** | ||
* @brief Checks if current ExecutableNetwork object is initialized | ||
* @return true if current ExecutableNetwork object is initialized, false - otherwise | ||
*/ | ||
explicit operator bool() const noexcept; | ||
}; | ||
|
||
} // namespace runtime | ||
} // namespace ov |
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
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
49 changes: 49 additions & 0 deletions
49
inference-engine/tests/functional/inference_engine/ov_executable_network_test.cpp
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,49 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <gtest/gtest.h> | ||
#include <openvino/runtime/executable_network.hpp> | ||
|
||
using namespace ::testing; | ||
using namespace std; | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedExportStream) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.export_model(std::cout), InferenceEngine::NotAllocated); | ||
} | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedGetFunction) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.get_function(), InferenceEngine::NotAllocated); | ||
} | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedGetParameters) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.get_parameters(), InferenceEngine::NotAllocated); | ||
} | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedGetResults) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.get_results(), InferenceEngine::NotAllocated); | ||
} | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedSetConfig) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.set_config({{}}), InferenceEngine::NotAllocated); | ||
} | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedGetConfig) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.get_config({}), InferenceEngine::NotAllocated); | ||
} | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedGetMetric) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.get_metric({}), InferenceEngine::NotAllocated); | ||
} | ||
|
||
TEST(ExecutableNetworkOVTests, throwsOnUninitializedGetContext) { | ||
ov::runtime::ExecutableNetwork exec; | ||
ASSERT_THROW(exec.get_context(), InferenceEngine::NotAllocated); | ||
} |