Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 22d6bc3

Browse files
committed
Create DSP control E2E emulator test
1 parent c28d0d3 commit 22d6bc3

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
// RUNx: %ACC_RUN_PLACEHOLDER %t.out
3+
//==---------- fpga_dsp_control.cpp - SYCL FPGA DSP control test -----------==//
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
#include <CL/sycl.hpp>
11+
#include <sycl/ext/intel/fpga_extensions.hpp>
12+
13+
int test_dsp_control(cl::sycl::queue Queue) {
14+
std::vector<float> input_data = {1.23f, 2.34f};
15+
std::vector<float> output_data = {.0f, .0f};
16+
17+
{
18+
cl::sycl::buffer input_buffer(input_data);
19+
cl::sycl::buffer output_buffer(output_data);
20+
21+
Queue.submit([&](cl::sycl::handler &cgh) {
22+
auto input_accessor =
23+
input_buffer.get_access<cl::sycl::access::mode::read>(cgh);
24+
25+
auto output_accessor =
26+
output_buffer.get_access<cl::sycl::access::mode::write>(cgh);
27+
28+
cgh.single_task<class kernel>([=] {
29+
cl::sycl::ext::intel::math_dsp_control<
30+
cl::sycl::ext::intel::Preference::DSP>(
31+
[&] { output_accessor[0] = input_accessor[0] + 1.0f; });
32+
33+
cl::sycl::ext::intel::math_dsp_control<
34+
cl::sycl::ext::intel::Preference::DSP,
35+
cl::sycl::ext::intel::Propagate::Off>(
36+
[&] { output_accessor[0] -= 1.0f; });
37+
38+
cl::sycl::ext::intel::math_dsp_control<
39+
cl::sycl::ext::intel::Preference::Softlogic>(
40+
[&] { output_accessor[1] = input_accessor[1] + 1.0f; });
41+
42+
cl::sycl::ext::intel::math_dsp_control<
43+
cl::sycl::ext::intel::Preference::Softlogic,
44+
cl::sycl::ext::intel::Propagate::Off>(
45+
[&] { output_accessor[1] -= 1.0f; });
46+
});
47+
});
48+
}
49+
50+
for (int i = 0; i < 2; i++) {
51+
if (output_data[i] != input_data[i]) {
52+
std::cout << "Unexpected read from output_data: " << output_data[i]
53+
<< ", v.s. expected " << input_data[i] << std::endl;
54+
55+
return -1;
56+
}
57+
}
58+
return 0;
59+
}
60+
61+
int main() {
62+
cl::sycl::queue Queue{cl::sycl::ext::intel::fpga_emulator_selector{}};
63+
64+
return test_dsp_control(Queue);
65+
}

0 commit comments

Comments
 (0)