Skip to content

Commit

Permalink
[SYCL] Fix ESIMD_EMULATOR being picked as default device (#6870)
Browse files Browse the repository at this point in the history
This commit attempts to fix the problem that occurs when the default
device selector picks the ESIMD_EMULATOR when other devices are
available.
  • Loading branch information
lbushi25 committed Oct 14, 2022
1 parent 429c09e commit 44d7926
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sycl/source/detail/filter_selector_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ filter create_filter(const std::string &Input) {
Result.Backend = backend::ext_oneapi_cuda;
} else if (Token == "hip" && !Result.Backend) {
Result.Backend = backend::ext_oneapi_hip;
} else if (Token == "esimd_emulator" && !Result.Backend) {
Result.Backend = backend::ext_intel_esimd_emulator;
} else if (std::regex_match(Token, IntegerExpr) && !Result.DeviceNum) {
try {
Result.DeviceNum = std::stoi(Token);
Expand Down
5 changes: 1 addition & 4 deletions sycl/source/detail/pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ std::vector<std::pair<std::string, backend>> findPlugins() {
backend::ext_oneapi_level_zero);
PluginNames.emplace_back(__SYCL_CUDA_PLUGIN_NAME, backend::ext_oneapi_cuda);
PluginNames.emplace_back(__SYCL_HIP_PLUGIN_NAME, backend::ext_oneapi_hip);
PluginNames.emplace_back(__SYCL_ESIMD_EMULATOR_PLUGIN_NAME,
backend::ext_intel_esimd_emulator);
} else {
std::vector<device_filter> Filters = FilterList->get();
bool OpenCLFound = false;
Expand All @@ -311,8 +309,7 @@ std::vector<std::pair<std::string, backend>> findPlugins() {
backend::ext_oneapi_cuda);
CudaFound = true;
}
if (!EsimdCpuFound && (Backend == backend::ext_intel_esimd_emulator ||
Backend == backend::all)) {
if (!EsimdCpuFound && Backend == backend::ext_intel_esimd_emulator) {
PluginNames.emplace_back(__SYCL_ESIMD_EMULATOR_PLUGIN_NAME,
backend::ext_intel_esimd_emulator);
EsimdCpuFound = true;
Expand Down
14 changes: 13 additions & 1 deletion sycl/source/device_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,22 @@ static void traceDeviceSelector(const std::string &DeviceType) {
bool ShouldTrace = false;
ShouldTrace = detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_BASIC);
if (ShouldTrace) {
std::cout << "SYCL_PI_TRACE[all]: Requested device_type: " << DeviceType << std::endl;
std::cout << "SYCL_PI_TRACE[all]: Requested device_type: " << DeviceType
<< std::endl;
}
}

__SYCL_EXPORT int default_selector_v(const device &dev) {
// The default selector doesn't reject any devices.
int Score = 0;

// we give the esimd_emulator device a score of zero to prevent it from being
// chosen among other devices. The same thing is done for gpu_selector_v
// below.
if (dev.get_backend() == backend::ext_intel_esimd_emulator) {
return 0;
}

traceDeviceSelector("info::device_type::automatic");
if (dev.get_info<info::device::device_type>() == detail::get_forced_type())
Score += 2000;
Expand All @@ -197,6 +205,10 @@ __SYCL_EXPORT int default_selector_v(const device &dev) {
__SYCL_EXPORT int gpu_selector_v(const device &dev) {
int Score = detail::REJECT_DEVICE_SCORE;

if (dev.get_backend() == backend::ext_intel_esimd_emulator) {
return 0;
}

traceDeviceSelector("info::device_type::gpu");
if (dev.is_gpu()) {
Score = 1000;
Expand Down

0 comments on commit 44d7926

Please sign in to comment.