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 {
18 inline namespace _V1 {
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 } // namespace _V1
107 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:66
platform get_platform() const
Get associated SYCL platform.
Definition: device.cpp:93
platform_selector(const std::string &platform_name)
int operator()(const device &device) const override
detail::ABINeutralT_t< typename detail::is_platform_info_desc< Param >::return_type > get_info() const
Queries this SYCL platform for info.
Definition: platform.cpp:65
#define __SYCL2020_DEPRECATED(message)
std::string string_view
Definition: handler.hpp:427
std::string string
Definition: handler.hpp:426
int selectDeviceByPlatform(std::string_view required_platform_name, const device &device)
int fpga_emulator_selector_v(const device &device)
int fpga_selector_v(const device &device)
int fpga_simulator_selector_v(const device &device)
static constexpr auto HARDWARE_PLATFORM_NAME
static constexpr auto EMULATION_PLATFORM_NAME
std::uint8_t instead
Definition: aliases.hpp:93
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:94
Definition: access.hpp:18