Skip to content

Commit ff8621a

Browse files
Address Ronan's comments
1 parent 23ad06b commit ff8621a

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

DirectProgramming/DPC++FPGA/Tutorials/DesignPatterns/compute_units/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ The `Source` kernel reads data from host memory and writes it to the first pipe:
4242
void SourceKernel(queue &q, float data) {
4343
4444
q.submit([&](handler &h) {
45-
h.single_task<Source>([=]() { Pipes::PipeAt<0>::write(data); });
45+
h.single_task<Source>([=] { Pipes::PipeAt<0>::write(data); });
4646
});
4747
}
4848
```
4949

5050
At the end of the chain, the `Sink` kernel reads data from the last pipe and returns it to the host:
5151

5252
``` c++
53-
void SinkKernel(queue &q, std::array<float, 1> &out_data) {
53+
void SinkKernel(queue &q, float *out_data) {
5454

55-
buffer<float, 1> out_buf(out_data.data(), 1);
55+
// The verbose buffer syntax is necessary here,
56+
// since out_data is just a single scalar value
57+
// and its size can not be inferred automatically
58+
buffer<float, 1> out_buf(out_data, 1);
5659

5760
q.submit([&](handler &h) {
5861
auto out_accessor = out_buf.get_access<access::mode::write>(h);
5962
h.single_task<Sink>(
60-
[=]() { out_accessor[0] = Pipes::PipeAt<kEngines>::read(); });
63+
[=] { out_accessor[0] = Pipes::PipeAt<kEngines>::read(); });
6164
});
6265
}
6366
```
@@ -66,7 +69,7 @@ void SinkKernel(queue &q, std::array<float, 1> &out_data) {
6669
6770
``` c++
6871
intelfpga::submit_compute_units<kEngines, ChainComputeUnit>(q, [=](auto ID) {
69-
float f = Pipes::PipeAt<ID>::read();
72+
auto f = Pipes::PipeAt<ID>::read();
7073
Pipes::PipeAt<ID + 1>::write(f);
7174
});
7275
```

DirectProgramming/DPC++FPGA/Tutorials/DesignPatterns/compute_units/src/compute_units.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ void SourceKernel(queue &q, float data) {
4545
}
4646

4747
// Get the data out of the chain and return it to the host
48-
void SinkKernel(queue &q, std::array<float, 1> &out_data) {
48+
void SinkKernel(queue &q, float *out_data) {
4949

50-
// Use verbose SYCL 1.2 syntax for the output buffer.
51-
// (This will become unnecessary in a future compiler version.)
52-
buffer<float, 1> out_buf(out_data.data(), 1);
50+
// The verbose buffer syntax is necessary here,
51+
// since out_data is just a single scalar value
52+
// and its size can not be inferred automatically
53+
buffer<float, 1> out_buf(out_data, 1);
5354

5455
q.submit([&](handler &h) {
5556
auto out_accessor = out_buf.get_access<access::mode::write>(h);
@@ -66,7 +67,7 @@ int main() {
6667
INTEL::fpga_selector device_selector;
6768
#endif
6869

69-
std::array<float, 1> out_data = {0};
70+
float out_data = 0;
7071

7172
try {
7273
queue q(device_selector, dpc_common::exception_handler);
@@ -77,12 +78,12 @@ int main() {
7778
// Enqueue the chain of kEngines compute units
7879
// Compute unit must take a single argument, its ID
7980
submit_compute_units<kEngines, ChainComputeUnit>(q, [=](auto ID) {
80-
float f = Pipes::PipeAt<ID>::read();
81+
auto f = Pipes::PipeAt<ID>::read();
8182
Pipes::PipeAt<ID + 1>::write(f);
8283
});
8384

8485
// Enqueue the Sink kernel
85-
SinkKernel(q, out_data);
86+
SinkKernel(q, &out_data);
8687

8788
} catch (sycl::exception const &e) {
8889
// Catches exceptions in the host code
@@ -99,9 +100,9 @@ int main() {
99100
}
100101

101102
// Verify result
102-
if (out_data[0] != kTestData) {
103+
if (out_data != kTestData) {
103104
std::cout << "FAILED: The results are incorrect\n";
104-
std::cout << "Expected: " << kTestData << " Got: " << out_data[0] << "\n";
105+
std::cout << "Expected: " << kTestData << " Got: " << out_data << "\n";
105106
return 1;
106107
}
107108

DirectProgramming/DPC++FPGA/Tutorials/DesignPatterns/compute_units/src/pipe_array.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace INTEL = sycl::intel; // Namespace alias for backward compatibility
1515
#else
1616
#include <CL/sycl/INTEL/fpga_extensions.hpp>
17+
using namespace sycl;
1718
#endif
1819

1920

0 commit comments

Comments
 (0)