Skip to content

Commit 790aa8b

Browse files
[SYCL] [FPGA] Create DSP control header (#5035)
Create header file that provides user API for FPGA DSP control feature. Related links: SPIR-V spec: https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_fpga_dsp_control.asciidoc SPIR-V implementation: [SPIRV] New FPGA function attribute for DSP control KhronosGroup/SPIRV-LLVM-Translator#1046 Test: intel/llvm-test-suite#591
1 parent f82ddf4 commit 790aa8b

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//==------------ fpga_dsp_control.hpp --- SYCL FPGA DSP Control ------------==//
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+
#pragma once
9+
10+
__SYCL_INLINE_NAMESPACE(cl) {
11+
namespace sycl {
12+
namespace ext {
13+
namespace intel {
14+
15+
enum class Preference { DSP, Softlogic, Compiler_default };
16+
enum class Propagate { On, Off };
17+
18+
template <typename Function>
19+
#ifdef __SYCL_DEVICE_ONLY__
20+
[[intel::prefer_dsp]]
21+
[[intel::propagate_dsp_preference]]
22+
#endif // __SYCL_DEVICE_ONLY__
23+
void math_prefer_dsp_propagate(Function f)
24+
{
25+
f();
26+
}
27+
28+
template <typename Function>
29+
#ifdef __SYCL_DEVICE_ONLY__
30+
[[intel::prefer_dsp]]
31+
#endif // __SYCL_DEVICE_ONLY__
32+
void math_prefer_dsp_no_propagate(Function f)
33+
{
34+
f();
35+
}
36+
37+
template <typename Function>
38+
#ifdef __SYCL_DEVICE_ONLY__
39+
[[intel::prefer_softlogic]]
40+
[[intel::propagate_dsp_preference]]
41+
#endif // __SYCL_DEVICE_ONLY__
42+
void math_prefer_softlogic_propagate(Function f)
43+
{
44+
f();
45+
}
46+
47+
template <typename Function>
48+
#ifdef __SYCL_DEVICE_ONLY__
49+
[[intel::prefer_softlogic]]
50+
#endif // __SYCL_DEVICE_ONLY__
51+
void math_prefer_softlogic_no_propagate(Function f)
52+
{
53+
f();
54+
}
55+
56+
template <Preference my_preference = Preference::DSP,
57+
Propagate my_propagate = Propagate::On, typename Function>
58+
void math_dsp_control(Function f) {
59+
if (my_preference == Preference::DSP) {
60+
if (my_propagate == Propagate::On) {
61+
math_prefer_dsp_propagate(f);
62+
} else {
63+
math_prefer_dsp_no_propagate(f);
64+
}
65+
} else if (my_preference == Preference::Softlogic) {
66+
if (my_propagate == Propagate::On) {
67+
math_prefer_softlogic_propagate(f);
68+
} else {
69+
math_prefer_softlogic_no_propagate(f);
70+
}
71+
} else { // my_preference == Preference::Compiler_default
72+
math_prefer_dsp_no_propagate([&]() { f(); });
73+
}
74+
}
75+
76+
} // namespace intel
77+
} // namespace ext
78+
} // namespace sycl
79+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/sycl/ext/intel/fpga_extensions.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010
#include <sycl/ext/intel/fpga_device_selector.hpp>
11+
#include <sycl/ext/intel/fpga_dsp_control.hpp>
1112
#include <sycl/ext/intel/fpga_loop_fuse.hpp>
1213
#include <sycl/ext/intel/fpga_lsu.hpp>
1314
#include <sycl/ext/intel/fpga_reg.hpp>

sycl/test/extensions/fpga.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,29 @@ int main() {
128128
}
129129
}
130130

131+
/*Check DSP control interface*/
132+
cl::sycl::buffer<int, 1> output_buffer(1);
133+
cl::sycl::buffer<int, 1> input_buffer(1);
134+
Queue.submit([&](sycl::handler &cgh) {
135+
auto output_accessor =
136+
output_buffer.get_access<cl::sycl::access::mode::write>(cgh);
137+
auto input_accessor =
138+
input_buffer.get_access<cl::sycl::access::mode::read>(cgh);
139+
cgh.single_task<class DSPControlKernel>([=]() {
140+
float sum = input_accessor[0];
141+
sycl::ext::intel::math_dsp_control<
142+
sycl::ext::intel::Preference::Softlogic>([&] { sum += 1.23f; });
143+
sycl::ext::intel::math_dsp_control<sycl::ext::intel::Preference::DSP>(
144+
[&] { sum += 1.23f; });
145+
sycl::ext::intel::math_dsp_control<
146+
sycl::ext::intel::Preference::Softlogic,
147+
sycl::ext::intel::Propagate::Off>([&] { sum += 4.56f; });
148+
sycl::ext::intel::math_dsp_control<sycl::ext::intel::Preference::DSP,
149+
sycl::ext::intel::Propagate::Off>(
150+
[&] { sum += 4.56f; });
151+
output_accessor[0] = sum;
152+
});
153+
});
154+
131155
return 0;
132156
}

0 commit comments

Comments
 (0)