Skip to content

Commit dda37d7

Browse files
authored
FPGA: compile - remove +/- in path (#1404)
1 parent 8477aa4 commit dda37d7

File tree

17 files changed

+370
-360
lines changed

17 files changed

+370
-360
lines changed

DirectProgramming/C++SYCL_FPGA/Tutorials/GettingStarted/fpga_compile/README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ Part 4 shows the vector addition in SYCL* C++ with a 'function' coding style and
224224
#### On a Linux* System
225225
For different parts of this tutorial, navigate to the appropriate sub-folder.
226226
```bash
227-
cd <partX-XXX>
227+
cd <partX_XXX>
228228
```
229-
`<partX-XXX>` can be:
230-
- `part1-C++`
231-
- `part2-dpcpp_functor_usm`
232-
- `part3-dpcpp_lambda_usm`
233-
- `part4-dpcpp_lambda_buffers`
229+
`<partX_XXX>` can be:
230+
- `part1_cpp`
231+
- `part2_dpcpp_functor_usm`
232+
- `part3_dpcpp_lambda_usm`
233+
- `part4_dpcpp_lambda_buffers`
234234

235235
Generate the `Makefile` by running `cmake`.
236236
```
@@ -256,13 +256,13 @@ Generate the `Makefile` by running `cmake`.
256256
#### On a Windows* System
257257
For different parts of this tutorial, navigate to the appropriate sub-folder.
258258
```cmd
259-
cd <partX-XXX>
259+
cd <partX_XXX>
260260
```
261-
`<partX-XXX>` can be:
262-
- `part1-C++`
263-
- `part2-dpcpp_functor_usm`
264-
- `part3-dpcpp_lambda_usm`
265-
- `part4-dpcpp_lambda_buffers`
261+
`<partX_XXX>` can be:
262+
- `part1_cpp`
263+
- `part2_dpcpp_functor_usm`
264+
- `part3_dpcpp_lambda_usm`
265+
- `part4_dpcpp_lambda_buffers`
266266

267267
Generate the `Makefile` by running `cmake`.
268268
```

DirectProgramming/C++SYCL_FPGA/Tutorials/GettingStarted/fpga_compile/part1-C++/src/vector_add.cpp

-46
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
3+
void VectorAdd(const int *a_in, const int *b_in, int *c_out, int len) {
4+
for (int idx = 0; idx < len; idx++) {
5+
int a_val = a_in[idx];
6+
int b_val = b_in[idx];
7+
int sum = a_val + b_val;
8+
c_out[idx] = sum;
9+
}
10+
}
11+
12+
constexpr int kVectSize = 256;
13+
14+
int main() {
15+
// declare arrays and fill them
16+
int *vec_a = new int[kVectSize];
17+
int *vec_b = new int[kVectSize];
18+
int *vec_c = new int[kVectSize];
19+
for (int i = 0; i < kVectSize; i++) {
20+
vec_a[i] = i;
21+
vec_b[i] = (kVectSize - i);
22+
}
23+
24+
std::cout << "add two vectors of size " << kVectSize << std::endl;
25+
26+
VectorAdd(vec_a, vec_b, vec_c, kVectSize);
27+
28+
// verify that vector C is correct
29+
bool passed = true;
30+
for (int i = 0; i < kVectSize; i++) {
31+
int expected = vec_a[i] + vec_b[i];
32+
if (vec_c[i] != expected) {
33+
std::cout << "idx=" << i << ": result " << vec_c[i] << ", expected ("
34+
<< expected << ") A=" << vec_a[i] << " + B=" << vec_b[i]
35+
<< std::endl;
36+
passed = false;
37+
}
38+
}
39+
40+
std::cout << (passed ? "PASSED" : "FAILED") << std::endl;
41+
42+
delete[] vec_a;
43+
delete[] vec_b;
44+
delete[] vec_c;
45+
46+
return passed ? EXIT_SUCCESS : EXIT_FAILURE;
47+
}

DirectProgramming/C++SYCL_FPGA/Tutorials/GettingStarted/fpga_compile/part2-dpcpp_functor_usm/src/vector_add.cpp

-101
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include <iostream>
2+
3+
// oneAPI headers
4+
#include <sycl/ext/intel/fpga_extensions.hpp>
5+
#include <sycl/sycl.hpp>
6+
7+
// Forward declare the kernel name in the global scope. This is an FPGA best
8+
// practice that reduces name mangling in the optimization reports.
9+
class VectorAddID;
10+
11+
struct VectorAdd {
12+
int *const vec_a_in;
13+
int *const vec_b_in;
14+
int *const vec_c_out;
15+
int len;
16+
17+
void operator()() const {
18+
for (int idx = 0; idx < len; idx++) {
19+
int a_val = vec_a_in[idx];
20+
int b_val = vec_b_in[idx];
21+
int sum = a_val + b_val;
22+
vec_c_out[idx] = sum;
23+
}
24+
}
25+
};
26+
27+
constexpr int kVectSize = 256;
28+
29+
int main() {
30+
bool passed = true;
31+
try {
32+
// Use compile-time macros to select either:
33+
// - the FPGA emulator device (CPU emulation of the FPGA)
34+
// - the FPGA device (a real FPGA)
35+
// - the simulator device
36+
#if FPGA_SIMULATOR
37+
auto selector = sycl::ext::intel::fpga_simulator_selector_v;
38+
#elif FPGA_HARDWARE
39+
auto selector = sycl::ext::intel::fpga_selector_v;
40+
#else // #if FPGA_EMULATOR
41+
auto selector = sycl::ext::intel::fpga_emulator_selector_v;
42+
#endif
43+
44+
// create the device queue
45+
sycl::queue q(selector);
46+
47+
auto device = q.get_device();
48+
49+
std::cout << "Running on device: "
50+
<< device.get_info<sycl::info::device::name>().c_str()
51+
<< std::endl;
52+
53+
if (!device.has(sycl::aspect::usm_host_allocations)) {
54+
std::terminate();
55+
}
56+
57+
// declare arrays and fill them
58+
// allocate in shared memory so the kernel can see them
59+
int *vec_a = sycl::malloc_shared<int>(kVectSize, q);
60+
int *vec_b = sycl::malloc_shared<int>(kVectSize, q);
61+
int *vec_c = sycl::malloc_shared<int>(kVectSize, q);
62+
for (int i = 0; i < kVectSize; i++) {
63+
vec_a[i] = i;
64+
vec_b[i] = (kVectSize - i);
65+
}
66+
67+
std::cout << "add two vectors of size " << kVectSize << std::endl;
68+
69+
q.single_task<VectorAddID>(VectorAdd{vec_a, vec_b, vec_c, kVectSize})
70+
.wait();
71+
72+
// verify that vec_c is correct
73+
for (int i = 0; i < kVectSize; i++) {
74+
int expected = vec_a[i] + vec_b[i];
75+
if (vec_c[i] != expected) {
76+
std::cout << "idx=" << i << ": result " << vec_c[i] << ", expected ("
77+
<< expected << ") A=" << vec_a[i] << " + B=" << vec_b[i]
78+
<< std::endl;
79+
passed = false;
80+
}
81+
}
82+
83+
std::cout << (passed ? "PASSED" : "FAILED") << std::endl;
84+
85+
sycl::free(vec_a, q);
86+
sycl::free(vec_b, q);
87+
sycl::free(vec_c, q);
88+
} catch (sycl::exception const &e) {
89+
// Catches exceptions in the host code.
90+
std::cerr << "Caught a SYCL host exception:\n" << e.what() << "\n";
91+
92+
// Most likely the runtime couldn't find FPGA hardware!
93+
if (e.code().value() == CL_DEVICE_NOT_FOUND) {
94+
std::cerr << "If you are targeting an FPGA, please ensure that your "
95+
"system has a correctly configured FPGA board.\n";
96+
std::cerr << "Run sys_check in the oneAPI root directory to verify.\n";
97+
std::cerr << "If you are targeting the FPGA emulator, compile with "
98+
"-DFPGA_EMULATOR.\n";
99+
}
100+
std::terminate();
101+
}
102+
return passed ? EXIT_SUCCESS : EXIT_FAILURE;
103+
}

0 commit comments

Comments
 (0)