Skip to content

Commit 357e9c8

Browse files
authored
[SYCL] Fix FPGA devices selection on queue initialization (#1794)
FPGA device selectors use global constants of std::string type as parameters in constructor. If some other inline global variable uses fpga_device_selector in its constructor then there may be a situation when FPGA device selector is initialized before global std::string objects that it is depending on. Then it cannot find FPGA hw or emulator devices because it has uninitialized platform name member. Change type of constant strings with platform names to constant C-string to guarantee initialization of FPGA device selector with proper platform name.
1 parent 767ddfe commit 357e9c8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

sycl/include/CL/sycl/intel/fpga_device_selector.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class platform_selector : public device_selector {
2222
platform_selector(const std::string &platform_name)
2323
: device_platform_name(platform_name){}
2424

25-
virtual int operator()(const device &device) const {
25+
int operator()(const device &device) const override {
2626
const platform &pf = device.get_platform();
2727
const std::string &platform_name = pf.get_info<info::platform::name>();
2828
if (platform_name == device_platform_name) {
@@ -32,9 +32,10 @@ class platform_selector : public device_selector {
3232
}
3333
};
3434

35-
const std::string EMULATION_PLATFORM_NAME =
35+
static constexpr auto EMULATION_PLATFORM_NAME =
3636
"Intel(R) FPGA Emulation Platform for OpenCL(TM)";
37-
const std::string HARDWARE_PLATFORM_NAME = "Intel(R) FPGA SDK for OpenCL(TM)";
37+
static constexpr auto HARDWARE_PLATFORM_NAME =
38+
"Intel(R) FPGA SDK for OpenCL(TM)";
3839

3940
class fpga_selector : public platform_selector {
4041
public:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// REQUIRES: aoc, accelerator
2+
3+
// RUN: %clangxx -fsycl -fintelfpga -std=c++17 %s -o %t.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
6+
#include <CL/sycl.hpp>
7+
#include <CL/sycl/intel/fpga_extensions.hpp>
8+
9+
// Check that FPGA emulator device is found if we try to initialize inline global
10+
// variable using fpga_emulator_selector parameter.
11+
12+
inline cl::sycl::queue fpga_emu_queue_inlined{
13+
cl::sycl::intel::fpga_emulator_selector{}};
14+
15+
int main() {
16+
return 0;
17+
}

0 commit comments

Comments
 (0)