forked from triSYCL/triSYCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single_task_vector_increment_drt.cpp
67 lines (53 loc) · 1.95 KB
/
single_task_vector_increment_drt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* RUN: %{execute}%s
REQUIRES: this-test-does-not-run-with-lit-yet
A simple typical FPGA-like kernel
*/
#include <CL/sycl.hpp>
#include <iostream>
#include <numeric>
#include <boost/test/minimal.hpp>
using namespace cl::sycl;
constexpr size_t N = 300;
using Type = int;
int test_main(int argc, char *argv[]) {
buffer<Type> input { N };
buffer<Type> output { N };
{
auto a_input = input.get_access<access::mode::write>();
// Initialize buffer with increasing numbers starting at 0
std::iota(a_input.begin(), a_input.end(), 0);
}
/* Construct the queue from the default OpenCL one.
You can use the following environment variables to select
the device to be chosen at runtime
BOOST_COMPUTE_DEFAULT_DEVICE
BOOST_COMPUTE_DEFAULT_DEVICE_TYPE
BOOST_COMPUTE_DEFAULT_ENFORCE
BOOST_COMPUTE_DEFAULT_PLATFORM
BOOST_COMPUTE_DEFAULT_VENDOR
for example doing in bash
export BOOST_COMPUTE_DEFAULT_VENDOR=Xilinx
export BOOST_COMPUTE_DEFAULT_ENFORCE=1
will select for execution a Xilinx FPGA on the machine
*/
queue q { default_selector {} };
// Launch a kernel to do the summation
q.submit([&] (handler &cgh) {
// Get access to the data
auto a_input = input.get_access<access::mode::read>(cgh);
auto x_output = output.get_access<access::mode::write>(cgh);
// A typical FPGA-style pipelined kernel
cgh.single_task<class add>([=,
x_output = drt::accessor<decltype(x_output)> { x_output },
a_input = drt::accessor<decltype(a_input)> { a_input }] {
for (unsigned int i = 0 ; i < N; ++i)
x_output[i] = a_input[i] + 42;
});
});
// Verify the result
auto a_input = input.get_access<access::mode::read>();
auto a_output = output.get_access<access::mode::read>();
for (unsigned int i = 0 ; i < input.get_count(); ++i)
BOOST_CHECK(a_output[i] == a_input[i] + 42);
return 0;
}