diff --git a/sycl/doc/extensions/supported/sycl_ext_intel_fpga_device_selector.asciidoc b/sycl/doc/extensions/supported/sycl_ext_intel_fpga_device_selector.asciidoc index a0abf36104cc7..dd6d98577f469 100644 --- a/sycl/doc/extensions/supported/sycl_ext_intel_fpga_device_selector.asciidoc +++ b/sycl/doc/extensions/supported/sycl_ext_intel_fpga_device_selector.asciidoc @@ -90,18 +90,25 @@ supports. |2 |fpga_simulator_selector added. + +|3 +|SYCL 2020 selector variants `fpga_selector_v`, `fpga_simulator_selector_v`, and +`fpga_emulator_selector_v` added. Old selectors `fpga_selector`, +`fpga_simulator_selector`, and `fpga_emulator_selector` deprecated. |=== === Select FPGA hardware device .... // select FPGA hardware device -sycl::queue deviceQueue{sycl::ext::intel::fpga_selector{}}; +sycl::queue deviceQueue1{sycl::ext::intel::fpga_selector{}}; // Deprecated +sycl::queue deviceQueue2{sycl::ext::intel::fpga_selector_v}; .... === Select FPGA simulator device .... // select FPGA simulator device -sycl::queue deviceQueue{sycl::ext::intel::fpga_simulator_selector{}}; +sycl::queue deviceQueue1{sycl::ext::intel::fpga_simulator_selector{}}; // Deprecated +sycl::queue deviceQueue2{sycl::ext::intel::fpga_simulator_selector_v}; .... [NOTE] @@ -112,14 +119,16 @@ Added in version 2 of this extension. === Select FPGA emulator device .... // select FPGA emulator device -sycl::queue deviceQueue{sycl::ext::intel::fpga_emulator_selector{}}; +sycl::queue deviceQueue1{sycl::ext::intel::fpga_emulator_selector{}}; // Deprecated +sycl::queue deviceQueue2{sycl::ext::intel::fpga_emulator_selector_v}; .... == Implementation notes The current implementation has a restriction on the use of -`fpga_simulator_selector`. If an object of `fpga_simulator_selector` is -defined in the application, FPGA hardware devices selected using -`fpga_selector` will select a simulator device. This behaviour is expected to +`fpga_simulator_selector` and `fpga_simulator_selector_v`. If an object of +`fpga_simulator_selector` is defined or `fpga_simulator_selector_v` is used in +the application, FPGA hardware devices selected using fpga_selector` and +`fpga_selector_v` will select a simulator device. This behaviour is expected to be eliminated in the future. diff --git a/sycl/include/sycl/ext/intel/fpga_device_selector.hpp b/sycl/include/sycl/ext/intel/fpga_device_selector.hpp index f1f9b73bcf77b..a2dae1c958933 100644 --- a/sycl/include/sycl/ext/intel/fpga_device_selector.hpp +++ b/sycl/include/sycl/ext/intel/fpga_device_selector.hpp @@ -12,6 +12,7 @@ #include #include +#include namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { @@ -22,6 +23,26 @@ class platform; namespace ext { namespace intel { +namespace detail { +// Scores a device by platform name. +inline int selectDeviceByPlatform(std::string_view required_platform_name, + const device &device) { + if (device.get_platform().get_info() == + required_platform_name) + return 10000; + return -1; +} + +// Enables an environment variable required by the FPGA simulator. +inline void enableFPGASimulator() { +#ifdef _WIN32 + _putenv_s("CL_CONTEXT_MPSIM_DEVICE_INTELFPGA", "1"); +#else + setenv("CL_CONTEXT_MPSIM_DEVICE_INTELFPGA", "1", 0); +#endif +} +} // namespace detail + class platform_selector : public device_selector { private: std::string device_platform_name; @@ -31,13 +52,7 @@ class platform_selector : public device_selector { : device_platform_name(platform_name) {} int operator()(const device &device) const override { - const platform &pf = device.get_platform(); - const std::string &platform_name = - pf.get_info(); - if (platform_name == device_platform_name) { - return 10000; - } - return -1; + return detail::selectDeviceByPlatform(device_platform_name, device); } }; @@ -46,25 +61,44 @@ static constexpr auto EMULATION_PLATFORM_NAME = static constexpr auto HARDWARE_PLATFORM_NAME = "Intel(R) FPGA SDK for OpenCL(TM)"; -class fpga_selector : public platform_selector { +int fpga_selector_v(const device &device) { + return detail::selectDeviceByPlatform(HARDWARE_PLATFORM_NAME, device); +} + +int fpga_emulator_selector_v(const device &device) { + return detail::selectDeviceByPlatform(EMULATION_PLATFORM_NAME, device); +} + +int fpga_simulator_selector_v(const device &device) { + static bool IsFirstCall = true; + if (IsFirstCall) { + detail::enableFPGASimulator(); + IsFirstCall = false; + } + return fpga_selector_v(device); +} + +class __SYCL2020_DEPRECATED( + "Use the callable sycl::ext::intel::fpga_selector_v instead.") fpga_selector + : public platform_selector { public: fpga_selector() : platform_selector(HARDWARE_PLATFORM_NAME) {} }; -class fpga_emulator_selector : public platform_selector { +class __SYCL2020_DEPRECATED( + "Use the callable sycl::ext::intel::fpga_emulator_selector_v instead.") + fpga_emulator_selector : public platform_selector { public: fpga_emulator_selector() : platform_selector(EMULATION_PLATFORM_NAME) {} }; -class fpga_simulator_selector : public fpga_selector { +class __SYCL2020_DEPRECATED( + "Use the callable sycl::ext::intel::fpga_simulator_selector_v instead.") + fpga_simulator_selector : public fpga_selector { public: fpga_simulator_selector() { // Tell the runtime to use a simulator device rather than hardware -#ifdef _WIN32 - _putenv_s("CL_CONTEXT_MPSIM_DEVICE_INTELFPGA", "1"); -#else - setenv("CL_CONTEXT_MPSIM_DEVICE_INTELFPGA", "1", 0); -#endif + detail::enableFPGASimulator(); } }; diff --git a/sycl/include/sycl/ext/intel/fpga_utils.hpp b/sycl/include/sycl/ext/intel/fpga_utils.hpp index 5bfa52ae33d01..289f9edbc7d79 100644 --- a/sycl/include/sycl/ext/intel/fpga_utils.hpp +++ b/sycl/include/sycl/ext/intel/fpga_utils.hpp @@ -27,8 +27,8 @@ template