DPC++ Runtime
Runtime libraries for oneAPI DPC++
fpga_device_selector.hpp
Go to the documentation of this file.
1 //==- fpga_device_selector.hpp --- SYCL FPGA device selector shortcut -----==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/device.hpp>
12 #include <sycl/device_selector.hpp>
13 
14 #include <string>
15 #include <string_view>
16 
17 namespace sycl {
19 
20 // Forward declaration
21 class platform;
22 
23 namespace ext::intel {
24 
25 namespace detail {
26 // Scores a device by platform name.
27 inline int selectDeviceByPlatform(std::string_view required_platform_name,
28  const device &device) {
29  if (device.get_platform().get_info<sycl::info::platform::name>() ==
30  required_platform_name)
31  return 10000;
32  return -1;
33 }
34 
35 // Enables an environment variable required by the FPGA simulator.
36 inline void enableFPGASimulator() {
37 #ifdef _WIN32
38  _putenv_s("CL_CONTEXT_MPSIM_DEVICE_INTELFPGA", "1");
39 #else
40  setenv("CL_CONTEXT_MPSIM_DEVICE_INTELFPGA", "1", 0);
41 #endif
42 }
43 } // namespace detail
44 
46 private:
47  std::string device_platform_name;
48 
49 public:
50  platform_selector(const std::string &platform_name)
51  : device_platform_name(platform_name) {}
52 
53  int operator()(const device &device) const override {
54  return detail::selectDeviceByPlatform(device_platform_name, device);
55  }
56 };
57 
58 static constexpr auto EMULATION_PLATFORM_NAME =
59  "Intel(R) FPGA Emulation Platform for OpenCL(TM)";
60 static constexpr auto HARDWARE_PLATFORM_NAME =
61  "Intel(R) FPGA SDK for OpenCL(TM)";
62 
63 inline int fpga_selector_v(const device &device) {
65 }
66 
69 }
70 
72  static bool IsFirstCall = true;
73  if (IsFirstCall) {
75  IsFirstCall = false;
76  }
77  return fpga_selector_v(device);
78 }
79 
81  "Use the callable sycl::ext::intel::fpga_selector_v instead.") fpga_selector
82  : public platform_selector {
83 public:
84  fpga_selector() : platform_selector(HARDWARE_PLATFORM_NAME) {}
85 };
86 
89  fpga_emulator_selector : public platform_selector {
90 public:
91  fpga_emulator_selector() : platform_selector(EMULATION_PLATFORM_NAME) {}
92 };
93 
96  fpga_simulator_selector : public fpga_selector {
97 public:
98  fpga_simulator_selector() {
99  // Tell the runtime to use a simulator device rather than hardware
101  }
102 };
103 
104 } // namespace ext::intel
105 
106 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
107 } // namespace sycl
sycl::_V1::device::get_platform
platform get_platform() const
Get associated SYCL platform.
Definition: device.cpp:91
sycl::_V1::__SYCL2020_DEPRECATED
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:96
sycl::_V1::instead
std::uint8_t instead
Definition: aliases.hpp:95
sycl::_V1::ext::intel::fpga_simulator_selector_v
int fpga_simulator_selector_v(const device &device)
Definition: fpga_device_selector.hpp:71
sycl::_V1::errc::platform
@ platform
device_selector.hpp
device.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::ext::intel::EMULATION_PLATFORM_NAME
static constexpr auto EMULATION_PLATFORM_NAME
Definition: fpga_device_selector.hpp:58
sycl::_V1::ext::intel::detail::enableFPGASimulator
void enableFPGASimulator()
Definition: fpga_device_selector.hpp:36
sycl::_V1::ext::intel::platform_selector::operator()
int operator()(const device &device) const override
Definition: fpga_device_selector.hpp:53
device_selector
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:49
sycl::_V1::ext::intel::platform_selector
Definition: fpga_device_selector.hpp:45
sycl::_V1::ext::intel::fpga_selector_v
int fpga_selector_v(const device &device)
Definition: fpga_device_selector.hpp:63
sycl::_V1::ext::intel::HARDWARE_PLATFORM_NAME
static constexpr auto HARDWARE_PLATFORM_NAME
Definition: fpga_device_selector.hpp:60
sycl::_V1::ext::intel::platform_selector::platform_selector
platform_selector(const std::string &platform_name)
Definition: fpga_device_selector.hpp:50
sycl::_V1::ext::intel::detail::selectDeviceByPlatform
int selectDeviceByPlatform(std::string_view required_platform_name, const device &device)
Definition: fpga_device_selector.hpp:27
sycl::_V1::ext::intel::fpga_emulator_selector_v
int fpga_emulator_selector_v(const device &device)
Definition: fpga_device_selector.hpp:67
sycl::_V1::platform::get_info
detail::is_platform_info_desc< Param >::return_type get_info() const
Queries this SYCL platform for info.
Definition: platform.cpp:61
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:57