From 0337b055dbb1f045437d3cef08b482942cdd2a88 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 27 Apr 2021 09:12:55 +0300 Subject: [PATCH] Added GetAvailableDevices for AUTO device (#5377) * Added GetAvailableDevices for AUTO device * Fixed tests compilation --- inference-engine/include/ie_core.hpp | 2 +- .../src/inference_engine/ie_core.cpp | 67 +++++++++++-------- inference-engine/src/plugin_api/ie_icore.hpp | 8 +++ .../cpp_interfaces/interface/mock_icore.hpp | 1 + 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/inference-engine/include/ie_core.hpp b/inference-engine/include/ie_core.hpp index fddf2b29069..2829d3234f2 100644 --- a/inference-engine/include/ie_core.hpp +++ b/inference-engine/include/ie_core.hpp @@ -238,7 +238,7 @@ public: * @brief Returns devices available for neural networks inference * * @return A vector of devices. The devices are returned as { CPU, FPGA.0, FPGA.1, MYRIAD } - If there more than one device of specific type, they are enumerated with .# suffix. + * If there more than one device of specific type, they are enumerated with .# suffix. */ std::vector GetAvailableDevices() const; diff --git a/inference-engine/src/inference_engine/ie_core.cpp b/inference-engine/src/inference_engine/ie_core.cpp index 2143bafbccd..94165f0887b 100644 --- a/inference-engine/src/inference_engine/ie_core.cpp +++ b/inference-engine/src/inference_engine/ie_core.cpp @@ -591,6 +591,43 @@ public: return copyParameterValue(GetCPPPluginByName(parsed._deviceName).GetMetric(name, parsed._config)); } + /** + * @brief Returns devices available for neural networks inference + * + * @return A vector of devices. The devices are returned as { CPU, FPGA.0, FPGA.1, MYRIAD } + * If there more than one device of specific type, they are enumerated with .# suffix. + */ + std::vector GetAvailableDevices() const override { + std::vector devices; + const std::string propertyName = METRIC_KEY(AVAILABLE_DEVICES); + + for (auto&& deviceName : GetListOfDevicesInRegistry()) { + std::vector devicesIDs; + try { + const Parameter p = GetMetric(deviceName, propertyName); + devicesIDs = p.as>(); + } catch (Exception&) { + // plugin is not created by e.g. invalid env + } catch (const std::exception& ex) { + IE_THROW() << "An exception is thrown while trying to create the " << deviceName + << " device and call GetMetric: " << ex.what(); + } catch (...) { + IE_THROW() << "Unknown exception is thrown while trying to create the " << deviceName + << " device and call GetMetric"; + } + + if (devicesIDs.size() > 1) { + for (auto&& deviceID : devicesIDs) { + devices.push_back(deviceName + '.' + deviceID); + } + } else if (!devicesIDs.empty()) { + devices.push_back(deviceName); + } + } + + return devices; + } + /** * @brief Returns reference to CPP plugin wrapper by a device name * @param deviceName A name of device @@ -1007,35 +1044,7 @@ Parameter Core::GetMetric(const std::string& deviceName, const std::string& name } std::vector Core::GetAvailableDevices() const { - std::vector devices; - - std::string propertyName = METRIC_KEY(AVAILABLE_DEVICES); - - for (auto&& deviceName : _impl->GetListOfDevicesInRegistry()) { - std::vector devicesIDs; - try { - Parameter p = GetMetric(deviceName, propertyName); - devicesIDs = p.as>(); - } catch (Exception&) { - // plugin is not created by e.g. invalid env - } catch (const std::exception& ex) { - IE_THROW() << "An exception is thrown while trying to create the " << deviceName - << " device and call GetMetric: " << ex.what(); - } catch (...) { - IE_THROW() << "Unknown exception is thrown while trying to create the " << deviceName - << " device and call GetMetric"; - } - - if (devicesIDs.size() > 1) { - for (auto&& deviceID : devicesIDs) { - devices.push_back(deviceName + '.' + deviceID); - } - } else if (!devicesIDs.empty()) { - devices.push_back(deviceName); - } - } - - return devices; + return _impl->GetAvailableDevices(); } void Core::RegisterPlugin(const std::string& pluginName, const std::string& deviceName) { diff --git a/inference-engine/src/plugin_api/ie_icore.hpp b/inference-engine/src/plugin_api/ie_icore.hpp index 7534c8c765e..d8acf837640 100644 --- a/inference-engine/src/plugin_api/ie_icore.hpp +++ b/inference-engine/src/plugin_api/ie_icore.hpp @@ -100,6 +100,14 @@ public: */ virtual Parameter GetMetric(const std::string& deviceName, const std::string& name) const = 0; + /** + * @brief Returns devices available for neural networks inference + * + * @return A vector of devices. The devices are returned as { CPU, FPGA.0, FPGA.1, MYRIAD } + * If there more than one device of specific type, they are enumerated with .# suffix. + */ + virtual std::vector GetAvailableDevices() const = 0; + /** * @brief Default virtual destructor */ diff --git a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp index e52f79bb156..c1adf355f16 100644 --- a/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp +++ b/inference-engine/tests/ie_test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp @@ -28,6 +28,7 @@ public: const InferenceEngine::CNNNetwork&, const std::string&, const std::map&)); MOCK_QUALIFIED_METHOD2(GetMetric, const, InferenceEngine::Parameter(const std::string&, const std::string&)); + MOCK_QUALIFIED_METHOD0(GetAvailableDevices, const, std::vector()); ~MockICore() = default; };