[AUTOPLUGIN] add device priority if set ov::device::priorities (#10296)
* support config key device priority for example: if AUTO:CPU,GPU the priority of CPU will be higher than GPU Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * add test and fix compile and test error Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * add an info for device priority and add lost [AUTOPLUGIN] on log Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * parseMetaDevice return all DEVICE of GPU, when use AUTO:GPU Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * fix compile issue Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * modify test and add test case, fix code issue Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * fix a bug and mutli with HETERO test failed Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * fix mock test faild issue Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * fix misprint Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * Disable AUTO:MYRIAD case MYRIAD/CoreThreadingTests.smoke_QueryNetwork/targetDevice=MULTI_config=MULTI_DEVICE_PRIORITIES:MYRIAD_ faild on windows the error is myriadFuncTests-0 INFO: [E:] [BSL] found 0 ioexpander device Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * use ov::device::priorities key in this PR Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com> * fix a logic bug in key_network_priority after enable device priority add test case cover it Signed-off-by: Hu, Yuan2 <yuan2.hu@intel.com>
This commit is contained in:
parent
ae42bf1e86
commit
09379dca86
@ -41,6 +41,7 @@ struct DeviceInformation {
|
||||
int numRequestsPerDevices;
|
||||
std::string defaultDeviceID;
|
||||
DeviceName uniqueName;
|
||||
unsigned int devicePriority;
|
||||
};
|
||||
|
||||
struct AutoContext {
|
||||
|
@ -115,6 +115,10 @@ std::vector<DeviceInformation> MultiDeviceInferencePlugin::ParseMetaDevices(cons
|
||||
return "";
|
||||
};
|
||||
|
||||
unsigned int devicePriority = 0;
|
||||
auto prioritiesIter = config.find(ov::device::priorities.name());
|
||||
bool enableDevicePriority = (prioritiesIter != config.end());
|
||||
auto deviceList = GetCore()->GetAvailableDevices();
|
||||
for (auto && d : devicesWithRequests) {
|
||||
auto openingBracket = d.find_first_of('(');
|
||||
auto closingBracket = d.find_first_of(')', openingBracket);
|
||||
@ -130,33 +134,60 @@ std::vector<DeviceInformation> MultiDeviceInferencePlugin::ParseMetaDevices(cons
|
||||
}
|
||||
}
|
||||
|
||||
std::string defaultDeviceID = "";
|
||||
DeviceIDParser parsed{deviceName};
|
||||
std::string deviceid = parsed.getDeviceID();
|
||||
if (deviceid.empty()) {
|
||||
defaultDeviceID = getDefaultDeviceID(deviceName);
|
||||
deviceid = defaultDeviceID;
|
||||
}
|
||||
|
||||
std::string fullDeviceName = "";
|
||||
std::string uniqueName = "";
|
||||
if (parsed.getDeviceName() == "GPU") {
|
||||
auto supportedMetrics = GetCore()->GetMetric(deviceName, METRIC_KEY(SUPPORTED_METRICS)).as<std::vector<std::string>>();
|
||||
if (std::find(supportedMetrics.begin(), supportedMetrics.end(), METRIC_KEY(FULL_DEVICE_NAME)) != supportedMetrics.end()) {
|
||||
fullDeviceName = GetCore()->GetMetric(deviceName, METRIC_KEY(FULL_DEVICE_NAME)).as<std::string>();
|
||||
std::vector<std::string> sameTypeDevices;
|
||||
// if AUTO:GPU case, replace GPU with GPU.0 and GPU.1
|
||||
// Disable AUTO:MYRIAD here because of below test case
|
||||
// MYRIAD/CoreThreadingTests.smoke_QueryNetwork/targetDevice=MULTI_config=MULTI_DEVICE_PRIORITIES:MYRIAD_
|
||||
// faild on windows
|
||||
// the error is
|
||||
// myriadFuncTests-0 INFO: [E:] [BSL] found 0 ioexpander device
|
||||
if (deviceid.empty() && deviceName.find("MYRIAD") == std::string::npos) {
|
||||
for (auto&& device : deviceList) {
|
||||
if (device.find(deviceName) != std::string::npos) {
|
||||
sameTypeDevices.push_back(std::move(device));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fullDeviceName.empty()) {
|
||||
uniqueName = parsed.getDeviceName() + "_" + deviceid;
|
||||
} else {
|
||||
uniqueName = fullDeviceName + "_" + deviceid;
|
||||
// it's a virtual device like HETERO, TEMPLATE
|
||||
// or real device with ID like GPU.1
|
||||
if (sameTypeDevices.size() == 0) {
|
||||
sameTypeDevices.push_back(std::move(deviceName));
|
||||
}
|
||||
|
||||
LOG_DEBUG("deviceName:%s, defaultDeviceID:%s, uniqueName:%s",
|
||||
deviceName.c_str(), defaultDeviceID.c_str(), uniqueName.c_str());
|
||||
// create meta device
|
||||
metaDevices.push_back({ deviceName, getDeviceConfig(deviceName), numRequests, defaultDeviceID, uniqueName});
|
||||
for (auto&& deviceNameWithID : sameTypeDevices) {
|
||||
DeviceIDParser newParsed{deviceNameWithID};
|
||||
std::string defaultDeviceID = "";
|
||||
if (newParsed.getDeviceID().empty()) {
|
||||
defaultDeviceID = getDefaultDeviceID(deviceNameWithID);
|
||||
} else {
|
||||
defaultDeviceID = newParsed.getDeviceID();
|
||||
}
|
||||
|
||||
std::string fullDeviceName = "";
|
||||
std::string uniqueName = "";
|
||||
if (newParsed.getDeviceName() == "GPU") {
|
||||
auto supportedMetrics = GetCore()->GetMetric(deviceNameWithID, METRIC_KEY(SUPPORTED_METRICS)).as<std::vector<std::string>>();
|
||||
if (std::find(supportedMetrics.begin(), supportedMetrics.end(), METRIC_KEY(FULL_DEVICE_NAME)) != supportedMetrics.end()) {
|
||||
fullDeviceName = GetCore()->GetMetric(deviceNameWithID, METRIC_KEY(FULL_DEVICE_NAME)).as<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
if (fullDeviceName.empty()) {
|
||||
uniqueName = newParsed.getDeviceName() + "_" + defaultDeviceID;
|
||||
} else {
|
||||
uniqueName = fullDeviceName + "_" + defaultDeviceID;
|
||||
}
|
||||
|
||||
LOG_DEBUG("[AUTOPLUGIN]:deviceNameWithID:%s, defaultDeviceID:%s, uniqueName:%s",
|
||||
deviceNameWithID.c_str(), defaultDeviceID.c_str(), uniqueName.c_str());
|
||||
// create meta device
|
||||
metaDevices.push_back({deviceNameWithID, getDeviceConfig(deviceNameWithID), numRequests, defaultDeviceID, uniqueName, devicePriority});
|
||||
}
|
||||
if (enableDevicePriority) {
|
||||
devicePriority++;
|
||||
}
|
||||
}
|
||||
|
||||
return metaDevices;
|
||||
@ -312,6 +343,7 @@ IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetworkImpl(cons
|
||||
iter->config = deviceConfig;
|
||||
strDevices += iter->deviceName;
|
||||
strDevices += ((iter + 1) == supportDevices.end()) ? "" : ",";
|
||||
LOG_INFO("[AUTOPLUGIN]:device:%s, priority:%ld", iter->deviceName.c_str(), iter->devicePriority);
|
||||
}
|
||||
return std::make_shared<MultiDeviceExecutableNetwork>(modelPath, network, supportDevices, strDevices, this, context, context.needPerfCounters);
|
||||
}
|
||||
@ -499,6 +531,10 @@ DeviceInformation MultiDeviceInferencePlugin::SelectDevice(const std::vector<Dev
|
||||
if (validDevices.empty()) {
|
||||
IE_THROW() << "Cannot select any device";
|
||||
}
|
||||
// sort validDevices
|
||||
validDevices.sort([](const DeviceInformation& a, const DeviceInformation& b) {
|
||||
return a.devicePriority < b.devicePriority;
|
||||
});
|
||||
// all available Devices are in validDevices now
|
||||
// need to remove higher priority devices
|
||||
// save the last device first
|
||||
|
@ -34,11 +34,12 @@ using ::testing::InvokeWithoutArgs;
|
||||
using Config = std::map<std::string, std::string>;
|
||||
using namespace MockMultiDevice;
|
||||
|
||||
using PriorityParams = std::tuple<unsigned int, std::string>; //{priority, deviceUniquName}
|
||||
using PriorityParams = std::tuple<unsigned int, std::string>; //{modelpriority, deviceUniquName}
|
||||
|
||||
using ConfigParams = std::tuple<
|
||||
std::string, // netPrecision
|
||||
std::vector<PriorityParams> // {{priority, expect device uniqueName}}
|
||||
std::string, // netPrecision
|
||||
bool, // enable device priority
|
||||
std::vector<PriorityParams> // {{modelpriority, expect device uniqueName}}
|
||||
>;
|
||||
class KeyNetworkPriorityTest : public ::testing::TestWithParam<ConfigParams> {
|
||||
public:
|
||||
@ -49,9 +50,15 @@ public:
|
||||
public:
|
||||
static std::string getTestCaseName(testing::TestParamInfo<ConfigParams> obj) {
|
||||
std::string netPrecision;
|
||||
bool enableDevicePriority;
|
||||
std::vector<PriorityParams> PriorityConfigs;
|
||||
std::tie(netPrecision, PriorityConfigs) = obj.param;
|
||||
std::tie(netPrecision, enableDevicePriority, PriorityConfigs) = obj.param;
|
||||
std::ostringstream result;
|
||||
if (enableDevicePriority) {
|
||||
result << "_enableDevicePriority_true";
|
||||
} else {
|
||||
result << "_enableDevicePriority_false";
|
||||
}
|
||||
for (auto& item : PriorityConfigs) {
|
||||
result << "_priority_" << std::get<0>(item);
|
||||
result << "_return_" << std::get<1>(item);
|
||||
@ -73,11 +80,7 @@ public:
|
||||
plugin = std::shared_ptr<MockMultiDeviceInferencePlugin>(origin_plugin);
|
||||
// replace core with mock Icore
|
||||
plugin->SetCore(core);
|
||||
metaDevices = {{CommonTestUtils::DEVICE_CPU, {}, 2, "", "CPU_01"},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "iGPU_01"},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "dGPU_01"},
|
||||
{CommonTestUtils::DEVICE_MYRIAD, {}, 2, "01", "MYRIAD_01" },
|
||||
{CommonTestUtils::DEVICE_KEEMBAY, {}, 2, "01", "VPUX_01"}};
|
||||
|
||||
IE_SET_METRIC(OPTIMIZATION_CAPABILITIES, cpuCability, {"FP32", "FP16", "INT8", "BIN"});
|
||||
IE_SET_METRIC(OPTIMIZATION_CAPABILITIES, gpuCability, {"FP32", "FP16", "BATCHED_BLOB", "BIN"});
|
||||
IE_SET_METRIC(OPTIMIZATION_CAPABILITIES, myriadCability, {"FP16"});
|
||||
@ -99,11 +102,27 @@ public:
|
||||
|
||||
TEST_P(KeyNetworkPriorityTest, SelectDevice) {
|
||||
// get Parameter
|
||||
|
||||
std::string netPrecision;
|
||||
bool enableDevicePriority;
|
||||
std::vector<PriorityParams> PriorityConfigs;
|
||||
std::tie(netPrecision, PriorityConfigs) = this->GetParam();
|
||||
std::tie(netPrecision, enableDevicePriority, PriorityConfigs) = this->GetParam();
|
||||
std::vector<DeviceInformation> resDevInfo;
|
||||
|
||||
if (enableDevicePriority) {
|
||||
metaDevices = {{CommonTestUtils::DEVICE_CPU, {}, 2, "", "CPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "iGPU_01", 1},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "dGPU_01", 2},
|
||||
{CommonTestUtils::DEVICE_MYRIAD, {}, 2, "01", "MYRIAD_01", 3},
|
||||
{CommonTestUtils::DEVICE_KEEMBAY, {}, 2, "01", "VPUX_01", 4}};
|
||||
} else {
|
||||
metaDevices = {{CommonTestUtils::DEVICE_CPU, {}, 2, "", "CPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "iGPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "dGPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_MYRIAD, {}, 2, "01", "MYRIAD_01", 0},
|
||||
{CommonTestUtils::DEVICE_KEEMBAY, {}, 2, "01", "VPUX_01", 0}};
|
||||
}
|
||||
|
||||
EXPECT_CALL(*plugin, SelectDevice(_, _, _)).Times(PriorityConfigs.size());
|
||||
EXPECT_CALL(*core, GetMetric(_, _, _)).Times(AtLeast(PriorityConfigs.size() * 4));
|
||||
|
||||
@ -119,11 +138,26 @@ TEST_P(KeyNetworkPriorityTest, SelectDevice) {
|
||||
TEST_P(KeyNetworkPriorityTest, MultiThreadsSelectDevice) {
|
||||
// get Parameter
|
||||
std::string netPrecision;
|
||||
bool enableDevicePriority;
|
||||
std::vector<PriorityParams> PriorityConfigs;
|
||||
std::tie(netPrecision, PriorityConfigs) = this->GetParam();
|
||||
std::tie(netPrecision, enableDevicePriority, PriorityConfigs) = this->GetParam();
|
||||
std::vector<DeviceInformation> resDevInfo;
|
||||
std::vector<std::future<void>> futureVect;
|
||||
|
||||
if (enableDevicePriority) {
|
||||
metaDevices = {{CommonTestUtils::DEVICE_CPU, {}, 2, "", "CPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "iGPU_01", 1},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "dGPU_01", 2},
|
||||
{CommonTestUtils::DEVICE_MYRIAD, {}, 2, "01", "MYRIAD_01", 3},
|
||||
{CommonTestUtils::DEVICE_KEEMBAY, {}, 2, "01", "VPUX_01", 4}};
|
||||
} else {
|
||||
metaDevices = {{CommonTestUtils::DEVICE_CPU, {}, 2, "", "CPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "iGPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_GPU, {}, 2, "01", "dGPU_01", 0},
|
||||
{CommonTestUtils::DEVICE_MYRIAD, {}, 2, "01", "MYRIAD_01", 0},
|
||||
{CommonTestUtils::DEVICE_KEEMBAY, {}, 2, "01", "VPUX_01", 0}};
|
||||
}
|
||||
|
||||
EXPECT_CALL(*plugin, SelectDevice(_, _, _)).Times(PriorityConfigs.size() * 2);
|
||||
EXPECT_CALL(*core, GetMetric(_, _, _)).Times(AtLeast(PriorityConfigs.size() * 4 * 2));
|
||||
// selectdevice in multi threads, and UnregisterPriority them all, should not affect the
|
||||
@ -153,86 +187,164 @@ TEST_P(KeyNetworkPriorityTest, MultiThreadsSelectDevice) {
|
||||
|
||||
// ConfigParams details
|
||||
// example
|
||||
// ConfigParams {"FP32", {PriorityParams {0, "dGPU_01"},
|
||||
// ConfigParams {"FP32", false, {PriorityParams {0, "dGPU_01"},
|
||||
// PriorityParams {1, "iGPU_01"},
|
||||
// PriorityParams {2, "MYRIAD_01"},
|
||||
// PriorityParams {2, "MYRIAD_01"}}},
|
||||
// {netPrecision, PriorityParamsVector{{priority, expect device uniqueName}}}
|
||||
// {netPrecision, enableDevicePriority, PriorityParamsVector{{modelpriority, expect device uniqueName}}}
|
||||
|
||||
const std::vector<ConfigParams> testConfigs = {
|
||||
ConfigParams {"FP32", {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"FP32", {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "iGPU_01"},
|
||||
PriorityParams {4, "CPU_01"},
|
||||
PriorityParams {5, "MYRIAD_01"}}},
|
||||
ConfigParams {"FP32", {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"}}},
|
||||
ConfigParams {"FP32", {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"FP32", {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "MYRIAD_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "MYRIAD_01"}}},
|
||||
ConfigParams {"INT8", {PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {1, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"INT8", {PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {3, "CPU_01"},
|
||||
PriorityParams {4, "CPU_01"},
|
||||
PriorityParams {5, "CPU_01"}}},
|
||||
ConfigParams {"INT8", {PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"INT8", {PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"INT8", {PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {1, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"},
|
||||
PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {1, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"BIN", {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"BIN", {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "iGPU_01"},
|
||||
PriorityParams {4, "CPU_01"},
|
||||
PriorityParams {5, "CPU_01"}}},
|
||||
ConfigParams {"BIN", {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"}}},
|
||||
ConfigParams {"BIN", {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"BIN", {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}}
|
||||
};
|
||||
ConfigParams {"FP32", false, {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"FP32", false, {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "iGPU_01"},
|
||||
PriorityParams {4, "CPU_01"},
|
||||
PriorityParams {5, "MYRIAD_01"}}},
|
||||
ConfigParams {"FP32", false, {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"}}},
|
||||
ConfigParams {"FP32", false, {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"FP32", false, {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "MYRIAD_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "MYRIAD_01"}}},
|
||||
ConfigParams {"INT8", false, {PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {1, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"INT8", false, {PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {3, "CPU_01"},
|
||||
PriorityParams {4, "CPU_01"},
|
||||
PriorityParams {5, "CPU_01"}}},
|
||||
ConfigParams {"INT8", false, {PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"INT8", false, {PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"INT8", false, {PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {1, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"},
|
||||
PriorityParams {0, "VPUX_01"},
|
||||
PriorityParams {1, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"BIN", false, {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {2, "CPU_01"}}},
|
||||
ConfigParams {"BIN", false, {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "iGPU_01"},
|
||||
PriorityParams {4, "CPU_01"},
|
||||
PriorityParams {5, "CPU_01"}}},
|
||||
ConfigParams {"BIN", false, {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"}}},
|
||||
ConfigParams {"BIN", false, {PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
ConfigParams {"BIN", false, {PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"},
|
||||
PriorityParams {0, "dGPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "CPU_01"}}},
|
||||
// metaDevices = {{CommonTestUtils::DEVICE_CPU, {}, 2, "", "CPU_01", 0},
|
||||
// {CommonTestUtils::DEVICE_GPU, {}, 2, "01", "iGPU_01", 1},
|
||||
// {CommonTestUtils::DEVICE_GPU, {}, 2, "01", "dGPU_01", 2},
|
||||
// {CommonTestUtils::DEVICE_MYRIAD, {}, 2, "01", "MYRIAD_01", 3},
|
||||
// {CommonTestUtils::DEVICE_KEEMBAY, {}, 2, "01", "VPUX_01", 4}};
|
||||
// cpu > igpu > dgpu > MYRIAD > VPUX
|
||||
ConfigParams {"FP32", true, {PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"}}},
|
||||
ConfigParams {"FP32", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "iGPU_01"},
|
||||
PriorityParams {4, "dGPU_01"},
|
||||
PriorityParams {5, "MYRIAD_01"}}},
|
||||
ConfigParams {"FP32", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"}}},
|
||||
ConfigParams {"FP32", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {3, "dGPU_01"}}},
|
||||
ConfigParams {"FP32", true, {PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "MYRIAD_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "MYRIAD_01"}}},
|
||||
ConfigParams {"INT8", true, {PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "VPUX_01"},
|
||||
PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {2, "VPUX_01"}}},
|
||||
ConfigParams {"INT8", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "VPUX_01"},
|
||||
PriorityParams {4, "VPUX_01"},
|
||||
PriorityParams {5, "VPUX_01"}}},
|
||||
ConfigParams {"INT8", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {2, "VPUX_01"}}},
|
||||
ConfigParams {"INT8", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {3, "VPUX_01"}}},
|
||||
ConfigParams {"INT8", true, {PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "VPUX_01"},
|
||||
PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {3, "VPUX_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "VPUX_01"},
|
||||
PriorityParams {2, "VPUX_01"},
|
||||
PriorityParams {3, "VPUX_01"}}},
|
||||
ConfigParams {"BIN", true, {PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"}}},
|
||||
ConfigParams {"BIN", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {3, "iGPU_01"},
|
||||
PriorityParams {4, "dGPU_01"},
|
||||
PriorityParams {5, "dGPU_01"}}},
|
||||
ConfigParams {"BIN", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {2, "iGPU_01"}}},
|
||||
ConfigParams {"BIN", true, {PriorityParams {2, "CPU_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {2, "iGPU_01"},
|
||||
PriorityParams {3, "dGPU_01"}}},
|
||||
ConfigParams {"BIN", true, {PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "dGPU_01"},
|
||||
PriorityParams {0, "CPU_01"},
|
||||
PriorityParams {1, "iGPU_01"},
|
||||
PriorityParams {2, "dGPU_01"},
|
||||
PriorityParams {3, "dGPU_01"}}}
|
||||
};
|
||||
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, KeyNetworkPriorityTest,
|
||||
|
@ -37,11 +37,13 @@ using ::testing::InvokeWithoutArgs;
|
||||
using Config = std::map<std::string, std::string>;
|
||||
using namespace MockMultiDevice;
|
||||
|
||||
const char cpuFullDeviceName[] = "Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz";
|
||||
// const char cpuFullDeviceName[] = "Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz";
|
||||
const char igpuFullDeviceName[] = "Intel(R) Gen9 HD Graphics (iGPU)";
|
||||
// const char dgpuFullDeviceName[] = "Intel(R) Iris(R) Xe MAX Graphics (dGPU)";
|
||||
const char myriadFullDeviceName[] = "Intel Movidius Myriad X VPU";
|
||||
const char vpuxFullDeviceName[] = "";
|
||||
const char dgpuFullDeviceName[] = "Intel(R) Iris(R) Xe MAX Graphics (dGPU)";
|
||||
// const char myriadFullDeviceName[] = "Intel Movidius Myriad X VPU";
|
||||
// const char vpuxFullDeviceName[] = "";
|
||||
const std::vector<std::string> availableDevs = {"CPU", "GPU.0", "GPU.1",
|
||||
"MYRIAD.9.2-ma2480", "MYRIAD.9.1-ma2480", "VPUX"};
|
||||
using ConfigParams = std::tuple<
|
||||
std::string, // Priority devices
|
||||
std::vector<DeviceInformation>, // expect metaDevices
|
||||
@ -85,22 +87,15 @@ public:
|
||||
ON_CALL(*core, GetMetric(_, StrEq(METRIC_KEY(SUPPORTED_METRICS)), _))
|
||||
.WillByDefault(RETURN_MOCK_VALUE(metrics));
|
||||
|
||||
ON_CALL(*core, GetMetric(HasSubstr(CommonTestUtils::DEVICE_CPU),
|
||||
StrEq(METRIC_KEY(FULL_DEVICE_NAME)), _)).WillByDefault(Return(cpuFullDeviceName));
|
||||
ON_CALL(*core, GetMetric(HasSubstr(CommonTestUtils::DEVICE_GPU),
|
||||
ON_CALL(*core, GetMetric(StrEq("GPU.0"),
|
||||
StrEq(METRIC_KEY(FULL_DEVICE_NAME)), _)).WillByDefault(Return(igpuFullDeviceName));
|
||||
ON_CALL(*core, GetMetric(HasSubstr(CommonTestUtils::DEVICE_MYRIAD),
|
||||
StrEq(METRIC_KEY(FULL_DEVICE_NAME)), _)).WillByDefault(Return(myriadFullDeviceName));
|
||||
ON_CALL(*core, GetMetric(HasSubstr(CommonTestUtils::DEVICE_KEEMBAY),
|
||||
StrEq(METRIC_KEY(FULL_DEVICE_NAME)), _)).WillByDefault(Return(vpuxFullDeviceName));
|
||||
IE_SET_METRIC(SUPPORTED_CONFIG_KEYS, otherConfigKeys, {CONFIG_KEY(DEVICE_ID)});
|
||||
IE_SET_METRIC(SUPPORTED_CONFIG_KEYS, cpuConfigKeys, {});
|
||||
ON_CALL(*core, GetMetric(HasSubstr(CommonTestUtils::DEVICE_CPU),
|
||||
StrEq(METRIC_KEY(SUPPORTED_CONFIG_KEYS)), _)).WillByDefault(RETURN_MOCK_VALUE(cpuConfigKeys));
|
||||
ON_CALL(*core, GetMetric(Not(HasSubstr(CommonTestUtils::DEVICE_CPU)),
|
||||
StrEq(METRIC_KEY(SUPPORTED_CONFIG_KEYS)), _)).WillByDefault(RETURN_MOCK_VALUE(otherConfigKeys));
|
||||
ON_CALL(*core, GetConfig(_, StrEq(CONFIG_KEY(DEVICE_ID))))
|
||||
.WillByDefault(InvokeWithoutArgs([](){return "01";}));
|
||||
ON_CALL(*core, GetMetric(StrEq("GPU.1"),
|
||||
StrEq(METRIC_KEY(FULL_DEVICE_NAME)), _)).WillByDefault(Return(dgpuFullDeviceName));
|
||||
IE_SET_METRIC(SUPPORTED_CONFIG_KEYS, configKeys, {});
|
||||
ON_CALL(*core, GetMetric(_, StrEq(METRIC_KEY(SUPPORTED_CONFIG_KEYS)), _))
|
||||
.WillByDefault(RETURN_MOCK_VALUE(configKeys));
|
||||
|
||||
ON_CALL(*core, GetAvailableDevices()).WillByDefault(Return(availableDevs));
|
||||
|
||||
ON_CALL(*plugin, ParseMetaDevices).WillByDefault([this](const std::string& priorityDevices,
|
||||
const std::map<std::string, std::string>& config) {
|
||||
@ -119,9 +114,18 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void compareDevicePriority(std::vector<DeviceInformation>& result, std::vector<DeviceInformation>& expect) {
|
||||
EXPECT_EQ(result.size(), expect.size());
|
||||
if (result.size() == expect.size()) {
|
||||
for (unsigned int i = 0 ; i < result.size(); i++) {
|
||||
EXPECT_EQ(result[i].devicePriority, expect[i].devicePriority);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ParseMetaDeviceTest, ParseMetaDevices) {
|
||||
TEST_P(ParseMetaDeviceTest, ParseMetaDevicesWithPriority) {
|
||||
// get Parameter
|
||||
std::string priorityDevices;
|
||||
std::vector<DeviceInformation> metaDevices;
|
||||
@ -131,11 +135,37 @@ TEST_P(ParseMetaDeviceTest, ParseMetaDevices) {
|
||||
EXPECT_CALL(*plugin, ParseMetaDevices(_, _)).Times(1);
|
||||
EXPECT_CALL(*core, GetMetric(_, _, _)).Times(AnyNumber());
|
||||
EXPECT_CALL(*core, GetConfig(_, _)).Times(AnyNumber());
|
||||
EXPECT_CALL(*core, GetAvailableDevices()).Times(1);
|
||||
EXPECT_CALL(*core, GetSupportedConfig(_, _)).Times(metaDevices.size());
|
||||
if (throwException) {
|
||||
ASSERT_ANY_THROW(plugin->ParseMetaDevices(priorityDevices, {}));
|
||||
} else {
|
||||
auto result = plugin->ParseMetaDevices(priorityDevices, {});
|
||||
auto result = plugin->ParseMetaDevices(priorityDevices, {{ov::device::priorities.name(), priorityDevices}});
|
||||
compare(result, metaDevices);
|
||||
compareDevicePriority(result, metaDevices);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ParseMetaDeviceTest, ParseMetaDevicesNotWithPriority) {
|
||||
// get Parameter
|
||||
std::string priorityDevices;
|
||||
std::vector<DeviceInformation> metaDevices;
|
||||
bool throwException;
|
||||
std::tie(priorityDevices, metaDevices, throwException) = this->GetParam();
|
||||
|
||||
EXPECT_CALL(*plugin, ParseMetaDevices(_, _)).Times(1);
|
||||
EXPECT_CALL(*core, GetMetric(_, _, _)).Times(AnyNumber());
|
||||
EXPECT_CALL(*core, GetConfig(_, _)).Times(AnyNumber());
|
||||
EXPECT_CALL(*core, GetAvailableDevices()).Times(1);
|
||||
EXPECT_CALL(*core, GetSupportedConfig(_, _)).Times(metaDevices.size());
|
||||
if (throwException) {
|
||||
ASSERT_ANY_THROW(plugin->ParseMetaDevices(priorityDevices, {}));
|
||||
} else {
|
||||
auto result = plugin->ParseMetaDevices(priorityDevices, {{}});
|
||||
compare(result, metaDevices);
|
||||
for (unsigned int i = 0 ; i < result.size(); i++) {
|
||||
EXPECT_EQ(result[i].devicePriority, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,24 +174,59 @@ TEST_P(ParseMetaDeviceTest, ParseMetaDevices) {
|
||||
// ConfigParams {devicePriority, expect metaDevices, ifThrowException}
|
||||
|
||||
const std::vector<ConfigParams> testConfigs = {
|
||||
// ConfigParams {"CPU,GPU,MYRIAD,VPUX",
|
||||
// {{"CPU", {}, -1, "", "CPU_", 0},
|
||||
// {"GPU.0", {}, -1, "0", std::string(igpuFullDeviceName) + "_0", 1},
|
||||
// {"GPU.1", {}, -1, "1", std::string(dgpuFullDeviceName) + "_1", 1},
|
||||
// {"MYRIAD.9.2-ma2480", {}, -1, "9.2-ma2480", "MYRIAD_9.2-ma2480", 2},
|
||||
// {"MYRIAD.9.1-ma2480", {}, -1, "9.1-ma2480", "MYRIAD_9.1-ma2480", 2},
|
||||
// {"VPUX", {}, -1, "", "VPUX_", 3}}, false},
|
||||
// ConfigParams {"VPUX,MYRIAD,GPU,CPU",
|
||||
// {{"VPUX", {}, -1, "", "VPUX_", 0},
|
||||
// {"MYRIAD.9.2-ma2480", {}, -1, "9.2-ma2480", "MYRIAD_9.2-ma2480", 1},
|
||||
// {"MYRIAD.9.1-ma2480", {}, -1, "9.1-ma2480", "MYRIAD_9.1-ma2480", 1},
|
||||
// {"GPU.0", {}, -1, "0", std::string(igpuFullDeviceName) + "_0", 2},
|
||||
// {"GPU.1", {}, -1, "1", std::string(dgpuFullDeviceName) + "_1", 2},
|
||||
// {"CPU", {}, -1, "", "CPU_", 3}}, false},
|
||||
// ConfigParams {"CPU(1),GPU(2),MYRIAD(3),VPUX(4)",
|
||||
// {{"CPU", {}, 1, "", "CPU_", 0},
|
||||
// {"GPU.0", {}, 2, "0", std::string(igpuFullDeviceName) + "_0", 1},
|
||||
// {"GPU.1", {}, 2, "1", std::string(dgpuFullDeviceName) + "_1", 1},
|
||||
// {"MYRIAD.9.2-ma2480", {}, 3, "9.2-ma2480", "MYRIAD_9.2-ma2480", 2},
|
||||
// {"MYRIAD.9.1-ma2480", {}, 3, "9.1-ma2480", "MYRIAD_9.1-ma2480", 2},
|
||||
// {"VPUX", {}, 4, "", "VPUX_", 3}}, false},
|
||||
//
|
||||
ConfigParams {"CPU,GPU,MYRIAD,VPUX",
|
||||
{{"CPU", {}, -1, "", "CPU_"},
|
||||
{"GPU", {}, -1, "01", std::string(igpuFullDeviceName) + "_01"},
|
||||
{"MYRIAD", {}, -1, "01", "MYRIAD_01"},
|
||||
{"VPUX", {}, -1, "01", "VPUX_01"}}, false},
|
||||
ConfigParams {"CPU(1),GPU(2),MYRIAD(3),VPUX(4)",
|
||||
{{"CPU", {}, 1, "", "CPU_"},
|
||||
{"GPU", {}, 2, "01", std::string(igpuFullDeviceName) + "_01"},
|
||||
{"MYRIAD", {}, 3, "01", "MYRIAD_01"},
|
||||
{"VPUX", {}, 4, "01", "VPUX_01"}}, false},
|
||||
{{"CPU", {}, -1, "", "CPU_", 0},
|
||||
{"GPU.0", {}, -1, "0", std::string(igpuFullDeviceName) + "_0", 1},
|
||||
{"GPU.1", {}, -1, "1", std::string(dgpuFullDeviceName) + "_1", 1},
|
||||
{"MYRIAD", {}, -1, "", "MYRIAD_", 2},
|
||||
{"VPUX", {}, -1, "", "VPUX_", 3}}, false},
|
||||
ConfigParams {"VPUX,GPU,CPU",
|
||||
{{"VPUX", {}, -1, "", "VPUX_", 0},
|
||||
{"GPU.0", {}, -1, "0", std::string(igpuFullDeviceName) + "_0", 1},
|
||||
{"GPU.1", {}, -1, "1", std::string(dgpuFullDeviceName) + "_1", 1},
|
||||
{"CPU", {}, -1, "", "CPU_", 2}}, false},
|
||||
ConfigParams {"CPU(1),GPU(2),VPUX(4)",
|
||||
{{"CPU", {}, 1, "", "CPU_", 0},
|
||||
{"GPU.0", {}, 2, "0", std::string(igpuFullDeviceName) + "_0", 1},
|
||||
{"GPU.1", {}, 2, "1", std::string(dgpuFullDeviceName) + "_1", 1},
|
||||
{"VPUX", {}, 4, "", "VPUX_", 2}}, false},
|
||||
|
||||
ConfigParams {"CPU(-1),GPU,MYRIAD,VPUX", {}, true},
|
||||
ConfigParams {"CPU(NA),GPU,MYRIAD,VPUX", {}, true},
|
||||
ConfigParams {"CPU.02(3),GPU.03,MYRIAD.04,VPUX.05",
|
||||
{{"CPU.02", {}, 3, "", "CPU_02"},
|
||||
{"GPU.03", {}, -1, "", std::string(igpuFullDeviceName) + "_03"},
|
||||
{"MYRIAD.04", {}, -1, "", "MYRIAD_04"},
|
||||
{"VPUX.05", {}, -1, "", "VPUX_05"}}, false}
|
||||
};
|
||||
|
||||
ConfigParams {"CPU(3),GPU.1,MYRIAD.9.2-ma2480,VPUX",
|
||||
{{"CPU", {}, 3, "", "CPU_", 0},
|
||||
{"GPU.1", {}, -1, "1", std::string(dgpuFullDeviceName) + "_1", 1},
|
||||
{"MYRIAD.9.2-ma2480", {}, -1, "9.2-ma2480", "MYRIAD_9.2-ma2480", 2},
|
||||
{"VPUX", {}, -1, "", "VPUX_", 3}}, false},
|
||||
ConfigParams {"VPUX,MYRIAD.9.2-ma2480,GPU.1,CPU(3)",
|
||||
{{"VPUX", {}, -1, "", "VPUX_", 0},
|
||||
{"MYRIAD.9.2-ma2480", {}, -1, "9.2-ma2480", "MYRIAD_9.2-ma2480", 1},
|
||||
{"GPU.1", {}, -1, "1", std::string(dgpuFullDeviceName) + "_1", 2},
|
||||
{"CPU", {}, 3, "", "CPU_", 3}}, false}
|
||||
};
|
||||
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, ParseMetaDeviceTest,
|
||||
|
@ -38,7 +38,9 @@ using ConfigParams = std::tuple<
|
||||
std::string, // netPrecision
|
||||
std::vector<DeviceInformation>, // metaDevices for select
|
||||
DeviceInformation, // expect DeviceInformation
|
||||
bool // throw exception
|
||||
bool, // throw exception
|
||||
bool, // enableDevicePriority
|
||||
bool // reverse total device
|
||||
>;
|
||||
|
||||
const DeviceInformation CPU_INFO = {CommonTestUtils::DEVICE_CPU, {}, 2, "01", "CPU_01"};
|
||||
@ -58,6 +60,7 @@ std::map<std::string, const std::vector<DeviceInformation>> devicesMap = {{"FP32
|
||||
{"BATCHED_BLOB", batchedblobDeviceVector}
|
||||
};
|
||||
const std::vector<DeviceInformation> totalDevices = {DGPU_INFO, IGPU_INFO, MYRIAD_INFO, CPU_INFO, KEEMBAY_INFO};
|
||||
const std::vector<DeviceInformation> reverseTotalDevices = {KEEMBAY_INFO, CPU_INFO, MYRIAD_INFO, IGPU_INFO, DGPU_INFO};
|
||||
const std::vector<std::string> netPrecisions = {"FP32", "FP16", "INT8", "BIN", "BATCHED_BLOB"};
|
||||
std::vector<ConfigParams> testConfigs;
|
||||
|
||||
@ -72,7 +75,9 @@ public:
|
||||
std::vector<DeviceInformation> devices;
|
||||
DeviceInformation expect;
|
||||
bool throwExcept;
|
||||
std::tie(netPrecision, devices, expect, throwExcept) = obj.param;
|
||||
bool enableDevicePriority;
|
||||
bool reverse;
|
||||
std::tie(netPrecision, devices, expect, throwExcept, enableDevicePriority, reverse) = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "_netPrecision_" << netPrecision;
|
||||
for (auto& item : devices) {
|
||||
@ -84,19 +89,39 @@ public:
|
||||
} else {
|
||||
result << "_throwExcept_false";
|
||||
}
|
||||
|
||||
if (enableDevicePriority) {
|
||||
result << "_enableDevicePriority_true";
|
||||
} else {
|
||||
result << "_enableDevicePriority_false";
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
result << "_reverseTotalDevice_true";
|
||||
} else {
|
||||
result << "_reverseTotalDevice_false";
|
||||
}
|
||||
|
||||
return result.str();
|
||||
}
|
||||
// combine select_num devices from devices and make them to ConfigParams
|
||||
// insert the ConfigParams into testConfigs
|
||||
static void combine_device(const std::vector<DeviceInformation>& devices, int start,
|
||||
int* result, int result_index, const int select_num, std::string& netPrecision) {
|
||||
int* result, int result_index, const int select_num, std::string& netPrecision,
|
||||
bool enableDevicePriority, bool reverse) {
|
||||
int i = 0;
|
||||
for (i = start; i < devices.size() + 1 - result_index; i++) {
|
||||
result[result_index - 1] = i;
|
||||
if (result_index - 1 == 0) {
|
||||
std::vector<DeviceInformation> metaDevices = {};
|
||||
int devicePriority = 0;
|
||||
for (int j = select_num - 1; j >= 0; j--) {
|
||||
metaDevices.push_back(devices[result[j]]);
|
||||
auto tmpDevInfo = devices[result[j]];
|
||||
if (enableDevicePriority) {
|
||||
tmpDevInfo.devicePriority = devicePriority;
|
||||
devicePriority++;
|
||||
}
|
||||
metaDevices.push_back(tmpDevInfo);
|
||||
}
|
||||
// Debug the combine_device
|
||||
// for (auto& item : metaDevices) {
|
||||
@ -107,24 +132,47 @@ public:
|
||||
bool find = false;
|
||||
DeviceInformation expect;
|
||||
if (metaDevices.size() > 1) {
|
||||
for (auto& item : devicesInfo) {
|
||||
auto device = std::find_if(metaDevices.begin(), metaDevices.end(),
|
||||
[&item](const DeviceInformation& d)->bool{return d.uniqueName == item.uniqueName;});
|
||||
if (device != metaDevices.end()) {
|
||||
if (enableDevicePriority) {
|
||||
std::vector<DeviceInformation> validDevices;
|
||||
for (auto& item : devicesInfo) {
|
||||
auto device = std::find_if(metaDevices.begin(), metaDevices.end(),
|
||||
[&item](const DeviceInformation& d)->bool{return d.uniqueName == item.uniqueName;});
|
||||
if (device != metaDevices.end()) {
|
||||
validDevices.push_back(*device);
|
||||
}
|
||||
}
|
||||
int currentDevicePriority = 100;
|
||||
for (auto iter = validDevices.begin(); iter != validDevices.end(); iter++) {
|
||||
if (iter->devicePriority < currentDevicePriority) {
|
||||
expect = *iter;
|
||||
currentDevicePriority = iter->devicePriority;
|
||||
}
|
||||
}
|
||||
if (currentDevicePriority != 100) {
|
||||
find = true;
|
||||
expect = item;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
for (auto& item : devicesInfo) {
|
||||
auto device = std::find_if(metaDevices.begin(), metaDevices.end(),
|
||||
[&item](const DeviceInformation& d)->bool{return d.uniqueName == item.uniqueName;});
|
||||
if (device != metaDevices.end()) {
|
||||
find = true;
|
||||
expect = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (metaDevices.size() == 1) {
|
||||
expect = metaDevices[0];
|
||||
find = true;
|
||||
expect = metaDevices[0];
|
||||
} else {
|
||||
find = false;
|
||||
}
|
||||
testConfigs.push_back(std::make_tuple(netPrecision, metaDevices, expect, !find));
|
||||
testConfigs.push_back(std::make_tuple(netPrecision, metaDevices,
|
||||
expect, !find, enableDevicePriority, reverse));
|
||||
} else {
|
||||
combine_device(devices, i + 1, result, result_index - 1, select_num, netPrecision);
|
||||
combine_device(devices, i + 1, result, result_index - 1,
|
||||
select_num, netPrecision, enableDevicePriority, reverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -139,10 +187,31 @@ public:
|
||||
// total test config num is 32*5 = 160
|
||||
for (auto netPrecision : netPrecisions) {
|
||||
for (int i = 1; i <= totalDevices.size(); i++) {
|
||||
combine_device(totalDevices, 0, result, i, i, netPrecision);
|
||||
combine_device(totalDevices, 0, result, i, i, netPrecision, false, false);
|
||||
}
|
||||
// test null device
|
||||
testConfigs.push_back(ConfigParams{netPrecision, {}, {}, true});
|
||||
testConfigs.push_back(ConfigParams{netPrecision, {}, {}, true, false, false});
|
||||
}
|
||||
// reverse totalDevices for test
|
||||
for (auto netPrecision : netPrecisions) {
|
||||
for (int i = 1; i <= reverseTotalDevices.size(); i++) {
|
||||
combine_device(reverseTotalDevices, 0, result, i, i, netPrecision, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
// add test for enableDevicePriority
|
||||
// test case num is 31*5 = 155
|
||||
for (auto netPrecision : netPrecisions) {
|
||||
for (int i = 1; i <= totalDevices.size(); i++) {
|
||||
combine_device(totalDevices, 0, result, i, i, netPrecision, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
// reverse totalDevices for test
|
||||
for (auto netPrecision : netPrecisions) {
|
||||
for (int i = 1; i <= reverseTotalDevices.size(); i++) {
|
||||
combine_device(reverseTotalDevices, 0, result, i, i, netPrecision, true, true);
|
||||
}
|
||||
}
|
||||
delete []result;
|
||||
return testConfigs;
|
||||
@ -193,7 +262,9 @@ TEST_P(SelectDeviceTest, SelectDevice) {
|
||||
std::vector<DeviceInformation> devices;
|
||||
DeviceInformation expect;
|
||||
bool throwExcept;
|
||||
std::tie(netPrecision, devices, expect, throwExcept) = this->GetParam();
|
||||
bool enableDevicePriority;
|
||||
bool reverse;
|
||||
std::tie(netPrecision, devices, expect, throwExcept, enableDevicePriority, reverse) = this->GetParam();
|
||||
|
||||
EXPECT_CALL(*plugin, SelectDevice(_, _, _)).Times(1);
|
||||
if (devices.size() >= 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user