Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Change device preference to acknowledge ESIMD_EMULATOR #1290

Closed
wants to merge 11 commits into from
19 changes: 9 additions & 10 deletions SYCL/ESIMD/esimd_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down
12 changes: 12 additions & 0 deletions SYCL/Regression/device_num.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,33 @@ int GetPreferredDeviceIndex(const std::vector<device> &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;
auto deviceType = devices[i].get_info<info::device::device_type>();
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;
}

Expand Down