From f5e2a463b53f70840c3f5ebc122983583ec0f0ba Mon Sep 17 00:00:00 2001 From: guozhong wang Date: Mon, 30 May 2022 10:04:13 +0800 Subject: [PATCH] remove CPU from default candidate list while GPUs more than 2 (#11753) --- src/plugins/auto/auto_schedule.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/plugins/auto/auto_schedule.cpp b/src/plugins/auto/auto_schedule.cpp index def13add5fd64f..e042e6fe652690 100644 --- a/src/plugins/auto/auto_schedule.cpp +++ b/src/plugins/auto/auto_schedule.cpp @@ -123,6 +123,36 @@ void AutoSchedule::init(const ScheduleContext::Ptr& sContext) { std::list validDevices = _autoSContext->_plugin->GetValidDevice(_autoSContext->_devicePriorities, _loadContext[ACTUALDEVICE].networkPrecision); + // check if device priority is enabled + bool enableDevicePriority = + std::find_if(std::begin(validDevices), std::end(validDevices), [](DeviceInformation& di) { + return di.devicePriority > 0; + }) != std::end(validDevices); + + // for the case of -d "AUTO" or "AUTO: -xxx" + if (!enableDevicePriority) { + std::list::iterator itCPUDevice; + int GPUNums = 0, CPUNums = 0; + for (auto it = validDevices.begin(); it != validDevices.end(); it++) { + if (it->deviceName.find("GPU") != std::string::npos) { + GPUNums++; + } + + if (it->deviceName.find("CPU") == 0) { + CPUNums++; + itCPUDevice = it; + } + } + + // remove CPU from default candidate list for Cumulative Throughput mode + if (GPUNums >= 2 && CPUNums > 0) { + validDevices.erase(itCPUDevice); + LOG_INFO("[AUTOPLUGIN]:GPUNums:%d, remove CPU from default candidate list for " + "CUMULATIVE_THROUGHPUT", + GPUNums); + } + } + std::string deviceName = "MULTI:"; for (auto& device : validDevices) { deviceName += device.deviceName;