diff --git a/SYCL/ESIMD/esimd_test_utils.hpp b/SYCL/ESIMD/esimd_test_utils.hpp index b72f2d8a9b..76c7984a4f 100644 --- a/SYCL/ESIMD/esimd_test_utils.hpp +++ b/SYCL/ESIMD/esimd_test_utils.hpp @@ -37,17 +37,16 @@ namespace esimd_test { class ESIMDSelector : public device_selector { // Require GPU device virtual int operator()(const device &device) const { - if (const char *dev_filter = getenv("SYCL_DEVICE_FILTER")) { - std::string filter_string(dev_filter); - if (filter_string.find("gpu") != std::string::npos) - return device.is_gpu() ? 1000 : -1; - std::cerr - << "Supported 'SYCL_DEVICE_FILTER' env var values is 'gpu' and '" - << filter_string << "' does not contain such substrings.\n"; - return -1; + if (device.get_backend() == backend::ext_intel_esimd_emulator) { + return 1000; + } else if (device.is_gpu()) { + // pick gpu device if esimd not available but give it a lower score in + // order not to compete with the esimd in environments where both are + // present + return 900; + } else { + return 0; } - // If "SYCL_DEVICE_FILTER" not defined, only allow gpu device - return device.is_gpu() ? 1000 : -1; } }; diff --git a/SYCL/Regression/device_num.cpp b/SYCL/Regression/device_num.cpp index 844cfa5382..6654d7797d 100644 --- a/SYCL/Regression/device_num.cpp +++ b/SYCL/Regression/device_num.cpp @@ -115,6 +115,8 @@ int GetPreferredDeviceIndex(const std::vector &devices, {info::device_type::host, 100}}; int score = -1; int index = -1; + int runnerup_index = -1; + int eligible_devices = 0; int devCount = devices.size(); for (int i = 0; i < devCount; i++) { int dev_score = 0; @@ -122,14 +124,24 @@ int GetPreferredDeviceIndex(const std::vector &devices, auto backend = devices[i].get_backend(); if ((type != info::device_type::all) && (deviceType != type)) continue; + ++eligible_devices; dev_score = scoreByType.at(deviceType); if (backend == backend::ext_oneapi_level_zero) dev_score += 100; if (dev_score > score) { score = dev_score; + runnerup_index = index; index = i; } } + if (index >= 0 && + devices[index].get_backend() == backend::ext_intel_esimd_emulator && + eligible_devices > 1) { + // if we chose ESIMD_EMULATOR, then must only return it if there are no + // other suitable devices in the system. Otherwise, we return the runner up + // device. + return runnerup_index; + } return index; }