From 44d7926c724c64c074bba55e50529a1cc25743fd Mon Sep 17 00:00:00 2001 From: lbushi25 <113361374+lbushi25@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:41:51 -0400 Subject: [PATCH] [SYCL] Fix ESIMD_EMULATOR being picked as default device (#6870) This commit attempts to fix the problem that occurs when the default device selector picks the ESIMD_EMULATOR when other devices are available. --- sycl/source/detail/filter_selector_impl.cpp | 2 ++ sycl/source/detail/pi.cpp | 5 +---- sycl/source/device_selector.cpp | 14 +++++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sycl/source/detail/filter_selector_impl.cpp b/sycl/source/detail/filter_selector_impl.cpp index 09046c0f6b8b5..5ed55aff47db2 100644 --- a/sycl/source/detail/filter_selector_impl.cpp +++ b/sycl/source/detail/filter_selector_impl.cpp @@ -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); diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index 7bf4ab0422a19..07dbdbf5502db 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -283,8 +283,6 @@ std::vector> 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 Filters = FilterList->get(); bool OpenCLFound = false; @@ -311,8 +309,7 @@ std::vector> 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; diff --git a/sycl/source/device_selector.cpp b/sycl/source/device_selector.cpp index 5f985716cc8b1..414c0ecb732af 100644 --- a/sycl/source/device_selector.cpp +++ b/sycl/source/device_selector.cpp @@ -164,7 +164,8 @@ 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; } } @@ -172,6 +173,13 @@ __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() == detail::get_forced_type()) Score += 2000; @@ -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;