Skip to content

Commit 47136b9

Browse files
FPGA: Revert "FPGA: Remove db query 9 in 2023.0 (#1257)" (#1281)
This reverts commit 86c4aa8 and reenables the db9 code sample in 2023.1
1 parent 71a6cc9 commit 47136b9

File tree

10 files changed

+1160
-14
lines changed

10 files changed

+1160
-14
lines changed

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/db/README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ This design leverages concepts discussed in the [FPGA tutorials](/DirectProgramm
7676

7777
### Query Implementations
7878

79-
The following sections describe at a high level how queries 1, 11 and 12 are implemented on the FPGA using a set of generalized database operators (found in `db_utils/`). In the block diagrams below, the blocks are oneAPI kernels, and the arrows represent `pipes` that shows the flow of data from one kernel to another.
79+
The following sections describe at a high level how queries 1, 9, 11 and 12 are implemented on the FPGA using a set of generalized database operators (found in `db_utils/`). In the block diagrams below, the blocks are oneAPI kernels, and the arrows represent `pipes` that shows the flow of data from one kernel to another.
8080

8181
#### Query 1
8282

8383
Query 1 is the simplest of the four queries and only uses the `Accumulator` database operator. The query streams in each row of the LINEITEM table and performs computation on each row.
8484

85+
#### Query 9
86+
87+
Query 9 is the most complicated of the four queries and utilizes all database operators (`LikeRegex`, `Accumulator`, `MapJoin`, `MergeJoin`, `DuplicateMergeJoin`, and `FifoSort`). The block diagram of the design is shown below.
88+
89+
![](assets/q9.png)
90+
8591
#### Query 11
8692

8793
Query 11 showcases the `MapJoin` and `FifoSort` database operators. The block diagram of the design is shown below.
@@ -101,6 +107,8 @@ Query 12 showcases the `MergeJoin` database operator. The block diagram of the d
101107
|`dbdata.cpp` | Contains code to parse the database input files and validate the query output
102108
|`dbdata.hpp` | Definitions of database related data structures and parsing functions
103109
|`query1/query1_kernel.cpp` | Contains the kernel for Query 1
110+
|`query9/query9_kernel.cpp` | Contains the kernel for Query 9
111+
|`query9/pipe_types.cpp` | All data types and instantiations for pipes used in query 9
104112
|`query11/query11_kernel.cpp` | Contains the kernel for Query 11
105113
|`query11/pipe_types.cpp` | All data types and instantiations for pipes used in query 11
106114
|`query12/query12_kernel.cpp` | Contains the kernel for Query 12
@@ -142,7 +150,7 @@ Query 12 showcases the `MergeJoin` database operator. The block diagram of the d
142150
cd build
143151
cmake .. -DQUERY=1
144152
```
145-
`-DQUERY=<QUERY_NUMBER>` can be any of the following query numbers: `1`, `11` or `12`.
153+
`-DQUERY=<QUERY_NUMBER>` can be any of the following query numbers: `1`, `9`, `11` or `12`.
146154

147155
3. Compile the design. (The provided targets match the recommended development flow.)
148156

@@ -156,12 +164,14 @@ Query 12 showcases the `MergeJoin` database operator. The block diagram of the d
156164
```
157165
The report resides at `db_report.prj/reports/report.html`.
158166
167+
>**Note**: If you are compiling Query 9 (`-DQUERY=9`), expect a long report generation time. You can download pre-generated reports from [https://iotdk.intel.com/fpga-precompiled-binaries/latest/db.fpga.tar.gz](https://iotdk.intel.com/fpga-precompiled-binaries/latest/db.fpga.tar.gz).
168+
159169
3. Compile for FPGA hardware (longer compile time, targets FPGA device).
160170
161171
```
162172
make fpga
163173
```
164-
When building for hardware, the default scale factor is **1**. To use the smaller scale factor of 0.01, add the flag `-DSF_SMALL=1` to the original `cmake` command. For example: `cmake .. -DQUERY=11 -DSF_SMALL=1`. See the [Database files](#database-files) for more information.
174+
When building for hardware, the default scale factor is **1**. To use the smaller scale factor of 0.01, add the flag `-DSF_SMALL=1` to the original `cmake` command. For example: `cmake .. -DQUERY=9 -DSF_SMALL=1`. See the [Database files](#database-files) for more information.
165175
166176
(Optional) The hardware compile may take several hours to complete. You can download a pre-compiled binary (compatible with Linux* Ubuntu* 18.04) for an Intel® FPGA PAC D5005 (with Intel Stratix® 10 SX) from [https://iotdk.intel.com/fpga-precompiled-binaries/latest/db.fpga.tar.gz](https://iotdk.intel.com/fpga-precompiled-binaries/latest/db.fpga.tar.gz).
167177
@@ -176,7 +186,7 @@ Query 12 showcases the `MergeJoin` database operator. The block diagram of the d
176186
cd build
177187
cmake -G "NMake Makefiles" -DQUERY=1
178188
```
179-
`-DQUERY=<QUERY_NUMBER>` can be any of the following query numbers: `1`, `11` or `12`.
189+
`-DQUERY=<QUERY_NUMBER>` can be any of the following query numbers: `1`, `9`, `11` or `12`.
180190
181191
3. Compile the design. (The provided targets match the recommended development flow.)
182192
@@ -191,6 +201,8 @@ Query 12 showcases the `MergeJoin` database operator. The block diagram of the d
191201
```
192202
The report resides at `db_report.prj/reports/report.html` directory.
193203
204+
>**Note**: If you are compiling Query 9 (`-DQUERY=9`), expect a long report generation time.
205+
194206
3. Compile for FPGA hardware (longer compile time, targets FPGA device):
195207
```
196208
nmake fpga
@@ -216,7 +228,7 @@ Query 12 showcases the `MergeJoin` database operator. The block diagram of the d
216228
```
217229
./db.fpga_emu --dbroot=../data/sf0.01 --test
218230
```
219-
(Optional) Run the design for queries `11` and `12`.
231+
(Optional) Run the design for queries `9`, `11` and `12`.
220232
221233
2. Run the design on an FPGA device.
222234
```
@@ -229,7 +241,7 @@ Query 12 showcases the `MergeJoin` database operator. The block diagram of the d
229241
```
230242
db.fpga_emu.exe --dbroot=../data/sf0.01 --test
231243
```
232-
(Optional) Run the design for queries `11` and `12`.
244+
(Optional) Run the design for queries `9`, `11` and `12`.
233245
234246
2. Run the sample on an FPGA device.
235247
```
Loading

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/db/sample.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
"./db.fpga_emu --dbroot=../data/sf0.01 --test"
3131
]
3232
},
33+
{
34+
"id": "fpga_emu_q9",
35+
"steps": [
36+
"icpx --version",
37+
"mkdir build-q9",
38+
"cd build-q9",
39+
"cmake .. -DQUERY=9",
40+
"make fpga_emu",
41+
"./db.fpga_emu --dbroot=../data/sf0.01 --test"
42+
]
43+
},
3344
{
3445
"id": "fpga_emu_q11",
3546
"steps": [
@@ -97,6 +108,19 @@
97108
"db.fpga_emu.exe --dbroot=../data/sf0.01 --test"
98109
]
99110
},
111+
{
112+
"id": "fpga_emu_q9",
113+
"steps": [
114+
"icpx --version",
115+
"cd ../..",
116+
"mkdir build-q9",
117+
"cd build-q9",
118+
"xcopy /E ..\\ReferenceDesigns\\db\\data ..\\data\\",
119+
"cmake -G \"NMake Makefiles\" ../ReferenceDesigns/db -DQUERY=9",
120+
"nmake fpga_emu",
121+
"db.fpga_emu.exe --dbroot=../data/sf0.01 --test"
122+
]
123+
},
100124
{
101125
"id": "fpga_emu_q11",
102126
"steps": [

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/db/src/CMakeLists.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ endif()
1515
if(${QUERY} EQUAL 1)
1616
set(DEFAULT_BOARD "intel_a10gx_pac:pac_a10")
1717
set(DEFAULT_BOARD_STR "Intel Arria(R) 10 GX")
18+
elseif(${QUERY} EQUAL 9)
19+
set(DEFAULT_BOARD "intel_s10sx_pac:pac_s10")
20+
set(DEFAULT_BOARD_STR "Intel Stratix(R) 10 SX")
1821
elseif(${QUERY} EQUAL 11)
1922
set(DEFAULT_BOARD "intel_s10sx_pac:pac_s10")
2023
set(DEFAULT_BOARD_STR "Intel Stratix(R) 10 SX")
@@ -42,8 +45,8 @@ else()
4245
endif()
4346

4447
# ensure a supported query was requested
45-
if(NOT ${QUERY} EQUAL 1 AND NOT ${QUERY} EQUAL 11 AND NOT ${QUERY} EQUAL 12)
46-
message(FATAL_ERROR "\tQUERY ${QUERY} not supported (supported queries are 1, 11 and 12)")
48+
if(NOT ${QUERY} EQUAL 1 AND NOT ${QUERY} EQUAL 9 AND NOT ${QUERY} EQUAL 11 AND NOT ${QUERY} EQUAL 12)
49+
message(FATAL_ERROR "\tQUERY ${QUERY} not supported (supported queries are 1, 9, 11 and 12)")
4750
endif()
4851

4952
# Pick the default seed if the user did not specify one to CMake.
@@ -52,6 +55,8 @@ if(NOT DEFINED SEED)
5255
if(${FPGA_DEVICE} MATCHES ".*a10.*")
5356
if(${QUERY} EQUAL 1)
5457
set(SEED "-Xsseed=2")
58+
elseif(${QUERY} EQUAL 9)
59+
set(SEED "-Xsseed=2")
5560
elseif(${QUERY} EQUAL 11)
5661
set(SEED "-Xsseed=4")
5762
elseif(${QUERY} EQUAL 12)
@@ -60,6 +65,8 @@ if(NOT DEFINED SEED)
6065
elseif(${FPGA_DEVICE} MATCHES ".*s10.*")
6166
if(${QUERY} EQUAL 1)
6267
set(SEED "-Xsseed=3")
68+
elseif(${QUERY} EQUAL 9)
69+
set(SEED "-Xsseed=2")
6370
elseif(${QUERY} EQUAL 11)
6471
set(SEED "-Xsseed=3")
6572
elseif(${QUERY} EQUAL 12)
@@ -68,6 +75,8 @@ if(NOT DEFINED SEED)
6875
elseif(${FPGA_DEVICE} MATCHES ".*agilex.*")
6976
if(${QUERY} EQUAL 1)
7077
set(SEED "-Xsseed=2")
78+
elseif(${QUERY} EQUAL 9)
79+
set(SEED "-Xsseed=2")
7180
elseif(${QUERY} EQUAL 11)
7281
set(SEED "-Xsseed=4")
7382
elseif(${QUERY} EQUAL 12)
@@ -82,10 +91,10 @@ if(IGNORE_DEFAULT_SEED)
8291
set(SEED "")
8392
endif()
8493

85-
# Error out if trying to run Q11 on Arria 10
94+
# Error out if trying to run Q9 or Q11 on Arria 10
8695
if (${FPGA_DEVICE} MATCHES ".*a10.*")
87-
if(${QUERY} EQUAL 11)
88-
message(FATAL_ERROR "Query 11 is not supported on Arria 10 devices")
96+
if(${QUERY} EQUAL 9 OR ${QUERY} EQUAL 11)
97+
message(FATAL_ERROR "Queries 9 and 11 are not supported on Arria 10 devices")
8998
endif()
9099
endif()
91100

@@ -106,14 +115,17 @@ endif()
106115
if(${QUERY} EQUAL 1)
107116
set(DEVICE_SOURCE query1/query1_kernel.cpp)
108117
set(DEVICE_HEADER query1/query1_kernel.hpp)
118+
elseif(${QUERY} EQUAL 9)
119+
set(DEVICE_SOURCE query9/query9_kernel.cpp)
120+
set(DEVICE_HEADER query9/query9_kernel.hpp)
109121
elseif(${QUERY} EQUAL 11)
110122
set(DEVICE_SOURCE query11/query11_kernel.cpp)
111123
set(DEVICE_HEADER query11/query11_kernel.hpp)
112124
elseif(${QUERY} EQUAL 12)
113125
set(DEVICE_SOURCE query12/query12_kernel.cpp)
114126
set(DEVICE_HEADER query12/query12_kernel.hpp)
115127
else()
116-
message(FATAL_ERROR "\tQUERY ${QUERY} not supported (supported queries are 1, 11 and 12)")
128+
message(FATAL_ERROR "\tQUERY ${QUERY} not supported (supported queries are 1, 9, 11 and 12)")
117129
endif()
118130

119131
# A SYCL ahead-of-time (AoT) compile processes the device code in two stages.

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/db/src/db.cpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ using namespace sycl;
4242
bool DoQuery1(queue& q, Database& dbinfo, std::string& db_root_dir,
4343
std::string& args, bool test, bool print, double& kernel_latency,
4444
double& total_latency);
45+
#elif (QUERY == 9)
46+
#include "query9/query9_kernel.hpp"
47+
bool DoQuery9(queue& q, Database& dbinfo, std::string& db_root_dir,
48+
std::string& args, bool test, bool print, double& kernel_latency,
49+
double& total_latency);
4550
#elif (QUERY == 11)
4651
#include "query11/query11_kernel.hpp"
4752
bool DoQuery11(queue& q, Database& dbinfo, std::string& db_root_dir,
@@ -168,9 +173,9 @@ int main(int argc, char* argv[]) {
168173
}
169174

170175
// make sure the query is supported
171-
if (!(query == 1 || query == 11 || query == 12)) {
176+
if (!(query == 1 || query == 9 || query == 11 || query == 12)) {
172177
std::cerr << "ERROR: unsupported query (" << query << "). "
173-
<< "Only queries 1, 11 and 12 are supported\n";
178+
<< "Only queries 1, 9, 11 and 12 are supported\n";
174179
return 1;
175180
}
176181

@@ -224,6 +229,13 @@ int main(int argc, char* argv[]) {
224229
success = DoQuery1(q, dbinfo, db_root_dir, args,
225230
test_query, print_result,
226231
kernel_latency[run], total_latency[run]);
232+
#endif
233+
} else if (query == 9) {
234+
// query9
235+
#if (QUERY == 9)
236+
success = DoQuery9(q, dbinfo, db_root_dir, args,
237+
test_query, print_result,
238+
kernel_latency[run], total_latency[run]);
227239
#endif
228240
} else if (query == 11) {
229241
// query11
@@ -351,6 +363,51 @@ bool DoQuery1(queue& q, Database& dbinfo, std::string& db_root_dir,
351363
}
352364
#endif
353365

366+
#if (QUERY == 9)
367+
bool DoQuery9(queue& q, Database& dbinfo, std::string& db_root_dir,
368+
std::string& args, bool test, bool print, double& kernel_latency,
369+
double& total_latency) {
370+
// the default colour regex based on the TPCH documents
371+
std::string colour = "GREEN";
372+
373+
// parse the query arguments
374+
if (!test && !args.empty()) {
375+
std::stringstream ss(args);
376+
std::getline(ss, colour, ',');
377+
} else {
378+
if (!args.empty()) {
379+
std::cout << "Testing query 9, therefore ignoring the '--args' flag\n";
380+
}
381+
}
382+
383+
// convert the colour regex to uppercase characters (convention)
384+
transform(colour.begin(), colour.end(), colour.begin(), ::toupper);
385+
386+
std::cout << "Running Q9 with colour regex: " << colour << std::endl;
387+
388+
// the output of the query
389+
std::array<DBDecimal, 25 * 2020> sum_profit;
390+
391+
// perform the query
392+
bool success = SubmitQuery9(q, dbinfo, colour, sum_profit, kernel_latency,
393+
total_latency);
394+
395+
if (success) {
396+
// validate the results of the query, if requested
397+
if (test) {
398+
success = dbinfo.ValidateQ9(db_root_dir, sum_profit);
399+
}
400+
401+
// print the results of the query, if requested
402+
if (print) {
403+
dbinfo.PrintQ9(sum_profit);
404+
}
405+
}
406+
407+
return success;
408+
}
409+
#endif
410+
354411
#if (QUERY == 11)
355412
bool DoQuery11(queue& q, Database& dbinfo, std::string& db_root_dir,
356413
std::string& args, bool test, bool print, double& kernel_latency,

0 commit comments

Comments
 (0)